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)
93 static struct nl_handle
* nl_create_handle(struct nl_cb
*cb
, const char *dbg
)
95 struct nl_handle
*handle
;
97 handle
= nl80211_handle_alloc(cb
);
99 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
100 "callbacks (%s)", dbg
);
104 if (genl_connect(handle
)) {
105 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
106 "netlink (%s)", dbg
);
107 nl80211_handle_destroy(handle
);
115 static void nl_destroy_handles(struct nl_handle
**handle
)
119 nl80211_handle_destroy(*handle
);
125 #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
127 #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
130 static void nl80211_register_eloop_read(struct nl_handle
**handle
,
131 eloop_sock_handler handler
,
134 #ifdef CONFIG_LIBNL20
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 */
148 #endif /* CONFIG_LIBNL20 */
150 nl_socket_set_nonblocking(*handle
);
151 eloop_register_read_sock(nl_socket_get_fd(*handle
), handler
,
152 eloop_data
, *handle
);
153 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
157 static void nl80211_destroy_eloop_handle(struct nl_handle
**handle
)
159 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
160 eloop_unregister_read_sock(nl_socket_get_fd(*handle
));
161 nl_destroy_handles(handle
);
165 static void nl80211_global_deinit(void *priv
);
166 static void nl80211_check_global(struct nl80211_global
*global
);
168 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
169 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
170 struct hostapd_freq_params
*freq
);
173 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
174 const u8
*set_addr
, int first
,
175 const char *driver_params
);
176 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
177 unsigned int freq
, unsigned int wait
,
178 const u8
*buf
, size_t buf_len
, u64
*cookie
,
179 int no_cck
, int no_ack
, int offchanok
,
180 const u16
*csa_offs
, size_t csa_offs_len
);
181 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
186 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
188 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
190 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
193 static int nl80211_set_channel(struct i802_bss
*bss
,
194 struct hostapd_freq_params
*freq
, int set_chan
);
195 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
196 int ifindex
, int disabled
);
198 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
201 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
);
202 static int nl80211_set_param(void *priv
, const char *param
);
204 static int nl80211_put_mesh_config(struct nl_msg
*msg
,
205 struct wpa_driver_mesh_bss_params
*params
);
206 #endif /* CONFIG_MESH */
207 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
211 /* Converts nl80211_chan_width to a common format */
212 enum chan_width
convert2width(int width
)
215 case NL80211_CHAN_WIDTH_20_NOHT
:
216 return CHAN_WIDTH_20_NOHT
;
217 case NL80211_CHAN_WIDTH_20
:
218 return CHAN_WIDTH_20
;
219 case NL80211_CHAN_WIDTH_40
:
220 return CHAN_WIDTH_40
;
221 case NL80211_CHAN_WIDTH_80
:
222 return CHAN_WIDTH_80
;
223 case NL80211_CHAN_WIDTH_80P80
:
224 return CHAN_WIDTH_80P80
;
225 case NL80211_CHAN_WIDTH_160
:
226 return CHAN_WIDTH_160
;
228 return CHAN_WIDTH_UNKNOWN
;
232 int is_ap_interface(enum nl80211_iftype nlmode
)
234 return nlmode
== NL80211_IFTYPE_AP
||
235 nlmode
== NL80211_IFTYPE_P2P_GO
;
239 int is_sta_interface(enum nl80211_iftype nlmode
)
241 return nlmode
== NL80211_IFTYPE_STATION
||
242 nlmode
== NL80211_IFTYPE_P2P_CLIENT
;
246 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
248 return nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
249 nlmode
== NL80211_IFTYPE_P2P_GO
;
253 struct i802_bss
* get_bss_ifindex(struct wpa_driver_nl80211_data
*drv
,
256 struct i802_bss
*bss
;
258 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
259 if (bss
->ifindex
== ifindex
)
267 static int is_mesh_interface(enum nl80211_iftype nlmode
)
269 return nlmode
== NL80211_IFTYPE_MESH_POINT
;
273 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
276 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
278 os_memset(drv
->bssid
, 0, ETH_ALEN
);
283 static int ack_handler(struct nl_msg
*msg
, void *arg
)
290 static int finish_handler(struct nl_msg
*msg
, void *arg
)
297 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
306 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
312 static void nl80211_nlmsg_clear(struct nl_msg
*msg
)
315 * Clear nlmsg data, e.g., to make sure key material is not left in
316 * heap memory for unnecessarily long time.
319 struct nlmsghdr
*hdr
= nlmsg_hdr(msg
);
320 void *data
= nlmsg_data(hdr
);
322 * This would use nlmsg_datalen() or the older nlmsg_len() if
323 * only libnl were to maintain a stable API.. Neither will work
324 * with all released versions, so just calculate the length
327 int len
= hdr
->nlmsg_len
- NLMSG_HDRLEN
;
329 os_memset(data
, 0, len
);
334 static int send_and_recv(struct nl80211_global
*global
,
335 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
336 int (*valid_handler
)(struct nl_msg
*, void *),
345 cb
= nl_cb_clone(global
->nl_cb
);
349 err
= nl_send_auto_complete(nl_handle
, msg
);
355 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
356 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
357 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
360 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
361 valid_handler
, valid_data
);
364 int res
= nl_recvmsgs(nl_handle
, cb
);
367 "nl80211: %s->nl_recvmsgs failed: %d",
373 if (!valid_handler
&& valid_data
== (void *) -1)
374 nl80211_nlmsg_clear(msg
);
380 int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
382 int (*valid_handler
)(struct nl_msg
*, void *),
385 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
386 valid_handler
, valid_data
);
396 static int family_handler(struct nl_msg
*msg
, void *arg
)
398 struct family_data
*res
= arg
;
399 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
400 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
401 struct nlattr
*mcgrp
;
404 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
405 genlmsg_attrlen(gnlh
, 0), NULL
);
406 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
409 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
410 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
411 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
412 nla_len(mcgrp
), NULL
);
413 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
414 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
415 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
417 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
419 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
427 static int nl_get_multicast_id(struct nl80211_global
*global
,
428 const char *family
, const char *group
)
432 struct family_data res
= { group
, -ENOENT
};
437 if (!genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
438 0, 0, CTRL_CMD_GETFAMILY
, 0) ||
439 nla_put_string(msg
, CTRL_ATTR_FAMILY_NAME
, family
)) {
444 ret
= send_and_recv(global
, global
->nl
, msg
, family_handler
, &res
);
451 void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
452 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
456 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
461 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
463 if (bss
->wdev_id_set
)
464 return nla_put_u64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
465 return nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
469 struct nl_msg
* nl80211_cmd_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
477 if (!nl80211_cmd(bss
->drv
, msg
, flags
, cmd
) ||
478 nl80211_set_iface_id(msg
, bss
) < 0) {
487 static struct nl_msg
*
488 nl80211_ifindex_msg(struct wpa_driver_nl80211_data
*drv
, int ifindex
,
489 int flags
, uint8_t cmd
)
497 if (!nl80211_cmd(drv
, msg
, flags
, cmd
) ||
498 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, ifindex
)) {
507 struct nl_msg
* nl80211_drv_msg(struct wpa_driver_nl80211_data
*drv
, int flags
,
510 return nl80211_ifindex_msg(drv
, drv
->ifindex
, flags
, cmd
);
514 struct nl_msg
* nl80211_bss_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
516 return nl80211_ifindex_msg(bss
->drv
, bss
->ifindex
, flags
, cmd
);
520 struct wiphy_idx_data
{
522 enum nl80211_iftype nlmode
;
527 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
529 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
530 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
531 struct wiphy_idx_data
*info
= arg
;
533 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
534 genlmsg_attrlen(gnlh
, 0), NULL
);
536 if (tb
[NL80211_ATTR_WIPHY
])
537 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
539 if (tb
[NL80211_ATTR_IFTYPE
])
540 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
542 if (tb
[NL80211_ATTR_MAC
] && info
->macaddr
)
543 os_memcpy(info
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
550 int nl80211_get_wiphy_index(struct i802_bss
*bss
)
553 struct wiphy_idx_data data
= {
558 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
561 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
562 return data
.wiphy_idx
;
567 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
570 struct wiphy_idx_data data
= {
571 .nlmode
= NL80211_IFTYPE_UNSPECIFIED
,
575 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
576 return NL80211_IFTYPE_UNSPECIFIED
;
578 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
580 return NL80211_IFTYPE_UNSPECIFIED
;
584 static int nl80211_get_macaddr(struct i802_bss
*bss
)
587 struct wiphy_idx_data data
= {
588 .macaddr
= bss
->addr
,
591 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
594 return send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
);
598 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
599 struct nl80211_wiphy_data
*w
)
608 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
) ||
609 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
)) {
614 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
616 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
617 "failed: ret=%d (%s)",
618 ret
, strerror(-ret
));
624 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
626 struct nl80211_wiphy_data
*w
= eloop_ctx
;
629 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
631 res
= nl_recvmsgs(handle
, w
->nl_cb
);
633 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
639 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
641 struct nl80211_wiphy_data
*w
= arg
;
642 struct wpa_driver_nl80211_data
*drv
;
643 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
644 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
645 union wpa_event_data event
;
647 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
648 genlmsg_attrlen(gnlh
, 0), NULL
);
650 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
651 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
656 if (!tb
[NL80211_ATTR_FRAME
])
659 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
661 os_memset(&event
, 0, sizeof(event
));
662 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
663 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
664 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
671 static struct nl80211_wiphy_data
*
672 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
674 static DEFINE_DL_LIST(nl80211_wiphys
);
675 struct nl80211_wiphy_data
*w
;
676 int wiphy_idx
, found
= 0;
677 struct i802_bss
*tmp_bss
;
679 if (bss
->wiphy_data
!= NULL
)
680 return bss
->wiphy_data
;
682 wiphy_idx
= nl80211_get_wiphy_index(bss
);
684 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
685 if (w
->wiphy_idx
== wiphy_idx
)
690 w
= os_zalloc(sizeof(*w
));
693 w
->wiphy_idx
= wiphy_idx
;
694 dl_list_init(&w
->bsss
);
695 dl_list_init(&w
->drvs
);
697 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
702 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
703 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
706 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
708 if (w
->nl_beacons
== NULL
) {
713 if (nl80211_register_beacons(bss
->drv
, w
)) {
714 nl_destroy_handles(&w
->nl_beacons
);
719 nl80211_register_eloop_read(&w
->nl_beacons
, nl80211_recv_beacons
, w
);
721 dl_list_add(&nl80211_wiphys
, &w
->list
);
724 /* drv entry for this bss already there? */
725 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
726 if (tmp_bss
->drv
== bss
->drv
) {
733 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
735 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
741 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
743 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
744 struct i802_bss
*tmp_bss
;
749 bss
->wiphy_data
= NULL
;
750 dl_list_del(&bss
->wiphy_list
);
752 /* still any for this drv present? */
753 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
754 if (tmp_bss
->drv
== bss
->drv
) {
759 /* if not remove it */
761 dl_list_del(&bss
->drv
->wiphy_list
);
763 if (!dl_list_empty(&w
->bsss
))
766 nl80211_destroy_eloop_handle(&w
->nl_beacons
);
769 dl_list_del(&w
->list
);
774 static unsigned int nl80211_get_ifindex(void *priv
)
776 struct i802_bss
*bss
= priv
;
777 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
783 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
785 struct i802_bss
*bss
= priv
;
786 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
787 if (!drv
->associated
)
789 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
794 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
796 struct i802_bss
*bss
= priv
;
797 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
798 if (!drv
->associated
)
800 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
801 return drv
->ssid_len
;
805 static void wpa_driver_nl80211_event_newlink(
806 struct nl80211_global
*global
, struct wpa_driver_nl80211_data
*drv
,
807 int ifindex
, const char *ifname
)
809 union wpa_event_data event
;
811 if (drv
&& os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
812 if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
813 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
814 drv
->first_bss
->ifname
);
817 if (!drv
->if_removed
)
819 wpa_printf(MSG_DEBUG
, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
820 drv
->first_bss
->ifname
);
824 os_memset(&event
, 0, sizeof(event
));
825 event
.interface_status
.ifindex
= ifindex
;
826 os_strlcpy(event
.interface_status
.ifname
, ifname
,
827 sizeof(event
.interface_status
.ifname
));
828 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
830 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
832 wpa_supplicant_event_global(global
->ctx
, EVENT_INTERFACE_STATUS
,
837 static void wpa_driver_nl80211_event_dellink(
838 struct nl80211_global
*global
, struct wpa_driver_nl80211_data
*drv
,
839 int ifindex
, const char *ifname
)
841 union wpa_event_data event
;
843 if (drv
&& os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
844 if (drv
->if_removed
) {
845 wpa_printf(MSG_DEBUG
, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
849 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
853 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed",
857 os_memset(&event
, 0, sizeof(event
));
858 event
.interface_status
.ifindex
= ifindex
;
859 os_strlcpy(event
.interface_status
.ifname
, ifname
,
860 sizeof(event
.interface_status
.ifname
));
861 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
863 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
865 wpa_supplicant_event_global(global
->ctx
, EVENT_INTERFACE_STATUS
,
870 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
873 int attrlen
, rta_len
;
877 attr
= (struct rtattr
*) buf
;
879 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
880 while (RTA_OK(attr
, attrlen
)) {
881 if (attr
->rta_type
== IFLA_IFNAME
) {
882 if (os_strcmp(((char *) attr
) + rta_len
,
883 drv
->first_bss
->ifname
) == 0)
888 attr
= RTA_NEXT(attr
, attrlen
);
895 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
896 int ifindex
, u8
*buf
, size_t len
)
898 if (drv
->ifindex
== ifindex
)
901 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
902 nl80211_check_global(drv
->global
);
903 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
905 wpa_driver_nl80211_finish_drv_init(drv
, NULL
, 0, NULL
);
913 static struct wpa_driver_nl80211_data
*
914 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
916 struct wpa_driver_nl80211_data
*drv
;
917 dl_list_for_each(drv
, &global
->interfaces
,
918 struct wpa_driver_nl80211_data
, list
) {
919 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
920 have_ifidx(drv
, idx
, IFIDX_ANY
))
927 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
928 struct ifinfomsg
*ifi
,
931 struct nl80211_global
*global
= ctx
;
932 struct wpa_driver_nl80211_data
*drv
;
936 char namebuf
[IFNAMSIZ
];
937 char ifname
[IFNAMSIZ
+ 1];
938 char extra
[100], *pos
, *end
;
942 end
= pos
+ sizeof(extra
);
946 attr
= (struct rtattr
*) buf
;
947 while (RTA_OK(attr
, attrlen
)) {
948 switch (attr
->rta_type
) {
950 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
952 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
953 ifname
[RTA_PAYLOAD(attr
)] = '\0';
956 brid
= nla_get_u32((struct nlattr
*) attr
);
957 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
960 pos
+= os_snprintf(pos
, end
- pos
, " wext");
963 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
964 nla_get_u32((struct nlattr
*) attr
));
967 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
968 nla_get_u32((struct nlattr
*) attr
));
971 attr
= RTA_NEXT(attr
, attrlen
);
973 extra
[sizeof(extra
) - 1] = '\0';
975 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
976 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
978 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
979 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
980 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
981 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
983 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
987 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
989 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
990 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) > 0) {
991 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
992 "event since interface %s is up", namebuf
);
993 drv
->ignore_if_down_event
= 0;
996 wpa_printf(MSG_DEBUG
, "nl80211: Interface down (%s/%s)",
998 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) != 0) {
999 wpa_printf(MSG_DEBUG
,
1000 "nl80211: Not the main interface (%s) - do not indicate interface down",
1001 drv
->first_bss
->ifname
);
1002 } else if (drv
->ignore_if_down_event
) {
1003 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1004 "event generated by mode change");
1005 drv
->ignore_if_down_event
= 0;
1007 drv
->if_disabled
= 1;
1008 wpa_supplicant_event(drv
->ctx
,
1009 EVENT_INTERFACE_DISABLED
, NULL
);
1012 * Try to get drv again, since it may be removed as
1013 * part of the EVENT_INTERFACE_DISABLED handling for
1014 * dynamic interfaces
1016 drv
= nl80211_find_drv(global
, ifi
->ifi_index
,
1023 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
1024 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1025 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) == 0) {
1026 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1027 "event since interface %s is down",
1029 } else if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
1030 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1031 "event since interface %s does not exist",
1032 drv
->first_bss
->ifname
);
1033 } else if (drv
->if_removed
) {
1034 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1035 "event since interface %s is marked "
1036 "removed", drv
->first_bss
->ifname
);
1038 struct i802_bss
*bss
;
1041 /* Re-read MAC address as it may have changed */
1042 bss
= get_bss_ifindex(drv
, ifi
->ifi_index
);
1044 linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
1045 bss
->ifname
, addr
) < 0) {
1046 wpa_printf(MSG_DEBUG
,
1047 "nl80211: %s: failed to re-read MAC address",
1050 os_memcmp(addr
, bss
->addr
, ETH_ALEN
) != 0) {
1051 wpa_printf(MSG_DEBUG
,
1052 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1053 MACSTR
" to " MACSTR
,
1054 ifi
->ifi_index
, bss
->ifname
,
1057 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
1060 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
1061 drv
->if_disabled
= 0;
1062 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1068 * Some drivers send the association event before the operup event--in
1069 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1070 * fails. This will hit us when wpa_supplicant does not need to do
1071 * IEEE 802.1X authentication
1073 if (drv
->operstate
== 1 &&
1074 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1075 !(ifi
->ifi_flags
& IFF_RUNNING
)) {
1076 wpa_printf(MSG_DEBUG
, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
1077 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1083 wpa_driver_nl80211_event_newlink(global
, drv
, ifi
->ifi_index
,
1086 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
&& drv
) {
1087 struct i802_bss
*bss
;
1089 /* device has been added to bridge */
1090 if (!if_indextoname(brid
, namebuf
)) {
1091 wpa_printf(MSG_DEBUG
,
1092 "nl80211: Could not find bridge ifname for ifindex %u",
1096 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1098 add_ifidx(drv
, brid
, ifi
->ifi_index
);
1100 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
1101 if (os_strcmp(ifname
, bss
->ifname
) == 0) {
1102 os_strlcpy(bss
->brname
, namebuf
, IFNAMSIZ
);
1110 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1111 struct ifinfomsg
*ifi
,
1112 u8
*buf
, size_t len
)
1114 struct nl80211_global
*global
= ctx
;
1115 struct wpa_driver_nl80211_data
*drv
;
1117 struct rtattr
*attr
;
1119 char ifname
[IFNAMSIZ
+ 1];
1120 char extra
[100], *pos
, *end
;
1124 end
= pos
+ sizeof(extra
);
1128 attr
= (struct rtattr
*) buf
;
1129 while (RTA_OK(attr
, attrlen
)) {
1130 switch (attr
->rta_type
) {
1132 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
1134 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
1135 ifname
[RTA_PAYLOAD(attr
)] = '\0';
1138 brid
= nla_get_u32((struct nlattr
*) attr
);
1139 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
1141 case IFLA_OPERSTATE
:
1142 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
1143 nla_get_u32((struct nlattr
*) attr
));
1146 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
1147 nla_get_u32((struct nlattr
*) attr
));
1150 attr
= RTA_NEXT(attr
, attrlen
);
1152 extra
[sizeof(extra
) - 1] = '\0';
1154 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1155 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
1157 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1158 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1159 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1160 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1162 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1164 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
&& drv
) {
1165 /* device has been removed from bridge */
1166 char namebuf
[IFNAMSIZ
];
1168 if (!if_indextoname(brid
, namebuf
)) {
1169 wpa_printf(MSG_DEBUG
,
1170 "nl80211: Could not find bridge ifname for ifindex %u",
1173 wpa_printf(MSG_DEBUG
,
1174 "nl80211: Remove ifindex %u for bridge %s",
1177 del_ifidx(drv
, brid
, ifi
->ifi_index
);
1180 if (ifi
->ifi_family
!= AF_BRIDGE
|| !brid
)
1181 wpa_driver_nl80211_event_dellink(global
, drv
, ifi
->ifi_index
,
1186 struct nl80211_get_assoc_freq_arg
{
1187 struct wpa_driver_nl80211_data
*drv
;
1188 unsigned int assoc_freq
;
1189 unsigned int ibss_freq
;
1190 u8 assoc_bssid
[ETH_ALEN
];
1191 u8 assoc_ssid
[SSID_MAX_LEN
];
1195 static int nl80211_get_assoc_freq_handler(struct nl_msg
*msg
, void *arg
)
1197 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1198 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1199 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
1200 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
1201 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
1202 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
1203 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
1204 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
1206 struct nl80211_get_assoc_freq_arg
*ctx
= arg
;
1207 enum nl80211_bss_status status
;
1209 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1210 genlmsg_attrlen(gnlh
, 0), NULL
);
1211 if (!tb
[NL80211_ATTR_BSS
] ||
1212 nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
1214 !bss
[NL80211_BSS_STATUS
])
1217 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
1218 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1219 bss
[NL80211_BSS_FREQUENCY
]) {
1220 ctx
->assoc_freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
1221 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
1224 if (status
== NL80211_BSS_STATUS_IBSS_JOINED
&&
1225 bss
[NL80211_BSS_FREQUENCY
]) {
1226 ctx
->ibss_freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
1227 wpa_printf(MSG_DEBUG
, "nl80211: IBSS-joined on %u MHz",
1230 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1231 bss
[NL80211_BSS_BSSID
]) {
1232 os_memcpy(ctx
->assoc_bssid
,
1233 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
1234 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
1235 MACSTR
, MAC2STR(ctx
->assoc_bssid
));
1238 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1239 bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
1240 const u8
*ie
, *ssid
;
1243 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
1244 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
1245 ssid
= get_ie(ie
, ie_len
, WLAN_EID_SSID
);
1246 if (ssid
&& ssid
[1] > 0 && ssid
[1] <= SSID_MAX_LEN
) {
1247 ctx
->assoc_ssid_len
= ssid
[1];
1248 os_memcpy(ctx
->assoc_ssid
, ssid
+ 2, ssid
[1]);
1256 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data
*drv
, u8
*ssid
)
1260 struct nl80211_get_assoc_freq_arg arg
;
1262 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1263 os_memset(&arg
, 0, sizeof(arg
));
1265 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_assoc_freq_handler
,
1268 os_memcpy(ssid
, arg
.assoc_ssid
, arg
.assoc_ssid_len
);
1269 return arg
.assoc_ssid_len
;
1271 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d (%s)",
1272 ret
, strerror(-ret
));
1277 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1281 struct nl80211_get_assoc_freq_arg arg
;
1283 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1284 os_memset(&arg
, 0, sizeof(arg
));
1286 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_assoc_freq_handler
,
1289 unsigned int freq
= drv
->nlmode
== NL80211_IFTYPE_ADHOC
?
1290 arg
.ibss_freq
: arg
.assoc_freq
;
1291 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1292 "associated BSS from scan results: %u MHz", freq
);
1294 drv
->assoc_freq
= freq
;
1295 return drv
->assoc_freq
;
1297 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1298 "(%s)", ret
, strerror(-ret
));
1299 return drv
->assoc_freq
;
1303 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1305 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1306 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1307 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1308 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1309 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1310 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
1311 [NL80211_STA_INFO_BEACON_SIGNAL_AVG
] = { .type
= NLA_U8
},
1313 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1314 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1315 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1316 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1317 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1318 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1320 struct wpa_signal_info
*sig_change
= arg
;
1322 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1323 genlmsg_attrlen(gnlh
, 0), NULL
);
1324 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1325 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1326 tb
[NL80211_ATTR_STA_INFO
], policy
))
1328 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1331 sig_change
->current_signal
=
1332 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1334 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
1335 sig_change
->avg_signal
=
1336 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
1338 sig_change
->avg_signal
= 0;
1340 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
1341 sig_change
->avg_beacon_signal
=
1343 nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]);
1345 sig_change
->avg_beacon_signal
= 0;
1347 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1348 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1349 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1351 sig_change
->current_txrate
= 0;
1353 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1354 sig_change
->current_txrate
=
1356 NL80211_RATE_INFO_BITRATE
]) * 100;
1365 int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1366 struct wpa_signal_info
*sig
)
1370 sig
->current_signal
= -9999;
1371 sig
->current_txrate
= 0;
1373 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_STATION
)) ||
1374 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
)) {
1379 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1383 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1385 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1386 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1387 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1388 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1389 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1390 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1392 struct wpa_signal_info
*sig_change
= arg
;
1394 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1395 genlmsg_attrlen(gnlh
, 0), NULL
);
1397 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1398 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1402 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1403 tb
[NL80211_ATTR_SURVEY_INFO
],
1405 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1410 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1413 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1414 sig_change
->frequency
)
1417 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1420 sig_change
->current_noise
=
1421 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1427 int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1428 struct wpa_signal_info
*sig_change
)
1432 sig_change
->current_noise
= 9999;
1433 sig_change
->frequency
= drv
->assoc_freq
;
1435 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1436 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1440 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
1443 struct nl_cb
*cb
= eloop_ctx
;
1446 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
1448 res
= nl_recvmsgs(handle
, cb
);
1450 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
1457 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1458 * @priv: driver_nl80211 private data
1459 * @alpha2_arg: country to which to switch to
1460 * Returns: 0 on success, -1 on failure
1462 * This asks nl80211 to set the regulatory domain for given
1463 * country ISO / IEC alpha2.
1465 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
1467 struct i802_bss
*bss
= priv
;
1468 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1472 msg
= nlmsg_alloc();
1476 alpha2
[0] = alpha2_arg
[0];
1477 alpha2
[1] = alpha2_arg
[1];
1480 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
) ||
1481 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
)) {
1485 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
1491 static int nl80211_get_country(struct nl_msg
*msg
, void *arg
)
1494 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
1495 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1497 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1498 genlmsg_attrlen(gnlh
, 0), NULL
);
1499 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
]) {
1500 wpa_printf(MSG_DEBUG
, "nl80211: No country information available");
1503 os_strlcpy(alpha2
, nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]), 3);
1508 static int wpa_driver_nl80211_get_country(void *priv
, char *alpha2
)
1510 struct i802_bss
*bss
= priv
;
1511 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1515 msg
= nlmsg_alloc();
1519 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
1521 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_country
, alpha2
);
1529 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
1533 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1534 if (global
->nl_cb
== NULL
) {
1535 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
1540 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
1541 if (global
->nl
== NULL
)
1544 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
1545 if (global
->nl80211_id
< 0) {
1546 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
1551 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
1552 if (global
->nl_event
== NULL
)
1555 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
1557 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1559 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1560 "membership for scan events: %d (%s)",
1561 ret
, strerror(-ret
));
1565 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
1567 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1569 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1570 "membership for mlme events: %d (%s)",
1571 ret
, strerror(-ret
));
1575 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
1577 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1579 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1580 "membership for regulatory events: %d (%s)",
1581 ret
, strerror(-ret
));
1582 /* Continue without regulatory events */
1585 ret
= nl_get_multicast_id(global
, "nl80211", "vendor");
1587 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1589 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1590 "membership for vendor events: %d (%s)",
1591 ret
, strerror(-ret
));
1592 /* Continue without vendor events */
1595 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1596 no_seq_check
, NULL
);
1597 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1598 process_global_event
, global
);
1600 nl80211_register_eloop_read(&global
->nl_event
,
1601 wpa_driver_nl80211_event_receive
,
1607 nl_destroy_handles(&global
->nl_event
);
1608 nl_destroy_handles(&global
->nl
);
1609 nl_cb_put(global
->nl_cb
);
1610 global
->nl_cb
= NULL
;
1615 static void nl80211_check_global(struct nl80211_global
*global
)
1617 struct nl_handle
*handle
;
1618 const char *groups
[] = { "scan", "mlme", "regulatory", "vendor", NULL
};
1623 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1624 * and all registration having been cleared.
1626 handle
= (void *) (((intptr_t) global
->nl_event
) ^
1627 ELOOP_SOCKET_INVALID
);
1629 for (i
= 0; groups
[i
]; i
++) {
1630 ret
= nl_get_multicast_id(global
, "nl80211", groups
[i
]);
1632 ret
= nl_socket_add_membership(handle
, ret
);
1634 wpa_printf(MSG_INFO
,
1635 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1636 groups
[i
], ret
, strerror(-ret
));
1642 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
1644 struct wpa_driver_nl80211_data
*drv
= ctx
;
1646 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
1649 * rtnetlink ifdown handler will report interfaces other than the P2P
1650 * Device interface as disabled.
1652 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
1653 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
1657 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
1659 struct wpa_driver_nl80211_data
*drv
= ctx
;
1660 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
1661 if (i802_set_iface_flags(drv
->first_bss
, 1)) {
1662 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
1663 "after rfkill unblock");
1667 if (is_p2p_net_interface(drv
->nlmode
))
1668 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
1671 * rtnetlink ifup handler will report interfaces other than the P2P
1672 * Device interface as enabled.
1674 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
1675 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
, NULL
);
1679 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
1683 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
1688 struct cmsghdr
*cmsg
;
1689 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
1690 union wpa_event_data event
;
1692 memset(&msg
, 0, sizeof(msg
));
1693 msg
.msg_iov
= &entry
;
1695 entry
.iov_base
= data
;
1696 entry
.iov_len
= sizeof(data
);
1697 msg
.msg_control
= &control
;
1698 msg
.msg_controllen
= sizeof(control
);
1700 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
1701 /* if error or not fitting 802.3 header, return */
1705 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
1707 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
1708 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
1712 ack
= (void *)CMSG_DATA(cmsg
);
1716 if (cmsg
->cmsg_level
== SOL_PACKET
&&
1717 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
1718 struct sock_extended_err
*err
=
1719 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
1721 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
1726 if (!found_ee
|| !found_wifi
)
1729 memset(&event
, 0, sizeof(event
));
1730 event
.eapol_tx_status
.dst
= data
;
1731 event
.eapol_tx_status
.data
= data
+ 14;
1732 event
.eapol_tx_status
.data_len
= res
- 14;
1733 event
.eapol_tx_status
.ack
= acked
;
1734 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
1738 static int nl80211_init_bss(struct i802_bss
*bss
)
1740 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1744 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1745 no_seq_check
, NULL
);
1746 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1747 process_bss_event
, bss
);
1753 static void nl80211_destroy_bss(struct i802_bss
*bss
)
1755 nl_cb_put(bss
->nl_cb
);
1761 wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data
*drv
)
1763 struct rfkill_config
*rcfg
;
1768 rcfg
= os_zalloc(sizeof(*rcfg
));
1774 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
1775 * not associated with a netdev, so use the name of some other interface
1776 * sharing the same wiphy as the P2P Device interface.
1778 * Note: This is valid, as a P2P Device interface is always dynamically
1779 * created and is created only once another wpa_s interface was added.
1781 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
1782 struct nl80211_global
*global
= drv
->global
;
1783 struct wpa_driver_nl80211_data
*tmp1
;
1785 dl_list_for_each(tmp1
, &global
->interfaces
,
1786 struct wpa_driver_nl80211_data
, list
) {
1787 if (drv
== tmp1
|| drv
->wiphy_idx
!= tmp1
->wiphy_idx
||
1791 wpa_printf(MSG_DEBUG
,
1792 "nl80211: Use (%s) to initialize P2P Device rfkill",
1793 tmp1
->first_bss
->ifname
);
1794 os_strlcpy(rcfg
->ifname
, tmp1
->first_bss
->ifname
,
1795 sizeof(rcfg
->ifname
));
1799 os_strlcpy(rcfg
->ifname
, drv
->first_bss
->ifname
,
1800 sizeof(rcfg
->ifname
));
1803 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
1804 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
1805 drv
->rfkill
= rfkill_init(rcfg
);
1807 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
1813 static void * wpa_driver_nl80211_drv_init(void *ctx
, const char *ifname
,
1814 void *global_priv
, int hostapd
,
1816 const char *driver_params
)
1818 struct wpa_driver_nl80211_data
*drv
;
1819 struct i802_bss
*bss
;
1821 if (global_priv
== NULL
)
1823 drv
= os_zalloc(sizeof(*drv
));
1826 drv
->global
= global_priv
;
1828 drv
->hostapd
= !!hostapd
;
1829 drv
->eapol_sock
= -1;
1832 * There is no driver capability flag for this, so assume it is
1833 * supported and disable this on first attempt to use if the driver
1834 * rejects the command due to missing support.
1836 drv
->set_rekey_offload
= 1;
1838 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
1839 drv
->if_indices
= drv
->default_if_indices
;
1840 drv
->if_indices_reason
= drv
->default_if_indices_reason
;
1842 drv
->first_bss
= os_zalloc(sizeof(*drv
->first_bss
));
1843 if (!drv
->first_bss
) {
1847 bss
= drv
->first_bss
;
1851 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
1852 drv
->monitor_ifidx
= -1;
1853 drv
->monitor_sock
= -1;
1854 drv
->eapol_tx_sock
= -1;
1855 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
1857 if (nl80211_init_bss(bss
))
1860 if (wpa_driver_nl80211_finish_drv_init(drv
, set_addr
, 1, driver_params
))
1863 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
1864 if (drv
->eapol_tx_sock
< 0)
1867 if (drv
->data_tx_status
) {
1870 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
1871 &enabled
, sizeof(enabled
)) < 0) {
1872 wpa_printf(MSG_DEBUG
,
1873 "nl80211: wifi status sockopt failed\n");
1874 drv
->data_tx_status
= 0;
1875 if (!drv
->use_monitor
)
1877 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
1879 eloop_register_read_sock(drv
->eapol_tx_sock
,
1880 wpa_driver_nl80211_handle_eapol_tx_status
,
1886 nl80211_check_global(drv
->global
);
1887 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
1888 drv
->in_interface_list
= 1;
1894 wpa_driver_nl80211_deinit(bss
);
1900 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1901 * @ctx: context to be used when calling wpa_supplicant functions,
1902 * e.g., wpa_supplicant_event()
1903 * @ifname: interface name, e.g., wlan0
1904 * @global_priv: private driver global data from global_init()
1905 * Returns: Pointer to private data, %NULL on failure
1907 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
1910 return wpa_driver_nl80211_drv_init(ctx
, ifname
, global_priv
, 0, NULL
,
1915 static int nl80211_register_frame(struct i802_bss
*bss
,
1916 struct nl_handle
*nl_handle
,
1917 u16 type
, const u8
*match
, size_t match_len
)
1919 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1925 wpa_snprintf_hex(buf
, sizeof(buf
), match
, match_len
);
1926 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1927 type
, fc2str(type
), nl_handle
, buf
);
1929 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REGISTER_ACTION
)) ||
1930 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
, type
) ||
1931 nla_put(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
)) {
1936 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
1938 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
1939 "failed (type=%u): ret=%d (%s)",
1940 type
, ret
, strerror(-ret
));
1941 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
1948 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
1951 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
1952 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
1956 bss
->nl_mgmt
= nl_create_handle(bss
->nl_cb
, "mgmt");
1957 if (bss
->nl_mgmt
== NULL
)
1964 static void nl80211_mgmt_handle_register_eloop(struct i802_bss
*bss
)
1966 nl80211_register_eloop_read(&bss
->nl_mgmt
,
1967 wpa_driver_nl80211_event_receive
,
1972 static int nl80211_register_action_frame(struct i802_bss
*bss
,
1973 const u8
*match
, size_t match_len
)
1975 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
1976 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
1977 type
, match
, match_len
);
1981 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
1983 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1986 if (nl80211_alloc_mgmt_handle(bss
))
1988 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
1989 "handle %p", bss
->nl_mgmt
);
1991 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
1992 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
1994 /* register for any AUTH message */
1995 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0);
1998 #ifdef CONFIG_INTERWORKING
1999 /* QoS Map Configure */
2000 if (nl80211_register_action_frame(bss
, (u8
*) "\x01\x04", 2) < 0)
2002 #endif /* CONFIG_INTERWORKING */
2003 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
2004 /* GAS Initial Request */
2005 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
2007 /* GAS Initial Response */
2008 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
2010 /* GAS Comeback Request */
2011 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
2013 /* GAS Comeback Response */
2014 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
2016 /* Protected GAS Initial Request */
2017 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0a", 2) < 0)
2019 /* Protected GAS Initial Response */
2020 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0b", 2) < 0)
2022 /* Protected GAS Comeback Request */
2023 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0c", 2) < 0)
2025 /* Protected GAS Comeback Response */
2026 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0d", 2) < 0)
2028 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
2030 /* P2P Public Action */
2031 if (nl80211_register_action_frame(bss
,
2032 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
2036 if (nl80211_register_action_frame(bss
,
2037 (u8
*) "\x7f\x50\x6f\x9a\x09",
2040 #endif /* CONFIG_P2P */
2041 #ifdef CONFIG_IEEE80211W
2042 /* SA Query Response */
2043 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
2045 #endif /* CONFIG_IEEE80211W */
2047 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
2048 /* TDLS Discovery Response */
2049 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
2053 #endif /* CONFIG_TDLS */
2055 /* FST Action frames */
2056 if (nl80211_register_action_frame(bss
, (u8
*) "\x12", 1) < 0)
2058 #endif /* CONFIG_FST */
2060 /* FT Action frames */
2061 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
2064 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
2065 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
2067 /* WNM - BSS Transition Management Request */
2068 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
2070 /* WNM-Sleep Mode Response */
2071 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
2075 /* WNM-Notification */
2076 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x1a", 2) < 0)
2078 #endif /* CONFIG_HS20 */
2080 /* WMM-AC ADDTS Response */
2081 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x01", 2) < 0)
2085 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x02", 2) < 0)
2088 /* Radio Measurement - Neighbor Report Response */
2089 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x05", 2) < 0)
2092 /* Radio Measurement - Radio Measurement Request */
2093 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x00", 2) < 0)
2096 /* Radio Measurement - Link Measurement Request */
2097 if ((drv
->capa
.rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
) &&
2098 (nl80211_register_action_frame(bss
, (u8
*) "\x05\x02", 2) < 0))
2101 nl80211_mgmt_handle_register_eloop(bss
);
2107 static int nl80211_mgmt_subscribe_mesh(struct i802_bss
*bss
)
2111 if (nl80211_alloc_mgmt_handle(bss
))
2114 wpa_printf(MSG_DEBUG
,
2115 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2118 /* Auth frames for mesh SAE */
2119 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2120 (WLAN_FC_TYPE_MGMT
<< 2) |
2121 (WLAN_FC_STYPE_AUTH
<< 4),
2125 /* Mesh peering open */
2126 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x01", 2) < 0)
2128 /* Mesh peering confirm */
2129 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x02", 2) < 0)
2131 /* Mesh peering close */
2132 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x03", 2) < 0)
2135 nl80211_mgmt_handle_register_eloop(bss
);
2141 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
2146 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
2147 ret
= send_and_recv(bss
->drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
2149 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
2150 "failed: ret=%d (%s)",
2151 ret
, strerror(-ret
));
2157 static int nl80211_action_subscribe_ap(struct i802_bss
*bss
)
2161 /* Public Action frames */
2162 if (nl80211_register_action_frame(bss
, (u8
*) "\x04", 1) < 0)
2164 /* RRM Measurement Report */
2165 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x01", 2) < 0)
2167 /* RRM Link Measurement Report */
2168 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x03", 2) < 0)
2170 /* RRM Neighbor Report Request */
2171 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x04", 2) < 0)
2173 /* FT Action frames */
2174 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
2176 #ifdef CONFIG_IEEE80211W
2178 if (nl80211_register_action_frame(bss
, (u8
*) "\x08", 1) < 0)
2180 #endif /* CONFIG_IEEE80211W */
2181 /* Protected Dual of Public Action */
2182 if (nl80211_register_action_frame(bss
, (u8
*) "\x09", 1) < 0)
2185 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a", 1) < 0)
2188 if (nl80211_register_action_frame(bss
, (u8
*) "\x11", 1) < 0)
2191 /* FST Action frames */
2192 if (nl80211_register_action_frame(bss
, (u8
*) "\x12", 1) < 0)
2194 #endif /* CONFIG_FST */
2195 /* Vendor-specific */
2196 if (nl80211_register_action_frame(bss
, (u8
*) "\x7f", 1) < 0)
2203 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
2205 static const int stypes
[] = {
2207 WLAN_FC_STYPE_ASSOC_REQ
,
2208 WLAN_FC_STYPE_REASSOC_REQ
,
2209 WLAN_FC_STYPE_DISASSOC
,
2210 WLAN_FC_STYPE_DEAUTH
,
2211 WLAN_FC_STYPE_PROBE_REQ
,
2212 /* Beacon doesn't work as mac80211 doesn't currently allow
2213 * it, but it wouldn't really be the right thing anyway as
2214 * it isn't per interface ... maybe just dump the scan
2215 * results periodically for OLBC?
2217 /* WLAN_FC_STYPE_BEACON, */
2221 if (nl80211_alloc_mgmt_handle(bss
))
2223 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2224 "handle %p", bss
->nl_mgmt
);
2226 for (i
= 0; i
< ARRAY_SIZE(stypes
); i
++) {
2227 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2228 (WLAN_FC_TYPE_MGMT
<< 2) |
2235 if (nl80211_action_subscribe_ap(bss
))
2238 if (nl80211_register_spurious_class3(bss
))
2241 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
2244 nl80211_mgmt_handle_register_eloop(bss
);
2248 nl_destroy_handles(&bss
->nl_mgmt
);
2253 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
2255 if (nl80211_alloc_mgmt_handle(bss
))
2257 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2258 "handle %p (device SME)", bss
->nl_mgmt
);
2260 if (nl80211_action_subscribe_ap(bss
))
2263 nl80211_mgmt_handle_register_eloop(bss
);
2267 nl_destroy_handles(&bss
->nl_mgmt
);
2272 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
2274 if (bss
->nl_mgmt
== NULL
)
2276 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
2277 "(%s)", bss
->nl_mgmt
, reason
);
2278 nl80211_destroy_eloop_handle(&bss
->nl_mgmt
);
2280 nl80211_put_wiphy_data_ap(bss
);
2284 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
2286 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
2290 static void nl80211_del_p2pdev(struct i802_bss
*bss
)
2295 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_INTERFACE
);
2296 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2298 wpa_printf(MSG_DEBUG
, "nl80211: Delete P2P Device %s (0x%llx): %s",
2299 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2304 static int nl80211_set_p2pdev(struct i802_bss
*bss
, int start
)
2309 msg
= nl80211_cmd_msg(bss
, 0, start
? NL80211_CMD_START_P2P_DEVICE
:
2310 NL80211_CMD_STOP_P2P_DEVICE
);
2311 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2313 wpa_printf(MSG_DEBUG
, "nl80211: %s P2P Device %s (0x%llx): %s",
2314 start
? "Start" : "Stop",
2315 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2321 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
)
2323 enum nl80211_iftype nlmode
;
2325 nlmode
= nl80211_get_ifmode(bss
);
2326 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2327 return linux_set_iface_flags(bss
->drv
->global
->ioctl_sock
,
2331 /* P2P Device has start/stop which is equivalent */
2332 return nl80211_set_p2pdev(bss
, up
);
2336 #ifdef CONFIG_TESTING_OPTIONS
2337 static int qca_vendor_test_cmd_handler(struct nl_msg
*msg
, void *arg
)
2339 /* struct wpa_driver_nl80211_data *drv = arg; */
2340 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2341 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2344 wpa_printf(MSG_DEBUG
,
2345 "nl80211: QCA vendor test command response received");
2347 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2348 genlmsg_attrlen(gnlh
, 0), NULL
);
2349 if (!tb
[NL80211_ATTR_VENDOR_DATA
]) {
2350 wpa_printf(MSG_DEBUG
, "nl80211: No vendor data attribute");
2354 wpa_hexdump(MSG_DEBUG
,
2355 "nl80211: Received QCA vendor test command response",
2356 nla_data(tb
[NL80211_ATTR_VENDOR_DATA
]),
2357 nla_len(tb
[NL80211_ATTR_VENDOR_DATA
]));
2361 #endif /* CONFIG_TESTING_OPTIONS */
2364 static void qca_vendor_test(struct wpa_driver_nl80211_data
*drv
)
2366 #ifdef CONFIG_TESTING_OPTIONS
2368 struct nlattr
*params
;
2371 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2372 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2373 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2374 QCA_NL80211_VENDOR_SUBCMD_TEST
) ||
2375 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
2376 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_TEST
, 123)) {
2380 nla_nest_end(msg
, params
);
2382 ret
= send_and_recv_msgs(drv
, msg
, qca_vendor_test_cmd_handler
, drv
);
2383 wpa_printf(MSG_DEBUG
,
2384 "nl80211: QCA vendor test command returned %d (%s)",
2385 ret
, strerror(-ret
));
2386 #endif /* CONFIG_TESTING_OPTIONS */
2391 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
2392 const u8
*set_addr
, int first
,
2393 const char *driver_params
)
2395 struct i802_bss
*bss
= drv
->first_bss
;
2396 int send_rfkill_event
= 0;
2397 enum nl80211_iftype nlmode
;
2399 drv
->ifindex
= if_nametoindex(bss
->ifname
);
2400 bss
->ifindex
= drv
->ifindex
;
2401 bss
->wdev_id
= drv
->global
->if_add_wdevid
;
2402 bss
->wdev_id_set
= drv
->global
->if_add_wdevid_set
;
2404 bss
->if_dynamic
= drv
->ifindex
== drv
->global
->if_add_ifindex
;
2405 bss
->if_dynamic
= bss
->if_dynamic
|| drv
->global
->if_add_wdevid_set
;
2406 drv
->global
->if_add_wdevid_set
= 0;
2408 if (!bss
->if_dynamic
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2412 nl80211_get_ifmode(bss
) != NL80211_IFTYPE_P2P_DEVICE
&&
2413 linux_iface_up(drv
->global
->ioctl_sock
, bss
->ifname
) > 0)
2414 drv
->start_iface_up
= 1;
2416 if (wpa_driver_nl80211_capa(drv
))
2419 if (driver_params
&& nl80211_set_param(bss
, driver_params
) < 0)
2422 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2423 bss
->ifname
, drv
->phyname
);
2426 (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) ||
2427 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2431 if (first
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2432 drv
->start_mode_ap
= 1;
2434 if (drv
->hostapd
|| bss
->static_ap
)
2435 nlmode
= NL80211_IFTYPE_AP
;
2436 else if (bss
->if_dynamic
||
2437 nl80211_get_ifmode(bss
) == NL80211_IFTYPE_MESH_POINT
)
2438 nlmode
= nl80211_get_ifmode(bss
);
2440 nlmode
= NL80211_IFTYPE_STATION
;
2442 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
2443 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver mode");
2447 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2448 nl80211_get_macaddr(bss
);
2450 wpa_driver_nl80211_drv_init_rfkill(drv
);
2452 if (!rfkill_is_blocked(drv
->rfkill
)) {
2453 int ret
= i802_set_iface_flags(bss
, 1);
2455 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
2456 "interface '%s' UP", bss
->ifname
);
2460 if (is_p2p_net_interface(nlmode
))
2461 nl80211_disable_11b_rates(bss
->drv
,
2462 bss
->drv
->ifindex
, 1);
2464 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2467 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
2468 "interface '%s' due to rfkill", bss
->ifname
);
2469 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
2470 drv
->if_disabled
= 1;
2472 send_rfkill_event
= 1;
2475 if (!drv
->hostapd
&& nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
2476 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
2477 1, IF_OPER_DORMANT
);
2479 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2480 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2483 os_memcpy(drv
->perm_addr
, bss
->addr
, ETH_ALEN
);
2486 if (send_rfkill_event
) {
2487 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
2491 if (drv
->vendor_cmd_test_avail
)
2492 qca_vendor_test(drv
);
2498 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
2502 wpa_printf(MSG_DEBUG
, "nl80211: Remove beacon (ifindex=%d)",
2504 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_DEL_BEACON
);
2505 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2510 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2511 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2513 * Shut down driver interface and processing of driver events. Free
2514 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2516 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
2518 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2521 wpa_printf(MSG_INFO
, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2522 bss
->ifname
, drv
->disabled_11b_rates
);
2525 if (drv
->data_tx_status
)
2526 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
2527 if (drv
->eapol_tx_sock
>= 0)
2528 close(drv
->eapol_tx_sock
);
2531 wpa_driver_nl80211_probe_req_report(bss
, 0);
2532 if (bss
->added_if_into_bridge
) {
2533 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
2535 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2536 "interface %s from bridge %s: %s",
2537 bss
->ifname
, bss
->brname
, strerror(errno
));
2539 nl80211_handle_destroy(drv
->rtnl_sk
);
2541 if (bss
->added_bridge
) {
2542 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->brname
,
2544 wpa_printf(MSG_INFO
,
2545 "nl80211: Could not set bridge %s down",
2547 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
2548 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2550 bss
->brname
, strerror(errno
));
2553 nl80211_remove_monitor_interface(drv
);
2555 if (is_ap_interface(drv
->nlmode
))
2556 wpa_driver_nl80211_del_beacon(drv
);
2558 if (drv
->eapol_sock
>= 0) {
2559 eloop_unregister_read_sock(drv
->eapol_sock
);
2560 close(drv
->eapol_sock
);
2563 if (drv
->if_indices
!= drv
->default_if_indices
)
2564 os_free(drv
->if_indices
);
2566 if (drv
->if_indices_reason
!= drv
->default_if_indices_reason
)
2567 os_free(drv
->if_indices_reason
);
2569 if (drv
->disabled_11b_rates
)
2570 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2572 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
2574 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill
, drv
, drv
->ctx
);
2575 rfkill_deinit(drv
->rfkill
);
2577 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2579 if (!drv
->start_iface_up
)
2580 (void) i802_set_iface_flags(bss
, 0);
2582 if (drv
->addr_changed
) {
2583 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
2585 wpa_printf(MSG_DEBUG
,
2586 "nl80211: Could not set interface down to restore permanent MAC address");
2588 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2589 drv
->perm_addr
) < 0) {
2590 wpa_printf(MSG_DEBUG
,
2591 "nl80211: Could not restore permanent MAC address");
2595 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2596 if (!drv
->hostapd
|| !drv
->start_mode_ap
)
2597 wpa_driver_nl80211_set_mode(bss
,
2598 NL80211_IFTYPE_STATION
);
2599 nl80211_mgmt_unsubscribe(bss
, "deinit");
2601 nl80211_mgmt_unsubscribe(bss
, "deinit");
2602 nl80211_del_p2pdev(bss
);
2605 nl80211_destroy_bss(drv
->first_bss
);
2607 os_free(drv
->filter_ssids
);
2609 os_free(drv
->auth_ie
);
2611 if (drv
->in_interface_list
)
2612 dl_list_del(&drv
->list
);
2614 os_free(drv
->extended_capa
);
2615 os_free(drv
->extended_capa_mask
);
2616 for (i
= 0; i
< drv
->num_iface_ext_capa
; i
++) {
2617 os_free(drv
->iface_ext_capa
[i
].ext_capa
);
2618 os_free(drv
->iface_ext_capa
[i
].ext_capa_mask
);
2620 os_free(drv
->first_bss
);
2625 static u32
wpa_alg_to_cipher_suite(enum wpa_alg alg
, size_t key_len
)
2630 return WLAN_CIPHER_SUITE_WEP40
;
2631 return WLAN_CIPHER_SUITE_WEP104
;
2633 return WLAN_CIPHER_SUITE_TKIP
;
2635 return WLAN_CIPHER_SUITE_CCMP
;
2637 return WLAN_CIPHER_SUITE_GCMP
;
2638 case WPA_ALG_CCMP_256
:
2639 return WLAN_CIPHER_SUITE_CCMP_256
;
2640 case WPA_ALG_GCMP_256
:
2641 return WLAN_CIPHER_SUITE_GCMP_256
;
2643 return WLAN_CIPHER_SUITE_AES_CMAC
;
2644 case WPA_ALG_BIP_GMAC_128
:
2645 return WLAN_CIPHER_SUITE_BIP_GMAC_128
;
2646 case WPA_ALG_BIP_GMAC_256
:
2647 return WLAN_CIPHER_SUITE_BIP_GMAC_256
;
2648 case WPA_ALG_BIP_CMAC_256
:
2649 return WLAN_CIPHER_SUITE_BIP_CMAC_256
;
2651 return WLAN_CIPHER_SUITE_SMS4
;
2653 return WLAN_CIPHER_SUITE_KRK
;
2656 wpa_printf(MSG_ERROR
, "nl80211: Unexpected encryption algorithm %d",
2661 wpa_printf(MSG_ERROR
, "nl80211: Unsupported encryption algorithm %d",
2667 static u32
wpa_cipher_to_cipher_suite(unsigned int cipher
)
2670 case WPA_CIPHER_CCMP_256
:
2671 return WLAN_CIPHER_SUITE_CCMP_256
;
2672 case WPA_CIPHER_GCMP_256
:
2673 return WLAN_CIPHER_SUITE_GCMP_256
;
2674 case WPA_CIPHER_CCMP
:
2675 return WLAN_CIPHER_SUITE_CCMP
;
2676 case WPA_CIPHER_GCMP
:
2677 return WLAN_CIPHER_SUITE_GCMP
;
2678 case WPA_CIPHER_TKIP
:
2679 return WLAN_CIPHER_SUITE_TKIP
;
2680 case WPA_CIPHER_WEP104
:
2681 return WLAN_CIPHER_SUITE_WEP104
;
2682 case WPA_CIPHER_WEP40
:
2683 return WLAN_CIPHER_SUITE_WEP40
;
2684 case WPA_CIPHER_GTK_NOT_USED
:
2685 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR
;
2692 static int wpa_cipher_to_cipher_suites(unsigned int ciphers
, u32 suites
[],
2697 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP_256
)
2698 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP_256
;
2699 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP_256
)
2700 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP_256
;
2701 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP
)
2702 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
2703 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP
)
2704 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP
;
2705 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_TKIP
)
2706 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
2707 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP104
)
2708 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
2709 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP40
)
2710 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
2716 #ifdef CONFIG_DRIVER_NL80211_QCA
2717 static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data
*drv
,
2718 const u8
*key
, size_t key_len
)
2723 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
))
2726 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2727 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2728 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2729 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY
) ||
2730 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, key_len
, key
)) {
2731 nl80211_nlmsg_clear(msg
);
2735 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
2737 wpa_printf(MSG_DEBUG
,
2738 "nl80211: Key management set key failed: ret=%d (%s)",
2739 ret
, strerror(-ret
));
2744 #endif /* CONFIG_DRIVER_NL80211_QCA */
2747 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
2748 enum wpa_alg alg
, const u8
*addr
,
2749 int key_idx
, int set_tx
,
2750 const u8
*seq
, size_t seq_len
,
2751 const u8
*key
, size_t key_len
)
2753 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2755 struct nl_msg
*msg
= NULL
;
2759 /* Ignore for P2P Device */
2760 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2763 ifindex
= if_nametoindex(ifname
);
2764 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
2765 "set_tx=%d seq_len=%lu key_len=%lu",
2766 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
2767 (unsigned long) seq_len
, (unsigned long) key_len
);
2769 if (key_idx
== -1) {
2773 #endif /* CONFIG_TDLS */
2775 #ifdef CONFIG_DRIVER_NL80211_QCA
2776 if (alg
== WPA_ALG_PMK
&&
2777 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
)) {
2778 wpa_printf(MSG_DEBUG
, "%s: calling issue_key_mgmt_set_key",
2780 ret
= issue_key_mgmt_set_key(drv
, key
, key_len
);
2783 #endif /* CONFIG_DRIVER_NL80211_QCA */
2785 if (alg
== WPA_ALG_NONE
) {
2786 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_DEL_KEY
);
2792 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
2795 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_NEW_KEY
);
2797 nla_put(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
) ||
2798 nla_put_u32(msg
, NL80211_ATTR_KEY_CIPHER
, suite
))
2800 wpa_hexdump_key(MSG_DEBUG
, "nl80211: KEY_DATA", key
, key_len
);
2803 if (seq
&& seq_len
) {
2804 if (nla_put(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
))
2806 wpa_hexdump(MSG_DEBUG
, "nl80211: KEY_SEQ", seq
, seq_len
);
2809 if (addr
&& !is_broadcast_ether_addr(addr
)) {
2810 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
2811 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
2814 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
2815 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
2816 if (nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
,
2817 NL80211_KEYTYPE_GROUP
))
2820 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
2821 struct nlattr
*types
;
2823 wpa_printf(MSG_DEBUG
, " broadcast key");
2825 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2827 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2829 nla_nest_end(msg
, types
);
2831 if (nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2834 ret
= send_and_recv_msgs(drv
, msg
, NULL
, key
? (void *) -1 : NULL
);
2835 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
2838 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
2839 ret
, strerror(-ret
));
2842 * If we failed or don't need to set the default TX key (below),
2845 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
|| tdls
)
2847 if (is_ap_interface(drv
->nlmode
) && addr
&&
2848 !is_broadcast_ether_addr(addr
))
2851 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_SET_KEY
);
2853 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
) ||
2854 nla_put_flag(msg
, (alg
== WPA_ALG_IGTK
||
2855 alg
== WPA_ALG_BIP_GMAC_128
||
2856 alg
== WPA_ALG_BIP_GMAC_256
||
2857 alg
== WPA_ALG_BIP_CMAC_256
) ?
2858 NL80211_ATTR_KEY_DEFAULT_MGMT
:
2859 NL80211_ATTR_KEY_DEFAULT
))
2861 if (addr
&& is_broadcast_ether_addr(addr
)) {
2862 struct nlattr
*types
;
2864 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2866 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2868 nla_nest_end(msg
, types
);
2870 struct nlattr
*types
;
2872 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2874 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
))
2876 nla_nest_end(msg
, types
);
2879 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2883 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
2884 "err=%d %s)", ret
, strerror(-ret
));
2888 nl80211_nlmsg_clear(msg
);
2894 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
2895 int key_idx
, int defkey
,
2896 const u8
*seq
, size_t seq_len
,
2897 const u8
*key
, size_t key_len
)
2899 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
2905 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
2909 if (defkey
&& alg
== WPA_ALG_IGTK
) {
2910 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT_MGMT
))
2912 } else if (defkey
) {
2913 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT
))
2917 if (nla_put_u8(msg
, NL80211_KEY_IDX
, key_idx
) ||
2918 nla_put_u32(msg
, NL80211_KEY_CIPHER
, suite
) ||
2920 nla_put(msg
, NL80211_KEY_SEQ
, seq_len
, seq
)) ||
2921 nla_put(msg
, NL80211_KEY_DATA
, key_len
, key
))
2924 nla_nest_end(msg
, key_attr
);
2930 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
2934 struct nlattr
*nl_keys
, *nl_key
;
2936 for (i
= 0; i
< 4; i
++) {
2937 if (!params
->wep_key
[i
])
2942 if (params
->wps
== WPS_MODE_PRIVACY
)
2944 if (params
->pairwise_suite
&&
2945 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
2951 if (nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
2954 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
2958 for (i
= 0; i
< 4; i
++) {
2959 if (!params
->wep_key
[i
])
2962 nl_key
= nla_nest_start(msg
, i
);
2964 nla_put(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
2965 params
->wep_key
[i
]) ||
2966 nla_put_u32(msg
, NL80211_KEY_CIPHER
,
2967 params
->wep_key_len
[i
] == 5 ?
2968 WLAN_CIPHER_SUITE_WEP40
:
2969 WLAN_CIPHER_SUITE_WEP104
) ||
2970 nla_put_u8(msg
, NL80211_KEY_IDX
, i
) ||
2971 (i
== params
->wep_tx_keyidx
&&
2972 nla_put_flag(msg
, NL80211_KEY_DEFAULT
)))
2975 nla_nest_end(msg
, nl_key
);
2977 nla_nest_end(msg
, nl_keys
);
2983 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
2984 const u8
*addr
, int cmd
, u16 reason_code
,
2985 int local_state_change
)
2990 if (!(msg
= nl80211_drv_msg(drv
, 0, cmd
)) ||
2991 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
) ||
2992 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
2993 (local_state_change
&&
2994 nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))) {
2999 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3001 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
3002 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3003 reason_code
, ret
, strerror(-ret
));
3009 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
3014 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
3015 nl80211_mark_disconnected(drv
);
3016 /* Disconnect command doesn't need BSSID - it uses cached value */
3017 ret
= wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
3020 * For locally generated disconnect, supplicant already generates a
3021 * DEAUTH event, so ignore the event from NL80211.
3023 drv
->ignore_next_local_disconnect
= ret
== 0;
3029 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
3030 const u8
*addr
, int reason_code
)
3032 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3035 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3036 nl80211_mark_disconnected(drv
);
3037 return nl80211_leave_ibss(drv
, 1);
3039 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
3040 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
3041 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
3042 __func__
, MAC2STR(addr
), reason_code
);
3043 nl80211_mark_disconnected(drv
);
3044 ret
= wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
3047 * For locally generated deauthenticate, supplicant already generates a
3048 * DEAUTH event, so ignore the event from NL80211.
3050 drv
->ignore_next_local_deauth
= ret
== 0;
3055 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
3056 struct wpa_driver_auth_params
*params
)
3060 drv
->auth_freq
= params
->freq
;
3061 drv
->auth_alg
= params
->auth_alg
;
3062 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
3063 drv
->auth_local_state_change
= params
->local_state_change
;
3064 drv
->auth_p2p
= params
->p2p
;
3067 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
3069 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
3072 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
3073 drv
->auth_ssid_len
= params
->ssid_len
;
3075 drv
->auth_ssid_len
= 0;
3078 os_free(drv
->auth_ie
);
3079 drv
->auth_ie
= NULL
;
3080 drv
->auth_ie_len
= 0;
3082 drv
->auth_ie
= os_malloc(params
->ie_len
);
3084 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
3085 drv
->auth_ie_len
= params
->ie_len
;
3089 for (i
= 0; i
< 4; i
++) {
3090 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
3091 params
->wep_key_len
[i
] <= 16) {
3092 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
3093 params
->wep_key_len
[i
]);
3094 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
3096 drv
->auth_wep_key_len
[i
] = 0;
3101 static void nl80211_unmask_11b_rates(struct i802_bss
*bss
)
3103 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3105 if (is_p2p_net_interface(drv
->nlmode
) || !drv
->disabled_11b_rates
)
3109 * Looks like we failed to unmask 11b rates previously. This could
3110 * happen, e.g., if the interface was down at the point in time when a
3111 * P2P group was terminated.
3113 wpa_printf(MSG_DEBUG
,
3114 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3116 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
3120 static int wpa_driver_nl80211_authenticate(
3121 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
3123 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3126 enum nl80211_auth_type type
;
3127 enum nl80211_iftype nlmode
;
3131 nl80211_unmask_11b_rates(bss
);
3133 is_retry
= drv
->retry_auth
;
3134 drv
->retry_auth
= 0;
3135 drv
->ignore_deauth_event
= 0;
3137 nl80211_mark_disconnected(drv
);
3138 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
3140 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
3142 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
3143 /* FIX: IBSS mode */
3144 nlmode
= params
->p2p
?
3145 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
3146 if (drv
->nlmode
!= nlmode
&&
3147 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
3151 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
3154 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_AUTHENTICATE
);
3158 for (i
= 0; i
< 4; i
++) {
3159 if (!params
->wep_key
[i
])
3161 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
3163 i
== params
->wep_tx_keyidx
, NULL
, 0,
3165 params
->wep_key_len
[i
]);
3166 if (params
->wep_tx_keyidx
!= i
)
3168 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
3169 params
->wep_key
[i
], params
->wep_key_len
[i
]))
3173 if (params
->bssid
) {
3174 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
3175 MAC2STR(params
->bssid
));
3176 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
3180 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
3181 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
))
3185 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
3186 params
->ssid
, params
->ssid_len
);
3187 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
3191 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
3193 nla_put(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
))
3195 if (params
->auth_data
) {
3196 wpa_hexdump(MSG_DEBUG
, " * auth_data", params
->auth_data
,
3197 params
->auth_data_len
);
3198 if (nla_put(msg
, NL80211_ATTR_SAE_DATA
, params
->auth_data_len
,
3202 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
3203 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
3204 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
3205 type
= NL80211_AUTHTYPE_SHARED_KEY
;
3206 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
3207 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
3208 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
3209 type
= NL80211_AUTHTYPE_FT
;
3210 else if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
3211 type
= NL80211_AUTHTYPE_SAE
;
3212 else if (params
->auth_alg
& WPA_AUTH_ALG_FILS
)
3213 type
= NL80211_AUTHTYPE_FILS_SK
;
3216 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
3217 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
3219 if (params
->local_state_change
) {
3220 wpa_printf(MSG_DEBUG
, " * Local state change only");
3221 if (nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))
3225 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3228 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
3229 "nl80211: MLME command failed (auth): ret=%d (%s)",
3230 ret
, strerror(-ret
));
3232 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
3233 !params
->local_state_change
) {
3235 * mac80211 does not currently accept new
3236 * authentication if we are already authenticated. As a
3237 * workaround, force deauthentication and try again.
3239 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
3240 "after forced deauthentication");
3241 drv
->ignore_deauth_event
= 1;
3242 wpa_driver_nl80211_deauthenticate(
3244 WLAN_REASON_PREV_AUTH_NOT_VALID
);
3249 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
3251 * cfg80211 has likely expired the BSS entry even
3252 * though it was previously available in our internal
3253 * BSS table. To recover quickly, start a single
3254 * channel scan on the specified channel.
3256 struct wpa_driver_scan_params scan
;
3259 os_memset(&scan
, 0, sizeof(scan
));
3262 scan
.ssids
[0].ssid
= params
->ssid
;
3263 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
3265 freqs
[0] = params
->freq
;
3268 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
3269 "channel scan to refresh cfg80211 BSS "
3271 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
3273 nl80211_copy_auth_params(drv
, params
);
3274 drv
->scan_for_auth
= 1;
3276 } else if (is_retry
) {
3278 * Need to indicate this with an event since the return
3279 * value from the retry is not delivered to core code.
3281 union wpa_event_data event
;
3282 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
3284 os_memset(&event
, 0, sizeof(event
));
3285 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
3287 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
3291 wpa_printf(MSG_DEBUG
,
3292 "nl80211: Authentication request send successfully");
3301 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data
*drv
)
3303 struct wpa_driver_auth_params params
;
3304 struct i802_bss
*bss
= drv
->first_bss
;
3307 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
3309 os_memset(¶ms
, 0, sizeof(params
));
3310 params
.freq
= drv
->auth_freq
;
3311 params
.auth_alg
= drv
->auth_alg
;
3312 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
3313 params
.local_state_change
= drv
->auth_local_state_change
;
3314 params
.p2p
= drv
->auth_p2p
;
3316 if (!is_zero_ether_addr(drv
->auth_bssid_
))
3317 params
.bssid
= drv
->auth_bssid_
;
3319 if (drv
->auth_ssid_len
) {
3320 params
.ssid
= drv
->auth_ssid
;
3321 params
.ssid_len
= drv
->auth_ssid_len
;
3324 params
.ie
= drv
->auth_ie
;
3325 params
.ie_len
= drv
->auth_ie_len
;
3327 for (i
= 0; i
< 4; i
++) {
3328 if (drv
->auth_wep_key_len
[i
]) {
3329 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
3330 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
3334 drv
->retry_auth
= 1;
3335 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
3339 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
3340 const void *data
, size_t len
,
3341 int encrypt
, int noack
,
3342 unsigned int freq
, int no_cck
,
3343 int offchanok
, unsigned int wait_time
,
3344 const u16
*csa_offs
,
3345 size_t csa_offs_len
)
3347 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3351 if (freq
== 0 && drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3352 freq
= nl80211_get_assoc_freq(drv
);
3353 wpa_printf(MSG_DEBUG
,
3354 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3358 wpa_printf(MSG_DEBUG
, "nl80211: send_frame - Use bss->freq=%u",
3363 if (drv
->use_monitor
) {
3364 wpa_printf(MSG_DEBUG
, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
3366 return nl80211_send_monitor(drv
, data
, len
, encrypt
, noack
);
3369 wpa_printf(MSG_DEBUG
, "nl80211: send_frame -> send_frame_cmd");
3370 res
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
3371 &cookie
, no_cck
, noack
, offchanok
,
3372 csa_offs
, csa_offs_len
);
3373 if (res
== 0 && !noack
) {
3374 const struct ieee80211_mgmt
*mgmt
;
3377 mgmt
= (const struct ieee80211_mgmt
*) data
;
3378 fc
= le_to_host16(mgmt
->frame_control
);
3379 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3380 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_ACTION
) {
3381 wpa_printf(MSG_MSGDUMP
,
3382 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3383 (long long unsigned int)
3384 drv
->send_action_cookie
,
3385 (long long unsigned int) cookie
);
3386 drv
->send_action_cookie
= cookie
;
3394 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
3395 size_t data_len
, int noack
,
3396 unsigned int freq
, int no_cck
,
3398 unsigned int wait_time
,
3399 const u16
*csa_offs
,
3400 size_t csa_offs_len
)
3402 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3403 struct ieee80211_mgmt
*mgmt
;
3407 mgmt
= (struct ieee80211_mgmt
*) data
;
3408 fc
= le_to_host16(mgmt
->frame_control
);
3409 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - da= " MACSTR
3410 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3411 MAC2STR(mgmt
->da
), noack
, freq
, no_cck
, offchanok
, wait_time
,
3412 fc
, fc2str(fc
), drv
->nlmode
);
3414 if ((is_sta_interface(drv
->nlmode
) ||
3415 drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) &&
3416 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3417 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
3419 * The use of last_mgmt_freq is a bit of a hack,
3420 * but it works due to the single-threaded nature
3421 * of wpa_supplicant.
3424 wpa_printf(MSG_DEBUG
, "nl80211: Use last_mgmt_freq=%d",
3425 drv
->last_mgmt_freq
);
3426 freq
= drv
->last_mgmt_freq
;
3428 return nl80211_send_frame_cmd(bss
, freq
, 0,
3429 data
, data_len
, NULL
, 1, noack
,
3430 1, csa_offs
, csa_offs_len
);
3433 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
3435 wpa_printf(MSG_DEBUG
, "nl80211: Use bss->freq=%d",
3439 return nl80211_send_frame_cmd(bss
, freq
,
3440 (int) freq
== bss
->freq
? 0 :
3443 &drv
->send_action_cookie
,
3444 no_cck
, noack
, offchanok
,
3445 csa_offs
, csa_offs_len
);
3448 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3449 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
3451 * Only one of the authentication frame types is encrypted.
3452 * In order for static WEP encryption to work properly (i.e.,
3453 * to not encrypt the frame), we need to tell mac80211 about
3454 * the frames that must not be encrypted.
3456 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
3457 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
3458 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
3462 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme -> send_frame");
3463 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
3464 noack
, freq
, no_cck
, offchanok
,
3465 wait_time
, csa_offs
,
3470 static int nl80211_put_basic_rates(struct nl_msg
*msg
, const int *basic_rates
)
3472 u8 rates
[NL80211_MAX_SUPP_RATES
];
3479 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0; i
++)
3480 rates
[rates_len
++] = basic_rates
[i
] / 5;
3482 return nla_put(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
3486 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
3487 int slot
, int ht_opmode
, int ap_isolate
,
3488 const int *basic_rates
)
3490 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3493 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_BSS
)) ||
3495 nla_put_u8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
)) ||
3497 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
)) ||
3499 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
)) ||
3501 nla_put_u16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
)) ||
3503 nla_put_u8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
)) ||
3504 nl80211_put_basic_rates(msg
, basic_rates
)) {
3509 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3513 static int wpa_driver_nl80211_set_acl(void *priv
,
3514 struct hostapd_acl_params
*params
)
3516 struct i802_bss
*bss
= priv
;
3517 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3523 if (!(drv
->capa
.max_acl_mac_addrs
))
3526 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
3529 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
3530 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
3532 acl
= nlmsg_alloc();
3535 for (i
= 0; i
< params
->num_mac_acl
; i
++) {
3536 if (nla_put(acl
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
)) {
3542 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MAC_ACL
)) ||
3543 nla_put_u32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
3544 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
3545 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
) ||
3546 nla_put_nested(msg
, NL80211_ATTR_MAC_ADDRS
, acl
)) {
3553 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3555 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
3556 ret
, strerror(-ret
));
3563 static int nl80211_put_beacon_int(struct nl_msg
*msg
, int beacon_int
)
3565 if (beacon_int
> 0) {
3566 wpa_printf(MSG_DEBUG
, " * beacon_int=%d", beacon_int
);
3567 return nla_put_u32(msg
, NL80211_ATTR_BEACON_INTERVAL
,
3575 static int nl80211_put_dtim_period(struct nl_msg
*msg
, int dtim_period
)
3577 if (dtim_period
> 0) {
3578 wpa_printf(MSG_DEBUG
, " * dtim_period=%d", dtim_period
);
3579 return nla_put_u32(msg
, NL80211_ATTR_DTIM_PERIOD
, dtim_period
);
3587 static int nl80211_set_mesh_config(void *priv
,
3588 struct wpa_driver_mesh_bss_params
*params
)
3590 struct i802_bss
*bss
= priv
;
3591 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3595 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MESH_CONFIG
);
3599 ret
= nl80211_put_mesh_config(msg
, params
);
3605 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3607 wpa_printf(MSG_ERROR
,
3608 "nl80211: Mesh config set failed: %d (%s)",
3609 ret
, strerror(-ret
));
3614 #endif /* CONFIG_MESH */
3617 static int nl80211_put_beacon_rate(struct nl_msg
*msg
, const u64 flags
,
3618 struct wpa_driver_ap_params
*params
)
3620 struct nlattr
*bands
, *band
;
3621 struct nl80211_txrate_vht vht_rate
;
3623 if (!params
->freq
||
3624 (params
->beacon_rate
== 0 &&
3625 params
->rate_type
== BEACON_RATE_LEGACY
))
3628 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
3632 switch (params
->freq
->mode
) {
3633 case HOSTAPD_MODE_IEEE80211B
:
3634 case HOSTAPD_MODE_IEEE80211G
:
3635 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
3637 case HOSTAPD_MODE_IEEE80211A
:
3638 band
= nla_nest_start(msg
, NL80211_BAND_5GHZ
);
3640 case HOSTAPD_MODE_IEEE80211AD
:
3641 band
= nla_nest_start(msg
, NL80211_BAND_60GHZ
);
3650 os_memset(&vht_rate
, 0, sizeof(vht_rate
));
3652 switch (params
->rate_type
) {
3653 case BEACON_RATE_LEGACY
:
3654 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY
)) {
3655 wpa_printf(MSG_INFO
,
3656 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
3660 if (nla_put_u8(msg
, NL80211_TXRATE_LEGACY
,
3661 (u8
) params
->beacon_rate
/ 5) ||
3662 nla_put(msg
, NL80211_TXRATE_HT
, 0, NULL
) ||
3663 (params
->freq
->vht_enabled
&&
3664 nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
3668 wpa_printf(MSG_DEBUG
, " * beacon_rate = legacy:%u (* 100 kbps)",
3669 params
->beacon_rate
);
3671 case BEACON_RATE_HT
:
3672 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_HT
)) {
3673 wpa_printf(MSG_INFO
,
3674 "nl80211: Driver does not support setting Beacon frame rate (HT)");
3677 if (nla_put(msg
, NL80211_TXRATE_LEGACY
, 0, NULL
) ||
3678 nla_put_u8(msg
, NL80211_TXRATE_HT
, params
->beacon_rate
) ||
3679 (params
->freq
->vht_enabled
&&
3680 nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
3683 wpa_printf(MSG_DEBUG
, " * beacon_rate = HT-MCS %u",
3684 params
->beacon_rate
);
3686 case BEACON_RATE_VHT
:
3687 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_VHT
)) {
3688 wpa_printf(MSG_INFO
,
3689 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
3692 vht_rate
.mcs
[0] = BIT(params
->beacon_rate
);
3693 if (nla_put(msg
, NL80211_TXRATE_LEGACY
, 0, NULL
))
3695 if (nla_put(msg
, NL80211_TXRATE_HT
, 0, NULL
))
3697 if (nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
3700 wpa_printf(MSG_DEBUG
, " * beacon_rate = VHT-MCS %u",
3701 params
->beacon_rate
);
3705 nla_nest_end(msg
, band
);
3706 nla_nest_end(msg
, bands
);
3712 static int nl80211_set_multicast_to_unicast(struct i802_bss
*bss
,
3713 int multicast_to_unicast
)
3715 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3719 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST
);
3721 (multicast_to_unicast
&&
3722 nla_put_flag(msg
, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
))) {
3723 wpa_printf(MSG_ERROR
,
3724 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
3730 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3734 wpa_printf(MSG_DEBUG
,
3735 "nl80211: multicast to unicast %s on interface %s",
3736 multicast_to_unicast
? "enabled" : "disabled",
3740 if (!multicast_to_unicast
)
3742 wpa_printf(MSG_INFO
,
3743 "nl80211: multicast to unicast not supported on interface %s",
3747 wpa_printf(MSG_ERROR
,
3748 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
3749 multicast_to_unicast
? "enabling" : "disabling",
3750 ret
, strerror(-ret
), bss
->ifname
);
3758 static int wpa_driver_nl80211_set_ap(void *priv
,
3759 struct wpa_driver_ap_params
*params
)
3761 struct i802_bss
*bss
= priv
;
3762 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3764 u8 cmd
= NL80211_CMD_NEW_BEACON
;
3769 u32 suites
[10], suite
;
3772 struct wpa_driver_mesh_bss_params mesh_params
;
3773 #endif /* CONFIG_MESH */
3775 beacon_set
= params
->reenable
? 0 : bss
->beacon_set
;
3777 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
3780 cmd
= NL80211_CMD_SET_BEACON
;
3782 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
3783 params
->head
, params
->head_len
);
3784 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
3785 params
->tail
, params
->tail_len
);
3786 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", bss
->ifindex
);
3787 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
3788 wpa_printf(MSG_DEBUG
, "nl80211: beacon_rate=%u", params
->beacon_rate
);
3789 wpa_printf(MSG_DEBUG
, "nl80211: rate_type=%d", params
->rate_type
);
3790 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
3791 wpa_hexdump_ascii(MSG_DEBUG
, "nl80211: ssid",
3792 params
->ssid
, params
->ssid_len
);
3793 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
3794 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
,
3796 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
,
3798 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
3799 nl80211_put_beacon_rate(msg
, drv
->capa
.flags
, params
) ||
3800 nl80211_put_dtim_period(msg
, params
->dtim_period
) ||
3801 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
3803 if (params
->proberesp
&& params
->proberesp_len
) {
3804 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
3805 params
->proberesp
, params
->proberesp_len
);
3806 if (nla_put(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
3810 switch (params
->hide_ssid
) {
3811 case NO_SSID_HIDING
:
3812 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
3813 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3814 NL80211_HIDDEN_SSID_NOT_IN_USE
))
3817 case HIDDEN_SSID_ZERO_LEN
:
3818 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
3819 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3820 NL80211_HIDDEN_SSID_ZERO_LEN
))
3823 case HIDDEN_SSID_ZERO_CONTENTS
:
3824 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
3825 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3826 NL80211_HIDDEN_SSID_ZERO_CONTENTS
))
3830 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
3831 if (params
->privacy
&&
3832 nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
3834 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
3835 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
3836 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
3837 /* Leave out the attribute */
3838 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
) {
3839 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3840 NL80211_AUTHTYPE_SHARED_KEY
))
3843 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3844 NL80211_AUTHTYPE_OPEN_SYSTEM
))
3848 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
3850 if (params
->wpa_version
& WPA_PROTO_WPA
)
3851 ver
|= NL80211_WPA_VERSION_1
;
3852 if (params
->wpa_version
& WPA_PROTO_RSN
)
3853 ver
|= NL80211_WPA_VERSION_2
;
3855 nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
3858 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
3859 params
->key_mgmt_suites
);
3861 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
3862 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
3863 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
3864 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
3866 nla_put(msg
, NL80211_ATTR_AKM_SUITES
, num_suites
* sizeof(u32
),
3870 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
3871 (!params
->pairwise_ciphers
||
3872 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
)) &&
3873 (nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, ETH_P_PAE
) ||
3874 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
3877 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
3878 params
->pairwise_ciphers
);
3879 num_suites
= wpa_cipher_to_cipher_suites(params
->pairwise_ciphers
,
3880 suites
, ARRAY_SIZE(suites
));
3882 nla_put(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
3883 num_suites
* sizeof(u32
), suites
))
3886 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
3887 params
->group_cipher
);
3888 suite
= wpa_cipher_to_cipher_suite(params
->group_cipher
);
3890 nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, suite
))
3893 if (params
->ht_opmode
!= -1) {
3894 switch (params
->smps_mode
) {
3895 case HT_CAP_INFO_SMPS_DYNAMIC
:
3896 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - dynamic");
3897 smps_mode
= NL80211_SMPS_DYNAMIC
;
3899 case HT_CAP_INFO_SMPS_STATIC
:
3900 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - static");
3901 smps_mode
= NL80211_SMPS_STATIC
;
3904 /* invalid - fallback to smps off */
3905 case HT_CAP_INFO_SMPS_DISABLED
:
3906 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - off");
3907 smps_mode
= NL80211_SMPS_OFF
;
3910 if (nla_put_u32(msg
, NL80211_ATTR_SMPS_MODE
, smps_mode
))
3914 if (params
->beacon_ies
) {
3915 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
3916 params
->beacon_ies
);
3917 if (nla_put(msg
, NL80211_ATTR_IE
,
3918 wpabuf_len(params
->beacon_ies
),
3919 wpabuf_head(params
->beacon_ies
)))
3922 if (params
->proberesp_ies
) {
3923 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
3924 params
->proberesp_ies
);
3925 if (nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
3926 wpabuf_len(params
->proberesp_ies
),
3927 wpabuf_head(params
->proberesp_ies
)))
3930 if (params
->assocresp_ies
) {
3931 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
3932 params
->assocresp_ies
);
3933 if (nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
3934 wpabuf_len(params
->assocresp_ies
),
3935 wpabuf_head(params
->assocresp_ies
)))
3939 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
3940 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
3941 params
->ap_max_inactivity
);
3942 if (nla_put_u16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
3943 params
->ap_max_inactivity
))
3948 if (params
->p2p_go_ctwindow
> 0) {
3949 if (drv
->p2p_go_ctwindow_supported
) {
3950 wpa_printf(MSG_DEBUG
, "nl80211: P2P GO ctwindow=%d",
3951 params
->p2p_go_ctwindow
);
3952 if (nla_put_u8(msg
, NL80211_ATTR_P2P_CTWINDOW
,
3953 params
->p2p_go_ctwindow
))
3956 wpa_printf(MSG_INFO
,
3957 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
3960 #endif /* CONFIG_P2P */
3963 wpa_printf(MSG_DEBUG
, "nl80211: PBSS");
3964 if (nla_put_flag(msg
, NL80211_ATTR_PBSS
))
3968 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3970 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
3971 ret
, strerror(-ret
));
3973 bss
->beacon_set
= 1;
3974 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
3975 params
->short_slot_time
, params
->ht_opmode
,
3976 params
->isolate
, params
->basic_rates
);
3977 nl80211_set_multicast_to_unicast(bss
,
3978 params
->multicast_to_unicast
);
3979 if (beacon_set
&& params
->freq
&&
3980 params
->freq
->bandwidth
!= bss
->bandwidth
) {
3981 wpa_printf(MSG_DEBUG
,
3982 "nl80211: Update BSS %s bandwidth: %d -> %d",
3983 bss
->ifname
, bss
->bandwidth
,
3984 params
->freq
->bandwidth
);
3985 ret
= nl80211_set_channel(bss
, params
->freq
, 1);
3987 wpa_printf(MSG_DEBUG
,
3988 "nl80211: Frequency set failed: %d (%s)",
3989 ret
, strerror(-ret
));
3991 wpa_printf(MSG_DEBUG
,
3992 "nl80211: Frequency set succeeded for ht2040 coex");
3993 bss
->bandwidth
= params
->freq
->bandwidth
;
3995 } else if (!beacon_set
&& params
->freq
) {
3997 * cfg80211 updates the driver on frequence change in AP
3998 * mode only at the point when beaconing is started, so
3999 * set the initial value here.
4001 bss
->bandwidth
= params
->freq
->bandwidth
;
4006 if (is_mesh_interface(drv
->nlmode
) && params
->ht_opmode
!= -1) {
4007 os_memset(&mesh_params
, 0, sizeof(mesh_params
));
4008 mesh_params
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE
;
4009 mesh_params
.ht_opmode
= params
->ht_opmode
;
4010 ret
= nl80211_set_mesh_config(priv
, &mesh_params
);
4014 #endif /* CONFIG_MESH */
4023 static int nl80211_put_freq_params(struct nl_msg
*msg
,
4024 const struct hostapd_freq_params
*freq
)
4026 wpa_printf(MSG_DEBUG
, " * freq=%d", freq
->freq
);
4027 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
))
4030 wpa_printf(MSG_DEBUG
, " * vht_enabled=%d", freq
->vht_enabled
);
4031 wpa_printf(MSG_DEBUG
, " * ht_enabled=%d", freq
->ht_enabled
);
4033 if (freq
->vht_enabled
) {
4034 enum nl80211_chan_width cw
;
4036 wpa_printf(MSG_DEBUG
, " * bandwidth=%d", freq
->bandwidth
);
4037 switch (freq
->bandwidth
) {
4039 cw
= NL80211_CHAN_WIDTH_20
;
4042 cw
= NL80211_CHAN_WIDTH_40
;
4045 if (freq
->center_freq2
)
4046 cw
= NL80211_CHAN_WIDTH_80P80
;
4048 cw
= NL80211_CHAN_WIDTH_80
;
4051 cw
= NL80211_CHAN_WIDTH_160
;
4057 wpa_printf(MSG_DEBUG
, " * channel_width=%d", cw
);
4058 wpa_printf(MSG_DEBUG
, " * center_freq1=%d",
4059 freq
->center_freq1
);
4060 wpa_printf(MSG_DEBUG
, " * center_freq2=%d",
4061 freq
->center_freq2
);
4062 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, cw
) ||
4063 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
,
4064 freq
->center_freq1
) ||
4065 (freq
->center_freq2
&&
4066 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
,
4067 freq
->center_freq2
)))
4069 } else if (freq
->ht_enabled
) {
4070 enum nl80211_channel_type ct
;
4072 wpa_printf(MSG_DEBUG
, " * sec_channel_offset=%d",
4073 freq
->sec_channel_offset
);
4074 switch (freq
->sec_channel_offset
) {
4076 ct
= NL80211_CHAN_HT40MINUS
;
4079 ct
= NL80211_CHAN_HT40PLUS
;
4082 ct
= NL80211_CHAN_HT20
;
4086 wpa_printf(MSG_DEBUG
, " * channel_type=%d", ct
);
4087 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, ct
))
4090 wpa_printf(MSG_DEBUG
, " * channel_type=%d",
4091 NL80211_CHAN_NO_HT
);
4092 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4093 NL80211_CHAN_NO_HT
))
4100 static int nl80211_set_channel(struct i802_bss
*bss
,
4101 struct hostapd_freq_params
*freq
, int set_chan
)
4103 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4107 wpa_printf(MSG_DEBUG
,
4108 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
4109 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
4110 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
4112 msg
= nl80211_drv_msg(drv
, 0, set_chan
? NL80211_CMD_SET_CHANNEL
:
4113 NL80211_CMD_SET_WIPHY
);
4114 if (!msg
|| nl80211_put_freq_params(msg
, freq
) < 0) {
4119 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4121 bss
->freq
= freq
->freq
;
4124 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
4125 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
4130 static u32
sta_flags_nl80211(int flags
)
4134 if (flags
& WPA_STA_AUTHORIZED
)
4135 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
4136 if (flags
& WPA_STA_WMM
)
4137 f
|= BIT(NL80211_STA_FLAG_WME
);
4138 if (flags
& WPA_STA_SHORT_PREAMBLE
)
4139 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
4140 if (flags
& WPA_STA_MFP
)
4141 f
|= BIT(NL80211_STA_FLAG_MFP
);
4142 if (flags
& WPA_STA_TDLS_PEER
)
4143 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
4144 if (flags
& WPA_STA_AUTHENTICATED
)
4145 f
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
4146 if (flags
& WPA_STA_ASSOCIATED
)
4147 f
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
4154 static u32
sta_plink_state_nl80211(enum mesh_plink_state state
)
4158 return NL80211_PLINK_LISTEN
;
4160 return NL80211_PLINK_OPN_SNT
;
4161 case PLINK_OPN_RCVD
:
4162 return NL80211_PLINK_OPN_RCVD
;
4163 case PLINK_CNF_RCVD
:
4164 return NL80211_PLINK_CNF_RCVD
;
4166 return NL80211_PLINK_ESTAB
;
4168 return NL80211_PLINK_HOLDING
;
4170 return NL80211_PLINK_BLOCKED
;
4172 wpa_printf(MSG_ERROR
, "nl80211: Invalid mesh plink state %d",
4177 #endif /* CONFIG_MESH */
4180 static int wpa_driver_nl80211_sta_add(void *priv
,
4181 struct hostapd_sta_add_params
*params
)
4183 struct i802_bss
*bss
= priv
;
4184 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4186 struct nl80211_sta_flag_update upd
;
4189 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
4190 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
4193 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
4194 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
4195 msg
= nl80211_bss_msg(bss
, 0, params
->set
? NL80211_CMD_SET_STATION
:
4196 NL80211_CMD_NEW_STATION
);
4197 if (!msg
|| nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
))
4201 * Set the below properties only in one of the following cases:
4202 * 1. New station is added, already associated.
4203 * 2. Set WPA_STA_TDLS_PEER station.
4204 * 3. Set an already added unassociated station, if driver supports
4205 * full AP client state. (Set these properties after station became
4206 * associated will be rejected by the driver).
4208 if (!params
->set
|| (params
->flags
& WPA_STA_TDLS_PEER
) ||
4209 (params
->set
&& FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
) &&
4210 (params
->flags
& WPA_STA_ASSOCIATED
))) {
4211 wpa_hexdump(MSG_DEBUG
, " * supported rates",
4212 params
->supp_rates
, params
->supp_rates_len
);
4213 wpa_printf(MSG_DEBUG
, " * capability=0x%x",
4214 params
->capability
);
4215 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
,
4216 params
->supp_rates_len
, params
->supp_rates
) ||
4217 nla_put_u16(msg
, NL80211_ATTR_STA_CAPABILITY
,
4218 params
->capability
))
4221 if (params
->ht_capabilities
) {
4222 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
4223 (u8
*) params
->ht_capabilities
,
4224 sizeof(*params
->ht_capabilities
));
4225 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
,
4226 sizeof(*params
->ht_capabilities
),
4227 params
->ht_capabilities
))
4231 if (params
->vht_capabilities
) {
4232 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
4233 (u8
*) params
->vht_capabilities
,
4234 sizeof(*params
->vht_capabilities
));
4235 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
,
4236 sizeof(*params
->vht_capabilities
),
4237 params
->vht_capabilities
))
4241 if (params
->ext_capab
) {
4242 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
4243 params
->ext_capab
, params
->ext_capab_len
);
4244 if (nla_put(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
4245 params
->ext_capab_len
, params
->ext_capab
))
4249 if (is_ap_interface(drv
->nlmode
) &&
4250 nla_put_u8(msg
, NL80211_ATTR_STA_SUPPORT_P2P_PS
,
4251 params
->support_p2p_ps
?
4252 NL80211_P2P_PS_SUPPORTED
:
4253 NL80211_P2P_PS_UNSUPPORTED
))
4258 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
4259 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
))
4263 * cfg80211 validates that AID is non-zero, so we have
4264 * to make this a non-zero value for the TDLS case where
4265 * a dummy STA entry is used for now and for a station
4266 * that is still not associated.
4268 wpa_printf(MSG_DEBUG
, " * aid=1 (%s workaround)",
4269 (params
->flags
& WPA_STA_TDLS_PEER
) ?
4270 "TDLS" : "UNASSOC_STA");
4271 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, 1))
4274 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
4275 params
->listen_interval
);
4276 if (nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4277 params
->listen_interval
))
4279 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
4280 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
4281 if (nla_put_u16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
))
4283 } else if (FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
) &&
4284 (params
->flags
& WPA_STA_ASSOCIATED
)) {
4285 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
4286 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
4287 params
->listen_interval
);
4288 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
) ||
4289 nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4290 params
->listen_interval
))
4294 if (params
->vht_opmode_enabled
) {
4295 wpa_printf(MSG_DEBUG
, " * opmode=%u", params
->vht_opmode
);
4296 if (nla_put_u8(msg
, NL80211_ATTR_OPMODE_NOTIF
,
4297 params
->vht_opmode
))
4301 if (params
->supp_channels
) {
4302 wpa_hexdump(MSG_DEBUG
, " * supported channels",
4303 params
->supp_channels
, params
->supp_channels_len
);
4304 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_CHANNELS
,
4305 params
->supp_channels_len
, params
->supp_channels
))
4309 if (params
->supp_oper_classes
) {
4310 wpa_hexdump(MSG_DEBUG
, " * supported operating classes",
4311 params
->supp_oper_classes
,
4312 params
->supp_oper_classes_len
);
4313 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
,
4314 params
->supp_oper_classes_len
,
4315 params
->supp_oper_classes
))
4319 os_memset(&upd
, 0, sizeof(upd
));
4320 upd
.set
= sta_flags_nl80211(params
->flags
);
4321 upd
.mask
= upd
.set
| sta_flags_nl80211(params
->flags_mask
);
4324 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
4325 * flags, as nl80211 driver moves a new station, by default, into
4328 * On the other hand, if the driver supports that feature and the
4329 * station is added in unauthenticated state, set the
4330 * authenticated/associated bits in the mask to prevent moving this
4331 * station to associated state before it is actually associated.
4333 * This is irrelevant for mesh mode where the station is added to the
4334 * driver as authenticated already, and ASSOCIATED isn't part of the
4337 if (!is_mesh_interface(drv
->nlmode
)) {
4338 if (!FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
)) {
4339 wpa_printf(MSG_DEBUG
,
4340 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
4341 upd
.mask
&= ~(BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4342 BIT(NL80211_STA_FLAG_AUTHENTICATED
));
4343 } else if (!params
->set
&&
4344 !(params
->flags
& WPA_STA_TDLS_PEER
)) {
4345 if (!(params
->flags
& WPA_STA_AUTHENTICATED
))
4346 upd
.mask
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
4347 if (!(params
->flags
& WPA_STA_ASSOCIATED
))
4348 upd
.mask
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
4352 if (params
->plink_state
== PLINK_ESTAB
&& params
->peer_aid
) {
4353 ret
= nla_put_u16(msg
, NL80211_ATTR_MESH_PEER_AID
,
4358 #endif /* CONFIG_MESH */
4361 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
4363 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
4367 if (params
->plink_state
&&
4368 nla_put_u8(msg
, NL80211_ATTR_STA_PLINK_STATE
,
4369 sta_plink_state_nl80211(params
->plink_state
)))
4371 #endif /* CONFIG_MESH */
4373 if (params
->flags
& WPA_STA_WMM
) {
4374 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
4376 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
4378 nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
4379 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
) ||
4380 nla_put_u8(msg
, NL80211_STA_WME_MAX_SP
,
4381 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
4382 WMM_QOSINFO_STA_SP_MASK
))
4384 nla_nest_end(msg
, wme
);
4387 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4390 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
4391 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
4401 static void rtnl_neigh_delete_fdb_entry(struct i802_bss
*bss
, const u8
*addr
)
4403 #ifdef CONFIG_LIBNL3_ROUTE
4404 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4405 struct rtnl_neigh
*rn
;
4406 struct nl_addr
*nl_addr
;
4409 rn
= rtnl_neigh_alloc();
4413 rtnl_neigh_set_family(rn
, AF_BRIDGE
);
4414 rtnl_neigh_set_ifindex(rn
, bss
->ifindex
);
4415 nl_addr
= nl_addr_build(AF_BRIDGE
, (void *) addr
, ETH_ALEN
);
4420 rtnl_neigh_set_lladdr(rn
, nl_addr
);
4422 err
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
4424 wpa_printf(MSG_DEBUG
, "nl80211: bridge FDB entry delete for "
4425 MACSTR
" ifindex=%d failed: %s", MAC2STR(addr
),
4426 bss
->ifindex
, nl_geterror(err
));
4428 wpa_printf(MSG_DEBUG
, "nl80211: deleted bridge FDB entry for "
4429 MACSTR
, MAC2STR(addr
));
4432 nl_addr_put(nl_addr
);
4434 #endif /* CONFIG_LIBNL3_ROUTE */
4438 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
,
4439 int deauth
, u16 reason_code
)
4441 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4445 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
)) ||
4446 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
4448 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
4449 WLAN_FC_STYPE_DISASSOC
)) ||
4451 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
4452 WLAN_FC_STYPE_DEAUTH
)) ||
4454 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
))) {
4459 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4460 wpa_printf(MSG_DEBUG
, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4462 bss
->ifname
, MAC2STR(addr
), ret
, strerror(-ret
));
4465 rtnl_neigh_delete_fdb_entry(bss
, addr
);
4473 void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
4476 struct wpa_driver_nl80211_data
*drv2
;
4478 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
4480 /* stop listening for EAPOL on this interface */
4481 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
4482 struct wpa_driver_nl80211_data
, list
)
4484 del_ifidx(drv2
, ifidx
, IFIDX_ANY
);
4485 /* Remove all bridges learned for this iface */
4486 del_ifidx(drv2
, IFIDX_ANY
, ifidx
);
4489 msg
= nl80211_ifindex_msg(drv
, ifidx
, 0, NL80211_CMD_DEL_INTERFACE
);
4490 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
4492 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
4496 const char * nl80211_iftype_str(enum nl80211_iftype mode
)
4499 case NL80211_IFTYPE_ADHOC
:
4501 case NL80211_IFTYPE_STATION
:
4503 case NL80211_IFTYPE_AP
:
4505 case NL80211_IFTYPE_AP_VLAN
:
4507 case NL80211_IFTYPE_WDS
:
4509 case NL80211_IFTYPE_MONITOR
:
4511 case NL80211_IFTYPE_MESH_POINT
:
4512 return "MESH_POINT";
4513 case NL80211_IFTYPE_P2P_CLIENT
:
4514 return "P2P_CLIENT";
4515 case NL80211_IFTYPE_P2P_GO
:
4517 case NL80211_IFTYPE_P2P_DEVICE
:
4518 return "P2P_DEVICE";
4525 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
4527 enum nl80211_iftype iftype
,
4528 const u8
*addr
, int wds
,
4529 int (*handler
)(struct nl_msg
*, void *),
4536 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
4537 iftype
, nl80211_iftype_str(iftype
));
4539 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_NEW_INTERFACE
);
4541 nla_put_string(msg
, NL80211_ATTR_IFNAME
, ifname
) ||
4542 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, iftype
))
4545 if (iftype
== NL80211_IFTYPE_MONITOR
) {
4546 struct nlattr
*flags
;
4548 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
4550 nla_put_flag(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
))
4553 nla_nest_end(msg
, flags
);
4555 if (nla_put_u8(msg
, NL80211_ATTR_4ADDR
, wds
))
4560 * Tell cfg80211 that the interface belongs to the socket that created
4561 * it, and the interface should be deleted when the socket is closed.
4563 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
4566 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
4571 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
4572 ifname
, ret
, strerror(-ret
));
4576 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
)
4579 ifidx
= if_nametoindex(ifname
);
4580 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
4587 * Some virtual interfaces need to process EAPOL packets and events on
4588 * the parent interface. This is used mainly with hostapd.
4591 iftype
== NL80211_IFTYPE_AP_VLAN
||
4592 iftype
== NL80211_IFTYPE_WDS
||
4593 iftype
== NL80211_IFTYPE_MONITOR
) {
4594 /* start listening for EAPOL on this interface */
4595 add_ifidx(drv
, ifidx
, IFIDX_ANY
);
4598 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4599 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
4600 nl80211_remove_iface(drv
, ifidx
);
4608 int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
4609 const char *ifname
, enum nl80211_iftype iftype
,
4610 const u8
*addr
, int wds
,
4611 int (*handler
)(struct nl_msg
*, void *),
4612 void *arg
, int use_existing
)
4616 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
4619 /* if error occurred and interface exists already */
4620 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
4622 wpa_printf(MSG_DEBUG
, "nl80211: Continue using existing interface %s",
4624 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4625 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
4627 (linux_set_iface_flags(drv
->global
->ioctl_sock
,
4629 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
4631 linux_set_iface_flags(drv
->global
->ioctl_sock
,
4636 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
4638 /* Try to remove the interface that was already there. */
4639 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
4641 /* Try to create the interface again */
4642 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
4646 if (ret
>= 0 && is_p2p_net_interface(iftype
)) {
4647 wpa_printf(MSG_DEBUG
,
4648 "nl80211: Interface %s created for P2P - disable 11b rates",
4650 nl80211_disable_11b_rates(drv
, ret
, 1);
4657 static int nl80211_setup_ap(struct i802_bss
*bss
)
4659 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4661 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4662 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
4665 * Disable Probe Request reporting unless we need it in this way for
4666 * devices that include the AP SME, in the other case (unless using
4667 * monitor iface) we'll get it through the nl_mgmt socket instead.
4669 if (!drv
->device_ap_sme
)
4670 wpa_driver_nl80211_probe_req_report(bss
, 0);
4672 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
4673 if (nl80211_mgmt_subscribe_ap(bss
))
4676 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
4677 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
4678 wpa_printf(MSG_DEBUG
,
4679 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
4681 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
4682 nl80211_create_monitor_interface(drv
) &&
4683 !drv
->device_ap_sme
)
4686 if (drv
->device_ap_sme
&&
4687 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
4688 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
4689 "Probe Request frame reporting in AP mode");
4690 /* Try to survive without this */
4697 static void nl80211_teardown_ap(struct i802_bss
*bss
)
4699 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4701 wpa_printf(MSG_DEBUG
, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4702 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
4703 if (drv
->device_ap_sme
) {
4704 wpa_driver_nl80211_probe_req_report(bss
, 0);
4705 if (!drv
->use_monitor
)
4706 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
4707 } else if (drv
->use_monitor
)
4708 nl80211_remove_monitor_interface(drv
);
4710 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
4712 bss
->beacon_set
= 0;
4716 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
4717 const u8
*addr
, const u8
*data
,
4720 struct sockaddr_ll ll
;
4723 if (bss
->drv
->eapol_tx_sock
< 0) {
4724 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
4728 os_memset(&ll
, 0, sizeof(ll
));
4729 ll
.sll_family
= AF_PACKET
;
4730 ll
.sll_ifindex
= bss
->ifindex
;
4731 ll
.sll_protocol
= htons(ETH_P_PAE
);
4732 ll
.sll_halen
= ETH_ALEN
;
4733 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
4734 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
4735 (struct sockaddr
*) &ll
, sizeof(ll
));
4737 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
4744 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4746 static int wpa_driver_nl80211_hapd_send_eapol(
4747 void *priv
, const u8
*addr
, const u8
*data
,
4748 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
4750 struct i802_bss
*bss
= priv
;
4751 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4752 struct ieee80211_hdr
*hdr
;
4756 int qos
= flags
& WPA_STA_WMM
;
4758 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
4759 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
4761 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
4763 hdr
= os_zalloc(len
);
4765 wpa_printf(MSG_INFO
, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4766 (unsigned long) len
);
4770 hdr
->frame_control
=
4771 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
4772 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
4774 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
4776 hdr
->frame_control
|=
4777 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
4780 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
4781 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
4782 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
4783 pos
= (u8
*) (hdr
+ 1);
4786 /* Set highest priority in QoS header */
4792 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
4793 pos
+= sizeof(rfc1042_header
);
4794 WPA_PUT_BE16(pos
, ETH_P_PAE
);
4796 memcpy(pos
, data
, data_len
);
4798 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
4799 0, 0, 0, 0, NULL
, 0);
4801 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
4803 (unsigned long) len
, errno
, strerror(errno
));
4811 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
4812 unsigned int total_flags
,
4813 unsigned int flags_or
,
4814 unsigned int flags_and
)
4816 struct i802_bss
*bss
= priv
;
4818 struct nlattr
*flags
;
4819 struct nl80211_sta_flag_update upd
;
4821 wpa_printf(MSG_DEBUG
, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4822 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4823 bss
->ifname
, MAC2STR(addr
), total_flags
, flags_or
, flags_and
,
4824 !!(total_flags
& WPA_STA_AUTHORIZED
));
4826 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
4827 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
4831 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4832 * can be removed eventually.
4834 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
4836 ((total_flags
& WPA_STA_AUTHORIZED
) &&
4837 nla_put_flag(msg
, NL80211_STA_FLAG_AUTHORIZED
)) ||
4838 ((total_flags
& WPA_STA_WMM
) &&
4839 nla_put_flag(msg
, NL80211_STA_FLAG_WME
)) ||
4840 ((total_flags
& WPA_STA_SHORT_PREAMBLE
) &&
4841 nla_put_flag(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
)) ||
4842 ((total_flags
& WPA_STA_MFP
) &&
4843 nla_put_flag(msg
, NL80211_STA_FLAG_MFP
)) ||
4844 ((total_flags
& WPA_STA_TDLS_PEER
) &&
4845 nla_put_flag(msg
, NL80211_STA_FLAG_TDLS_PEER
)))
4848 nla_nest_end(msg
, flags
);
4850 os_memset(&upd
, 0, sizeof(upd
));
4851 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
4852 upd
.set
= sta_flags_nl80211(flags_or
);
4853 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
4856 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
4863 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
4864 struct wpa_driver_associate_params
*params
)
4866 enum nl80211_iftype nlmode
, old_mode
;
4869 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
4871 nlmode
= NL80211_IFTYPE_P2P_GO
;
4873 nlmode
= NL80211_IFTYPE_AP
;
4875 old_mode
= drv
->nlmode
;
4876 if (wpa_driver_nl80211_set_mode(drv
->first_bss
, nlmode
)) {
4877 nl80211_remove_monitor_interface(drv
);
4881 if (params
->freq
.freq
&&
4882 nl80211_set_channel(drv
->first_bss
, ¶ms
->freq
, 0)) {
4883 if (old_mode
!= nlmode
)
4884 wpa_driver_nl80211_set_mode(drv
->first_bss
, old_mode
);
4885 nl80211_remove_monitor_interface(drv
);
4893 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
4899 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_IBSS
);
4900 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4902 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
4903 "(%s)", ret
, strerror(-ret
));
4905 wpa_printf(MSG_DEBUG
,
4906 "nl80211: Leave IBSS request sent successfully");
4910 wpa_driver_nl80211_set_mode(drv
->first_bss
,
4911 NL80211_IFTYPE_STATION
)) {
4912 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
4920 static int nl80211_ht_vht_overrides(struct nl_msg
*msg
,
4921 struct wpa_driver_associate_params
*params
)
4923 if (params
->disable_ht
&& nla_put_flag(msg
, NL80211_ATTR_DISABLE_HT
))
4926 if (params
->htcaps
&& params
->htcaps_mask
) {
4927 int sz
= sizeof(struct ieee80211_ht_capabilities
);
4928 wpa_hexdump(MSG_DEBUG
, " * htcaps", params
->htcaps
, sz
);
4929 wpa_hexdump(MSG_DEBUG
, " * htcaps_mask",
4930 params
->htcaps_mask
, sz
);
4931 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
,
4933 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
4934 params
->htcaps_mask
))
4938 #ifdef CONFIG_VHT_OVERRIDES
4939 if (params
->disable_vht
) {
4940 wpa_printf(MSG_DEBUG
, " * VHT disabled");
4941 if (nla_put_flag(msg
, NL80211_ATTR_DISABLE_VHT
))
4945 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
4946 int sz
= sizeof(struct ieee80211_vht_capabilities
);
4947 wpa_hexdump(MSG_DEBUG
, " * vhtcaps", params
->vhtcaps
, sz
);
4948 wpa_hexdump(MSG_DEBUG
, " * vhtcaps_mask",
4949 params
->vhtcaps_mask
, sz
);
4950 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
,
4952 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
4953 params
->vhtcaps_mask
))
4956 #endif /* CONFIG_VHT_OVERRIDES */
4962 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
4963 struct wpa_driver_associate_params
*params
)
4969 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
4971 if (wpa_driver_nl80211_set_mode_ibss(drv
->first_bss
, ¶ms
->freq
)) {
4972 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
4978 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_IBSS
)) ||
4979 params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
4982 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4983 params
->ssid
, params
->ssid_len
);
4984 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
4986 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
4987 drv
->ssid_len
= params
->ssid_len
;
4989 if (nl80211_put_freq_params(msg
, ¶ms
->freq
) < 0 ||
4990 nl80211_put_beacon_int(msg
, params
->beacon_int
))
4993 ret
= nl80211_set_conn_keys(params
, msg
);
4997 if (params
->bssid
&& params
->fixed_bssid
) {
4998 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
4999 MAC2STR(params
->bssid
));
5000 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
5004 if (params
->fixed_freq
) {
5005 wpa_printf(MSG_DEBUG
, " * fixed_freq");
5006 if (nla_put_flag(msg
, NL80211_ATTR_FREQ_FIXED
))
5010 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
5011 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5012 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
5013 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
) {
5014 wpa_printf(MSG_DEBUG
, " * control port");
5015 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
5019 if (params
->wpa_ie
) {
5020 wpa_hexdump(MSG_DEBUG
,
5021 " * Extra IEs for Beacon/Probe Response frames",
5022 params
->wpa_ie
, params
->wpa_ie_len
);
5023 if (nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5028 ret
= nl80211_ht_vht_overrides(msg
, params
);
5032 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5035 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
5036 ret
, strerror(-ret
));
5038 if (ret
== -EALREADY
&& count
== 1) {
5039 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
5041 nl80211_leave_ibss(drv
, 0);
5046 wpa_printf(MSG_DEBUG
,
5047 "nl80211: Join IBSS request sent successfully");
5056 static int nl80211_connect_common(struct wpa_driver_nl80211_data
*drv
,
5057 struct wpa_driver_associate_params
*params
,
5060 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
5063 if (params
->bssid
) {
5064 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5065 MAC2STR(params
->bssid
));
5066 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
5070 if (params
->bssid_hint
) {
5071 wpa_printf(MSG_DEBUG
, " * bssid_hint=" MACSTR
,
5072 MAC2STR(params
->bssid_hint
));
5073 if (nla_put(msg
, NL80211_ATTR_MAC_HINT
, ETH_ALEN
,
5074 params
->bssid_hint
))
5078 if (params
->freq
.freq
) {
5079 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
.freq
);
5080 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
5083 drv
->assoc_freq
= params
->freq
.freq
;
5085 drv
->assoc_freq
= 0;
5087 if (params
->freq_hint
) {
5088 wpa_printf(MSG_DEBUG
, " * freq_hint=%d", params
->freq_hint
);
5089 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_HINT
,
5094 if (params
->bg_scan_period
>= 0) {
5095 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
5096 params
->bg_scan_period
);
5097 if (nla_put_u16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
5098 params
->bg_scan_period
))
5103 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5104 params
->ssid
, params
->ssid_len
);
5105 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5108 if (params
->ssid_len
> sizeof(drv
->ssid
))
5110 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5111 drv
->ssid_len
= params
->ssid_len
;
5114 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
5115 if (params
->wpa_ie
&&
5116 nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
, params
->wpa_ie
))
5119 if (params
->wpa_proto
) {
5120 enum nl80211_wpa_versions ver
= 0;
5122 if (params
->wpa_proto
& WPA_PROTO_WPA
)
5123 ver
|= NL80211_WPA_VERSION_1
;
5124 if (params
->wpa_proto
& WPA_PROTO_RSN
)
5125 ver
|= NL80211_WPA_VERSION_2
;
5127 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
5128 if (nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
5132 if (params
->pairwise_suite
!= WPA_CIPHER_NONE
) {
5133 u32 cipher
= wpa_cipher_to_cipher_suite(params
->pairwise_suite
);
5134 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
5135 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
5140 if (params
->group_suite
== WPA_CIPHER_GTK_NOT_USED
&&
5141 !(drv
->capa
.enc
& WPA_DRIVER_CAPA_ENC_GTK_NOT_USED
)) {
5143 * This is likely to work even though many drivers do not
5144 * advertise support for operations without GTK.
5146 wpa_printf(MSG_DEBUG
, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
5147 } else if (params
->group_suite
!= WPA_CIPHER_NONE
) {
5148 u32 cipher
= wpa_cipher_to_cipher_suite(params
->group_suite
);
5149 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
5150 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
))
5154 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
5155 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5156 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_IEEE8021X
||
5157 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
||
5158 params
->key_mgmt_suite
== WPA_KEY_MGMT_CCKM
||
5159 params
->key_mgmt_suite
== WPA_KEY_MGMT_OSEN
||
5160 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
5161 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
5162 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
||
5163 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
5164 int mgmt
= WLAN_AKM_SUITE_PSK
;
5166 switch (params
->key_mgmt_suite
) {
5167 case WPA_KEY_MGMT_CCKM
:
5168 mgmt
= WLAN_AKM_SUITE_CCKM
;
5170 case WPA_KEY_MGMT_IEEE8021X
:
5171 mgmt
= WLAN_AKM_SUITE_8021X
;
5173 case WPA_KEY_MGMT_FT_IEEE8021X
:
5174 mgmt
= WLAN_AKM_SUITE_FT_8021X
;
5176 case WPA_KEY_MGMT_FT_PSK
:
5177 mgmt
= WLAN_AKM_SUITE_FT_PSK
;
5179 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
5180 mgmt
= WLAN_AKM_SUITE_8021X_SHA256
;
5182 case WPA_KEY_MGMT_PSK_SHA256
:
5183 mgmt
= WLAN_AKM_SUITE_PSK_SHA256
;
5185 case WPA_KEY_MGMT_OSEN
:
5186 mgmt
= WLAN_AKM_SUITE_OSEN
;
5188 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
5189 mgmt
= WLAN_AKM_SUITE_8021X_SUITE_B
;
5191 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
5192 mgmt
= WLAN_AKM_SUITE_8021X_SUITE_B_192
;
5194 case WPA_KEY_MGMT_PSK
:
5196 mgmt
= WLAN_AKM_SUITE_PSK
;
5199 wpa_printf(MSG_DEBUG
, " * akm=0x%x", mgmt
);
5200 if (nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
))
5204 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
5207 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
5208 (params
->pairwise_suite
== WPA_CIPHER_NONE
||
5209 params
->pairwise_suite
== WPA_CIPHER_WEP104
||
5210 params
->pairwise_suite
== WPA_CIPHER_WEP40
) &&
5211 (nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, ETH_P_PAE
) ||
5212 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
5215 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
&&
5216 nla_put_u32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
))
5219 if (params
->rrm_used
) {
5220 u32 drv_rrm_flags
= drv
->capa
.rrm_flags
;
5221 if ((!((drv_rrm_flags
&
5222 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
5223 (drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
5224 !(drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) ||
5225 nla_put_flag(msg
, NL80211_ATTR_USE_RRM
))
5229 if (nl80211_ht_vht_overrides(msg
, params
) < 0)
5233 wpa_printf(MSG_DEBUG
, " * P2P group");
5236 wpa_printf(MSG_DEBUG
, " * PBSS");
5237 if (nla_put_flag(msg
, NL80211_ATTR_PBSS
))
5241 drv
->connect_reassoc
= 0;
5242 if (params
->prev_bssid
) {
5243 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
5244 MAC2STR(params
->prev_bssid
));
5245 if (nla_put(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
5246 params
->prev_bssid
))
5248 drv
->connect_reassoc
= 1;
5255 static int wpa_driver_nl80211_try_connect(
5256 struct wpa_driver_nl80211_data
*drv
,
5257 struct wpa_driver_associate_params
*params
)
5260 enum nl80211_auth_type type
;
5264 #ifdef CONFIG_DRIVER_NL80211_QCA
5265 if (params
->req_key_mgmt_offload
&& params
->psk
&&
5266 (params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5267 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
5268 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
5269 wpa_printf(MSG_DEBUG
, "nl80211: Key management set PSK");
5270 ret
= issue_key_mgmt_set_key(drv
, params
->psk
, 32);
5274 #endif /* CONFIG_DRIVER_NL80211_QCA */
5276 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
5277 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_CONNECT
);
5281 ret
= nl80211_connect_common(drv
, params
, msg
);
5286 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5288 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5290 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5293 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
5295 goto skip_auth_type
;
5298 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5299 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
5300 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5301 type
= NL80211_AUTHTYPE_SHARED_KEY
;
5302 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5303 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
5304 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
5305 type
= NL80211_AUTHTYPE_FT
;
5309 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5310 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
5314 ret
= nl80211_set_conn_keys(params
, msg
);
5318 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5321 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
5322 "(%s)", ret
, strerror(-ret
));
5324 wpa_printf(MSG_DEBUG
,
5325 "nl80211: Connect request send successfully");
5335 static int wpa_driver_nl80211_connect(
5336 struct wpa_driver_nl80211_data
*drv
,
5337 struct wpa_driver_associate_params
*params
)
5341 /* Store the connection attempted bssid for future use */
5343 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
5345 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
5347 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
5348 if (ret
== -EALREADY
) {
5350 * cfg80211 does not currently accept new connections if
5351 * we are already connected. As a workaround, force
5352 * disconnection and try again.
5354 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
5355 "disconnecting before reassociation "
5357 if (wpa_driver_nl80211_disconnect(
5358 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
5360 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
5366 static int wpa_driver_nl80211_associate(
5367 void *priv
, struct wpa_driver_associate_params
*params
)
5369 struct i802_bss
*bss
= priv
;
5370 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5374 nl80211_unmask_11b_rates(bss
);
5376 if (params
->mode
== IEEE80211_MODE_AP
)
5377 return wpa_driver_nl80211_ap(drv
, params
);
5379 if (params
->mode
== IEEE80211_MODE_IBSS
)
5380 return wpa_driver_nl80211_ibss(drv
, params
);
5382 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
5383 enum nl80211_iftype nlmode
= params
->p2p
?
5384 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
5386 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
5388 return wpa_driver_nl80211_connect(drv
, params
);
5391 nl80211_mark_disconnected(drv
);
5393 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
5395 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_ASSOCIATE
);
5399 ret
= nl80211_connect_common(drv
, params
, msg
);
5403 if (params
->fils_kek
) {
5404 wpa_printf(MSG_DEBUG
, " * FILS KEK (len=%u)",
5405 (unsigned int) params
->fils_kek_len
);
5406 if (nla_put(msg
, NL80211_ATTR_FILS_KEK
, params
->fils_kek_len
,
5410 if (params
->fils_nonces
) {
5411 wpa_hexdump(MSG_DEBUG
, " * FILS nonces (for AAD)",
5412 params
->fils_nonces
,
5413 params
->fils_nonces_len
);
5414 if (nla_put(msg
, NL80211_ATTR_FILS_NONCES
,
5415 params
->fils_nonces_len
, params
->fils_nonces
))
5419 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5422 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5423 "nl80211: MLME command failed (assoc): ret=%d (%s)",
5424 ret
, strerror(-ret
));
5425 nl80211_dump_scan(drv
);
5427 wpa_printf(MSG_DEBUG
,
5428 "nl80211: Association request send successfully");
5437 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
5438 int ifindex
, enum nl80211_iftype mode
)
5443 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
5444 ifindex
, mode
, nl80211_iftype_str(mode
));
5446 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_SET_INTERFACE
);
5447 if (!msg
|| nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, mode
))
5450 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5456 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
5457 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
5462 static int wpa_driver_nl80211_set_mode_impl(
5463 struct i802_bss
*bss
,
5464 enum nl80211_iftype nlmode
,
5465 struct hostapd_freq_params
*desired_freq_params
)
5467 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5470 int was_ap
= is_ap_interface(drv
->nlmode
);
5472 int mode_switch_res
;
5477 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
5478 if (mode_switch_res
&& nlmode
== nl80211_get_ifmode(bss
))
5479 mode_switch_res
= 0;
5481 if (mode_switch_res
== 0) {
5482 drv
->nlmode
= nlmode
;
5487 if (mode_switch_res
== -ENODEV
)
5490 if (nlmode
== drv
->nlmode
) {
5491 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
5492 "requested mode - ignore error");
5494 goto done
; /* Already in the requested mode */
5497 /* mac80211 doesn't allow mode changes while the device is up, so
5498 * take the device down, try to set the mode again, and bring the
5501 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
5503 for (i
= 0; i
< 10; i
++) {
5504 res
= i802_set_iface_flags(bss
, 0);
5505 if (res
== -EACCES
|| res
== -ENODEV
)
5508 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
5510 os_sleep(0, 100000);
5515 * Setting the mode will fail for some drivers if the phy is
5516 * on a frequency that the mode is disallowed in.
5518 if (desired_freq_params
) {
5519 res
= nl80211_set_channel(bss
, desired_freq_params
, 0);
5521 wpa_printf(MSG_DEBUG
,
5522 "nl80211: Failed to set frequency on interface");
5526 /* Try to set the mode again while the interface is down */
5527 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
5528 if (mode_switch_res
== -EBUSY
) {
5529 wpa_printf(MSG_DEBUG
,
5530 "nl80211: Delaying mode set while interface going down");
5531 os_sleep(0, 100000);
5534 ret
= mode_switch_res
;
5539 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
5540 "interface is down");
5541 drv
->nlmode
= nlmode
;
5542 drv
->ignore_if_down_event
= 1;
5545 /* Bring the interface back up */
5546 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1);
5548 wpa_printf(MSG_DEBUG
,
5549 "nl80211: Failed to set interface up after switching mode");
5555 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
5556 "from %d failed", nlmode
, drv
->nlmode
);
5560 if (is_p2p_net_interface(nlmode
)) {
5561 wpa_printf(MSG_DEBUG
,
5562 "nl80211: Interface %s mode change to P2P - disable 11b rates",
5564 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
5565 } else if (drv
->disabled_11b_rates
) {
5566 wpa_printf(MSG_DEBUG
,
5567 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
5569 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
5572 if (is_ap_interface(nlmode
)) {
5573 nl80211_mgmt_unsubscribe(bss
, "start AP");
5574 /* Setup additional AP mode functionality if needed */
5575 if (nl80211_setup_ap(bss
))
5577 } else if (was_ap
) {
5578 /* Remove additional AP mode functionality */
5579 nl80211_teardown_ap(bss
);
5581 nl80211_mgmt_unsubscribe(bss
, "mode change");
5584 if (is_mesh_interface(nlmode
) &&
5585 nl80211_mgmt_subscribe_mesh(bss
))
5588 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
5589 !is_mesh_interface(nlmode
) &&
5590 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
5591 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
5592 "frame processing - ignore for now");
5598 int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
5599 enum nl80211_iftype nlmode
)
5601 return wpa_driver_nl80211_set_mode_impl(bss
, nlmode
, NULL
);
5605 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
5606 struct hostapd_freq_params
*freq
)
5608 return wpa_driver_nl80211_set_mode_impl(bss
, NL80211_IFTYPE_ADHOC
,
5613 static int wpa_driver_nl80211_get_capa(void *priv
,
5614 struct wpa_driver_capa
*capa
)
5616 struct i802_bss
*bss
= priv
;
5617 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5619 if (!drv
->has_capability
)
5621 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
5622 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
5623 capa
->extended_capa
= drv
->extended_capa
;
5624 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
5625 capa
->extended_capa_len
= drv
->extended_capa_len
;
5632 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
5634 struct i802_bss
*bss
= priv
;
5635 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5637 wpa_printf(MSG_DEBUG
, "nl80211: Set %s operstate %d->%d (%s)",
5638 bss
->ifname
, drv
->operstate
, state
,
5639 state
? "UP" : "DORMANT");
5640 drv
->operstate
= state
;
5641 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
5642 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
5646 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
5648 struct i802_bss
*bss
= priv
;
5649 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5651 struct nl80211_sta_flag_update upd
;
5654 if (!drv
->associated
&& is_zero_ether_addr(drv
->bssid
) && !authorized
) {
5655 wpa_printf(MSG_DEBUG
, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5659 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
5660 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
5662 os_memset(&upd
, 0, sizeof(upd
));
5663 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5665 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5667 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5668 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
) ||
5669 nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
)) {
5674 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5677 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set STA flag: %d (%s)",
5678 ret
, strerror(-ret
));
5683 /* Set kernel driver on given frequency (MHz) */
5684 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
5686 struct i802_bss
*bss
= priv
;
5687 return nl80211_set_channel(bss
, freq
, 0);
5691 static inline int min_int(int a
, int b
)
5699 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
5701 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5702 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5704 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5705 genlmsg_attrlen(gnlh
, 0), NULL
);
5708 * TODO: validate the key index and mac address!
5709 * Otherwise, there's a race condition as soon as
5710 * the kernel starts sending key notifications.
5713 if (tb
[NL80211_ATTR_KEY_SEQ
])
5714 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
5715 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
5720 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
5723 struct i802_bss
*bss
= priv
;
5724 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5727 msg
= nl80211_ifindex_msg(drv
, if_nametoindex(iface
), 0,
5728 NL80211_CMD_GET_KEY
);
5730 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
5731 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, idx
)) {
5738 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
5742 static int i802_set_rts(void *priv
, int rts
)
5744 struct i802_bss
*bss
= priv
;
5745 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5755 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5756 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
)) {
5761 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5764 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
5765 "%d (%s)", rts
, ret
, strerror(-ret
));
5770 static int i802_set_frag(void *priv
, int frag
)
5772 struct i802_bss
*bss
= priv
;
5773 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5783 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5784 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
)) {
5789 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5792 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
5793 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
5798 static int i802_flush(void *priv
)
5800 struct i802_bss
*bss
= priv
;
5804 wpa_printf(MSG_DEBUG
, "nl80211: flush -> DEL_STATION %s (all)",
5808 * XXX: FIX! this needs to flush all VLANs too
5810 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
);
5811 res
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
5813 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
5814 "(%s)", res
, strerror(-res
));
5820 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
5822 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5823 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5824 struct hostap_sta_driver_data
*data
= arg
;
5825 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
5826 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
5827 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
5828 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
5829 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
5830 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
5831 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
5832 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
5833 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
5834 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
5837 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5838 genlmsg_attrlen(gnlh
, 0), NULL
);
5841 * TODO: validate the interface and mac address!
5842 * Otherwise, there's a race condition as soon as
5843 * the kernel starts sending station notifications.
5846 if (!tb
[NL80211_ATTR_STA_INFO
]) {
5847 wpa_printf(MSG_DEBUG
, "sta stats missing!");
5850 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
5851 tb
[NL80211_ATTR_STA_INFO
],
5853 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
5857 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
5858 data
->inactive_msec
=
5859 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
5860 /* For backwards compatibility, fetch the 32-bit counters first. */
5861 if (stats
[NL80211_STA_INFO_RX_BYTES
])
5862 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
5863 if (stats
[NL80211_STA_INFO_TX_BYTES
])
5864 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
5865 if (stats
[NL80211_STA_INFO_RX_BYTES64
] &&
5866 stats
[NL80211_STA_INFO_TX_BYTES64
]) {
5868 * The driver supports 64-bit counters, so use them to override
5869 * the 32-bit values.
5872 nla_get_u64(stats
[NL80211_STA_INFO_RX_BYTES64
]);
5874 nla_get_u64(stats
[NL80211_STA_INFO_TX_BYTES64
]);
5875 data
->bytes_64bit
= 1;
5877 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
5879 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
5880 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
5882 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
5883 if (stats
[NL80211_STA_INFO_TX_FAILED
])
5884 data
->tx_retry_failed
=
5885 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
5890 static int i802_read_sta_data(struct i802_bss
*bss
,
5891 struct hostap_sta_driver_data
*data
,
5896 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_GET_STATION
)) ||
5897 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
5902 return send_and_recv_msgs(bss
->drv
, msg
, get_sta_handler
, data
);
5906 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
5907 int cw_min
, int cw_max
, int burst_time
)
5909 struct i802_bss
*bss
= priv
;
5910 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5912 struct nlattr
*txq
, *params
;
5914 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_WIPHY
);
5918 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
5922 /* We are only sending parameters for a single TXQ at a time */
5923 params
= nla_nest_start(msg
, 1);
5929 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
))
5933 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
))
5937 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
))
5941 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
))
5945 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5946 * 32 usec, so need to convert the value here. */
5947 if (nla_put_u16(msg
, NL80211_TXQ_ATTR_TXOP
,
5948 (burst_time
* 100 + 16) / 32) ||
5949 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
) ||
5950 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
) ||
5951 nla_put_u8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
))
5954 nla_nest_end(msg
, params
);
5956 nla_nest_end(msg
, txq
);
5958 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
5967 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
5968 const char *ifname
, int vlan_id
)
5970 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5974 wpa_printf(MSG_DEBUG
, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5975 ", ifname=%s[%d], vlan_id=%d)",
5976 bss
->ifname
, if_nametoindex(bss
->ifname
),
5977 MAC2STR(addr
), ifname
, if_nametoindex(ifname
), vlan_id
);
5978 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5979 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
5980 nla_put_u32(msg
, NL80211_ATTR_STA_VLAN
, if_nametoindex(ifname
))) {
5985 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5987 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5988 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
5989 MAC2STR(addr
), ifname
, vlan_id
, ret
,
5996 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
5998 struct hostap_sta_driver_data data
;
6001 os_memset(&data
, 0, sizeof(data
));
6002 data
.inactive_msec
= (unsigned long) -1;
6003 ret
= i802_read_sta_data(priv
, &data
, addr
);
6006 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
6008 return data
.inactive_msec
/ 1000;
6012 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
6021 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
6024 struct i802_bss
*bss
= priv
;
6025 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6026 struct ieee80211_mgmt mgmt
;
6029 if (ieee80211_freq_to_chan(bss
->freq
, &channel
) ==
6030 HOSTAPD_MODE_IEEE80211AD
) {
6031 /* Deauthentication is not used in DMG/IEEE 802.11ad;
6032 * disassociate the STA instead. */
6033 return i802_sta_disassoc(priv
, own_addr
, addr
, reason
);
6036 if (is_mesh_interface(drv
->nlmode
))
6039 if (drv
->device_ap_sme
)
6040 return wpa_driver_nl80211_sta_remove(bss
, addr
, 1, reason
);
6042 memset(&mgmt
, 0, sizeof(mgmt
));
6043 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6044 WLAN_FC_STYPE_DEAUTH
);
6045 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6046 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6047 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6048 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
6049 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6051 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
6056 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
6059 struct i802_bss
*bss
= priv
;
6060 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6061 struct ieee80211_mgmt mgmt
;
6063 if (is_mesh_interface(drv
->nlmode
))
6066 if (drv
->device_ap_sme
)
6067 return wpa_driver_nl80211_sta_remove(bss
, addr
, 0, reason
);
6069 memset(&mgmt
, 0, sizeof(mgmt
));
6070 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6071 WLAN_FC_STYPE_DISASSOC
);
6072 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6073 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6074 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6075 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
6076 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6078 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
6083 static void dump_ifidx(struct wpa_driver_nl80211_data
*drv
)
6085 char buf
[200], *pos
, *end
;
6089 end
= pos
+ sizeof(buf
);
6091 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6092 if (!drv
->if_indices
[i
])
6094 res
= os_snprintf(pos
, end
- pos
, " %d(%d)",
6096 drv
->if_indices_reason
[i
]);
6097 if (os_snprintf_error(end
- pos
, res
))
6103 wpa_printf(MSG_DEBUG
, "nl80211: if_indices[%d]:%s",
6104 drv
->num_if_indices
, buf
);
6108 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6112 int *old
, *old_reason
;
6114 wpa_printf(MSG_DEBUG
,
6115 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
6116 ifidx
, ifidx_reason
);
6117 if (have_ifidx(drv
, ifidx
, ifidx_reason
)) {
6118 wpa_printf(MSG_DEBUG
, "nl80211: ifindex %d already in the list",
6122 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6123 if (drv
->if_indices
[i
] == 0) {
6124 drv
->if_indices
[i
] = ifidx
;
6125 drv
->if_indices_reason
[i
] = ifidx_reason
;
6131 if (drv
->if_indices
!= drv
->default_if_indices
)
6132 old
= drv
->if_indices
;
6136 if (drv
->if_indices_reason
!= drv
->default_if_indices_reason
)
6137 old_reason
= drv
->if_indices_reason
;
6141 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
6143 drv
->if_indices_reason
= os_realloc_array(old_reason
,
6144 drv
->num_if_indices
+ 1,
6146 if (!drv
->if_indices
) {
6148 drv
->if_indices
= drv
->default_if_indices
;
6150 drv
->if_indices
= old
;
6152 if (!drv
->if_indices_reason
) {
6154 drv
->if_indices_reason
= drv
->default_if_indices_reason
;
6156 drv
->if_indices_reason
= old_reason
;
6158 if (!drv
->if_indices
|| !drv
->if_indices_reason
) {
6159 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
6161 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
6165 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
6166 sizeof(drv
->default_if_indices
));
6168 os_memcpy(drv
->if_indices_reason
,
6169 drv
->default_if_indices_reason
,
6170 sizeof(drv
->default_if_indices_reason
));
6171 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
6172 drv
->if_indices_reason
[drv
->num_if_indices
] = ifidx_reason
;
6173 drv
->num_if_indices
++;
6178 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6183 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6184 if ((drv
->if_indices
[i
] == ifidx
|| ifidx
== IFIDX_ANY
) &&
6185 (drv
->if_indices_reason
[i
] == ifidx_reason
||
6186 ifidx_reason
== IFIDX_ANY
)) {
6187 drv
->if_indices
[i
] = 0;
6195 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6200 for (i
= 0; i
< drv
->num_if_indices
; i
++)
6201 if (drv
->if_indices
[i
] == ifidx
&&
6202 (drv
->if_indices_reason
[i
] == ifidx_reason
||
6203 ifidx_reason
== IFIDX_ANY
))
6210 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
6211 const char *bridge_ifname
, char *ifname_wds
)
6213 struct i802_bss
*bss
= priv
;
6214 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6215 char name
[IFNAMSIZ
+ 1];
6217 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
6219 os_strlcpy(ifname_wds
, name
, IFNAMSIZ
+ 1);
6221 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
6222 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
6224 if (!if_nametoindex(name
)) {
6225 if (nl80211_create_iface(drv
, name
,
6226 NL80211_IFTYPE_AP_VLAN
,
6227 bss
->addr
, 1, NULL
, NULL
, 0) <
6230 if (bridge_ifname
&&
6231 linux_br_add_if(drv
->global
->ioctl_sock
,
6232 bridge_ifname
, name
) < 0)
6235 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
6236 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
6237 "interface %s up", name
);
6239 return i802_set_sta_vlan(priv
, addr
, name
, 0);
6242 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
6245 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
6246 nl80211_remove_iface(drv
, if_nametoindex(name
));
6252 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
6254 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
6255 struct sockaddr_ll lladdr
;
6256 unsigned char buf
[3000];
6258 socklen_t fromlen
= sizeof(lladdr
);
6260 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
6261 (struct sockaddr
*)&lladdr
, &fromlen
);
6263 wpa_printf(MSG_ERROR
, "nl80211: EAPOL recv failed: %s",
6268 if (have_ifidx(drv
, lladdr
.sll_ifindex
, IFIDX_ANY
))
6269 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
6273 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
6274 struct i802_bss
*bss
,
6275 const char *brname
, const char *ifname
)
6278 char in_br
[IFNAMSIZ
];
6280 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
6281 br_ifindex
= if_nametoindex(brname
);
6282 if (br_ifindex
== 0) {
6284 * Bridge was configured, but the bridge device does
6285 * not exist. Try to add it now.
6287 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
6288 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
6289 "bridge interface %s: %s",
6290 brname
, strerror(errno
));
6293 bss
->added_bridge
= 1;
6294 br_ifindex
= if_nametoindex(brname
);
6295 add_ifidx(drv
, br_ifindex
, drv
->ifindex
);
6297 bss
->br_ifindex
= br_ifindex
;
6299 if (linux_br_get(in_br
, ifname
) == 0) {
6300 if (os_strcmp(in_br
, brname
) == 0)
6301 return 0; /* already in the bridge */
6303 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
6304 "bridge %s", ifname
, in_br
);
6305 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
6307 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
6308 "remove interface %s from bridge "
6310 ifname
, brname
, strerror(errno
));
6315 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
6317 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
6318 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
6319 "into bridge %s: %s",
6320 ifname
, brname
, strerror(errno
));
6323 bss
->added_if_into_bridge
= 1;
6329 static void *i802_init(struct hostapd_data
*hapd
,
6330 struct wpa_init_params
*params
)
6332 struct wpa_driver_nl80211_data
*drv
;
6333 struct i802_bss
*bss
;
6335 char master_ifname
[IFNAMSIZ
];
6336 int ifindex
, br_ifindex
= 0;
6339 bss
= wpa_driver_nl80211_drv_init(hapd
, params
->ifname
,
6340 params
->global_priv
, 1,
6341 params
->bssid
, params
->driver_params
);
6347 if (linux_br_get(master_ifname
, params
->ifname
) == 0) {
6348 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
6349 params
->ifname
, master_ifname
);
6350 br_ifindex
= if_nametoindex(master_ifname
);
6351 os_strlcpy(bss
->brname
, master_ifname
, IFNAMSIZ
);
6352 } else if ((params
->num_bridge
== 0 || !params
->bridge
[0]) &&
6353 linux_master_get(master_ifname
, params
->ifname
) == 0) {
6354 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in master %s",
6355 params
->ifname
, master_ifname
);
6356 /* start listening for EAPOL on the master interface */
6357 add_ifidx(drv
, if_nametoindex(master_ifname
), drv
->ifindex
);
6359 /* check if master itself is under bridge */
6360 if (linux_br_get(master_ifname
, master_ifname
) == 0) {
6361 wpa_printf(MSG_DEBUG
, "nl80211: which is in bridge %s",
6363 br_ifindex
= if_nametoindex(master_ifname
);
6364 os_strlcpy(bss
->brname
, master_ifname
, IFNAMSIZ
);
6367 master_ifname
[0] = '\0';
6370 bss
->br_ifindex
= br_ifindex
;
6372 for (i
= 0; i
< params
->num_bridge
; i
++) {
6373 if (params
->bridge
[i
]) {
6374 ifindex
= if_nametoindex(params
->bridge
[i
]);
6376 add_ifidx(drv
, ifindex
, drv
->ifindex
);
6377 if (ifindex
== br_ifindex
)
6382 /* start listening for EAPOL on the default AP interface */
6383 add_ifidx(drv
, drv
->ifindex
, IFIDX_ANY
);
6385 if (params
->num_bridge
&& params
->bridge
[0]) {
6386 if (i802_check_bridge(drv
, bss
, params
->bridge
[0],
6387 params
->ifname
) < 0)
6389 if (os_strcmp(params
->bridge
[0], master_ifname
) != 0)
6393 if (!br_added
&& br_ifindex
&&
6394 (params
->num_bridge
== 0 || !params
->bridge
[0]))
6395 add_ifidx(drv
, br_ifindex
, drv
->ifindex
);
6397 #ifdef CONFIG_LIBNL3_ROUTE
6398 if (bss
->added_if_into_bridge
) {
6399 drv
->rtnl_sk
= nl_socket_alloc();
6400 if (drv
->rtnl_sk
== NULL
) {
6401 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate nl_sock");
6405 if (nl_connect(drv
->rtnl_sk
, NETLINK_ROUTE
)) {
6406 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
6411 #endif /* CONFIG_LIBNL3_ROUTE */
6413 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
6414 if (drv
->eapol_sock
< 0) {
6415 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
6420 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
6422 wpa_printf(MSG_INFO
, "nl80211: Could not register read socket for eapol");
6426 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6429 os_memcpy(drv
->perm_addr
, params
->own_addr
, ETH_ALEN
);
6431 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
6436 wpa_driver_nl80211_deinit(bss
);
6441 static void i802_deinit(void *priv
)
6443 struct i802_bss
*bss
= priv
;
6444 wpa_driver_nl80211_deinit(bss
);
6448 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
6449 enum wpa_driver_if_type type
)
6452 case WPA_IF_STATION
:
6453 return NL80211_IFTYPE_STATION
;
6454 case WPA_IF_P2P_CLIENT
:
6455 case WPA_IF_P2P_GROUP
:
6456 return NL80211_IFTYPE_P2P_CLIENT
;
6457 case WPA_IF_AP_VLAN
:
6458 return NL80211_IFTYPE_AP_VLAN
;
6460 return NL80211_IFTYPE_AP
;
6462 return NL80211_IFTYPE_P2P_GO
;
6463 case WPA_IF_P2P_DEVICE
:
6464 return NL80211_IFTYPE_P2P_DEVICE
;
6466 return NL80211_IFTYPE_MESH_POINT
;
6473 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
6475 struct wpa_driver_nl80211_data
*drv
;
6476 dl_list_for_each(drv
, &global
->interfaces
,
6477 struct wpa_driver_nl80211_data
, list
) {
6478 if (os_memcmp(addr
, drv
->first_bss
->addr
, ETH_ALEN
) == 0)
6485 static int nl80211_vif_addr(struct wpa_driver_nl80211_data
*drv
, u8
*new_addr
)
6492 os_memcpy(new_addr
, drv
->first_bss
->addr
, ETH_ALEN
);
6493 for (idx
= 0; idx
< 64; idx
++) {
6494 new_addr
[0] = drv
->first_bss
->addr
[0] | 0x02;
6495 new_addr
[0] ^= idx
<< 2;
6496 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
6502 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new virtual interface address "
6503 MACSTR
, MAC2STR(new_addr
));
6512 u8 macaddr
[ETH_ALEN
];
6515 static int nl80211_wdev_handler(struct nl_msg
*msg
, void *arg
)
6517 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6518 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6519 struct wdev_info
*wi
= arg
;
6521 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6522 genlmsg_attrlen(gnlh
, 0), NULL
);
6523 if (tb
[NL80211_ATTR_WDEV
]) {
6524 wi
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
6525 wi
->wdev_id_set
= 1;
6528 if (tb
[NL80211_ATTR_MAC
])
6529 os_memcpy(wi
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
6536 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
6537 const char *ifname
, const u8
*addr
,
6538 void *bss_ctx
, void **drv_priv
,
6539 char *force_ifname
, u8
*if_addr
,
6540 const char *bridge
, int use_existing
,
6543 enum nl80211_iftype nlmode
;
6544 struct i802_bss
*bss
= priv
;
6545 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6550 os_memcpy(if_addr
, addr
, ETH_ALEN
);
6551 nlmode
= wpa_driver_nl80211_if_type(type
);
6552 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
6553 struct wdev_info p2pdev_info
;
6555 os_memset(&p2pdev_info
, 0, sizeof(p2pdev_info
));
6556 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
6557 0, nl80211_wdev_handler
,
6558 &p2pdev_info
, use_existing
);
6559 if (!p2pdev_info
.wdev_id_set
|| ifidx
!= 0) {
6560 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
6565 drv
->global
->if_add_wdevid
= p2pdev_info
.wdev_id
;
6566 drv
->global
->if_add_wdevid_set
= p2pdev_info
.wdev_id_set
;
6567 if (!is_zero_ether_addr(p2pdev_info
.macaddr
))
6568 os_memcpy(if_addr
, p2pdev_info
.macaddr
, ETH_ALEN
);
6569 wpa_printf(MSG_DEBUG
, "nl80211: New P2P Device interface %s (0x%llx) created",
6571 (long long unsigned int) p2pdev_info
.wdev_id
);
6573 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
6574 0, NULL
, NULL
, use_existing
);
6575 if (use_existing
&& ifidx
== -ENFILE
) {
6577 ifidx
= if_nametoindex(ifname
);
6578 } else if (ifidx
< 0) {
6584 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
6585 os_memcpy(if_addr
, bss
->addr
, ETH_ALEN
);
6586 else if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
6587 ifname
, if_addr
) < 0) {
6589 nl80211_remove_iface(drv
, ifidx
);
6595 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
6596 type
== WPA_IF_P2P_GO
|| type
== WPA_IF_MESH
||
6597 type
== WPA_IF_STATION
)) {
6598 /* Enforce unique address */
6599 u8 new_addr
[ETH_ALEN
];
6601 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6604 nl80211_remove_iface(drv
, ifidx
);
6607 if (nl80211_addr_in_use(drv
->global
, new_addr
)) {
6608 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
6609 "for interface %s type %d", ifname
, type
);
6610 if (nl80211_vif_addr(drv
, new_addr
) < 0) {
6612 nl80211_remove_iface(drv
, ifidx
);
6615 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6618 nl80211_remove_iface(drv
, ifidx
);
6622 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
6625 if (type
== WPA_IF_AP_BSS
&& setup_ap
) {
6626 struct i802_bss
*new_bss
= os_zalloc(sizeof(*new_bss
));
6627 if (new_bss
== NULL
) {
6629 nl80211_remove_iface(drv
, ifidx
);
6634 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
6635 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
6636 "interface %s to a bridge %s",
6639 nl80211_remove_iface(drv
, ifidx
);
6644 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
6647 nl80211_remove_iface(drv
, ifidx
);
6651 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
6652 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
6653 new_bss
->ifindex
= ifidx
;
6655 new_bss
->next
= drv
->first_bss
->next
;
6656 new_bss
->freq
= drv
->first_bss
->freq
;
6657 new_bss
->ctx
= bss_ctx
;
6658 new_bss
->added_if
= added
;
6659 drv
->first_bss
->next
= new_bss
;
6661 *drv_priv
= new_bss
;
6662 nl80211_init_bss(new_bss
);
6664 /* Subscribe management frames for this WPA_IF_AP_BSS */
6665 if (nl80211_setup_ap(new_bss
))
6670 drv
->global
->if_add_ifindex
= ifidx
;
6673 * Some virtual interfaces need to process EAPOL packets and events on
6674 * the parent interface. This is used mainly with hostapd.
6678 nlmode
== NL80211_IFTYPE_AP_VLAN
||
6679 nlmode
== NL80211_IFTYPE_WDS
||
6680 nlmode
== NL80211_IFTYPE_MONITOR
))
6681 add_ifidx(drv
, ifidx
, IFIDX_ANY
);
6687 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
6688 enum wpa_driver_if_type type
,
6691 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6692 int ifindex
= if_nametoindex(ifname
);
6694 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6695 __func__
, type
, ifname
, ifindex
, bss
->added_if
);
6696 if (ifindex
> 0 && (bss
->added_if
|| bss
->ifindex
!= ifindex
))
6697 nl80211_remove_iface(drv
, ifindex
);
6698 else if (ifindex
> 0 && !bss
->added_if
) {
6699 struct wpa_driver_nl80211_data
*drv2
;
6700 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
6701 struct wpa_driver_nl80211_data
, list
) {
6702 del_ifidx(drv2
, ifindex
, IFIDX_ANY
);
6703 del_ifidx(drv2
, IFIDX_ANY
, ifindex
);
6707 if (type
!= WPA_IF_AP_BSS
)
6710 if (bss
->added_if_into_bridge
) {
6711 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
6713 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6714 "interface %s from bridge %s: %s",
6715 bss
->ifname
, bss
->brname
, strerror(errno
));
6717 if (bss
->added_bridge
) {
6718 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
6719 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6721 bss
->brname
, strerror(errno
));
6724 if (bss
!= drv
->first_bss
) {
6725 struct i802_bss
*tbss
;
6727 wpa_printf(MSG_DEBUG
, "nl80211: Not the first BSS - remove it");
6728 for (tbss
= drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
6729 if (tbss
->next
== bss
) {
6730 tbss
->next
= bss
->next
;
6731 /* Unsubscribe management frames */
6732 nl80211_teardown_ap(bss
);
6733 nl80211_destroy_bss(bss
);
6735 i802_set_iface_flags(bss
, 0);
6742 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
6743 "BSS %p in the list", __func__
, bss
);
6745 wpa_printf(MSG_DEBUG
, "nl80211: First BSS - reassign context");
6746 nl80211_teardown_ap(bss
);
6747 if (!bss
->added_if
&& !drv
->first_bss
->next
)
6748 wpa_driver_nl80211_del_beacon(drv
);
6749 nl80211_destroy_bss(bss
);
6751 i802_set_iface_flags(bss
, 0);
6752 if (drv
->first_bss
->next
) {
6753 drv
->first_bss
= drv
->first_bss
->next
;
6754 drv
->ctx
= drv
->first_bss
->ctx
;
6757 wpa_printf(MSG_DEBUG
, "nl80211: No second BSS to reassign context to");
6765 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
6767 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6768 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6770 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6771 genlmsg_attrlen(gnlh
, 0), NULL
);
6772 if (tb
[NL80211_ATTR_COOKIE
])
6773 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
6778 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
6779 unsigned int freq
, unsigned int wait
,
6780 const u8
*buf
, size_t buf_len
,
6781 u64
*cookie_out
, int no_cck
, int no_ack
,
6782 int offchanok
, const u16
*csa_offs
,
6783 size_t csa_offs_len
)
6785 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6790 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
6791 "no_ack=%d offchanok=%d",
6792 freq
, wait
, no_cck
, no_ack
, offchanok
);
6793 wpa_hexdump(MSG_MSGDUMP
, "CMD_FRAME", buf
, buf_len
);
6795 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME
)) ||
6796 (freq
&& nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
6797 (wait
&& nla_put_u32(msg
, NL80211_ATTR_DURATION
, wait
)) ||
6798 (offchanok
&& ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
6799 drv
->test_use_roc_tx
) &&
6800 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
)) ||
6801 (no_cck
&& nla_put_flag(msg
, NL80211_ATTR_TX_NO_CCK_RATE
)) ||
6802 (no_ack
&& nla_put_flag(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
)) ||
6803 (csa_offs
&& nla_put(msg
, NL80211_ATTR_CSA_C_OFFSETS_TX
,
6804 csa_offs_len
* sizeof(u16
), csa_offs
)) ||
6805 nla_put(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
))
6809 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6812 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
6813 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
6816 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
6817 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
6818 (long long unsigned int) cookie
);
6821 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
6823 if (drv
->num_send_action_cookies
== MAX_SEND_ACTION_COOKIES
) {
6824 wpa_printf(MSG_DEBUG
,
6825 "nl80211: Drop oldest pending send action cookie 0x%llx",
6826 (long long unsigned int)
6827 drv
->send_action_cookies
[0]);
6828 os_memmove(&drv
->send_action_cookies
[0],
6829 &drv
->send_action_cookies
[1],
6830 (MAX_SEND_ACTION_COOKIES
- 1) *
6832 drv
->num_send_action_cookies
--;
6834 drv
->send_action_cookies
[drv
->num_send_action_cookies
] = cookie
;
6835 drv
->num_send_action_cookies
++;
6844 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
6846 unsigned int wait_time
,
6847 const u8
*dst
, const u8
*src
,
6849 const u8
*data
, size_t data_len
,
6852 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6855 struct ieee80211_hdr
*hdr
;
6857 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
6858 "freq=%u MHz wait=%d ms no_cck=%d)",
6859 drv
->ifindex
, freq
, wait_time
, no_cck
);
6861 buf
= os_zalloc(24 + data_len
);
6864 os_memcpy(buf
+ 24, data
, data_len
);
6865 hdr
= (struct ieee80211_hdr
*) buf
;
6866 hdr
->frame_control
=
6867 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
6868 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
6869 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
6870 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
6872 if (is_ap_interface(drv
->nlmode
) &&
6873 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
6874 (int) freq
== bss
->freq
|| drv
->device_ap_sme
||
6876 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
6878 wait_time
, NULL
, 0);
6880 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
6882 &drv
->send_action_cookie
,
6883 no_cck
, 0, 1, NULL
, 0);
6890 static void nl80211_frame_wait_cancel(struct i802_bss
*bss
, u64 cookie
)
6892 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6896 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
6897 (long long unsigned int) cookie
);
6898 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
)) ||
6899 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
)) {
6904 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6906 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
6907 "(%s)", ret
, strerror(-ret
));
6911 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
6913 struct i802_bss
*bss
= priv
;
6914 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6918 /* Cancel the last pending TX cookie */
6919 nl80211_frame_wait_cancel(bss
, drv
->send_action_cookie
);
6922 * Cancel the other pending TX cookies, if any. This is needed since
6923 * the driver may keep a list of all pending offchannel TX operations
6924 * and free up the radio only once they have expired or cancelled.
6926 for (i
= drv
->num_send_action_cookies
; i
> 0; i
--) {
6927 cookie
= drv
->send_action_cookies
[i
- 1];
6928 if (cookie
!= drv
->send_action_cookie
)
6929 nl80211_frame_wait_cancel(bss
, cookie
);
6931 drv
->num_send_action_cookies
= 0;
6935 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
6936 unsigned int duration
)
6938 struct i802_bss
*bss
= priv
;
6939 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6944 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
)) ||
6945 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
6946 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
)) {
6952 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6954 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
6955 "0x%llx for freq=%u MHz duration=%u",
6956 (long long unsigned int) cookie
, freq
, duration
);
6957 drv
->remain_on_chan_cookie
= cookie
;
6958 drv
->pending_remain_on_chan
= 1;
6961 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
6962 "(freq=%d duration=%u): %d (%s)",
6963 freq
, duration
, ret
, strerror(-ret
));
6968 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
6970 struct i802_bss
*bss
= priv
;
6971 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6975 if (!drv
->pending_remain_on_chan
) {
6976 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
6981 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
6983 (long long unsigned int) drv
->remain_on_chan_cookie
);
6985 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
6987 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
)) {
6992 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6995 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
6996 "%d (%s)", ret
, strerror(-ret
));
7001 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
7003 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7006 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
7007 is_ap_interface(drv
->nlmode
) && !bss
->in_deinit
&&
7010 * Do not disable Probe Request reporting that was
7011 * enabled in nl80211_setup_ap().
7013 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
7014 "Probe Request reporting nl_preq=%p while "
7015 "in AP mode", bss
->nl_preq
);
7016 } else if (bss
->nl_preq
) {
7017 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
7018 "reporting nl_preq=%p", bss
->nl_preq
);
7019 nl80211_destroy_eloop_handle(&bss
->nl_preq
);
7025 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
7026 "already on! nl_preq=%p", bss
->nl_preq
);
7030 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
7031 if (bss
->nl_preq
== NULL
)
7033 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
7034 "reporting nl_preq=%p", bss
->nl_preq
);
7036 if (nl80211_register_frame(bss
, bss
->nl_preq
,
7037 (WLAN_FC_TYPE_MGMT
<< 2) |
7038 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
7042 nl80211_register_eloop_read(&bss
->nl_preq
,
7043 wpa_driver_nl80211_event_receive
,
7049 nl_destroy_handles(&bss
->nl_preq
);
7054 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
7055 int ifindex
, int disabled
)
7058 struct nlattr
*bands
, *band
;
7061 wpa_printf(MSG_DEBUG
,
7062 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
7063 ifindex
, disabled
? "NL80211_TXRATE_LEGACY=OFDM-only" :
7064 "no NL80211_TXRATE_LEGACY constraint");
7066 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0,
7067 NL80211_CMD_SET_TX_BITRATE_MASK
);
7071 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
7076 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
7077 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
7078 * rates. All 5 GHz rates are left enabled.
7080 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
7082 (disabled
&& nla_put(msg
, NL80211_TXRATE_LEGACY
, 8,
7083 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
7085 nla_nest_end(msg
, band
);
7087 nla_nest_end(msg
, bands
);
7089 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7091 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
7092 "(%s)", ret
, strerror(-ret
));
7094 drv
->disabled_11b_rates
= disabled
;
7104 static int wpa_driver_nl80211_deinit_ap(void *priv
)
7106 struct i802_bss
*bss
= priv
;
7107 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7108 if (!is_ap_interface(drv
->nlmode
))
7110 wpa_driver_nl80211_del_beacon(drv
);
7111 bss
->beacon_set
= 0;
7114 * If the P2P GO interface was dynamically added, then it is
7115 * possible that the interface change to station is not possible.
7117 if (drv
->nlmode
== NL80211_IFTYPE_P2P_GO
&& bss
->if_dynamic
)
7120 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
7124 static int wpa_driver_nl80211_stop_ap(void *priv
)
7126 struct i802_bss
*bss
= priv
;
7127 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7128 if (!is_ap_interface(drv
->nlmode
))
7130 wpa_driver_nl80211_del_beacon(drv
);
7131 bss
->beacon_set
= 0;
7136 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
7138 struct i802_bss
*bss
= priv
;
7139 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7140 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
7144 * If the P2P Client interface was dynamically added, then it is
7145 * possible that the interface change to station is not possible.
7147 if (bss
->if_dynamic
)
7150 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
7154 static void wpa_driver_nl80211_resume(void *priv
)
7156 struct i802_bss
*bss
= priv
;
7157 enum nl80211_iftype nlmode
= nl80211_get_ifmode(bss
);
7159 if (i802_set_iface_flags(bss
, 1))
7160 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on resume event");
7162 if (is_p2p_net_interface(nlmode
))
7163 nl80211_disable_11b_rates(bss
->drv
, bss
->drv
->ifindex
, 1);
7167 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
7169 struct i802_bss
*bss
= priv
;
7170 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7174 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
7175 "hysteresis=%d", threshold
, hysteresis
);
7177 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_CQM
)) ||
7178 !(cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
)) ||
7179 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
) ||
7180 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
)) {
7184 nla_nest_end(msg
, cqm
);
7186 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7190 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
7192 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7193 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7194 struct wpa_signal_info
*sig_change
= arg
;
7196 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7197 genlmsg_attrlen(gnlh
, 0), NULL
);
7199 sig_change
->center_frq1
= -1;
7200 sig_change
->center_frq2
= -1;
7201 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
7203 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
7204 sig_change
->chanwidth
= convert2width(
7205 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
7206 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
7207 sig_change
->center_frq1
=
7208 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
7209 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
7210 sig_change
->center_frq2
=
7211 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
7218 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
7219 struct wpa_signal_info
*sig
)
7223 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_INTERFACE
);
7224 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
7228 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
7230 struct i802_bss
*bss
= priv
;
7231 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7234 os_memset(si
, 0, sizeof(*si
));
7235 res
= nl80211_get_link_signal(drv
, si
);
7237 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
&&
7238 drv
->nlmode
!= NL80211_IFTYPE_MESH_POINT
)
7240 si
->current_signal
= 0;
7243 res
= nl80211_get_channel_width(drv
, si
);
7247 return nl80211_get_link_noise(drv
, si
);
7251 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
7254 struct i802_bss
*bss
= priv
;
7255 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
7256 0, 0, 0, 0, NULL
, 0);
7260 static int nl80211_set_param(void *priv
, const char *param
)
7262 struct i802_bss
*bss
= priv
;
7263 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7267 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
7270 if (os_strstr(param
, "use_p2p_group_interface=1")) {
7271 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
7273 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
7274 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
7276 #endif /* CONFIG_P2P */
7278 if (os_strstr(param
, "use_monitor=1"))
7279 drv
->use_monitor
= 1;
7281 if (os_strstr(param
, "force_connect_cmd=1")) {
7282 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_SME
;
7283 drv
->force_connect_cmd
= 1;
7286 if (os_strstr(param
, "force_bss_selection=1"))
7287 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
7289 if (os_strstr(param
, "no_offchannel_tx=1")) {
7290 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
7291 drv
->test_use_roc_tx
= 1;
7298 static void * nl80211_global_init(void *ctx
)
7300 struct nl80211_global
*global
;
7301 struct netlink_config
*cfg
;
7303 global
= os_zalloc(sizeof(*global
));
7307 global
->ioctl_sock
= -1;
7308 dl_list_init(&global
->interfaces
);
7309 global
->if_add_ifindex
= -1;
7311 cfg
= os_zalloc(sizeof(*cfg
));
7316 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
7317 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
7318 global
->netlink
= netlink_init(cfg
);
7319 if (global
->netlink
== NULL
) {
7324 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
7327 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
7328 if (global
->ioctl_sock
< 0) {
7329 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
7337 nl80211_global_deinit(global
);
7342 static void nl80211_global_deinit(void *priv
)
7344 struct nl80211_global
*global
= priv
;
7347 if (!dl_list_empty(&global
->interfaces
)) {
7348 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
7349 "nl80211_global_deinit",
7350 dl_list_len(&global
->interfaces
));
7353 if (global
->netlink
)
7354 netlink_deinit(global
->netlink
);
7356 nl_destroy_handles(&global
->nl
);
7358 if (global
->nl_event
)
7359 nl80211_destroy_eloop_handle(&global
->nl_event
);
7361 nl_cb_put(global
->nl_cb
);
7363 if (global
->ioctl_sock
>= 0)
7364 close(global
->ioctl_sock
);
7370 static const char * nl80211_get_radio_name(void *priv
)
7372 struct i802_bss
*bss
= priv
;
7373 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7374 return drv
->phyname
;
7378 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
7383 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
7384 (pmkid
&& nla_put(msg
, NL80211_ATTR_PMKID
, 16, pmkid
)) ||
7385 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))) {
7390 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
7394 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
7396 struct i802_bss
*bss
= priv
;
7397 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
7398 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
7402 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
7404 struct i802_bss
*bss
= priv
;
7405 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
7407 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
7411 static int nl80211_flush_pmkid(void *priv
)
7413 struct i802_bss
*bss
= priv
;
7414 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
7415 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
7419 static void clean_survey_results(struct survey_results
*survey_results
)
7421 struct freq_survey
*survey
, *tmp
;
7423 if (dl_list_empty(&survey_results
->survey_list
))
7426 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
7427 struct freq_survey
, list
) {
7428 dl_list_del(&survey
->list
);
7434 static void add_survey(struct nlattr
**sinfo
, u32 ifidx
,
7435 struct dl_list
*survey_list
)
7437 struct freq_survey
*survey
;
7439 survey
= os_zalloc(sizeof(struct freq_survey
));
7443 survey
->ifidx
= ifidx
;
7444 survey
->freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
7447 if (sinfo
[NL80211_SURVEY_INFO_NOISE
]) {
7448 survey
->nf
= (int8_t)
7449 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
7450 survey
->filled
|= SURVEY_HAS_NF
;
7453 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]) {
7454 survey
->channel_time
=
7455 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]);
7456 survey
->filled
|= SURVEY_HAS_CHAN_TIME
;
7459 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]) {
7460 survey
->channel_time_busy
=
7461 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]);
7462 survey
->filled
|= SURVEY_HAS_CHAN_TIME_BUSY
;
7465 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]) {
7466 survey
->channel_time_rx
=
7467 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]);
7468 survey
->filled
|= SURVEY_HAS_CHAN_TIME_RX
;
7471 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]) {
7472 survey
->channel_time_tx
=
7473 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]);
7474 survey
->filled
|= SURVEY_HAS_CHAN_TIME_TX
;
7477 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)",
7480 (unsigned long int) survey
->channel_time
,
7481 (unsigned long int) survey
->channel_time_busy
,
7482 (unsigned long int) survey
->channel_time_tx
,
7483 (unsigned long int) survey
->channel_time_rx
,
7486 dl_list_add_tail(survey_list
, &survey
->list
);
7490 static int check_survey_ok(struct nlattr
**sinfo
, u32 surveyed_freq
,
7491 unsigned int freq_filter
)
7496 return freq_filter
== surveyed_freq
;
7500 static int survey_handler(struct nl_msg
*msg
, void *arg
)
7502 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7503 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7504 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
7505 struct survey_results
*survey_results
;
7506 u32 surveyed_freq
= 0;
7509 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
7510 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
7511 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
7514 survey_results
= (struct survey_results
*) arg
;
7516 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7517 genlmsg_attrlen(gnlh
, 0), NULL
);
7519 if (!tb
[NL80211_ATTR_IFINDEX
])
7522 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
7524 if (!tb
[NL80211_ATTR_SURVEY_INFO
])
7527 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
7528 tb
[NL80211_ATTR_SURVEY_INFO
],
7532 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) {
7533 wpa_printf(MSG_ERROR
, "nl80211: Invalid survey data");
7537 surveyed_freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
7539 if (!check_survey_ok(sinfo
, surveyed_freq
,
7540 survey_results
->freq_filter
))
7543 if (survey_results
->freq_filter
&&
7544 survey_results
->freq_filter
!= surveyed_freq
) {
7545 wpa_printf(MSG_EXCESSIVE
, "nl80211: Ignoring survey data for freq %d MHz",
7550 add_survey(sinfo
, ifidx
, &survey_results
->survey_list
);
7556 static int wpa_driver_nl80211_get_survey(void *priv
, unsigned int freq
)
7558 struct i802_bss
*bss
= priv
;
7559 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7562 union wpa_event_data data
;
7563 struct survey_results
*survey_results
;
7565 os_memset(&data
, 0, sizeof(data
));
7566 survey_results
= &data
.survey_results
;
7568 dl_list_init(&survey_results
->survey_list
);
7570 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
7575 data
.survey_results
.freq_filter
= freq
;
7578 wpa_printf(MSG_DEBUG
, "nl80211: Fetch survey data");
7579 err
= send_and_recv_msgs(drv
, msg
, survey_handler
,
7584 wpa_printf(MSG_ERROR
, "nl80211: Failed to process survey data");
7586 wpa_supplicant_event(drv
->ctx
, EVENT_SURVEY
, &data
);
7588 clean_survey_results(survey_results
);
7593 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, size_t kek_len
,
7594 const u8
*kck
, size_t kck_len
,
7595 const u8
*replay_ctr
)
7597 struct i802_bss
*bss
= priv
;
7598 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7599 struct nlattr
*replay_nested
;
7603 if (!drv
->set_rekey_offload
)
7606 wpa_printf(MSG_DEBUG
, "nl80211: Set rekey offload");
7607 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
)) ||
7608 !(replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
)) ||
7609 nla_put(msg
, NL80211_REKEY_DATA_KEK
, kek_len
, kek
) ||
7610 nla_put(msg
, NL80211_REKEY_DATA_KCK
, kck_len
, kck
) ||
7611 nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
7613 nl80211_nlmsg_clear(msg
);
7618 nla_nest_end(msg
, replay_nested
);
7620 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
7621 if (ret
== -EOPNOTSUPP
) {
7622 wpa_printf(MSG_DEBUG
,
7623 "nl80211: Driver does not support rekey offload");
7624 drv
->set_rekey_offload
= 0;
7629 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
7630 const u8
*addr
, int qos
)
7632 /* send data frame to poll STA and check whether
7633 * this frame is ACKed */
7635 struct ieee80211_hdr hdr
;
7637 } STRUCT_PACKED nulldata
;
7640 /* Send data frame to poll STA and check whether this frame is ACKed */
7642 os_memset(&nulldata
, 0, sizeof(nulldata
));
7645 nulldata
.hdr
.frame_control
=
7646 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7647 WLAN_FC_STYPE_QOS_NULL
);
7648 size
= sizeof(nulldata
);
7650 nulldata
.hdr
.frame_control
=
7651 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7652 WLAN_FC_STYPE_NULLFUNC
);
7653 size
= sizeof(struct ieee80211_hdr
);
7656 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7657 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7658 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7659 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7661 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
7663 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
7667 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
7670 struct i802_bss
*bss
= priv
;
7671 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7675 if (!drv
->poll_command_supported
) {
7676 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
7680 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_PROBE_CLIENT
)) ||
7681 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7686 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7688 wpa_printf(MSG_DEBUG
, "nl80211: Client probe request for "
7689 MACSTR
" failed: ret=%d (%s)",
7690 MAC2STR(addr
), ret
, strerror(-ret
));
7695 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
7699 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_POWER_SAVE
)) ||
7700 nla_put_u32(msg
, NL80211_ATTR_PS_STATE
,
7701 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
)) {
7705 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
7709 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
7712 struct i802_bss
*bss
= priv
;
7714 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
7715 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
7717 if (opp_ps
!= -1 || ctwindow
!= -1) {
7719 wpa_driver_set_p2p_ps(priv
, legacy_ps
, opp_ps
, ctwindow
);
7720 #else /* ANDROID_P2P */
7721 return -1; /* Not yet supported */
7722 #endif /* ANDROID_P2P */
7725 if (legacy_ps
== -1)
7727 if (legacy_ps
!= 0 && legacy_ps
!= 1)
7728 return -1; /* Not yet supported */
7730 return nl80211_set_power_save(bss
, legacy_ps
);
7734 static int nl80211_start_radar_detection(void *priv
,
7735 struct hostapd_freq_params
*freq
)
7737 struct i802_bss
*bss
= priv
;
7738 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7742 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)",
7743 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
7744 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
7746 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
7747 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
7752 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_RADAR_DETECT
)) ||
7753 nl80211_put_freq_params(msg
, freq
) < 0) {
7758 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7761 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
7762 "%d (%s)", ret
, strerror(-ret
));
7768 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
7769 u8 dialog_token
, u16 status_code
,
7770 u32 peer_capab
, int initiator
, const u8
*buf
,
7773 struct i802_bss
*bss
= priv
;
7774 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7777 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
7783 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_MGMT
)) ||
7784 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
7785 nla_put_u8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
) ||
7786 nla_put_u8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
) ||
7787 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
))
7791 * The internal enum tdls_peer_capability definition is
7792 * currently identical with the nl80211 enum
7793 * nl80211_tdls_peer_capability, so no conversion is needed
7796 if (nla_put_u32(msg
, NL80211_ATTR_TDLS_PEER_CAPABILITY
,
7801 nla_put_flag(msg
, NL80211_ATTR_TDLS_INITIATOR
)) ||
7802 nla_put(msg
, NL80211_ATTR_IE
, len
, buf
))
7805 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7813 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
7815 struct i802_bss
*bss
= priv
;
7816 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7818 enum nl80211_tdls_operation nl80211_oper
;
7821 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
7825 case TDLS_DISCOVERY_REQ
:
7826 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
7829 nl80211_oper
= NL80211_TDLS_SETUP
;
7832 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
7834 case TDLS_ENABLE_LINK
:
7835 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
7837 case TDLS_DISABLE_LINK
:
7838 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
7848 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_OPER
)) ||
7849 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
) ||
7850 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
)) {
7855 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7856 wpa_printf(MSG_DEBUG
, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
7857 " --> res=%d (%s)", nl80211_oper
, MAC2STR(peer
), res
,
7864 nl80211_tdls_enable_channel_switch(void *priv
, const u8
*addr
, u8 oper_class
,
7865 const struct hostapd_freq_params
*params
)
7867 struct i802_bss
*bss
= priv
;
7868 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7872 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
7873 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
7876 wpa_printf(MSG_DEBUG
, "nl80211: Enable TDLS channel switch " MACSTR
7877 " oper_class=%u freq=%u",
7878 MAC2STR(addr
), oper_class
, params
->freq
);
7879 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH
);
7881 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
7882 nla_put_u8(msg
, NL80211_ATTR_OPER_CLASS
, oper_class
) ||
7883 (ret
= nl80211_put_freq_params(msg
, params
))) {
7885 wpa_printf(MSG_DEBUG
, "nl80211: Could not build TDLS chan switch");
7889 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7894 nl80211_tdls_disable_channel_switch(void *priv
, const u8
*addr
)
7896 struct i802_bss
*bss
= priv
;
7897 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7900 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
7901 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
7904 wpa_printf(MSG_DEBUG
, "nl80211: Disable TDLS channel switch " MACSTR
,
7906 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
);
7908 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7910 wpa_printf(MSG_DEBUG
,
7911 "nl80211: Could not build TDLS cancel chan switch");
7915 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7918 #endif /* CONFIG TDLS */
7921 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
7922 enum wpa_alg alg
, const u8
*addr
,
7923 int key_idx
, int set_tx
,
7924 const u8
*seq
, size_t seq_len
,
7925 const u8
*key
, size_t key_len
)
7927 struct i802_bss
*bss
= priv
;
7928 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
7929 set_tx
, seq
, seq_len
, key
, key_len
);
7933 static int driver_nl80211_scan2(void *priv
,
7934 struct wpa_driver_scan_params
*params
)
7936 struct i802_bss
*bss
= priv
;
7937 #ifdef CONFIG_DRIVER_NL80211_QCA
7938 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7941 * Do a vendor specific scan if possible. If only_new_results is
7942 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
7943 * cannot be achieved through a vendor scan. The below condition may
7944 * need to be modified if new scan flags are added in the future whose
7945 * functionality can only be achieved through a normal scan.
7947 if (drv
->scan_vendor_cmd_avail
&& !params
->only_new_results
)
7948 return wpa_driver_nl80211_vendor_scan(bss
, params
);
7949 #endif /* CONFIG_DRIVER_NL80211_QCA */
7950 return wpa_driver_nl80211_scan(bss
, params
);
7954 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
7957 struct i802_bss
*bss
= priv
;
7958 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
7962 static int driver_nl80211_authenticate(void *priv
,
7963 struct wpa_driver_auth_params
*params
)
7965 struct i802_bss
*bss
= priv
;
7966 return wpa_driver_nl80211_authenticate(bss
, params
);
7970 static void driver_nl80211_deinit(void *priv
)
7972 struct i802_bss
*bss
= priv
;
7973 wpa_driver_nl80211_deinit(bss
);
7977 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
7980 struct i802_bss
*bss
= priv
;
7981 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
7985 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
7986 size_t data_len
, int noack
,
7988 const u16
*csa_offs
, size_t csa_offs_len
)
7990 struct i802_bss
*bss
= priv
;
7991 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
7992 freq
, 0, 0, 0, csa_offs
,
7997 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
7999 struct i802_bss
*bss
= priv
;
8000 return wpa_driver_nl80211_sta_remove(bss
, addr
, -1, 0);
8004 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
8005 const char *ifname
, int vlan_id
)
8007 struct i802_bss
*bss
= priv
;
8008 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
8012 static int driver_nl80211_read_sta_data(void *priv
,
8013 struct hostap_sta_driver_data
*data
,
8016 struct i802_bss
*bss
= priv
;
8018 os_memset(data
, 0, sizeof(*data
));
8019 return i802_read_sta_data(bss
, data
, addr
);
8023 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
8024 unsigned int wait_time
,
8025 const u8
*dst
, const u8
*src
,
8027 const u8
*data
, size_t data_len
,
8030 struct i802_bss
*bss
= priv
;
8031 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
8032 bssid
, data
, data_len
, no_cck
);
8036 static int driver_nl80211_probe_req_report(void *priv
, int report
)
8038 struct i802_bss
*bss
= priv
;
8039 return wpa_driver_nl80211_probe_req_report(bss
, report
);
8043 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
8044 const u8
*ies
, size_t ies_len
)
8048 struct i802_bss
*bss
= priv
;
8049 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8050 u16 mdid
= WPA_GET_LE16(md
);
8052 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
8053 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_UPDATE_FT_IES
)) ||
8054 nla_put(msg
, NL80211_ATTR_IE
, ies_len
, ies
) ||
8055 nla_put_u16(msg
, NL80211_ATTR_MDID
, mdid
)) {
8060 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8062 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
8063 "err=%d (%s)", ret
, strerror(-ret
));
8070 static const u8
* wpa_driver_nl80211_get_macaddr(void *priv
)
8072 struct i802_bss
*bss
= priv
;
8073 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8075 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
8082 static const char * scan_state_str(enum scan_states scan_state
)
8084 switch (scan_state
) {
8087 case SCAN_REQUESTED
:
8088 return "SCAN_REQUESTED";
8090 return "SCAN_STARTED";
8091 case SCAN_COMPLETED
:
8092 return "SCAN_COMPLETED";
8094 return "SCAN_ABORTED";
8095 case SCHED_SCAN_STARTED
:
8096 return "SCHED_SCAN_STARTED";
8097 case SCHED_SCAN_STOPPED
:
8098 return "SCHED_SCAN_STOPPED";
8099 case SCHED_SCAN_RESULTS
:
8100 return "SCHED_SCAN_RESULTS";
8107 static int wpa_driver_nl80211_status(void *priv
, char *buf
, size_t buflen
)
8109 struct i802_bss
*bss
= priv
;
8110 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8117 res
= os_snprintf(pos
, end
- pos
,
8129 bss
->beacon_set
? "beacon_set=1\n" : "",
8130 bss
->added_if_into_bridge
?
8131 "added_if_into_bridge=1\n" : "",
8132 bss
->added_bridge
? "added_bridge=1\n" : "",
8133 bss
->in_deinit
? "in_deinit=1\n" : "",
8134 bss
->if_dynamic
? "if_dynamic=1\n" : "");
8135 if (os_snprintf_error(end
- pos
, res
))
8139 if (bss
->wdev_id_set
) {
8140 res
= os_snprintf(pos
, end
- pos
, "wdev_id=%llu\n",
8141 (unsigned long long) bss
->wdev_id
);
8142 if (os_snprintf_error(end
- pos
, res
))
8147 res
= os_snprintf(pos
, end
- pos
,
8149 "perm_addr=" MACSTR
"\n"
8153 "auth_bssid=" MACSTR
"\n"
8154 "auth_attempt_bssid=" MACSTR
"\n"
8155 "bssid=" MACSTR
"\n"
8156 "prev_bssid=" MACSTR
"\n"
8160 "monitor_ifidx=%d\n"
8161 "monitor_refcount=%d\n"
8162 "last_mgmt_freq=%u\n"
8163 "eapol_tx_sock=%d\n"
8164 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
8166 MAC2STR(drv
->perm_addr
),
8169 scan_state_str(drv
->scan_state
),
8170 MAC2STR(drv
->auth_bssid
),
8171 MAC2STR(drv
->auth_attempt_bssid
),
8172 MAC2STR(drv
->bssid
),
8173 MAC2STR(drv
->prev_bssid
),
8178 drv
->monitor_refcount
,
8179 drv
->last_mgmt_freq
,
8181 drv
->ignore_if_down_event
?
8182 "ignore_if_down_event=1\n" : "",
8183 drv
->scan_complete_events
?
8184 "scan_complete_events=1\n" : "",
8185 drv
->disabled_11b_rates
?
8186 "disabled_11b_rates=1\n" : "",
8187 drv
->pending_remain_on_chan
?
8188 "pending_remain_on_chan=1\n" : "",
8189 drv
->in_interface_list
? "in_interface_list=1\n" : "",
8190 drv
->device_ap_sme
? "device_ap_sme=1\n" : "",
8191 drv
->poll_command_supported
?
8192 "poll_command_supported=1\n" : "",
8193 drv
->data_tx_status
? "data_tx_status=1\n" : "",
8194 drv
->scan_for_auth
? "scan_for_auth=1\n" : "",
8195 drv
->retry_auth
? "retry_auth=1\n" : "",
8196 drv
->use_monitor
? "use_monitor=1\n" : "",
8197 drv
->ignore_next_local_disconnect
?
8198 "ignore_next_local_disconnect=1\n" : "",
8199 drv
->ignore_next_local_deauth
?
8200 "ignore_next_local_deauth=1\n" : "");
8201 if (os_snprintf_error(end
- pos
, res
))
8205 if (drv
->has_capability
) {
8206 res
= os_snprintf(pos
, end
- pos
,
8207 "capa.key_mgmt=0x%x\n"
8210 "capa.flags=0x%llx\n"
8211 "capa.rrm_flags=0x%x\n"
8212 "capa.max_scan_ssids=%d\n"
8213 "capa.max_sched_scan_ssids=%d\n"
8214 "capa.sched_scan_supported=%d\n"
8215 "capa.max_match_sets=%d\n"
8216 "capa.max_remain_on_chan=%u\n"
8217 "capa.max_stations=%u\n"
8218 "capa.probe_resp_offloads=0x%x\n"
8219 "capa.max_acl_mac_addrs=%u\n"
8220 "capa.num_multichan_concurrent=%u\n"
8221 "capa.mac_addr_rand_sched_scan_supported=%d\n"
8222 "capa.mac_addr_rand_scan_supported=%d\n"
8223 "capa.conc_capab=%u\n"
8224 "capa.max_conc_chan_2_4=%u\n"
8225 "capa.max_conc_chan_5_0=%u\n"
8226 "capa.max_sched_scan_plans=%u\n"
8227 "capa.max_sched_scan_plan_interval=%u\n"
8228 "capa.max_sched_scan_plan_iterations=%u\n",
8232 (unsigned long long) drv
->capa
.flags
,
8233 drv
->capa
.rrm_flags
,
8234 drv
->capa
.max_scan_ssids
,
8235 drv
->capa
.max_sched_scan_ssids
,
8236 drv
->capa
.sched_scan_supported
,
8237 drv
->capa
.max_match_sets
,
8238 drv
->capa
.max_remain_on_chan
,
8239 drv
->capa
.max_stations
,
8240 drv
->capa
.probe_resp_offloads
,
8241 drv
->capa
.max_acl_mac_addrs
,
8242 drv
->capa
.num_multichan_concurrent
,
8243 drv
->capa
.mac_addr_rand_sched_scan_supported
,
8244 drv
->capa
.mac_addr_rand_scan_supported
,
8245 drv
->capa
.conc_capab
,
8246 drv
->capa
.max_conc_chan_2_4
,
8247 drv
->capa
.max_conc_chan_5_0
,
8248 drv
->capa
.max_sched_scan_plans
,
8249 drv
->capa
.max_sched_scan_plan_interval
,
8250 drv
->capa
.max_sched_scan_plan_iterations
);
8251 if (os_snprintf_error(end
- pos
, res
))
8260 static int set_beacon_data(struct nl_msg
*msg
, struct beacon_data
*settings
)
8262 if ((settings
->head
&&
8263 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
,
8264 settings
->head_len
, settings
->head
)) ||
8266 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
,
8267 settings
->tail_len
, settings
->tail
)) ||
8268 (settings
->beacon_ies
&&
8269 nla_put(msg
, NL80211_ATTR_IE
,
8270 settings
->beacon_ies_len
, settings
->beacon_ies
)) ||
8271 (settings
->proberesp_ies
&&
8272 nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
8273 settings
->proberesp_ies_len
, settings
->proberesp_ies
)) ||
8274 (settings
->assocresp_ies
&&
8275 nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
8276 settings
->assocresp_ies_len
, settings
->assocresp_ies
)) ||
8277 (settings
->probe_resp
&&
8278 nla_put(msg
, NL80211_ATTR_PROBE_RESP
,
8279 settings
->probe_resp_len
, settings
->probe_resp
)))
8286 static int nl80211_switch_channel(void *priv
, struct csa_settings
*settings
)
8289 struct i802_bss
*bss
= priv
;
8290 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8291 struct nlattr
*beacon_csa
;
8293 int csa_off_len
= 0;
8296 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
8297 settings
->cs_count
, settings
->block_tx
,
8298 settings
->freq_params
.freq
, settings
->freq_params
.bandwidth
,
8299 settings
->freq_params
.center_freq1
,
8300 settings
->freq_params
.center_freq2
);
8302 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
8303 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support channel switch command");
8307 if ((drv
->nlmode
!= NL80211_IFTYPE_AP
) &&
8308 (drv
->nlmode
!= NL80211_IFTYPE_P2P_GO
))
8312 * Remove empty counters, assuming Probe Response and Beacon frame
8313 * counters match. This implementation assumes that there are only two
8316 if (settings
->counter_offset_beacon
[0] &&
8317 !settings
->counter_offset_beacon
[1]) {
8319 } else if (settings
->counter_offset_beacon
[1] &&
8320 !settings
->counter_offset_beacon
[0]) {
8322 settings
->counter_offset_beacon
[0] =
8323 settings
->counter_offset_beacon
[1];
8324 settings
->counter_offset_presp
[0] =
8325 settings
->counter_offset_presp
[1];
8326 } else if (settings
->counter_offset_beacon
[1] &&
8327 settings
->counter_offset_beacon
[0]) {
8330 wpa_printf(MSG_ERROR
, "nl80211: No CSA counters provided");
8334 /* Check CSA counters validity */
8335 if (drv
->capa
.max_csa_counters
&&
8336 csa_off_len
> drv
->capa
.max_csa_counters
) {
8337 wpa_printf(MSG_ERROR
,
8338 "nl80211: Too many CSA counters provided");
8342 if (!settings
->beacon_csa
.tail
)
8345 for (i
= 0; i
< csa_off_len
; i
++) {
8346 u16 csa_c_off_bcn
= settings
->counter_offset_beacon
[i
];
8347 u16 csa_c_off_presp
= settings
->counter_offset_presp
[i
];
8349 if ((settings
->beacon_csa
.tail_len
<= csa_c_off_bcn
) ||
8350 (settings
->beacon_csa
.tail
[csa_c_off_bcn
] !=
8351 settings
->cs_count
))
8354 if (settings
->beacon_csa
.probe_resp
&&
8355 ((settings
->beacon_csa
.probe_resp_len
<=
8357 (settings
->beacon_csa
.probe_resp
[csa_c_off_presp
] !=
8358 settings
->cs_count
)))
8362 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_CHANNEL_SWITCH
)) ||
8363 nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
,
8364 settings
->cs_count
) ||
8365 (ret
= nl80211_put_freq_params(msg
, &settings
->freq_params
)) ||
8366 (settings
->block_tx
&&
8367 nla_put_flag(msg
, NL80211_ATTR_CH_SWITCH_BLOCK_TX
)))
8370 /* beacon_after params */
8371 ret
= set_beacon_data(msg
, &settings
->beacon_after
);
8375 /* beacon_csa params */
8376 beacon_csa
= nla_nest_start(msg
, NL80211_ATTR_CSA_IES
);
8380 ret
= set_beacon_data(msg
, &settings
->beacon_csa
);
8384 if (nla_put(msg
, NL80211_ATTR_CSA_C_OFF_BEACON
,
8385 csa_off_len
* sizeof(u16
),
8386 settings
->counter_offset_beacon
) ||
8387 (settings
->beacon_csa
.probe_resp
&&
8388 nla_put(msg
, NL80211_ATTR_CSA_C_OFF_PRESP
,
8389 csa_off_len
* sizeof(u16
),
8390 settings
->counter_offset_presp
)))
8393 nla_nest_end(msg
, beacon_csa
);
8394 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8396 wpa_printf(MSG_DEBUG
, "nl80211: switch_channel failed err=%d (%s)",
8397 ret
, strerror(-ret
));
8405 wpa_printf(MSG_DEBUG
, "nl80211: Could not build channel switch request");
8410 static int nl80211_add_ts(void *priv
, u8 tsid
, const u8
*addr
,
8411 u8 user_priority
, u16 admitted_time
)
8413 struct i802_bss
*bss
= priv
;
8414 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8418 wpa_printf(MSG_DEBUG
,
8419 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
8420 tsid
, admitted_time
, user_priority
);
8422 if (!is_sta_interface(drv
->nlmode
))
8425 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_ADD_TX_TS
);
8427 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
8428 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8429 nla_put_u8(msg
, NL80211_ATTR_USER_PRIO
, user_priority
) ||
8430 nla_put_u16(msg
, NL80211_ATTR_ADMITTED_TIME
, admitted_time
)) {
8435 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8437 wpa_printf(MSG_DEBUG
, "nl80211: add_ts failed err=%d (%s)",
8438 ret
, strerror(-ret
));
8443 static int nl80211_del_ts(void *priv
, u8 tsid
, const u8
*addr
)
8445 struct i802_bss
*bss
= priv
;
8446 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8450 wpa_printf(MSG_DEBUG
, "nl80211: del_ts request: tsid=%u", tsid
);
8452 if (!is_sta_interface(drv
->nlmode
))
8455 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_TX_TS
)) ||
8456 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
8457 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
8462 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8464 wpa_printf(MSG_DEBUG
, "nl80211: del_ts failed err=%d (%s)",
8465 ret
, strerror(-ret
));
8470 #ifdef CONFIG_TESTING_OPTIONS
8471 static int cmd_reply_handler(struct nl_msg
*msg
, void *arg
)
8473 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8474 struct wpabuf
*buf
= arg
;
8479 if ((size_t) genlmsg_attrlen(gnlh
, 0) > wpabuf_tailroom(buf
)) {
8480 wpa_printf(MSG_INFO
, "nl80211: insufficient buffer space for reply");
8484 wpabuf_put_data(buf
, genlmsg_attrdata(gnlh
, 0),
8485 genlmsg_attrlen(gnlh
, 0));
8489 #endif /* CONFIG_TESTING_OPTIONS */
8492 static int vendor_reply_handler(struct nl_msg
*msg
, void *arg
)
8494 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8495 struct nlattr
*nl_vendor_reply
, *nl
;
8496 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8497 struct wpabuf
*buf
= arg
;
8503 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8504 genlmsg_attrlen(gnlh
, 0), NULL
);
8505 nl_vendor_reply
= tb
[NL80211_ATTR_VENDOR_DATA
];
8507 if (!nl_vendor_reply
)
8510 if ((size_t) nla_len(nl_vendor_reply
) > wpabuf_tailroom(buf
)) {
8511 wpa_printf(MSG_INFO
, "nl80211: Vendor command: insufficient buffer space for reply");
8515 nla_for_each_nested(nl
, nl_vendor_reply
, rem
) {
8516 wpabuf_put_data(buf
, nla_data(nl
), nla_len(nl
));
8523 static int nl80211_vendor_cmd(void *priv
, unsigned int vendor_id
,
8524 unsigned int subcmd
, const u8
*data
,
8525 size_t data_len
, struct wpabuf
*buf
)
8527 struct i802_bss
*bss
= priv
;
8528 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8532 #ifdef CONFIG_TESTING_OPTIONS
8533 if (vendor_id
== 0xffffffff) {
8534 msg
= nlmsg_alloc();
8538 nl80211_cmd(drv
, msg
, 0, subcmd
);
8539 if (nlmsg_append(msg
, (void *) data
, data_len
, NLMSG_ALIGNTO
) <
8542 ret
= send_and_recv_msgs(drv
, msg
, cmd_reply_handler
, buf
);
8544 wpa_printf(MSG_DEBUG
, "nl80211: command failed err=%d",
8548 #endif /* CONFIG_TESTING_OPTIONS */
8550 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_VENDOR
)) ||
8551 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, vendor_id
) ||
8552 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
) ||
8554 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, data_len
, data
)))
8557 ret
= send_and_recv_msgs(drv
, msg
, vendor_reply_handler
, buf
);
8559 wpa_printf(MSG_DEBUG
, "nl80211: vendor command failed err=%d",
8569 static int nl80211_set_qos_map(void *priv
, const u8
*qos_map_set
,
8572 struct i802_bss
*bss
= priv
;
8573 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8577 wpa_hexdump(MSG_DEBUG
, "nl80211: Setting QoS Map",
8578 qos_map_set
, qos_map_set_len
);
8580 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_QOS_MAP
)) ||
8581 nla_put(msg
, NL80211_ATTR_QOS_MAP
, qos_map_set_len
, qos_map_set
)) {
8586 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8588 wpa_printf(MSG_DEBUG
, "nl80211: Setting QoS Map failed");
8594 static int nl80211_set_wowlan(void *priv
,
8595 const struct wowlan_triggers
*triggers
)
8597 struct i802_bss
*bss
= priv
;
8598 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8600 struct nlattr
*wowlan_triggers
;
8603 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan");
8605 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_SET_WOWLAN
)) ||
8606 !(wowlan_triggers
= nla_nest_start(msg
,
8607 NL80211_ATTR_WOWLAN_TRIGGERS
)) ||
8609 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
8610 (triggers
->disconnect
&&
8611 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
8612 (triggers
->magic_pkt
&&
8613 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
8614 (triggers
->gtk_rekey_failure
&&
8615 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
8616 (triggers
->eap_identity_req
&&
8617 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
8618 (triggers
->four_way_handshake
&&
8619 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
8620 (triggers
->rfkill_release
&&
8621 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))) {
8626 nla_nest_end(msg
, wowlan_triggers
);
8628 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8630 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan failed");
8636 #ifdef CONFIG_DRIVER_NL80211_QCA
8637 static int nl80211_roaming(void *priv
, int allowed
, const u8
*bssid
)
8639 struct i802_bss
*bss
= priv
;
8640 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8642 struct nlattr
*params
;
8644 wpa_printf(MSG_DEBUG
, "nl80211: Roaming policy: allowed=%d", allowed
);
8646 if (!drv
->roaming_vendor_cmd_avail
) {
8647 wpa_printf(MSG_DEBUG
,
8648 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
8652 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8653 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8654 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8655 QCA_NL80211_VENDOR_SUBCMD_ROAMING
) ||
8656 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8657 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY
,
8658 allowed
? QCA_ROAMING_ALLOWED_WITHIN_ESS
:
8659 QCA_ROAMING_NOT_ALLOWED
) ||
8661 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_MAC_ADDR
, ETH_ALEN
, bssid
))) {
8665 nla_nest_end(msg
, params
);
8667 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8669 #endif /* CONFIG_DRIVER_NL80211_QCA */
8672 static int nl80211_set_mac_addr(void *priv
, const u8
*addr
)
8674 struct i802_bss
*bss
= priv
;
8675 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8676 int new_addr
= addr
!= NULL
;
8682 addr
= drv
->perm_addr
;
8684 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) < 0)
8687 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
, addr
) < 0)
8689 wpa_printf(MSG_DEBUG
,
8690 "nl80211: failed to set_mac_addr for %s to " MACSTR
,
8691 bss
->ifname
, MAC2STR(addr
));
8692 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
8694 wpa_printf(MSG_DEBUG
,
8695 "nl80211: Could not restore interface UP after failed set_mac_addr");
8700 wpa_printf(MSG_DEBUG
, "nl80211: set_mac_addr for %s to " MACSTR
,
8701 bss
->ifname
, MAC2STR(addr
));
8702 drv
->addr_changed
= new_addr
;
8703 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
8705 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1) < 0)
8707 wpa_printf(MSG_DEBUG
,
8708 "nl80211: Could not restore interface UP after set_mac_addr");
8717 static int wpa_driver_nl80211_init_mesh(void *priv
)
8719 if (wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_MESH_POINT
)) {
8720 wpa_printf(MSG_INFO
,
8721 "nl80211: Failed to set interface into mesh mode");
8728 static int nl80211_put_mesh_id(struct nl_msg
*msg
, const u8
*mesh_id
,
8732 wpa_hexdump_ascii(MSG_DEBUG
, " * Mesh ID (SSID)",
8733 mesh_id
, mesh_id_len
);
8734 return nla_put(msg
, NL80211_ATTR_MESH_ID
, mesh_id_len
, mesh_id
);
8741 static int nl80211_put_mesh_config(struct nl_msg
*msg
,
8742 struct wpa_driver_mesh_bss_params
*params
)
8744 struct nlattr
*container
;
8746 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
8750 if (((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
) &&
8751 nla_put_u32(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
8752 params
->auto_plinks
)) ||
8753 ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS
) &&
8754 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
8755 params
->max_peer_links
)))
8759 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
8760 * the timer could disconnect stations even in that case.
8762 if ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT
) &&
8763 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
8764 params
->peer_link_timeout
)) {
8765 wpa_printf(MSG_ERROR
, "nl80211: Failed to set PLINK_TIMEOUT");
8769 if ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE
) &&
8770 nla_put_u16(msg
, NL80211_MESHCONF_HT_OPMODE
, params
->ht_opmode
)) {
8771 wpa_printf(MSG_ERROR
, "nl80211: Failed to set HT_OP_MODE");
8775 nla_nest_end(msg
, container
);
8781 static int nl80211_join_mesh(struct i802_bss
*bss
,
8782 struct wpa_driver_mesh_join_params
*params
)
8784 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8786 struct nlattr
*container
;
8789 wpa_printf(MSG_DEBUG
, "nl80211: mesh join (ifindex=%d)", drv
->ifindex
);
8790 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_MESH
);
8792 nl80211_put_freq_params(msg
, ¶ms
->freq
) ||
8793 nl80211_put_basic_rates(msg
, params
->basic_rates
) ||
8794 nl80211_put_mesh_id(msg
, params
->meshid
, params
->meshid_len
) ||
8795 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
8796 nl80211_put_dtim_period(msg
, params
->dtim_period
))
8799 wpa_printf(MSG_DEBUG
, " * flags=%08X", params
->flags
);
8801 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_SETUP
);
8806 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ies
, params
->ie_len
);
8807 if (nla_put(msg
, NL80211_MESH_SETUP_IE
, params
->ie_len
,
8811 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
8812 if (params
->flags
& WPA_DRIVER_MESH_FLAG_SAE_AUTH
) {
8813 if (nla_put_u8(msg
, NL80211_MESH_SETUP_AUTH_PROTOCOL
, 0x1) ||
8814 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AUTH
))
8817 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_AMPE
) &&
8818 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AMPE
))
8820 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
) &&
8821 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_MPM
))
8823 nla_nest_end(msg
, container
);
8825 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
;
8826 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT
;
8827 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS
;
8828 if (nl80211_put_mesh_config(msg
, ¶ms
->conf
) < 0)
8831 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8834 wpa_printf(MSG_DEBUG
, "nl80211: mesh join failed: ret=%d (%s)",
8835 ret
, strerror(-ret
));
8839 drv
->assoc_freq
= bss
->freq
= params
->freq
.freq
;
8840 wpa_printf(MSG_DEBUG
, "nl80211: mesh join request send successfully");
8849 wpa_driver_nl80211_join_mesh(void *priv
,
8850 struct wpa_driver_mesh_join_params
*params
)
8852 struct i802_bss
*bss
= priv
;
8855 timeout
= params
->conf
.peer_link_timeout
;
8857 /* Disable kernel inactivity timer */
8858 if (params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
)
8859 params
->conf
.peer_link_timeout
= 0;
8861 ret
= nl80211_join_mesh(bss
, params
);
8862 if (ret
== -EINVAL
&& params
->conf
.peer_link_timeout
== 0) {
8863 wpa_printf(MSG_DEBUG
,
8864 "nl80211: Mesh join retry for peer_link_timeout");
8866 * Old kernel does not support setting
8867 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
8868 * into future from peer_link_timeout.
8870 params
->conf
.peer_link_timeout
= timeout
+ 60;
8871 ret
= nl80211_join_mesh(priv
, params
);
8874 params
->conf
.peer_link_timeout
= timeout
;
8879 static int wpa_driver_nl80211_leave_mesh(void *priv
)
8881 struct i802_bss
*bss
= priv
;
8882 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8886 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave (ifindex=%d)", drv
->ifindex
);
8887 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_MESH
);
8888 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8890 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave failed: ret=%d (%s)",
8891 ret
, strerror(-ret
));
8893 wpa_printf(MSG_DEBUG
,
8894 "nl80211: mesh leave request send successfully");
8897 if (wpa_driver_nl80211_set_mode(drv
->first_bss
,
8898 NL80211_IFTYPE_STATION
)) {
8899 wpa_printf(MSG_INFO
,
8900 "nl80211: Failed to set interface into station mode");
8905 #endif /* CONFIG_MESH */
8908 static int wpa_driver_br_add_ip_neigh(void *priv
, u8 version
,
8909 const u8
*ipaddr
, int prefixlen
,
8912 #ifdef CONFIG_LIBNL3_ROUTE
8913 struct i802_bss
*bss
= priv
;
8914 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8915 struct rtnl_neigh
*rn
;
8916 struct nl_addr
*nl_ipaddr
= NULL
;
8917 struct nl_addr
*nl_lladdr
= NULL
;
8918 int family
, addrsize
;
8921 if (!ipaddr
|| prefixlen
== 0 || !addr
)
8924 if (bss
->br_ifindex
== 0) {
8925 wpa_printf(MSG_DEBUG
,
8926 "nl80211: bridge must be set before adding an ip neigh to it");
8930 if (!drv
->rtnl_sk
) {
8931 wpa_printf(MSG_DEBUG
,
8932 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8939 } else if (version
== 6) {
8946 rn
= rtnl_neigh_alloc();
8950 /* set the destination ip address for neigh */
8951 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
8952 if (nl_ipaddr
== NULL
) {
8953 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
8957 nl_addr_set_prefixlen(nl_ipaddr
, prefixlen
);
8958 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
8960 wpa_printf(MSG_DEBUG
,
8961 "nl80211: neigh set destination addr failed");
8965 /* set the corresponding lladdr for neigh */
8966 nl_lladdr
= nl_addr_build(AF_BRIDGE
, (u8
*) addr
, ETH_ALEN
);
8967 if (nl_lladdr
== NULL
) {
8968 wpa_printf(MSG_DEBUG
, "nl80211: neigh set lladdr failed");
8972 rtnl_neigh_set_lladdr(rn
, nl_lladdr
);
8974 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
8975 rtnl_neigh_set_state(rn
, NUD_PERMANENT
);
8977 res
= rtnl_neigh_add(drv
->rtnl_sk
, rn
, NLM_F_CREATE
);
8979 wpa_printf(MSG_DEBUG
,
8980 "nl80211: Adding bridge ip neigh failed: %s",
8985 nl_addr_put(nl_lladdr
);
8987 nl_addr_put(nl_ipaddr
);
8991 #else /* CONFIG_LIBNL3_ROUTE */
8993 #endif /* CONFIG_LIBNL3_ROUTE */
8997 static int wpa_driver_br_delete_ip_neigh(void *priv
, u8 version
,
9000 #ifdef CONFIG_LIBNL3_ROUTE
9001 struct i802_bss
*bss
= priv
;
9002 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9003 struct rtnl_neigh
*rn
;
9004 struct nl_addr
*nl_ipaddr
;
9005 int family
, addrsize
;
9014 } else if (version
== 6) {
9021 if (bss
->br_ifindex
== 0) {
9022 wpa_printf(MSG_DEBUG
,
9023 "nl80211: bridge must be set to delete an ip neigh");
9027 if (!drv
->rtnl_sk
) {
9028 wpa_printf(MSG_DEBUG
,
9029 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9033 rn
= rtnl_neigh_alloc();
9037 /* set the destination ip address for neigh */
9038 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
9039 if (nl_ipaddr
== NULL
) {
9040 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
9044 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
9046 wpa_printf(MSG_DEBUG
,
9047 "nl80211: neigh set destination addr failed");
9051 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
9053 res
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
9055 wpa_printf(MSG_DEBUG
,
9056 "nl80211: Deleting bridge ip neigh failed: %s",
9061 nl_addr_put(nl_ipaddr
);
9065 #else /* CONFIG_LIBNL3_ROUTE */
9067 #endif /* CONFIG_LIBNL3_ROUTE */
9071 static int linux_write_system_file(const char *path
, unsigned int val
)
9076 len
= os_snprintf(buf
, sizeof(buf
), "%u\n", val
);
9077 if (os_snprintf_error(sizeof(buf
), len
))
9080 fd
= open(path
, O_WRONLY
);
9084 if (write(fd
, buf
, len
) < 0) {
9085 wpa_printf(MSG_DEBUG
,
9086 "nl80211: Failed to write Linux system file: %s with the value of %d",
9097 static const char * drv_br_port_attr_str(enum drv_br_port_attr attr
)
9100 case DRV_BR_PORT_ATTR_PROXYARP
:
9101 return "proxyarp_wifi";
9102 case DRV_BR_PORT_ATTR_HAIRPIN_MODE
:
9103 return "hairpin_mode";
9110 static int wpa_driver_br_port_set_attr(void *priv
, enum drv_br_port_attr attr
,
9113 struct i802_bss
*bss
= priv
;
9115 const char *attr_txt
;
9117 attr_txt
= drv_br_port_attr_str(attr
);
9118 if (attr_txt
== NULL
)
9121 os_snprintf(path
, sizeof(path
), "/sys/class/net/%s/brport/%s",
9122 bss
->ifname
, attr_txt
);
9124 if (linux_write_system_file(path
, val
))
9131 static const char * drv_br_net_param_str(enum drv_br_net_param param
)
9134 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
9135 return "arp_accept";
9142 static int wpa_driver_br_set_net_param(void *priv
, enum drv_br_net_param param
,
9145 struct i802_bss
*bss
= priv
;
9147 const char *param_txt
;
9150 if (param
== DRV_BR_MULTICAST_SNOOPING
) {
9151 os_snprintf(path
, sizeof(path
),
9152 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
9157 param_txt
= drv_br_net_param_str(param
);
9158 if (param_txt
== NULL
)
9162 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
9169 os_snprintf(path
, sizeof(path
), "/proc/sys/net/ipv%d/conf/%s/%s",
9170 ip_version
, bss
->brname
, param_txt
);
9173 if (linux_write_system_file(path
, val
))
9180 #ifdef CONFIG_DRIVER_NL80211_QCA
9182 static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode
)
9185 case HOSTAPD_MODE_IEEE80211B
:
9186 return QCA_ACS_MODE_IEEE80211B
;
9187 case HOSTAPD_MODE_IEEE80211G
:
9188 return QCA_ACS_MODE_IEEE80211G
;
9189 case HOSTAPD_MODE_IEEE80211A
:
9190 return QCA_ACS_MODE_IEEE80211A
;
9191 case HOSTAPD_MODE_IEEE80211AD
:
9192 return QCA_ACS_MODE_IEEE80211AD
;
9193 case HOSTAPD_MODE_IEEE80211ANY
:
9194 return QCA_ACS_MODE_IEEE80211ANY
;
9201 static int add_acs_freq_list(struct nl_msg
*msg
, const int *freq_list
)
9208 len
= int_array_len(freq_list
);
9209 freqs
= os_malloc(sizeof(u32
) * len
);
9212 for (i
= 0; i
< len
; i
++)
9213 freqs
[i
] = freq_list
[i
];
9214 ret
= nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST
,
9215 sizeof(u32
) * len
, freqs
);
9221 static int wpa_driver_do_acs(void *priv
, struct drv_acs_params
*params
)
9223 struct i802_bss
*bss
= priv
;
9224 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9226 struct nlattr
*data
;
9230 mode
= hw_mode_to_qca_acs(params
->hw_mode
);
9234 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9235 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9236 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9237 QCA_NL80211_VENDOR_SUBCMD_DO_ACS
) ||
9238 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9239 nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE
, mode
) ||
9240 (params
->ht_enabled
&&
9241 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED
)) ||
9242 (params
->ht40_enabled
&&
9243 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED
)) ||
9244 (params
->vht_enabled
&&
9245 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED
)) ||
9246 nla_put_u16(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH
,
9247 params
->ch_width
) ||
9248 (params
->ch_list_len
&&
9249 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST
, params
->ch_list_len
,
9250 params
->ch_list
)) ||
9251 add_acs_freq_list(msg
, params
->freq_list
)) {
9255 nla_nest_end(msg
, data
);
9257 wpa_printf(MSG_DEBUG
,
9258 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
9259 params
->hw_mode
, params
->ht_enabled
, params
->ht40_enabled
,
9260 params
->vht_enabled
, params
->ch_width
, params
->ch_list_len
);
9262 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9264 wpa_printf(MSG_DEBUG
,
9265 "nl80211: Failed to invoke driver ACS function: %s",
9272 static int nl80211_set_band(void *priv
, enum set_band band
)
9274 struct i802_bss
*bss
= priv
;
9275 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9277 struct nlattr
*data
;
9279 enum qca_set_band qca_band
;
9281 if (!drv
->setband_vendor_cmd_avail
)
9285 case WPA_SETBAND_AUTO
:
9286 qca_band
= QCA_SETBAND_AUTO
;
9288 case WPA_SETBAND_5G
:
9289 qca_band
= QCA_SETBAND_5G
;
9291 case WPA_SETBAND_2G
:
9292 qca_band
= QCA_SETBAND_2G
;
9298 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9299 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9300 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9301 QCA_NL80211_VENDOR_SUBCMD_SETBAND
) ||
9302 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9303 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE
, qca_band
)) {
9307 nla_nest_end(msg
, data
);
9309 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9311 wpa_printf(MSG_DEBUG
,
9312 "nl80211: Driver setband function failed: %s",
9319 struct nl80211_pcl
{
9321 unsigned int *freq_list
;
9324 static int preferred_freq_info_handler(struct nl_msg
*msg
, void *arg
)
9326 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9327 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9328 struct nl80211_pcl
*param
= arg
;
9329 struct nlattr
*nl_vend
, *attr
;
9330 enum qca_iface_type iface_type
;
9331 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
9332 unsigned int num
, max_num
;
9335 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9336 genlmsg_attrlen(gnlh
, 0), NULL
);
9338 nl_vend
= tb
[NL80211_ATTR_VENDOR_DATA
];
9342 nla_parse(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
9343 nla_data(nl_vend
), nla_len(nl_vend
), NULL
);
9346 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
];
9348 wpa_printf(MSG_ERROR
, "nl80211: iface_type couldn't be found");
9353 iface_type
= (enum qca_iface_type
) nla_get_u32(attr
);
9354 wpa_printf(MSG_DEBUG
, "nl80211: Driver returned iface_type=%d",
9357 attr
= tb_vendor
[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST
];
9359 wpa_printf(MSG_ERROR
,
9360 "nl80211: preferred_freq_list couldn't be found");
9366 * param->num has the maximum number of entries for which there
9367 * is room in the freq_list provided by the caller.
9369 freqs
= nla_data(attr
);
9370 max_num
= nla_len(attr
) / sizeof(u32
);
9371 if (max_num
> param
->num
)
9372 max_num
= param
->num
;
9373 for (num
= 0; num
< max_num
; num
++)
9374 param
->freq_list
[num
] = freqs
[num
];
9381 static int nl80211_get_pref_freq_list(void *priv
,
9382 enum wpa_driver_if_type if_type
,
9384 unsigned int *freq_list
)
9386 struct i802_bss
*bss
= priv
;
9387 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9391 struct nlattr
*params
;
9392 struct nl80211_pcl param
;
9393 enum qca_iface_type iface_type
;
9395 if (!drv
->get_pref_freq_list
)
9399 case WPA_IF_STATION
:
9400 iface_type
= QCA_IFACE_TYPE_STA
;
9403 iface_type
= QCA_IFACE_TYPE_AP
;
9406 iface_type
= QCA_IFACE_TYPE_P2P_GO
;
9408 case WPA_IF_P2P_CLIENT
:
9409 iface_type
= QCA_IFACE_TYPE_P2P_CLIENT
;
9412 iface_type
= QCA_IFACE_TYPE_IBSS
;
9415 iface_type
= QCA_IFACE_TYPE_TDLS
;
9422 param
.freq_list
= freq_list
;
9424 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9425 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
) ||
9426 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9427 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9428 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST
) ||
9429 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9431 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
,
9433 wpa_printf(MSG_ERROR
,
9434 "%s: err in adding vendor_cmd and vendor_data",
9439 nla_nest_end(msg
, params
);
9441 os_memset(freq_list
, 0, *num
* sizeof(freq_list
[0]));
9442 ret
= send_and_recv_msgs(drv
, msg
, preferred_freq_info_handler
, ¶m
);
9444 wpa_printf(MSG_ERROR
,
9445 "%s: err in send_and_recv_msgs", __func__
);
9451 for (i
= 0; i
< *num
; i
++) {
9452 wpa_printf(MSG_DEBUG
, "nl80211: preferred_channel_list[%d]=%d",
9460 static int nl80211_set_prob_oper_freq(void *priv
, unsigned int freq
)
9462 struct i802_bss
*bss
= priv
;
9463 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9466 struct nlattr
*params
;
9468 if (!drv
->set_prob_oper_freq
)
9471 wpa_printf(MSG_DEBUG
,
9472 "nl80211: Set P2P probable operating freq %u for ifindex %d",
9473 freq
, bss
->ifindex
);
9475 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9476 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9477 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9478 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL
) ||
9479 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9481 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE
,
9482 QCA_IFACE_TYPE_P2P_CLIENT
) ||
9484 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ
,
9486 wpa_printf(MSG_ERROR
,
9487 "%s: err in adding vendor_cmd and vendor_data",
9492 nla_nest_end(msg
, params
);
9494 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9497 wpa_printf(MSG_ERROR
, "%s: err in send_and_recv_msgs",
9506 static int nl80211_p2p_lo_start(void *priv
, unsigned int freq
,
9507 unsigned int period
, unsigned int interval
,
9508 unsigned int count
, const u8
*device_types
,
9509 size_t dev_types_len
,
9510 const u8
*ies
, size_t ies_len
)
9512 struct i802_bss
*bss
= priv
;
9513 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9515 struct nlattr
*container
;
9518 wpa_printf(MSG_DEBUG
,
9519 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
9520 freq
, period
, interval
, count
);
9522 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD
))
9525 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9526 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9527 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9528 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START
))
9531 container
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
9535 if (nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL
,
9537 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD
,
9539 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL
,
9541 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT
,
9543 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES
,
9544 dev_types_len
, device_types
) ||
9545 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE
,
9549 nla_nest_end(msg
, container
);
9550 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9553 wpa_printf(MSG_DEBUG
,
9554 "nl80211: Failed to send P2P Listen offload vendor command");
9566 static int nl80211_p2p_lo_stop(void *priv
)
9568 struct i802_bss
*bss
= priv
;
9569 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9572 wpa_printf(MSG_DEBUG
, "nl80211: Stop P2P Listen offload");
9574 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD
))
9577 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9578 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9579 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9580 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP
)) {
9585 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9589 static int nl80211_set_tdls_mode(void *priv
, int tdls_external_control
)
9591 struct i802_bss
*bss
= priv
;
9592 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9594 struct nlattr
*params
;
9598 wpa_printf(MSG_DEBUG
,
9599 "nl80211: Set TDKS mode: tdls_external_control=%d",
9600 tdls_external_control
);
9602 if (tdls_external_control
== 1)
9603 tdls_mode
= QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT
|
9604 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL
;
9606 tdls_mode
= QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT
;
9608 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9609 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9610 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9611 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS
))
9614 params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
9618 if (nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE
,
9622 nla_nest_end(msg
, params
);
9624 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9627 wpa_printf(MSG_ERROR
,
9628 "nl80211: Set TDLS mode failed: ret=%d (%s)",
9629 ret
, strerror(-ret
));
9638 #endif /* CONFIG_DRIVER_NL80211_QCA */
9641 static int nl80211_write_to_file(const char *name
, unsigned int val
)
9646 fd
= open(name
, O_RDWR
);
9648 wpa_printf(MSG_ERROR
, "nl80211: Failed to open %s: %s",
9649 name
, strerror(errno
));
9653 len
= os_snprintf(tmp
, sizeof(tmp
), "%u\n", val
);
9654 len
= write(fd
, tmp
, len
);
9656 wpa_printf(MSG_ERROR
, "nl80211: Failed to write to %s: %s",
9657 name
, strerror(errno
));
9664 static int nl80211_configure_data_frame_filters(void *priv
, u32 filter_flags
)
9666 struct i802_bss
*bss
= priv
;
9670 wpa_printf(MSG_DEBUG
, "nl80211: Data frame filter flags=0x%x",
9673 /* Configure filtering of unicast frame encrypted using GTK */
9674 ret
= os_snprintf(path
, sizeof(path
),
9675 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
9677 if (os_snprintf_error(sizeof(path
), ret
))
9680 ret
= nl80211_write_to_file(path
,
9682 WPA_DATA_FRAME_FILTER_FLAG_GTK
));
9684 wpa_printf(MSG_ERROR
,
9685 "nl80211: Failed to set IPv4 unicast in multicast filter");
9689 os_snprintf(path
, sizeof(path
),
9690 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
9692 ret
= nl80211_write_to_file(path
,
9694 WPA_DATA_FRAME_FILTER_FLAG_GTK
));
9697 wpa_printf(MSG_ERROR
,
9698 "nl80211: Failed to set IPv6 unicast in multicast filter");
9702 /* Configure filtering of unicast frame encrypted using GTK */
9703 os_snprintf(path
, sizeof(path
),
9704 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
9706 ret
= nl80211_write_to_file(path
,
9708 WPA_DATA_FRAME_FILTER_FLAG_ARP
));
9710 wpa_printf(MSG_ERROR
,
9711 "nl80211: Failed set gratuitous ARP filter");
9715 /* Configure filtering of IPv6 NA frames */
9716 os_snprintf(path
, sizeof(path
),
9717 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
9719 ret
= nl80211_write_to_file(path
,
9721 WPA_DATA_FRAME_FILTER_FLAG_NA
));
9723 wpa_printf(MSG_ERROR
,
9724 "nl80211: Failed to set unsolicited NA filter");
9732 static int nl80211_get_ext_capab(void *priv
, enum wpa_driver_if_type type
,
9733 const u8
**ext_capa
, const u8
**ext_capa_mask
,
9734 unsigned int *ext_capa_len
)
9736 struct i802_bss
*bss
= priv
;
9737 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9738 enum nl80211_iftype nlmode
;
9741 if (!ext_capa
|| !ext_capa_mask
|| !ext_capa_len
)
9744 nlmode
= wpa_driver_nl80211_if_type(type
);
9746 /* By default, use the per-radio values */
9747 *ext_capa
= drv
->extended_capa
;
9748 *ext_capa_mask
= drv
->extended_capa_mask
;
9749 *ext_capa_len
= drv
->extended_capa_len
;
9751 /* Replace the default value if a per-interface type value exists */
9752 for (i
= 0; i
< drv
->num_iface_ext_capa
; i
++) {
9753 if (nlmode
== drv
->iface_ext_capa
[i
].iftype
) {
9754 *ext_capa
= drv
->iface_ext_capa
[i
].ext_capa
;
9755 *ext_capa_mask
= drv
->iface_ext_capa
[i
].ext_capa_mask
;
9756 *ext_capa_len
= drv
->iface_ext_capa
[i
].ext_capa_len
;
9765 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
9767 .desc
= "Linux nl80211/cfg80211",
9768 .get_bssid
= wpa_driver_nl80211_get_bssid
,
9769 .get_ssid
= wpa_driver_nl80211_get_ssid
,
9770 .set_key
= driver_nl80211_set_key
,
9771 .scan2
= driver_nl80211_scan2
,
9772 .sched_scan
= wpa_driver_nl80211_sched_scan
,
9773 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
9774 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
9775 .abort_scan
= wpa_driver_nl80211_abort_scan
,
9776 .deauthenticate
= driver_nl80211_deauthenticate
,
9777 .authenticate
= driver_nl80211_authenticate
,
9778 .associate
= wpa_driver_nl80211_associate
,
9779 .global_init
= nl80211_global_init
,
9780 .global_deinit
= nl80211_global_deinit
,
9781 .init2
= wpa_driver_nl80211_init
,
9782 .deinit
= driver_nl80211_deinit
,
9783 .get_capa
= wpa_driver_nl80211_get_capa
,
9784 .set_operstate
= wpa_driver_nl80211_set_operstate
,
9785 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
9786 .set_country
= wpa_driver_nl80211_set_country
,
9787 .get_country
= wpa_driver_nl80211_get_country
,
9788 .set_ap
= wpa_driver_nl80211_set_ap
,
9789 .set_acl
= wpa_driver_nl80211_set_acl
,
9790 .if_add
= wpa_driver_nl80211_if_add
,
9791 .if_remove
= driver_nl80211_if_remove
,
9792 .send_mlme
= driver_nl80211_send_mlme
,
9793 .get_hw_feature_data
= nl80211_get_hw_feature_data
,
9794 .sta_add
= wpa_driver_nl80211_sta_add
,
9795 .sta_remove
= driver_nl80211_sta_remove
,
9796 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
9797 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
9798 .hapd_init
= i802_init
,
9799 .hapd_deinit
= i802_deinit
,
9800 .set_wds_sta
= i802_set_wds_sta
,
9801 .get_seqnum
= i802_get_seqnum
,
9802 .flush
= i802_flush
,
9803 .get_inact_sec
= i802_get_inact_sec
,
9804 .sta_clear_stats
= i802_sta_clear_stats
,
9805 .set_rts
= i802_set_rts
,
9806 .set_frag
= i802_set_frag
,
9807 .set_tx_queue_params
= i802_set_tx_queue_params
,
9808 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
9809 .sta_deauth
= i802_sta_deauth
,
9810 .sta_disassoc
= i802_sta_disassoc
,
9811 .read_sta_data
= driver_nl80211_read_sta_data
,
9812 .set_freq
= i802_set_freq
,
9813 .send_action
= driver_nl80211_send_action
,
9814 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
9815 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
9816 .cancel_remain_on_channel
=
9817 wpa_driver_nl80211_cancel_remain_on_channel
,
9818 .probe_req_report
= driver_nl80211_probe_req_report
,
9819 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
9820 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
9821 .resume
= wpa_driver_nl80211_resume
,
9822 .signal_monitor
= nl80211_signal_monitor
,
9823 .signal_poll
= nl80211_signal_poll
,
9824 .send_frame
= nl80211_send_frame
,
9825 .set_param
= nl80211_set_param
,
9826 .get_radio_name
= nl80211_get_radio_name
,
9827 .add_pmkid
= nl80211_add_pmkid
,
9828 .remove_pmkid
= nl80211_remove_pmkid
,
9829 .flush_pmkid
= nl80211_flush_pmkid
,
9830 .set_rekey_info
= nl80211_set_rekey_info
,
9831 .poll_client
= nl80211_poll_client
,
9832 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
9833 .start_dfs_cac
= nl80211_start_radar_detection
,
9834 .stop_ap
= wpa_driver_nl80211_stop_ap
,
9836 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
9837 .tdls_oper
= nl80211_tdls_oper
,
9838 .tdls_enable_channel_switch
= nl80211_tdls_enable_channel_switch
,
9839 .tdls_disable_channel_switch
= nl80211_tdls_disable_channel_switch
,
9840 #endif /* CONFIG_TDLS */
9841 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,
9842 .get_mac_addr
= wpa_driver_nl80211_get_macaddr
,
9843 .get_survey
= wpa_driver_nl80211_get_survey
,
9844 .status
= wpa_driver_nl80211_status
,
9845 .switch_channel
= nl80211_switch_channel
,
9847 .set_noa
= wpa_driver_set_p2p_noa
,
9848 .get_noa
= wpa_driver_get_p2p_noa
,
9849 .set_ap_wps_ie
= wpa_driver_set_ap_wps_p2p_ie
,
9850 #endif /* ANDROID_P2P */
9852 #ifndef ANDROID_LIB_STUB
9853 .driver_cmd
= wpa_driver_nl80211_driver_cmd
,
9854 #endif /* !ANDROID_LIB_STUB */
9855 #endif /* ANDROID */
9856 .vendor_cmd
= nl80211_vendor_cmd
,
9857 .set_qos_map
= nl80211_set_qos_map
,
9858 .set_wowlan
= nl80211_set_wowlan
,
9859 .set_mac_addr
= nl80211_set_mac_addr
,
9861 .init_mesh
= wpa_driver_nl80211_init_mesh
,
9862 .join_mesh
= wpa_driver_nl80211_join_mesh
,
9863 .leave_mesh
= wpa_driver_nl80211_leave_mesh
,
9864 #endif /* CONFIG_MESH */
9865 .br_add_ip_neigh
= wpa_driver_br_add_ip_neigh
,
9866 .br_delete_ip_neigh
= wpa_driver_br_delete_ip_neigh
,
9867 .br_port_set_attr
= wpa_driver_br_port_set_attr
,
9868 .br_set_net_param
= wpa_driver_br_set_net_param
,
9869 .add_tx_ts
= nl80211_add_ts
,
9870 .del_tx_ts
= nl80211_del_ts
,
9871 .get_ifindex
= nl80211_get_ifindex
,
9872 #ifdef CONFIG_DRIVER_NL80211_QCA
9873 .roaming
= nl80211_roaming
,
9874 .do_acs
= wpa_driver_do_acs
,
9875 .set_band
= nl80211_set_band
,
9876 .get_pref_freq_list
= nl80211_get_pref_freq_list
,
9877 .set_prob_oper_freq
= nl80211_set_prob_oper_freq
,
9878 .p2p_lo_start
= nl80211_p2p_lo_start
,
9879 .p2p_lo_stop
= nl80211_p2p_lo_stop
,
9880 .set_default_scan_ies
= nl80211_set_default_scan_ies
,
9881 .set_tdls_mode
= nl80211_set_tdls_mode
,
9882 #endif /* CONFIG_DRIVER_NL80211_QCA */
9883 .configure_data_frame_filters
= nl80211_configure_data_frame_filters
,
9884 .get_ext_capab
= nl80211_get_ext_capab
,