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
,
184 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
185 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
186 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
188 static int nl80211_set_channel(struct i802_bss
*bss
,
189 struct hostapd_freq_params
*freq
, int set_chan
);
190 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
191 int ifindex
, int disabled
);
193 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
196 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
);
197 static int nl80211_set_param(void *priv
, const char *param
);
200 /* Converts nl80211_chan_width to a common format */
201 enum chan_width
convert2width(int width
)
204 case NL80211_CHAN_WIDTH_20_NOHT
:
205 return CHAN_WIDTH_20_NOHT
;
206 case NL80211_CHAN_WIDTH_20
:
207 return CHAN_WIDTH_20
;
208 case NL80211_CHAN_WIDTH_40
:
209 return CHAN_WIDTH_40
;
210 case NL80211_CHAN_WIDTH_80
:
211 return CHAN_WIDTH_80
;
212 case NL80211_CHAN_WIDTH_80P80
:
213 return CHAN_WIDTH_80P80
;
214 case NL80211_CHAN_WIDTH_160
:
215 return CHAN_WIDTH_160
;
217 return CHAN_WIDTH_UNKNOWN
;
221 int is_ap_interface(enum nl80211_iftype nlmode
)
223 return nlmode
== NL80211_IFTYPE_AP
||
224 nlmode
== NL80211_IFTYPE_P2P_GO
;
228 int is_sta_interface(enum nl80211_iftype nlmode
)
230 return nlmode
== NL80211_IFTYPE_STATION
||
231 nlmode
== NL80211_IFTYPE_P2P_CLIENT
;
235 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
237 return nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
238 nlmode
== NL80211_IFTYPE_P2P_GO
;
242 struct i802_bss
* get_bss_ifindex(struct wpa_driver_nl80211_data
*drv
,
245 struct i802_bss
*bss
;
247 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
248 if (bss
->ifindex
== ifindex
)
256 static int is_mesh_interface(enum nl80211_iftype nlmode
)
258 return nlmode
== NL80211_IFTYPE_MESH_POINT
;
262 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
265 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
267 os_memset(drv
->bssid
, 0, ETH_ALEN
);
272 static int ack_handler(struct nl_msg
*msg
, void *arg
)
279 static int finish_handler(struct nl_msg
*msg
, void *arg
)
286 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
295 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
301 static void nl80211_nlmsg_clear(struct nl_msg
*msg
)
304 * Clear nlmsg data, e.g., to make sure key material is not left in
305 * heap memory for unnecessarily long time.
308 struct nlmsghdr
*hdr
= nlmsg_hdr(msg
);
309 void *data
= nlmsg_data(hdr
);
311 * This would use nlmsg_datalen() or the older nlmsg_len() if
312 * only libnl were to maintain a stable API.. Neither will work
313 * with all released versions, so just calculate the length
316 int len
= hdr
->nlmsg_len
- NLMSG_HDRLEN
;
318 os_memset(data
, 0, len
);
323 static int send_and_recv(struct nl80211_global
*global
,
324 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
325 int (*valid_handler
)(struct nl_msg
*, void *),
334 cb
= nl_cb_clone(global
->nl_cb
);
338 err
= nl_send_auto_complete(nl_handle
, msg
);
344 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
345 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
346 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
349 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
350 valid_handler
, valid_data
);
353 int res
= nl_recvmsgs(nl_handle
, cb
);
356 "nl80211: %s->nl_recvmsgs failed: %d",
362 if (!valid_handler
&& valid_data
== (void *) -1)
363 nl80211_nlmsg_clear(msg
);
369 int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
371 int (*valid_handler
)(struct nl_msg
*, void *),
374 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
375 valid_handler
, valid_data
);
385 static int family_handler(struct nl_msg
*msg
, void *arg
)
387 struct family_data
*res
= arg
;
388 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
389 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
390 struct nlattr
*mcgrp
;
393 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
394 genlmsg_attrlen(gnlh
, 0), NULL
);
395 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
398 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
399 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
400 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
401 nla_len(mcgrp
), NULL
);
402 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
403 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
404 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
406 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
408 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
416 static int nl_get_multicast_id(struct nl80211_global
*global
,
417 const char *family
, const char *group
)
421 struct family_data res
= { group
, -ENOENT
};
426 if (!genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
427 0, 0, CTRL_CMD_GETFAMILY
, 0) ||
428 nla_put_string(msg
, CTRL_ATTR_FAMILY_NAME
, family
)) {
433 ret
= send_and_recv(global
, global
->nl
, msg
, family_handler
, &res
);
440 void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
441 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
443 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
448 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
450 if (bss
->wdev_id_set
)
451 return nla_put_u64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
452 return nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
456 struct nl_msg
* nl80211_cmd_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
464 if (!nl80211_cmd(bss
->drv
, msg
, flags
, cmd
) ||
465 nl80211_set_iface_id(msg
, bss
) < 0) {
474 static struct nl_msg
*
475 nl80211_ifindex_msg(struct wpa_driver_nl80211_data
*drv
, int ifindex
,
476 int flags
, uint8_t cmd
)
484 if (!nl80211_cmd(drv
, msg
, flags
, cmd
) ||
485 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, ifindex
)) {
494 struct nl_msg
* nl80211_drv_msg(struct wpa_driver_nl80211_data
*drv
, int flags
,
497 return nl80211_ifindex_msg(drv
, drv
->ifindex
, flags
, cmd
);
501 struct nl_msg
* nl80211_bss_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
503 return nl80211_ifindex_msg(bss
->drv
, bss
->ifindex
, flags
, cmd
);
507 struct wiphy_idx_data
{
509 enum nl80211_iftype nlmode
;
514 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
516 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
517 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
518 struct wiphy_idx_data
*info
= arg
;
520 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
521 genlmsg_attrlen(gnlh
, 0), NULL
);
523 if (tb
[NL80211_ATTR_WIPHY
])
524 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
526 if (tb
[NL80211_ATTR_IFTYPE
])
527 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
529 if (tb
[NL80211_ATTR_MAC
] && info
->macaddr
)
530 os_memcpy(info
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
537 int nl80211_get_wiphy_index(struct i802_bss
*bss
)
540 struct wiphy_idx_data data
= {
545 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
548 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
549 return data
.wiphy_idx
;
554 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
557 struct wiphy_idx_data data
= {
558 .nlmode
= NL80211_IFTYPE_UNSPECIFIED
,
562 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
563 return NL80211_IFTYPE_UNSPECIFIED
;
565 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
567 return NL80211_IFTYPE_UNSPECIFIED
;
571 static int nl80211_get_macaddr(struct i802_bss
*bss
)
574 struct wiphy_idx_data data
= {
575 .macaddr
= bss
->addr
,
578 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
581 return send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
);
585 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
586 struct nl80211_wiphy_data
*w
)
595 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
) ||
596 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
)) {
601 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
603 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
604 "failed: ret=%d (%s)",
605 ret
, strerror(-ret
));
611 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
613 struct nl80211_wiphy_data
*w
= eloop_ctx
;
616 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
618 res
= nl_recvmsgs(handle
, w
->nl_cb
);
620 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
626 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
628 struct nl80211_wiphy_data
*w
= arg
;
629 struct wpa_driver_nl80211_data
*drv
;
630 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
631 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
632 union wpa_event_data event
;
634 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
635 genlmsg_attrlen(gnlh
, 0), NULL
);
637 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
638 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
643 if (!tb
[NL80211_ATTR_FRAME
])
646 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
648 os_memset(&event
, 0, sizeof(event
));
649 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
650 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
651 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
658 static struct nl80211_wiphy_data
*
659 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
661 static DEFINE_DL_LIST(nl80211_wiphys
);
662 struct nl80211_wiphy_data
*w
;
663 int wiphy_idx
, found
= 0;
664 struct i802_bss
*tmp_bss
;
666 if (bss
->wiphy_data
!= NULL
)
667 return bss
->wiphy_data
;
669 wiphy_idx
= nl80211_get_wiphy_index(bss
);
671 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
672 if (w
->wiphy_idx
== wiphy_idx
)
677 w
= os_zalloc(sizeof(*w
));
680 w
->wiphy_idx
= wiphy_idx
;
681 dl_list_init(&w
->bsss
);
682 dl_list_init(&w
->drvs
);
684 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
689 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
690 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
693 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
695 if (w
->nl_beacons
== NULL
) {
700 if (nl80211_register_beacons(bss
->drv
, w
)) {
701 nl_destroy_handles(&w
->nl_beacons
);
706 nl80211_register_eloop_read(&w
->nl_beacons
, nl80211_recv_beacons
, w
);
708 dl_list_add(&nl80211_wiphys
, &w
->list
);
711 /* drv entry for this bss already there? */
712 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
713 if (tmp_bss
->drv
== bss
->drv
) {
720 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
722 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
728 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
730 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
731 struct i802_bss
*tmp_bss
;
736 bss
->wiphy_data
= NULL
;
737 dl_list_del(&bss
->wiphy_list
);
739 /* still any for this drv present? */
740 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
741 if (tmp_bss
->drv
== bss
->drv
) {
746 /* if not remove it */
748 dl_list_del(&bss
->drv
->wiphy_list
);
750 if (!dl_list_empty(&w
->bsss
))
753 nl80211_destroy_eloop_handle(&w
->nl_beacons
);
756 dl_list_del(&w
->list
);
761 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
763 struct i802_bss
*bss
= priv
;
764 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
765 if (!drv
->associated
)
767 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
772 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
774 struct i802_bss
*bss
= priv
;
775 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
776 if (!drv
->associated
)
778 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
779 return drv
->ssid_len
;
783 static void wpa_driver_nl80211_event_newlink(
784 struct wpa_driver_nl80211_data
*drv
, const char *ifname
)
786 union wpa_event_data event
;
788 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
789 if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
790 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
791 drv
->first_bss
->ifname
);
794 if (!drv
->if_removed
)
796 wpa_printf(MSG_DEBUG
, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
797 drv
->first_bss
->ifname
);
801 os_memset(&event
, 0, sizeof(event
));
802 os_strlcpy(event
.interface_status
.ifname
, ifname
,
803 sizeof(event
.interface_status
.ifname
));
804 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
805 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
809 static void wpa_driver_nl80211_event_dellink(
810 struct wpa_driver_nl80211_data
*drv
, const char *ifname
)
812 union wpa_event_data event
;
814 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
815 if (drv
->if_removed
) {
816 wpa_printf(MSG_DEBUG
, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
820 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
824 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed",
828 os_memset(&event
, 0, sizeof(event
));
829 os_strlcpy(event
.interface_status
.ifname
, ifname
,
830 sizeof(event
.interface_status
.ifname
));
831 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
832 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
836 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
839 int attrlen
, rta_len
;
843 attr
= (struct rtattr
*) buf
;
845 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
846 while (RTA_OK(attr
, attrlen
)) {
847 if (attr
->rta_type
== IFLA_IFNAME
) {
848 if (os_strcmp(((char *) attr
) + rta_len
,
849 drv
->first_bss
->ifname
) == 0)
854 attr
= RTA_NEXT(attr
, attrlen
);
861 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
862 int ifindex
, u8
*buf
, size_t len
)
864 if (drv
->ifindex
== ifindex
)
867 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
868 nl80211_check_global(drv
->global
);
869 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
871 wpa_driver_nl80211_finish_drv_init(drv
, NULL
, 0, NULL
);
879 static struct wpa_driver_nl80211_data
*
880 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
882 struct wpa_driver_nl80211_data
*drv
;
883 dl_list_for_each(drv
, &global
->interfaces
,
884 struct wpa_driver_nl80211_data
, list
) {
885 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
886 have_ifidx(drv
, idx
))
893 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
894 struct ifinfomsg
*ifi
,
897 struct nl80211_global
*global
= ctx
;
898 struct wpa_driver_nl80211_data
*drv
;
902 char namebuf
[IFNAMSIZ
];
903 char ifname
[IFNAMSIZ
+ 1];
904 char extra
[100], *pos
, *end
;
906 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
908 wpa_printf(MSG_DEBUG
, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d",
915 end
= pos
+ sizeof(extra
);
919 attr
= (struct rtattr
*) buf
;
920 while (RTA_OK(attr
, attrlen
)) {
921 switch (attr
->rta_type
) {
923 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
925 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
926 ifname
[RTA_PAYLOAD(attr
)] = '\0';
929 brid
= nla_get_u32((struct nlattr
*) attr
);
930 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
933 pos
+= os_snprintf(pos
, end
- pos
, " wext");
936 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
937 nla_get_u32((struct nlattr
*) attr
));
940 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
941 nla_get_u32((struct nlattr
*) attr
));
944 attr
= RTA_NEXT(attr
, attrlen
);
946 extra
[sizeof(extra
) - 1] = '\0';
948 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
949 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
951 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
952 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
953 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
954 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
956 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
958 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
959 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) > 0) {
960 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
961 "event since interface %s is up", namebuf
);
962 drv
->ignore_if_down_event
= 0;
965 wpa_printf(MSG_DEBUG
, "nl80211: Interface down (%s/%s)",
967 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) != 0) {
968 wpa_printf(MSG_DEBUG
,
969 "nl80211: Not the main interface (%s) - do not indicate interface down",
970 drv
->first_bss
->ifname
);
971 } else if (drv
->ignore_if_down_event
) {
972 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
973 "event generated by mode change");
974 drv
->ignore_if_down_event
= 0;
976 drv
->if_disabled
= 1;
977 wpa_supplicant_event(drv
->ctx
,
978 EVENT_INTERFACE_DISABLED
, NULL
);
981 * Try to get drv again, since it may be removed as
982 * part of the EVENT_INTERFACE_DISABLED handling for
985 drv
= nl80211_find_drv(global
, ifi
->ifi_index
,
992 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
993 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
994 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) == 0) {
995 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
996 "event since interface %s is down",
998 } else if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
999 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1000 "event since interface %s does not exist",
1001 drv
->first_bss
->ifname
);
1002 } else if (drv
->if_removed
) {
1003 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1004 "event since interface %s is marked "
1005 "removed", drv
->first_bss
->ifname
);
1007 struct i802_bss
*bss
;
1010 /* Re-read MAC address as it may have changed */
1011 bss
= get_bss_ifindex(drv
, ifi
->ifi_index
);
1013 linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
1014 bss
->ifname
, addr
) < 0) {
1015 wpa_printf(MSG_DEBUG
,
1016 "nl80211: %s: failed to re-read MAC address",
1019 os_memcmp(addr
, bss
->addr
, ETH_ALEN
) != 0) {
1020 wpa_printf(MSG_DEBUG
,
1021 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1022 MACSTR
" to " MACSTR
,
1023 ifi
->ifi_index
, bss
->ifname
,
1026 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
1029 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
1030 drv
->if_disabled
= 0;
1031 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1037 * Some drivers send the association event before the operup event--in
1038 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1039 * fails. This will hit us when wpa_supplicant does not need to do
1040 * IEEE 802.1X authentication
1042 if (drv
->operstate
== 1 &&
1043 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1044 !(ifi
->ifi_flags
& IFF_RUNNING
)) {
1045 wpa_printf(MSG_DEBUG
, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
1046 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1051 wpa_driver_nl80211_event_newlink(drv
, ifname
);
1053 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1054 struct i802_bss
*bss
;
1056 /* device has been added to bridge */
1057 if (!if_indextoname(brid
, namebuf
)) {
1058 wpa_printf(MSG_DEBUG
,
1059 "nl80211: Could not find bridge ifname for ifindex %u",
1063 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1065 add_ifidx(drv
, brid
);
1067 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
1068 if (os_strcmp(ifname
, bss
->ifname
) == 0) {
1069 os_strlcpy(bss
->brname
, namebuf
, IFNAMSIZ
);
1077 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1078 struct ifinfomsg
*ifi
,
1079 u8
*buf
, size_t len
)
1081 struct nl80211_global
*global
= ctx
;
1082 struct wpa_driver_nl80211_data
*drv
;
1084 struct rtattr
*attr
;
1086 char ifname
[IFNAMSIZ
+ 1];
1087 char extra
[100], *pos
, *end
;
1089 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1091 wpa_printf(MSG_DEBUG
, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d",
1098 end
= pos
+ sizeof(extra
);
1102 attr
= (struct rtattr
*) buf
;
1103 while (RTA_OK(attr
, attrlen
)) {
1104 switch (attr
->rta_type
) {
1106 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
1108 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
1109 ifname
[RTA_PAYLOAD(attr
)] = '\0';
1112 brid
= nla_get_u32((struct nlattr
*) attr
);
1113 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
1115 case IFLA_OPERSTATE
:
1116 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
1117 nla_get_u32((struct nlattr
*) attr
));
1120 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
1121 nla_get_u32((struct nlattr
*) attr
));
1124 attr
= RTA_NEXT(attr
, attrlen
);
1126 extra
[sizeof(extra
) - 1] = '\0';
1128 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1129 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
1131 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1132 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1133 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1134 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1136 if (ifname
[0] && (ifi
->ifi_family
!= AF_BRIDGE
|| !brid
))
1137 wpa_driver_nl80211_event_dellink(drv
, ifname
);
1139 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1140 /* device has been removed from bridge */
1141 char namebuf
[IFNAMSIZ
];
1143 if (!if_indextoname(brid
, namebuf
)) {
1144 wpa_printf(MSG_DEBUG
,
1145 "nl80211: Could not find bridge ifname for ifindex %u",
1148 wpa_printf(MSG_DEBUG
,
1149 "nl80211: Remove ifindex %u for bridge %s",
1152 del_ifidx(drv
, brid
);
1157 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1161 struct nl80211_bss_info_arg arg
;
1163 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1164 os_memset(&arg
, 0, sizeof(arg
));
1166 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1168 unsigned int freq
= drv
->nlmode
== NL80211_IFTYPE_ADHOC
?
1169 arg
.ibss_freq
: arg
.assoc_freq
;
1170 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1171 "associated BSS from scan results: %u MHz", freq
);
1173 drv
->assoc_freq
= freq
;
1174 return drv
->assoc_freq
;
1176 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1177 "(%s)", ret
, strerror(-ret
));
1178 return drv
->assoc_freq
;
1182 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1184 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1185 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1186 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1187 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1188 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1189 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
1190 [NL80211_STA_INFO_BEACON_SIGNAL_AVG
] = { .type
= NLA_U8
},
1192 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1193 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1194 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1195 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1196 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1197 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1199 struct wpa_signal_info
*sig_change
= arg
;
1201 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1202 genlmsg_attrlen(gnlh
, 0), NULL
);
1203 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1204 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1205 tb
[NL80211_ATTR_STA_INFO
], policy
))
1207 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1210 sig_change
->current_signal
=
1211 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1213 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
1214 sig_change
->avg_signal
=
1215 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
1217 sig_change
->avg_signal
= 0;
1219 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
1220 sig_change
->avg_beacon_signal
=
1222 nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]);
1224 sig_change
->avg_beacon_signal
= 0;
1226 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1227 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1228 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1230 sig_change
->current_txrate
= 0;
1232 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1233 sig_change
->current_txrate
=
1235 NL80211_RATE_INFO_BITRATE
]) * 100;
1244 int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1245 struct wpa_signal_info
*sig
)
1249 sig
->current_signal
= -9999;
1250 sig
->current_txrate
= 0;
1252 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_STATION
)) ||
1253 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
)) {
1258 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1262 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1264 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1265 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1266 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1267 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1268 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1269 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1271 struct wpa_signal_info
*sig_change
= arg
;
1273 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1274 genlmsg_attrlen(gnlh
, 0), NULL
);
1276 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1277 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1281 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1282 tb
[NL80211_ATTR_SURVEY_INFO
],
1284 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1289 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1292 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1293 sig_change
->frequency
)
1296 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1299 sig_change
->current_noise
=
1300 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1306 int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1307 struct wpa_signal_info
*sig_change
)
1311 sig_change
->current_noise
= 9999;
1312 sig_change
->frequency
= drv
->assoc_freq
;
1314 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1315 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1319 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
1322 struct nl_cb
*cb
= eloop_ctx
;
1325 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
1327 res
= nl_recvmsgs(handle
, cb
);
1329 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
1336 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1337 * @priv: driver_nl80211 private data
1338 * @alpha2_arg: country to which to switch to
1339 * Returns: 0 on success, -1 on failure
1341 * This asks nl80211 to set the regulatory domain for given
1342 * country ISO / IEC alpha2.
1344 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
1346 struct i802_bss
*bss
= priv
;
1347 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1351 msg
= nlmsg_alloc();
1355 alpha2
[0] = alpha2_arg
[0];
1356 alpha2
[1] = alpha2_arg
[1];
1359 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
) ||
1360 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
)) {
1364 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
1370 static int nl80211_get_country(struct nl_msg
*msg
, void *arg
)
1373 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
1374 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1376 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1377 genlmsg_attrlen(gnlh
, 0), NULL
);
1378 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
]) {
1379 wpa_printf(MSG_DEBUG
, "nl80211: No country information available");
1382 os_strlcpy(alpha2
, nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]), 3);
1387 static int wpa_driver_nl80211_get_country(void *priv
, char *alpha2
)
1389 struct i802_bss
*bss
= priv
;
1390 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1394 msg
= nlmsg_alloc();
1398 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
1400 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_country
, alpha2
);
1408 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
1412 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1413 if (global
->nl_cb
== NULL
) {
1414 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
1419 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
1420 if (global
->nl
== NULL
)
1423 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
1424 if (global
->nl80211_id
< 0) {
1425 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
1430 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
1431 if (global
->nl_event
== NULL
)
1434 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
1436 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1438 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1439 "membership for scan events: %d (%s)",
1440 ret
, strerror(-ret
));
1444 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
1446 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1448 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1449 "membership for mlme events: %d (%s)",
1450 ret
, strerror(-ret
));
1454 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
1456 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1458 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1459 "membership for regulatory events: %d (%s)",
1460 ret
, strerror(-ret
));
1461 /* Continue without regulatory events */
1464 ret
= nl_get_multicast_id(global
, "nl80211", "vendor");
1466 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1468 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1469 "membership for vendor events: %d (%s)",
1470 ret
, strerror(-ret
));
1471 /* Continue without vendor events */
1474 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1475 no_seq_check
, NULL
);
1476 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1477 process_global_event
, global
);
1479 nl80211_register_eloop_read(&global
->nl_event
,
1480 wpa_driver_nl80211_event_receive
,
1486 nl_destroy_handles(&global
->nl_event
);
1487 nl_destroy_handles(&global
->nl
);
1488 nl_cb_put(global
->nl_cb
);
1489 global
->nl_cb
= NULL
;
1494 static void nl80211_check_global(struct nl80211_global
*global
)
1496 struct nl_handle
*handle
;
1497 const char *groups
[] = { "scan", "mlme", "regulatory", "vendor", NULL
};
1502 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1503 * and all registration having been cleared.
1505 handle
= (void *) (((intptr_t) global
->nl_event
) ^
1506 ELOOP_SOCKET_INVALID
);
1508 for (i
= 0; groups
[i
]; i
++) {
1509 ret
= nl_get_multicast_id(global
, "nl80211", groups
[i
]);
1511 ret
= nl_socket_add_membership(handle
, ret
);
1513 wpa_printf(MSG_INFO
,
1514 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1515 groups
[i
], ret
, strerror(-ret
));
1521 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
1523 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
1525 * This may be for any interface; use ifdown event to disable
1531 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
1533 struct wpa_driver_nl80211_data
*drv
= ctx
;
1534 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
1535 if (i802_set_iface_flags(drv
->first_bss
, 1)) {
1536 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
1537 "after rfkill unblock");
1541 if (is_p2p_net_interface(drv
->nlmode
))
1542 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
1544 /* rtnetlink ifup handler will report interface as enabled */
1548 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
1552 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
1557 struct cmsghdr
*cmsg
;
1558 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
1559 union wpa_event_data event
;
1561 memset(&msg
, 0, sizeof(msg
));
1562 msg
.msg_iov
= &entry
;
1564 entry
.iov_base
= data
;
1565 entry
.iov_len
= sizeof(data
);
1566 msg
.msg_control
= &control
;
1567 msg
.msg_controllen
= sizeof(control
);
1569 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
1570 /* if error or not fitting 802.3 header, return */
1574 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
1576 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
1577 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
1581 ack
= (void *)CMSG_DATA(cmsg
);
1585 if (cmsg
->cmsg_level
== SOL_PACKET
&&
1586 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
1587 struct sock_extended_err
*err
=
1588 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
1590 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
1595 if (!found_ee
|| !found_wifi
)
1598 memset(&event
, 0, sizeof(event
));
1599 event
.eapol_tx_status
.dst
= data
;
1600 event
.eapol_tx_status
.data
= data
+ 14;
1601 event
.eapol_tx_status
.data_len
= res
- 14;
1602 event
.eapol_tx_status
.ack
= acked
;
1603 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
1607 static int nl80211_init_bss(struct i802_bss
*bss
)
1609 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1613 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1614 no_seq_check
, NULL
);
1615 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1616 process_bss_event
, bss
);
1622 static void nl80211_destroy_bss(struct i802_bss
*bss
)
1624 nl_cb_put(bss
->nl_cb
);
1629 static void * wpa_driver_nl80211_drv_init(void *ctx
, const char *ifname
,
1630 void *global_priv
, int hostapd
,
1632 const char *driver_params
)
1634 struct wpa_driver_nl80211_data
*drv
;
1635 struct rfkill_config
*rcfg
;
1636 struct i802_bss
*bss
;
1638 if (global_priv
== NULL
)
1640 drv
= os_zalloc(sizeof(*drv
));
1643 drv
->global
= global_priv
;
1645 drv
->hostapd
= !!hostapd
;
1646 drv
->eapol_sock
= -1;
1649 * There is no driver capability flag for this, so assume it is
1650 * supported and disable this on first attempt to use if the driver
1651 * rejects the command due to missing support.
1653 drv
->set_rekey_offload
= 1;
1655 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
1656 drv
->if_indices
= drv
->default_if_indices
;
1658 drv
->first_bss
= os_zalloc(sizeof(*drv
->first_bss
));
1659 if (!drv
->first_bss
) {
1663 bss
= drv
->first_bss
;
1667 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
1668 drv
->monitor_ifidx
= -1;
1669 drv
->monitor_sock
= -1;
1670 drv
->eapol_tx_sock
= -1;
1671 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
1673 if (nl80211_init_bss(bss
))
1676 rcfg
= os_zalloc(sizeof(*rcfg
));
1680 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
1681 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
1682 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
1683 drv
->rfkill
= rfkill_init(rcfg
);
1684 if (drv
->rfkill
== NULL
) {
1685 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
1689 if (linux_iface_up(drv
->global
->ioctl_sock
, ifname
) > 0)
1690 drv
->start_iface_up
= 1;
1692 if (wpa_driver_nl80211_finish_drv_init(drv
, set_addr
, 1, driver_params
))
1695 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
1696 if (drv
->eapol_tx_sock
< 0)
1699 if (drv
->data_tx_status
) {
1702 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
1703 &enabled
, sizeof(enabled
)) < 0) {
1704 wpa_printf(MSG_DEBUG
,
1705 "nl80211: wifi status sockopt failed\n");
1706 drv
->data_tx_status
= 0;
1707 if (!drv
->use_monitor
)
1709 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
1711 eloop_register_read_sock(drv
->eapol_tx_sock
,
1712 wpa_driver_nl80211_handle_eapol_tx_status
,
1718 nl80211_check_global(drv
->global
);
1719 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
1720 drv
->in_interface_list
= 1;
1726 wpa_driver_nl80211_deinit(bss
);
1732 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1733 * @ctx: context to be used when calling wpa_supplicant functions,
1734 * e.g., wpa_supplicant_event()
1735 * @ifname: interface name, e.g., wlan0
1736 * @global_priv: private driver global data from global_init()
1737 * Returns: Pointer to private data, %NULL on failure
1739 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
1742 return wpa_driver_nl80211_drv_init(ctx
, ifname
, global_priv
, 0, NULL
,
1747 static int nl80211_register_frame(struct i802_bss
*bss
,
1748 struct nl_handle
*nl_handle
,
1749 u16 type
, const u8
*match
, size_t match_len
)
1751 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1757 wpa_snprintf_hex(buf
, sizeof(buf
), match
, match_len
);
1758 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1759 type
, fc2str(type
), nl_handle
, buf
);
1761 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REGISTER_ACTION
)) ||
1762 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
, type
) ||
1763 nla_put(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
)) {
1768 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
1770 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
1771 "failed (type=%u): ret=%d (%s)",
1772 type
, ret
, strerror(-ret
));
1773 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
1780 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
1783 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
1784 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
1788 bss
->nl_mgmt
= nl_create_handle(bss
->nl_cb
, "mgmt");
1789 if (bss
->nl_mgmt
== NULL
)
1796 static void nl80211_mgmt_handle_register_eloop(struct i802_bss
*bss
)
1798 nl80211_register_eloop_read(&bss
->nl_mgmt
,
1799 wpa_driver_nl80211_event_receive
,
1804 static int nl80211_register_action_frame(struct i802_bss
*bss
,
1805 const u8
*match
, size_t match_len
)
1807 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
1808 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
1809 type
, match
, match_len
);
1813 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
1815 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1818 if (nl80211_alloc_mgmt_handle(bss
))
1820 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
1821 "handle %p", bss
->nl_mgmt
);
1823 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
1824 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
1826 /* register for any AUTH message */
1827 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0);
1830 #ifdef CONFIG_INTERWORKING
1831 /* QoS Map Configure */
1832 if (nl80211_register_action_frame(bss
, (u8
*) "\x01\x04", 2) < 0)
1834 #endif /* CONFIG_INTERWORKING */
1835 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
1836 /* GAS Initial Request */
1837 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
1839 /* GAS Initial Response */
1840 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
1842 /* GAS Comeback Request */
1843 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
1845 /* GAS Comeback Response */
1846 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
1848 /* Protected GAS Initial Request */
1849 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0a", 2) < 0)
1851 /* Protected GAS Initial Response */
1852 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0b", 2) < 0)
1854 /* Protected GAS Comeback Request */
1855 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0c", 2) < 0)
1857 /* Protected GAS Comeback Response */
1858 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0d", 2) < 0)
1860 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
1862 /* P2P Public Action */
1863 if (nl80211_register_action_frame(bss
,
1864 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
1868 if (nl80211_register_action_frame(bss
,
1869 (u8
*) "\x7f\x50\x6f\x9a\x09",
1872 #endif /* CONFIG_P2P */
1873 #ifdef CONFIG_IEEE80211W
1874 /* SA Query Response */
1875 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
1877 #endif /* CONFIG_IEEE80211W */
1879 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
1880 /* TDLS Discovery Response */
1881 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
1885 #endif /* CONFIG_TDLS */
1887 /* FST Action frames */
1888 if (nl80211_register_action_frame(bss
, (u8
*) "\x12", 1) < 0)
1890 #endif /* CONFIG_FST */
1892 /* FT Action frames */
1893 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
1896 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
1897 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
1899 /* WNM - BSS Transition Management Request */
1900 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
1902 /* WNM-Sleep Mode Response */
1903 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
1907 /* WNM-Notification */
1908 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x1a", 2) < 0)
1910 #endif /* CONFIG_HS20 */
1912 /* WMM-AC ADDTS Response */
1913 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x01", 2) < 0)
1917 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x02", 2) < 0)
1920 /* Radio Measurement - Neighbor Report Response */
1921 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x05", 2) < 0)
1924 /* Radio Measurement - Link Measurement Request */
1925 if ((drv
->capa
.rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
) &&
1926 (nl80211_register_action_frame(bss
, (u8
*) "\x05\x02", 2) < 0))
1929 nl80211_mgmt_handle_register_eloop(bss
);
1935 static int nl80211_mgmt_subscribe_mesh(struct i802_bss
*bss
)
1939 if (nl80211_alloc_mgmt_handle(bss
))
1942 wpa_printf(MSG_DEBUG
,
1943 "nl80211: Subscribe to mgmt frames with mesh handle %p",
1946 /* Auth frames for mesh SAE */
1947 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
1948 (WLAN_FC_TYPE_MGMT
<< 2) |
1949 (WLAN_FC_STYPE_AUTH
<< 4),
1953 /* Mesh peering open */
1954 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x01", 2) < 0)
1956 /* Mesh peering confirm */
1957 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x02", 2) < 0)
1959 /* Mesh peering close */
1960 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x03", 2) < 0)
1963 nl80211_mgmt_handle_register_eloop(bss
);
1969 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
1974 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
1975 ret
= send_and_recv(bss
->drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
1977 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
1978 "failed: ret=%d (%s)",
1979 ret
, strerror(-ret
));
1985 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
1987 static const int stypes
[] = {
1989 WLAN_FC_STYPE_ASSOC_REQ
,
1990 WLAN_FC_STYPE_REASSOC_REQ
,
1991 WLAN_FC_STYPE_DISASSOC
,
1992 WLAN_FC_STYPE_DEAUTH
,
1993 WLAN_FC_STYPE_ACTION
,
1994 WLAN_FC_STYPE_PROBE_REQ
,
1995 /* Beacon doesn't work as mac80211 doesn't currently allow
1996 * it, but it wouldn't really be the right thing anyway as
1997 * it isn't per interface ... maybe just dump the scan
1998 * results periodically for OLBC?
2000 /* WLAN_FC_STYPE_BEACON, */
2004 if (nl80211_alloc_mgmt_handle(bss
))
2006 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2007 "handle %p", bss
->nl_mgmt
);
2009 for (i
= 0; i
< ARRAY_SIZE(stypes
); i
++) {
2010 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2011 (WLAN_FC_TYPE_MGMT
<< 2) |
2018 if (nl80211_register_spurious_class3(bss
))
2021 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
2024 nl80211_mgmt_handle_register_eloop(bss
);
2028 nl_destroy_handles(&bss
->nl_mgmt
);
2033 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
2035 if (nl80211_alloc_mgmt_handle(bss
))
2037 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2038 "handle %p (device SME)", bss
->nl_mgmt
);
2040 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2041 (WLAN_FC_TYPE_MGMT
<< 2) |
2042 (WLAN_FC_STYPE_ACTION
<< 4),
2046 nl80211_mgmt_handle_register_eloop(bss
);
2050 nl_destroy_handles(&bss
->nl_mgmt
);
2055 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
2057 if (bss
->nl_mgmt
== NULL
)
2059 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
2060 "(%s)", bss
->nl_mgmt
, reason
);
2061 nl80211_destroy_eloop_handle(&bss
->nl_mgmt
);
2063 nl80211_put_wiphy_data_ap(bss
);
2067 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
2069 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
2073 static void nl80211_del_p2pdev(struct i802_bss
*bss
)
2078 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_INTERFACE
);
2079 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2081 wpa_printf(MSG_DEBUG
, "nl80211: Delete P2P Device %s (0x%llx): %s",
2082 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2087 static int nl80211_set_p2pdev(struct i802_bss
*bss
, int start
)
2092 msg
= nl80211_cmd_msg(bss
, 0, start
? NL80211_CMD_START_P2P_DEVICE
:
2093 NL80211_CMD_STOP_P2P_DEVICE
);
2094 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2096 wpa_printf(MSG_DEBUG
, "nl80211: %s P2P Device %s (0x%llx): %s",
2097 start
? "Start" : "Stop",
2098 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2104 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
)
2106 enum nl80211_iftype nlmode
;
2108 nlmode
= nl80211_get_ifmode(bss
);
2109 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2110 return linux_set_iface_flags(bss
->drv
->global
->ioctl_sock
,
2114 /* P2P Device has start/stop which is equivalent */
2115 return nl80211_set_p2pdev(bss
, up
);
2119 #ifdef CONFIG_TESTING_OPTIONS
2120 static int qca_vendor_test_cmd_handler(struct nl_msg
*msg
, void *arg
)
2122 /* struct wpa_driver_nl80211_data *drv = arg; */
2123 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2124 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2127 wpa_printf(MSG_DEBUG
,
2128 "nl80211: QCA vendor test command response received");
2130 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2131 genlmsg_attrlen(gnlh
, 0), NULL
);
2132 if (!tb
[NL80211_ATTR_VENDOR_DATA
]) {
2133 wpa_printf(MSG_DEBUG
, "nl80211: No vendor data attribute");
2137 wpa_hexdump(MSG_DEBUG
,
2138 "nl80211: Received QCA vendor test command response",
2139 nla_data(tb
[NL80211_ATTR_VENDOR_DATA
]),
2140 nla_len(tb
[NL80211_ATTR_VENDOR_DATA
]));
2144 #endif /* CONFIG_TESTING_OPTIONS */
2147 static void qca_vendor_test(struct wpa_driver_nl80211_data
*drv
)
2149 #ifdef CONFIG_TESTING_OPTIONS
2151 struct nlattr
*params
;
2154 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2155 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2156 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2157 QCA_NL80211_VENDOR_SUBCMD_TEST
) ||
2158 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
2159 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_TEST
, 123)) {
2163 nla_nest_end(msg
, params
);
2165 ret
= send_and_recv_msgs(drv
, msg
, qca_vendor_test_cmd_handler
, drv
);
2166 wpa_printf(MSG_DEBUG
,
2167 "nl80211: QCA vendor test command returned %d (%s)",
2168 ret
, strerror(-ret
));
2169 #endif /* CONFIG_TESTING_OPTIONS */
2174 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
2175 const u8
*set_addr
, int first
,
2176 const char *driver_params
)
2178 struct i802_bss
*bss
= drv
->first_bss
;
2179 int send_rfkill_event
= 0;
2180 enum nl80211_iftype nlmode
;
2182 drv
->ifindex
= if_nametoindex(bss
->ifname
);
2183 bss
->ifindex
= drv
->ifindex
;
2184 bss
->wdev_id
= drv
->global
->if_add_wdevid
;
2185 bss
->wdev_id_set
= drv
->global
->if_add_wdevid_set
;
2187 bss
->if_dynamic
= drv
->ifindex
== drv
->global
->if_add_ifindex
;
2188 bss
->if_dynamic
= bss
->if_dynamic
|| drv
->global
->if_add_wdevid_set
;
2189 drv
->global
->if_add_wdevid_set
= 0;
2191 if (!bss
->if_dynamic
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2194 if (wpa_driver_nl80211_capa(drv
))
2197 if (driver_params
&& nl80211_set_param(bss
, driver_params
) < 0)
2200 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2201 bss
->ifname
, drv
->phyname
);
2204 (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) ||
2205 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2209 if (first
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2210 drv
->start_mode_ap
= 1;
2212 if (drv
->hostapd
|| bss
->static_ap
)
2213 nlmode
= NL80211_IFTYPE_AP
;
2214 else if (bss
->if_dynamic
)
2215 nlmode
= nl80211_get_ifmode(bss
);
2217 nlmode
= NL80211_IFTYPE_STATION
;
2219 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
2220 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver mode");
2224 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2225 nl80211_get_macaddr(bss
);
2227 if (!rfkill_is_blocked(drv
->rfkill
)) {
2228 int ret
= i802_set_iface_flags(bss
, 1);
2230 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
2231 "interface '%s' UP", bss
->ifname
);
2235 if (is_p2p_net_interface(nlmode
))
2236 nl80211_disable_11b_rates(bss
->drv
,
2237 bss
->drv
->ifindex
, 1);
2239 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2242 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
2243 "interface '%s' due to rfkill", bss
->ifname
);
2244 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2246 drv
->if_disabled
= 1;
2247 send_rfkill_event
= 1;
2251 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
2252 1, IF_OPER_DORMANT
);
2254 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2257 os_memcpy(drv
->perm_addr
, bss
->addr
, ETH_ALEN
);
2259 if (send_rfkill_event
) {
2260 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
2264 if (drv
->vendor_cmd_test_avail
)
2265 qca_vendor_test(drv
);
2271 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
2275 wpa_printf(MSG_DEBUG
, "nl80211: Remove beacon (ifindex=%d)",
2277 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_DEL_BEACON
);
2278 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2283 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2284 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2286 * Shut down driver interface and processing of driver events. Free
2287 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2289 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
2291 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2293 wpa_printf(MSG_INFO
, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2294 bss
->ifname
, drv
->disabled_11b_rates
);
2297 if (drv
->data_tx_status
)
2298 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
2299 if (drv
->eapol_tx_sock
>= 0)
2300 close(drv
->eapol_tx_sock
);
2303 wpa_driver_nl80211_probe_req_report(bss
, 0);
2304 if (bss
->added_if_into_bridge
) {
2305 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
2307 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2308 "interface %s from bridge %s: %s",
2309 bss
->ifname
, bss
->brname
, strerror(errno
));
2311 nl80211_handle_destroy(drv
->rtnl_sk
);
2313 if (bss
->added_bridge
) {
2314 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->brname
,
2316 wpa_printf(MSG_INFO
,
2317 "nl80211: Could not set bridge %s down",
2319 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
2320 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2322 bss
->brname
, strerror(errno
));
2325 nl80211_remove_monitor_interface(drv
);
2327 if (is_ap_interface(drv
->nlmode
))
2328 wpa_driver_nl80211_del_beacon(drv
);
2330 if (drv
->eapol_sock
>= 0) {
2331 eloop_unregister_read_sock(drv
->eapol_sock
);
2332 close(drv
->eapol_sock
);
2335 if (drv
->if_indices
!= drv
->default_if_indices
)
2336 os_free(drv
->if_indices
);
2338 if (drv
->disabled_11b_rates
)
2339 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2341 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
2343 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill
, drv
, drv
->ctx
);
2344 rfkill_deinit(drv
->rfkill
);
2346 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2348 if (!drv
->start_iface_up
)
2349 (void) i802_set_iface_flags(bss
, 0);
2351 if (drv
->addr_changed
) {
2352 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
2354 wpa_printf(MSG_DEBUG
,
2355 "nl80211: Could not set interface down to restore permanent MAC address");
2357 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2358 drv
->perm_addr
) < 0) {
2359 wpa_printf(MSG_DEBUG
,
2360 "nl80211: Could not restore permanent MAC address");
2364 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2365 if (!drv
->hostapd
|| !drv
->start_mode_ap
)
2366 wpa_driver_nl80211_set_mode(bss
,
2367 NL80211_IFTYPE_STATION
);
2368 nl80211_mgmt_unsubscribe(bss
, "deinit");
2370 nl80211_mgmt_unsubscribe(bss
, "deinit");
2371 nl80211_del_p2pdev(bss
);
2374 nl80211_destroy_bss(drv
->first_bss
);
2376 os_free(drv
->filter_ssids
);
2378 os_free(drv
->auth_ie
);
2380 if (drv
->in_interface_list
)
2381 dl_list_del(&drv
->list
);
2383 os_free(drv
->extended_capa
);
2384 os_free(drv
->extended_capa_mask
);
2385 os_free(drv
->first_bss
);
2390 static u32
wpa_alg_to_cipher_suite(enum wpa_alg alg
, size_t key_len
)
2395 return WLAN_CIPHER_SUITE_WEP40
;
2396 return WLAN_CIPHER_SUITE_WEP104
;
2398 return WLAN_CIPHER_SUITE_TKIP
;
2400 return WLAN_CIPHER_SUITE_CCMP
;
2402 return WLAN_CIPHER_SUITE_GCMP
;
2403 case WPA_ALG_CCMP_256
:
2404 return WLAN_CIPHER_SUITE_CCMP_256
;
2405 case WPA_ALG_GCMP_256
:
2406 return WLAN_CIPHER_SUITE_GCMP_256
;
2408 return WLAN_CIPHER_SUITE_AES_CMAC
;
2409 case WPA_ALG_BIP_GMAC_128
:
2410 return WLAN_CIPHER_SUITE_BIP_GMAC_128
;
2411 case WPA_ALG_BIP_GMAC_256
:
2412 return WLAN_CIPHER_SUITE_BIP_GMAC_256
;
2413 case WPA_ALG_BIP_CMAC_256
:
2414 return WLAN_CIPHER_SUITE_BIP_CMAC_256
;
2416 return WLAN_CIPHER_SUITE_SMS4
;
2418 return WLAN_CIPHER_SUITE_KRK
;
2421 wpa_printf(MSG_ERROR
, "nl80211: Unexpected encryption algorithm %d",
2426 wpa_printf(MSG_ERROR
, "nl80211: Unsupported encryption algorithm %d",
2432 static u32
wpa_cipher_to_cipher_suite(unsigned int cipher
)
2435 case WPA_CIPHER_CCMP_256
:
2436 return WLAN_CIPHER_SUITE_CCMP_256
;
2437 case WPA_CIPHER_GCMP_256
:
2438 return WLAN_CIPHER_SUITE_GCMP_256
;
2439 case WPA_CIPHER_CCMP
:
2440 return WLAN_CIPHER_SUITE_CCMP
;
2441 case WPA_CIPHER_GCMP
:
2442 return WLAN_CIPHER_SUITE_GCMP
;
2443 case WPA_CIPHER_TKIP
:
2444 return WLAN_CIPHER_SUITE_TKIP
;
2445 case WPA_CIPHER_WEP104
:
2446 return WLAN_CIPHER_SUITE_WEP104
;
2447 case WPA_CIPHER_WEP40
:
2448 return WLAN_CIPHER_SUITE_WEP40
;
2449 case WPA_CIPHER_GTK_NOT_USED
:
2450 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR
;
2457 static int wpa_cipher_to_cipher_suites(unsigned int ciphers
, u32 suites
[],
2462 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP_256
)
2463 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP_256
;
2464 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP_256
)
2465 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP_256
;
2466 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP
)
2467 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
2468 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP
)
2469 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP
;
2470 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_TKIP
)
2471 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
2472 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP104
)
2473 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
2474 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP40
)
2475 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
2481 #ifdef CONFIG_DRIVER_NL80211_QCA
2482 static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data
*drv
,
2483 const u8
*key
, size_t key_len
)
2488 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
))
2491 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2492 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2493 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2494 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY
) ||
2495 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, key_len
, key
)) {
2496 nl80211_nlmsg_clear(msg
);
2500 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
2502 wpa_printf(MSG_DEBUG
,
2503 "nl80211: Key management set key failed: ret=%d (%s)",
2504 ret
, strerror(-ret
));
2509 #endif /* CONFIG_DRIVER_NL80211_QCA */
2512 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
2513 enum wpa_alg alg
, const u8
*addr
,
2514 int key_idx
, int set_tx
,
2515 const u8
*seq
, size_t seq_len
,
2516 const u8
*key
, size_t key_len
)
2518 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2520 struct nl_msg
*msg
= NULL
;
2524 /* Ignore for P2P Device */
2525 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2528 ifindex
= if_nametoindex(ifname
);
2529 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
2530 "set_tx=%d seq_len=%lu key_len=%lu",
2531 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
2532 (unsigned long) seq_len
, (unsigned long) key_len
);
2534 if (key_idx
== -1) {
2538 #endif /* CONFIG_TDLS */
2540 #ifdef CONFIG_DRIVER_NL80211_QCA
2541 if (alg
== WPA_ALG_PMK
&&
2542 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
)) {
2543 wpa_printf(MSG_DEBUG
, "%s: calling issue_key_mgmt_set_key",
2545 ret
= issue_key_mgmt_set_key(drv
, key
, key_len
);
2548 #endif /* CONFIG_DRIVER_NL80211_QCA */
2550 if (alg
== WPA_ALG_NONE
) {
2551 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_DEL_KEY
);
2557 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
2560 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_NEW_KEY
);
2562 nla_put(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
) ||
2563 nla_put_u32(msg
, NL80211_ATTR_KEY_CIPHER
, suite
))
2565 wpa_hexdump_key(MSG_DEBUG
, "nl80211: KEY_DATA", key
, key_len
);
2568 if (seq
&& seq_len
) {
2569 if (nla_put(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
))
2571 wpa_hexdump(MSG_DEBUG
, "nl80211: KEY_SEQ", seq
, seq_len
);
2574 if (addr
&& !is_broadcast_ether_addr(addr
)) {
2575 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
2576 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
2579 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
2580 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
2581 if (nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
,
2582 NL80211_KEYTYPE_GROUP
))
2585 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
2586 struct nlattr
*types
;
2588 wpa_printf(MSG_DEBUG
, " broadcast key");
2590 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2592 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2594 nla_nest_end(msg
, types
);
2596 if (nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2599 ret
= send_and_recv_msgs(drv
, msg
, NULL
, key
? (void *) -1 : NULL
);
2600 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
2603 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
2604 ret
, strerror(-ret
));
2607 * If we failed or don't need to set the default TX key (below),
2610 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
|| tdls
)
2612 if (is_ap_interface(drv
->nlmode
) && addr
&&
2613 !is_broadcast_ether_addr(addr
))
2616 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_SET_KEY
);
2618 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
) ||
2619 nla_put_flag(msg
, (alg
== WPA_ALG_IGTK
||
2620 alg
== WPA_ALG_BIP_GMAC_128
||
2621 alg
== WPA_ALG_BIP_GMAC_256
||
2622 alg
== WPA_ALG_BIP_CMAC_256
) ?
2623 NL80211_ATTR_KEY_DEFAULT_MGMT
:
2624 NL80211_ATTR_KEY_DEFAULT
))
2626 if (addr
&& is_broadcast_ether_addr(addr
)) {
2627 struct nlattr
*types
;
2629 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2631 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2633 nla_nest_end(msg
, types
);
2635 struct nlattr
*types
;
2637 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2639 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
))
2641 nla_nest_end(msg
, types
);
2644 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2648 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
2649 "err=%d %s)", ret
, strerror(-ret
));
2653 nl80211_nlmsg_clear(msg
);
2659 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
2660 int key_idx
, int defkey
,
2661 const u8
*seq
, size_t seq_len
,
2662 const u8
*key
, size_t key_len
)
2664 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
2670 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
2674 if (defkey
&& alg
== WPA_ALG_IGTK
) {
2675 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT_MGMT
))
2677 } else if (defkey
) {
2678 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT
))
2682 if (nla_put_u8(msg
, NL80211_KEY_IDX
, key_idx
) ||
2683 nla_put_u32(msg
, NL80211_KEY_CIPHER
, suite
) ||
2685 nla_put(msg
, NL80211_KEY_SEQ
, seq_len
, seq
)) ||
2686 nla_put(msg
, NL80211_KEY_DATA
, key_len
, key
))
2689 nla_nest_end(msg
, key_attr
);
2695 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
2699 struct nlattr
*nl_keys
, *nl_key
;
2701 for (i
= 0; i
< 4; i
++) {
2702 if (!params
->wep_key
[i
])
2707 if (params
->wps
== WPS_MODE_PRIVACY
)
2709 if (params
->pairwise_suite
&&
2710 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
2716 if (nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
2719 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
2723 for (i
= 0; i
< 4; i
++) {
2724 if (!params
->wep_key
[i
])
2727 nl_key
= nla_nest_start(msg
, i
);
2729 nla_put(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
2730 params
->wep_key
[i
]) ||
2731 nla_put_u32(msg
, NL80211_KEY_CIPHER
,
2732 params
->wep_key_len
[i
] == 5 ?
2733 WLAN_CIPHER_SUITE_WEP40
:
2734 WLAN_CIPHER_SUITE_WEP104
) ||
2735 nla_put_u8(msg
, NL80211_KEY_IDX
, i
) ||
2736 (i
== params
->wep_tx_keyidx
&&
2737 nla_put_flag(msg
, NL80211_KEY_DEFAULT
)))
2740 nla_nest_end(msg
, nl_key
);
2742 nla_nest_end(msg
, nl_keys
);
2748 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
2749 const u8
*addr
, int cmd
, u16 reason_code
,
2750 int local_state_change
)
2755 if (!(msg
= nl80211_drv_msg(drv
, 0, cmd
)) ||
2756 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
) ||
2757 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
2758 (local_state_change
&&
2759 nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))) {
2764 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2766 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2767 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
2768 reason_code
, ret
, strerror(-ret
));
2774 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
2779 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
2780 nl80211_mark_disconnected(drv
);
2781 /* Disconnect command doesn't need BSSID - it uses cached value */
2782 ret
= wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
2785 * For locally generated disconnect, supplicant already generates a
2786 * DEAUTH event, so ignore the event from NL80211.
2788 drv
->ignore_next_local_disconnect
= ret
== 0;
2794 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
2795 const u8
*addr
, int reason_code
)
2797 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2800 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
2801 nl80211_mark_disconnected(drv
);
2802 return nl80211_leave_ibss(drv
, 1);
2804 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
2805 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
2806 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
2807 __func__
, MAC2STR(addr
), reason_code
);
2808 nl80211_mark_disconnected(drv
);
2809 ret
= wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
2812 * For locally generated deauthenticate, supplicant already generates a
2813 * DEAUTH event, so ignore the event from NL80211.
2815 drv
->ignore_next_local_deauth
= ret
== 0;
2820 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
2821 struct wpa_driver_auth_params
*params
)
2825 drv
->auth_freq
= params
->freq
;
2826 drv
->auth_alg
= params
->auth_alg
;
2827 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
2828 drv
->auth_local_state_change
= params
->local_state_change
;
2829 drv
->auth_p2p
= params
->p2p
;
2832 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
2834 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
2837 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
2838 drv
->auth_ssid_len
= params
->ssid_len
;
2840 drv
->auth_ssid_len
= 0;
2843 os_free(drv
->auth_ie
);
2844 drv
->auth_ie
= NULL
;
2845 drv
->auth_ie_len
= 0;
2847 drv
->auth_ie
= os_malloc(params
->ie_len
);
2849 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
2850 drv
->auth_ie_len
= params
->ie_len
;
2854 for (i
= 0; i
< 4; i
++) {
2855 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
2856 params
->wep_key_len
[i
] <= 16) {
2857 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
2858 params
->wep_key_len
[i
]);
2859 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
2861 drv
->auth_wep_key_len
[i
] = 0;
2866 static void nl80211_unmask_11b_rates(struct i802_bss
*bss
)
2868 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2870 if (is_p2p_net_interface(drv
->nlmode
) || !drv
->disabled_11b_rates
)
2874 * Looks like we failed to unmask 11b rates previously. This could
2875 * happen, e.g., if the interface was down at the point in time when a
2876 * P2P group was terminated.
2878 wpa_printf(MSG_DEBUG
,
2879 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
2881 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2885 static int wpa_driver_nl80211_authenticate(
2886 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
2888 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2891 enum nl80211_auth_type type
;
2892 enum nl80211_iftype nlmode
;
2896 nl80211_unmask_11b_rates(bss
);
2898 is_retry
= drv
->retry_auth
;
2899 drv
->retry_auth
= 0;
2900 drv
->ignore_deauth_event
= 0;
2902 nl80211_mark_disconnected(drv
);
2903 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
2905 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
2907 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
2908 /* FIX: IBSS mode */
2909 nlmode
= params
->p2p
?
2910 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
2911 if (drv
->nlmode
!= nlmode
&&
2912 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
2916 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
2919 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_AUTHENTICATE
);
2923 for (i
= 0; i
< 4; i
++) {
2924 if (!params
->wep_key
[i
])
2926 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
2928 i
== params
->wep_tx_keyidx
, NULL
, 0,
2930 params
->wep_key_len
[i
]);
2931 if (params
->wep_tx_keyidx
!= i
)
2933 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
2934 params
->wep_key
[i
], params
->wep_key_len
[i
]))
2938 if (params
->bssid
) {
2939 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
2940 MAC2STR(params
->bssid
));
2941 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
2945 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
2946 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
))
2950 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
2951 params
->ssid
, params
->ssid_len
);
2952 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
2956 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
2958 nla_put(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
))
2960 if (params
->sae_data
) {
2961 wpa_hexdump(MSG_DEBUG
, " * SAE data", params
->sae_data
,
2962 params
->sae_data_len
);
2963 if (nla_put(msg
, NL80211_ATTR_SAE_DATA
, params
->sae_data_len
,
2967 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
2968 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
2969 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
2970 type
= NL80211_AUTHTYPE_SHARED_KEY
;
2971 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
2972 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
2973 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
2974 type
= NL80211_AUTHTYPE_FT
;
2975 else if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
2976 type
= NL80211_AUTHTYPE_SAE
;
2979 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
2980 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
2982 if (params
->local_state_change
) {
2983 wpa_printf(MSG_DEBUG
, " * Local state change only");
2984 if (nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))
2988 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2991 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2992 "nl80211: MLME command failed (auth): ret=%d (%s)",
2993 ret
, strerror(-ret
));
2995 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
2996 !params
->local_state_change
) {
2998 * mac80211 does not currently accept new
2999 * authentication if we are already authenticated. As a
3000 * workaround, force deauthentication and try again.
3002 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
3003 "after forced deauthentication");
3004 drv
->ignore_deauth_event
= 1;
3005 wpa_driver_nl80211_deauthenticate(
3007 WLAN_REASON_PREV_AUTH_NOT_VALID
);
3012 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
3014 * cfg80211 has likely expired the BSS entry even
3015 * though it was previously available in our internal
3016 * BSS table. To recover quickly, start a single
3017 * channel scan on the specified channel.
3019 struct wpa_driver_scan_params scan
;
3022 os_memset(&scan
, 0, sizeof(scan
));
3025 scan
.ssids
[0].ssid
= params
->ssid
;
3026 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
3028 freqs
[0] = params
->freq
;
3031 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
3032 "channel scan to refresh cfg80211 BSS "
3034 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
3036 nl80211_copy_auth_params(drv
, params
);
3037 drv
->scan_for_auth
= 1;
3039 } else if (is_retry
) {
3041 * Need to indicate this with an event since the return
3042 * value from the retry is not delivered to core code.
3044 union wpa_event_data event
;
3045 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
3047 os_memset(&event
, 0, sizeof(event
));
3048 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
3050 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
3054 wpa_printf(MSG_DEBUG
,
3055 "nl80211: Authentication request send successfully");
3064 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data
*drv
)
3066 struct wpa_driver_auth_params params
;
3067 struct i802_bss
*bss
= drv
->first_bss
;
3070 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
3072 os_memset(¶ms
, 0, sizeof(params
));
3073 params
.freq
= drv
->auth_freq
;
3074 params
.auth_alg
= drv
->auth_alg
;
3075 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
3076 params
.local_state_change
= drv
->auth_local_state_change
;
3077 params
.p2p
= drv
->auth_p2p
;
3079 if (!is_zero_ether_addr(drv
->auth_bssid_
))
3080 params
.bssid
= drv
->auth_bssid_
;
3082 if (drv
->auth_ssid_len
) {
3083 params
.ssid
= drv
->auth_ssid
;
3084 params
.ssid_len
= drv
->auth_ssid_len
;
3087 params
.ie
= drv
->auth_ie
;
3088 params
.ie_len
= drv
->auth_ie_len
;
3090 for (i
= 0; i
< 4; i
++) {
3091 if (drv
->auth_wep_key_len
[i
]) {
3092 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
3093 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
3097 drv
->retry_auth
= 1;
3098 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
3102 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
3103 const void *data
, size_t len
,
3104 int encrypt
, int noack
,
3105 unsigned int freq
, int no_cck
,
3106 int offchanok
, unsigned int wait_time
,
3107 const u16
*csa_offs
,
3108 size_t csa_offs_len
)
3110 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3114 if (freq
== 0 && drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3115 freq
= nl80211_get_assoc_freq(drv
);
3116 wpa_printf(MSG_DEBUG
,
3117 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3121 wpa_printf(MSG_DEBUG
, "nl80211: send_frame - Use bss->freq=%u",
3126 if (drv
->use_monitor
) {
3127 wpa_printf(MSG_DEBUG
, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
3129 return nl80211_send_monitor(drv
, data
, len
, encrypt
, noack
);
3132 wpa_printf(MSG_DEBUG
, "nl80211: send_frame -> send_frame_cmd");
3133 res
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
3134 &cookie
, no_cck
, noack
, offchanok
,
3135 csa_offs
, csa_offs_len
);
3136 if (res
== 0 && !noack
) {
3137 const struct ieee80211_mgmt
*mgmt
;
3140 mgmt
= (const struct ieee80211_mgmt
*) data
;
3141 fc
= le_to_host16(mgmt
->frame_control
);
3142 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3143 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_ACTION
) {
3144 wpa_printf(MSG_MSGDUMP
,
3145 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3146 (long long unsigned int)
3147 drv
->send_action_cookie
,
3148 (long long unsigned int) cookie
);
3149 drv
->send_action_cookie
= cookie
;
3157 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
3158 size_t data_len
, int noack
,
3159 unsigned int freq
, int no_cck
,
3161 unsigned int wait_time
,
3162 const u16
*csa_offs
,
3163 size_t csa_offs_len
)
3165 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3166 struct ieee80211_mgmt
*mgmt
;
3170 mgmt
= (struct ieee80211_mgmt
*) data
;
3171 fc
= le_to_host16(mgmt
->frame_control
);
3172 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - da= " MACSTR
3173 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3174 MAC2STR(mgmt
->da
), noack
, freq
, no_cck
, offchanok
, wait_time
,
3175 fc
, fc2str(fc
), drv
->nlmode
);
3177 if ((is_sta_interface(drv
->nlmode
) ||
3178 drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) &&
3179 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3180 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
3182 * The use of last_mgmt_freq is a bit of a hack,
3183 * but it works due to the single-threaded nature
3184 * of wpa_supplicant.
3187 wpa_printf(MSG_DEBUG
, "nl80211: Use last_mgmt_freq=%d",
3188 drv
->last_mgmt_freq
);
3189 freq
= drv
->last_mgmt_freq
;
3191 return nl80211_send_frame_cmd(bss
, freq
, 0,
3192 data
, data_len
, NULL
, 1, noack
,
3193 1, csa_offs
, csa_offs_len
);
3196 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
3198 wpa_printf(MSG_DEBUG
, "nl80211: Use bss->freq=%d",
3202 return nl80211_send_frame_cmd(bss
, freq
,
3203 (int) freq
== bss
->freq
? 0 :
3206 &drv
->send_action_cookie
,
3207 no_cck
, noack
, offchanok
,
3208 csa_offs
, csa_offs_len
);
3211 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3212 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
3214 * Only one of the authentication frame types is encrypted.
3215 * In order for static WEP encryption to work properly (i.e.,
3216 * to not encrypt the frame), we need to tell mac80211 about
3217 * the frames that must not be encrypted.
3219 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
3220 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
3221 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
3225 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme -> send_frame");
3226 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
3227 noack
, freq
, no_cck
, offchanok
,
3228 wait_time
, csa_offs
,
3233 static int nl80211_put_basic_rates(struct nl_msg
*msg
, const int *basic_rates
)
3235 u8 rates
[NL80211_MAX_SUPP_RATES
];
3242 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0; i
++)
3243 rates
[rates_len
++] = basic_rates
[i
] / 5;
3245 return nla_put(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
3249 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
3250 int slot
, int ht_opmode
, int ap_isolate
,
3251 const int *basic_rates
)
3253 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3256 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_BSS
)) ||
3258 nla_put_u8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
)) ||
3260 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
)) ||
3262 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
)) ||
3264 nla_put_u16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
)) ||
3266 nla_put_u8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
)) ||
3267 nl80211_put_basic_rates(msg
, basic_rates
)) {
3272 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3276 static int wpa_driver_nl80211_set_acl(void *priv
,
3277 struct hostapd_acl_params
*params
)
3279 struct i802_bss
*bss
= priv
;
3280 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3286 if (!(drv
->capa
.max_acl_mac_addrs
))
3289 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
3292 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
3293 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
3295 acl
= nlmsg_alloc();
3298 for (i
= 0; i
< params
->num_mac_acl
; i
++) {
3299 if (nla_put(acl
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
)) {
3305 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MAC_ACL
)) ||
3306 nla_put_u32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
3307 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
3308 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
) ||
3309 nla_put_nested(msg
, NL80211_ATTR_MAC_ADDRS
, acl
)) {
3316 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3318 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
3319 ret
, strerror(-ret
));
3326 static int nl80211_put_beacon_int(struct nl_msg
*msg
, int beacon_int
)
3328 if (beacon_int
> 0) {
3329 wpa_printf(MSG_DEBUG
, " * beacon_int=%d", beacon_int
);
3330 return nla_put_u32(msg
, NL80211_ATTR_BEACON_INTERVAL
,
3338 static int wpa_driver_nl80211_set_ap(void *priv
,
3339 struct wpa_driver_ap_params
*params
)
3341 struct i802_bss
*bss
= priv
;
3342 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3344 u8 cmd
= NL80211_CMD_NEW_BEACON
;
3349 u32 suites
[10], suite
;
3352 beacon_set
= params
->reenable
? 0 : bss
->beacon_set
;
3354 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
3357 cmd
= NL80211_CMD_SET_BEACON
;
3359 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
3360 params
->head
, params
->head_len
);
3361 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
3362 params
->tail
, params
->tail_len
);
3363 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", bss
->ifindex
);
3364 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
3365 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
3366 wpa_hexdump_ascii(MSG_DEBUG
, "nl80211: ssid",
3367 params
->ssid
, params
->ssid_len
);
3368 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
3369 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
,
3371 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
,
3373 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
3374 nla_put_u32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
) ||
3375 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
3377 if (params
->proberesp
&& params
->proberesp_len
) {
3378 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
3379 params
->proberesp
, params
->proberesp_len
);
3380 if (nla_put(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
3384 switch (params
->hide_ssid
) {
3385 case NO_SSID_HIDING
:
3386 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
3387 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3388 NL80211_HIDDEN_SSID_NOT_IN_USE
))
3391 case HIDDEN_SSID_ZERO_LEN
:
3392 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
3393 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3394 NL80211_HIDDEN_SSID_ZERO_LEN
))
3397 case HIDDEN_SSID_ZERO_CONTENTS
:
3398 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
3399 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3400 NL80211_HIDDEN_SSID_ZERO_CONTENTS
))
3404 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
3405 if (params
->privacy
&&
3406 nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
3408 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
3409 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
3410 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
3411 /* Leave out the attribute */
3412 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
) {
3413 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3414 NL80211_AUTHTYPE_SHARED_KEY
))
3417 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3418 NL80211_AUTHTYPE_OPEN_SYSTEM
))
3422 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
3424 if (params
->wpa_version
& WPA_PROTO_WPA
)
3425 ver
|= NL80211_WPA_VERSION_1
;
3426 if (params
->wpa_version
& WPA_PROTO_RSN
)
3427 ver
|= NL80211_WPA_VERSION_2
;
3429 nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
3432 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
3433 params
->key_mgmt_suites
);
3435 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
3436 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
3437 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
3438 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
3440 nla_put(msg
, NL80211_ATTR_AKM_SUITES
, num_suites
* sizeof(u32
),
3444 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
3445 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
) &&
3446 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
))
3449 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
3450 params
->pairwise_ciphers
);
3451 num_suites
= wpa_cipher_to_cipher_suites(params
->pairwise_ciphers
,
3452 suites
, ARRAY_SIZE(suites
));
3454 nla_put(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
3455 num_suites
* sizeof(u32
), suites
))
3458 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
3459 params
->group_cipher
);
3460 suite
= wpa_cipher_to_cipher_suite(params
->group_cipher
);
3462 nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, suite
))
3465 switch (params
->smps_mode
) {
3466 case HT_CAP_INFO_SMPS_DYNAMIC
:
3467 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - dynamic");
3468 smps_mode
= NL80211_SMPS_DYNAMIC
;
3470 case HT_CAP_INFO_SMPS_STATIC
:
3471 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - static");
3472 smps_mode
= NL80211_SMPS_STATIC
;
3475 /* invalid - fallback to smps off */
3476 case HT_CAP_INFO_SMPS_DISABLED
:
3477 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - off");
3478 smps_mode
= NL80211_SMPS_OFF
;
3481 if (nla_put_u32(msg
, NL80211_ATTR_SMPS_MODE
, smps_mode
))
3484 if (params
->beacon_ies
) {
3485 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
3486 params
->beacon_ies
);
3487 if (nla_put(msg
, NL80211_ATTR_IE
,
3488 wpabuf_len(params
->beacon_ies
),
3489 wpabuf_head(params
->beacon_ies
)))
3492 if (params
->proberesp_ies
) {
3493 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
3494 params
->proberesp_ies
);
3495 if (nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
3496 wpabuf_len(params
->proberesp_ies
),
3497 wpabuf_head(params
->proberesp_ies
)))
3500 if (params
->assocresp_ies
) {
3501 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
3502 params
->assocresp_ies
);
3503 if (nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
3504 wpabuf_len(params
->assocresp_ies
),
3505 wpabuf_head(params
->assocresp_ies
)))
3509 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
3510 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
3511 params
->ap_max_inactivity
);
3512 if (nla_put_u16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
3513 params
->ap_max_inactivity
))
3518 if (params
->p2p_go_ctwindow
> 0) {
3519 if (drv
->p2p_go_ctwindow_supported
) {
3520 wpa_printf(MSG_DEBUG
, "nl80211: P2P GO ctwindow=%d",
3521 params
->p2p_go_ctwindow
);
3522 if (nla_put_u8(msg
, NL80211_ATTR_P2P_CTWINDOW
,
3523 params
->p2p_go_ctwindow
))
3526 wpa_printf(MSG_INFO
,
3527 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
3530 #endif /* CONFIG_P2P */
3532 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3534 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
3535 ret
, strerror(-ret
));
3537 bss
->beacon_set
= 1;
3538 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
3539 params
->short_slot_time
, params
->ht_opmode
,
3540 params
->isolate
, params
->basic_rates
);
3541 if (beacon_set
&& params
->freq
&&
3542 params
->freq
->bandwidth
!= bss
->bandwidth
) {
3543 wpa_printf(MSG_DEBUG
,
3544 "nl80211: Update BSS %s bandwidth: %d -> %d",
3545 bss
->ifname
, bss
->bandwidth
,
3546 params
->freq
->bandwidth
);
3547 ret
= nl80211_set_channel(bss
, params
->freq
, 1);
3549 wpa_printf(MSG_DEBUG
,
3550 "nl80211: Frequency set failed: %d (%s)",
3551 ret
, strerror(-ret
));
3553 wpa_printf(MSG_DEBUG
,
3554 "nl80211: Frequency set succeeded for ht2040 coex");
3555 bss
->bandwidth
= params
->freq
->bandwidth
;
3557 } else if (!beacon_set
) {
3559 * cfg80211 updates the driver on frequence change in AP
3560 * mode only at the point when beaconing is started, so
3561 * set the initial value here.
3563 bss
->bandwidth
= params
->freq
->bandwidth
;
3573 static int nl80211_put_freq_params(struct nl_msg
*msg
,
3574 const struct hostapd_freq_params
*freq
)
3576 wpa_printf(MSG_DEBUG
, " * freq=%d", freq
->freq
);
3577 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
))
3580 wpa_printf(MSG_DEBUG
, " * vht_enabled=%d", freq
->vht_enabled
);
3581 wpa_printf(MSG_DEBUG
, " * ht_enabled=%d", freq
->ht_enabled
);
3583 if (freq
->vht_enabled
) {
3584 enum nl80211_chan_width cw
;
3586 wpa_printf(MSG_DEBUG
, " * bandwidth=%d", freq
->bandwidth
);
3587 switch (freq
->bandwidth
) {
3589 cw
= NL80211_CHAN_WIDTH_20
;
3592 cw
= NL80211_CHAN_WIDTH_40
;
3595 if (freq
->center_freq2
)
3596 cw
= NL80211_CHAN_WIDTH_80P80
;
3598 cw
= NL80211_CHAN_WIDTH_80
;
3601 cw
= NL80211_CHAN_WIDTH_160
;
3607 wpa_printf(MSG_DEBUG
, " * channel_width=%d", cw
);
3608 wpa_printf(MSG_DEBUG
, " * center_freq1=%d",
3609 freq
->center_freq1
);
3610 wpa_printf(MSG_DEBUG
, " * center_freq2=%d",
3611 freq
->center_freq2
);
3612 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, cw
) ||
3613 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
,
3614 freq
->center_freq1
) ||
3615 (freq
->center_freq2
&&
3616 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
,
3617 freq
->center_freq2
)))
3619 } else if (freq
->ht_enabled
) {
3620 enum nl80211_channel_type ct
;
3622 wpa_printf(MSG_DEBUG
, " * sec_channel_offset=%d",
3623 freq
->sec_channel_offset
);
3624 switch (freq
->sec_channel_offset
) {
3626 ct
= NL80211_CHAN_HT40MINUS
;
3629 ct
= NL80211_CHAN_HT40PLUS
;
3632 ct
= NL80211_CHAN_HT20
;
3636 wpa_printf(MSG_DEBUG
, " * channel_type=%d", ct
);
3637 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, ct
))
3644 static int nl80211_set_channel(struct i802_bss
*bss
,
3645 struct hostapd_freq_params
*freq
, int set_chan
)
3647 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3651 wpa_printf(MSG_DEBUG
,
3652 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
3653 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
3654 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
3656 msg
= nl80211_drv_msg(drv
, 0, set_chan
? NL80211_CMD_SET_CHANNEL
:
3657 NL80211_CMD_SET_WIPHY
);
3658 if (!msg
|| nl80211_put_freq_params(msg
, freq
) < 0) {
3663 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3665 bss
->freq
= freq
->freq
;
3668 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
3669 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
3674 static u32
sta_flags_nl80211(int flags
)
3678 if (flags
& WPA_STA_AUTHORIZED
)
3679 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
3680 if (flags
& WPA_STA_WMM
)
3681 f
|= BIT(NL80211_STA_FLAG_WME
);
3682 if (flags
& WPA_STA_SHORT_PREAMBLE
)
3683 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
3684 if (flags
& WPA_STA_MFP
)
3685 f
|= BIT(NL80211_STA_FLAG_MFP
);
3686 if (flags
& WPA_STA_TDLS_PEER
)
3687 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
3688 if (flags
& WPA_STA_AUTHENTICATED
)
3689 f
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
3696 static u32
sta_plink_state_nl80211(enum mesh_plink_state state
)
3700 return NL80211_PLINK_LISTEN
;
3701 case PLINK_OPEN_SENT
:
3702 return NL80211_PLINK_OPN_SNT
;
3703 case PLINK_OPEN_RCVD
:
3704 return NL80211_PLINK_OPN_RCVD
;
3705 case PLINK_CNF_RCVD
:
3706 return NL80211_PLINK_CNF_RCVD
;
3708 return NL80211_PLINK_ESTAB
;
3710 return NL80211_PLINK_HOLDING
;
3712 return NL80211_PLINK_BLOCKED
;
3714 wpa_printf(MSG_ERROR
, "nl80211: Invalid mesh plink state %d",
3719 #endif /* CONFIG_MESH */
3722 static int wpa_driver_nl80211_sta_add(void *priv
,
3723 struct hostapd_sta_add_params
*params
)
3725 struct i802_bss
*bss
= priv
;
3726 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3728 struct nl80211_sta_flag_update upd
;
3731 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
3732 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
3735 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
3736 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
3737 msg
= nl80211_bss_msg(bss
, 0, params
->set
? NL80211_CMD_SET_STATION
:
3738 NL80211_CMD_NEW_STATION
);
3739 if (!msg
|| nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
))
3742 if (!params
->set
|| (params
->flags
& WPA_STA_TDLS_PEER
)) {
3743 wpa_hexdump(MSG_DEBUG
, " * supported rates",
3744 params
->supp_rates
, params
->supp_rates_len
);
3745 wpa_printf(MSG_DEBUG
, " * capability=0x%x",
3746 params
->capability
);
3747 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
,
3748 params
->supp_rates_len
, params
->supp_rates
) ||
3749 nla_put_u16(msg
, NL80211_ATTR_STA_CAPABILITY
,
3750 params
->capability
))
3753 if (params
->ht_capabilities
) {
3754 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
3755 (u8
*) params
->ht_capabilities
,
3756 sizeof(*params
->ht_capabilities
));
3757 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
,
3758 sizeof(*params
->ht_capabilities
),
3759 params
->ht_capabilities
))
3763 if (params
->vht_capabilities
) {
3764 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
3765 (u8
*) params
->vht_capabilities
,
3766 sizeof(*params
->vht_capabilities
));
3767 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
,
3768 sizeof(*params
->vht_capabilities
),
3769 params
->vht_capabilities
))
3773 if (params
->ext_capab
) {
3774 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
3775 params
->ext_capab
, params
->ext_capab_len
);
3776 if (nla_put(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
3777 params
->ext_capab_len
, params
->ext_capab
))
3783 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
3784 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
))
3788 * cfg80211 validates that AID is non-zero, so we have
3789 * to make this a non-zero value for the TDLS case where
3790 * a dummy STA entry is used for now.
3792 wpa_printf(MSG_DEBUG
, " * aid=1 (TDLS workaround)");
3793 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, 1))
3796 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
3797 params
->listen_interval
);
3798 if (nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
3799 params
->listen_interval
))
3801 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
3802 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
3803 if (nla_put_u16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
))
3807 if (params
->vht_opmode_enabled
) {
3808 wpa_printf(MSG_DEBUG
, " * opmode=%u", params
->vht_opmode
);
3809 if (nla_put_u8(msg
, NL80211_ATTR_OPMODE_NOTIF
,
3810 params
->vht_opmode
))
3814 if (params
->supp_channels
) {
3815 wpa_hexdump(MSG_DEBUG
, " * supported channels",
3816 params
->supp_channels
, params
->supp_channels_len
);
3817 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_CHANNELS
,
3818 params
->supp_channels_len
, params
->supp_channels
))
3822 if (params
->supp_oper_classes
) {
3823 wpa_hexdump(MSG_DEBUG
, " * supported operating classes",
3824 params
->supp_oper_classes
,
3825 params
->supp_oper_classes_len
);
3826 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
,
3827 params
->supp_oper_classes_len
,
3828 params
->supp_oper_classes
))
3832 os_memset(&upd
, 0, sizeof(upd
));
3833 upd
.set
= sta_flags_nl80211(params
->flags
);
3834 upd
.mask
= upd
.set
| sta_flags_nl80211(params
->flags_mask
);
3835 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
3837 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
3841 if (params
->plink_state
&&
3842 nla_put_u8(msg
, NL80211_ATTR_STA_PLINK_STATE
,
3843 sta_plink_state_nl80211(params
->plink_state
)))
3845 #endif /* CONFIG_MESH */
3847 if (params
->flags
& WPA_STA_WMM
) {
3848 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
3850 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
3852 nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
3853 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
) ||
3854 nla_put_u8(msg
, NL80211_STA_WME_MAX_SP
,
3855 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
3856 WMM_QOSINFO_STA_SP_MASK
))
3858 nla_nest_end(msg
, wme
);
3861 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3864 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
3865 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
3875 static void rtnl_neigh_delete_fdb_entry(struct i802_bss
*bss
, const u8
*addr
)
3877 #ifdef CONFIG_LIBNL3_ROUTE
3878 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3879 struct rtnl_neigh
*rn
;
3880 struct nl_addr
*nl_addr
;
3883 rn
= rtnl_neigh_alloc();
3887 rtnl_neigh_set_family(rn
, AF_BRIDGE
);
3888 rtnl_neigh_set_ifindex(rn
, bss
->ifindex
);
3889 nl_addr
= nl_addr_build(AF_BRIDGE
, (void *) addr
, ETH_ALEN
);
3894 rtnl_neigh_set_lladdr(rn
, nl_addr
);
3896 err
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
3898 wpa_printf(MSG_DEBUG
, "nl80211: bridge FDB entry delete for "
3899 MACSTR
" ifindex=%d failed: %s", MAC2STR(addr
),
3900 bss
->ifindex
, nl_geterror(err
));
3902 wpa_printf(MSG_DEBUG
, "nl80211: deleted bridge FDB entry for "
3903 MACSTR
, MAC2STR(addr
));
3906 nl_addr_put(nl_addr
);
3908 #endif /* CONFIG_LIBNL3_ROUTE */
3912 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
,
3913 int deauth
, u16 reason_code
)
3915 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3919 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
)) ||
3920 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
3922 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
3923 WLAN_FC_STYPE_DISASSOC
)) ||
3925 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
3926 WLAN_FC_STYPE_DEAUTH
)) ||
3928 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
))) {
3933 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3934 wpa_printf(MSG_DEBUG
, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
3936 bss
->ifname
, MAC2STR(addr
), ret
, strerror(-ret
));
3939 rtnl_neigh_delete_fdb_entry(bss
, addr
);
3947 void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
3950 struct wpa_driver_nl80211_data
*drv2
;
3952 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
3954 /* stop listening for EAPOL on this interface */
3955 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
3956 struct wpa_driver_nl80211_data
, list
)
3957 del_ifidx(drv2
, ifidx
);
3959 msg
= nl80211_ifindex_msg(drv
, ifidx
, 0, NL80211_CMD_DEL_INTERFACE
);
3960 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
3962 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
3966 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
3969 case NL80211_IFTYPE_ADHOC
:
3971 case NL80211_IFTYPE_STATION
:
3973 case NL80211_IFTYPE_AP
:
3975 case NL80211_IFTYPE_AP_VLAN
:
3977 case NL80211_IFTYPE_WDS
:
3979 case NL80211_IFTYPE_MONITOR
:
3981 case NL80211_IFTYPE_MESH_POINT
:
3982 return "MESH_POINT";
3983 case NL80211_IFTYPE_P2P_CLIENT
:
3984 return "P2P_CLIENT";
3985 case NL80211_IFTYPE_P2P_GO
:
3987 case NL80211_IFTYPE_P2P_DEVICE
:
3988 return "P2P_DEVICE";
3995 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
3997 enum nl80211_iftype iftype
,
3998 const u8
*addr
, int wds
,
3999 int (*handler
)(struct nl_msg
*, void *),
4006 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
4007 iftype
, nl80211_iftype_str(iftype
));
4009 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_NEW_INTERFACE
);
4011 nla_put_string(msg
, NL80211_ATTR_IFNAME
, ifname
) ||
4012 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, iftype
))
4015 if (iftype
== NL80211_IFTYPE_MONITOR
) {
4016 struct nlattr
*flags
;
4018 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
4020 nla_put_flag(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
))
4023 nla_nest_end(msg
, flags
);
4025 if (nla_put_u8(msg
, NL80211_ATTR_4ADDR
, wds
))
4030 * Tell cfg80211 that the interface belongs to the socket that created
4031 * it, and the interface should be deleted when the socket is closed.
4033 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
4036 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
4041 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
4042 ifname
, ret
, strerror(-ret
));
4046 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
)
4049 ifidx
= if_nametoindex(ifname
);
4050 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
4057 * Some virtual interfaces need to process EAPOL packets and events on
4058 * the parent interface. This is used mainly with hostapd.
4061 iftype
== NL80211_IFTYPE_AP_VLAN
||
4062 iftype
== NL80211_IFTYPE_WDS
||
4063 iftype
== NL80211_IFTYPE_MONITOR
) {
4064 /* start listening for EAPOL on this interface */
4065 add_ifidx(drv
, ifidx
);
4068 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4069 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
4070 nl80211_remove_iface(drv
, ifidx
);
4078 int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
4079 const char *ifname
, enum nl80211_iftype iftype
,
4080 const u8
*addr
, int wds
,
4081 int (*handler
)(struct nl_msg
*, void *),
4082 void *arg
, int use_existing
)
4086 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
4089 /* if error occurred and interface exists already */
4090 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
4092 wpa_printf(MSG_DEBUG
, "nl80211: Continue using existing interface %s",
4094 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4095 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
4097 (linux_set_iface_flags(drv
->global
->ioctl_sock
,
4099 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
4101 linux_set_iface_flags(drv
->global
->ioctl_sock
,
4106 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
4108 /* Try to remove the interface that was already there. */
4109 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
4111 /* Try to create the interface again */
4112 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
4116 if (ret
>= 0 && is_p2p_net_interface(iftype
)) {
4117 wpa_printf(MSG_DEBUG
,
4118 "nl80211: Interface %s created for P2P - disable 11b rates",
4120 nl80211_disable_11b_rates(drv
, ret
, 1);
4127 static int nl80211_setup_ap(struct i802_bss
*bss
)
4129 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4131 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4132 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
4135 * Disable Probe Request reporting unless we need it in this way for
4136 * devices that include the AP SME, in the other case (unless using
4137 * monitor iface) we'll get it through the nl_mgmt socket instead.
4139 if (!drv
->device_ap_sme
)
4140 wpa_driver_nl80211_probe_req_report(bss
, 0);
4142 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
4143 if (nl80211_mgmt_subscribe_ap(bss
))
4146 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
4147 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
4150 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
4151 nl80211_create_monitor_interface(drv
) &&
4152 !drv
->device_ap_sme
)
4155 if (drv
->device_ap_sme
&&
4156 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
4157 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
4158 "Probe Request frame reporting in AP mode");
4159 /* Try to survive without this */
4166 static void nl80211_teardown_ap(struct i802_bss
*bss
)
4168 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4170 wpa_printf(MSG_DEBUG
, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4171 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
4172 if (drv
->device_ap_sme
) {
4173 wpa_driver_nl80211_probe_req_report(bss
, 0);
4174 if (!drv
->use_monitor
)
4175 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
4176 } else if (drv
->use_monitor
)
4177 nl80211_remove_monitor_interface(drv
);
4179 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
4181 bss
->beacon_set
= 0;
4185 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
4186 const u8
*addr
, const u8
*data
,
4189 struct sockaddr_ll ll
;
4192 if (bss
->drv
->eapol_tx_sock
< 0) {
4193 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
4197 os_memset(&ll
, 0, sizeof(ll
));
4198 ll
.sll_family
= AF_PACKET
;
4199 ll
.sll_ifindex
= bss
->ifindex
;
4200 ll
.sll_protocol
= htons(ETH_P_PAE
);
4201 ll
.sll_halen
= ETH_ALEN
;
4202 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
4203 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
4204 (struct sockaddr
*) &ll
, sizeof(ll
));
4206 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
4213 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4215 static int wpa_driver_nl80211_hapd_send_eapol(
4216 void *priv
, const u8
*addr
, const u8
*data
,
4217 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
4219 struct i802_bss
*bss
= priv
;
4220 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4221 struct ieee80211_hdr
*hdr
;
4225 int qos
= flags
& WPA_STA_WMM
;
4227 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
4228 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
4230 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
4232 hdr
= os_zalloc(len
);
4234 wpa_printf(MSG_INFO
, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4235 (unsigned long) len
);
4239 hdr
->frame_control
=
4240 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
4241 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
4243 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
4245 hdr
->frame_control
|=
4246 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
4249 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
4250 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
4251 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
4252 pos
= (u8
*) (hdr
+ 1);
4255 /* Set highest priority in QoS header */
4261 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
4262 pos
+= sizeof(rfc1042_header
);
4263 WPA_PUT_BE16(pos
, ETH_P_PAE
);
4265 memcpy(pos
, data
, data_len
);
4267 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
4268 0, 0, 0, 0, NULL
, 0);
4270 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
4272 (unsigned long) len
, errno
, strerror(errno
));
4280 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
4281 unsigned int total_flags
,
4282 unsigned int flags_or
,
4283 unsigned int flags_and
)
4285 struct i802_bss
*bss
= priv
;
4287 struct nlattr
*flags
;
4288 struct nl80211_sta_flag_update upd
;
4290 wpa_printf(MSG_DEBUG
, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4291 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4292 bss
->ifname
, MAC2STR(addr
), total_flags
, flags_or
, flags_and
,
4293 !!(total_flags
& WPA_STA_AUTHORIZED
));
4295 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
4296 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
4300 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4301 * can be removed eventually.
4303 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
4305 ((total_flags
& WPA_STA_AUTHORIZED
) &&
4306 nla_put_flag(msg
, NL80211_STA_FLAG_AUTHORIZED
)) ||
4307 ((total_flags
& WPA_STA_WMM
) &&
4308 nla_put_flag(msg
, NL80211_STA_FLAG_WME
)) ||
4309 ((total_flags
& WPA_STA_SHORT_PREAMBLE
) &&
4310 nla_put_flag(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
)) ||
4311 ((total_flags
& WPA_STA_MFP
) &&
4312 nla_put_flag(msg
, NL80211_STA_FLAG_MFP
)) ||
4313 ((total_flags
& WPA_STA_TDLS_PEER
) &&
4314 nla_put_flag(msg
, NL80211_STA_FLAG_TDLS_PEER
)))
4317 nla_nest_end(msg
, flags
);
4319 os_memset(&upd
, 0, sizeof(upd
));
4320 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
4321 upd
.set
= sta_flags_nl80211(flags_or
);
4322 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
4325 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
4332 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
4333 struct wpa_driver_associate_params
*params
)
4335 enum nl80211_iftype nlmode
, old_mode
;
4338 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
4340 nlmode
= NL80211_IFTYPE_P2P_GO
;
4342 nlmode
= NL80211_IFTYPE_AP
;
4344 old_mode
= drv
->nlmode
;
4345 if (wpa_driver_nl80211_set_mode(drv
->first_bss
, nlmode
)) {
4346 nl80211_remove_monitor_interface(drv
);
4350 if (params
->freq
.freq
&&
4351 nl80211_set_channel(drv
->first_bss
, ¶ms
->freq
, 0)) {
4352 if (old_mode
!= nlmode
)
4353 wpa_driver_nl80211_set_mode(drv
->first_bss
, old_mode
);
4354 nl80211_remove_monitor_interface(drv
);
4362 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
4368 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_IBSS
);
4369 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4371 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
4372 "(%s)", ret
, strerror(-ret
));
4374 wpa_printf(MSG_DEBUG
,
4375 "nl80211: Leave IBSS request sent successfully");
4379 wpa_driver_nl80211_set_mode(drv
->first_bss
,
4380 NL80211_IFTYPE_STATION
)) {
4381 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
4389 static int nl80211_ht_vht_overrides(struct nl_msg
*msg
,
4390 struct wpa_driver_associate_params
*params
)
4392 if (params
->disable_ht
&& nla_put_flag(msg
, NL80211_ATTR_DISABLE_HT
))
4395 if (params
->htcaps
&& params
->htcaps_mask
) {
4396 int sz
= sizeof(struct ieee80211_ht_capabilities
);
4397 wpa_hexdump(MSG_DEBUG
, " * htcaps", params
->htcaps
, sz
);
4398 wpa_hexdump(MSG_DEBUG
, " * htcaps_mask",
4399 params
->htcaps_mask
, sz
);
4400 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
,
4402 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
4403 params
->htcaps_mask
))
4407 #ifdef CONFIG_VHT_OVERRIDES
4408 if (params
->disable_vht
) {
4409 wpa_printf(MSG_DEBUG
, " * VHT disabled");
4410 if (nla_put_flag(msg
, NL80211_ATTR_DISABLE_VHT
))
4414 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
4415 int sz
= sizeof(struct ieee80211_vht_capabilities
);
4416 wpa_hexdump(MSG_DEBUG
, " * vhtcaps", params
->vhtcaps
, sz
);
4417 wpa_hexdump(MSG_DEBUG
, " * vhtcaps_mask",
4418 params
->vhtcaps_mask
, sz
);
4419 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
,
4421 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
4422 params
->vhtcaps_mask
))
4425 #endif /* CONFIG_VHT_OVERRIDES */
4431 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
4432 struct wpa_driver_associate_params
*params
)
4438 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
4440 if (wpa_driver_nl80211_set_mode_ibss(drv
->first_bss
, ¶ms
->freq
)) {
4441 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
4447 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_IBSS
)) ||
4448 params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
4451 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4452 params
->ssid
, params
->ssid_len
);
4453 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
4455 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
4456 drv
->ssid_len
= params
->ssid_len
;
4458 if (nl80211_put_freq_params(msg
, ¶ms
->freq
) < 0 ||
4459 nl80211_put_beacon_int(msg
, params
->beacon_int
))
4462 ret
= nl80211_set_conn_keys(params
, msg
);
4466 if (params
->bssid
&& params
->fixed_bssid
) {
4467 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
4468 MAC2STR(params
->bssid
));
4469 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
4473 if (params
->fixed_freq
) {
4474 wpa_printf(MSG_DEBUG
, " * fixed_freq");
4475 if (nla_put_flag(msg
, NL80211_ATTR_FREQ_FIXED
))
4479 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
4480 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
4481 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
4482 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
) {
4483 wpa_printf(MSG_DEBUG
, " * control port");
4484 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
4488 if (params
->wpa_ie
) {
4489 wpa_hexdump(MSG_DEBUG
,
4490 " * Extra IEs for Beacon/Probe Response frames",
4491 params
->wpa_ie
, params
->wpa_ie_len
);
4492 if (nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
4497 if (nl80211_ht_vht_overrides(msg
, params
) < 0)
4500 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4503 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
4504 ret
, strerror(-ret
));
4506 if (ret
== -EALREADY
&& count
== 1) {
4507 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
4509 nl80211_leave_ibss(drv
, 0);
4514 wpa_printf(MSG_DEBUG
,
4515 "nl80211: Join IBSS request sent successfully");
4524 static int nl80211_connect_common(struct wpa_driver_nl80211_data
*drv
,
4525 struct wpa_driver_associate_params
*params
,
4528 if (params
->bssid
) {
4529 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
4530 MAC2STR(params
->bssid
));
4531 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
4535 if (params
->bssid_hint
) {
4536 wpa_printf(MSG_DEBUG
, " * bssid_hint=" MACSTR
,
4537 MAC2STR(params
->bssid_hint
));
4538 if (nla_put(msg
, NL80211_ATTR_MAC_HINT
, ETH_ALEN
,
4539 params
->bssid_hint
))
4543 if (params
->freq
.freq
) {
4544 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
.freq
);
4545 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
4548 drv
->assoc_freq
= params
->freq
.freq
;
4550 drv
->assoc_freq
= 0;
4552 if (params
->freq_hint
) {
4553 wpa_printf(MSG_DEBUG
, " * freq_hint=%d", params
->freq_hint
);
4554 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_HINT
,
4559 if (params
->bg_scan_period
>= 0) {
4560 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
4561 params
->bg_scan_period
);
4562 if (nla_put_u16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
4563 params
->bg_scan_period
))
4568 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4569 params
->ssid
, params
->ssid_len
);
4570 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4573 if (params
->ssid_len
> sizeof(drv
->ssid
))
4575 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
4576 drv
->ssid_len
= params
->ssid_len
;
4579 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
4580 if (params
->wpa_ie
&&
4581 nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
, params
->wpa_ie
))
4584 if (params
->wpa_proto
) {
4585 enum nl80211_wpa_versions ver
= 0;
4587 if (params
->wpa_proto
& WPA_PROTO_WPA
)
4588 ver
|= NL80211_WPA_VERSION_1
;
4589 if (params
->wpa_proto
& WPA_PROTO_RSN
)
4590 ver
|= NL80211_WPA_VERSION_2
;
4592 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
4593 if (nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
4597 if (params
->pairwise_suite
!= WPA_CIPHER_NONE
) {
4598 u32 cipher
= wpa_cipher_to_cipher_suite(params
->pairwise_suite
);
4599 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
4600 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
4605 if (params
->group_suite
== WPA_CIPHER_GTK_NOT_USED
&&
4606 !(drv
->capa
.enc
& WPA_DRIVER_CAPA_ENC_GTK_NOT_USED
)) {
4608 * This is likely to work even though many drivers do not
4609 * advertise support for operations without GTK.
4611 wpa_printf(MSG_DEBUG
, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
4612 } else if (params
->group_suite
!= WPA_CIPHER_NONE
) {
4613 u32 cipher
= wpa_cipher_to_cipher_suite(params
->group_suite
);
4614 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
4615 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
))
4619 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
4620 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
4621 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_IEEE8021X
||
4622 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
||
4623 params
->key_mgmt_suite
== WPA_KEY_MGMT_CCKM
||
4624 params
->key_mgmt_suite
== WPA_KEY_MGMT_OSEN
||
4625 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
4626 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
4627 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
||
4628 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
4629 int mgmt
= WLAN_AKM_SUITE_PSK
;
4631 switch (params
->key_mgmt_suite
) {
4632 case WPA_KEY_MGMT_CCKM
:
4633 mgmt
= WLAN_AKM_SUITE_CCKM
;
4635 case WPA_KEY_MGMT_IEEE8021X
:
4636 mgmt
= WLAN_AKM_SUITE_8021X
;
4638 case WPA_KEY_MGMT_FT_IEEE8021X
:
4639 mgmt
= WLAN_AKM_SUITE_FT_8021X
;
4641 case WPA_KEY_MGMT_FT_PSK
:
4642 mgmt
= WLAN_AKM_SUITE_FT_PSK
;
4644 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
4645 mgmt
= WLAN_AKM_SUITE_8021X_SHA256
;
4647 case WPA_KEY_MGMT_PSK_SHA256
:
4648 mgmt
= WLAN_AKM_SUITE_PSK_SHA256
;
4650 case WPA_KEY_MGMT_OSEN
:
4651 mgmt
= WLAN_AKM_SUITE_OSEN
;
4653 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
4654 mgmt
= WLAN_AKM_SUITE_8021X_SUITE_B
;
4656 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
4657 mgmt
= WLAN_AKM_SUITE_8021X_SUITE_B_192
;
4659 case WPA_KEY_MGMT_PSK
:
4661 mgmt
= WLAN_AKM_SUITE_PSK
;
4664 wpa_printf(MSG_DEBUG
, " * akm=0x%x", mgmt
);
4665 if (nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
))
4669 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
4672 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
&&
4673 nla_put_u32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
))
4676 if (params
->rrm_used
) {
4677 u32 drv_rrm_flags
= drv
->capa
.rrm_flags
;
4678 if (!(drv_rrm_flags
&
4679 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) ||
4680 !(drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
) ||
4681 nla_put_flag(msg
, NL80211_ATTR_USE_RRM
))
4685 if (nl80211_ht_vht_overrides(msg
, params
) < 0)
4689 wpa_printf(MSG_DEBUG
, " * P2P group");
4695 static int wpa_driver_nl80211_try_connect(
4696 struct wpa_driver_nl80211_data
*drv
,
4697 struct wpa_driver_associate_params
*params
)
4700 enum nl80211_auth_type type
;
4704 #ifdef CONFIG_DRIVER_NL80211_QCA
4705 if (params
->req_key_mgmt_offload
&& params
->psk
&&
4706 (params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
4707 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
4708 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
4709 wpa_printf(MSG_DEBUG
, "nl80211: Key management set PSK");
4710 ret
= issue_key_mgmt_set_key(drv
, params
->psk
, 32);
4714 #endif /* CONFIG_DRIVER_NL80211_QCA */
4716 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
4717 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_CONNECT
);
4721 ret
= nl80211_connect_common(drv
, params
, msg
);
4726 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4728 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4730 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4733 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
4735 goto skip_auth_type
;
4738 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4739 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
4740 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4741 type
= NL80211_AUTHTYPE_SHARED_KEY
;
4742 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4743 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
4744 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
4745 type
= NL80211_AUTHTYPE_FT
;
4749 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
4750 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
4754 ret
= nl80211_set_conn_keys(params
, msg
);
4758 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4761 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
4762 "(%s)", ret
, strerror(-ret
));
4764 wpa_printf(MSG_DEBUG
,
4765 "nl80211: Connect request send successfully");
4775 static int wpa_driver_nl80211_connect(
4776 struct wpa_driver_nl80211_data
*drv
,
4777 struct wpa_driver_associate_params
*params
)
4781 /* Store the connection attempted bssid for future use */
4783 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
4785 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
4787 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
4788 if (ret
== -EALREADY
) {
4790 * cfg80211 does not currently accept new connections if
4791 * we are already connected. As a workaround, force
4792 * disconnection and try again.
4794 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
4795 "disconnecting before reassociation "
4797 if (wpa_driver_nl80211_disconnect(
4798 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
4800 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
4806 static int wpa_driver_nl80211_associate(
4807 void *priv
, struct wpa_driver_associate_params
*params
)
4809 struct i802_bss
*bss
= priv
;
4810 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4814 nl80211_unmask_11b_rates(bss
);
4816 if (params
->mode
== IEEE80211_MODE_AP
)
4817 return wpa_driver_nl80211_ap(drv
, params
);
4819 if (params
->mode
== IEEE80211_MODE_IBSS
)
4820 return wpa_driver_nl80211_ibss(drv
, params
);
4822 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
4823 enum nl80211_iftype nlmode
= params
->p2p
?
4824 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
4826 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
4828 return wpa_driver_nl80211_connect(drv
, params
);
4831 nl80211_mark_disconnected(drv
);
4833 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
4835 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_ASSOCIATE
);
4839 ret
= nl80211_connect_common(drv
, params
, msg
);
4843 if (params
->prev_bssid
) {
4844 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
4845 MAC2STR(params
->prev_bssid
));
4846 if (nla_put(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
4847 params
->prev_bssid
))
4851 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4854 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4855 "nl80211: MLME command failed (assoc): ret=%d (%s)",
4856 ret
, strerror(-ret
));
4857 nl80211_dump_scan(drv
);
4859 wpa_printf(MSG_DEBUG
,
4860 "nl80211: Association request send successfully");
4869 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
4870 int ifindex
, enum nl80211_iftype mode
)
4875 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
4876 ifindex
, mode
, nl80211_iftype_str(mode
));
4878 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_SET_INTERFACE
);
4879 if (!msg
|| nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, mode
))
4882 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4888 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
4889 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
4894 static int wpa_driver_nl80211_set_mode_impl(
4895 struct i802_bss
*bss
,
4896 enum nl80211_iftype nlmode
,
4897 struct hostapd_freq_params
*desired_freq_params
)
4899 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4902 int was_ap
= is_ap_interface(drv
->nlmode
);
4904 int mode_switch_res
;
4906 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
4907 if (mode_switch_res
&& nlmode
== nl80211_get_ifmode(bss
))
4908 mode_switch_res
= 0;
4910 if (mode_switch_res
== 0) {
4911 drv
->nlmode
= nlmode
;
4916 if (mode_switch_res
== -ENODEV
)
4919 if (nlmode
== drv
->nlmode
) {
4920 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
4921 "requested mode - ignore error");
4923 goto done
; /* Already in the requested mode */
4926 /* mac80211 doesn't allow mode changes while the device is up, so
4927 * take the device down, try to set the mode again, and bring the
4930 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
4932 for (i
= 0; i
< 10; i
++) {
4933 res
= i802_set_iface_flags(bss
, 0);
4934 if (res
== -EACCES
|| res
== -ENODEV
)
4937 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
4939 os_sleep(0, 100000);
4944 * Setting the mode will fail for some drivers if the phy is
4945 * on a frequency that the mode is disallowed in.
4947 if (desired_freq_params
) {
4948 res
= nl80211_set_channel(bss
, desired_freq_params
, 0);
4950 wpa_printf(MSG_DEBUG
,
4951 "nl80211: Failed to set frequency on interface");
4955 /* Try to set the mode again while the interface is down */
4956 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
4957 if (mode_switch_res
== -EBUSY
) {
4958 wpa_printf(MSG_DEBUG
,
4959 "nl80211: Delaying mode set while interface going down");
4960 os_sleep(0, 100000);
4963 ret
= mode_switch_res
;
4968 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
4969 "interface is down");
4970 drv
->nlmode
= nlmode
;
4971 drv
->ignore_if_down_event
= 1;
4974 /* Bring the interface back up */
4975 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1);
4977 wpa_printf(MSG_DEBUG
,
4978 "nl80211: Failed to set interface up after switching mode");
4984 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
4985 "from %d failed", nlmode
, drv
->nlmode
);
4989 if (is_p2p_net_interface(nlmode
)) {
4990 wpa_printf(MSG_DEBUG
,
4991 "nl80211: Interface %s mode change to P2P - disable 11b rates",
4993 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
4994 } else if (drv
->disabled_11b_rates
) {
4995 wpa_printf(MSG_DEBUG
,
4996 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
4998 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
5001 if (is_ap_interface(nlmode
)) {
5002 nl80211_mgmt_unsubscribe(bss
, "start AP");
5003 /* Setup additional AP mode functionality if needed */
5004 if (nl80211_setup_ap(bss
))
5006 } else if (was_ap
) {
5007 /* Remove additional AP mode functionality */
5008 nl80211_teardown_ap(bss
);
5010 nl80211_mgmt_unsubscribe(bss
, "mode change");
5013 if (is_mesh_interface(nlmode
) &&
5014 nl80211_mgmt_subscribe_mesh(bss
))
5017 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
5018 !is_mesh_interface(nlmode
) &&
5019 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
5020 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
5021 "frame processing - ignore for now");
5027 int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
5028 enum nl80211_iftype nlmode
)
5030 return wpa_driver_nl80211_set_mode_impl(bss
, nlmode
, NULL
);
5034 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
5035 struct hostapd_freq_params
*freq
)
5037 return wpa_driver_nl80211_set_mode_impl(bss
, NL80211_IFTYPE_ADHOC
,
5042 static int wpa_driver_nl80211_get_capa(void *priv
,
5043 struct wpa_driver_capa
*capa
)
5045 struct i802_bss
*bss
= priv
;
5046 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5048 if (!drv
->has_capability
)
5050 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
5051 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
5052 capa
->extended_capa
= drv
->extended_capa
;
5053 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
5054 capa
->extended_capa_len
= drv
->extended_capa_len
;
5061 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
5063 struct i802_bss
*bss
= priv
;
5064 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5066 wpa_printf(MSG_DEBUG
, "nl80211: Set %s operstate %d->%d (%s)",
5067 bss
->ifname
, drv
->operstate
, state
,
5068 state
? "UP" : "DORMANT");
5069 drv
->operstate
= state
;
5070 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
5071 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
5075 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
5077 struct i802_bss
*bss
= priv
;
5078 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5080 struct nl80211_sta_flag_update upd
;
5083 if (!drv
->associated
&& is_zero_ether_addr(drv
->bssid
) && !authorized
) {
5084 wpa_printf(MSG_DEBUG
, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5088 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
5089 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
5091 os_memset(&upd
, 0, sizeof(upd
));
5092 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5094 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5096 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5097 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
) ||
5098 nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
)) {
5103 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5106 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set STA flag: %d (%s)",
5107 ret
, strerror(-ret
));
5112 /* Set kernel driver on given frequency (MHz) */
5113 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
5115 struct i802_bss
*bss
= priv
;
5116 return nl80211_set_channel(bss
, freq
, 0);
5120 static inline int min_int(int a
, int b
)
5128 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
5130 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5131 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5133 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5134 genlmsg_attrlen(gnlh
, 0), NULL
);
5137 * TODO: validate the key index and mac address!
5138 * Otherwise, there's a race condition as soon as
5139 * the kernel starts sending key notifications.
5142 if (tb
[NL80211_ATTR_KEY_SEQ
])
5143 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
5144 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
5149 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
5152 struct i802_bss
*bss
= priv
;
5153 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5156 msg
= nl80211_ifindex_msg(drv
, if_nametoindex(iface
), 0,
5157 NL80211_CMD_GET_KEY
);
5159 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
5160 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, idx
)) {
5167 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
5171 static int i802_set_rts(void *priv
, int rts
)
5173 struct i802_bss
*bss
= priv
;
5174 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5184 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5185 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
)) {
5190 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5193 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
5194 "%d (%s)", rts
, ret
, strerror(-ret
));
5199 static int i802_set_frag(void *priv
, int frag
)
5201 struct i802_bss
*bss
= priv
;
5202 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5212 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5213 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
)) {
5218 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5221 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
5222 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
5227 static int i802_flush(void *priv
)
5229 struct i802_bss
*bss
= priv
;
5233 wpa_printf(MSG_DEBUG
, "nl80211: flush -> DEL_STATION %s (all)",
5237 * XXX: FIX! this needs to flush all VLANs too
5239 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
);
5240 res
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
5242 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
5243 "(%s)", res
, strerror(-res
));
5249 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
5251 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5252 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5253 struct hostap_sta_driver_data
*data
= arg
;
5254 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
5255 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
5256 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
5257 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
5258 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
5259 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
5260 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
5261 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
5264 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5265 genlmsg_attrlen(gnlh
, 0), NULL
);
5268 * TODO: validate the interface and mac address!
5269 * Otherwise, there's a race condition as soon as
5270 * the kernel starts sending station notifications.
5273 if (!tb
[NL80211_ATTR_STA_INFO
]) {
5274 wpa_printf(MSG_DEBUG
, "sta stats missing!");
5277 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
5278 tb
[NL80211_ATTR_STA_INFO
],
5280 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
5284 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
5285 data
->inactive_msec
=
5286 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
5287 if (stats
[NL80211_STA_INFO_RX_BYTES
])
5288 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
5289 if (stats
[NL80211_STA_INFO_TX_BYTES
])
5290 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
5291 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
5293 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
5294 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
5296 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
5297 if (stats
[NL80211_STA_INFO_TX_FAILED
])
5298 data
->tx_retry_failed
=
5299 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
5304 static int i802_read_sta_data(struct i802_bss
*bss
,
5305 struct hostap_sta_driver_data
*data
,
5310 os_memset(data
, 0, sizeof(*data
));
5312 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_GET_STATION
)) ||
5313 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
5318 return send_and_recv_msgs(bss
->drv
, msg
, get_sta_handler
, data
);
5322 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
5323 int cw_min
, int cw_max
, int burst_time
)
5325 struct i802_bss
*bss
= priv
;
5326 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5328 struct nlattr
*txq
, *params
;
5330 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_WIPHY
);
5334 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
5338 /* We are only sending parameters for a single TXQ at a time */
5339 params
= nla_nest_start(msg
, 1);
5345 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
))
5349 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
))
5353 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
))
5357 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
))
5361 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5362 * 32 usec, so need to convert the value here. */
5363 if (nla_put_u16(msg
, NL80211_TXQ_ATTR_TXOP
,
5364 (burst_time
* 100 + 16) / 32) ||
5365 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
) ||
5366 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
) ||
5367 nla_put_u8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
))
5370 nla_nest_end(msg
, params
);
5372 nla_nest_end(msg
, txq
);
5374 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
5383 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
5384 const char *ifname
, int vlan_id
)
5386 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5390 wpa_printf(MSG_DEBUG
, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5391 ", ifname=%s[%d], vlan_id=%d)",
5392 bss
->ifname
, if_nametoindex(bss
->ifname
),
5393 MAC2STR(addr
), ifname
, if_nametoindex(ifname
), vlan_id
);
5394 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5395 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
5396 nla_put_u32(msg
, NL80211_ATTR_STA_VLAN
, if_nametoindex(ifname
))) {
5401 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5403 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5404 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
5405 MAC2STR(addr
), ifname
, vlan_id
, ret
,
5412 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
5414 struct hostap_sta_driver_data data
;
5417 data
.inactive_msec
= (unsigned long) -1;
5418 ret
= i802_read_sta_data(priv
, &data
, addr
);
5421 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
5423 return data
.inactive_msec
/ 1000;
5427 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
5436 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
5439 struct i802_bss
*bss
= priv
;
5440 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5441 struct ieee80211_mgmt mgmt
;
5443 if (is_mesh_interface(drv
->nlmode
))
5446 if (drv
->device_ap_sme
)
5447 return wpa_driver_nl80211_sta_remove(bss
, addr
, 1, reason
);
5449 memset(&mgmt
, 0, sizeof(mgmt
));
5450 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
5451 WLAN_FC_STYPE_DEAUTH
);
5452 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
5453 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
5454 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
5455 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
5456 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
5458 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
5463 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
5466 struct i802_bss
*bss
= priv
;
5467 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5468 struct ieee80211_mgmt mgmt
;
5470 if (is_mesh_interface(drv
->nlmode
))
5473 if (drv
->device_ap_sme
)
5474 return wpa_driver_nl80211_sta_remove(bss
, addr
, 0, reason
);
5476 memset(&mgmt
, 0, sizeof(mgmt
));
5477 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
5478 WLAN_FC_STYPE_DISASSOC
);
5479 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
5480 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
5481 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
5482 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
5483 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
5485 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
5490 static void dump_ifidx(struct wpa_driver_nl80211_data
*drv
)
5492 char buf
[200], *pos
, *end
;
5496 end
= pos
+ sizeof(buf
);
5498 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
5499 if (!drv
->if_indices
[i
])
5501 res
= os_snprintf(pos
, end
- pos
, " %d", drv
->if_indices
[i
]);
5502 if (os_snprintf_error(end
- pos
, res
))
5508 wpa_printf(MSG_DEBUG
, "nl80211: if_indices[%d]:%s",
5509 drv
->num_if_indices
, buf
);
5513 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
5518 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
5520 if (have_ifidx(drv
, ifidx
)) {
5521 wpa_printf(MSG_DEBUG
, "nl80211: ifindex %d already in the list",
5525 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
5526 if (drv
->if_indices
[i
] == 0) {
5527 drv
->if_indices
[i
] = ifidx
;
5533 if (drv
->if_indices
!= drv
->default_if_indices
)
5534 old
= drv
->if_indices
;
5538 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
5540 if (!drv
->if_indices
) {
5542 drv
->if_indices
= drv
->default_if_indices
;
5544 drv
->if_indices
= old
;
5545 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
5547 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
5550 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
5551 sizeof(drv
->default_if_indices
));
5552 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
5553 drv
->num_if_indices
++;
5558 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
5562 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
5563 if (drv
->if_indices
[i
] == ifidx
) {
5564 drv
->if_indices
[i
] = 0;
5572 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
5576 for (i
= 0; i
< drv
->num_if_indices
; i
++)
5577 if (drv
->if_indices
[i
] == ifidx
)
5584 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
5585 const char *bridge_ifname
, char *ifname_wds
)
5587 struct i802_bss
*bss
= priv
;
5588 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5589 char name
[IFNAMSIZ
+ 1];
5591 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
5593 os_strlcpy(ifname_wds
, name
, IFNAMSIZ
+ 1);
5595 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
5596 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
5598 if (!if_nametoindex(name
)) {
5599 if (nl80211_create_iface(drv
, name
,
5600 NL80211_IFTYPE_AP_VLAN
,
5601 bss
->addr
, 1, NULL
, NULL
, 0) <
5604 if (bridge_ifname
&&
5605 linux_br_add_if(drv
->global
->ioctl_sock
,
5606 bridge_ifname
, name
) < 0)
5609 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
5610 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
5611 "interface %s up", name
);
5613 return i802_set_sta_vlan(priv
, addr
, name
, 0);
5616 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
5619 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
5620 nl80211_remove_iface(drv
, if_nametoindex(name
));
5626 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
5628 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
5629 struct sockaddr_ll lladdr
;
5630 unsigned char buf
[3000];
5632 socklen_t fromlen
= sizeof(lladdr
);
5634 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
5635 (struct sockaddr
*)&lladdr
, &fromlen
);
5637 wpa_printf(MSG_ERROR
, "nl80211: EAPOL recv failed: %s",
5642 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
5643 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
5647 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
5648 struct i802_bss
*bss
,
5649 const char *brname
, const char *ifname
)
5652 char in_br
[IFNAMSIZ
];
5654 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
5655 br_ifindex
= if_nametoindex(brname
);
5656 if (br_ifindex
== 0) {
5658 * Bridge was configured, but the bridge device does
5659 * not exist. Try to add it now.
5661 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
5662 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
5663 "bridge interface %s: %s",
5664 brname
, strerror(errno
));
5667 bss
->added_bridge
= 1;
5668 br_ifindex
= if_nametoindex(brname
);
5669 add_ifidx(drv
, br_ifindex
);
5671 bss
->br_ifindex
= br_ifindex
;
5673 if (linux_br_get(in_br
, ifname
) == 0) {
5674 if (os_strcmp(in_br
, brname
) == 0)
5675 return 0; /* already in the bridge */
5677 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
5678 "bridge %s", ifname
, in_br
);
5679 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
5681 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
5682 "remove interface %s from bridge "
5684 ifname
, brname
, strerror(errno
));
5689 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
5691 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
5692 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
5693 "into bridge %s: %s",
5694 ifname
, brname
, strerror(errno
));
5697 bss
->added_if_into_bridge
= 1;
5703 static void *i802_init(struct hostapd_data
*hapd
,
5704 struct wpa_init_params
*params
)
5706 struct wpa_driver_nl80211_data
*drv
;
5707 struct i802_bss
*bss
;
5709 char master_ifname
[IFNAMSIZ
];
5710 int ifindex
, br_ifindex
= 0;
5713 bss
= wpa_driver_nl80211_drv_init(hapd
, params
->ifname
,
5714 params
->global_priv
, 1,
5715 params
->bssid
, params
->driver_params
);
5721 if (linux_br_get(master_ifname
, params
->ifname
) == 0) {
5722 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
5723 params
->ifname
, master_ifname
);
5724 br_ifindex
= if_nametoindex(master_ifname
);
5725 os_strlcpy(bss
->brname
, master_ifname
, IFNAMSIZ
);
5726 } else if ((params
->num_bridge
== 0 || !params
->bridge
[0]) &&
5727 linux_master_get(master_ifname
, params
->ifname
) == 0) {
5728 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in master %s",
5729 params
->ifname
, master_ifname
);
5730 /* start listening for EAPOL on the master interface */
5731 add_ifidx(drv
, if_nametoindex(master_ifname
));
5733 master_ifname
[0] = '\0';
5736 bss
->br_ifindex
= br_ifindex
;
5738 for (i
= 0; i
< params
->num_bridge
; i
++) {
5739 if (params
->bridge
[i
]) {
5740 ifindex
= if_nametoindex(params
->bridge
[i
]);
5742 add_ifidx(drv
, ifindex
);
5743 if (ifindex
== br_ifindex
)
5748 /* start listening for EAPOL on the default AP interface */
5749 add_ifidx(drv
, drv
->ifindex
);
5751 if (params
->num_bridge
&& params
->bridge
[0]) {
5752 if (i802_check_bridge(drv
, bss
, params
->bridge
[0],
5753 params
->ifname
) < 0)
5755 if (os_strcmp(params
->bridge
[0], master_ifname
) != 0)
5759 if (!br_added
&& br_ifindex
&&
5760 (params
->num_bridge
== 0 || !params
->bridge
[0]))
5761 add_ifidx(drv
, br_ifindex
);
5763 #ifdef CONFIG_LIBNL3_ROUTE
5764 if (bss
->added_if_into_bridge
) {
5765 drv
->rtnl_sk
= nl_socket_alloc();
5766 if (drv
->rtnl_sk
== NULL
) {
5767 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate nl_sock");
5771 if (nl_connect(drv
->rtnl_sk
, NETLINK_ROUTE
)) {
5772 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
5777 #endif /* CONFIG_LIBNL3_ROUTE */
5779 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
5780 if (drv
->eapol_sock
< 0) {
5781 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
5786 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
5788 wpa_printf(MSG_INFO
, "nl80211: Could not register read socket for eapol");
5792 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
5795 os_memcpy(drv
->perm_addr
, params
->own_addr
, ETH_ALEN
);
5797 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
5802 wpa_driver_nl80211_deinit(bss
);
5807 static void i802_deinit(void *priv
)
5809 struct i802_bss
*bss
= priv
;
5810 wpa_driver_nl80211_deinit(bss
);
5814 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
5815 enum wpa_driver_if_type type
)
5818 case WPA_IF_STATION
:
5819 return NL80211_IFTYPE_STATION
;
5820 case WPA_IF_P2P_CLIENT
:
5821 case WPA_IF_P2P_GROUP
:
5822 return NL80211_IFTYPE_P2P_CLIENT
;
5823 case WPA_IF_AP_VLAN
:
5824 return NL80211_IFTYPE_AP_VLAN
;
5826 return NL80211_IFTYPE_AP
;
5828 return NL80211_IFTYPE_P2P_GO
;
5829 case WPA_IF_P2P_DEVICE
:
5830 return NL80211_IFTYPE_P2P_DEVICE
;
5832 return NL80211_IFTYPE_MESH_POINT
;
5839 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
5841 struct wpa_driver_nl80211_data
*drv
;
5842 dl_list_for_each(drv
, &global
->interfaces
,
5843 struct wpa_driver_nl80211_data
, list
) {
5844 if (os_memcmp(addr
, drv
->first_bss
->addr
, ETH_ALEN
) == 0)
5851 static int nl80211_vif_addr(struct wpa_driver_nl80211_data
*drv
, u8
*new_addr
)
5858 os_memcpy(new_addr
, drv
->first_bss
->addr
, ETH_ALEN
);
5859 for (idx
= 0; idx
< 64; idx
++) {
5860 new_addr
[0] = drv
->first_bss
->addr
[0] | 0x02;
5861 new_addr
[0] ^= idx
<< 2;
5862 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
5868 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new virtual interface address "
5869 MACSTR
, MAC2STR(new_addr
));
5878 u8 macaddr
[ETH_ALEN
];
5881 static int nl80211_wdev_handler(struct nl_msg
*msg
, void *arg
)
5883 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5884 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5885 struct wdev_info
*wi
= arg
;
5887 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5888 genlmsg_attrlen(gnlh
, 0), NULL
);
5889 if (tb
[NL80211_ATTR_WDEV
]) {
5890 wi
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
5891 wi
->wdev_id_set
= 1;
5894 if (tb
[NL80211_ATTR_MAC
])
5895 os_memcpy(wi
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
5902 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
5903 const char *ifname
, const u8
*addr
,
5904 void *bss_ctx
, void **drv_priv
,
5905 char *force_ifname
, u8
*if_addr
,
5906 const char *bridge
, int use_existing
,
5909 enum nl80211_iftype nlmode
;
5910 struct i802_bss
*bss
= priv
;
5911 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5916 os_memcpy(if_addr
, addr
, ETH_ALEN
);
5917 nlmode
= wpa_driver_nl80211_if_type(type
);
5918 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
5919 struct wdev_info p2pdev_info
;
5921 os_memset(&p2pdev_info
, 0, sizeof(p2pdev_info
));
5922 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
5923 0, nl80211_wdev_handler
,
5924 &p2pdev_info
, use_existing
);
5925 if (!p2pdev_info
.wdev_id_set
|| ifidx
!= 0) {
5926 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
5931 drv
->global
->if_add_wdevid
= p2pdev_info
.wdev_id
;
5932 drv
->global
->if_add_wdevid_set
= p2pdev_info
.wdev_id_set
;
5933 if (!is_zero_ether_addr(p2pdev_info
.macaddr
))
5934 os_memcpy(if_addr
, p2pdev_info
.macaddr
, ETH_ALEN
);
5935 wpa_printf(MSG_DEBUG
, "nl80211: New P2P Device interface %s (0x%llx) created",
5937 (long long unsigned int) p2pdev_info
.wdev_id
);
5939 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
5940 0, NULL
, NULL
, use_existing
);
5941 if (use_existing
&& ifidx
== -ENFILE
) {
5943 ifidx
= if_nametoindex(ifname
);
5944 } else if (ifidx
< 0) {
5950 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
5951 os_memcpy(if_addr
, bss
->addr
, ETH_ALEN
);
5952 else if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
5953 ifname
, if_addr
) < 0) {
5955 nl80211_remove_iface(drv
, ifidx
);
5961 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
5962 type
== WPA_IF_P2P_GO
|| type
== WPA_IF_MESH
||
5963 type
== WPA_IF_STATION
)) {
5964 /* Enforce unique address */
5965 u8 new_addr
[ETH_ALEN
];
5967 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
5970 nl80211_remove_iface(drv
, ifidx
);
5973 if (nl80211_addr_in_use(drv
->global
, new_addr
)) {
5974 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
5975 "for interface %s type %d", ifname
, type
);
5976 if (nl80211_vif_addr(drv
, new_addr
) < 0) {
5978 nl80211_remove_iface(drv
, ifidx
);
5981 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
5984 nl80211_remove_iface(drv
, ifidx
);
5988 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
5991 if (type
== WPA_IF_AP_BSS
&& setup_ap
) {
5992 struct i802_bss
*new_bss
= os_zalloc(sizeof(*new_bss
));
5993 if (new_bss
== NULL
) {
5995 nl80211_remove_iface(drv
, ifidx
);
6000 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
6001 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
6002 "interface %s to a bridge %s",
6005 nl80211_remove_iface(drv
, ifidx
);
6010 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
6013 nl80211_remove_iface(drv
, ifidx
);
6017 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
6018 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
6019 new_bss
->ifindex
= ifidx
;
6021 new_bss
->next
= drv
->first_bss
->next
;
6022 new_bss
->freq
= drv
->first_bss
->freq
;
6023 new_bss
->ctx
= bss_ctx
;
6024 new_bss
->added_if
= added
;
6025 drv
->first_bss
->next
= new_bss
;
6027 *drv_priv
= new_bss
;
6028 nl80211_init_bss(new_bss
);
6030 /* Subscribe management frames for this WPA_IF_AP_BSS */
6031 if (nl80211_setup_ap(new_bss
))
6036 drv
->global
->if_add_ifindex
= ifidx
;
6039 * Some virtual interfaces need to process EAPOL packets and events on
6040 * the parent interface. This is used mainly with hostapd.
6044 nlmode
== NL80211_IFTYPE_AP_VLAN
||
6045 nlmode
== NL80211_IFTYPE_WDS
||
6046 nlmode
== NL80211_IFTYPE_MONITOR
))
6047 add_ifidx(drv
, ifidx
);
6053 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
6054 enum wpa_driver_if_type type
,
6057 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6058 int ifindex
= if_nametoindex(ifname
);
6060 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6061 __func__
, type
, ifname
, ifindex
, bss
->added_if
);
6062 if (ifindex
> 0 && (bss
->added_if
|| bss
->ifindex
!= ifindex
))
6063 nl80211_remove_iface(drv
, ifindex
);
6064 else if (ifindex
> 0 && !bss
->added_if
) {
6065 struct wpa_driver_nl80211_data
*drv2
;
6066 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
6067 struct wpa_driver_nl80211_data
, list
)
6068 del_ifidx(drv2
, ifindex
);
6071 if (type
!= WPA_IF_AP_BSS
)
6074 if (bss
->added_if_into_bridge
) {
6075 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
6077 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6078 "interface %s from bridge %s: %s",
6079 bss
->ifname
, bss
->brname
, strerror(errno
));
6081 if (bss
->added_bridge
) {
6082 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
6083 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6085 bss
->brname
, strerror(errno
));
6088 if (bss
!= drv
->first_bss
) {
6089 struct i802_bss
*tbss
;
6091 wpa_printf(MSG_DEBUG
, "nl80211: Not the first BSS - remove it");
6092 for (tbss
= drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
6093 if (tbss
->next
== bss
) {
6094 tbss
->next
= bss
->next
;
6095 /* Unsubscribe management frames */
6096 nl80211_teardown_ap(bss
);
6097 nl80211_destroy_bss(bss
);
6099 i802_set_iface_flags(bss
, 0);
6106 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
6107 "BSS %p in the list", __func__
, bss
);
6109 wpa_printf(MSG_DEBUG
, "nl80211: First BSS - reassign context");
6110 nl80211_teardown_ap(bss
);
6111 if (!bss
->added_if
&& !drv
->first_bss
->next
)
6112 wpa_driver_nl80211_del_beacon(drv
);
6113 nl80211_destroy_bss(bss
);
6115 i802_set_iface_flags(bss
, 0);
6116 if (drv
->first_bss
->next
) {
6117 drv
->first_bss
= drv
->first_bss
->next
;
6118 drv
->ctx
= drv
->first_bss
->ctx
;
6121 wpa_printf(MSG_DEBUG
, "nl80211: No second BSS to reassign context to");
6129 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
6131 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6132 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6134 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6135 genlmsg_attrlen(gnlh
, 0), NULL
);
6136 if (tb
[NL80211_ATTR_COOKIE
])
6137 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
6142 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
6143 unsigned int freq
, unsigned int wait
,
6144 const u8
*buf
, size_t buf_len
,
6145 u64
*cookie_out
, int no_cck
, int no_ack
,
6146 int offchanok
, const u16
*csa_offs
,
6147 size_t csa_offs_len
)
6149 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6154 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
6155 "no_ack=%d offchanok=%d",
6156 freq
, wait
, no_cck
, no_ack
, offchanok
);
6157 wpa_hexdump(MSG_MSGDUMP
, "CMD_FRAME", buf
, buf_len
);
6159 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME
)) ||
6160 (freq
&& nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
6161 (wait
&& nla_put_u32(msg
, NL80211_ATTR_DURATION
, wait
)) ||
6162 (offchanok
&& ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
6163 drv
->test_use_roc_tx
) &&
6164 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
)) ||
6165 (no_cck
&& nla_put_flag(msg
, NL80211_ATTR_TX_NO_CCK_RATE
)) ||
6166 (no_ack
&& nla_put_flag(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
)) ||
6167 (csa_offs
&& nla_put(msg
, NL80211_ATTR_CSA_C_OFFSETS_TX
,
6168 csa_offs_len
* sizeof(u16
), csa_offs
)) ||
6169 nla_put(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
))
6173 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6176 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
6177 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
6180 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
6181 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
6182 (long long unsigned int) cookie
);
6185 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
6187 if (drv
->num_send_action_cookies
== MAX_SEND_ACTION_COOKIES
) {
6188 wpa_printf(MSG_DEBUG
,
6189 "nl80211: Drop oldest pending send action cookie 0x%llx",
6190 (long long unsigned int)
6191 drv
->send_action_cookies
[0]);
6192 os_memmove(&drv
->send_action_cookies
[0],
6193 &drv
->send_action_cookies
[1],
6194 (MAX_SEND_ACTION_COOKIES
- 1) *
6196 drv
->num_send_action_cookies
--;
6198 drv
->send_action_cookies
[drv
->num_send_action_cookies
] = cookie
;
6199 drv
->num_send_action_cookies
++;
6208 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
6210 unsigned int wait_time
,
6211 const u8
*dst
, const u8
*src
,
6213 const u8
*data
, size_t data_len
,
6216 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6219 struct ieee80211_hdr
*hdr
;
6221 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
6222 "freq=%u MHz wait=%d ms no_cck=%d)",
6223 drv
->ifindex
, freq
, wait_time
, no_cck
);
6225 buf
= os_zalloc(24 + data_len
);
6228 os_memcpy(buf
+ 24, data
, data_len
);
6229 hdr
= (struct ieee80211_hdr
*) buf
;
6230 hdr
->frame_control
=
6231 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
6232 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
6233 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
6234 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
6236 if (is_ap_interface(drv
->nlmode
) &&
6237 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
6238 (int) freq
== bss
->freq
|| drv
->device_ap_sme
||
6240 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
6242 wait_time
, NULL
, 0);
6244 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
6246 &drv
->send_action_cookie
,
6247 no_cck
, 0, 1, NULL
, 0);
6254 static void nl80211_frame_wait_cancel(struct i802_bss
*bss
, u64 cookie
)
6256 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6260 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
6261 (long long unsigned int) cookie
);
6262 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
)) ||
6263 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
)) {
6268 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6270 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
6271 "(%s)", ret
, strerror(-ret
));
6275 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
6277 struct i802_bss
*bss
= priv
;
6278 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6282 /* Cancel the last pending TX cookie */
6283 nl80211_frame_wait_cancel(bss
, drv
->send_action_cookie
);
6286 * Cancel the other pending TX cookies, if any. This is needed since
6287 * the driver may keep a list of all pending offchannel TX operations
6288 * and free up the radio only once they have expired or cancelled.
6290 for (i
= drv
->num_send_action_cookies
; i
> 0; i
--) {
6291 cookie
= drv
->send_action_cookies
[i
- 1];
6292 if (cookie
!= drv
->send_action_cookie
)
6293 nl80211_frame_wait_cancel(bss
, cookie
);
6295 drv
->num_send_action_cookies
= 0;
6299 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
6300 unsigned int duration
)
6302 struct i802_bss
*bss
= priv
;
6303 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6308 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
)) ||
6309 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
6310 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
)) {
6316 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6318 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
6319 "0x%llx for freq=%u MHz duration=%u",
6320 (long long unsigned int) cookie
, freq
, duration
);
6321 drv
->remain_on_chan_cookie
= cookie
;
6322 drv
->pending_remain_on_chan
= 1;
6325 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
6326 "(freq=%d duration=%u): %d (%s)",
6327 freq
, duration
, ret
, strerror(-ret
));
6332 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
6334 struct i802_bss
*bss
= priv
;
6335 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6339 if (!drv
->pending_remain_on_chan
) {
6340 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
6345 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
6347 (long long unsigned int) drv
->remain_on_chan_cookie
);
6349 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
6351 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
)) {
6356 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6359 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
6360 "%d (%s)", ret
, strerror(-ret
));
6365 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
6367 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6370 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
6371 is_ap_interface(drv
->nlmode
) && !bss
->in_deinit
&&
6374 * Do not disable Probe Request reporting that was
6375 * enabled in nl80211_setup_ap().
6377 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
6378 "Probe Request reporting nl_preq=%p while "
6379 "in AP mode", bss
->nl_preq
);
6380 } else if (bss
->nl_preq
) {
6381 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
6382 "reporting nl_preq=%p", bss
->nl_preq
);
6383 nl80211_destroy_eloop_handle(&bss
->nl_preq
);
6389 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
6390 "already on! nl_preq=%p", bss
->nl_preq
);
6394 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
6395 if (bss
->nl_preq
== NULL
)
6397 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
6398 "reporting nl_preq=%p", bss
->nl_preq
);
6400 if (nl80211_register_frame(bss
, bss
->nl_preq
,
6401 (WLAN_FC_TYPE_MGMT
<< 2) |
6402 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
6406 nl80211_register_eloop_read(&bss
->nl_preq
,
6407 wpa_driver_nl80211_event_receive
,
6413 nl_destroy_handles(&bss
->nl_preq
);
6418 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
6419 int ifindex
, int disabled
)
6422 struct nlattr
*bands
, *band
;
6425 wpa_printf(MSG_DEBUG
,
6426 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
6427 ifindex
, disabled
? "NL80211_TXRATE_LEGACY=OFDM-only" :
6428 "no NL80211_TXRATE_LEGACY constraint");
6430 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0,
6431 NL80211_CMD_SET_TX_BITRATE_MASK
);
6435 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
6440 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6441 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6442 * rates. All 5 GHz rates are left enabled.
6444 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
6446 (disabled
&& nla_put(msg
, NL80211_TXRATE_LEGACY
, 8,
6447 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
6449 nla_nest_end(msg
, band
);
6451 nla_nest_end(msg
, bands
);
6453 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6455 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
6456 "(%s)", ret
, strerror(-ret
));
6458 drv
->disabled_11b_rates
= disabled
;
6468 static int wpa_driver_nl80211_deinit_ap(void *priv
)
6470 struct i802_bss
*bss
= priv
;
6471 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6472 if (!is_ap_interface(drv
->nlmode
))
6474 wpa_driver_nl80211_del_beacon(drv
);
6475 bss
->beacon_set
= 0;
6478 * If the P2P GO interface was dynamically added, then it is
6479 * possible that the interface change to station is not possible.
6481 if (drv
->nlmode
== NL80211_IFTYPE_P2P_GO
&& bss
->if_dynamic
)
6484 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
6488 static int wpa_driver_nl80211_stop_ap(void *priv
)
6490 struct i802_bss
*bss
= priv
;
6491 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6492 if (!is_ap_interface(drv
->nlmode
))
6494 wpa_driver_nl80211_del_beacon(drv
);
6495 bss
->beacon_set
= 0;
6500 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
6502 struct i802_bss
*bss
= priv
;
6503 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6504 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
6508 * If the P2P Client interface was dynamically added, then it is
6509 * possible that the interface change to station is not possible.
6511 if (bss
->if_dynamic
)
6514 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
6518 static void wpa_driver_nl80211_resume(void *priv
)
6520 struct i802_bss
*bss
= priv
;
6521 enum nl80211_iftype nlmode
= nl80211_get_ifmode(bss
);
6523 if (i802_set_iface_flags(bss
, 1))
6524 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on resume event");
6526 if (is_p2p_net_interface(nlmode
))
6527 nl80211_disable_11b_rates(bss
->drv
, bss
->drv
->ifindex
, 1);
6531 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
6533 struct i802_bss
*bss
= priv
;
6534 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6538 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
6539 "hysteresis=%d", threshold
, hysteresis
);
6541 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_CQM
)) ||
6542 !(cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
)) ||
6543 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
) ||
6544 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
)) {
6548 nla_nest_end(msg
, cqm
);
6550 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6554 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
6556 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6557 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6558 struct wpa_signal_info
*sig_change
= arg
;
6560 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6561 genlmsg_attrlen(gnlh
, 0), NULL
);
6563 sig_change
->center_frq1
= -1;
6564 sig_change
->center_frq2
= -1;
6565 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
6567 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
6568 sig_change
->chanwidth
= convert2width(
6569 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
6570 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
6571 sig_change
->center_frq1
=
6572 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
6573 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
6574 sig_change
->center_frq2
=
6575 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
6582 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
6583 struct wpa_signal_info
*sig
)
6587 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_INTERFACE
);
6588 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
6592 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
6594 struct i802_bss
*bss
= priv
;
6595 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6598 os_memset(si
, 0, sizeof(*si
));
6599 res
= nl80211_get_link_signal(drv
, si
);
6601 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
&&
6602 drv
->nlmode
!= NL80211_IFTYPE_MESH_POINT
)
6604 si
->current_signal
= 0;
6607 res
= nl80211_get_channel_width(drv
, si
);
6611 return nl80211_get_link_noise(drv
, si
);
6615 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
6618 struct i802_bss
*bss
= priv
;
6619 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
6620 0, 0, 0, 0, NULL
, 0);
6624 static int nl80211_set_param(void *priv
, const char *param
)
6626 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
6631 if (os_strstr(param
, "use_p2p_group_interface=1")) {
6632 struct i802_bss
*bss
= priv
;
6633 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6635 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
6637 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
6638 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
6640 #endif /* CONFIG_P2P */
6642 if (os_strstr(param
, "use_monitor=1")) {
6643 struct i802_bss
*bss
= priv
;
6644 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6645 drv
->use_monitor
= 1;
6648 if (os_strstr(param
, "force_connect_cmd=1")) {
6649 struct i802_bss
*bss
= priv
;
6650 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6651 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_SME
;
6652 drv
->force_connect_cmd
= 1;
6655 if (os_strstr(param
, "no_offchannel_tx=1")) {
6656 struct i802_bss
*bss
= priv
;
6657 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6658 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
6659 drv
->test_use_roc_tx
= 1;
6666 static void * nl80211_global_init(void)
6668 struct nl80211_global
*global
;
6669 struct netlink_config
*cfg
;
6671 global
= os_zalloc(sizeof(*global
));
6674 global
->ioctl_sock
= -1;
6675 dl_list_init(&global
->interfaces
);
6676 global
->if_add_ifindex
= -1;
6678 cfg
= os_zalloc(sizeof(*cfg
));
6683 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
6684 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
6685 global
->netlink
= netlink_init(cfg
);
6686 if (global
->netlink
== NULL
) {
6691 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
6694 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
6695 if (global
->ioctl_sock
< 0) {
6696 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
6704 nl80211_global_deinit(global
);
6709 static void nl80211_global_deinit(void *priv
)
6711 struct nl80211_global
*global
= priv
;
6714 if (!dl_list_empty(&global
->interfaces
)) {
6715 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
6716 "nl80211_global_deinit",
6717 dl_list_len(&global
->interfaces
));
6720 if (global
->netlink
)
6721 netlink_deinit(global
->netlink
);
6723 nl_destroy_handles(&global
->nl
);
6725 if (global
->nl_event
)
6726 nl80211_destroy_eloop_handle(&global
->nl_event
);
6728 nl_cb_put(global
->nl_cb
);
6730 if (global
->ioctl_sock
>= 0)
6731 close(global
->ioctl_sock
);
6737 static const char * nl80211_get_radio_name(void *priv
)
6739 struct i802_bss
*bss
= priv
;
6740 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6741 return drv
->phyname
;
6745 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
6750 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
6751 (pmkid
&& nla_put(msg
, NL80211_ATTR_PMKID
, 16, pmkid
)) ||
6752 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))) {
6757 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
6761 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
6763 struct i802_bss
*bss
= priv
;
6764 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
6765 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
6769 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
6771 struct i802_bss
*bss
= priv
;
6772 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
6774 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
6778 static int nl80211_flush_pmkid(void *priv
)
6780 struct i802_bss
*bss
= priv
;
6781 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
6782 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
6786 static void clean_survey_results(struct survey_results
*survey_results
)
6788 struct freq_survey
*survey
, *tmp
;
6790 if (dl_list_empty(&survey_results
->survey_list
))
6793 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
6794 struct freq_survey
, list
) {
6795 dl_list_del(&survey
->list
);
6801 static void add_survey(struct nlattr
**sinfo
, u32 ifidx
,
6802 struct dl_list
*survey_list
)
6804 struct freq_survey
*survey
;
6806 survey
= os_zalloc(sizeof(struct freq_survey
));
6810 survey
->ifidx
= ifidx
;
6811 survey
->freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
6814 if (sinfo
[NL80211_SURVEY_INFO_NOISE
]) {
6815 survey
->nf
= (int8_t)
6816 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
6817 survey
->filled
|= SURVEY_HAS_NF
;
6820 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]) {
6821 survey
->channel_time
=
6822 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]);
6823 survey
->filled
|= SURVEY_HAS_CHAN_TIME
;
6826 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]) {
6827 survey
->channel_time_busy
=
6828 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]);
6829 survey
->filled
|= SURVEY_HAS_CHAN_TIME_BUSY
;
6832 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]) {
6833 survey
->channel_time_rx
=
6834 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]);
6835 survey
->filled
|= SURVEY_HAS_CHAN_TIME_RX
;
6838 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]) {
6839 survey
->channel_time_tx
=
6840 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]);
6841 survey
->filled
|= SURVEY_HAS_CHAN_TIME_TX
;
6844 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)",
6847 (unsigned long int) survey
->channel_time
,
6848 (unsigned long int) survey
->channel_time_busy
,
6849 (unsigned long int) survey
->channel_time_tx
,
6850 (unsigned long int) survey
->channel_time_rx
,
6853 dl_list_add_tail(survey_list
, &survey
->list
);
6857 static int check_survey_ok(struct nlattr
**sinfo
, u32 surveyed_freq
,
6858 unsigned int freq_filter
)
6863 return freq_filter
== surveyed_freq
;
6867 static int survey_handler(struct nl_msg
*msg
, void *arg
)
6869 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6870 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6871 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
6872 struct survey_results
*survey_results
;
6873 u32 surveyed_freq
= 0;
6876 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
6877 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
6878 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
6881 survey_results
= (struct survey_results
*) arg
;
6883 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6884 genlmsg_attrlen(gnlh
, 0), NULL
);
6886 if (!tb
[NL80211_ATTR_IFINDEX
])
6889 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
6891 if (!tb
[NL80211_ATTR_SURVEY_INFO
])
6894 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
6895 tb
[NL80211_ATTR_SURVEY_INFO
],
6899 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) {
6900 wpa_printf(MSG_ERROR
, "nl80211: Invalid survey data");
6904 surveyed_freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
6906 if (!check_survey_ok(sinfo
, surveyed_freq
,
6907 survey_results
->freq_filter
))
6910 if (survey_results
->freq_filter
&&
6911 survey_results
->freq_filter
!= surveyed_freq
) {
6912 wpa_printf(MSG_EXCESSIVE
, "nl80211: Ignoring survey data for freq %d MHz",
6917 add_survey(sinfo
, ifidx
, &survey_results
->survey_list
);
6923 static int wpa_driver_nl80211_get_survey(void *priv
, unsigned int freq
)
6925 struct i802_bss
*bss
= priv
;
6926 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6929 union wpa_event_data data
;
6930 struct survey_results
*survey_results
;
6932 os_memset(&data
, 0, sizeof(data
));
6933 survey_results
= &data
.survey_results
;
6935 dl_list_init(&survey_results
->survey_list
);
6937 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
6942 data
.survey_results
.freq_filter
= freq
;
6945 wpa_printf(MSG_DEBUG
, "nl80211: Fetch survey data");
6946 err
= send_and_recv_msgs(drv
, msg
, survey_handler
,
6951 wpa_printf(MSG_ERROR
, "nl80211: Failed to process survey data");
6953 wpa_supplicant_event(drv
->ctx
, EVENT_SURVEY
, &data
);
6955 clean_survey_results(survey_results
);
6960 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, size_t kek_len
,
6961 const u8
*kck
, size_t kck_len
,
6962 const u8
*replay_ctr
)
6964 struct i802_bss
*bss
= priv
;
6965 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6966 struct nlattr
*replay_nested
;
6970 if (!drv
->set_rekey_offload
)
6973 wpa_printf(MSG_DEBUG
, "nl80211: Set rekey offload");
6974 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
)) ||
6975 !(replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
)) ||
6976 nla_put(msg
, NL80211_REKEY_DATA_KEK
, kek_len
, kek
) ||
6977 nla_put(msg
, NL80211_REKEY_DATA_KCK
, kck_len
, kck
) ||
6978 nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
6980 nl80211_nlmsg_clear(msg
);
6985 nla_nest_end(msg
, replay_nested
);
6987 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
6988 if (ret
== -EOPNOTSUPP
) {
6989 wpa_printf(MSG_DEBUG
,
6990 "nl80211: Driver does not support rekey offload");
6991 drv
->set_rekey_offload
= 0;
6996 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
6997 const u8
*addr
, int qos
)
6999 /* send data frame to poll STA and check whether
7000 * this frame is ACKed */
7002 struct ieee80211_hdr hdr
;
7004 } STRUCT_PACKED nulldata
;
7007 /* Send data frame to poll STA and check whether this frame is ACKed */
7009 os_memset(&nulldata
, 0, sizeof(nulldata
));
7012 nulldata
.hdr
.frame_control
=
7013 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7014 WLAN_FC_STYPE_QOS_NULL
);
7015 size
= sizeof(nulldata
);
7017 nulldata
.hdr
.frame_control
=
7018 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7019 WLAN_FC_STYPE_NULLFUNC
);
7020 size
= sizeof(struct ieee80211_hdr
);
7023 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7024 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7025 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7026 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7028 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
7030 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
7034 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
7037 struct i802_bss
*bss
= priv
;
7038 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7042 if (!drv
->poll_command_supported
) {
7043 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
7047 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_PROBE_CLIENT
)) ||
7048 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7053 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7055 wpa_printf(MSG_DEBUG
, "nl80211: Client probe request for "
7056 MACSTR
" failed: ret=%d (%s)",
7057 MAC2STR(addr
), ret
, strerror(-ret
));
7062 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
7066 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_POWER_SAVE
)) ||
7067 nla_put_u32(msg
, NL80211_ATTR_PS_STATE
,
7068 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
)) {
7072 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
7076 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
7079 struct i802_bss
*bss
= priv
;
7081 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
7082 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
7084 if (opp_ps
!= -1 || ctwindow
!= -1) {
7086 wpa_driver_set_p2p_ps(priv
, legacy_ps
, opp_ps
, ctwindow
);
7087 #else /* ANDROID_P2P */
7088 return -1; /* Not yet supported */
7089 #endif /* ANDROID_P2P */
7092 if (legacy_ps
== -1)
7094 if (legacy_ps
!= 0 && legacy_ps
!= 1)
7095 return -1; /* Not yet supported */
7097 return nl80211_set_power_save(bss
, legacy_ps
);
7101 static int nl80211_start_radar_detection(void *priv
,
7102 struct hostapd_freq_params
*freq
)
7104 struct i802_bss
*bss
= priv
;
7105 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7109 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)",
7110 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
7111 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
7113 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
7114 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
7119 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_RADAR_DETECT
)) ||
7120 nl80211_put_freq_params(msg
, freq
) < 0) {
7125 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7128 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
7129 "%d (%s)", ret
, strerror(-ret
));
7135 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
7136 u8 dialog_token
, u16 status_code
,
7137 u32 peer_capab
, int initiator
, const u8
*buf
,
7140 struct i802_bss
*bss
= priv
;
7141 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7144 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
7150 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_MGMT
)) ||
7151 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
7152 nla_put_u8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
) ||
7153 nla_put_u8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
) ||
7154 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
))
7158 * The internal enum tdls_peer_capability definition is
7159 * currently identical with the nl80211 enum
7160 * nl80211_tdls_peer_capability, so no conversion is needed
7163 if (nla_put_u32(msg
, NL80211_ATTR_TDLS_PEER_CAPABILITY
,
7168 nla_put_flag(msg
, NL80211_ATTR_TDLS_INITIATOR
)) ||
7169 nla_put(msg
, NL80211_ATTR_IE
, len
, buf
))
7172 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7180 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
7182 struct i802_bss
*bss
= priv
;
7183 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7185 enum nl80211_tdls_operation nl80211_oper
;
7187 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
7191 case TDLS_DISCOVERY_REQ
:
7192 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
7195 nl80211_oper
= NL80211_TDLS_SETUP
;
7198 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
7200 case TDLS_ENABLE_LINK
:
7201 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
7203 case TDLS_DISABLE_LINK
:
7204 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
7214 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_OPER
)) ||
7215 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
) ||
7216 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
)) {
7221 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7226 nl80211_tdls_enable_channel_switch(void *priv
, const u8
*addr
, u8 oper_class
,
7227 const struct hostapd_freq_params
*params
)
7229 struct i802_bss
*bss
= priv
;
7230 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7234 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
7235 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
7238 wpa_printf(MSG_DEBUG
, "nl80211: Enable TDLS channel switch " MACSTR
7239 " oper_class=%u freq=%u",
7240 MAC2STR(addr
), oper_class
, params
->freq
);
7241 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH
);
7243 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
7244 nla_put_u8(msg
, NL80211_ATTR_OPER_CLASS
, oper_class
) ||
7245 (ret
= nl80211_put_freq_params(msg
, params
))) {
7247 wpa_printf(MSG_DEBUG
, "nl80211: Could not build TDLS chan switch");
7251 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7256 nl80211_tdls_disable_channel_switch(void *priv
, const u8
*addr
)
7258 struct i802_bss
*bss
= priv
;
7259 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7262 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
7263 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
7266 wpa_printf(MSG_DEBUG
, "nl80211: Disable TDLS channel switch " MACSTR
,
7268 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
);
7270 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7272 wpa_printf(MSG_DEBUG
,
7273 "nl80211: Could not build TDLS cancel chan switch");
7277 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7280 #endif /* CONFIG TDLS */
7283 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
7284 enum wpa_alg alg
, const u8
*addr
,
7285 int key_idx
, int set_tx
,
7286 const u8
*seq
, size_t seq_len
,
7287 const u8
*key
, size_t key_len
)
7289 struct i802_bss
*bss
= priv
;
7290 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
7291 set_tx
, seq
, seq_len
, key
, key_len
);
7295 static int driver_nl80211_scan2(void *priv
,
7296 struct wpa_driver_scan_params
*params
)
7298 struct i802_bss
*bss
= priv
;
7299 #ifdef CONFIG_DRIVER_NL80211_QCA
7300 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7303 * Do a vendor specific scan if possible. If only_new_results is
7304 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
7305 * cannot be achieved through a vendor scan. The below condition may
7306 * need to be modified if new scan flags are added in the future whose
7307 * functionality can only be achieved through a normal scan.
7309 if (drv
->scan_vendor_cmd_avail
&& !params
->only_new_results
)
7310 return wpa_driver_nl80211_vendor_scan(bss
, params
);
7311 #endif /* CONFIG_DRIVER_NL80211_QCA */
7312 return wpa_driver_nl80211_scan(bss
, params
);
7316 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
7319 struct i802_bss
*bss
= priv
;
7320 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
7324 static int driver_nl80211_authenticate(void *priv
,
7325 struct wpa_driver_auth_params
*params
)
7327 struct i802_bss
*bss
= priv
;
7328 return wpa_driver_nl80211_authenticate(bss
, params
);
7332 static void driver_nl80211_deinit(void *priv
)
7334 struct i802_bss
*bss
= priv
;
7335 wpa_driver_nl80211_deinit(bss
);
7339 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
7342 struct i802_bss
*bss
= priv
;
7343 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
7347 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
7348 size_t data_len
, int noack
,
7350 const u16
*csa_offs
, size_t csa_offs_len
)
7352 struct i802_bss
*bss
= priv
;
7353 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
7354 freq
, 0, 0, 0, csa_offs
,
7359 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
7361 struct i802_bss
*bss
= priv
;
7362 return wpa_driver_nl80211_sta_remove(bss
, addr
, -1, 0);
7366 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
7367 const char *ifname
, int vlan_id
)
7369 struct i802_bss
*bss
= priv
;
7370 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
7374 static int driver_nl80211_read_sta_data(void *priv
,
7375 struct hostap_sta_driver_data
*data
,
7378 struct i802_bss
*bss
= priv
;
7379 return i802_read_sta_data(bss
, data
, addr
);
7383 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
7384 unsigned int wait_time
,
7385 const u8
*dst
, const u8
*src
,
7387 const u8
*data
, size_t data_len
,
7390 struct i802_bss
*bss
= priv
;
7391 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
7392 bssid
, data
, data_len
, no_cck
);
7396 static int driver_nl80211_probe_req_report(void *priv
, int report
)
7398 struct i802_bss
*bss
= priv
;
7399 return wpa_driver_nl80211_probe_req_report(bss
, report
);
7403 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
7404 const u8
*ies
, size_t ies_len
)
7408 struct i802_bss
*bss
= priv
;
7409 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7410 u16 mdid
= WPA_GET_LE16(md
);
7412 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
7413 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_UPDATE_FT_IES
)) ||
7414 nla_put(msg
, NL80211_ATTR_IE
, ies_len
, ies
) ||
7415 nla_put_u16(msg
, NL80211_ATTR_MDID
, mdid
)) {
7420 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7422 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
7423 "err=%d (%s)", ret
, strerror(-ret
));
7430 const u8
* wpa_driver_nl80211_get_macaddr(void *priv
)
7432 struct i802_bss
*bss
= priv
;
7433 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7435 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
7442 static const char * scan_state_str(enum scan_states scan_state
)
7444 switch (scan_state
) {
7447 case SCAN_REQUESTED
:
7448 return "SCAN_REQUESTED";
7450 return "SCAN_STARTED";
7451 case SCAN_COMPLETED
:
7452 return "SCAN_COMPLETED";
7454 return "SCAN_ABORTED";
7455 case SCHED_SCAN_STARTED
:
7456 return "SCHED_SCAN_STARTED";
7457 case SCHED_SCAN_STOPPED
:
7458 return "SCHED_SCAN_STOPPED";
7459 case SCHED_SCAN_RESULTS
:
7460 return "SCHED_SCAN_RESULTS";
7467 static int wpa_driver_nl80211_status(void *priv
, char *buf
, size_t buflen
)
7469 struct i802_bss
*bss
= priv
;
7470 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7477 res
= os_snprintf(pos
, end
- pos
,
7489 bss
->beacon_set
? "beacon_set=1\n" : "",
7490 bss
->added_if_into_bridge
?
7491 "added_if_into_bridge=1\n" : "",
7492 bss
->added_bridge
? "added_bridge=1\n" : "",
7493 bss
->in_deinit
? "in_deinit=1\n" : "",
7494 bss
->if_dynamic
? "if_dynamic=1\n" : "");
7495 if (os_snprintf_error(end
- pos
, res
))
7499 if (bss
->wdev_id_set
) {
7500 res
= os_snprintf(pos
, end
- pos
, "wdev_id=%llu\n",
7501 (unsigned long long) bss
->wdev_id
);
7502 if (os_snprintf_error(end
- pos
, res
))
7507 res
= os_snprintf(pos
, end
- pos
,
7509 "perm_addr=" MACSTR
"\n"
7513 "auth_bssid=" MACSTR
"\n"
7514 "auth_attempt_bssid=" MACSTR
"\n"
7515 "bssid=" MACSTR
"\n"
7516 "prev_bssid=" MACSTR
"\n"
7520 "monitor_ifidx=%d\n"
7521 "monitor_refcount=%d\n"
7522 "last_mgmt_freq=%u\n"
7523 "eapol_tx_sock=%d\n"
7524 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
7526 MAC2STR(drv
->perm_addr
),
7529 scan_state_str(drv
->scan_state
),
7530 MAC2STR(drv
->auth_bssid
),
7531 MAC2STR(drv
->auth_attempt_bssid
),
7532 MAC2STR(drv
->bssid
),
7533 MAC2STR(drv
->prev_bssid
),
7538 drv
->monitor_refcount
,
7539 drv
->last_mgmt_freq
,
7541 drv
->ignore_if_down_event
?
7542 "ignore_if_down_event=1\n" : "",
7543 drv
->scan_complete_events
?
7544 "scan_complete_events=1\n" : "",
7545 drv
->disabled_11b_rates
?
7546 "disabled_11b_rates=1\n" : "",
7547 drv
->pending_remain_on_chan
?
7548 "pending_remain_on_chan=1\n" : "",
7549 drv
->in_interface_list
? "in_interface_list=1\n" : "",
7550 drv
->device_ap_sme
? "device_ap_sme=1\n" : "",
7551 drv
->poll_command_supported
?
7552 "poll_command_supported=1\n" : "",
7553 drv
->data_tx_status
? "data_tx_status=1\n" : "",
7554 drv
->scan_for_auth
? "scan_for_auth=1\n" : "",
7555 drv
->retry_auth
? "retry_auth=1\n" : "",
7556 drv
->use_monitor
? "use_monitor=1\n" : "",
7557 drv
->ignore_next_local_disconnect
?
7558 "ignore_next_local_disconnect=1\n" : "",
7559 drv
->ignore_next_local_deauth
?
7560 "ignore_next_local_deauth=1\n" : "");
7561 if (os_snprintf_error(end
- pos
, res
))
7565 if (drv
->has_capability
) {
7566 res
= os_snprintf(pos
, end
- pos
,
7567 "capa.key_mgmt=0x%x\n"
7570 "capa.flags=0x%llx\n"
7571 "capa.rrm_flags=0x%x\n"
7572 "capa.max_scan_ssids=%d\n"
7573 "capa.max_sched_scan_ssids=%d\n"
7574 "capa.sched_scan_supported=%d\n"
7575 "capa.max_match_sets=%d\n"
7576 "capa.max_remain_on_chan=%u\n"
7577 "capa.max_stations=%u\n"
7578 "capa.probe_resp_offloads=0x%x\n"
7579 "capa.max_acl_mac_addrs=%u\n"
7580 "capa.num_multichan_concurrent=%u\n"
7581 "capa.mac_addr_rand_sched_scan_supported=%d\n"
7582 "capa.mac_addr_rand_scan_supported=%d\n"
7583 "capa.conc_capab=%u\n"
7584 "capa.max_conc_chan_2_4=%u\n"
7585 "capa.max_conc_chan_5_0=%u\n"
7586 "capa.max_sched_scan_plans=%u\n"
7587 "capa.max_sched_scan_plan_interval=%u\n"
7588 "capa.max_sched_scan_plan_iterations=%u\n",
7592 (unsigned long long) drv
->capa
.flags
,
7593 drv
->capa
.rrm_flags
,
7594 drv
->capa
.max_scan_ssids
,
7595 drv
->capa
.max_sched_scan_ssids
,
7596 drv
->capa
.sched_scan_supported
,
7597 drv
->capa
.max_match_sets
,
7598 drv
->capa
.max_remain_on_chan
,
7599 drv
->capa
.max_stations
,
7600 drv
->capa
.probe_resp_offloads
,
7601 drv
->capa
.max_acl_mac_addrs
,
7602 drv
->capa
.num_multichan_concurrent
,
7603 drv
->capa
.mac_addr_rand_sched_scan_supported
,
7604 drv
->capa
.mac_addr_rand_scan_supported
,
7605 drv
->capa
.conc_capab
,
7606 drv
->capa
.max_conc_chan_2_4
,
7607 drv
->capa
.max_conc_chan_5_0
,
7608 drv
->capa
.max_sched_scan_plans
,
7609 drv
->capa
.max_sched_scan_plan_interval
,
7610 drv
->capa
.max_sched_scan_plan_iterations
);
7611 if (os_snprintf_error(end
- pos
, res
))
7620 static int set_beacon_data(struct nl_msg
*msg
, struct beacon_data
*settings
)
7622 if ((settings
->head
&&
7623 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
,
7624 settings
->head_len
, settings
->head
)) ||
7626 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
,
7627 settings
->tail_len
, settings
->tail
)) ||
7628 (settings
->beacon_ies
&&
7629 nla_put(msg
, NL80211_ATTR_IE
,
7630 settings
->beacon_ies_len
, settings
->beacon_ies
)) ||
7631 (settings
->proberesp_ies
&&
7632 nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
7633 settings
->proberesp_ies_len
, settings
->proberesp_ies
)) ||
7634 (settings
->assocresp_ies
&&
7635 nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
7636 settings
->assocresp_ies_len
, settings
->assocresp_ies
)) ||
7637 (settings
->probe_resp
&&
7638 nla_put(msg
, NL80211_ATTR_PROBE_RESP
,
7639 settings
->probe_resp_len
, settings
->probe_resp
)))
7646 static int nl80211_switch_channel(void *priv
, struct csa_settings
*settings
)
7649 struct i802_bss
*bss
= priv
;
7650 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7651 struct nlattr
*beacon_csa
;
7653 int csa_off_len
= 0;
7656 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
7657 settings
->cs_count
, settings
->block_tx
,
7658 settings
->freq_params
.freq
, settings
->freq_params
.bandwidth
,
7659 settings
->freq_params
.center_freq1
,
7660 settings
->freq_params
.center_freq2
);
7662 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
7663 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support channel switch command");
7667 if ((drv
->nlmode
!= NL80211_IFTYPE_AP
) &&
7668 (drv
->nlmode
!= NL80211_IFTYPE_P2P_GO
))
7672 * Remove empty counters, assuming Probe Response and Beacon frame
7673 * counters match. This implementation assumes that there are only two
7676 if (settings
->counter_offset_beacon
[0] &&
7677 !settings
->counter_offset_beacon
[1]) {
7679 } else if (settings
->counter_offset_beacon
[1] &&
7680 !settings
->counter_offset_beacon
[0]) {
7682 settings
->counter_offset_beacon
[0] =
7683 settings
->counter_offset_beacon
[1];
7684 settings
->counter_offset_presp
[0] =
7685 settings
->counter_offset_presp
[1];
7686 } else if (settings
->counter_offset_beacon
[1] &&
7687 settings
->counter_offset_beacon
[0]) {
7690 wpa_printf(MSG_ERROR
, "nl80211: No CSA counters provided");
7694 /* Check CSA counters validity */
7695 if (drv
->capa
.max_csa_counters
&&
7696 csa_off_len
> drv
->capa
.max_csa_counters
) {
7697 wpa_printf(MSG_ERROR
,
7698 "nl80211: Too many CSA counters provided");
7702 if (!settings
->beacon_csa
.tail
)
7705 for (i
= 0; i
< csa_off_len
; i
++) {
7706 u16 csa_c_off_bcn
= settings
->counter_offset_beacon
[i
];
7707 u16 csa_c_off_presp
= settings
->counter_offset_presp
[i
];
7709 if ((settings
->beacon_csa
.tail_len
<= csa_c_off_bcn
) ||
7710 (settings
->beacon_csa
.tail
[csa_c_off_bcn
] !=
7711 settings
->cs_count
))
7714 if (settings
->beacon_csa
.probe_resp
&&
7715 ((settings
->beacon_csa
.probe_resp_len
<=
7717 (settings
->beacon_csa
.probe_resp
[csa_c_off_presp
] !=
7718 settings
->cs_count
)))
7722 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_CHANNEL_SWITCH
)) ||
7723 nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
,
7724 settings
->cs_count
) ||
7725 (ret
= nl80211_put_freq_params(msg
, &settings
->freq_params
)) ||
7726 (settings
->block_tx
&&
7727 nla_put_flag(msg
, NL80211_ATTR_CH_SWITCH_BLOCK_TX
)))
7730 /* beacon_after params */
7731 ret
= set_beacon_data(msg
, &settings
->beacon_after
);
7735 /* beacon_csa params */
7736 beacon_csa
= nla_nest_start(msg
, NL80211_ATTR_CSA_IES
);
7740 ret
= set_beacon_data(msg
, &settings
->beacon_csa
);
7744 if (nla_put(msg
, NL80211_ATTR_CSA_C_OFF_BEACON
,
7745 csa_off_len
* sizeof(u16
),
7746 settings
->counter_offset_beacon
) ||
7747 (settings
->beacon_csa
.probe_resp
&&
7748 nla_put(msg
, NL80211_ATTR_CSA_C_OFF_PRESP
,
7749 csa_off_len
* sizeof(u16
),
7750 settings
->counter_offset_presp
)))
7753 nla_nest_end(msg
, beacon_csa
);
7754 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7756 wpa_printf(MSG_DEBUG
, "nl80211: switch_channel failed err=%d (%s)",
7757 ret
, strerror(-ret
));
7765 wpa_printf(MSG_DEBUG
, "nl80211: Could not build channel switch request");
7770 static int nl80211_add_ts(void *priv
, u8 tsid
, const u8
*addr
,
7771 u8 user_priority
, u16 admitted_time
)
7773 struct i802_bss
*bss
= priv
;
7774 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7778 wpa_printf(MSG_DEBUG
,
7779 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
7780 tsid
, admitted_time
, user_priority
);
7782 if (!is_sta_interface(drv
->nlmode
))
7785 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_ADD_TX_TS
);
7787 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
7788 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
7789 nla_put_u8(msg
, NL80211_ATTR_USER_PRIO
, user_priority
) ||
7790 nla_put_u16(msg
, NL80211_ATTR_ADMITTED_TIME
, admitted_time
)) {
7795 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7797 wpa_printf(MSG_DEBUG
, "nl80211: add_ts failed err=%d (%s)",
7798 ret
, strerror(-ret
));
7803 static int nl80211_del_ts(void *priv
, u8 tsid
, const u8
*addr
)
7805 struct i802_bss
*bss
= priv
;
7806 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7810 wpa_printf(MSG_DEBUG
, "nl80211: del_ts request: tsid=%u", tsid
);
7812 if (!is_sta_interface(drv
->nlmode
))
7815 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_TX_TS
)) ||
7816 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
7817 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7822 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7824 wpa_printf(MSG_DEBUG
, "nl80211: del_ts failed err=%d (%s)",
7825 ret
, strerror(-ret
));
7830 #ifdef CONFIG_TESTING_OPTIONS
7831 static int cmd_reply_handler(struct nl_msg
*msg
, void *arg
)
7833 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7834 struct wpabuf
*buf
= arg
;
7839 if ((size_t) genlmsg_attrlen(gnlh
, 0) > wpabuf_tailroom(buf
)) {
7840 wpa_printf(MSG_INFO
, "nl80211: insufficient buffer space for reply");
7844 wpabuf_put_data(buf
, genlmsg_attrdata(gnlh
, 0),
7845 genlmsg_attrlen(gnlh
, 0));
7849 #endif /* CONFIG_TESTING_OPTIONS */
7852 static int vendor_reply_handler(struct nl_msg
*msg
, void *arg
)
7854 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7855 struct nlattr
*nl_vendor_reply
, *nl
;
7856 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7857 struct wpabuf
*buf
= arg
;
7863 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7864 genlmsg_attrlen(gnlh
, 0), NULL
);
7865 nl_vendor_reply
= tb
[NL80211_ATTR_VENDOR_DATA
];
7867 if (!nl_vendor_reply
)
7870 if ((size_t) nla_len(nl_vendor_reply
) > wpabuf_tailroom(buf
)) {
7871 wpa_printf(MSG_INFO
, "nl80211: Vendor command: insufficient buffer space for reply");
7875 nla_for_each_nested(nl
, nl_vendor_reply
, rem
) {
7876 wpabuf_put_data(buf
, nla_data(nl
), nla_len(nl
));
7883 static int nl80211_vendor_cmd(void *priv
, unsigned int vendor_id
,
7884 unsigned int subcmd
, const u8
*data
,
7885 size_t data_len
, struct wpabuf
*buf
)
7887 struct i802_bss
*bss
= priv
;
7888 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7892 #ifdef CONFIG_TESTING_OPTIONS
7893 if (vendor_id
== 0xffffffff) {
7894 msg
= nlmsg_alloc();
7898 nl80211_cmd(drv
, msg
, 0, subcmd
);
7899 if (nlmsg_append(msg
, (void *) data
, data_len
, NLMSG_ALIGNTO
) <
7902 ret
= send_and_recv_msgs(drv
, msg
, cmd_reply_handler
, buf
);
7904 wpa_printf(MSG_DEBUG
, "nl80211: command failed err=%d",
7908 #endif /* CONFIG_TESTING_OPTIONS */
7910 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_VENDOR
)) ||
7911 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, vendor_id
) ||
7912 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
) ||
7914 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, data_len
, data
)))
7917 ret
= send_and_recv_msgs(drv
, msg
, vendor_reply_handler
, buf
);
7919 wpa_printf(MSG_DEBUG
, "nl80211: vendor command failed err=%d",
7929 static int nl80211_set_qos_map(void *priv
, const u8
*qos_map_set
,
7932 struct i802_bss
*bss
= priv
;
7933 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7937 wpa_hexdump(MSG_DEBUG
, "nl80211: Setting QoS Map",
7938 qos_map_set
, qos_map_set_len
);
7940 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_QOS_MAP
)) ||
7941 nla_put(msg
, NL80211_ATTR_QOS_MAP
, qos_map_set_len
, qos_map_set
)) {
7946 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7948 wpa_printf(MSG_DEBUG
, "nl80211: Setting QoS Map failed");
7954 static int nl80211_set_wowlan(void *priv
,
7955 const struct wowlan_triggers
*triggers
)
7957 struct i802_bss
*bss
= priv
;
7958 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7960 struct nlattr
*wowlan_triggers
;
7963 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan");
7965 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_SET_WOWLAN
)) ||
7966 !(wowlan_triggers
= nla_nest_start(msg
,
7967 NL80211_ATTR_WOWLAN_TRIGGERS
)) ||
7969 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7970 (triggers
->disconnect
&&
7971 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7972 (triggers
->magic_pkt
&&
7973 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7974 (triggers
->gtk_rekey_failure
&&
7975 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7976 (triggers
->eap_identity_req
&&
7977 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7978 (triggers
->four_way_handshake
&&
7979 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7980 (triggers
->rfkill_release
&&
7981 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))) {
7986 nla_nest_end(msg
, wowlan_triggers
);
7988 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7990 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan failed");
7996 #ifdef CONFIG_DRIVER_NL80211_QCA
7997 static int nl80211_roaming(void *priv
, int allowed
, const u8
*bssid
)
7999 struct i802_bss
*bss
= priv
;
8000 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8002 struct nlattr
*params
;
8004 wpa_printf(MSG_DEBUG
, "nl80211: Roaming policy: allowed=%d", allowed
);
8006 if (!drv
->roaming_vendor_cmd_avail
) {
8007 wpa_printf(MSG_DEBUG
,
8008 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
8012 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8013 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8014 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8015 QCA_NL80211_VENDOR_SUBCMD_ROAMING
) ||
8016 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8017 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY
,
8018 allowed
? QCA_ROAMING_ALLOWED_WITHIN_ESS
:
8019 QCA_ROAMING_NOT_ALLOWED
) ||
8021 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_MAC_ADDR
, ETH_ALEN
, bssid
))) {
8025 nla_nest_end(msg
, params
);
8027 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8029 #endif /* CONFIG_DRIVER_NL80211_QCA */
8032 static int nl80211_set_mac_addr(void *priv
, const u8
*addr
)
8034 struct i802_bss
*bss
= priv
;
8035 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8036 int new_addr
= addr
!= NULL
;
8039 addr
= drv
->perm_addr
;
8041 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) < 0)
8044 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
, addr
) < 0)
8046 wpa_printf(MSG_DEBUG
,
8047 "nl80211: failed to set_mac_addr for %s to " MACSTR
,
8048 bss
->ifname
, MAC2STR(addr
));
8049 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
8051 wpa_printf(MSG_DEBUG
,
8052 "nl80211: Could not restore interface UP after failed set_mac_addr");
8057 wpa_printf(MSG_DEBUG
, "nl80211: set_mac_addr for %s to " MACSTR
,
8058 bss
->ifname
, MAC2STR(addr
));
8059 drv
->addr_changed
= new_addr
;
8060 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
8062 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1) < 0)
8064 wpa_printf(MSG_DEBUG
,
8065 "nl80211: Could not restore interface UP after set_mac_addr");
8074 static int wpa_driver_nl80211_init_mesh(void *priv
)
8076 if (wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_MESH_POINT
)) {
8077 wpa_printf(MSG_INFO
,
8078 "nl80211: Failed to set interface into mesh mode");
8085 static int nl80211_put_mesh_id(struct nl_msg
*msg
, const u8
*mesh_id
,
8089 wpa_hexdump_ascii(MSG_DEBUG
, " * Mesh ID (SSID)",
8090 mesh_id
, mesh_id_len
);
8091 return nla_put(msg
, NL80211_ATTR_MESH_ID
, mesh_id_len
, mesh_id
);
8098 static int nl80211_join_mesh(struct i802_bss
*bss
,
8099 struct wpa_driver_mesh_join_params
*params
)
8101 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8103 struct nlattr
*container
;
8106 wpa_printf(MSG_DEBUG
, "nl80211: mesh join (ifindex=%d)", drv
->ifindex
);
8107 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_MESH
);
8109 nl80211_put_freq_params(msg
, ¶ms
->freq
) ||
8110 nl80211_put_basic_rates(msg
, params
->basic_rates
) ||
8111 nl80211_put_mesh_id(msg
, params
->meshid
, params
->meshid_len
) ||
8112 nl80211_put_beacon_int(msg
, params
->beacon_int
))
8115 wpa_printf(MSG_DEBUG
, " * flags=%08X", params
->flags
);
8117 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_SETUP
);
8122 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ies
, params
->ie_len
);
8123 if (nla_put(msg
, NL80211_MESH_SETUP_IE
, params
->ie_len
,
8127 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
8128 if (params
->flags
& WPA_DRIVER_MESH_FLAG_SAE_AUTH
) {
8129 if (nla_put_u8(msg
, NL80211_MESH_SETUP_AUTH_PROTOCOL
, 0x1) ||
8130 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AUTH
))
8133 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_AMPE
) &&
8134 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AMPE
))
8136 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
) &&
8137 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_MPM
))
8139 nla_nest_end(msg
, container
);
8141 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
8145 if (!(params
->conf
.flags
& WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
) &&
8146 nla_put_u32(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, 0))
8148 if ((params
->conf
.flags
& WPA_DRIVER_MESH_FLAG_DRIVER_MPM
) &&
8149 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
8150 params
->max_peer_links
))
8154 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
8155 * the timer could disconnect stations even in that case.
8157 if (nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
8158 params
->conf
.peer_link_timeout
)) {
8159 wpa_printf(MSG_ERROR
, "nl80211: Failed to set PLINK_TIMEOUT");
8163 nla_nest_end(msg
, container
);
8165 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8168 wpa_printf(MSG_DEBUG
, "nl80211: mesh join failed: ret=%d (%s)",
8169 ret
, strerror(-ret
));
8173 bss
->freq
= params
->freq
.freq
;
8174 wpa_printf(MSG_DEBUG
, "nl80211: mesh join request send successfully");
8183 wpa_driver_nl80211_join_mesh(void *priv
,
8184 struct wpa_driver_mesh_join_params
*params
)
8186 struct i802_bss
*bss
= priv
;
8189 timeout
= params
->conf
.peer_link_timeout
;
8191 /* Disable kernel inactivity timer */
8192 if (params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
)
8193 params
->conf
.peer_link_timeout
= 0;
8195 ret
= nl80211_join_mesh(bss
, params
);
8196 if (ret
== -EINVAL
&& params
->conf
.peer_link_timeout
== 0) {
8197 wpa_printf(MSG_DEBUG
,
8198 "nl80211: Mesh join retry for peer_link_timeout");
8200 * Old kernel does not support setting
8201 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
8202 * into future from peer_link_timeout.
8204 params
->conf
.peer_link_timeout
= timeout
+ 60;
8205 ret
= nl80211_join_mesh(priv
, params
);
8208 params
->conf
.peer_link_timeout
= timeout
;
8213 static int wpa_driver_nl80211_leave_mesh(void *priv
)
8215 struct i802_bss
*bss
= priv
;
8216 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8220 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave (ifindex=%d)", drv
->ifindex
);
8221 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_MESH
);
8222 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8224 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave failed: ret=%d (%s)",
8225 ret
, strerror(-ret
));
8227 wpa_printf(MSG_DEBUG
,
8228 "nl80211: mesh leave request send successfully");
8231 if (wpa_driver_nl80211_set_mode(drv
->first_bss
,
8232 NL80211_IFTYPE_STATION
)) {
8233 wpa_printf(MSG_INFO
,
8234 "nl80211: Failed to set interface into station mode");
8239 #endif /* CONFIG_MESH */
8242 static int wpa_driver_br_add_ip_neigh(void *priv
, u8 version
,
8243 const u8
*ipaddr
, int prefixlen
,
8246 #ifdef CONFIG_LIBNL3_ROUTE
8247 struct i802_bss
*bss
= priv
;
8248 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8249 struct rtnl_neigh
*rn
;
8250 struct nl_addr
*nl_ipaddr
= NULL
;
8251 struct nl_addr
*nl_lladdr
= NULL
;
8252 int family
, addrsize
;
8255 if (!ipaddr
|| prefixlen
== 0 || !addr
)
8258 if (bss
->br_ifindex
== 0) {
8259 wpa_printf(MSG_DEBUG
,
8260 "nl80211: bridge must be set before adding an ip neigh to it");
8264 if (!drv
->rtnl_sk
) {
8265 wpa_printf(MSG_DEBUG
,
8266 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8273 } else if (version
== 6) {
8280 rn
= rtnl_neigh_alloc();
8284 /* set the destination ip address for neigh */
8285 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
8286 if (nl_ipaddr
== NULL
) {
8287 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
8291 nl_addr_set_prefixlen(nl_ipaddr
, prefixlen
);
8292 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
8294 wpa_printf(MSG_DEBUG
,
8295 "nl80211: neigh set destination addr failed");
8299 /* set the corresponding lladdr for neigh */
8300 nl_lladdr
= nl_addr_build(AF_BRIDGE
, (u8
*) addr
, ETH_ALEN
);
8301 if (nl_lladdr
== NULL
) {
8302 wpa_printf(MSG_DEBUG
, "nl80211: neigh set lladdr failed");
8306 rtnl_neigh_set_lladdr(rn
, nl_lladdr
);
8308 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
8309 rtnl_neigh_set_state(rn
, NUD_PERMANENT
);
8311 res
= rtnl_neigh_add(drv
->rtnl_sk
, rn
, NLM_F_CREATE
);
8313 wpa_printf(MSG_DEBUG
,
8314 "nl80211: Adding bridge ip neigh failed: %s",
8319 nl_addr_put(nl_lladdr
);
8321 nl_addr_put(nl_ipaddr
);
8325 #else /* CONFIG_LIBNL3_ROUTE */
8327 #endif /* CONFIG_LIBNL3_ROUTE */
8331 static int wpa_driver_br_delete_ip_neigh(void *priv
, u8 version
,
8334 #ifdef CONFIG_LIBNL3_ROUTE
8335 struct i802_bss
*bss
= priv
;
8336 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8337 struct rtnl_neigh
*rn
;
8338 struct nl_addr
*nl_ipaddr
;
8339 int family
, addrsize
;
8348 } else if (version
== 6) {
8355 if (bss
->br_ifindex
== 0) {
8356 wpa_printf(MSG_DEBUG
,
8357 "nl80211: bridge must be set to delete an ip neigh");
8361 if (!drv
->rtnl_sk
) {
8362 wpa_printf(MSG_DEBUG
,
8363 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8367 rn
= rtnl_neigh_alloc();
8371 /* set the destination ip address for neigh */
8372 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
8373 if (nl_ipaddr
== NULL
) {
8374 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
8378 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
8380 wpa_printf(MSG_DEBUG
,
8381 "nl80211: neigh set destination addr failed");
8385 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
8387 res
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
8389 wpa_printf(MSG_DEBUG
,
8390 "nl80211: Deleting bridge ip neigh failed: %s",
8395 nl_addr_put(nl_ipaddr
);
8399 #else /* CONFIG_LIBNL3_ROUTE */
8401 #endif /* CONFIG_LIBNL3_ROUTE */
8405 static int linux_write_system_file(const char *path
, unsigned int val
)
8410 len
= os_snprintf(buf
, sizeof(buf
), "%u\n", val
);
8411 if (os_snprintf_error(sizeof(buf
), len
))
8414 fd
= open(path
, O_WRONLY
);
8418 if (write(fd
, buf
, len
) < 0) {
8419 wpa_printf(MSG_DEBUG
,
8420 "nl80211: Failed to write Linux system file: %s with the value of %d",
8431 static const char * drv_br_port_attr_str(enum drv_br_port_attr attr
)
8434 case DRV_BR_PORT_ATTR_PROXYARP
:
8435 return "proxyarp_wifi";
8436 case DRV_BR_PORT_ATTR_HAIRPIN_MODE
:
8437 return "hairpin_mode";
8444 static int wpa_driver_br_port_set_attr(void *priv
, enum drv_br_port_attr attr
,
8447 struct i802_bss
*bss
= priv
;
8449 const char *attr_txt
;
8451 attr_txt
= drv_br_port_attr_str(attr
);
8452 if (attr_txt
== NULL
)
8455 os_snprintf(path
, sizeof(path
), "/sys/class/net/%s/brport/%s",
8456 bss
->ifname
, attr_txt
);
8458 if (linux_write_system_file(path
, val
))
8465 static const char * drv_br_net_param_str(enum drv_br_net_param param
)
8468 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
8469 return "arp_accept";
8476 static int wpa_driver_br_set_net_param(void *priv
, enum drv_br_net_param param
,
8479 struct i802_bss
*bss
= priv
;
8481 const char *param_txt
;
8484 if (param
== DRV_BR_MULTICAST_SNOOPING
) {
8485 os_snprintf(path
, sizeof(path
),
8486 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
8491 param_txt
= drv_br_net_param_str(param
);
8492 if (param_txt
== NULL
)
8496 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
8503 os_snprintf(path
, sizeof(path
), "/proc/sys/net/ipv%d/conf/%s/%s",
8504 ip_version
, bss
->brname
, param_txt
);
8507 if (linux_write_system_file(path
, val
))
8514 #ifdef CONFIG_DRIVER_NL80211_QCA
8516 static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode
)
8519 case HOSTAPD_MODE_IEEE80211B
:
8520 return QCA_ACS_MODE_IEEE80211B
;
8521 case HOSTAPD_MODE_IEEE80211G
:
8522 return QCA_ACS_MODE_IEEE80211G
;
8523 case HOSTAPD_MODE_IEEE80211A
:
8524 return QCA_ACS_MODE_IEEE80211A
;
8525 case HOSTAPD_MODE_IEEE80211AD
:
8526 return QCA_ACS_MODE_IEEE80211AD
;
8527 case HOSTAPD_MODE_IEEE80211ANY
:
8528 return QCA_ACS_MODE_IEEE80211ANY
;
8535 static int add_acs_freq_list(struct nl_msg
*msg
, const int *freq_list
)
8542 len
= int_array_len(freq_list
);
8543 freqs
= os_malloc(sizeof(u32
) * len
);
8546 for (i
= 0; i
< len
; i
++)
8547 freqs
[i
] = freq_list
[i
];
8548 ret
= nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST
,
8549 sizeof(u32
) * len
, freqs
);
8555 static int wpa_driver_do_acs(void *priv
, struct drv_acs_params
*params
)
8557 struct i802_bss
*bss
= priv
;
8558 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8560 struct nlattr
*data
;
8564 mode
= hw_mode_to_qca_acs(params
->hw_mode
);
8568 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8569 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8570 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8571 QCA_NL80211_VENDOR_SUBCMD_DO_ACS
) ||
8572 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8573 nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE
, mode
) ||
8574 (params
->ht_enabled
&&
8575 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED
)) ||
8576 (params
->ht40_enabled
&&
8577 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED
)) ||
8578 (params
->vht_enabled
&&
8579 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED
)) ||
8580 nla_put_u16(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH
,
8581 params
->ch_width
) ||
8582 (params
->ch_list_len
&&
8583 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST
, params
->ch_list_len
,
8584 params
->ch_list
)) ||
8585 add_acs_freq_list(msg
, params
->freq_list
)) {
8589 nla_nest_end(msg
, data
);
8591 wpa_printf(MSG_DEBUG
,
8592 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
8593 params
->hw_mode
, params
->ht_enabled
, params
->ht40_enabled
,
8594 params
->vht_enabled
, params
->ch_width
, params
->ch_list_len
);
8596 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8598 wpa_printf(MSG_DEBUG
,
8599 "nl80211: Failed to invoke driver ACS function: %s",
8606 static int nl80211_set_band(void *priv
, enum set_band band
)
8608 struct i802_bss
*bss
= priv
;
8609 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8611 struct nlattr
*data
;
8613 enum qca_set_band qca_band
;
8615 if (!drv
->setband_vendor_cmd_avail
)
8619 case WPA_SETBAND_AUTO
:
8620 qca_band
= QCA_SETBAND_AUTO
;
8622 case WPA_SETBAND_5G
:
8623 qca_band
= QCA_SETBAND_5G
;
8625 case WPA_SETBAND_2G
:
8626 qca_band
= QCA_SETBAND_2G
;
8632 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8633 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8634 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8635 QCA_NL80211_VENDOR_SUBCMD_SETBAND
) ||
8636 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8637 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE
, qca_band
)) {
8641 nla_nest_end(msg
, data
);
8643 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8645 wpa_printf(MSG_DEBUG
,
8646 "nl80211: Driver setband function failed: %s",
8653 struct nl80211_pcl
{
8655 unsigned int *freq_list
;
8658 static int preferred_freq_info_handler(struct nl_msg
*msg
, void *arg
)
8660 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8661 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8662 struct nl80211_pcl
*param
= arg
;
8663 struct nlattr
*nl_vend
, *attr
;
8664 enum qca_iface_type iface_type
;
8665 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
8666 unsigned int num
, max_num
;
8669 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8670 genlmsg_attrlen(gnlh
, 0), NULL
);
8672 nl_vend
= tb
[NL80211_ATTR_VENDOR_DATA
];
8676 nla_parse(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
8677 nla_data(nl_vend
), nla_len(nl_vend
), NULL
);
8680 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
];
8682 wpa_printf(MSG_ERROR
, "nl80211: iface_type couldn't be found");
8687 iface_type
= (enum qca_iface_type
) nla_get_u32(attr
);
8688 wpa_printf(MSG_DEBUG
, "nl80211: Driver returned iface_type=%d",
8691 attr
= tb_vendor
[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST
];
8693 wpa_printf(MSG_ERROR
,
8694 "nl80211: preferred_freq_list couldn't be found");
8700 * param->num has the maximum number of entries for which there
8701 * is room in the freq_list provided by the caller.
8703 freqs
= nla_data(attr
);
8704 max_num
= nla_len(attr
) / sizeof(u32
);
8705 if (max_num
> param
->num
)
8706 max_num
= param
->num
;
8707 for (num
= 0; num
< max_num
; num
++)
8708 param
->freq_list
[num
] = freqs
[num
];
8715 static int nl80211_get_pref_freq_list(void *priv
,
8716 enum wpa_driver_if_type if_type
,
8718 unsigned int *freq_list
)
8720 struct i802_bss
*bss
= priv
;
8721 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8725 struct nlattr
*params
;
8726 struct nl80211_pcl param
;
8727 enum qca_iface_type iface_type
;
8729 if (!drv
->get_pref_freq_list
)
8733 case WPA_IF_STATION
:
8734 iface_type
= QCA_IFACE_TYPE_STA
;
8737 iface_type
= QCA_IFACE_TYPE_AP
;
8740 iface_type
= QCA_IFACE_TYPE_P2P_GO
;
8742 case WPA_IF_P2P_CLIENT
:
8743 iface_type
= QCA_IFACE_TYPE_P2P_CLIENT
;
8746 iface_type
= QCA_IFACE_TYPE_IBSS
;
8749 iface_type
= QCA_IFACE_TYPE_TDLS
;
8756 param
.freq_list
= freq_list
;
8758 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8759 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
) ||
8760 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8761 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8762 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST
) ||
8763 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8765 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
,
8767 wpa_printf(MSG_ERROR
,
8768 "%s: err in adding vendor_cmd and vendor_data",
8773 nla_nest_end(msg
, params
);
8775 os_memset(freq_list
, 0, *num
* sizeof(freq_list
[0]));
8776 ret
= send_and_recv_msgs(drv
, msg
, preferred_freq_info_handler
, ¶m
);
8778 wpa_printf(MSG_ERROR
,
8779 "%s: err in send_and_recv_msgs", __func__
);
8785 for (i
= 0; i
< *num
; i
++) {
8786 wpa_printf(MSG_DEBUG
, "nl80211: preferred_channel_list[%d]=%d",
8794 static int nl80211_set_prob_oper_freq(void *priv
, unsigned int freq
)
8796 struct i802_bss
*bss
= priv
;
8797 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8800 struct nlattr
*params
;
8802 if (!drv
->set_prob_oper_freq
)
8805 wpa_printf(MSG_DEBUG
,
8806 "nl80211: Set P2P probable operating freq %u for ifindex %d",
8807 freq
, bss
->ifindex
);
8809 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8810 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8811 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8812 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL
) ||
8813 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8815 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE
,
8816 QCA_IFACE_TYPE_P2P_CLIENT
) ||
8818 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ
,
8820 wpa_printf(MSG_ERROR
,
8821 "%s: err in adding vendor_cmd and vendor_data",
8826 nla_nest_end(msg
, params
);
8828 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8831 wpa_printf(MSG_ERROR
, "%s: err in send_and_recv_msgs",
8839 #endif /* CONFIG_DRIVER_NL80211_QCA */
8842 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
8844 .desc
= "Linux nl80211/cfg80211",
8845 .get_bssid
= wpa_driver_nl80211_get_bssid
,
8846 .get_ssid
= wpa_driver_nl80211_get_ssid
,
8847 .set_key
= driver_nl80211_set_key
,
8848 .scan2
= driver_nl80211_scan2
,
8849 .sched_scan
= wpa_driver_nl80211_sched_scan
,
8850 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
8851 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
8852 .abort_scan
= wpa_driver_nl80211_abort_scan
,
8853 .deauthenticate
= driver_nl80211_deauthenticate
,
8854 .authenticate
= driver_nl80211_authenticate
,
8855 .associate
= wpa_driver_nl80211_associate
,
8856 .global_init
= nl80211_global_init
,
8857 .global_deinit
= nl80211_global_deinit
,
8858 .init2
= wpa_driver_nl80211_init
,
8859 .deinit
= driver_nl80211_deinit
,
8860 .get_capa
= wpa_driver_nl80211_get_capa
,
8861 .set_operstate
= wpa_driver_nl80211_set_operstate
,
8862 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
8863 .set_country
= wpa_driver_nl80211_set_country
,
8864 .get_country
= wpa_driver_nl80211_get_country
,
8865 .set_ap
= wpa_driver_nl80211_set_ap
,
8866 .set_acl
= wpa_driver_nl80211_set_acl
,
8867 .if_add
= wpa_driver_nl80211_if_add
,
8868 .if_remove
= driver_nl80211_if_remove
,
8869 .send_mlme
= driver_nl80211_send_mlme
,
8870 .get_hw_feature_data
= nl80211_get_hw_feature_data
,
8871 .sta_add
= wpa_driver_nl80211_sta_add
,
8872 .sta_remove
= driver_nl80211_sta_remove
,
8873 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
8874 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
8875 .hapd_init
= i802_init
,
8876 .hapd_deinit
= i802_deinit
,
8877 .set_wds_sta
= i802_set_wds_sta
,
8878 .get_seqnum
= i802_get_seqnum
,
8879 .flush
= i802_flush
,
8880 .get_inact_sec
= i802_get_inact_sec
,
8881 .sta_clear_stats
= i802_sta_clear_stats
,
8882 .set_rts
= i802_set_rts
,
8883 .set_frag
= i802_set_frag
,
8884 .set_tx_queue_params
= i802_set_tx_queue_params
,
8885 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
8886 .sta_deauth
= i802_sta_deauth
,
8887 .sta_disassoc
= i802_sta_disassoc
,
8888 .read_sta_data
= driver_nl80211_read_sta_data
,
8889 .set_freq
= i802_set_freq
,
8890 .send_action
= driver_nl80211_send_action
,
8891 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
8892 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
8893 .cancel_remain_on_channel
=
8894 wpa_driver_nl80211_cancel_remain_on_channel
,
8895 .probe_req_report
= driver_nl80211_probe_req_report
,
8896 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
8897 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
8898 .resume
= wpa_driver_nl80211_resume
,
8899 .signal_monitor
= nl80211_signal_monitor
,
8900 .signal_poll
= nl80211_signal_poll
,
8901 .send_frame
= nl80211_send_frame
,
8902 .set_param
= nl80211_set_param
,
8903 .get_radio_name
= nl80211_get_radio_name
,
8904 .add_pmkid
= nl80211_add_pmkid
,
8905 .remove_pmkid
= nl80211_remove_pmkid
,
8906 .flush_pmkid
= nl80211_flush_pmkid
,
8907 .set_rekey_info
= nl80211_set_rekey_info
,
8908 .poll_client
= nl80211_poll_client
,
8909 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
8910 .start_dfs_cac
= nl80211_start_radar_detection
,
8911 .stop_ap
= wpa_driver_nl80211_stop_ap
,
8913 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
8914 .tdls_oper
= nl80211_tdls_oper
,
8915 .tdls_enable_channel_switch
= nl80211_tdls_enable_channel_switch
,
8916 .tdls_disable_channel_switch
= nl80211_tdls_disable_channel_switch
,
8917 #endif /* CONFIG_TDLS */
8918 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,
8919 .get_mac_addr
= wpa_driver_nl80211_get_macaddr
,
8920 .get_survey
= wpa_driver_nl80211_get_survey
,
8921 .status
= wpa_driver_nl80211_status
,
8922 .switch_channel
= nl80211_switch_channel
,
8924 .set_noa
= wpa_driver_set_p2p_noa
,
8925 .get_noa
= wpa_driver_get_p2p_noa
,
8926 .set_ap_wps_ie
= wpa_driver_set_ap_wps_p2p_ie
,
8927 #endif /* ANDROID_P2P */
8929 #ifndef ANDROID_LIB_STUB
8930 .driver_cmd
= wpa_driver_nl80211_driver_cmd
,
8931 #endif /* !ANDROID_LIB_STUB */
8932 #endif /* ANDROID */
8933 .vendor_cmd
= nl80211_vendor_cmd
,
8934 .set_qos_map
= nl80211_set_qos_map
,
8935 .set_wowlan
= nl80211_set_wowlan
,
8936 #ifdef CONFIG_DRIVER_NL80211_QCA
8937 .roaming
= nl80211_roaming
,
8938 #endif /* CONFIG_DRIVER_NL80211_QCA */
8939 .set_mac_addr
= nl80211_set_mac_addr
,
8941 .init_mesh
= wpa_driver_nl80211_init_mesh
,
8942 .join_mesh
= wpa_driver_nl80211_join_mesh
,
8943 .leave_mesh
= wpa_driver_nl80211_leave_mesh
,
8944 #endif /* CONFIG_MESH */
8945 .br_add_ip_neigh
= wpa_driver_br_add_ip_neigh
,
8946 .br_delete_ip_neigh
= wpa_driver_br_delete_ip_neigh
,
8947 .br_port_set_attr
= wpa_driver_br_port_set_attr
,
8948 .br_set_net_param
= wpa_driver_br_set_net_param
,
8949 .add_tx_ts
= nl80211_add_ts
,
8950 .del_tx_ts
= nl80211_del_ts
,
8951 #ifdef CONFIG_DRIVER_NL80211_QCA
8952 .do_acs
= wpa_driver_do_acs
,
8953 .set_band
= nl80211_set_band
,
8954 .get_pref_freq_list
= nl80211_get_pref_freq_list
,
8955 .set_prob_oper_freq
= nl80211_set_prob_oper_freq
,
8956 #endif /* CONFIG_DRIVER_NL80211_QCA */