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 "l2_packet/l2_packet.h"
34 #include "linux_defines.h"
35 #include "linux_ioctl.h"
37 #include "radiotap_iter.h"
39 #include "driver_nl80211.h"
42 #ifndef CONFIG_LIBNL20
44 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
45 * but when you free a socket again it will mess up its bitmap and
46 * and use the wrong number the next time it needs a socket ID.
47 * Therefore, we wrap the handle alloc/destroy and add our own pid
50 static uint32_t port_bitmap
[32] = { 0 };
52 static struct nl_handle
*nl80211_handle_alloc(void *cb
)
54 struct nl_handle
*handle
;
55 uint32_t pid
= getpid() & 0x3FFFFF;
58 handle
= nl_handle_alloc_cb(cb
);
60 for (i
= 0; i
< 1024; i
++) {
61 if (port_bitmap
[i
/ 32] & (1 << (i
% 32)))
63 port_bitmap
[i
/ 32] |= 1 << (i
% 32);
68 nl_socket_set_local_port(handle
, pid
);
73 static void nl80211_handle_destroy(struct nl_handle
*handle
)
75 uint32_t port
= nl_socket_get_local_port(handle
);
78 port_bitmap
[port
/ 32] &= ~(1 << (port
% 32));
80 nl_handle_destroy(handle
);
82 #endif /* CONFIG_LIBNL20 */
86 /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
87 #undef nl_socket_set_nonblocking
88 #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
90 #define genl_ctrl_resolve android_genl_ctrl_resolve
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
,
136 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
137 * by default. It is possible to hit that limit in some cases where
138 * operations are blocked, e.g., with a burst of Deauthentication frames
139 * to hostapd and STA entry deletion. Try to increase the buffer to make
140 * this less likely to occur.
142 if (nl_socket_set_buffer_size(*handle
, 262144, 0) < 0) {
143 wpa_printf(MSG_DEBUG
,
144 "nl80211: Could not set nl_socket RX buffer size: %s",
146 /* continue anyway with the default (smaller) buffer */
149 nl_socket_set_nonblocking(*handle
);
150 eloop_register_read_sock(nl_socket_get_fd(*handle
), handler
,
151 eloop_data
, *handle
);
152 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
156 static void nl80211_destroy_eloop_handle(struct nl_handle
**handle
)
158 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
159 eloop_unregister_read_sock(nl_socket_get_fd(*handle
));
160 nl_destroy_handles(handle
);
164 static void nl80211_global_deinit(void *priv
);
166 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
167 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
168 struct hostapd_freq_params
*freq
);
171 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
172 const u8
*set_addr
, int first
,
173 const char *driver_params
);
174 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
175 unsigned int freq
, unsigned int wait
,
176 const u8
*buf
, size_t buf_len
, u64
*cookie
,
177 int no_cck
, int no_ack
, int offchanok
);
178 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
181 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
182 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
183 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
185 static int nl80211_set_channel(struct i802_bss
*bss
,
186 struct hostapd_freq_params
*freq
, int set_chan
);
187 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
188 int ifindex
, int disabled
);
190 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
193 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
);
194 static int nl80211_set_param(void *priv
, const char *param
);
197 /* Converts nl80211_chan_width to a common format */
198 enum chan_width
convert2width(int width
)
201 case NL80211_CHAN_WIDTH_20_NOHT
:
202 return CHAN_WIDTH_20_NOHT
;
203 case NL80211_CHAN_WIDTH_20
:
204 return CHAN_WIDTH_20
;
205 case NL80211_CHAN_WIDTH_40
:
206 return CHAN_WIDTH_40
;
207 case NL80211_CHAN_WIDTH_80
:
208 return CHAN_WIDTH_80
;
209 case NL80211_CHAN_WIDTH_80P80
:
210 return CHAN_WIDTH_80P80
;
211 case NL80211_CHAN_WIDTH_160
:
212 return CHAN_WIDTH_160
;
214 return CHAN_WIDTH_UNKNOWN
;
218 int is_ap_interface(enum nl80211_iftype nlmode
)
220 return nlmode
== NL80211_IFTYPE_AP
||
221 nlmode
== NL80211_IFTYPE_P2P_GO
;
225 int is_sta_interface(enum nl80211_iftype nlmode
)
227 return nlmode
== NL80211_IFTYPE_STATION
||
228 nlmode
== NL80211_IFTYPE_P2P_CLIENT
;
232 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
234 return nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
235 nlmode
== NL80211_IFTYPE_P2P_GO
;
239 struct i802_bss
* get_bss_ifindex(struct wpa_driver_nl80211_data
*drv
,
242 struct i802_bss
*bss
;
244 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
245 if (bss
->ifindex
== ifindex
)
253 static int is_mesh_interface(enum nl80211_iftype nlmode
)
255 return nlmode
== NL80211_IFTYPE_MESH_POINT
;
259 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
262 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
264 os_memset(drv
->bssid
, 0, ETH_ALEN
);
269 static int ack_handler(struct nl_msg
*msg
, void *arg
)
276 static int finish_handler(struct nl_msg
*msg
, void *arg
)
283 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
292 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
298 static void nl80211_nlmsg_clear(struct nl_msg
*msg
)
301 * Clear nlmsg data, e.g., to make sure key material is not left in
302 * heap memory for unnecessarily long time.
305 struct nlmsghdr
*hdr
= nlmsg_hdr(msg
);
306 void *data
= nlmsg_data(hdr
);
308 * This would use nlmsg_datalen() or the older nlmsg_len() if
309 * only libnl were to maintain a stable API.. Neither will work
310 * with all released versions, so just calculate the length
313 int len
= hdr
->nlmsg_len
- NLMSG_HDRLEN
;
315 os_memset(data
, 0, len
);
320 static int send_and_recv(struct nl80211_global
*global
,
321 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
322 int (*valid_handler
)(struct nl_msg
*, void *),
331 cb
= nl_cb_clone(global
->nl_cb
);
335 err
= nl_send_auto_complete(nl_handle
, msg
);
341 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
342 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
343 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
346 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
347 valid_handler
, valid_data
);
350 int res
= nl_recvmsgs(nl_handle
, cb
);
353 "nl80211: %s->nl_recvmsgs failed: %d",
359 if (!valid_handler
&& valid_data
== (void *) -1)
360 nl80211_nlmsg_clear(msg
);
366 int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
368 int (*valid_handler
)(struct nl_msg
*, void *),
371 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
372 valid_handler
, valid_data
);
382 static int family_handler(struct nl_msg
*msg
, void *arg
)
384 struct family_data
*res
= arg
;
385 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
386 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
387 struct nlattr
*mcgrp
;
390 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
391 genlmsg_attrlen(gnlh
, 0), NULL
);
392 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
395 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
396 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
397 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
398 nla_len(mcgrp
), NULL
);
399 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
400 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
401 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
403 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
405 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
413 static int nl_get_multicast_id(struct nl80211_global
*global
,
414 const char *family
, const char *group
)
418 struct family_data res
= { group
, -ENOENT
};
423 if (!genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
424 0, 0, CTRL_CMD_GETFAMILY
, 0) ||
425 nla_put_string(msg
, CTRL_ATTR_FAMILY_NAME
, family
)) {
430 ret
= send_and_recv(global
, global
->nl
, msg
, family_handler
, &res
);
437 void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
438 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
440 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
445 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
447 if (bss
->wdev_id_set
)
448 return nla_put_u64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
449 return nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
453 struct nl_msg
* nl80211_cmd_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
461 if (!nl80211_cmd(bss
->drv
, msg
, flags
, cmd
) ||
462 nl80211_set_iface_id(msg
, bss
) < 0) {
471 static struct nl_msg
*
472 nl80211_ifindex_msg(struct wpa_driver_nl80211_data
*drv
, int ifindex
,
473 int flags
, uint8_t cmd
)
481 if (!nl80211_cmd(drv
, msg
, flags
, cmd
) ||
482 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, ifindex
)) {
491 struct nl_msg
* nl80211_drv_msg(struct wpa_driver_nl80211_data
*drv
, int flags
,
494 return nl80211_ifindex_msg(drv
, drv
->ifindex
, flags
, cmd
);
498 struct nl_msg
* nl80211_bss_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
500 return nl80211_ifindex_msg(bss
->drv
, bss
->ifindex
, flags
, cmd
);
504 struct wiphy_idx_data
{
506 enum nl80211_iftype nlmode
;
511 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
513 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
514 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
515 struct wiphy_idx_data
*info
= arg
;
517 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
518 genlmsg_attrlen(gnlh
, 0), NULL
);
520 if (tb
[NL80211_ATTR_WIPHY
])
521 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
523 if (tb
[NL80211_ATTR_IFTYPE
])
524 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
526 if (tb
[NL80211_ATTR_MAC
] && info
->macaddr
)
527 os_memcpy(info
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
534 int nl80211_get_wiphy_index(struct i802_bss
*bss
)
537 struct wiphy_idx_data data
= {
542 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
545 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
546 return data
.wiphy_idx
;
551 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
554 struct wiphy_idx_data data
= {
555 .nlmode
= NL80211_IFTYPE_UNSPECIFIED
,
559 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
560 return NL80211_IFTYPE_UNSPECIFIED
;
562 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
564 return NL80211_IFTYPE_UNSPECIFIED
;
568 static int nl80211_get_macaddr(struct i802_bss
*bss
)
571 struct wiphy_idx_data data
= {
572 .macaddr
= bss
->addr
,
575 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
578 return send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
);
582 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
583 struct nl80211_wiphy_data
*w
)
592 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
) ||
593 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
)) {
598 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
600 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
601 "failed: ret=%d (%s)",
602 ret
, strerror(-ret
));
608 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
610 struct nl80211_wiphy_data
*w
= eloop_ctx
;
613 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
615 res
= nl_recvmsgs(handle
, w
->nl_cb
);
617 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
623 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
625 struct nl80211_wiphy_data
*w
= arg
;
626 struct wpa_driver_nl80211_data
*drv
;
627 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
628 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
629 union wpa_event_data event
;
631 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
632 genlmsg_attrlen(gnlh
, 0), NULL
);
634 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
635 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
640 if (!tb
[NL80211_ATTR_FRAME
])
643 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
645 os_memset(&event
, 0, sizeof(event
));
646 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
647 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
648 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
655 static struct nl80211_wiphy_data
*
656 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
658 static DEFINE_DL_LIST(nl80211_wiphys
);
659 struct nl80211_wiphy_data
*w
;
660 int wiphy_idx
, found
= 0;
661 struct i802_bss
*tmp_bss
;
663 if (bss
->wiphy_data
!= NULL
)
664 return bss
->wiphy_data
;
666 wiphy_idx
= nl80211_get_wiphy_index(bss
);
668 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
669 if (w
->wiphy_idx
== wiphy_idx
)
674 w
= os_zalloc(sizeof(*w
));
677 w
->wiphy_idx
= wiphy_idx
;
678 dl_list_init(&w
->bsss
);
679 dl_list_init(&w
->drvs
);
681 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
686 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
687 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
690 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
692 if (w
->nl_beacons
== NULL
) {
697 if (nl80211_register_beacons(bss
->drv
, w
)) {
698 nl_destroy_handles(&w
->nl_beacons
);
703 nl80211_register_eloop_read(&w
->nl_beacons
, nl80211_recv_beacons
, w
);
705 dl_list_add(&nl80211_wiphys
, &w
->list
);
708 /* drv entry for this bss already there? */
709 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
710 if (tmp_bss
->drv
== bss
->drv
) {
717 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
719 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
725 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
727 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
728 struct i802_bss
*tmp_bss
;
733 bss
->wiphy_data
= NULL
;
734 dl_list_del(&bss
->wiphy_list
);
736 /* still any for this drv present? */
737 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
738 if (tmp_bss
->drv
== bss
->drv
) {
743 /* if not remove it */
745 dl_list_del(&bss
->drv
->wiphy_list
);
747 if (!dl_list_empty(&w
->bsss
))
750 nl80211_destroy_eloop_handle(&w
->nl_beacons
);
753 dl_list_del(&w
->list
);
758 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
760 struct i802_bss
*bss
= priv
;
761 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
762 if (!drv
->associated
)
764 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
769 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
771 struct i802_bss
*bss
= priv
;
772 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
773 if (!drv
->associated
)
775 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
776 return drv
->ssid_len
;
780 static void wpa_driver_nl80211_event_newlink(
781 struct wpa_driver_nl80211_data
*drv
, const char *ifname
)
783 union wpa_event_data event
;
785 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
786 if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
787 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
788 drv
->first_bss
->ifname
);
791 if (!drv
->if_removed
)
793 wpa_printf(MSG_DEBUG
, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
794 drv
->first_bss
->ifname
);
798 os_memset(&event
, 0, sizeof(event
));
799 os_strlcpy(event
.interface_status
.ifname
, ifname
,
800 sizeof(event
.interface_status
.ifname
));
801 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
802 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
806 static void wpa_driver_nl80211_event_dellink(
807 struct wpa_driver_nl80211_data
*drv
, const char *ifname
)
809 union wpa_event_data event
;
811 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
812 if (drv
->if_removed
) {
813 wpa_printf(MSG_DEBUG
, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
817 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
821 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed",
825 os_memset(&event
, 0, sizeof(event
));
826 os_strlcpy(event
.interface_status
.ifname
, ifname
,
827 sizeof(event
.interface_status
.ifname
));
828 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
829 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
833 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
836 int attrlen
, rta_len
;
840 attr
= (struct rtattr
*) buf
;
842 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
843 while (RTA_OK(attr
, attrlen
)) {
844 if (attr
->rta_type
== IFLA_IFNAME
) {
845 if (os_strcmp(((char *) attr
) + rta_len
,
846 drv
->first_bss
->ifname
) == 0)
851 attr
= RTA_NEXT(attr
, attrlen
);
858 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
859 int ifindex
, u8
*buf
, size_t len
)
861 if (drv
->ifindex
== ifindex
)
864 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
865 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
867 wpa_driver_nl80211_finish_drv_init(drv
, NULL
, 0, NULL
);
875 static struct wpa_driver_nl80211_data
*
876 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
878 struct wpa_driver_nl80211_data
*drv
;
879 dl_list_for_each(drv
, &global
->interfaces
,
880 struct wpa_driver_nl80211_data
, list
) {
881 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
882 have_ifidx(drv
, idx
))
889 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
890 struct ifinfomsg
*ifi
,
893 struct nl80211_global
*global
= ctx
;
894 struct wpa_driver_nl80211_data
*drv
;
898 char namebuf
[IFNAMSIZ
];
899 char ifname
[IFNAMSIZ
+ 1];
900 char extra
[100], *pos
, *end
;
902 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
904 wpa_printf(MSG_DEBUG
, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d",
911 end
= pos
+ sizeof(extra
);
915 attr
= (struct rtattr
*) buf
;
916 while (RTA_OK(attr
, attrlen
)) {
917 switch (attr
->rta_type
) {
919 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
921 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
922 ifname
[RTA_PAYLOAD(attr
)] = '\0';
925 brid
= nla_get_u32((struct nlattr
*) attr
);
926 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
929 pos
+= os_snprintf(pos
, end
- pos
, " wext");
932 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
933 nla_get_u32((struct nlattr
*) attr
));
936 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
937 nla_get_u32((struct nlattr
*) attr
));
940 attr
= RTA_NEXT(attr
, attrlen
);
942 extra
[sizeof(extra
) - 1] = '\0';
944 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
945 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
947 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
948 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
949 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
950 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
952 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
953 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
954 linux_iface_up(drv
->global
->ioctl_sock
,
955 drv
->first_bss
->ifname
) > 0) {
956 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
957 "event since interface %s is up", namebuf
);
958 drv
->ignore_if_down_event
= 0;
961 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
962 if (drv
->ignore_if_down_event
) {
963 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
964 "event generated by mode change");
965 drv
->ignore_if_down_event
= 0;
967 drv
->if_disabled
= 1;
968 wpa_supplicant_event(drv
->ctx
,
969 EVENT_INTERFACE_DISABLED
, NULL
);
972 * Try to get drv again, since it may be removed as
973 * part of the EVENT_INTERFACE_DISABLED handling for
976 drv
= nl80211_find_drv(global
, ifi
->ifi_index
,
983 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
984 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
985 linux_iface_up(drv
->global
->ioctl_sock
,
986 drv
->first_bss
->ifname
) == 0) {
987 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
988 "event since interface %s is down",
990 } else if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
991 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
992 "event since interface %s does not exist",
993 drv
->first_bss
->ifname
);
994 } else if (drv
->if_removed
) {
995 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
996 "event since interface %s is marked "
997 "removed", drv
->first_bss
->ifname
);
999 struct i802_bss
*bss
;
1002 /* Re-read MAC address as it may have changed */
1003 bss
= get_bss_ifindex(drv
, ifi
->ifi_index
);
1005 linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
1006 bss
->ifname
, addr
) < 0) {
1007 wpa_printf(MSG_DEBUG
,
1008 "nl80211: %s: failed to re-read MAC address",
1011 os_memcmp(addr
, bss
->addr
, ETH_ALEN
) != 0) {
1012 wpa_printf(MSG_DEBUG
,
1013 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1014 MACSTR
" to " MACSTR
,
1015 ifi
->ifi_index
, bss
->ifname
,
1018 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
1021 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
1022 drv
->if_disabled
= 0;
1023 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1029 * Some drivers send the association event before the operup event--in
1030 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1031 * fails. This will hit us when wpa_supplicant does not need to do
1032 * IEEE 802.1X authentication
1034 if (drv
->operstate
== 1 &&
1035 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1036 !(ifi
->ifi_flags
& IFF_RUNNING
)) {
1037 wpa_printf(MSG_DEBUG
, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
1038 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1043 wpa_driver_nl80211_event_newlink(drv
, ifname
);
1045 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1046 struct i802_bss
*bss
;
1048 /* device has been added to bridge */
1049 if (!if_indextoname(brid
, namebuf
)) {
1050 wpa_printf(MSG_DEBUG
,
1051 "nl80211: Could not find bridge ifname for ifindex %u",
1055 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1057 add_ifidx(drv
, brid
);
1059 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
1060 if (os_strcmp(ifname
, bss
->ifname
) == 0) {
1061 os_strlcpy(bss
->brname
, namebuf
, IFNAMSIZ
);
1069 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1070 struct ifinfomsg
*ifi
,
1071 u8
*buf
, size_t len
)
1073 struct nl80211_global
*global
= ctx
;
1074 struct wpa_driver_nl80211_data
*drv
;
1076 struct rtattr
*attr
;
1078 char ifname
[IFNAMSIZ
+ 1];
1079 char extra
[100], *pos
, *end
;
1081 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1083 wpa_printf(MSG_DEBUG
, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d",
1090 end
= pos
+ sizeof(extra
);
1094 attr
= (struct rtattr
*) buf
;
1095 while (RTA_OK(attr
, attrlen
)) {
1096 switch (attr
->rta_type
) {
1098 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
1100 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
1101 ifname
[RTA_PAYLOAD(attr
)] = '\0';
1104 brid
= nla_get_u32((struct nlattr
*) attr
);
1105 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
1107 case IFLA_OPERSTATE
:
1108 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
1109 nla_get_u32((struct nlattr
*) attr
));
1112 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
1113 nla_get_u32((struct nlattr
*) attr
));
1116 attr
= RTA_NEXT(attr
, attrlen
);
1118 extra
[sizeof(extra
) - 1] = '\0';
1120 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1121 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
1123 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1124 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1125 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1126 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1128 if (ifname
[0] && (ifi
->ifi_family
!= AF_BRIDGE
|| !brid
))
1129 wpa_driver_nl80211_event_dellink(drv
, ifname
);
1131 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1132 /* device has been removed from bridge */
1133 char namebuf
[IFNAMSIZ
];
1135 if (!if_indextoname(brid
, namebuf
)) {
1136 wpa_printf(MSG_DEBUG
,
1137 "nl80211: Could not find bridge ifname for ifindex %u",
1140 wpa_printf(MSG_DEBUG
,
1141 "nl80211: Remove ifindex %u for bridge %s",
1144 del_ifidx(drv
, brid
);
1149 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1153 struct nl80211_bss_info_arg arg
;
1155 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1156 os_memset(&arg
, 0, sizeof(arg
));
1158 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1160 unsigned int freq
= drv
->nlmode
== NL80211_IFTYPE_ADHOC
?
1161 arg
.ibss_freq
: arg
.assoc_freq
;
1162 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1163 "associated BSS from scan results: %u MHz", freq
);
1165 drv
->assoc_freq
= freq
;
1166 return drv
->assoc_freq
;
1168 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1169 "(%s)", ret
, strerror(-ret
));
1170 return drv
->assoc_freq
;
1174 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1176 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1177 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1178 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1179 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1180 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1181 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
1183 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1184 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1185 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1186 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1187 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1188 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1190 struct wpa_signal_info
*sig_change
= arg
;
1192 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1193 genlmsg_attrlen(gnlh
, 0), NULL
);
1194 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1195 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1196 tb
[NL80211_ATTR_STA_INFO
], policy
))
1198 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1201 sig_change
->current_signal
=
1202 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1204 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
1205 sig_change
->avg_signal
=
1206 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
1208 sig_change
->avg_signal
= 0;
1210 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1211 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1212 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1214 sig_change
->current_txrate
= 0;
1216 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1217 sig_change
->current_txrate
=
1219 NL80211_RATE_INFO_BITRATE
]) * 100;
1228 int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1229 struct wpa_signal_info
*sig
)
1233 sig
->current_signal
= -9999;
1234 sig
->current_txrate
= 0;
1236 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_STATION
)) ||
1237 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
)) {
1242 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1246 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1248 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1249 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1250 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1251 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1252 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1253 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1255 struct wpa_signal_info
*sig_change
= arg
;
1257 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1258 genlmsg_attrlen(gnlh
, 0), NULL
);
1260 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1261 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1265 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1266 tb
[NL80211_ATTR_SURVEY_INFO
],
1268 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1273 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1276 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1277 sig_change
->frequency
)
1280 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1283 sig_change
->current_noise
=
1284 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1290 int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1291 struct wpa_signal_info
*sig_change
)
1295 sig_change
->current_noise
= 9999;
1296 sig_change
->frequency
= drv
->assoc_freq
;
1298 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1299 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1303 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
1306 struct nl_cb
*cb
= eloop_ctx
;
1309 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
1311 res
= nl_recvmsgs(handle
, cb
);
1313 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
1320 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1321 * @priv: driver_nl80211 private data
1322 * @alpha2_arg: country to which to switch to
1323 * Returns: 0 on success, -1 on failure
1325 * This asks nl80211 to set the regulatory domain for given
1326 * country ISO / IEC alpha2.
1328 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
1330 struct i802_bss
*bss
= priv
;
1331 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1335 msg
= nlmsg_alloc();
1339 alpha2
[0] = alpha2_arg
[0];
1340 alpha2
[1] = alpha2_arg
[1];
1343 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
) ||
1344 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
)) {
1348 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
1354 static int nl80211_get_country(struct nl_msg
*msg
, void *arg
)
1357 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
1358 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1360 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1361 genlmsg_attrlen(gnlh
, 0), NULL
);
1362 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
]) {
1363 wpa_printf(MSG_DEBUG
, "nl80211: No country information available");
1366 os_strlcpy(alpha2
, nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]), 3);
1371 static int wpa_driver_nl80211_get_country(void *priv
, char *alpha2
)
1373 struct i802_bss
*bss
= priv
;
1374 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1378 msg
= nlmsg_alloc();
1382 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
1384 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_country
, alpha2
);
1392 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
1396 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1397 if (global
->nl_cb
== NULL
) {
1398 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
1403 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
1404 if (global
->nl
== NULL
)
1407 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
1408 if (global
->nl80211_id
< 0) {
1409 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
1414 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
1415 if (global
->nl_event
== NULL
)
1418 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
1420 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1422 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1423 "membership for scan events: %d (%s)",
1424 ret
, strerror(-ret
));
1428 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
1430 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1432 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1433 "membership for mlme events: %d (%s)",
1434 ret
, strerror(-ret
));
1438 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
1440 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1442 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1443 "membership for regulatory events: %d (%s)",
1444 ret
, strerror(-ret
));
1445 /* Continue without regulatory events */
1448 ret
= nl_get_multicast_id(global
, "nl80211", "vendor");
1450 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1452 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1453 "membership for vendor events: %d (%s)",
1454 ret
, strerror(-ret
));
1455 /* Continue without vendor events */
1458 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1459 no_seq_check
, NULL
);
1460 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1461 process_global_event
, global
);
1463 nl80211_register_eloop_read(&global
->nl_event
,
1464 wpa_driver_nl80211_event_receive
,
1470 nl_destroy_handles(&global
->nl_event
);
1471 nl_destroy_handles(&global
->nl
);
1472 nl_cb_put(global
->nl_cb
);
1473 global
->nl_cb
= NULL
;
1478 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
1480 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
1482 * This may be for any interface; use ifdown event to disable
1488 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
1490 struct wpa_driver_nl80211_data
*drv
= ctx
;
1491 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
1492 if (i802_set_iface_flags(drv
->first_bss
, 1)) {
1493 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
1494 "after rfkill unblock");
1497 /* rtnetlink ifup handler will report interface as enabled */
1501 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
1505 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
1510 struct cmsghdr
*cmsg
;
1511 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
1512 union wpa_event_data event
;
1514 memset(&msg
, 0, sizeof(msg
));
1515 msg
.msg_iov
= &entry
;
1517 entry
.iov_base
= data
;
1518 entry
.iov_len
= sizeof(data
);
1519 msg
.msg_control
= &control
;
1520 msg
.msg_controllen
= sizeof(control
);
1522 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
1523 /* if error or not fitting 802.3 header, return */
1527 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
1529 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
1530 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
1534 ack
= (void *)CMSG_DATA(cmsg
);
1538 if (cmsg
->cmsg_level
== SOL_PACKET
&&
1539 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
1540 struct sock_extended_err
*err
=
1541 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
1543 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
1548 if (!found_ee
|| !found_wifi
)
1551 memset(&event
, 0, sizeof(event
));
1552 event
.eapol_tx_status
.dst
= data
;
1553 event
.eapol_tx_status
.data
= data
+ 14;
1554 event
.eapol_tx_status
.data_len
= res
- 14;
1555 event
.eapol_tx_status
.ack
= acked
;
1556 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
1560 static int nl80211_init_bss(struct i802_bss
*bss
)
1562 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1566 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1567 no_seq_check
, NULL
);
1568 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1569 process_bss_event
, bss
);
1575 static void nl80211_destroy_bss(struct i802_bss
*bss
)
1577 nl_cb_put(bss
->nl_cb
);
1582 static void * wpa_driver_nl80211_drv_init(void *ctx
, const char *ifname
,
1583 void *global_priv
, int hostapd
,
1585 const char *driver_params
)
1587 struct wpa_driver_nl80211_data
*drv
;
1588 struct rfkill_config
*rcfg
;
1589 struct i802_bss
*bss
;
1591 if (global_priv
== NULL
)
1593 drv
= os_zalloc(sizeof(*drv
));
1596 drv
->global
= global_priv
;
1598 drv
->hostapd
= !!hostapd
;
1599 drv
->eapol_sock
= -1;
1602 * There is no driver capability flag for this, so assume it is
1603 * supported and disable this on first attempt to use if the driver
1604 * rejects the command due to missing support.
1606 drv
->set_rekey_offload
= 1;
1608 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
1609 drv
->if_indices
= drv
->default_if_indices
;
1611 drv
->first_bss
= os_zalloc(sizeof(*drv
->first_bss
));
1612 if (!drv
->first_bss
) {
1616 bss
= drv
->first_bss
;
1620 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
1621 drv
->monitor_ifidx
= -1;
1622 drv
->monitor_sock
= -1;
1623 drv
->eapol_tx_sock
= -1;
1624 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
1626 if (nl80211_init_bss(bss
))
1629 rcfg
= os_zalloc(sizeof(*rcfg
));
1633 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
1634 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
1635 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
1636 drv
->rfkill
= rfkill_init(rcfg
);
1637 if (drv
->rfkill
== NULL
) {
1638 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
1642 if (linux_iface_up(drv
->global
->ioctl_sock
, ifname
) > 0)
1643 drv
->start_iface_up
= 1;
1645 if (wpa_driver_nl80211_finish_drv_init(drv
, set_addr
, 1, driver_params
))
1648 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
1649 if (drv
->eapol_tx_sock
< 0)
1652 if (drv
->data_tx_status
) {
1655 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
1656 &enabled
, sizeof(enabled
)) < 0) {
1657 wpa_printf(MSG_DEBUG
,
1658 "nl80211: wifi status sockopt failed\n");
1659 drv
->data_tx_status
= 0;
1660 if (!drv
->use_monitor
)
1662 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
1664 eloop_register_read_sock(drv
->eapol_tx_sock
,
1665 wpa_driver_nl80211_handle_eapol_tx_status
,
1671 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
1672 drv
->in_interface_list
= 1;
1678 wpa_driver_nl80211_deinit(bss
);
1684 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1685 * @ctx: context to be used when calling wpa_supplicant functions,
1686 * e.g., wpa_supplicant_event()
1687 * @ifname: interface name, e.g., wlan0
1688 * @global_priv: private driver global data from global_init()
1689 * Returns: Pointer to private data, %NULL on failure
1691 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
1694 return wpa_driver_nl80211_drv_init(ctx
, ifname
, global_priv
, 0, NULL
,
1699 static int nl80211_register_frame(struct i802_bss
*bss
,
1700 struct nl_handle
*nl_handle
,
1701 u16 type
, const u8
*match
, size_t match_len
)
1703 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1709 wpa_snprintf_hex(buf
, sizeof(buf
), match
, match_len
);
1710 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1711 type
, fc2str(type
), nl_handle
, buf
);
1713 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REGISTER_ACTION
)) ||
1714 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
, type
) ||
1715 nla_put(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
)) {
1720 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
1722 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
1723 "failed (type=%u): ret=%d (%s)",
1724 type
, ret
, strerror(-ret
));
1725 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
1732 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
1735 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
1736 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
1740 bss
->nl_mgmt
= nl_create_handle(bss
->nl_cb
, "mgmt");
1741 if (bss
->nl_mgmt
== NULL
)
1748 static void nl80211_mgmt_handle_register_eloop(struct i802_bss
*bss
)
1750 nl80211_register_eloop_read(&bss
->nl_mgmt
,
1751 wpa_driver_nl80211_event_receive
,
1756 static int nl80211_register_action_frame(struct i802_bss
*bss
,
1757 const u8
*match
, size_t match_len
)
1759 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
1760 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
1761 type
, match
, match_len
);
1765 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
1767 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1770 if (nl80211_alloc_mgmt_handle(bss
))
1772 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
1773 "handle %p", bss
->nl_mgmt
);
1775 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
1776 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
1778 /* register for any AUTH message */
1779 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0);
1782 #ifdef CONFIG_INTERWORKING
1783 /* QoS Map Configure */
1784 if (nl80211_register_action_frame(bss
, (u8
*) "\x01\x04", 2) < 0)
1786 #endif /* CONFIG_INTERWORKING */
1787 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
1788 /* GAS Initial Request */
1789 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
1791 /* GAS Initial Response */
1792 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
1794 /* GAS Comeback Request */
1795 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
1797 /* GAS Comeback Response */
1798 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
1800 /* Protected GAS Initial Request */
1801 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0a", 2) < 0)
1803 /* Protected GAS Initial Response */
1804 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0b", 2) < 0)
1806 /* Protected GAS Comeback Request */
1807 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0c", 2) < 0)
1809 /* Protected GAS Comeback Response */
1810 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0d", 2) < 0)
1812 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
1814 /* P2P Public Action */
1815 if (nl80211_register_action_frame(bss
,
1816 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
1820 if (nl80211_register_action_frame(bss
,
1821 (u8
*) "\x7f\x50\x6f\x9a\x09",
1824 #endif /* CONFIG_P2P */
1825 #ifdef CONFIG_IEEE80211W
1826 /* SA Query Response */
1827 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
1829 #endif /* CONFIG_IEEE80211W */
1831 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
1832 /* TDLS Discovery Response */
1833 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
1837 #endif /* CONFIG_TDLS */
1839 /* FT Action frames */
1840 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
1843 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
1844 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
1846 /* WNM - BSS Transition Management Request */
1847 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
1849 /* WNM-Sleep Mode Response */
1850 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
1854 /* WNM-Notification */
1855 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x1a", 2) < 0)
1857 #endif /* CONFIG_HS20 */
1859 /* WMM-AC ADDTS Response */
1860 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x01", 2) < 0)
1864 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x02", 2) < 0)
1867 /* Radio Measurement - Neighbor Report Response */
1868 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x05", 2) < 0)
1871 /* Radio Measurement - Link Measurement Request */
1872 if ((drv
->capa
.rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
) &&
1873 (nl80211_register_action_frame(bss
, (u8
*) "\x05\x02", 2) < 0))
1876 nl80211_mgmt_handle_register_eloop(bss
);
1882 static int nl80211_mgmt_subscribe_mesh(struct i802_bss
*bss
)
1886 if (nl80211_alloc_mgmt_handle(bss
))
1889 wpa_printf(MSG_DEBUG
,
1890 "nl80211: Subscribe to mgmt frames with mesh handle %p",
1893 /* Auth frames for mesh SAE */
1894 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
1895 (WLAN_FC_TYPE_MGMT
<< 2) |
1896 (WLAN_FC_STYPE_AUTH
<< 4),
1900 /* Mesh peering open */
1901 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x01", 2) < 0)
1903 /* Mesh peering confirm */
1904 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x02", 2) < 0)
1906 /* Mesh peering close */
1907 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x03", 2) < 0)
1910 nl80211_mgmt_handle_register_eloop(bss
);
1916 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
1921 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
1922 ret
= send_and_recv(bss
->drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
1924 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
1925 "failed: ret=%d (%s)",
1926 ret
, strerror(-ret
));
1932 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
1934 static const int stypes
[] = {
1936 WLAN_FC_STYPE_ASSOC_REQ
,
1937 WLAN_FC_STYPE_REASSOC_REQ
,
1938 WLAN_FC_STYPE_DISASSOC
,
1939 WLAN_FC_STYPE_DEAUTH
,
1940 WLAN_FC_STYPE_ACTION
,
1941 WLAN_FC_STYPE_PROBE_REQ
,
1942 /* Beacon doesn't work as mac80211 doesn't currently allow
1943 * it, but it wouldn't really be the right thing anyway as
1944 * it isn't per interface ... maybe just dump the scan
1945 * results periodically for OLBC?
1947 /* WLAN_FC_STYPE_BEACON, */
1951 if (nl80211_alloc_mgmt_handle(bss
))
1953 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
1954 "handle %p", bss
->nl_mgmt
);
1956 for (i
= 0; i
< ARRAY_SIZE(stypes
); i
++) {
1957 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
1958 (WLAN_FC_TYPE_MGMT
<< 2) |
1965 if (nl80211_register_spurious_class3(bss
))
1968 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
1971 nl80211_mgmt_handle_register_eloop(bss
);
1975 nl_destroy_handles(&bss
->nl_mgmt
);
1980 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
1982 if (nl80211_alloc_mgmt_handle(bss
))
1984 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
1985 "handle %p (device SME)", bss
->nl_mgmt
);
1987 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
1988 (WLAN_FC_TYPE_MGMT
<< 2) |
1989 (WLAN_FC_STYPE_ACTION
<< 4),
1993 nl80211_mgmt_handle_register_eloop(bss
);
1997 nl_destroy_handles(&bss
->nl_mgmt
);
2002 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
2004 if (bss
->nl_mgmt
== NULL
)
2006 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
2007 "(%s)", bss
->nl_mgmt
, reason
);
2008 nl80211_destroy_eloop_handle(&bss
->nl_mgmt
);
2010 nl80211_put_wiphy_data_ap(bss
);
2014 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
2016 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
2020 static void nl80211_del_p2pdev(struct i802_bss
*bss
)
2025 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_INTERFACE
);
2026 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2028 wpa_printf(MSG_DEBUG
, "nl80211: Delete P2P Device %s (0x%llx): %s",
2029 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2034 static int nl80211_set_p2pdev(struct i802_bss
*bss
, int start
)
2039 msg
= nl80211_cmd_msg(bss
, 0, start
? NL80211_CMD_START_P2P_DEVICE
:
2040 NL80211_CMD_STOP_P2P_DEVICE
);
2041 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2043 wpa_printf(MSG_DEBUG
, "nl80211: %s P2P Device %s (0x%llx): %s",
2044 start
? "Start" : "Stop",
2045 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2051 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
)
2053 enum nl80211_iftype nlmode
;
2055 nlmode
= nl80211_get_ifmode(bss
);
2056 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2057 return linux_set_iface_flags(bss
->drv
->global
->ioctl_sock
,
2061 /* P2P Device has start/stop which is equivalent */
2062 return nl80211_set_p2pdev(bss
, up
);
2067 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
2068 const u8
*set_addr
, int first
,
2069 const char *driver_params
)
2071 struct i802_bss
*bss
= drv
->first_bss
;
2072 int send_rfkill_event
= 0;
2073 enum nl80211_iftype nlmode
;
2075 drv
->ifindex
= if_nametoindex(bss
->ifname
);
2076 bss
->ifindex
= drv
->ifindex
;
2077 bss
->wdev_id
= drv
->global
->if_add_wdevid
;
2078 bss
->wdev_id_set
= drv
->global
->if_add_wdevid_set
;
2080 bss
->if_dynamic
= drv
->ifindex
== drv
->global
->if_add_ifindex
;
2081 bss
->if_dynamic
= bss
->if_dynamic
|| drv
->global
->if_add_wdevid_set
;
2082 drv
->global
->if_add_wdevid_set
= 0;
2084 if (!bss
->if_dynamic
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2087 if (wpa_driver_nl80211_capa(drv
))
2090 if (driver_params
&& nl80211_set_param(bss
, driver_params
) < 0)
2093 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2094 bss
->ifname
, drv
->phyname
);
2097 (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) ||
2098 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2102 if (first
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2103 drv
->start_mode_ap
= 1;
2105 if (drv
->hostapd
|| bss
->static_ap
)
2106 nlmode
= NL80211_IFTYPE_AP
;
2107 else if (bss
->if_dynamic
)
2108 nlmode
= nl80211_get_ifmode(bss
);
2110 nlmode
= NL80211_IFTYPE_STATION
;
2112 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
2113 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver mode");
2117 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2118 nl80211_get_macaddr(bss
);
2120 if (!rfkill_is_blocked(drv
->rfkill
)) {
2121 int ret
= i802_set_iface_flags(bss
, 1);
2123 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
2124 "interface '%s' UP", bss
->ifname
);
2127 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2130 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
2131 "interface '%s' due to rfkill", bss
->ifname
);
2132 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2134 drv
->if_disabled
= 1;
2135 send_rfkill_event
= 1;
2139 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
2140 1, IF_OPER_DORMANT
);
2142 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2145 os_memcpy(drv
->perm_addr
, bss
->addr
, ETH_ALEN
);
2147 if (send_rfkill_event
) {
2148 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
2156 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
2160 wpa_printf(MSG_DEBUG
, "nl80211: Remove beacon (ifindex=%d)",
2162 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_DEL_BEACON
);
2163 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2168 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2169 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2171 * Shut down driver interface and processing of driver events. Free
2172 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2174 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
2176 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2178 wpa_printf(MSG_INFO
, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2179 bss
->ifname
, drv
->disabled_11b_rates
);
2182 if (drv
->data_tx_status
)
2183 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
2184 if (drv
->eapol_tx_sock
>= 0)
2185 close(drv
->eapol_tx_sock
);
2188 wpa_driver_nl80211_probe_req_report(bss
, 0);
2189 if (bss
->added_if_into_bridge
) {
2190 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
2192 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2193 "interface %s from bridge %s: %s",
2194 bss
->ifname
, bss
->brname
, strerror(errno
));
2196 nl80211_handle_destroy(drv
->rtnl_sk
);
2198 if (bss
->added_bridge
) {
2199 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->brname
,
2201 wpa_printf(MSG_INFO
,
2202 "nl80211: Could not set bridge %s down",
2204 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
2205 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2207 bss
->brname
, strerror(errno
));
2210 nl80211_remove_monitor_interface(drv
);
2212 if (is_ap_interface(drv
->nlmode
))
2213 wpa_driver_nl80211_del_beacon(drv
);
2215 if (drv
->eapol_sock
>= 0) {
2216 eloop_unregister_read_sock(drv
->eapol_sock
);
2217 close(drv
->eapol_sock
);
2220 if (drv
->if_indices
!= drv
->default_if_indices
)
2221 os_free(drv
->if_indices
);
2223 if (drv
->disabled_11b_rates
)
2224 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2226 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
2228 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill
, drv
, drv
->ctx
);
2229 rfkill_deinit(drv
->rfkill
);
2231 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2233 if (!drv
->start_iface_up
)
2234 (void) i802_set_iface_flags(bss
, 0);
2236 if (drv
->addr_changed
) {
2237 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
2239 wpa_printf(MSG_DEBUG
,
2240 "nl80211: Could not set interface down to restore permanent MAC address");
2242 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2243 drv
->perm_addr
) < 0) {
2244 wpa_printf(MSG_DEBUG
,
2245 "nl80211: Could not restore permanent MAC address");
2249 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2250 if (!drv
->hostapd
|| !drv
->start_mode_ap
)
2251 wpa_driver_nl80211_set_mode(bss
,
2252 NL80211_IFTYPE_STATION
);
2253 nl80211_mgmt_unsubscribe(bss
, "deinit");
2255 nl80211_mgmt_unsubscribe(bss
, "deinit");
2256 nl80211_del_p2pdev(bss
);
2259 nl80211_destroy_bss(drv
->first_bss
);
2261 os_free(drv
->filter_ssids
);
2263 os_free(drv
->auth_ie
);
2265 if (drv
->in_interface_list
)
2266 dl_list_del(&drv
->list
);
2268 os_free(drv
->extended_capa
);
2269 os_free(drv
->extended_capa_mask
);
2270 os_free(drv
->first_bss
);
2275 static u32
wpa_alg_to_cipher_suite(enum wpa_alg alg
, size_t key_len
)
2280 return WLAN_CIPHER_SUITE_WEP40
;
2281 return WLAN_CIPHER_SUITE_WEP104
;
2283 return WLAN_CIPHER_SUITE_TKIP
;
2285 return WLAN_CIPHER_SUITE_CCMP
;
2287 return WLAN_CIPHER_SUITE_GCMP
;
2288 case WPA_ALG_CCMP_256
:
2289 return WLAN_CIPHER_SUITE_CCMP_256
;
2290 case WPA_ALG_GCMP_256
:
2291 return WLAN_CIPHER_SUITE_GCMP_256
;
2293 return WLAN_CIPHER_SUITE_AES_CMAC
;
2294 case WPA_ALG_BIP_GMAC_128
:
2295 return WLAN_CIPHER_SUITE_BIP_GMAC_128
;
2296 case WPA_ALG_BIP_GMAC_256
:
2297 return WLAN_CIPHER_SUITE_BIP_GMAC_256
;
2298 case WPA_ALG_BIP_CMAC_256
:
2299 return WLAN_CIPHER_SUITE_BIP_CMAC_256
;
2301 return WLAN_CIPHER_SUITE_SMS4
;
2303 return WLAN_CIPHER_SUITE_KRK
;
2306 wpa_printf(MSG_ERROR
, "nl80211: Unexpected encryption algorithm %d",
2311 wpa_printf(MSG_ERROR
, "nl80211: Unsupported encryption algorithm %d",
2317 static u32
wpa_cipher_to_cipher_suite(unsigned int cipher
)
2320 case WPA_CIPHER_CCMP_256
:
2321 return WLAN_CIPHER_SUITE_CCMP_256
;
2322 case WPA_CIPHER_GCMP_256
:
2323 return WLAN_CIPHER_SUITE_GCMP_256
;
2324 case WPA_CIPHER_CCMP
:
2325 return WLAN_CIPHER_SUITE_CCMP
;
2326 case WPA_CIPHER_GCMP
:
2327 return WLAN_CIPHER_SUITE_GCMP
;
2328 case WPA_CIPHER_TKIP
:
2329 return WLAN_CIPHER_SUITE_TKIP
;
2330 case WPA_CIPHER_WEP104
:
2331 return WLAN_CIPHER_SUITE_WEP104
;
2332 case WPA_CIPHER_WEP40
:
2333 return WLAN_CIPHER_SUITE_WEP40
;
2334 case WPA_CIPHER_GTK_NOT_USED
:
2335 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR
;
2342 static int wpa_cipher_to_cipher_suites(unsigned int ciphers
, u32 suites
[],
2347 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP_256
)
2348 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP_256
;
2349 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP_256
)
2350 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP_256
;
2351 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP
)
2352 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
2353 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP
)
2354 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP
;
2355 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_TKIP
)
2356 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
2357 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP104
)
2358 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
2359 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP40
)
2360 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
2366 static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data
*drv
,
2367 const u8
*key
, size_t key_len
)
2372 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
))
2375 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2376 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2377 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2378 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY
) ||
2379 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, key_len
, key
)) {
2380 nl80211_nlmsg_clear(msg
);
2384 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
2386 wpa_printf(MSG_DEBUG
,
2387 "nl80211: Key management set key failed: ret=%d (%s)",
2388 ret
, strerror(-ret
));
2395 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
2396 enum wpa_alg alg
, const u8
*addr
,
2397 int key_idx
, int set_tx
,
2398 const u8
*seq
, size_t seq_len
,
2399 const u8
*key
, size_t key_len
)
2401 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2407 /* Ignore for P2P Device */
2408 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2411 ifindex
= if_nametoindex(ifname
);
2412 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
2413 "set_tx=%d seq_len=%lu key_len=%lu",
2414 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
2415 (unsigned long) seq_len
, (unsigned long) key_len
);
2417 if (key_idx
== -1) {
2421 #endif /* CONFIG_TDLS */
2423 if (alg
== WPA_ALG_PMK
&&
2424 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
)) {
2425 wpa_printf(MSG_DEBUG
, "%s: calling issue_key_mgmt_set_key",
2427 ret
= issue_key_mgmt_set_key(drv
, key
, key_len
);
2431 if (alg
== WPA_ALG_NONE
) {
2432 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_DEL_KEY
);
2436 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_NEW_KEY
);
2438 nla_put(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
) ||
2439 nla_put_u32(msg
, NL80211_ATTR_KEY_CIPHER
,
2440 wpa_alg_to_cipher_suite(alg
, key_len
)))
2442 wpa_hexdump_key(MSG_DEBUG
, "nl80211: KEY_DATA", key
, key_len
);
2445 if (seq
&& seq_len
) {
2446 if (nla_put(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
))
2448 wpa_hexdump(MSG_DEBUG
, "nl80211: KEY_SEQ", seq
, seq_len
);
2451 if (addr
&& !is_broadcast_ether_addr(addr
)) {
2452 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
2453 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
2456 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
2457 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
2458 if (nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
,
2459 NL80211_KEYTYPE_GROUP
))
2462 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
2463 struct nlattr
*types
;
2465 wpa_printf(MSG_DEBUG
, " broadcast key");
2467 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2469 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2471 nla_nest_end(msg
, types
);
2473 if (nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2476 ret
= send_and_recv_msgs(drv
, msg
, NULL
, key
? (void *) -1 : NULL
);
2477 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
2480 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
2481 ret
, strerror(-ret
));
2484 * If we failed or don't need to set the default TX key (below),
2487 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
|| tdls
)
2489 if (is_ap_interface(drv
->nlmode
) && addr
&&
2490 !is_broadcast_ether_addr(addr
))
2493 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_SET_KEY
);
2495 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
) ||
2496 nla_put_flag(msg
, (alg
== WPA_ALG_IGTK
||
2497 alg
== WPA_ALG_BIP_GMAC_128
||
2498 alg
== WPA_ALG_BIP_GMAC_256
||
2499 alg
== WPA_ALG_BIP_CMAC_256
) ?
2500 NL80211_ATTR_KEY_DEFAULT_MGMT
:
2501 NL80211_ATTR_KEY_DEFAULT
))
2503 if (addr
&& is_broadcast_ether_addr(addr
)) {
2504 struct nlattr
*types
;
2506 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2508 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2510 nla_nest_end(msg
, types
);
2512 struct nlattr
*types
;
2514 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2516 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
))
2518 nla_nest_end(msg
, types
);
2521 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2525 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
2526 "err=%d %s)", ret
, strerror(-ret
));
2530 nl80211_nlmsg_clear(msg
);
2536 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
2537 int key_idx
, int defkey
,
2538 const u8
*seq
, size_t seq_len
,
2539 const u8
*key
, size_t key_len
)
2541 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
2545 if (defkey
&& alg
== WPA_ALG_IGTK
) {
2546 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT_MGMT
))
2548 } else if (defkey
) {
2549 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT
))
2553 if (nla_put_u8(msg
, NL80211_KEY_IDX
, key_idx
) ||
2554 nla_put_u32(msg
, NL80211_KEY_CIPHER
,
2555 wpa_alg_to_cipher_suite(alg
, key_len
)) ||
2557 nla_put(msg
, NL80211_KEY_SEQ
, seq_len
, seq
)) ||
2558 nla_put(msg
, NL80211_KEY_DATA
, key_len
, key
))
2561 nla_nest_end(msg
, key_attr
);
2567 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
2571 struct nlattr
*nl_keys
, *nl_key
;
2573 for (i
= 0; i
< 4; i
++) {
2574 if (!params
->wep_key
[i
])
2579 if (params
->wps
== WPS_MODE_PRIVACY
)
2581 if (params
->pairwise_suite
&&
2582 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
2588 if (nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
2591 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
2595 for (i
= 0; i
< 4; i
++) {
2596 if (!params
->wep_key
[i
])
2599 nl_key
= nla_nest_start(msg
, i
);
2601 nla_put(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
2602 params
->wep_key
[i
]) ||
2603 nla_put_u32(msg
, NL80211_KEY_CIPHER
,
2604 params
->wep_key_len
[i
] == 5 ?
2605 WLAN_CIPHER_SUITE_WEP40
:
2606 WLAN_CIPHER_SUITE_WEP104
) ||
2607 nla_put_u8(msg
, NL80211_KEY_IDX
, i
) ||
2608 (i
== params
->wep_tx_keyidx
&&
2609 nla_put_flag(msg
, NL80211_KEY_DEFAULT
)))
2612 nla_nest_end(msg
, nl_key
);
2614 nla_nest_end(msg
, nl_keys
);
2620 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
2621 const u8
*addr
, int cmd
, u16 reason_code
,
2622 int local_state_change
)
2627 if (!(msg
= nl80211_drv_msg(drv
, 0, cmd
)) ||
2628 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
) ||
2629 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
2630 (local_state_change
&&
2631 nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))) {
2636 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2638 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2639 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
2640 reason_code
, ret
, strerror(-ret
));
2646 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
2651 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
2652 nl80211_mark_disconnected(drv
);
2653 /* Disconnect command doesn't need BSSID - it uses cached value */
2654 ret
= wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
2657 * For locally generated disconnect, supplicant already generates a
2658 * DEAUTH event, so ignore the event from NL80211.
2660 drv
->ignore_next_local_disconnect
= ret
== 0;
2666 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
2667 const u8
*addr
, int reason_code
)
2669 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2672 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
2673 nl80211_mark_disconnected(drv
);
2674 return nl80211_leave_ibss(drv
, 1);
2676 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
2677 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
2678 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
2679 __func__
, MAC2STR(addr
), reason_code
);
2680 nl80211_mark_disconnected(drv
);
2681 ret
= wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
2684 * For locally generated deauthenticate, supplicant already generates a
2685 * DEAUTH event, so ignore the event from NL80211.
2687 drv
->ignore_next_local_deauth
= ret
== 0;
2692 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
2693 struct wpa_driver_auth_params
*params
)
2697 drv
->auth_freq
= params
->freq
;
2698 drv
->auth_alg
= params
->auth_alg
;
2699 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
2700 drv
->auth_local_state_change
= params
->local_state_change
;
2701 drv
->auth_p2p
= params
->p2p
;
2704 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
2706 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
2709 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
2710 drv
->auth_ssid_len
= params
->ssid_len
;
2712 drv
->auth_ssid_len
= 0;
2715 os_free(drv
->auth_ie
);
2716 drv
->auth_ie
= NULL
;
2717 drv
->auth_ie_len
= 0;
2719 drv
->auth_ie
= os_malloc(params
->ie_len
);
2721 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
2722 drv
->auth_ie_len
= params
->ie_len
;
2726 for (i
= 0; i
< 4; i
++) {
2727 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
2728 params
->wep_key_len
[i
] <= 16) {
2729 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
2730 params
->wep_key_len
[i
]);
2731 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
2733 drv
->auth_wep_key_len
[i
] = 0;
2738 static void nl80211_unmask_11b_rates(struct i802_bss
*bss
)
2740 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2742 if (is_p2p_net_interface(drv
->nlmode
) || !drv
->disabled_11b_rates
)
2746 * Looks like we failed to unmask 11b rates previously. This could
2747 * happen, e.g., if the interface was down at the point in time when a
2748 * P2P group was terminated.
2750 wpa_printf(MSG_DEBUG
,
2751 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
2753 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2757 static int wpa_driver_nl80211_authenticate(
2758 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
2760 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2763 enum nl80211_auth_type type
;
2764 enum nl80211_iftype nlmode
;
2768 nl80211_unmask_11b_rates(bss
);
2770 is_retry
= drv
->retry_auth
;
2771 drv
->retry_auth
= 0;
2772 drv
->ignore_deauth_event
= 0;
2774 nl80211_mark_disconnected(drv
);
2775 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
2777 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
2779 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
2780 /* FIX: IBSS mode */
2781 nlmode
= params
->p2p
?
2782 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
2783 if (drv
->nlmode
!= nlmode
&&
2784 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
2788 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
2791 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_AUTHENTICATE
);
2795 for (i
= 0; i
< 4; i
++) {
2796 if (!params
->wep_key
[i
])
2798 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
2800 i
== params
->wep_tx_keyidx
, NULL
, 0,
2802 params
->wep_key_len
[i
]);
2803 if (params
->wep_tx_keyidx
!= i
)
2805 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
2806 params
->wep_key
[i
], params
->wep_key_len
[i
]))
2810 if (params
->bssid
) {
2811 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
2812 MAC2STR(params
->bssid
));
2813 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
2817 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
2818 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
))
2822 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
2823 params
->ssid
, params
->ssid_len
);
2824 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
2828 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
2830 nla_put(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
))
2832 if (params
->sae_data
) {
2833 wpa_hexdump(MSG_DEBUG
, " * SAE data", params
->sae_data
,
2834 params
->sae_data_len
);
2835 if (nla_put(msg
, NL80211_ATTR_SAE_DATA
, params
->sae_data_len
,
2839 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
2840 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
2841 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
2842 type
= NL80211_AUTHTYPE_SHARED_KEY
;
2843 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
2844 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
2845 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
2846 type
= NL80211_AUTHTYPE_FT
;
2847 else if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
2848 type
= NL80211_AUTHTYPE_SAE
;
2851 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
2852 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
2854 if (params
->local_state_change
) {
2855 wpa_printf(MSG_DEBUG
, " * Local state change only");
2856 if (nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))
2860 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2863 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2864 "nl80211: MLME command failed (auth): ret=%d (%s)",
2865 ret
, strerror(-ret
));
2867 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
2868 !params
->local_state_change
) {
2870 * mac80211 does not currently accept new
2871 * authentication if we are already authenticated. As a
2872 * workaround, force deauthentication and try again.
2874 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
2875 "after forced deauthentication");
2876 drv
->ignore_deauth_event
= 1;
2877 wpa_driver_nl80211_deauthenticate(
2879 WLAN_REASON_PREV_AUTH_NOT_VALID
);
2884 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
2886 * cfg80211 has likely expired the BSS entry even
2887 * though it was previously available in our internal
2888 * BSS table. To recover quickly, start a single
2889 * channel scan on the specified channel.
2891 struct wpa_driver_scan_params scan
;
2894 os_memset(&scan
, 0, sizeof(scan
));
2897 scan
.ssids
[0].ssid
= params
->ssid
;
2898 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
2900 freqs
[0] = params
->freq
;
2903 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
2904 "channel scan to refresh cfg80211 BSS "
2906 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
2908 nl80211_copy_auth_params(drv
, params
);
2909 drv
->scan_for_auth
= 1;
2911 } else if (is_retry
) {
2913 * Need to indicate this with an event since the return
2914 * value from the retry is not delivered to core code.
2916 union wpa_event_data event
;
2917 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
2919 os_memset(&event
, 0, sizeof(event
));
2920 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
2922 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
2926 wpa_printf(MSG_DEBUG
,
2927 "nl80211: Authentication request send successfully");
2936 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data
*drv
)
2938 struct wpa_driver_auth_params params
;
2939 struct i802_bss
*bss
= drv
->first_bss
;
2942 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
2944 os_memset(¶ms
, 0, sizeof(params
));
2945 params
.freq
= drv
->auth_freq
;
2946 params
.auth_alg
= drv
->auth_alg
;
2947 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
2948 params
.local_state_change
= drv
->auth_local_state_change
;
2949 params
.p2p
= drv
->auth_p2p
;
2951 if (!is_zero_ether_addr(drv
->auth_bssid_
))
2952 params
.bssid
= drv
->auth_bssid_
;
2954 if (drv
->auth_ssid_len
) {
2955 params
.ssid
= drv
->auth_ssid
;
2956 params
.ssid_len
= drv
->auth_ssid_len
;
2959 params
.ie
= drv
->auth_ie
;
2960 params
.ie_len
= drv
->auth_ie_len
;
2962 for (i
= 0; i
< 4; i
++) {
2963 if (drv
->auth_wep_key_len
[i
]) {
2964 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
2965 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
2969 drv
->retry_auth
= 1;
2970 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
2974 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
2975 const void *data
, size_t len
,
2976 int encrypt
, int noack
,
2977 unsigned int freq
, int no_cck
,
2978 int offchanok
, unsigned int wait_time
)
2980 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2984 if (freq
== 0 && drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
2985 freq
= nl80211_get_assoc_freq(drv
);
2986 wpa_printf(MSG_DEBUG
,
2987 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
2991 wpa_printf(MSG_DEBUG
, "nl80211: send_frame - Use bss->freq=%u",
2996 if (drv
->use_monitor
) {
2997 wpa_printf(MSG_DEBUG
, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
2999 return nl80211_send_monitor(drv
, data
, len
, encrypt
, noack
);
3002 wpa_printf(MSG_DEBUG
, "nl80211: send_frame -> send_frame_cmd");
3003 res
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
3004 &cookie
, no_cck
, noack
, offchanok
);
3005 if (res
== 0 && !noack
) {
3006 const struct ieee80211_mgmt
*mgmt
;
3009 mgmt
= (const struct ieee80211_mgmt
*) data
;
3010 fc
= le_to_host16(mgmt
->frame_control
);
3011 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3012 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_ACTION
) {
3013 wpa_printf(MSG_MSGDUMP
,
3014 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3015 (long long unsigned int)
3016 drv
->send_action_cookie
,
3017 (long long unsigned int) cookie
);
3018 drv
->send_action_cookie
= cookie
;
3026 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
3027 size_t data_len
, int noack
,
3028 unsigned int freq
, int no_cck
,
3030 unsigned int wait_time
)
3032 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3033 struct ieee80211_mgmt
*mgmt
;
3037 mgmt
= (struct ieee80211_mgmt
*) data
;
3038 fc
= le_to_host16(mgmt
->frame_control
);
3039 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - da= " MACSTR
3040 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3041 MAC2STR(mgmt
->da
), noack
, freq
, no_cck
, offchanok
, wait_time
,
3042 fc
, fc2str(fc
), drv
->nlmode
);
3044 if ((is_sta_interface(drv
->nlmode
) ||
3045 drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) &&
3046 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3047 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
3049 * The use of last_mgmt_freq is a bit of a hack,
3050 * but it works due to the single-threaded nature
3051 * of wpa_supplicant.
3054 wpa_printf(MSG_DEBUG
, "nl80211: Use last_mgmt_freq=%d",
3055 drv
->last_mgmt_freq
);
3056 freq
= drv
->last_mgmt_freq
;
3058 return nl80211_send_frame_cmd(bss
, freq
, 0,
3059 data
, data_len
, NULL
, 1, noack
,
3063 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
3065 wpa_printf(MSG_DEBUG
, "nl80211: Use bss->freq=%d",
3069 return nl80211_send_frame_cmd(bss
, freq
,
3070 (int) freq
== bss
->freq
? 0 :
3073 &drv
->send_action_cookie
,
3074 no_cck
, noack
, offchanok
);
3077 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3078 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
3080 * Only one of the authentication frame types is encrypted.
3081 * In order for static WEP encryption to work properly (i.e.,
3082 * to not encrypt the frame), we need to tell mac80211 about
3083 * the frames that must not be encrypted.
3085 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
3086 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
3087 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
3091 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme -> send_frame");
3092 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
3093 noack
, freq
, no_cck
, offchanok
,
3098 static int nl80211_put_basic_rates(struct nl_msg
*msg
, const int *basic_rates
)
3100 u8 rates
[NL80211_MAX_SUPP_RATES
];
3107 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0; i
++)
3108 rates
[rates_len
++] = basic_rates
[i
] / 5;
3110 return nla_put(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
3114 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
3115 int slot
, int ht_opmode
, int ap_isolate
,
3116 const int *basic_rates
)
3118 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3121 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_BSS
)) ||
3123 nla_put_u8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
)) ||
3125 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
)) ||
3127 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
)) ||
3129 nla_put_u16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
)) ||
3131 nla_put_u8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
)) ||
3132 nl80211_put_basic_rates(msg
, basic_rates
)) {
3137 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3141 static int wpa_driver_nl80211_set_acl(void *priv
,
3142 struct hostapd_acl_params
*params
)
3144 struct i802_bss
*bss
= priv
;
3145 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3151 if (!(drv
->capa
.max_acl_mac_addrs
))
3154 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
3157 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
3158 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
3160 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MAC_ACL
)) ||
3161 nla_put_u32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
3162 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
3163 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
) ||
3164 (acl
= nla_nest_start(msg
, NL80211_ATTR_MAC_ADDRS
)) == NULL
) {
3169 for (i
= 0; i
< params
->num_mac_acl
; i
++) {
3170 if (nla_put(msg
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
)) {
3176 nla_nest_end(msg
, acl
);
3178 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3180 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
3181 ret
, strerror(-ret
));
3188 static int nl80211_put_beacon_int(struct nl_msg
*msg
, int beacon_int
)
3190 if (beacon_int
> 0) {
3191 wpa_printf(MSG_DEBUG
, " * beacon_int=%d", beacon_int
);
3192 return nla_put_u32(msg
, NL80211_ATTR_BEACON_INTERVAL
,
3200 static int wpa_driver_nl80211_set_ap(void *priv
,
3201 struct wpa_driver_ap_params
*params
)
3203 struct i802_bss
*bss
= priv
;
3204 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3206 u8 cmd
= NL80211_CMD_NEW_BEACON
;
3211 u32 suites
[10], suite
;
3214 beacon_set
= bss
->beacon_set
;
3216 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
3219 cmd
= NL80211_CMD_SET_BEACON
;
3221 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
3222 params
->head
, params
->head_len
);
3223 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
3224 params
->tail
, params
->tail_len
);
3225 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", bss
->ifindex
);
3226 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
3227 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
3228 wpa_hexdump_ascii(MSG_DEBUG
, "nl80211: ssid",
3229 params
->ssid
, params
->ssid_len
);
3230 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
3231 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
,
3233 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
,
3235 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
3236 nla_put_u32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
) ||
3237 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
3239 if (params
->proberesp
&& params
->proberesp_len
) {
3240 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
3241 params
->proberesp
, params
->proberesp_len
);
3242 if (nla_put(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
3246 switch (params
->hide_ssid
) {
3247 case NO_SSID_HIDING
:
3248 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
3249 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3250 NL80211_HIDDEN_SSID_NOT_IN_USE
))
3253 case HIDDEN_SSID_ZERO_LEN
:
3254 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
3255 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3256 NL80211_HIDDEN_SSID_ZERO_LEN
))
3259 case HIDDEN_SSID_ZERO_CONTENTS
:
3260 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
3261 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3262 NL80211_HIDDEN_SSID_ZERO_CONTENTS
))
3266 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
3267 if (params
->privacy
&&
3268 nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
3270 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
3271 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
3272 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
3273 /* Leave out the attribute */
3274 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
) {
3275 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3276 NL80211_AUTHTYPE_SHARED_KEY
))
3279 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3280 NL80211_AUTHTYPE_OPEN_SYSTEM
))
3284 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
3286 if (params
->wpa_version
& WPA_PROTO_WPA
)
3287 ver
|= NL80211_WPA_VERSION_1
;
3288 if (params
->wpa_version
& WPA_PROTO_RSN
)
3289 ver
|= NL80211_WPA_VERSION_2
;
3291 nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
3294 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
3295 params
->key_mgmt_suites
);
3297 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
3298 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
3299 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
3300 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
3302 nla_put(msg
, NL80211_ATTR_AKM_SUITES
, num_suites
* sizeof(u32
),
3306 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
3307 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
) &&
3308 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
))
3311 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
3312 params
->pairwise_ciphers
);
3313 num_suites
= wpa_cipher_to_cipher_suites(params
->pairwise_ciphers
,
3314 suites
, ARRAY_SIZE(suites
));
3316 nla_put(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
3317 num_suites
* sizeof(u32
), suites
))
3320 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
3321 params
->group_cipher
);
3322 suite
= wpa_cipher_to_cipher_suite(params
->group_cipher
);
3324 nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, suite
))
3327 switch (params
->smps_mode
) {
3328 case HT_CAP_INFO_SMPS_DYNAMIC
:
3329 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - dynamic");
3330 smps_mode
= NL80211_SMPS_DYNAMIC
;
3332 case HT_CAP_INFO_SMPS_STATIC
:
3333 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - static");
3334 smps_mode
= NL80211_SMPS_STATIC
;
3337 /* invalid - fallback to smps off */
3338 case HT_CAP_INFO_SMPS_DISABLED
:
3339 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - off");
3340 smps_mode
= NL80211_SMPS_OFF
;
3343 if (nla_put_u32(msg
, NL80211_ATTR_SMPS_MODE
, smps_mode
))
3346 if (params
->beacon_ies
) {
3347 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
3348 params
->beacon_ies
);
3349 if (nla_put(msg
, NL80211_ATTR_IE
,
3350 wpabuf_len(params
->beacon_ies
),
3351 wpabuf_head(params
->beacon_ies
)))
3354 if (params
->proberesp_ies
) {
3355 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
3356 params
->proberesp_ies
);
3357 if (nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
3358 wpabuf_len(params
->proberesp_ies
),
3359 wpabuf_head(params
->proberesp_ies
)))
3362 if (params
->assocresp_ies
) {
3363 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
3364 params
->assocresp_ies
);
3365 if (nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
3366 wpabuf_len(params
->assocresp_ies
),
3367 wpabuf_head(params
->assocresp_ies
)))
3371 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
3372 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
3373 params
->ap_max_inactivity
);
3374 if (nla_put_u16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
3375 params
->ap_max_inactivity
))
3379 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3381 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
3382 ret
, strerror(-ret
));
3384 bss
->beacon_set
= 1;
3385 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
3386 params
->short_slot_time
, params
->ht_opmode
,
3387 params
->isolate
, params
->basic_rates
);
3388 if (beacon_set
&& params
->freq
&&
3389 params
->freq
->bandwidth
!= bss
->bandwidth
) {
3390 wpa_printf(MSG_DEBUG
,
3391 "nl80211: Update BSS %s bandwidth: %d -> %d",
3392 bss
->ifname
, bss
->bandwidth
,
3393 params
->freq
->bandwidth
);
3394 ret
= nl80211_set_channel(bss
, params
->freq
, 1);
3396 wpa_printf(MSG_DEBUG
,
3397 "nl80211: Frequency set failed: %d (%s)",
3398 ret
, strerror(-ret
));
3400 wpa_printf(MSG_DEBUG
,
3401 "nl80211: Frequency set succeeded for ht2040 coex");
3402 bss
->bandwidth
= params
->freq
->bandwidth
;
3404 } else if (!beacon_set
) {
3406 * cfg80211 updates the driver on frequence change in AP
3407 * mode only at the point when beaconing is started, so
3408 * set the initial value here.
3410 bss
->bandwidth
= params
->freq
->bandwidth
;
3420 static int nl80211_put_freq_params(struct nl_msg
*msg
,
3421 const struct hostapd_freq_params
*freq
)
3423 wpa_printf(MSG_DEBUG
, " * freq=%d", freq
->freq
);
3424 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
))
3427 wpa_printf(MSG_DEBUG
, " * vht_enabled=%d", freq
->vht_enabled
);
3428 wpa_printf(MSG_DEBUG
, " * ht_enabled=%d", freq
->ht_enabled
);
3430 if (freq
->vht_enabled
) {
3431 enum nl80211_chan_width cw
;
3433 wpa_printf(MSG_DEBUG
, " * bandwidth=%d", freq
->bandwidth
);
3434 switch (freq
->bandwidth
) {
3436 cw
= NL80211_CHAN_WIDTH_20
;
3439 cw
= NL80211_CHAN_WIDTH_40
;
3442 if (freq
->center_freq2
)
3443 cw
= NL80211_CHAN_WIDTH_80P80
;
3445 cw
= NL80211_CHAN_WIDTH_80
;
3448 cw
= NL80211_CHAN_WIDTH_160
;
3454 wpa_printf(MSG_DEBUG
, " * channel_width=%d", cw
);
3455 wpa_printf(MSG_DEBUG
, " * center_freq1=%d",
3456 freq
->center_freq1
);
3457 wpa_printf(MSG_DEBUG
, " * center_freq2=%d",
3458 freq
->center_freq2
);
3459 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, cw
) ||
3460 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
,
3461 freq
->center_freq1
) ||
3462 (freq
->center_freq2
&&
3463 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
,
3464 freq
->center_freq2
)))
3466 } else if (freq
->ht_enabled
) {
3467 enum nl80211_channel_type ct
;
3469 wpa_printf(MSG_DEBUG
, " * sec_channel_offset=%d",
3470 freq
->sec_channel_offset
);
3471 switch (freq
->sec_channel_offset
) {
3473 ct
= NL80211_CHAN_HT40MINUS
;
3476 ct
= NL80211_CHAN_HT40PLUS
;
3479 ct
= NL80211_CHAN_HT20
;
3483 wpa_printf(MSG_DEBUG
, " * channel_type=%d", ct
);
3484 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, ct
))
3491 static int nl80211_set_channel(struct i802_bss
*bss
,
3492 struct hostapd_freq_params
*freq
, int set_chan
)
3494 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3498 wpa_printf(MSG_DEBUG
,
3499 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
3500 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
3501 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
3503 msg
= nl80211_drv_msg(drv
, 0, set_chan
? NL80211_CMD_SET_CHANNEL
:
3504 NL80211_CMD_SET_WIPHY
);
3505 if (!msg
|| nl80211_put_freq_params(msg
, freq
) < 0) {
3510 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3512 bss
->freq
= freq
->freq
;
3515 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
3516 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
3521 static u32
sta_flags_nl80211(int flags
)
3525 if (flags
& WPA_STA_AUTHORIZED
)
3526 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
3527 if (flags
& WPA_STA_WMM
)
3528 f
|= BIT(NL80211_STA_FLAG_WME
);
3529 if (flags
& WPA_STA_SHORT_PREAMBLE
)
3530 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
3531 if (flags
& WPA_STA_MFP
)
3532 f
|= BIT(NL80211_STA_FLAG_MFP
);
3533 if (flags
& WPA_STA_TDLS_PEER
)
3534 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
3535 if (flags
& WPA_STA_AUTHENTICATED
)
3536 f
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
3543 static u32
sta_plink_state_nl80211(enum mesh_plink_state state
)
3547 return NL80211_PLINK_LISTEN
;
3548 case PLINK_OPEN_SENT
:
3549 return NL80211_PLINK_OPN_SNT
;
3550 case PLINK_OPEN_RCVD
:
3551 return NL80211_PLINK_OPN_RCVD
;
3552 case PLINK_CNF_RCVD
:
3553 return NL80211_PLINK_CNF_RCVD
;
3555 return NL80211_PLINK_ESTAB
;
3557 return NL80211_PLINK_HOLDING
;
3559 return NL80211_PLINK_BLOCKED
;
3561 wpa_printf(MSG_ERROR
, "nl80211: Invalid mesh plink state %d",
3566 #endif /* CONFIG_MESH */
3569 static int wpa_driver_nl80211_sta_add(void *priv
,
3570 struct hostapd_sta_add_params
*params
)
3572 struct i802_bss
*bss
= priv
;
3573 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3575 struct nl80211_sta_flag_update upd
;
3578 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
3579 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
3582 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
3583 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
3584 msg
= nl80211_bss_msg(bss
, 0, params
->set
? NL80211_CMD_SET_STATION
:
3585 NL80211_CMD_NEW_STATION
);
3586 if (!msg
|| nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
))
3589 if (!params
->set
|| (params
->flags
& WPA_STA_TDLS_PEER
)) {
3590 wpa_hexdump(MSG_DEBUG
, " * supported rates",
3591 params
->supp_rates
, params
->supp_rates_len
);
3592 wpa_printf(MSG_DEBUG
, " * capability=0x%x",
3593 params
->capability
);
3594 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
,
3595 params
->supp_rates_len
, params
->supp_rates
) ||
3596 nla_put_u16(msg
, NL80211_ATTR_STA_CAPABILITY
,
3597 params
->capability
))
3600 if (params
->ht_capabilities
) {
3601 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
3602 (u8
*) params
->ht_capabilities
,
3603 sizeof(*params
->ht_capabilities
));
3604 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
,
3605 sizeof(*params
->ht_capabilities
),
3606 params
->ht_capabilities
))
3610 if (params
->vht_capabilities
) {
3611 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
3612 (u8
*) params
->vht_capabilities
,
3613 sizeof(*params
->vht_capabilities
));
3614 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
,
3615 sizeof(*params
->vht_capabilities
),
3616 params
->vht_capabilities
))
3620 if (params
->ext_capab
) {
3621 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
3622 params
->ext_capab
, params
->ext_capab_len
);
3623 if (nla_put(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
3624 params
->ext_capab_len
, params
->ext_capab
))
3630 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
3631 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
))
3635 * cfg80211 validates that AID is non-zero, so we have
3636 * to make this a non-zero value for the TDLS case where
3637 * a dummy STA entry is used for now.
3639 wpa_printf(MSG_DEBUG
, " * aid=1 (TDLS workaround)");
3640 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, 1))
3643 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
3644 params
->listen_interval
);
3645 if (nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
3646 params
->listen_interval
))
3648 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
3649 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
3650 if (nla_put_u16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
))
3654 if (params
->vht_opmode_enabled
) {
3655 wpa_printf(MSG_DEBUG
, " * opmode=%u", params
->vht_opmode
);
3656 if (nla_put_u8(msg
, NL80211_ATTR_OPMODE_NOTIF
,
3657 params
->vht_opmode
))
3661 if (params
->supp_channels
) {
3662 wpa_hexdump(MSG_DEBUG
, " * supported channels",
3663 params
->supp_channels
, params
->supp_channels_len
);
3664 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_CHANNELS
,
3665 params
->supp_channels_len
, params
->supp_channels
))
3669 if (params
->supp_oper_classes
) {
3670 wpa_hexdump(MSG_DEBUG
, " * supported operating classes",
3671 params
->supp_oper_classes
,
3672 params
->supp_oper_classes_len
);
3673 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
,
3674 params
->supp_oper_classes_len
,
3675 params
->supp_oper_classes
))
3679 os_memset(&upd
, 0, sizeof(upd
));
3680 upd
.set
= sta_flags_nl80211(params
->flags
);
3681 upd
.mask
= upd
.set
| sta_flags_nl80211(params
->flags_mask
);
3682 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
3684 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
3688 if (params
->plink_state
&&
3689 nla_put_u8(msg
, NL80211_ATTR_STA_PLINK_STATE
,
3690 sta_plink_state_nl80211(params
->plink_state
)))
3692 #endif /* CONFIG_MESH */
3694 if (params
->flags
& WPA_STA_WMM
) {
3695 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
3697 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
3699 nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
3700 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
) ||
3701 nla_put_u8(msg
, NL80211_STA_WME_MAX_SP
,
3702 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
3703 WMM_QOSINFO_STA_SP_MASK
))
3705 nla_nest_end(msg
, wme
);
3708 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3711 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
3712 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
3722 static void rtnl_neigh_delete_fdb_entry(struct i802_bss
*bss
, const u8
*addr
)
3724 #ifdef CONFIG_LIBNL3_ROUTE
3725 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3726 struct rtnl_neigh
*rn
;
3727 struct nl_addr
*nl_addr
;
3730 rn
= rtnl_neigh_alloc();
3734 rtnl_neigh_set_family(rn
, AF_BRIDGE
);
3735 rtnl_neigh_set_ifindex(rn
, bss
->ifindex
);
3736 nl_addr
= nl_addr_build(AF_BRIDGE
, (void *) addr
, ETH_ALEN
);
3741 rtnl_neigh_set_lladdr(rn
, nl_addr
);
3743 err
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
3745 wpa_printf(MSG_DEBUG
, "nl80211: bridge FDB entry delete for "
3746 MACSTR
" ifindex=%d failed: %s", MAC2STR(addr
),
3747 bss
->ifindex
, nl_geterror(err
));
3749 wpa_printf(MSG_DEBUG
, "nl80211: deleted bridge FDB entry for "
3750 MACSTR
, MAC2STR(addr
));
3753 nl_addr_put(nl_addr
);
3755 #endif /* CONFIG_LIBNL3_ROUTE */
3759 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
,
3760 int deauth
, u16 reason_code
)
3762 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3766 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
)) ||
3767 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
3769 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
3770 WLAN_FC_STYPE_DISASSOC
)) ||
3772 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
3773 WLAN_FC_STYPE_DEAUTH
)) ||
3775 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
))) {
3780 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3781 wpa_printf(MSG_DEBUG
, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
3783 bss
->ifname
, MAC2STR(addr
), ret
, strerror(-ret
));
3786 rtnl_neigh_delete_fdb_entry(bss
, addr
);
3794 void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
3797 struct wpa_driver_nl80211_data
*drv2
;
3799 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
3801 /* stop listening for EAPOL on this interface */
3802 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
3803 struct wpa_driver_nl80211_data
, list
)
3804 del_ifidx(drv2
, ifidx
);
3806 msg
= nl80211_ifindex_msg(drv
, ifidx
, 0, NL80211_CMD_DEL_INTERFACE
);
3807 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
3809 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
3813 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
3816 case NL80211_IFTYPE_ADHOC
:
3818 case NL80211_IFTYPE_STATION
:
3820 case NL80211_IFTYPE_AP
:
3822 case NL80211_IFTYPE_AP_VLAN
:
3824 case NL80211_IFTYPE_WDS
:
3826 case NL80211_IFTYPE_MONITOR
:
3828 case NL80211_IFTYPE_MESH_POINT
:
3829 return "MESH_POINT";
3830 case NL80211_IFTYPE_P2P_CLIENT
:
3831 return "P2P_CLIENT";
3832 case NL80211_IFTYPE_P2P_GO
:
3834 case NL80211_IFTYPE_P2P_DEVICE
:
3835 return "P2P_DEVICE";
3842 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
3844 enum nl80211_iftype iftype
,
3845 const u8
*addr
, int wds
,
3846 int (*handler
)(struct nl_msg
*, void *),
3853 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
3854 iftype
, nl80211_iftype_str(iftype
));
3856 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_NEW_INTERFACE
);
3858 nla_put_string(msg
, NL80211_ATTR_IFNAME
, ifname
) ||
3859 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, iftype
))
3862 if (iftype
== NL80211_IFTYPE_MONITOR
) {
3863 struct nlattr
*flags
;
3865 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
3867 nla_put_flag(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
))
3870 nla_nest_end(msg
, flags
);
3872 if (nla_put_u8(msg
, NL80211_ATTR_4ADDR
, wds
))
3877 * Tell cfg80211 that the interface belongs to the socket that created
3878 * it, and the interface should be deleted when the socket is closed.
3880 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
3883 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
3888 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
3889 ifname
, ret
, strerror(-ret
));
3893 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
)
3896 ifidx
= if_nametoindex(ifname
);
3897 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
3904 * Some virtual interfaces need to process EAPOL packets and events on
3905 * the parent interface. This is used mainly with hostapd.
3908 iftype
== NL80211_IFTYPE_AP_VLAN
||
3909 iftype
== NL80211_IFTYPE_WDS
||
3910 iftype
== NL80211_IFTYPE_MONITOR
) {
3911 /* start listening for EAPOL on this interface */
3912 add_ifidx(drv
, ifidx
);
3915 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
3916 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
3917 nl80211_remove_iface(drv
, ifidx
);
3925 int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
3926 const char *ifname
, enum nl80211_iftype iftype
,
3927 const u8
*addr
, int wds
,
3928 int (*handler
)(struct nl_msg
*, void *),
3929 void *arg
, int use_existing
)
3933 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
3936 /* if error occurred and interface exists already */
3937 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
3939 wpa_printf(MSG_DEBUG
, "nl80211: Continue using existing interface %s",
3941 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
3942 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
3944 (linux_set_iface_flags(drv
->global
->ioctl_sock
,
3946 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
3948 linux_set_iface_flags(drv
->global
->ioctl_sock
,
3953 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
3955 /* Try to remove the interface that was already there. */
3956 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
3958 /* Try to create the interface again */
3959 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
3963 if (ret
>= 0 && is_p2p_net_interface(iftype
)) {
3964 wpa_printf(MSG_DEBUG
,
3965 "nl80211: Interface %s created for P2P - disable 11b rates",
3967 nl80211_disable_11b_rates(drv
, ret
, 1);
3974 static int nl80211_setup_ap(struct i802_bss
*bss
)
3976 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3978 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
3979 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
3982 * Disable Probe Request reporting unless we need it in this way for
3983 * devices that include the AP SME, in the other case (unless using
3984 * monitor iface) we'll get it through the nl_mgmt socket instead.
3986 if (!drv
->device_ap_sme
)
3987 wpa_driver_nl80211_probe_req_report(bss
, 0);
3989 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
3990 if (nl80211_mgmt_subscribe_ap(bss
))
3993 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
3994 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
3997 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
3998 nl80211_create_monitor_interface(drv
) &&
3999 !drv
->device_ap_sme
)
4002 if (drv
->device_ap_sme
&&
4003 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
4004 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
4005 "Probe Request frame reporting in AP mode");
4006 /* Try to survive without this */
4013 static void nl80211_teardown_ap(struct i802_bss
*bss
)
4015 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4017 wpa_printf(MSG_DEBUG
, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4018 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
4019 if (drv
->device_ap_sme
) {
4020 wpa_driver_nl80211_probe_req_report(bss
, 0);
4021 if (!drv
->use_monitor
)
4022 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
4023 } else if (drv
->use_monitor
)
4024 nl80211_remove_monitor_interface(drv
);
4026 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
4028 bss
->beacon_set
= 0;
4032 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
4033 const u8
*addr
, const u8
*data
,
4036 struct sockaddr_ll ll
;
4039 if (bss
->drv
->eapol_tx_sock
< 0) {
4040 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
4044 os_memset(&ll
, 0, sizeof(ll
));
4045 ll
.sll_family
= AF_PACKET
;
4046 ll
.sll_ifindex
= bss
->ifindex
;
4047 ll
.sll_protocol
= htons(ETH_P_PAE
);
4048 ll
.sll_halen
= ETH_ALEN
;
4049 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
4050 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
4051 (struct sockaddr
*) &ll
, sizeof(ll
));
4053 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
4060 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4062 static int wpa_driver_nl80211_hapd_send_eapol(
4063 void *priv
, const u8
*addr
, const u8
*data
,
4064 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
4066 struct i802_bss
*bss
= priv
;
4067 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4068 struct ieee80211_hdr
*hdr
;
4072 int qos
= flags
& WPA_STA_WMM
;
4074 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
4075 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
4077 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
4079 hdr
= os_zalloc(len
);
4081 wpa_printf(MSG_INFO
, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4082 (unsigned long) len
);
4086 hdr
->frame_control
=
4087 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
4088 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
4090 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
4092 hdr
->frame_control
|=
4093 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
4096 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
4097 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
4098 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
4099 pos
= (u8
*) (hdr
+ 1);
4102 /* Set highest priority in QoS header */
4108 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
4109 pos
+= sizeof(rfc1042_header
);
4110 WPA_PUT_BE16(pos
, ETH_P_PAE
);
4112 memcpy(pos
, data
, data_len
);
4114 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
4117 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
4119 (unsigned long) len
, errno
, strerror(errno
));
4127 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
4129 int flags_or
, int flags_and
)
4131 struct i802_bss
*bss
= priv
;
4133 struct nlattr
*flags
;
4134 struct nl80211_sta_flag_update upd
;
4136 wpa_printf(MSG_DEBUG
, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4137 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4138 bss
->ifname
, MAC2STR(addr
), total_flags
, flags_or
, flags_and
,
4139 !!(total_flags
& WPA_STA_AUTHORIZED
));
4141 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
4142 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
4146 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4147 * can be removed eventually.
4149 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
4151 ((total_flags
& WPA_STA_AUTHORIZED
) &&
4152 nla_put_flag(msg
, NL80211_STA_FLAG_AUTHORIZED
)) ||
4153 ((total_flags
& WPA_STA_WMM
) &&
4154 nla_put_flag(msg
, NL80211_STA_FLAG_WME
)) ||
4155 ((total_flags
& WPA_STA_SHORT_PREAMBLE
) &&
4156 nla_put_flag(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
)) ||
4157 ((total_flags
& WPA_STA_MFP
) &&
4158 nla_put_flag(msg
, NL80211_STA_FLAG_MFP
)) ||
4159 ((total_flags
& WPA_STA_TDLS_PEER
) &&
4160 nla_put_flag(msg
, NL80211_STA_FLAG_TDLS_PEER
)))
4163 nla_nest_end(msg
, flags
);
4165 os_memset(&upd
, 0, sizeof(upd
));
4166 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
4167 upd
.set
= sta_flags_nl80211(flags_or
);
4168 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
4171 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
4178 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
4179 struct wpa_driver_associate_params
*params
)
4181 enum nl80211_iftype nlmode
, old_mode
;
4184 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
4186 nlmode
= NL80211_IFTYPE_P2P_GO
;
4188 nlmode
= NL80211_IFTYPE_AP
;
4190 old_mode
= drv
->nlmode
;
4191 if (wpa_driver_nl80211_set_mode(drv
->first_bss
, nlmode
)) {
4192 nl80211_remove_monitor_interface(drv
);
4196 if (nl80211_set_channel(drv
->first_bss
, ¶ms
->freq
, 0)) {
4197 if (old_mode
!= nlmode
)
4198 wpa_driver_nl80211_set_mode(drv
->first_bss
, old_mode
);
4199 nl80211_remove_monitor_interface(drv
);
4207 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
4213 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_IBSS
);
4214 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4216 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
4217 "(%s)", ret
, strerror(-ret
));
4219 wpa_printf(MSG_DEBUG
,
4220 "nl80211: Leave IBSS request sent successfully");
4224 wpa_driver_nl80211_set_mode(drv
->first_bss
,
4225 NL80211_IFTYPE_STATION
)) {
4226 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
4234 static int nl80211_ht_vht_overrides(struct nl_msg
*msg
,
4235 struct wpa_driver_associate_params
*params
)
4237 if (params
->disable_ht
&& nla_put_flag(msg
, NL80211_ATTR_DISABLE_HT
))
4240 if (params
->htcaps
&& params
->htcaps_mask
) {
4241 int sz
= sizeof(struct ieee80211_ht_capabilities
);
4242 wpa_hexdump(MSG_DEBUG
, " * htcaps", params
->htcaps
, sz
);
4243 wpa_hexdump(MSG_DEBUG
, " * htcaps_mask",
4244 params
->htcaps_mask
, sz
);
4245 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
,
4247 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
4248 params
->htcaps_mask
))
4252 #ifdef CONFIG_VHT_OVERRIDES
4253 if (params
->disable_vht
) {
4254 wpa_printf(MSG_DEBUG
, " * VHT disabled");
4255 if (nla_put_flag(msg
, NL80211_ATTR_DISABLE_VHT
))
4259 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
4260 int sz
= sizeof(struct ieee80211_vht_capabilities
);
4261 wpa_hexdump(MSG_DEBUG
, " * vhtcaps", params
->vhtcaps
, sz
);
4262 wpa_hexdump(MSG_DEBUG
, " * vhtcaps_mask",
4263 params
->vhtcaps_mask
, sz
);
4264 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
,
4266 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
4267 params
->vhtcaps_mask
))
4270 #endif /* CONFIG_VHT_OVERRIDES */
4276 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
4277 struct wpa_driver_associate_params
*params
)
4283 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
4285 if (wpa_driver_nl80211_set_mode_ibss(drv
->first_bss
, ¶ms
->freq
)) {
4286 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
4292 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_IBSS
)) ||
4293 params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
4296 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4297 params
->ssid
, params
->ssid_len
);
4298 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
4300 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
4301 drv
->ssid_len
= params
->ssid_len
;
4303 if (nl80211_put_freq_params(msg
, ¶ms
->freq
) < 0 ||
4304 nl80211_put_beacon_int(msg
, params
->beacon_int
))
4307 ret
= nl80211_set_conn_keys(params
, msg
);
4311 if (params
->bssid
&& params
->fixed_bssid
) {
4312 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
4313 MAC2STR(params
->bssid
));
4314 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
4318 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
4319 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
4320 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
4321 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
) {
4322 wpa_printf(MSG_DEBUG
, " * control port");
4323 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
4327 if (params
->wpa_ie
) {
4328 wpa_hexdump(MSG_DEBUG
,
4329 " * Extra IEs for Beacon/Probe Response frames",
4330 params
->wpa_ie
, params
->wpa_ie_len
);
4331 if (nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
4336 if (nl80211_ht_vht_overrides(msg
, params
) < 0)
4339 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4342 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
4343 ret
, strerror(-ret
));
4345 if (ret
== -EALREADY
&& count
== 1) {
4346 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
4348 nl80211_leave_ibss(drv
, 0);
4353 wpa_printf(MSG_DEBUG
,
4354 "nl80211: Join IBSS request sent successfully");
4363 static int nl80211_connect_common(struct wpa_driver_nl80211_data
*drv
,
4364 struct wpa_driver_associate_params
*params
,
4367 if (params
->bssid
) {
4368 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
4369 MAC2STR(params
->bssid
));
4370 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
4374 if (params
->bssid_hint
) {
4375 wpa_printf(MSG_DEBUG
, " * bssid_hint=" MACSTR
,
4376 MAC2STR(params
->bssid_hint
));
4377 if (nla_put(msg
, NL80211_ATTR_MAC_HINT
, ETH_ALEN
,
4378 params
->bssid_hint
))
4382 if (params
->freq
.freq
) {
4383 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
.freq
);
4384 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
4387 drv
->assoc_freq
= params
->freq
.freq
;
4389 drv
->assoc_freq
= 0;
4391 if (params
->freq_hint
) {
4392 wpa_printf(MSG_DEBUG
, " * freq_hint=%d", params
->freq_hint
);
4393 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_HINT
,
4398 if (params
->bg_scan_period
>= 0) {
4399 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
4400 params
->bg_scan_period
);
4401 if (nla_put_u16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
4402 params
->bg_scan_period
))
4407 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4408 params
->ssid
, params
->ssid_len
);
4409 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4412 if (params
->ssid_len
> sizeof(drv
->ssid
))
4414 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
4415 drv
->ssid_len
= params
->ssid_len
;
4418 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
4419 if (params
->wpa_ie
&&
4420 nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
, params
->wpa_ie
))
4423 if (params
->wpa_proto
) {
4424 enum nl80211_wpa_versions ver
= 0;
4426 if (params
->wpa_proto
& WPA_PROTO_WPA
)
4427 ver
|= NL80211_WPA_VERSION_1
;
4428 if (params
->wpa_proto
& WPA_PROTO_RSN
)
4429 ver
|= NL80211_WPA_VERSION_2
;
4431 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
4432 if (nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
4436 if (params
->pairwise_suite
!= WPA_CIPHER_NONE
) {
4437 u32 cipher
= wpa_cipher_to_cipher_suite(params
->pairwise_suite
);
4438 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
4439 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
4444 if (params
->group_suite
== WPA_CIPHER_GTK_NOT_USED
&&
4445 !(drv
->capa
.enc
& WPA_DRIVER_CAPA_ENC_GTK_NOT_USED
)) {
4447 * This is likely to work even though many drivers do not
4448 * advertise support for operations without GTK.
4450 wpa_printf(MSG_DEBUG
, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
4451 } else if (params
->group_suite
!= WPA_CIPHER_NONE
) {
4452 u32 cipher
= wpa_cipher_to_cipher_suite(params
->group_suite
);
4453 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
4454 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
))
4458 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
4459 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
4460 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_IEEE8021X
||
4461 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
||
4462 params
->key_mgmt_suite
== WPA_KEY_MGMT_CCKM
||
4463 params
->key_mgmt_suite
== WPA_KEY_MGMT_OSEN
||
4464 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
4465 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
4466 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
||
4467 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
4468 int mgmt
= WLAN_AKM_SUITE_PSK
;
4470 switch (params
->key_mgmt_suite
) {
4471 case WPA_KEY_MGMT_CCKM
:
4472 mgmt
= WLAN_AKM_SUITE_CCKM
;
4474 case WPA_KEY_MGMT_IEEE8021X
:
4475 mgmt
= WLAN_AKM_SUITE_8021X
;
4477 case WPA_KEY_MGMT_FT_IEEE8021X
:
4478 mgmt
= WLAN_AKM_SUITE_FT_8021X
;
4480 case WPA_KEY_MGMT_FT_PSK
:
4481 mgmt
= WLAN_AKM_SUITE_FT_PSK
;
4483 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
4484 mgmt
= WLAN_AKM_SUITE_8021X_SHA256
;
4486 case WPA_KEY_MGMT_PSK_SHA256
:
4487 mgmt
= WLAN_AKM_SUITE_PSK_SHA256
;
4489 case WPA_KEY_MGMT_OSEN
:
4490 mgmt
= WLAN_AKM_SUITE_OSEN
;
4492 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
4493 mgmt
= WLAN_AKM_SUITE_8021X_SUITE_B
;
4495 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
4496 mgmt
= WLAN_AKM_SUITE_8021X_SUITE_B_192
;
4498 case WPA_KEY_MGMT_PSK
:
4500 mgmt
= WLAN_AKM_SUITE_PSK
;
4503 wpa_printf(MSG_DEBUG
, " * akm=0x%x", mgmt
);
4504 if (nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
))
4508 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
4511 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
&&
4512 nla_put_u32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
))
4515 if (params
->rrm_used
) {
4516 u32 drv_rrm_flags
= drv
->capa
.rrm_flags
;
4517 if (!(drv_rrm_flags
&
4518 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) ||
4519 !(drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
) ||
4520 nla_put_flag(msg
, NL80211_ATTR_USE_RRM
))
4524 if (nl80211_ht_vht_overrides(msg
, params
) < 0)
4528 wpa_printf(MSG_DEBUG
, " * P2P group");
4534 static int wpa_driver_nl80211_try_connect(
4535 struct wpa_driver_nl80211_data
*drv
,
4536 struct wpa_driver_associate_params
*params
)
4539 enum nl80211_auth_type type
;
4543 if (params
->req_key_mgmt_offload
&& params
->psk
&&
4544 (params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
4545 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
4546 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
4547 wpa_printf(MSG_DEBUG
, "nl80211: Key management set PSK");
4548 ret
= issue_key_mgmt_set_key(drv
, params
->psk
, 32);
4553 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
4554 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_CONNECT
);
4558 ret
= nl80211_connect_common(drv
, params
, msg
);
4563 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4565 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4567 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4570 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
4572 goto skip_auth_type
;
4575 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4576 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
4577 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4578 type
= NL80211_AUTHTYPE_SHARED_KEY
;
4579 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4580 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
4581 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
4582 type
= NL80211_AUTHTYPE_FT
;
4586 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
4587 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
4591 ret
= nl80211_set_conn_keys(params
, msg
);
4595 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4598 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
4599 "(%s)", ret
, strerror(-ret
));
4601 wpa_printf(MSG_DEBUG
,
4602 "nl80211: Connect request send successfully");
4612 static int wpa_driver_nl80211_connect(
4613 struct wpa_driver_nl80211_data
*drv
,
4614 struct wpa_driver_associate_params
*params
)
4618 /* Store the connection attempted bssid for future use */
4620 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
4622 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
4624 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
4625 if (ret
== -EALREADY
) {
4627 * cfg80211 does not currently accept new connections if
4628 * we are already connected. As a workaround, force
4629 * disconnection and try again.
4631 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
4632 "disconnecting before reassociation "
4634 if (wpa_driver_nl80211_disconnect(
4635 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
4637 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
4643 static int wpa_driver_nl80211_associate(
4644 void *priv
, struct wpa_driver_associate_params
*params
)
4646 struct i802_bss
*bss
= priv
;
4647 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4651 nl80211_unmask_11b_rates(bss
);
4653 if (params
->mode
== IEEE80211_MODE_AP
)
4654 return wpa_driver_nl80211_ap(drv
, params
);
4656 if (params
->mode
== IEEE80211_MODE_IBSS
)
4657 return wpa_driver_nl80211_ibss(drv
, params
);
4659 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
4660 enum nl80211_iftype nlmode
= params
->p2p
?
4661 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
4663 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
4665 return wpa_driver_nl80211_connect(drv
, params
);
4668 nl80211_mark_disconnected(drv
);
4670 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
4672 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_ASSOCIATE
);
4676 ret
= nl80211_connect_common(drv
, params
, msg
);
4680 if (params
->prev_bssid
) {
4681 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
4682 MAC2STR(params
->prev_bssid
));
4683 if (nla_put(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
4684 params
->prev_bssid
))
4688 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4691 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4692 "nl80211: MLME command failed (assoc): ret=%d (%s)",
4693 ret
, strerror(-ret
));
4694 nl80211_dump_scan(drv
);
4696 wpa_printf(MSG_DEBUG
,
4697 "nl80211: Association request send successfully");
4706 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
4707 int ifindex
, enum nl80211_iftype mode
)
4712 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
4713 ifindex
, mode
, nl80211_iftype_str(mode
));
4715 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_SET_INTERFACE
);
4716 if (!msg
|| nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, mode
))
4719 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4725 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
4726 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
4731 static int wpa_driver_nl80211_set_mode_impl(
4732 struct i802_bss
*bss
,
4733 enum nl80211_iftype nlmode
,
4734 struct hostapd_freq_params
*desired_freq_params
)
4736 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4739 int was_ap
= is_ap_interface(drv
->nlmode
);
4741 int mode_switch_res
;
4743 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
4744 if (mode_switch_res
&& nlmode
== nl80211_get_ifmode(bss
))
4745 mode_switch_res
= 0;
4747 if (mode_switch_res
== 0) {
4748 drv
->nlmode
= nlmode
;
4753 if (mode_switch_res
== -ENODEV
)
4756 if (nlmode
== drv
->nlmode
) {
4757 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
4758 "requested mode - ignore error");
4760 goto done
; /* Already in the requested mode */
4763 /* mac80211 doesn't allow mode changes while the device is up, so
4764 * take the device down, try to set the mode again, and bring the
4767 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
4769 for (i
= 0; i
< 10; i
++) {
4770 res
= i802_set_iface_flags(bss
, 0);
4771 if (res
== -EACCES
|| res
== -ENODEV
)
4774 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
4776 os_sleep(0, 100000);
4781 * Setting the mode will fail for some drivers if the phy is
4782 * on a frequency that the mode is disallowed in.
4784 if (desired_freq_params
) {
4785 res
= nl80211_set_channel(bss
, desired_freq_params
, 0);
4787 wpa_printf(MSG_DEBUG
,
4788 "nl80211: Failed to set frequency on interface");
4792 /* Try to set the mode again while the interface is down */
4793 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
4794 if (mode_switch_res
== -EBUSY
) {
4795 wpa_printf(MSG_DEBUG
,
4796 "nl80211: Delaying mode set while interface going down");
4797 os_sleep(0, 100000);
4800 ret
= mode_switch_res
;
4805 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
4806 "interface is down");
4807 drv
->nlmode
= nlmode
;
4808 drv
->ignore_if_down_event
= 1;
4811 /* Bring the interface back up */
4812 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1);
4814 wpa_printf(MSG_DEBUG
,
4815 "nl80211: Failed to set interface up after switching mode");
4821 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
4822 "from %d failed", nlmode
, drv
->nlmode
);
4826 if (is_p2p_net_interface(nlmode
)) {
4827 wpa_printf(MSG_DEBUG
,
4828 "nl80211: Interface %s mode change to P2P - disable 11b rates",
4830 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
4831 } else if (drv
->disabled_11b_rates
) {
4832 wpa_printf(MSG_DEBUG
,
4833 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
4835 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
4838 if (is_ap_interface(nlmode
)) {
4839 nl80211_mgmt_unsubscribe(bss
, "start AP");
4840 /* Setup additional AP mode functionality if needed */
4841 if (nl80211_setup_ap(bss
))
4843 } else if (was_ap
) {
4844 /* Remove additional AP mode functionality */
4845 nl80211_teardown_ap(bss
);
4847 nl80211_mgmt_unsubscribe(bss
, "mode change");
4850 if (is_mesh_interface(nlmode
) &&
4851 nl80211_mgmt_subscribe_mesh(bss
))
4854 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
4855 !is_mesh_interface(nlmode
) &&
4856 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
4857 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
4858 "frame processing - ignore for now");
4864 int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
4865 enum nl80211_iftype nlmode
)
4867 return wpa_driver_nl80211_set_mode_impl(bss
, nlmode
, NULL
);
4871 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
4872 struct hostapd_freq_params
*freq
)
4874 return wpa_driver_nl80211_set_mode_impl(bss
, NL80211_IFTYPE_ADHOC
,
4879 static int wpa_driver_nl80211_get_capa(void *priv
,
4880 struct wpa_driver_capa
*capa
)
4882 struct i802_bss
*bss
= priv
;
4883 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4885 if (!drv
->has_capability
)
4887 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
4888 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
4889 capa
->extended_capa
= drv
->extended_capa
;
4890 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
4891 capa
->extended_capa_len
= drv
->extended_capa_len
;
4898 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
4900 struct i802_bss
*bss
= priv
;
4901 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4903 wpa_printf(MSG_DEBUG
, "nl80211: Set %s operstate %d->%d (%s)",
4904 bss
->ifname
, drv
->operstate
, state
,
4905 state
? "UP" : "DORMANT");
4906 drv
->operstate
= state
;
4907 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
4908 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
4912 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
4914 struct i802_bss
*bss
= priv
;
4915 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4917 struct nl80211_sta_flag_update upd
;
4920 if (!drv
->associated
&& is_zero_ether_addr(drv
->bssid
) && !authorized
) {
4921 wpa_printf(MSG_DEBUG
, "nl80211: Skip set_supp_port(unauthorized) while not associated");
4925 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
4926 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
4928 os_memset(&upd
, 0, sizeof(upd
));
4929 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
4931 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
4933 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
4934 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
) ||
4935 nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
)) {
4940 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4943 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set STA flag: %d (%s)",
4944 ret
, strerror(-ret
));
4949 /* Set kernel driver on given frequency (MHz) */
4950 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
4952 struct i802_bss
*bss
= priv
;
4953 return nl80211_set_channel(bss
, freq
, 0);
4957 static inline int min_int(int a
, int b
)
4965 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
4967 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
4968 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4970 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4971 genlmsg_attrlen(gnlh
, 0), NULL
);
4974 * TODO: validate the key index and mac address!
4975 * Otherwise, there's a race condition as soon as
4976 * the kernel starts sending key notifications.
4979 if (tb
[NL80211_ATTR_KEY_SEQ
])
4980 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
4981 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
4986 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
4989 struct i802_bss
*bss
= priv
;
4990 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4993 msg
= nl80211_ifindex_msg(drv
, if_nametoindex(iface
), 0,
4994 NL80211_CMD_GET_KEY
);
4996 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
4997 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, idx
)) {
5004 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
5008 static int i802_set_rts(void *priv
, int rts
)
5010 struct i802_bss
*bss
= priv
;
5011 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5021 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5022 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
)) {
5027 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5030 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
5031 "%d (%s)", rts
, ret
, strerror(-ret
));
5036 static int i802_set_frag(void *priv
, int frag
)
5038 struct i802_bss
*bss
= priv
;
5039 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5049 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5050 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
)) {
5055 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5058 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
5059 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
5064 static int i802_flush(void *priv
)
5066 struct i802_bss
*bss
= priv
;
5070 wpa_printf(MSG_DEBUG
, "nl80211: flush -> DEL_STATION %s (all)",
5074 * XXX: FIX! this needs to flush all VLANs too
5076 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
);
5077 res
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
5079 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
5080 "(%s)", res
, strerror(-res
));
5086 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
5088 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5089 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5090 struct hostap_sta_driver_data
*data
= arg
;
5091 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
5092 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
5093 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
5094 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
5095 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
5096 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
5097 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
5098 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
5101 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5102 genlmsg_attrlen(gnlh
, 0), NULL
);
5105 * TODO: validate the interface and mac address!
5106 * Otherwise, there's a race condition as soon as
5107 * the kernel starts sending station notifications.
5110 if (!tb
[NL80211_ATTR_STA_INFO
]) {
5111 wpa_printf(MSG_DEBUG
, "sta stats missing!");
5114 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
5115 tb
[NL80211_ATTR_STA_INFO
],
5117 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
5121 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
5122 data
->inactive_msec
=
5123 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
5124 if (stats
[NL80211_STA_INFO_RX_BYTES
])
5125 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
5126 if (stats
[NL80211_STA_INFO_TX_BYTES
])
5127 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
5128 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
5130 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
5131 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
5133 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
5134 if (stats
[NL80211_STA_INFO_TX_FAILED
])
5135 data
->tx_retry_failed
=
5136 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
5141 static int i802_read_sta_data(struct i802_bss
*bss
,
5142 struct hostap_sta_driver_data
*data
,
5147 os_memset(data
, 0, sizeof(*data
));
5149 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_GET_STATION
)) ||
5150 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
5155 return send_and_recv_msgs(bss
->drv
, msg
, get_sta_handler
, data
);
5159 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
5160 int cw_min
, int cw_max
, int burst_time
)
5162 struct i802_bss
*bss
= priv
;
5163 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5165 struct nlattr
*txq
, *params
;
5167 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_WIPHY
);
5171 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
5175 /* We are only sending parameters for a single TXQ at a time */
5176 params
= nla_nest_start(msg
, 1);
5182 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
))
5186 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
))
5190 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
))
5194 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
))
5198 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5199 * 32 usec, so need to convert the value here. */
5200 if (nla_put_u16(msg
, NL80211_TXQ_ATTR_TXOP
,
5201 (burst_time
* 100 + 16) / 32) ||
5202 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
) ||
5203 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
) ||
5204 nla_put_u8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
))
5207 nla_nest_end(msg
, params
);
5209 nla_nest_end(msg
, txq
);
5211 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
5220 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
5221 const char *ifname
, int vlan_id
)
5223 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5227 wpa_printf(MSG_DEBUG
, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5228 ", ifname=%s[%d], vlan_id=%d)",
5229 bss
->ifname
, if_nametoindex(bss
->ifname
),
5230 MAC2STR(addr
), ifname
, if_nametoindex(ifname
), vlan_id
);
5231 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5232 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
5233 nla_put_u32(msg
, NL80211_ATTR_STA_VLAN
, if_nametoindex(ifname
))) {
5238 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5240 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5241 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
5242 MAC2STR(addr
), ifname
, vlan_id
, ret
,
5249 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
5251 struct hostap_sta_driver_data data
;
5254 data
.inactive_msec
= (unsigned long) -1;
5255 ret
= i802_read_sta_data(priv
, &data
, addr
);
5258 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
5260 return data
.inactive_msec
/ 1000;
5264 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
5273 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
5276 struct i802_bss
*bss
= priv
;
5277 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5278 struct ieee80211_mgmt mgmt
;
5280 if (is_mesh_interface(drv
->nlmode
))
5283 if (drv
->device_ap_sme
)
5284 return wpa_driver_nl80211_sta_remove(bss
, addr
, 1, reason
);
5286 memset(&mgmt
, 0, sizeof(mgmt
));
5287 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
5288 WLAN_FC_STYPE_DEAUTH
);
5289 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
5290 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
5291 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
5292 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
5293 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
5295 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
5300 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
5303 struct i802_bss
*bss
= priv
;
5304 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5305 struct ieee80211_mgmt mgmt
;
5307 if (is_mesh_interface(drv
->nlmode
))
5310 if (drv
->device_ap_sme
)
5311 return wpa_driver_nl80211_sta_remove(bss
, addr
, 0, reason
);
5313 memset(&mgmt
, 0, sizeof(mgmt
));
5314 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
5315 WLAN_FC_STYPE_DISASSOC
);
5316 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
5317 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
5318 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
5319 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
5320 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
5322 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
5327 static void dump_ifidx(struct wpa_driver_nl80211_data
*drv
)
5329 char buf
[200], *pos
, *end
;
5333 end
= pos
+ sizeof(buf
);
5335 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
5336 if (!drv
->if_indices
[i
])
5338 res
= os_snprintf(pos
, end
- pos
, " %d", drv
->if_indices
[i
]);
5339 if (os_snprintf_error(end
- pos
, res
))
5345 wpa_printf(MSG_DEBUG
, "nl80211: if_indices[%d]:%s",
5346 drv
->num_if_indices
, buf
);
5350 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
5355 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
5357 if (have_ifidx(drv
, ifidx
)) {
5358 wpa_printf(MSG_DEBUG
, "nl80211: ifindex %d already in the list",
5362 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
5363 if (drv
->if_indices
[i
] == 0) {
5364 drv
->if_indices
[i
] = ifidx
;
5370 if (drv
->if_indices
!= drv
->default_if_indices
)
5371 old
= drv
->if_indices
;
5375 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
5377 if (!drv
->if_indices
) {
5379 drv
->if_indices
= drv
->default_if_indices
;
5381 drv
->if_indices
= old
;
5382 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
5384 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
5387 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
5388 sizeof(drv
->default_if_indices
));
5389 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
5390 drv
->num_if_indices
++;
5395 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
5399 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
5400 if (drv
->if_indices
[i
] == ifidx
) {
5401 drv
->if_indices
[i
] = 0;
5409 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
5413 for (i
= 0; i
< drv
->num_if_indices
; i
++)
5414 if (drv
->if_indices
[i
] == ifidx
)
5421 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
5422 const char *bridge_ifname
, char *ifname_wds
)
5424 struct i802_bss
*bss
= priv
;
5425 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5426 char name
[IFNAMSIZ
+ 1];
5428 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
5430 os_strlcpy(ifname_wds
, name
, IFNAMSIZ
+ 1);
5432 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
5433 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
5435 if (!if_nametoindex(name
)) {
5436 if (nl80211_create_iface(drv
, name
,
5437 NL80211_IFTYPE_AP_VLAN
,
5438 bss
->addr
, 1, NULL
, NULL
, 0) <
5441 if (bridge_ifname
&&
5442 linux_br_add_if(drv
->global
->ioctl_sock
,
5443 bridge_ifname
, name
) < 0)
5446 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
5447 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
5448 "interface %s up", name
);
5450 return i802_set_sta_vlan(priv
, addr
, name
, 0);
5453 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
5456 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
5457 nl80211_remove_iface(drv
, if_nametoindex(name
));
5463 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
5465 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
5466 struct sockaddr_ll lladdr
;
5467 unsigned char buf
[3000];
5469 socklen_t fromlen
= sizeof(lladdr
);
5471 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
5472 (struct sockaddr
*)&lladdr
, &fromlen
);
5474 wpa_printf(MSG_ERROR
, "nl80211: EAPOL recv failed: %s",
5479 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
5480 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
5484 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
5485 struct i802_bss
*bss
,
5486 const char *brname
, const char *ifname
)
5489 char in_br
[IFNAMSIZ
];
5491 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
5492 br_ifindex
= if_nametoindex(brname
);
5493 if (br_ifindex
== 0) {
5495 * Bridge was configured, but the bridge device does
5496 * not exist. Try to add it now.
5498 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
5499 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
5500 "bridge interface %s: %s",
5501 brname
, strerror(errno
));
5504 bss
->added_bridge
= 1;
5505 br_ifindex
= if_nametoindex(brname
);
5506 add_ifidx(drv
, br_ifindex
);
5508 bss
->br_ifindex
= br_ifindex
;
5510 if (linux_br_get(in_br
, ifname
) == 0) {
5511 if (os_strcmp(in_br
, brname
) == 0)
5512 return 0; /* already in the bridge */
5514 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
5515 "bridge %s", ifname
, in_br
);
5516 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
5518 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
5519 "remove interface %s from bridge "
5521 ifname
, brname
, strerror(errno
));
5526 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
5528 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
5529 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
5530 "into bridge %s: %s",
5531 ifname
, brname
, strerror(errno
));
5534 bss
->added_if_into_bridge
= 1;
5540 static void *i802_init(struct hostapd_data
*hapd
,
5541 struct wpa_init_params
*params
)
5543 struct wpa_driver_nl80211_data
*drv
;
5544 struct i802_bss
*bss
;
5546 char brname
[IFNAMSIZ
];
5547 int ifindex
, br_ifindex
;
5550 bss
= wpa_driver_nl80211_drv_init(hapd
, params
->ifname
,
5551 params
->global_priv
, 1,
5552 params
->bssid
, params
->driver_params
);
5558 if (linux_br_get(brname
, params
->ifname
) == 0) {
5559 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
5560 params
->ifname
, brname
);
5561 br_ifindex
= if_nametoindex(brname
);
5562 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
5567 bss
->br_ifindex
= br_ifindex
;
5569 for (i
= 0; i
< params
->num_bridge
; i
++) {
5570 if (params
->bridge
[i
]) {
5571 ifindex
= if_nametoindex(params
->bridge
[i
]);
5573 add_ifidx(drv
, ifindex
);
5574 if (ifindex
== br_ifindex
)
5579 /* start listening for EAPOL on the default AP interface */
5580 add_ifidx(drv
, drv
->ifindex
);
5582 if (params
->num_bridge
&& params
->bridge
[0]) {
5583 if (i802_check_bridge(drv
, bss
, params
->bridge
[0],
5584 params
->ifname
) < 0)
5586 if (os_strcmp(params
->bridge
[0], brname
) != 0)
5590 if (!br_added
&& br_ifindex
&&
5591 (params
->num_bridge
== 0 || !params
->bridge
[0]))
5592 add_ifidx(drv
, br_ifindex
);
5594 #ifdef CONFIG_LIBNL3_ROUTE
5595 if (bss
->added_if_into_bridge
) {
5596 drv
->rtnl_sk
= nl_socket_alloc();
5597 if (drv
->rtnl_sk
== NULL
) {
5598 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate nl_sock");
5602 if (nl_connect(drv
->rtnl_sk
, NETLINK_ROUTE
)) {
5603 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
5608 #endif /* CONFIG_LIBNL3_ROUTE */
5610 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
5611 if (drv
->eapol_sock
< 0) {
5612 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
5617 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
5619 wpa_printf(MSG_INFO
, "nl80211: Could not register read socket for eapol");
5623 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
5626 os_memcpy(drv
->perm_addr
, params
->own_addr
, ETH_ALEN
);
5628 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
5633 wpa_driver_nl80211_deinit(bss
);
5638 static void i802_deinit(void *priv
)
5640 struct i802_bss
*bss
= priv
;
5641 wpa_driver_nl80211_deinit(bss
);
5645 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
5646 enum wpa_driver_if_type type
)
5649 case WPA_IF_STATION
:
5650 return NL80211_IFTYPE_STATION
;
5651 case WPA_IF_P2P_CLIENT
:
5652 case WPA_IF_P2P_GROUP
:
5653 return NL80211_IFTYPE_P2P_CLIENT
;
5654 case WPA_IF_AP_VLAN
:
5655 return NL80211_IFTYPE_AP_VLAN
;
5657 return NL80211_IFTYPE_AP
;
5659 return NL80211_IFTYPE_P2P_GO
;
5660 case WPA_IF_P2P_DEVICE
:
5661 return NL80211_IFTYPE_P2P_DEVICE
;
5663 return NL80211_IFTYPE_MESH_POINT
;
5669 #if defined(CONFIG_P2P) || defined(CONFIG_MESH)
5671 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
5673 struct wpa_driver_nl80211_data
*drv
;
5674 dl_list_for_each(drv
, &global
->interfaces
,
5675 struct wpa_driver_nl80211_data
, list
) {
5676 if (os_memcmp(addr
, drv
->first_bss
->addr
, ETH_ALEN
) == 0)
5683 static int nl80211_vif_addr(struct wpa_driver_nl80211_data
*drv
, u8
*new_addr
)
5690 os_memcpy(new_addr
, drv
->first_bss
->addr
, ETH_ALEN
);
5691 for (idx
= 0; idx
< 64; idx
++) {
5692 new_addr
[0] = drv
->first_bss
->addr
[0] | 0x02;
5693 new_addr
[0] ^= idx
<< 2;
5694 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
5700 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new virtual interface address "
5701 MACSTR
, MAC2STR(new_addr
));
5706 #endif /* CONFIG_P2P || CONFIG_MESH */
5712 u8 macaddr
[ETH_ALEN
];
5715 static int nl80211_wdev_handler(struct nl_msg
*msg
, void *arg
)
5717 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5718 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5719 struct wdev_info
*wi
= arg
;
5721 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5722 genlmsg_attrlen(gnlh
, 0), NULL
);
5723 if (tb
[NL80211_ATTR_WDEV
]) {
5724 wi
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
5725 wi
->wdev_id_set
= 1;
5728 if (tb
[NL80211_ATTR_MAC
])
5729 os_memcpy(wi
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
5736 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
5737 const char *ifname
, const u8
*addr
,
5738 void *bss_ctx
, void **drv_priv
,
5739 char *force_ifname
, u8
*if_addr
,
5740 const char *bridge
, int use_existing
)
5742 enum nl80211_iftype nlmode
;
5743 struct i802_bss
*bss
= priv
;
5744 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5749 os_memcpy(if_addr
, addr
, ETH_ALEN
);
5750 nlmode
= wpa_driver_nl80211_if_type(type
);
5751 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
5752 struct wdev_info p2pdev_info
;
5754 os_memset(&p2pdev_info
, 0, sizeof(p2pdev_info
));
5755 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
5756 0, nl80211_wdev_handler
,
5757 &p2pdev_info
, use_existing
);
5758 if (!p2pdev_info
.wdev_id_set
|| ifidx
!= 0) {
5759 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
5764 drv
->global
->if_add_wdevid
= p2pdev_info
.wdev_id
;
5765 drv
->global
->if_add_wdevid_set
= p2pdev_info
.wdev_id_set
;
5766 if (!is_zero_ether_addr(p2pdev_info
.macaddr
))
5767 os_memcpy(if_addr
, p2pdev_info
.macaddr
, ETH_ALEN
);
5768 wpa_printf(MSG_DEBUG
, "nl80211: New P2P Device interface %s (0x%llx) created",
5770 (long long unsigned int) p2pdev_info
.wdev_id
);
5772 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
5773 0, NULL
, NULL
, use_existing
);
5774 if (use_existing
&& ifidx
== -ENFILE
) {
5776 ifidx
= if_nametoindex(ifname
);
5777 } else if (ifidx
< 0) {
5783 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
5784 os_memcpy(if_addr
, bss
->addr
, ETH_ALEN
);
5785 else if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
5786 bss
->ifname
, if_addr
) < 0) {
5788 nl80211_remove_iface(drv
, ifidx
);
5793 #if defined(CONFIG_P2P) || defined(CONFIG_MESH)
5795 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
5796 type
== WPA_IF_P2P_GO
|| type
== WPA_IF_MESH
)) {
5797 /* Enforce unique P2P Interface Address */
5798 u8 new_addr
[ETH_ALEN
];
5800 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
5803 nl80211_remove_iface(drv
, ifidx
);
5806 if (nl80211_addr_in_use(drv
->global
, new_addr
)) {
5807 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
5808 "for %s interface", type
== WPA_IF_MESH
?
5809 "mesh" : "P2P group");
5810 if (nl80211_vif_addr(drv
, new_addr
) < 0) {
5812 nl80211_remove_iface(drv
, ifidx
);
5815 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
5818 nl80211_remove_iface(drv
, ifidx
);
5822 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
5824 #endif /* CONFIG_P2P || CONFIG_MESH */
5826 if (type
== WPA_IF_AP_BSS
) {
5827 struct i802_bss
*new_bss
= os_zalloc(sizeof(*new_bss
));
5828 if (new_bss
== NULL
) {
5830 nl80211_remove_iface(drv
, ifidx
);
5835 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
5836 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
5837 "interface %s to a bridge %s",
5840 nl80211_remove_iface(drv
, ifidx
);
5845 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
5848 nl80211_remove_iface(drv
, ifidx
);
5852 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
5853 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
5854 new_bss
->ifindex
= ifidx
;
5856 new_bss
->next
= drv
->first_bss
->next
;
5857 new_bss
->freq
= drv
->first_bss
->freq
;
5858 new_bss
->ctx
= bss_ctx
;
5859 new_bss
->added_if
= added
;
5860 drv
->first_bss
->next
= new_bss
;
5862 *drv_priv
= new_bss
;
5863 nl80211_init_bss(new_bss
);
5865 /* Subscribe management frames for this WPA_IF_AP_BSS */
5866 if (nl80211_setup_ap(new_bss
))
5871 drv
->global
->if_add_ifindex
= ifidx
;
5874 * Some virtual interfaces need to process EAPOL packets and events on
5875 * the parent interface. This is used mainly with hostapd.
5879 nlmode
== NL80211_IFTYPE_AP_VLAN
||
5880 nlmode
== NL80211_IFTYPE_WDS
||
5881 nlmode
== NL80211_IFTYPE_MONITOR
))
5882 add_ifidx(drv
, ifidx
);
5888 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
5889 enum wpa_driver_if_type type
,
5892 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5893 int ifindex
= if_nametoindex(ifname
);
5895 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
5896 __func__
, type
, ifname
, ifindex
, bss
->added_if
);
5897 if (ifindex
> 0 && (bss
->added_if
|| bss
->ifindex
!= ifindex
))
5898 nl80211_remove_iface(drv
, ifindex
);
5899 else if (ifindex
> 0 && !bss
->added_if
) {
5900 struct wpa_driver_nl80211_data
*drv2
;
5901 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
5902 struct wpa_driver_nl80211_data
, list
)
5903 del_ifidx(drv2
, ifindex
);
5906 if (type
!= WPA_IF_AP_BSS
)
5909 if (bss
->added_if_into_bridge
) {
5910 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
5912 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
5913 "interface %s from bridge %s: %s",
5914 bss
->ifname
, bss
->brname
, strerror(errno
));
5916 if (bss
->added_bridge
) {
5917 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
5918 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
5920 bss
->brname
, strerror(errno
));
5923 if (bss
!= drv
->first_bss
) {
5924 struct i802_bss
*tbss
;
5926 wpa_printf(MSG_DEBUG
, "nl80211: Not the first BSS - remove it");
5927 for (tbss
= drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
5928 if (tbss
->next
== bss
) {
5929 tbss
->next
= bss
->next
;
5930 /* Unsubscribe management frames */
5931 nl80211_teardown_ap(bss
);
5932 nl80211_destroy_bss(bss
);
5934 i802_set_iface_flags(bss
, 0);
5941 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
5942 "BSS %p in the list", __func__
, bss
);
5944 wpa_printf(MSG_DEBUG
, "nl80211: First BSS - reassign context");
5945 nl80211_teardown_ap(bss
);
5946 if (!bss
->added_if
&& !drv
->first_bss
->next
)
5947 wpa_driver_nl80211_del_beacon(drv
);
5948 nl80211_destroy_bss(bss
);
5950 i802_set_iface_flags(bss
, 0);
5951 if (drv
->first_bss
->next
) {
5952 drv
->first_bss
= drv
->first_bss
->next
;
5953 drv
->ctx
= drv
->first_bss
->ctx
;
5956 wpa_printf(MSG_DEBUG
, "nl80211: No second BSS to reassign context to");
5964 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
5966 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5967 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5969 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5970 genlmsg_attrlen(gnlh
, 0), NULL
);
5971 if (tb
[NL80211_ATTR_COOKIE
])
5972 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
5977 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
5978 unsigned int freq
, unsigned int wait
,
5979 const u8
*buf
, size_t buf_len
,
5980 u64
*cookie_out
, int no_cck
, int no_ack
,
5983 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5988 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
5989 "no_ack=%d offchanok=%d",
5990 freq
, wait
, no_cck
, no_ack
, offchanok
);
5991 wpa_hexdump(MSG_MSGDUMP
, "CMD_FRAME", buf
, buf_len
);
5993 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME
)) ||
5994 (freq
&& nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
5995 (wait
&& nla_put_u32(msg
, NL80211_ATTR_DURATION
, wait
)) ||
5996 (offchanok
&& ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
5997 drv
->test_use_roc_tx
) &&
5998 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
)) ||
5999 (no_cck
&& nla_put_flag(msg
, NL80211_ATTR_TX_NO_CCK_RATE
)) ||
6000 (no_ack
&& nla_put_flag(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
)) ||
6001 nla_put(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
))
6005 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6008 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
6009 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
6012 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
6013 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
6014 (long long unsigned int) cookie
);
6017 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
6026 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
6028 unsigned int wait_time
,
6029 const u8
*dst
, const u8
*src
,
6031 const u8
*data
, size_t data_len
,
6034 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6037 struct ieee80211_hdr
*hdr
;
6039 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
6040 "freq=%u MHz wait=%d ms no_cck=%d)",
6041 drv
->ifindex
, freq
, wait_time
, no_cck
);
6043 buf
= os_zalloc(24 + data_len
);
6046 os_memcpy(buf
+ 24, data
, data_len
);
6047 hdr
= (struct ieee80211_hdr
*) buf
;
6048 hdr
->frame_control
=
6049 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
6050 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
6051 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
6052 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
6054 if (is_ap_interface(drv
->nlmode
) &&
6055 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
6056 (int) freq
== bss
->freq
|| drv
->device_ap_sme
||
6058 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
6062 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
6064 &drv
->send_action_cookie
,
6072 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
6074 struct i802_bss
*bss
= priv
;
6075 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6079 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
6080 (long long unsigned int) drv
->send_action_cookie
);
6081 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
)) ||
6082 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
)) {
6087 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6089 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
6090 "(%s)", ret
, strerror(-ret
));
6094 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
6095 unsigned int duration
)
6097 struct i802_bss
*bss
= priv
;
6098 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6103 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
)) ||
6104 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
6105 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
)) {
6111 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6113 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
6114 "0x%llx for freq=%u MHz duration=%u",
6115 (long long unsigned int) cookie
, freq
, duration
);
6116 drv
->remain_on_chan_cookie
= cookie
;
6117 drv
->pending_remain_on_chan
= 1;
6120 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
6121 "(freq=%d duration=%u): %d (%s)",
6122 freq
, duration
, ret
, strerror(-ret
));
6127 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
6129 struct i802_bss
*bss
= priv
;
6130 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6134 if (!drv
->pending_remain_on_chan
) {
6135 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
6140 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
6142 (long long unsigned int) drv
->remain_on_chan_cookie
);
6144 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
6146 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
)) {
6151 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6154 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
6155 "%d (%s)", ret
, strerror(-ret
));
6160 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
6162 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6165 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
6166 is_ap_interface(drv
->nlmode
) && !bss
->in_deinit
&&
6169 * Do not disable Probe Request reporting that was
6170 * enabled in nl80211_setup_ap().
6172 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
6173 "Probe Request reporting nl_preq=%p while "
6174 "in AP mode", bss
->nl_preq
);
6175 } else if (bss
->nl_preq
) {
6176 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
6177 "reporting nl_preq=%p", bss
->nl_preq
);
6178 nl80211_destroy_eloop_handle(&bss
->nl_preq
);
6184 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
6185 "already on! nl_preq=%p", bss
->nl_preq
);
6189 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
6190 if (bss
->nl_preq
== NULL
)
6192 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
6193 "reporting nl_preq=%p", bss
->nl_preq
);
6195 if (nl80211_register_frame(bss
, bss
->nl_preq
,
6196 (WLAN_FC_TYPE_MGMT
<< 2) |
6197 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
6201 nl80211_register_eloop_read(&bss
->nl_preq
,
6202 wpa_driver_nl80211_event_receive
,
6208 nl_destroy_handles(&bss
->nl_preq
);
6213 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
6214 int ifindex
, int disabled
)
6217 struct nlattr
*bands
, *band
;
6220 wpa_printf(MSG_DEBUG
,
6221 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
6222 ifindex
, disabled
? "NL80211_TXRATE_LEGACY=OFDM-only" :
6223 "no NL80211_TXRATE_LEGACY constraint");
6225 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0,
6226 NL80211_CMD_SET_TX_BITRATE_MASK
);
6230 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
6235 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6236 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6237 * rates. All 5 GHz rates are left enabled.
6239 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
6241 (disabled
&& nla_put(msg
, NL80211_TXRATE_LEGACY
, 8,
6242 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
6244 nla_nest_end(msg
, band
);
6246 nla_nest_end(msg
, bands
);
6248 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6250 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
6251 "(%s)", ret
, strerror(-ret
));
6253 drv
->disabled_11b_rates
= disabled
;
6263 static int wpa_driver_nl80211_deinit_ap(void *priv
)
6265 struct i802_bss
*bss
= priv
;
6266 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6267 if (!is_ap_interface(drv
->nlmode
))
6269 wpa_driver_nl80211_del_beacon(drv
);
6270 bss
->beacon_set
= 0;
6273 * If the P2P GO interface was dynamically added, then it is
6274 * possible that the interface change to station is not possible.
6276 if (drv
->nlmode
== NL80211_IFTYPE_P2P_GO
&& bss
->if_dynamic
)
6279 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
6283 static int wpa_driver_nl80211_stop_ap(void *priv
)
6285 struct i802_bss
*bss
= priv
;
6286 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6287 if (!is_ap_interface(drv
->nlmode
))
6289 wpa_driver_nl80211_del_beacon(drv
);
6290 bss
->beacon_set
= 0;
6295 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
6297 struct i802_bss
*bss
= priv
;
6298 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6299 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
6303 * If the P2P Client interface was dynamically added, then it is
6304 * possible that the interface change to station is not possible.
6306 if (bss
->if_dynamic
)
6309 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
6313 static void wpa_driver_nl80211_resume(void *priv
)
6315 struct i802_bss
*bss
= priv
;
6317 if (i802_set_iface_flags(bss
, 1))
6318 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on resume event");
6322 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
6324 struct i802_bss
*bss
= priv
;
6325 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6329 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
6330 "hysteresis=%d", threshold
, hysteresis
);
6332 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_CQM
)) ||
6333 !(cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
)) ||
6334 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
) ||
6335 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
)) {
6339 nla_nest_end(msg
, cqm
);
6341 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6345 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
6347 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6348 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6349 struct wpa_signal_info
*sig_change
= arg
;
6351 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6352 genlmsg_attrlen(gnlh
, 0), NULL
);
6354 sig_change
->center_frq1
= -1;
6355 sig_change
->center_frq2
= -1;
6356 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
6358 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
6359 sig_change
->chanwidth
= convert2width(
6360 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
6361 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
6362 sig_change
->center_frq1
=
6363 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
6364 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
6365 sig_change
->center_frq2
=
6366 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
6373 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
6374 struct wpa_signal_info
*sig
)
6378 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_INTERFACE
);
6379 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
6383 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
6385 struct i802_bss
*bss
= priv
;
6386 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6389 os_memset(si
, 0, sizeof(*si
));
6390 res
= nl80211_get_link_signal(drv
, si
);
6394 res
= nl80211_get_channel_width(drv
, si
);
6398 return nl80211_get_link_noise(drv
, si
);
6402 static int wpa_driver_nl80211_shared_freq(void *priv
)
6404 struct i802_bss
*bss
= priv
;
6405 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6406 struct wpa_driver_nl80211_data
*driver
;
6410 * If the same PHY is in connected state with some other interface,
6411 * then retrieve the assoc freq.
6413 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
6416 dl_list_for_each(driver
, &drv
->global
->interfaces
,
6417 struct wpa_driver_nl80211_data
, list
) {
6418 if (drv
== driver
||
6419 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
6420 !driver
->associated
)
6423 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
6425 driver
->phyname
, driver
->first_bss
->ifname
,
6426 MAC2STR(driver
->first_bss
->addr
));
6427 if (is_ap_interface(driver
->nlmode
))
6428 freq
= driver
->first_bss
->freq
;
6430 freq
= nl80211_get_assoc_freq(driver
);
6431 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
6432 drv
->phyname
, freq
);
6436 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
6437 "PHY (%s) in associated state", drv
->phyname
);
6443 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
6446 struct i802_bss
*bss
= priv
;
6447 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
6452 static int nl80211_set_param(void *priv
, const char *param
)
6454 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
6459 if (os_strstr(param
, "use_p2p_group_interface=1")) {
6460 struct i802_bss
*bss
= priv
;
6461 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6463 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
6465 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
6466 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
6468 #endif /* CONFIG_P2P */
6470 if (os_strstr(param
, "use_monitor=1")) {
6471 struct i802_bss
*bss
= priv
;
6472 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6473 drv
->use_monitor
= 1;
6476 if (os_strstr(param
, "force_connect_cmd=1")) {
6477 struct i802_bss
*bss
= priv
;
6478 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6479 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_SME
;
6480 drv
->force_connect_cmd
= 1;
6483 if (os_strstr(param
, "no_offchannel_tx=1")) {
6484 struct i802_bss
*bss
= priv
;
6485 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6486 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
6487 drv
->test_use_roc_tx
= 1;
6494 static void * nl80211_global_init(void)
6496 struct nl80211_global
*global
;
6497 struct netlink_config
*cfg
;
6499 global
= os_zalloc(sizeof(*global
));
6502 global
->ioctl_sock
= -1;
6503 dl_list_init(&global
->interfaces
);
6504 global
->if_add_ifindex
= -1;
6506 cfg
= os_zalloc(sizeof(*cfg
));
6511 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
6512 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
6513 global
->netlink
= netlink_init(cfg
);
6514 if (global
->netlink
== NULL
) {
6519 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
6522 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
6523 if (global
->ioctl_sock
< 0) {
6524 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
6532 nl80211_global_deinit(global
);
6537 static void nl80211_global_deinit(void *priv
)
6539 struct nl80211_global
*global
= priv
;
6542 if (!dl_list_empty(&global
->interfaces
)) {
6543 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
6544 "nl80211_global_deinit",
6545 dl_list_len(&global
->interfaces
));
6548 if (global
->netlink
)
6549 netlink_deinit(global
->netlink
);
6551 nl_destroy_handles(&global
->nl
);
6553 if (global
->nl_event
)
6554 nl80211_destroy_eloop_handle(&global
->nl_event
);
6556 nl_cb_put(global
->nl_cb
);
6558 if (global
->ioctl_sock
>= 0)
6559 close(global
->ioctl_sock
);
6565 static const char * nl80211_get_radio_name(void *priv
)
6567 struct i802_bss
*bss
= priv
;
6568 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6569 return drv
->phyname
;
6573 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
6578 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
6579 (pmkid
&& nla_put(msg
, NL80211_ATTR_PMKID
, 16, pmkid
)) ||
6580 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))) {
6585 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
6589 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
6591 struct i802_bss
*bss
= priv
;
6592 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
6593 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
6597 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
6599 struct i802_bss
*bss
= priv
;
6600 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
6602 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
6606 static int nl80211_flush_pmkid(void *priv
)
6608 struct i802_bss
*bss
= priv
;
6609 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
6610 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
6614 static void clean_survey_results(struct survey_results
*survey_results
)
6616 struct freq_survey
*survey
, *tmp
;
6618 if (dl_list_empty(&survey_results
->survey_list
))
6621 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
6622 struct freq_survey
, list
) {
6623 dl_list_del(&survey
->list
);
6629 static void add_survey(struct nlattr
**sinfo
, u32 ifidx
,
6630 struct dl_list
*survey_list
)
6632 struct freq_survey
*survey
;
6634 survey
= os_zalloc(sizeof(struct freq_survey
));
6638 survey
->ifidx
= ifidx
;
6639 survey
->freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
6642 if (sinfo
[NL80211_SURVEY_INFO_NOISE
]) {
6643 survey
->nf
= (int8_t)
6644 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
6645 survey
->filled
|= SURVEY_HAS_NF
;
6648 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]) {
6649 survey
->channel_time
=
6650 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]);
6651 survey
->filled
|= SURVEY_HAS_CHAN_TIME
;
6654 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]) {
6655 survey
->channel_time_busy
=
6656 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]);
6657 survey
->filled
|= SURVEY_HAS_CHAN_TIME_BUSY
;
6660 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]) {
6661 survey
->channel_time_rx
=
6662 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]);
6663 survey
->filled
|= SURVEY_HAS_CHAN_TIME_RX
;
6666 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]) {
6667 survey
->channel_time_tx
=
6668 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]);
6669 survey
->filled
|= SURVEY_HAS_CHAN_TIME_TX
;
6672 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)",
6675 (unsigned long int) survey
->channel_time
,
6676 (unsigned long int) survey
->channel_time_busy
,
6677 (unsigned long int) survey
->channel_time_tx
,
6678 (unsigned long int) survey
->channel_time_rx
,
6681 dl_list_add_tail(survey_list
, &survey
->list
);
6685 static int check_survey_ok(struct nlattr
**sinfo
, u32 surveyed_freq
,
6686 unsigned int freq_filter
)
6691 return freq_filter
== surveyed_freq
;
6695 static int survey_handler(struct nl_msg
*msg
, void *arg
)
6697 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6698 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6699 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
6700 struct survey_results
*survey_results
;
6701 u32 surveyed_freq
= 0;
6704 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
6705 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
6706 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
6709 survey_results
= (struct survey_results
*) arg
;
6711 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6712 genlmsg_attrlen(gnlh
, 0), NULL
);
6714 if (!tb
[NL80211_ATTR_IFINDEX
])
6717 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
6719 if (!tb
[NL80211_ATTR_SURVEY_INFO
])
6722 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
6723 tb
[NL80211_ATTR_SURVEY_INFO
],
6727 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) {
6728 wpa_printf(MSG_ERROR
, "nl80211: Invalid survey data");
6732 surveyed_freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
6734 if (!check_survey_ok(sinfo
, surveyed_freq
,
6735 survey_results
->freq_filter
))
6738 if (survey_results
->freq_filter
&&
6739 survey_results
->freq_filter
!= surveyed_freq
) {
6740 wpa_printf(MSG_EXCESSIVE
, "nl80211: Ignoring survey data for freq %d MHz",
6745 add_survey(sinfo
, ifidx
, &survey_results
->survey_list
);
6751 static int wpa_driver_nl80211_get_survey(void *priv
, unsigned int freq
)
6753 struct i802_bss
*bss
= priv
;
6754 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6757 union wpa_event_data data
;
6758 struct survey_results
*survey_results
;
6760 os_memset(&data
, 0, sizeof(data
));
6761 survey_results
= &data
.survey_results
;
6763 dl_list_init(&survey_results
->survey_list
);
6765 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
6770 data
.survey_results
.freq_filter
= freq
;
6773 wpa_printf(MSG_DEBUG
, "nl80211: Fetch survey data");
6774 err
= send_and_recv_msgs(drv
, msg
, survey_handler
,
6779 wpa_printf(MSG_ERROR
, "nl80211: Failed to process survey data");
6781 wpa_supplicant_event(drv
->ctx
, EVENT_SURVEY
, &data
);
6783 clean_survey_results(survey_results
);
6788 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, size_t kek_len
,
6789 const u8
*kck
, size_t kck_len
,
6790 const u8
*replay_ctr
)
6792 struct i802_bss
*bss
= priv
;
6793 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6794 struct nlattr
*replay_nested
;
6798 if (!drv
->set_rekey_offload
)
6801 wpa_printf(MSG_DEBUG
, "nl80211: Set rekey offload");
6802 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
)) ||
6803 !(replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
)) ||
6804 nla_put(msg
, NL80211_REKEY_DATA_KEK
, kek_len
, kek
) ||
6805 nla_put(msg
, NL80211_REKEY_DATA_KCK
, kck_len
, kck
) ||
6806 nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
6808 nl80211_nlmsg_clear(msg
);
6813 nla_nest_end(msg
, replay_nested
);
6815 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
6816 if (ret
== -EOPNOTSUPP
) {
6817 wpa_printf(MSG_DEBUG
,
6818 "nl80211: Driver does not support rekey offload");
6819 drv
->set_rekey_offload
= 0;
6824 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
6825 const u8
*addr
, int qos
)
6827 /* send data frame to poll STA and check whether
6828 * this frame is ACKed */
6830 struct ieee80211_hdr hdr
;
6832 } STRUCT_PACKED nulldata
;
6835 /* Send data frame to poll STA and check whether this frame is ACKed */
6837 os_memset(&nulldata
, 0, sizeof(nulldata
));
6840 nulldata
.hdr
.frame_control
=
6841 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
6842 WLAN_FC_STYPE_QOS_NULL
);
6843 size
= sizeof(nulldata
);
6845 nulldata
.hdr
.frame_control
=
6846 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
6847 WLAN_FC_STYPE_NULLFUNC
);
6848 size
= sizeof(struct ieee80211_hdr
);
6851 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
6852 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
6853 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
6854 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
6856 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
6858 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
6862 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
6865 struct i802_bss
*bss
= priv
;
6866 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6869 if (!drv
->poll_command_supported
) {
6870 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
6874 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_PROBE_CLIENT
)) ||
6875 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
6880 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6884 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
6888 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_POWER_SAVE
)) ||
6889 nla_put_u32(msg
, NL80211_ATTR_PS_STATE
,
6890 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
)) {
6894 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
6898 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
6901 struct i802_bss
*bss
= priv
;
6903 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
6904 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
6906 if (opp_ps
!= -1 || ctwindow
!= -1) {
6908 wpa_driver_set_p2p_ps(priv
, legacy_ps
, opp_ps
, ctwindow
);
6909 #else /* ANDROID_P2P */
6910 return -1; /* Not yet supported */
6911 #endif /* ANDROID_P2P */
6914 if (legacy_ps
== -1)
6916 if (legacy_ps
!= 0 && legacy_ps
!= 1)
6917 return -1; /* Not yet supported */
6919 return nl80211_set_power_save(bss
, legacy_ps
);
6923 static int nl80211_start_radar_detection(void *priv
,
6924 struct hostapd_freq_params
*freq
)
6926 struct i802_bss
*bss
= priv
;
6927 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6931 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)",
6932 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
6933 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
6935 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
6936 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
6941 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_RADAR_DETECT
)) ||
6942 nl80211_put_freq_params(msg
, freq
) < 0) {
6947 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6950 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
6951 "%d (%s)", ret
, strerror(-ret
));
6957 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
6958 u8 dialog_token
, u16 status_code
,
6959 u32 peer_capab
, int initiator
, const u8
*buf
,
6962 struct i802_bss
*bss
= priv
;
6963 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6966 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
6972 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_MGMT
)) ||
6973 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
6974 nla_put_u8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
) ||
6975 nla_put_u8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
) ||
6976 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
))
6980 * The internal enum tdls_peer_capability definition is
6981 * currently identical with the nl80211 enum
6982 * nl80211_tdls_peer_capability, so no conversion is needed
6985 if (nla_put_u32(msg
, NL80211_ATTR_TDLS_PEER_CAPABILITY
,
6990 nla_put_flag(msg
, NL80211_ATTR_TDLS_INITIATOR
)) ||
6991 nla_put(msg
, NL80211_ATTR_IE
, len
, buf
))
6994 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7002 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
7004 struct i802_bss
*bss
= priv
;
7005 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7007 enum nl80211_tdls_operation nl80211_oper
;
7009 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
7013 case TDLS_DISCOVERY_REQ
:
7014 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
7017 nl80211_oper
= NL80211_TDLS_SETUP
;
7020 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
7022 case TDLS_ENABLE_LINK
:
7023 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
7025 case TDLS_DISABLE_LINK
:
7026 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
7036 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_OPER
)) ||
7037 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
) ||
7038 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
)) {
7043 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7048 nl80211_tdls_enable_channel_switch(void *priv
, const u8
*addr
, u8 oper_class
,
7049 const struct hostapd_freq_params
*params
)
7051 struct i802_bss
*bss
= priv
;
7052 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7056 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
7057 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
7060 wpa_printf(MSG_DEBUG
, "nl80211: Enable TDLS channel switch " MACSTR
7061 " oper_class=%u freq=%u",
7062 MAC2STR(addr
), oper_class
, params
->freq
);
7063 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH
);
7065 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
7066 nla_put_u8(msg
, NL80211_ATTR_OPER_CLASS
, oper_class
) ||
7067 (ret
= nl80211_put_freq_params(msg
, params
))) {
7069 wpa_printf(MSG_DEBUG
, "nl80211: Could not build TDLS chan switch");
7073 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7078 nl80211_tdls_disable_channel_switch(void *priv
, const u8
*addr
)
7080 struct i802_bss
*bss
= priv
;
7081 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7084 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
7085 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
7088 wpa_printf(MSG_DEBUG
, "nl80211: Disable TDLS channel switch " MACSTR
,
7090 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
);
7092 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7094 wpa_printf(MSG_DEBUG
,
7095 "nl80211: Could not build TDLS cancel chan switch");
7099 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7102 #endif /* CONFIG TDLS */
7105 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
7106 enum wpa_alg alg
, const u8
*addr
,
7107 int key_idx
, int set_tx
,
7108 const u8
*seq
, size_t seq_len
,
7109 const u8
*key
, size_t key_len
)
7111 struct i802_bss
*bss
= priv
;
7112 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
7113 set_tx
, seq
, seq_len
, key
, key_len
);
7117 static int driver_nl80211_scan2(void *priv
,
7118 struct wpa_driver_scan_params
*params
)
7120 struct i802_bss
*bss
= priv
;
7121 return wpa_driver_nl80211_scan(bss
, params
);
7125 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
7128 struct i802_bss
*bss
= priv
;
7129 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
7133 static int driver_nl80211_authenticate(void *priv
,
7134 struct wpa_driver_auth_params
*params
)
7136 struct i802_bss
*bss
= priv
;
7137 return wpa_driver_nl80211_authenticate(bss
, params
);
7141 static void driver_nl80211_deinit(void *priv
)
7143 struct i802_bss
*bss
= priv
;
7144 wpa_driver_nl80211_deinit(bss
);
7148 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
7151 struct i802_bss
*bss
= priv
;
7152 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
7156 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
7157 size_t data_len
, int noack
)
7159 struct i802_bss
*bss
= priv
;
7160 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
7165 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
7167 struct i802_bss
*bss
= priv
;
7168 return wpa_driver_nl80211_sta_remove(bss
, addr
, -1, 0);
7172 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
7173 const char *ifname
, int vlan_id
)
7175 struct i802_bss
*bss
= priv
;
7176 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
7180 static int driver_nl80211_read_sta_data(void *priv
,
7181 struct hostap_sta_driver_data
*data
,
7184 struct i802_bss
*bss
= priv
;
7185 return i802_read_sta_data(bss
, data
, addr
);
7189 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
7190 unsigned int wait_time
,
7191 const u8
*dst
, const u8
*src
,
7193 const u8
*data
, size_t data_len
,
7196 struct i802_bss
*bss
= priv
;
7197 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
7198 bssid
, data
, data_len
, no_cck
);
7202 static int driver_nl80211_probe_req_report(void *priv
, int report
)
7204 struct i802_bss
*bss
= priv
;
7205 return wpa_driver_nl80211_probe_req_report(bss
, report
);
7209 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
7210 const u8
*ies
, size_t ies_len
)
7214 struct i802_bss
*bss
= priv
;
7215 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7216 u16 mdid
= WPA_GET_LE16(md
);
7218 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
7219 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_UPDATE_FT_IES
)) ||
7220 nla_put(msg
, NL80211_ATTR_IE
, ies_len
, ies
) ||
7221 nla_put_u16(msg
, NL80211_ATTR_MDID
, mdid
)) {
7226 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7228 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
7229 "err=%d (%s)", ret
, strerror(-ret
));
7236 const u8
* wpa_driver_nl80211_get_macaddr(void *priv
)
7238 struct i802_bss
*bss
= priv
;
7239 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7241 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
7248 static const char * scan_state_str(enum scan_states scan_state
)
7250 switch (scan_state
) {
7253 case SCAN_REQUESTED
:
7254 return "SCAN_REQUESTED";
7256 return "SCAN_STARTED";
7257 case SCAN_COMPLETED
:
7258 return "SCAN_COMPLETED";
7260 return "SCAN_ABORTED";
7261 case SCHED_SCAN_STARTED
:
7262 return "SCHED_SCAN_STARTED";
7263 case SCHED_SCAN_STOPPED
:
7264 return "SCHED_SCAN_STOPPED";
7265 case SCHED_SCAN_RESULTS
:
7266 return "SCHED_SCAN_RESULTS";
7273 static int wpa_driver_nl80211_status(void *priv
, char *buf
, size_t buflen
)
7275 struct i802_bss
*bss
= priv
;
7276 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7283 res
= os_snprintf(pos
, end
- pos
,
7295 bss
->beacon_set
? "beacon_set=1\n" : "",
7296 bss
->added_if_into_bridge
?
7297 "added_if_into_bridge=1\n" : "",
7298 bss
->added_bridge
? "added_bridge=1\n" : "",
7299 bss
->in_deinit
? "in_deinit=1\n" : "",
7300 bss
->if_dynamic
? "if_dynamic=1\n" : "");
7301 if (os_snprintf_error(end
- pos
, res
))
7305 if (bss
->wdev_id_set
) {
7306 res
= os_snprintf(pos
, end
- pos
, "wdev_id=%llu\n",
7307 (unsigned long long) bss
->wdev_id
);
7308 if (os_snprintf_error(end
- pos
, res
))
7313 res
= os_snprintf(pos
, end
- pos
,
7315 "perm_addr=" MACSTR
"\n"
7319 "auth_bssid=" MACSTR
"\n"
7320 "auth_attempt_bssid=" MACSTR
"\n"
7321 "bssid=" MACSTR
"\n"
7322 "prev_bssid=" MACSTR
"\n"
7326 "monitor_ifidx=%d\n"
7327 "monitor_refcount=%d\n"
7328 "last_mgmt_freq=%u\n"
7329 "eapol_tx_sock=%d\n"
7330 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
7332 MAC2STR(drv
->perm_addr
),
7335 scan_state_str(drv
->scan_state
),
7336 MAC2STR(drv
->auth_bssid
),
7337 MAC2STR(drv
->auth_attempt_bssid
),
7338 MAC2STR(drv
->bssid
),
7339 MAC2STR(drv
->prev_bssid
),
7344 drv
->monitor_refcount
,
7345 drv
->last_mgmt_freq
,
7347 drv
->ignore_if_down_event
?
7348 "ignore_if_down_event=1\n" : "",
7349 drv
->scan_complete_events
?
7350 "scan_complete_events=1\n" : "",
7351 drv
->disabled_11b_rates
?
7352 "disabled_11b_rates=1\n" : "",
7353 drv
->pending_remain_on_chan
?
7354 "pending_remain_on_chan=1\n" : "",
7355 drv
->in_interface_list
? "in_interface_list=1\n" : "",
7356 drv
->device_ap_sme
? "device_ap_sme=1\n" : "",
7357 drv
->poll_command_supported
?
7358 "poll_command_supported=1\n" : "",
7359 drv
->data_tx_status
? "data_tx_status=1\n" : "",
7360 drv
->scan_for_auth
? "scan_for_auth=1\n" : "",
7361 drv
->retry_auth
? "retry_auth=1\n" : "",
7362 drv
->use_monitor
? "use_monitor=1\n" : "",
7363 drv
->ignore_next_local_disconnect
?
7364 "ignore_next_local_disconnect=1\n" : "",
7365 drv
->ignore_next_local_deauth
?
7366 "ignore_next_local_deauth=1\n" : "");
7367 if (os_snprintf_error(end
- pos
, res
))
7371 if (drv
->has_capability
) {
7372 res
= os_snprintf(pos
, end
- pos
,
7373 "capa.key_mgmt=0x%x\n"
7376 "capa.flags=0x%llx\n"
7377 "capa.rrm_flags=0x%x\n"
7378 "capa.max_scan_ssids=%d\n"
7379 "capa.max_sched_scan_ssids=%d\n"
7380 "capa.sched_scan_supported=%d\n"
7381 "capa.max_match_sets=%d\n"
7382 "capa.max_remain_on_chan=%u\n"
7383 "capa.max_stations=%u\n"
7384 "capa.probe_resp_offloads=0x%x\n"
7385 "capa.max_acl_mac_addrs=%u\n"
7386 "capa.num_multichan_concurrent=%u\n"
7387 "capa.mac_addr_rand_sched_scan_supported=%d\n"
7388 "capa.mac_addr_rand_scan_supported=%d\n",
7392 (unsigned long long) drv
->capa
.flags
,
7393 drv
->capa
.rrm_flags
,
7394 drv
->capa
.max_scan_ssids
,
7395 drv
->capa
.max_sched_scan_ssids
,
7396 drv
->capa
.sched_scan_supported
,
7397 drv
->capa
.max_match_sets
,
7398 drv
->capa
.max_remain_on_chan
,
7399 drv
->capa
.max_stations
,
7400 drv
->capa
.probe_resp_offloads
,
7401 drv
->capa
.max_acl_mac_addrs
,
7402 drv
->capa
.num_multichan_concurrent
,
7403 drv
->capa
.mac_addr_rand_sched_scan_supported
,
7404 drv
->capa
.mac_addr_rand_scan_supported
);
7405 if (os_snprintf_error(end
- pos
, res
))
7414 static int set_beacon_data(struct nl_msg
*msg
, struct beacon_data
*settings
)
7416 if ((settings
->head
&&
7417 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
,
7418 settings
->head_len
, settings
->head
)) ||
7420 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
,
7421 settings
->tail_len
, settings
->tail
)) ||
7422 (settings
->beacon_ies
&&
7423 nla_put(msg
, NL80211_ATTR_IE
,
7424 settings
->beacon_ies_len
, settings
->beacon_ies
)) ||
7425 (settings
->proberesp_ies
&&
7426 nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
7427 settings
->proberesp_ies_len
, settings
->proberesp_ies
)) ||
7428 (settings
->assocresp_ies
&&
7429 nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
7430 settings
->assocresp_ies_len
, settings
->assocresp_ies
)) ||
7431 (settings
->probe_resp
&&
7432 nla_put(msg
, NL80211_ATTR_PROBE_RESP
,
7433 settings
->probe_resp_len
, settings
->probe_resp
)))
7440 static int nl80211_switch_channel(void *priv
, struct csa_settings
*settings
)
7443 struct i802_bss
*bss
= priv
;
7444 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7445 struct nlattr
*beacon_csa
;
7448 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
7449 settings
->cs_count
, settings
->block_tx
,
7450 settings
->freq_params
.freq
, settings
->freq_params
.bandwidth
,
7451 settings
->freq_params
.center_freq1
,
7452 settings
->freq_params
.center_freq2
);
7454 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
7455 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support channel switch command");
7459 if ((drv
->nlmode
!= NL80211_IFTYPE_AP
) &&
7460 (drv
->nlmode
!= NL80211_IFTYPE_P2P_GO
))
7463 /* check settings validity */
7464 if (!settings
->beacon_csa
.tail
||
7465 ((settings
->beacon_csa
.tail_len
<=
7466 settings
->counter_offset_beacon
) ||
7467 (settings
->beacon_csa
.tail
[settings
->counter_offset_beacon
] !=
7468 settings
->cs_count
)))
7471 if (settings
->beacon_csa
.probe_resp
&&
7472 ((settings
->beacon_csa
.probe_resp_len
<=
7473 settings
->counter_offset_presp
) ||
7474 (settings
->beacon_csa
.probe_resp
[settings
->counter_offset_presp
] !=
7475 settings
->cs_count
)))
7478 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_CHANNEL_SWITCH
)) ||
7479 nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
,
7480 settings
->cs_count
) ||
7481 (ret
= nl80211_put_freq_params(msg
, &settings
->freq_params
)) ||
7482 (settings
->block_tx
&&
7483 nla_put_flag(msg
, NL80211_ATTR_CH_SWITCH_BLOCK_TX
)))
7486 /* beacon_after params */
7487 ret
= set_beacon_data(msg
, &settings
->beacon_after
);
7491 /* beacon_csa params */
7492 beacon_csa
= nla_nest_start(msg
, NL80211_ATTR_CSA_IES
);
7496 ret
= set_beacon_data(msg
, &settings
->beacon_csa
);
7500 if (nla_put_u16(msg
, NL80211_ATTR_CSA_C_OFF_BEACON
,
7501 settings
->counter_offset_beacon
) ||
7502 (settings
->beacon_csa
.probe_resp
&&
7503 nla_put_u16(msg
, NL80211_ATTR_CSA_C_OFF_PRESP
,
7504 settings
->counter_offset_presp
)))
7507 nla_nest_end(msg
, beacon_csa
);
7508 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7510 wpa_printf(MSG_DEBUG
, "nl80211: switch_channel failed err=%d (%s)",
7511 ret
, strerror(-ret
));
7519 wpa_printf(MSG_DEBUG
, "nl80211: Could not build channel switch request");
7524 static int nl80211_add_ts(void *priv
, u8 tsid
, const u8
*addr
,
7525 u8 user_priority
, u16 admitted_time
)
7527 struct i802_bss
*bss
= priv
;
7528 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7532 wpa_printf(MSG_DEBUG
,
7533 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
7534 tsid
, admitted_time
, user_priority
);
7536 if (!is_sta_interface(drv
->nlmode
))
7539 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_ADD_TX_TS
);
7541 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
7542 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
7543 nla_put_u8(msg
, NL80211_ATTR_USER_PRIO
, user_priority
) ||
7544 nla_put_u16(msg
, NL80211_ATTR_ADMITTED_TIME
, admitted_time
)) {
7549 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7551 wpa_printf(MSG_DEBUG
, "nl80211: add_ts failed err=%d (%s)",
7552 ret
, strerror(-ret
));
7557 static int nl80211_del_ts(void *priv
, u8 tsid
, const u8
*addr
)
7559 struct i802_bss
*bss
= priv
;
7560 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7564 wpa_printf(MSG_DEBUG
, "nl80211: del_ts request: tsid=%u", tsid
);
7566 if (!is_sta_interface(drv
->nlmode
))
7569 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_TX_TS
)) ||
7570 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
7571 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7576 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7578 wpa_printf(MSG_DEBUG
, "nl80211: del_ts failed err=%d (%s)",
7579 ret
, strerror(-ret
));
7584 #ifdef CONFIG_TESTING_OPTIONS
7585 static int cmd_reply_handler(struct nl_msg
*msg
, void *arg
)
7587 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7588 struct wpabuf
*buf
= arg
;
7593 if ((size_t) genlmsg_attrlen(gnlh
, 0) > wpabuf_tailroom(buf
)) {
7594 wpa_printf(MSG_INFO
, "nl80211: insufficient buffer space for reply");
7598 wpabuf_put_data(buf
, genlmsg_attrdata(gnlh
, 0),
7599 genlmsg_attrlen(gnlh
, 0));
7603 #endif /* CONFIG_TESTING_OPTIONS */
7606 static int vendor_reply_handler(struct nl_msg
*msg
, void *arg
)
7608 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7609 struct nlattr
*nl_vendor_reply
, *nl
;
7610 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7611 struct wpabuf
*buf
= arg
;
7617 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7618 genlmsg_attrlen(gnlh
, 0), NULL
);
7619 nl_vendor_reply
= tb
[NL80211_ATTR_VENDOR_DATA
];
7621 if (!nl_vendor_reply
)
7624 if ((size_t) nla_len(nl_vendor_reply
) > wpabuf_tailroom(buf
)) {
7625 wpa_printf(MSG_INFO
, "nl80211: Vendor command: insufficient buffer space for reply");
7629 nla_for_each_nested(nl
, nl_vendor_reply
, rem
) {
7630 wpabuf_put_data(buf
, nla_data(nl
), nla_len(nl
));
7637 static int nl80211_vendor_cmd(void *priv
, unsigned int vendor_id
,
7638 unsigned int subcmd
, const u8
*data
,
7639 size_t data_len
, struct wpabuf
*buf
)
7641 struct i802_bss
*bss
= priv
;
7642 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7646 #ifdef CONFIG_TESTING_OPTIONS
7647 if (vendor_id
== 0xffffffff) {
7648 msg
= nlmsg_alloc();
7652 nl80211_cmd(drv
, msg
, 0, subcmd
);
7653 if (nlmsg_append(msg
, (void *) data
, data_len
, NLMSG_ALIGNTO
) <
7656 ret
= send_and_recv_msgs(drv
, msg
, cmd_reply_handler
, buf
);
7658 wpa_printf(MSG_DEBUG
, "nl80211: command failed err=%d",
7662 #endif /* CONFIG_TESTING_OPTIONS */
7664 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_VENDOR
)) ||
7665 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, vendor_id
) ||
7666 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
) ||
7668 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, data_len
, data
)))
7671 ret
= send_and_recv_msgs(drv
, msg
, vendor_reply_handler
, buf
);
7673 wpa_printf(MSG_DEBUG
, "nl80211: vendor command failed err=%d",
7683 static int nl80211_set_qos_map(void *priv
, const u8
*qos_map_set
,
7686 struct i802_bss
*bss
= priv
;
7687 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7691 wpa_hexdump(MSG_DEBUG
, "nl80211: Setting QoS Map",
7692 qos_map_set
, qos_map_set_len
);
7694 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_QOS_MAP
)) ||
7695 nla_put(msg
, NL80211_ATTR_QOS_MAP
, qos_map_set_len
, qos_map_set
)) {
7700 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7702 wpa_printf(MSG_DEBUG
, "nl80211: Setting QoS Map failed");
7708 static int nl80211_set_wowlan(void *priv
,
7709 const struct wowlan_triggers
*triggers
)
7711 struct i802_bss
*bss
= priv
;
7712 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7714 struct nlattr
*wowlan_triggers
;
7717 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan");
7719 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WOWLAN
)) ||
7720 !(wowlan_triggers
= nla_nest_start(msg
,
7721 NL80211_ATTR_WOWLAN_TRIGGERS
)) ||
7723 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7724 (triggers
->disconnect
&&
7725 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7726 (triggers
->magic_pkt
&&
7727 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7728 (triggers
->gtk_rekey_failure
&&
7729 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7730 (triggers
->eap_identity_req
&&
7731 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7732 (triggers
->four_way_handshake
&&
7733 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7734 (triggers
->rfkill_release
&&
7735 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))) {
7740 nla_nest_end(msg
, wowlan_triggers
);
7742 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7744 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan failed");
7750 static int nl80211_roaming(void *priv
, int allowed
, const u8
*bssid
)
7752 struct i802_bss
*bss
= priv
;
7753 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7755 struct nlattr
*params
;
7757 wpa_printf(MSG_DEBUG
, "nl80211: Roaming policy: allowed=%d", allowed
);
7759 if (!drv
->roaming_vendor_cmd_avail
) {
7760 wpa_printf(MSG_DEBUG
,
7761 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
7765 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
7766 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
7767 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
7768 QCA_NL80211_VENDOR_SUBCMD_ROAMING
) ||
7769 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
7770 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY
,
7771 allowed
? QCA_ROAMING_ALLOWED_WITHIN_ESS
:
7772 QCA_ROAMING_NOT_ALLOWED
) ||
7774 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_MAC_ADDR
, ETH_ALEN
, bssid
))) {
7778 nla_nest_end(msg
, params
);
7780 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7784 static int nl80211_set_mac_addr(void *priv
, const u8
*addr
)
7786 struct i802_bss
*bss
= priv
;
7787 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7788 int new_addr
= addr
!= NULL
;
7791 addr
= drv
->perm_addr
;
7793 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) < 0)
7796 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
, addr
) < 0)
7798 wpa_printf(MSG_DEBUG
,
7799 "nl80211: failed to set_mac_addr for %s to " MACSTR
,
7800 bss
->ifname
, MAC2STR(addr
));
7801 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
7803 wpa_printf(MSG_DEBUG
,
7804 "nl80211: Could not restore interface UP after failed set_mac_addr");
7809 wpa_printf(MSG_DEBUG
, "nl80211: set_mac_addr for %s to " MACSTR
,
7810 bss
->ifname
, MAC2STR(addr
));
7811 drv
->addr_changed
= new_addr
;
7812 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
7814 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1) < 0)
7816 wpa_printf(MSG_DEBUG
,
7817 "nl80211: Could not restore interface UP after set_mac_addr");
7826 static int wpa_driver_nl80211_init_mesh(void *priv
)
7828 if (wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_MESH_POINT
)) {
7829 wpa_printf(MSG_INFO
,
7830 "nl80211: Failed to set interface into mesh mode");
7837 static int nl80211_put_mesh_id(struct nl_msg
*msg
, const u8
*mesh_id
,
7841 wpa_hexdump_ascii(MSG_DEBUG
, " * Mesh ID (SSID)",
7842 mesh_id
, mesh_id_len
);
7843 return nla_put(msg
, NL80211_ATTR_MESH_ID
, mesh_id_len
, mesh_id
);
7851 wpa_driver_nl80211_join_mesh(void *priv
,
7852 struct wpa_driver_mesh_join_params
*params
)
7854 struct i802_bss
*bss
= priv
;
7855 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7857 struct nlattr
*container
;
7861 wpa_printf(MSG_DEBUG
, "nl80211: mesh join (ifindex=%d)", drv
->ifindex
);
7862 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_MESH
);
7864 nl80211_put_freq_params(msg
, ¶ms
->freq
) ||
7865 nl80211_put_basic_rates(msg
, params
->basic_rates
) ||
7866 nl80211_put_mesh_id(msg
, params
->meshid
, params
->meshid_len
) ||
7867 nl80211_put_beacon_int(msg
, params
->beacon_int
))
7870 wpa_printf(MSG_DEBUG
, " * flags=%08X", params
->flags
);
7872 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_SETUP
);
7877 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ies
, params
->ie_len
);
7878 if (nla_put(msg
, NL80211_MESH_SETUP_IE
, params
->ie_len
,
7882 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
7883 if (params
->flags
& WPA_DRIVER_MESH_FLAG_SAE_AUTH
) {
7884 if (nla_put_u8(msg
, NL80211_MESH_SETUP_AUTH_PROTOCOL
, 0x1) ||
7885 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AUTH
))
7888 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_AMPE
) &&
7889 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AMPE
))
7891 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
) &&
7892 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_MPM
))
7894 nla_nest_end(msg
, container
);
7896 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
7900 if (!(params
->conf
.flags
& WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
) &&
7901 nla_put_u32(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, 0))
7903 if ((params
->conf
.flags
& WPA_DRIVER_MESH_FLAG_DRIVER_MPM
) &&
7904 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
7905 params
->max_peer_links
))
7909 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
7910 * the timer could disconnect stations even in that case.
7912 * Set 0xffffffff instead of 0 because NL80211_MESHCONF_PLINK_TIMEOUT
7915 timeout
= params
->conf
.peer_link_timeout
;
7916 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
) || timeout
== 0)
7917 timeout
= 0xffffffff;
7918 if (nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
, timeout
)) {
7919 wpa_printf(MSG_ERROR
, "nl80211: Failed to set PLINK_TIMEOUT");
7923 nla_nest_end(msg
, container
);
7925 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7928 wpa_printf(MSG_DEBUG
, "nl80211: mesh join failed: ret=%d (%s)",
7929 ret
, strerror(-ret
));
7933 bss
->freq
= params
->freq
.freq
;
7934 wpa_printf(MSG_DEBUG
, "nl80211: mesh join request send successfully");
7942 static int wpa_driver_nl80211_leave_mesh(void *priv
)
7944 struct i802_bss
*bss
= priv
;
7945 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7949 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave (ifindex=%d)", drv
->ifindex
);
7950 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_MESH
);
7951 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7953 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave failed: ret=%d (%s)",
7954 ret
, strerror(-ret
));
7956 wpa_printf(MSG_DEBUG
,
7957 "nl80211: mesh leave request send successfully");
7960 if (wpa_driver_nl80211_set_mode(drv
->first_bss
,
7961 NL80211_IFTYPE_STATION
)) {
7962 wpa_printf(MSG_INFO
,
7963 "nl80211: Failed to set interface into station mode");
7968 #endif /* CONFIG_MESH */
7971 static int wpa_driver_br_add_ip_neigh(void *priv
, u8 version
,
7972 const u8
*ipaddr
, int prefixlen
,
7975 #ifdef CONFIG_LIBNL3_ROUTE
7976 struct i802_bss
*bss
= priv
;
7977 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7978 struct rtnl_neigh
*rn
;
7979 struct nl_addr
*nl_ipaddr
= NULL
;
7980 struct nl_addr
*nl_lladdr
= NULL
;
7981 int family
, addrsize
;
7984 if (!ipaddr
|| prefixlen
== 0 || !addr
)
7987 if (bss
->br_ifindex
== 0) {
7988 wpa_printf(MSG_DEBUG
,
7989 "nl80211: bridge must be set before adding an ip neigh to it");
7993 if (!drv
->rtnl_sk
) {
7994 wpa_printf(MSG_DEBUG
,
7995 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8002 } else if (version
== 6) {
8009 rn
= rtnl_neigh_alloc();
8013 /* set the destination ip address for neigh */
8014 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
8015 if (nl_ipaddr
== NULL
) {
8016 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
8020 nl_addr_set_prefixlen(nl_ipaddr
, prefixlen
);
8021 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
8023 wpa_printf(MSG_DEBUG
,
8024 "nl80211: neigh set destination addr failed");
8028 /* set the corresponding lladdr for neigh */
8029 nl_lladdr
= nl_addr_build(AF_BRIDGE
, (u8
*) addr
, ETH_ALEN
);
8030 if (nl_lladdr
== NULL
) {
8031 wpa_printf(MSG_DEBUG
, "nl80211: neigh set lladdr failed");
8035 rtnl_neigh_set_lladdr(rn
, nl_lladdr
);
8037 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
8038 rtnl_neigh_set_state(rn
, NUD_PERMANENT
);
8040 res
= rtnl_neigh_add(drv
->rtnl_sk
, rn
, NLM_F_CREATE
);
8042 wpa_printf(MSG_DEBUG
,
8043 "nl80211: Adding bridge ip neigh failed: %s",
8048 nl_addr_put(nl_lladdr
);
8050 nl_addr_put(nl_ipaddr
);
8054 #else /* CONFIG_LIBNL3_ROUTE */
8056 #endif /* CONFIG_LIBNL3_ROUTE */
8060 static int wpa_driver_br_delete_ip_neigh(void *priv
, u8 version
,
8063 #ifdef CONFIG_LIBNL3_ROUTE
8064 struct i802_bss
*bss
= priv
;
8065 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8066 struct rtnl_neigh
*rn
;
8067 struct nl_addr
*nl_ipaddr
;
8068 int family
, addrsize
;
8077 } else if (version
== 6) {
8084 if (bss
->br_ifindex
== 0) {
8085 wpa_printf(MSG_DEBUG
,
8086 "nl80211: bridge must be set to delete an ip neigh");
8090 if (!drv
->rtnl_sk
) {
8091 wpa_printf(MSG_DEBUG
,
8092 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8096 rn
= rtnl_neigh_alloc();
8100 /* set the destination ip address for neigh */
8101 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
8102 if (nl_ipaddr
== NULL
) {
8103 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
8107 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
8109 wpa_printf(MSG_DEBUG
,
8110 "nl80211: neigh set destination addr failed");
8114 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
8116 res
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
8118 wpa_printf(MSG_DEBUG
,
8119 "nl80211: Deleting bridge ip neigh failed: %s",
8124 nl_addr_put(nl_ipaddr
);
8128 #else /* CONFIG_LIBNL3_ROUTE */
8130 #endif /* CONFIG_LIBNL3_ROUTE */
8134 static int linux_write_system_file(const char *path
, unsigned int val
)
8139 len
= os_snprintf(buf
, sizeof(buf
), "%u\n", val
);
8140 if (os_snprintf_error(sizeof(buf
), len
))
8143 fd
= open(path
, O_WRONLY
);
8147 if (write(fd
, buf
, len
) < 0) {
8148 wpa_printf(MSG_DEBUG
,
8149 "nl80211: Failed to write Linux system file: %s with the value of %d",
8160 static const char * drv_br_port_attr_str(enum drv_br_port_attr attr
)
8163 case DRV_BR_PORT_ATTR_PROXYARP
:
8165 case DRV_BR_PORT_ATTR_HAIRPIN_MODE
:
8166 return "hairpin_mode";
8173 static int wpa_driver_br_port_set_attr(void *priv
, enum drv_br_port_attr attr
,
8176 struct i802_bss
*bss
= priv
;
8178 const char *attr_txt
;
8180 attr_txt
= drv_br_port_attr_str(attr
);
8181 if (attr_txt
== NULL
)
8184 os_snprintf(path
, sizeof(path
), "/sys/class/net/%s/brport/%s",
8185 bss
->ifname
, attr_txt
);
8187 if (linux_write_system_file(path
, val
))
8194 static const char * drv_br_net_param_str(enum drv_br_net_param param
)
8197 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
8198 return "arp_accept";
8205 static int wpa_driver_br_set_net_param(void *priv
, enum drv_br_net_param param
,
8208 struct i802_bss
*bss
= priv
;
8210 const char *param_txt
;
8213 param_txt
= drv_br_net_param_str(param
);
8214 if (param_txt
== NULL
)
8218 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
8225 os_snprintf(path
, sizeof(path
), "/proc/sys/net/ipv%d/conf/%s/%s",
8226 ip_version
, bss
->brname
, param_txt
);
8228 if (linux_write_system_file(path
, val
))
8235 static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode
)
8238 case HOSTAPD_MODE_IEEE80211B
:
8239 return QCA_ACS_MODE_IEEE80211B
;
8240 case HOSTAPD_MODE_IEEE80211G
:
8241 return QCA_ACS_MODE_IEEE80211G
;
8242 case HOSTAPD_MODE_IEEE80211A
:
8243 return QCA_ACS_MODE_IEEE80211A
;
8244 case HOSTAPD_MODE_IEEE80211AD
:
8245 return QCA_ACS_MODE_IEEE80211AD
;
8252 static int wpa_driver_do_acs(void *priv
, struct drv_acs_params
*params
)
8254 struct i802_bss
*bss
= priv
;
8255 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8257 struct nlattr
*data
;
8261 mode
= hw_mode_to_qca_acs(params
->hw_mode
);
8265 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8266 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8267 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8268 QCA_NL80211_VENDOR_SUBCMD_DO_ACS
) ||
8269 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8270 nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE
, mode
) ||
8271 (params
->ht_enabled
&&
8272 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED
)) ||
8273 (params
->ht40_enabled
&&
8274 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED
))) {
8278 nla_nest_end(msg
, data
);
8280 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8282 wpa_printf(MSG_DEBUG
,
8283 "nl80211: Failed to invoke driver ACS function: %s",
8290 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
8292 .desc
= "Linux nl80211/cfg80211",
8293 .get_bssid
= wpa_driver_nl80211_get_bssid
,
8294 .get_ssid
= wpa_driver_nl80211_get_ssid
,
8295 .set_key
= driver_nl80211_set_key
,
8296 .scan2
= driver_nl80211_scan2
,
8297 .sched_scan
= wpa_driver_nl80211_sched_scan
,
8298 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
8299 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
8300 .deauthenticate
= driver_nl80211_deauthenticate
,
8301 .authenticate
= driver_nl80211_authenticate
,
8302 .associate
= wpa_driver_nl80211_associate
,
8303 .global_init
= nl80211_global_init
,
8304 .global_deinit
= nl80211_global_deinit
,
8305 .init2
= wpa_driver_nl80211_init
,
8306 .deinit
= driver_nl80211_deinit
,
8307 .get_capa
= wpa_driver_nl80211_get_capa
,
8308 .set_operstate
= wpa_driver_nl80211_set_operstate
,
8309 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
8310 .set_country
= wpa_driver_nl80211_set_country
,
8311 .get_country
= wpa_driver_nl80211_get_country
,
8312 .set_ap
= wpa_driver_nl80211_set_ap
,
8313 .set_acl
= wpa_driver_nl80211_set_acl
,
8314 .if_add
= wpa_driver_nl80211_if_add
,
8315 .if_remove
= driver_nl80211_if_remove
,
8316 .send_mlme
= driver_nl80211_send_mlme
,
8317 .get_hw_feature_data
= nl80211_get_hw_feature_data
,
8318 .sta_add
= wpa_driver_nl80211_sta_add
,
8319 .sta_remove
= driver_nl80211_sta_remove
,
8320 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
8321 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
8322 .hapd_init
= i802_init
,
8323 .hapd_deinit
= i802_deinit
,
8324 .set_wds_sta
= i802_set_wds_sta
,
8325 .get_seqnum
= i802_get_seqnum
,
8326 .flush
= i802_flush
,
8327 .get_inact_sec
= i802_get_inact_sec
,
8328 .sta_clear_stats
= i802_sta_clear_stats
,
8329 .set_rts
= i802_set_rts
,
8330 .set_frag
= i802_set_frag
,
8331 .set_tx_queue_params
= i802_set_tx_queue_params
,
8332 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
8333 .sta_deauth
= i802_sta_deauth
,
8334 .sta_disassoc
= i802_sta_disassoc
,
8335 .read_sta_data
= driver_nl80211_read_sta_data
,
8336 .set_freq
= i802_set_freq
,
8337 .send_action
= driver_nl80211_send_action
,
8338 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
8339 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
8340 .cancel_remain_on_channel
=
8341 wpa_driver_nl80211_cancel_remain_on_channel
,
8342 .probe_req_report
= driver_nl80211_probe_req_report
,
8343 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
8344 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
8345 .resume
= wpa_driver_nl80211_resume
,
8346 .signal_monitor
= nl80211_signal_monitor
,
8347 .signal_poll
= nl80211_signal_poll
,
8348 .send_frame
= nl80211_send_frame
,
8349 .shared_freq
= wpa_driver_nl80211_shared_freq
,
8350 .set_param
= nl80211_set_param
,
8351 .get_radio_name
= nl80211_get_radio_name
,
8352 .add_pmkid
= nl80211_add_pmkid
,
8353 .remove_pmkid
= nl80211_remove_pmkid
,
8354 .flush_pmkid
= nl80211_flush_pmkid
,
8355 .set_rekey_info
= nl80211_set_rekey_info
,
8356 .poll_client
= nl80211_poll_client
,
8357 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
8358 .start_dfs_cac
= nl80211_start_radar_detection
,
8359 .stop_ap
= wpa_driver_nl80211_stop_ap
,
8361 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
8362 .tdls_oper
= nl80211_tdls_oper
,
8363 .tdls_enable_channel_switch
= nl80211_tdls_enable_channel_switch
,
8364 .tdls_disable_channel_switch
= nl80211_tdls_disable_channel_switch
,
8365 #endif /* CONFIG_TDLS */
8366 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,
8367 .get_mac_addr
= wpa_driver_nl80211_get_macaddr
,
8368 .get_survey
= wpa_driver_nl80211_get_survey
,
8369 .status
= wpa_driver_nl80211_status
,
8370 .switch_channel
= nl80211_switch_channel
,
8372 .set_noa
= wpa_driver_set_p2p_noa
,
8373 .get_noa
= wpa_driver_get_p2p_noa
,
8374 .set_ap_wps_ie
= wpa_driver_set_ap_wps_p2p_ie
,
8375 #endif /* ANDROID_P2P */
8377 .driver_cmd
= wpa_driver_nl80211_driver_cmd
,
8378 #endif /* ANDROID */
8379 .vendor_cmd
= nl80211_vendor_cmd
,
8380 .set_qos_map
= nl80211_set_qos_map
,
8381 .set_wowlan
= nl80211_set_wowlan
,
8382 .roaming
= nl80211_roaming
,
8383 .set_mac_addr
= nl80211_set_mac_addr
,
8385 .init_mesh
= wpa_driver_nl80211_init_mesh
,
8386 .join_mesh
= wpa_driver_nl80211_join_mesh
,
8387 .leave_mesh
= wpa_driver_nl80211_leave_mesh
,
8388 #endif /* CONFIG_MESH */
8389 .br_add_ip_neigh
= wpa_driver_br_add_ip_neigh
,
8390 .br_delete_ip_neigh
= wpa_driver_br_delete_ip_neigh
,
8391 .br_port_set_attr
= wpa_driver_br_port_set_attr
,
8392 .br_set_net_param
= wpa_driver_br_set_net_param
,
8393 .add_tx_ts
= nl80211_add_ts
,
8394 .del_tx_ts
= nl80211_del_ts
,
8395 .do_acs
= wpa_driver_do_acs
,