2 * WPA Supplicant - testing driver interface
3 * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 /* Make sure we get winsock2.h for Windows build to get sockaddr_storage */
16 #include "build_config.h"
17 #ifdef CONFIG_NATIVE_WINDOWS
19 #endif /* CONFIG_NATIVE_WINDOWS */
23 #ifndef CONFIG_NATIVE_WINDOWS
27 #define DRIVER_TEST_UNIX
28 #endif /* CONFIG_NATIVE_WINDOWS */
32 #include "l2_packet/l2_packet.h"
35 #include "ieee802_11_defs.h"
40 #include "../../hostapd/hostapd.h"
41 #include "../../hostapd/wpa.h"
42 #include "../../hostapd/hw_features.h"
43 #include "../../hostapd/wps_hostapd.h"
46 struct test_client_socket
{
47 struct test_client_socket
*next
;
49 struct sockaddr_un un
;
51 struct test_driver_bss
*bss
;
54 struct test_driver_bss
{
55 struct test_driver_bss
*next
;
56 char ifname
[IFNAMSIZ
+ 1];
61 size_t wps_beacon_ie_len
;
62 u8
*wps_probe_resp_ie
;
63 size_t wps_probe_resp_ie_len
;
69 struct test_driver_data
{
70 struct hostapd_data
*hapd
;
71 struct test_client_socket
*cli
;
73 struct test_driver_bss
*bss
;
75 char *own_socket_path
;
81 struct wpa_driver_test_global
{
85 struct wpa_driver_test_data
{
86 struct wpa_driver_test_global
*global
;
88 u8 own_addr
[ETH_ALEN
];
90 #ifdef DRIVER_TEST_UNIX
91 struct sockaddr_un hostapd_addr
;
92 #endif /* DRIVER_TEST_UNIX */
94 struct sockaddr_in hostapd_addr_udp
;
95 int hostapd_addr_udp_set
;
96 char *own_socket_path
;
101 #define MAX_SCAN_RESULTS 30
102 struct wpa_scan_res
*scanres
[MAX_SCAN_RESULTS
];
106 size_t assoc_wpa_ie_len
;
110 size_t probe_req_ie_len
;
120 static void test_driver_free_bss(struct test_driver_bss
*bss
)
123 free(bss
->wps_beacon_ie
);
124 free(bss
->wps_probe_resp_ie
);
129 static void test_driver_free_priv(struct test_driver_data
*drv
)
131 struct test_driver_bss
*bss
, *prev
;
140 test_driver_free_bss(prev
);
142 free(drv
->own_socket_path
);
143 free(drv
->socket_dir
);
148 static struct test_client_socket
*
149 test_driver_get_cli(struct test_driver_data
*drv
, struct sockaddr_un
*from
,
152 struct test_client_socket
*cli
= drv
->cli
;
155 if (cli
->unlen
== fromlen
&&
156 strncmp(cli
->un
.sun_path
, from
->sun_path
,
157 fromlen
- sizeof(cli
->un
.sun_family
)) == 0)
166 static int test_driver_send_eapol(void *priv
, const u8
*addr
, const u8
*data
,
167 size_t data_len
, int encrypt
,
170 struct test_driver_data
*drv
= priv
;
171 struct test_client_socket
*cli
;
174 struct l2_ethhdr eth
;
176 if (drv
->test_socket
< 0)
181 if (memcmp(cli
->addr
, addr
, ETH_ALEN
) == 0)
187 wpa_printf(MSG_DEBUG
, "%s: no destination client entry",
192 memcpy(eth
.h_dest
, addr
, ETH_ALEN
);
193 memcpy(eth
.h_source
, own_addr
, ETH_ALEN
);
194 eth
.h_proto
= host_to_be16(ETH_P_EAPOL
);
196 io
[0].iov_base
= "EAPOL ";
198 io
[1].iov_base
= ð
;
199 io
[1].iov_len
= sizeof(eth
);
200 io
[2].iov_base
= (u8
*) data
;
201 io
[2].iov_len
= data_len
;
203 memset(&msg
, 0, sizeof(msg
));
206 msg
.msg_name
= &cli
->un
;
207 msg
.msg_namelen
= cli
->unlen
;
208 return sendmsg(drv
->test_socket
, &msg
, 0);
212 static int test_driver_send_ether(void *priv
, const u8
*dst
, const u8
*src
,
213 u16 proto
, const u8
*data
, size_t data_len
)
215 struct test_driver_data
*drv
= priv
;
218 struct l2_ethhdr eth
;
220 struct sockaddr_un addr
;
223 int ret
= 0, broadcast
= 0, count
= 0;
225 if (drv
->test_socket
< 0 || drv
->socket_dir
== NULL
) {
226 wpa_printf(MSG_DEBUG
, "%s: invalid parameters (sock=%d "
228 __func__
, drv
->test_socket
, drv
->socket_dir
);
232 broadcast
= memcmp(dst
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0;
233 snprintf(desttxt
, sizeof(desttxt
), MACSTR
, MAC2STR(dst
));
235 memcpy(eth
.h_dest
, dst
, ETH_ALEN
);
236 memcpy(eth
.h_source
, src
, ETH_ALEN
);
237 eth
.h_proto
= host_to_be16(proto
);
239 io
[0].iov_base
= "ETHER ";
241 io
[1].iov_base
= ð
;
242 io
[1].iov_len
= sizeof(eth
);
243 io
[2].iov_base
= (u8
*) data
;
244 io
[2].iov_len
= data_len
;
246 memset(&msg
, 0, sizeof(msg
));
250 dir
= opendir(drv
->socket_dir
);
252 perror("test_driver: opendir");
255 while ((dent
= readdir(dir
))) {
256 #ifdef _DIRENT_HAVE_D_TYPE
257 /* Skip the file if it is not a socket. Also accept
258 * DT_UNKNOWN (0) in case the C library or underlying file
259 * system does not support d_type. */
260 if (dent
->d_type
!= DT_SOCK
&& dent
->d_type
!= DT_UNKNOWN
)
262 #endif /* _DIRENT_HAVE_D_TYPE */
263 if (strcmp(dent
->d_name
, ".") == 0 ||
264 strcmp(dent
->d_name
, "..") == 0)
267 memset(&addr
, 0, sizeof(addr
));
268 addr
.sun_family
= AF_UNIX
;
269 snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s/%s",
270 drv
->socket_dir
, dent
->d_name
);
272 if (strcmp(addr
.sun_path
, drv
->own_socket_path
) == 0)
274 if (!broadcast
&& strstr(dent
->d_name
, desttxt
) == NULL
)
277 wpa_printf(MSG_DEBUG
, "%s: Send ether frame to %s",
278 __func__
, dent
->d_name
);
280 msg
.msg_name
= &addr
;
281 msg
.msg_namelen
= sizeof(addr
);
282 ret
= sendmsg(drv
->test_socket
, &msg
, 0);
284 perror("driver_test: sendmsg");
289 if (!broadcast
&& count
== 0) {
290 wpa_printf(MSG_DEBUG
, "%s: Destination " MACSTR
" not found",
291 __func__
, MAC2STR(dst
));
299 static int wpa_driver_test_send_mlme(void *priv
, const u8
*buf
, size_t len
)
301 struct test_driver_data
*drv
= priv
;
305 int ret
= 0, broadcast
= 0;
307 struct sockaddr_un addr
;
310 struct ieee80211_hdr
*hdr
;
313 if (drv
->test_socket
< 0 || len
< 10 || drv
->socket_dir
== NULL
) {
314 wpa_printf(MSG_DEBUG
, "%s: invalid parameters (sock=%d len=%lu"
316 __func__
, drv
->test_socket
, (unsigned long) len
,
323 broadcast
= memcmp(dest
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0;
324 snprintf(desttxt
, sizeof(desttxt
), MACSTR
, MAC2STR(dest
));
326 io
[0].iov_base
= "MLME ";
328 io
[1].iov_base
= (void *) buf
;
331 memset(&msg
, 0, sizeof(msg
));
335 dir
= opendir(drv
->socket_dir
);
337 perror("test_driver: opendir");
340 while ((dent
= readdir(dir
))) {
341 #ifdef _DIRENT_HAVE_D_TYPE
342 /* Skip the file if it is not a socket. Also accept
343 * DT_UNKNOWN (0) in case the C library or underlying file
344 * system does not support d_type. */
345 if (dent
->d_type
!= DT_SOCK
&& dent
->d_type
!= DT_UNKNOWN
)
347 #endif /* _DIRENT_HAVE_D_TYPE */
348 if (strcmp(dent
->d_name
, ".") == 0 ||
349 strcmp(dent
->d_name
, "..") == 0)
352 memset(&addr
, 0, sizeof(addr
));
353 addr
.sun_family
= AF_UNIX
;
354 snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s/%s",
355 drv
->socket_dir
, dent
->d_name
);
357 if (strcmp(addr
.sun_path
, drv
->own_socket_path
) == 0)
359 if (!broadcast
&& strstr(dent
->d_name
, desttxt
) == NULL
)
362 wpa_printf(MSG_DEBUG
, "%s: Send management frame to %s",
363 __func__
, dent
->d_name
);
365 msg
.msg_name
= &addr
;
366 msg
.msg_namelen
= sizeof(addr
);
367 ret
= sendmsg(drv
->test_socket
, &msg
, 0);
369 perror("driver_test: sendmsg");
373 hdr
= (struct ieee80211_hdr
*) buf
;
374 fc
= le_to_host16(hdr
->frame_control
);
375 hostapd_mgmt_tx_cb(drv
->hapd
, (u8
*) buf
, len
, WLAN_FC_GET_STYPE(fc
),
382 static void test_driver_scan(struct test_driver_data
*drv
,
383 struct sockaddr_un
*from
, socklen_t fromlen
,
386 char buf
[512], *pos
, *end
;
388 struct test_driver_bss
*bss
;
393 /* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
395 wpa_printf(MSG_DEBUG
, "test_driver: SCAN");
399 hwaddr_aton(data
+ 1, sa
)) {
400 wpa_printf(MSG_DEBUG
, "test_driver: Unexpected SCAN "
408 ielen
= os_strlen(data
) / 2;
409 if (ielen
> sizeof(ie
))
411 if (hexstr2bin(data
, ie
, ielen
) < 0)
414 wpa_printf(MSG_DEBUG
, "test_driver: Scan from " MACSTR
,
416 wpa_hexdump(MSG_MSGDUMP
, "test_driver: scan IEs", ie
, ielen
);
418 hostapd_wps_probe_req_rx(drv
->hapd
, sa
, ie
, ielen
);
421 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
423 end
= buf
+ sizeof(buf
);
425 /* reply: SCANRESP BSSID SSID IEs */
426 ret
= snprintf(pos
, end
- pos
, "SCANRESP " MACSTR
" ",
427 MAC2STR(bss
->bssid
));
428 if (ret
< 0 || ret
>= end
- pos
)
431 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
432 bss
->ssid
, bss
->ssid_len
);
433 ret
= snprintf(pos
, end
- pos
, " ");
434 if (ret
< 0 || ret
>= end
- pos
)
437 pos
+= wpa_snprintf_hex(pos
, end
- pos
, bss
->ie
, bss
->ielen
);
438 pos
+= wpa_snprintf_hex(pos
, end
- pos
, bss
->wps_probe_resp_ie
,
439 bss
->wps_probe_resp_ie_len
);
442 ret
= snprintf(pos
, end
- pos
, " PRIVACY");
443 if (ret
< 0 || ret
>= end
- pos
)
448 sendto(drv
->test_socket
, buf
, pos
- buf
, 0,
449 (struct sockaddr
*) from
, fromlen
);
454 static struct hostapd_data
* test_driver_get_hapd(struct test_driver_data
*drv
,
455 struct test_driver_bss
*bss
)
457 struct hostapd_iface
*iface
= drv
->hapd
->iface
;
458 struct hostapd_data
*hapd
= NULL
;
462 wpa_printf(MSG_DEBUG
, "%s: bss == NULL", __func__
);
466 for (i
= 0; i
< iface
->num_bss
; i
++) {
467 hapd
= iface
->bss
[i
];
468 if (memcmp(hapd
->own_addr
, bss
->bssid
, ETH_ALEN
) == 0)
471 if (i
== iface
->num_bss
) {
472 wpa_printf(MSG_DEBUG
, "%s: no matching interface entry found "
473 "for BSSID " MACSTR
, __func__
, MAC2STR(bss
->bssid
));
481 static int test_driver_new_sta(struct test_driver_data
*drv
,
482 struct test_driver_bss
*bss
, const u8
*addr
,
483 const u8
*ie
, size_t ielen
)
485 struct hostapd_data
*hapd
;
487 hapd
= test_driver_get_hapd(drv
, bss
);
491 return hostapd_notif_assoc(hapd
, addr
, ie
, ielen
);
495 static void test_driver_assoc(struct test_driver_data
*drv
,
496 struct sockaddr_un
*from
, socklen_t fromlen
,
499 struct test_client_socket
*cli
;
500 u8 ie
[256], ssid
[32];
501 size_t ielen
, ssid_len
= 0;
502 char *pos
, *pos2
, cmd
[50];
503 struct test_driver_bss
*bss
;
505 /* data: STA-addr SSID(hex) IEs(hex) */
507 cli
= os_zalloc(sizeof(*cli
));
511 if (hwaddr_aton(data
, cli
->addr
)) {
512 printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
520 pos2
= strchr(pos
, ' ');
523 ssid_len
= (pos2
- pos
) / 2;
524 if (hexstr2bin(pos
, ssid
, ssid_len
) < 0) {
525 wpa_printf(MSG_DEBUG
, "%s: Invalid SSID", __func__
);
529 wpa_hexdump_ascii(MSG_DEBUG
, "test_driver_assoc: SSID",
533 ielen
= strlen(pos
) / 2;
534 if (ielen
> sizeof(ie
))
536 if (hexstr2bin(pos
, ie
, ielen
) < 0)
540 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
541 if (bss
->ssid_len
== ssid_len
&&
542 memcmp(bss
->ssid
, ssid
, ssid_len
) == 0)
546 wpa_printf(MSG_DEBUG
, "%s: No matching SSID found from "
547 "configured BSSes", __func__
);
553 memcpy(&cli
->un
, from
, sizeof(cli
->un
));
554 cli
->unlen
= fromlen
;
555 cli
->next
= drv
->cli
;
557 wpa_hexdump_ascii(MSG_DEBUG
, "test_socket: ASSOC sun_path",
558 (const u8
*) cli
->un
.sun_path
,
559 cli
->unlen
- sizeof(cli
->un
.sun_family
));
561 snprintf(cmd
, sizeof(cmd
), "ASSOCRESP " MACSTR
" 0",
562 MAC2STR(bss
->bssid
));
563 sendto(drv
->test_socket
, cmd
, strlen(cmd
), 0,
564 (struct sockaddr
*) from
, fromlen
);
566 if (test_driver_new_sta(drv
, bss
, cli
->addr
, ie
, ielen
) < 0) {
567 wpa_printf(MSG_DEBUG
, "test_driver: failed to add new STA");
572 static void test_driver_disassoc(struct test_driver_data
*drv
,
573 struct sockaddr_un
*from
, socklen_t fromlen
)
575 struct test_client_socket
*cli
;
577 cli
= test_driver_get_cli(drv
, from
, fromlen
);
581 hostapd_notif_disassoc(drv
->hapd
, cli
->addr
);
585 static void test_driver_eapol(struct test_driver_data
*drv
,
586 struct sockaddr_un
*from
, socklen_t fromlen
,
587 u8
*data
, size_t datalen
)
589 struct test_client_socket
*cli
;
591 /* Skip Ethernet header */
592 wpa_printf(MSG_DEBUG
, "test_driver: dst=" MACSTR
" src="
593 MACSTR
" proto=%04x",
594 MAC2STR(data
), MAC2STR(data
+ ETH_ALEN
),
595 WPA_GET_BE16(data
+ 2 * ETH_ALEN
));
599 cli
= test_driver_get_cli(drv
, from
, fromlen
);
601 struct hostapd_data
*hapd
;
602 hapd
= test_driver_get_hapd(drv
, cli
->bss
);
605 hostapd_eapol_receive(hapd
, cli
->addr
, data
, datalen
);
607 wpa_printf(MSG_DEBUG
, "test_socket: EAPOL from unknown "
613 static void test_driver_ether(struct test_driver_data
*drv
,
614 struct sockaddr_un
*from
, socklen_t fromlen
,
615 u8
*data
, size_t datalen
)
617 struct l2_ethhdr
*eth
;
619 if (datalen
< sizeof(*eth
))
622 eth
= (struct l2_ethhdr
*) data
;
623 wpa_printf(MSG_DEBUG
, "test_driver: RX ETHER dst=" MACSTR
" src="
624 MACSTR
" proto=%04x",
625 MAC2STR(eth
->h_dest
), MAC2STR(eth
->h_source
),
626 be_to_host16(eth
->h_proto
));
628 #ifdef CONFIG_IEEE80211R
629 if (be_to_host16(eth
->h_proto
) == ETH_P_RRB
) {
630 wpa_ft_rrb_rx(drv
->hapd
->wpa_auth
, eth
->h_source
,
631 data
+ sizeof(*eth
), datalen
- sizeof(*eth
));
633 #endif /* CONFIG_IEEE80211R */
637 static void test_driver_mlme(struct test_driver_data
*drv
,
638 struct sockaddr_un
*from
, socklen_t fromlen
,
639 u8
*data
, size_t datalen
)
641 struct ieee80211_hdr
*hdr
;
644 hdr
= (struct ieee80211_hdr
*) data
;
646 if (test_driver_get_cli(drv
, from
, fromlen
) == NULL
&& datalen
>= 16) {
647 struct test_client_socket
*cli
;
648 cli
= os_zalloc(sizeof(*cli
));
651 wpa_printf(MSG_DEBUG
, "Adding client entry for " MACSTR
,
652 MAC2STR(hdr
->addr2
));
653 memcpy(cli
->addr
, hdr
->addr2
, ETH_ALEN
);
654 memcpy(&cli
->un
, from
, sizeof(cli
->un
));
655 cli
->unlen
= fromlen
;
656 cli
->next
= drv
->cli
;
660 wpa_hexdump(MSG_MSGDUMP
, "test_driver_mlme: received frame",
662 fc
= le_to_host16(hdr
->frame_control
);
663 if (WLAN_FC_GET_TYPE(fc
) != WLAN_FC_TYPE_MGMT
) {
664 wpa_printf(MSG_ERROR
, "%s: received non-mgmt frame",
668 hostapd_mgmt_rx(drv
->hapd
, data
, datalen
, WLAN_FC_GET_STYPE(fc
), NULL
);
672 static void test_driver_receive_unix(int sock
, void *eloop_ctx
, void *sock_ctx
)
674 struct test_driver_data
*drv
= eloop_ctx
;
677 struct sockaddr_un from
;
678 socklen_t fromlen
= sizeof(from
);
680 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
681 (struct sockaddr
*) &from
, &fromlen
);
683 perror("recvfrom(test_socket)");
688 wpa_printf(MSG_DEBUG
, "test_driver: received %u bytes", res
);
690 if (strncmp(buf
, "SCAN", 4) == 0) {
691 test_driver_scan(drv
, &from
, fromlen
, buf
+ 4);
692 } else if (strncmp(buf
, "ASSOC ", 6) == 0) {
693 test_driver_assoc(drv
, &from
, fromlen
, buf
+ 6);
694 } else if (strcmp(buf
, "DISASSOC") == 0) {
695 test_driver_disassoc(drv
, &from
, fromlen
);
696 } else if (strncmp(buf
, "EAPOL ", 6) == 0) {
697 test_driver_eapol(drv
, &from
, fromlen
, (u8
*) buf
+ 6,
699 } else if (strncmp(buf
, "ETHER ", 6) == 0) {
700 test_driver_ether(drv
, &from
, fromlen
, (u8
*) buf
+ 6,
702 } else if (strncmp(buf
, "MLME ", 5) == 0) {
703 test_driver_mlme(drv
, &from
, fromlen
, (u8
*) buf
+ 5, res
- 5);
705 wpa_hexdump_ascii(MSG_DEBUG
, "Unknown test_socket command",
711 static struct test_driver_bss
*
712 test_driver_get_bss(struct test_driver_data
*drv
, const char *ifname
)
714 struct test_driver_bss
*bss
;
716 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
717 if (strcmp(bss
->ifname
, ifname
) == 0)
724 static int test_driver_set_generic_elem(const char *ifname
, void *priv
,
725 const u8
*elem
, size_t elem_len
)
727 struct test_driver_data
*drv
= priv
;
728 struct test_driver_bss
*bss
;
730 bss
= test_driver_get_bss(drv
, ifname
);
742 bss
->ie
= malloc(elem_len
);
743 if (bss
->ie
== NULL
) {
748 memcpy(bss
->ie
, elem
, elem_len
);
749 bss
->ielen
= elem_len
;
754 static int test_driver_set_wps_beacon_ie(const char *ifname
, void *priv
,
755 const u8
*ie
, size_t len
)
757 struct test_driver_data
*drv
= priv
;
758 struct test_driver_bss
*bss
;
760 wpa_hexdump(MSG_DEBUG
, "test_driver: Beacon WPS IE", ie
, len
);
761 bss
= test_driver_get_bss(drv
, ifname
);
765 free(bss
->wps_beacon_ie
);
768 bss
->wps_beacon_ie
= NULL
;
769 bss
->wps_beacon_ie_len
= 0;
773 bss
->wps_beacon_ie
= malloc(len
);
774 if (bss
->wps_beacon_ie
== NULL
) {
775 bss
->wps_beacon_ie_len
= 0;
779 memcpy(bss
->wps_beacon_ie
, ie
, len
);
780 bss
->wps_beacon_ie_len
= len
;
785 static int test_driver_set_wps_probe_resp_ie(const char *ifname
, void *priv
,
786 const u8
*ie
, size_t len
)
788 struct test_driver_data
*drv
= priv
;
789 struct test_driver_bss
*bss
;
791 wpa_hexdump(MSG_DEBUG
, "test_driver: ProbeResp WPS IE", ie
, len
);
792 bss
= test_driver_get_bss(drv
, ifname
);
796 free(bss
->wps_probe_resp_ie
);
799 bss
->wps_probe_resp_ie
= NULL
;
800 bss
->wps_probe_resp_ie_len
= 0;
804 bss
->wps_probe_resp_ie
= malloc(len
);
805 if (bss
->wps_probe_resp_ie
== NULL
) {
806 bss
->wps_probe_resp_ie_len
= 0;
810 memcpy(bss
->wps_probe_resp_ie
, ie
, len
);
811 bss
->wps_probe_resp_ie_len
= len
;
816 static int test_driver_sta_deauth(void *priv
, const u8
*addr
, int reason
)
818 struct test_driver_data
*drv
= priv
;
819 struct test_client_socket
*cli
;
821 if (drv
->test_socket
< 0)
826 if (memcmp(cli
->addr
, addr
, ETH_ALEN
) == 0)
834 return sendto(drv
->test_socket
, "DEAUTH", 6, 0,
835 (struct sockaddr
*) &cli
->un
, cli
->unlen
);
839 static int test_driver_sta_disassoc(void *priv
, const u8
*addr
, int reason
)
841 struct test_driver_data
*drv
= priv
;
842 struct test_client_socket
*cli
;
844 if (drv
->test_socket
< 0)
849 if (memcmp(cli
->addr
, addr
, ETH_ALEN
) == 0)
857 return sendto(drv
->test_socket
, "DISASSOC", 8, 0,
858 (struct sockaddr
*) &cli
->un
, cli
->unlen
);
862 static int test_driver_bss_add(void *priv
, const char *ifname
, const u8
*bssid
)
864 struct test_driver_data
*drv
= priv
;
865 struct test_driver_bss
*bss
;
867 wpa_printf(MSG_DEBUG
, "%s(ifname=%s bssid=" MACSTR
")",
868 __func__
, ifname
, MAC2STR(bssid
));
870 bss
= os_zalloc(sizeof(*bss
));
874 os_strlcpy(bss
->ifname
, ifname
, IFNAMSIZ
);
875 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
877 bss
->next
= drv
->bss
;
884 static int test_driver_bss_remove(void *priv
, const char *ifname
)
886 struct test_driver_data
*drv
= priv
;
887 struct test_driver_bss
*bss
, *prev
;
888 struct test_client_socket
*cli
, *prev_c
;
890 wpa_printf(MSG_DEBUG
, "%s(ifname=%s)", __func__
, ifname
);
892 for (prev
= NULL
, bss
= drv
->bss
; bss
; prev
= bss
, bss
= bss
->next
) {
893 if (strcmp(bss
->ifname
, ifname
) != 0)
897 prev
->next
= bss
->next
;
899 drv
->bss
= bss
->next
;
901 for (prev_c
= NULL
, cli
= drv
->cli
; cli
;
902 prev_c
= cli
, cli
= cli
->next
) {
906 prev_c
->next
= cli
->next
;
908 drv
->cli
= cli
->next
;
913 test_driver_free_bss(bss
);
921 static int test_driver_if_add(const char *iface
, void *priv
,
922 enum hostapd_driver_if_type type
, char *ifname
,
925 wpa_printf(MSG_DEBUG
, "%s(iface=%s type=%d ifname=%s)",
926 __func__
, iface
, type
, ifname
);
931 static int test_driver_if_update(void *priv
, enum hostapd_driver_if_type type
,
932 char *ifname
, const u8
*addr
)
934 wpa_printf(MSG_DEBUG
, "%s(type=%d ifname=%s)", __func__
, type
, ifname
);
939 static int test_driver_if_remove(void *priv
, enum hostapd_driver_if_type type
,
940 const char *ifname
, const u8
*addr
)
942 wpa_printf(MSG_DEBUG
, "%s(type=%d ifname=%s)", __func__
, type
, ifname
);
947 static int test_driver_valid_bss_mask(void *priv
, const u8
*addr
,
954 static int test_driver_set_ssid(const char *ifname
, void *priv
, const u8
*buf
,
957 struct test_driver_data
*drv
= priv
;
958 struct test_driver_bss
*bss
;
960 wpa_printf(MSG_DEBUG
, "%s(ifname=%s)", __func__
, ifname
);
961 wpa_hexdump_ascii(MSG_DEBUG
, "test_driver_set_ssid: SSID", buf
, len
);
963 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
964 if (strcmp(bss
->ifname
, ifname
) != 0)
967 if (len
< 0 || (size_t) len
> sizeof(bss
->ssid
))
970 memcpy(bss
->ssid
, buf
, len
);
980 static int test_driver_set_privacy(const char *ifname
, void *priv
, int enabled
)
982 struct test_driver_data
*drv
= priv
;
983 struct test_driver_bss
*bss
;
985 wpa_printf(MSG_DEBUG
, "%s(ifname=%s enabled=%d)",
986 __func__
, ifname
, enabled
);
988 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
989 if (strcmp(bss
->ifname
, ifname
) != 0)
992 bss
->privacy
= enabled
;
1001 static int test_driver_set_key(const char *iface
, void *priv
, wpa_alg alg
,
1002 const u8
*addr
, int key_idx
, int set_tx
,
1003 const u8
*seq
, size_t seq_len
,
1004 const u8
*key
, size_t key_len
)
1006 wpa_printf(MSG_DEBUG
, "%s(iface=%s alg=%d idx=%d set_tx=%d)",
1007 __func__
, iface
, alg
, key_idx
, set_tx
);
1009 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
1011 wpa_hexdump_key(MSG_DEBUG
, " key", key
, key_len
);
1016 static int test_driver_set_sta_vlan(void *priv
, const u8
*addr
,
1017 const char *ifname
, int vlan_id
)
1019 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" ifname=%s vlan_id=%d)",
1020 __func__
, MAC2STR(addr
), ifname
, vlan_id
);
1025 static int test_driver_sta_add(const char *ifname
, void *priv
,
1026 struct hostapd_sta_add_params
*params
)
1028 struct test_driver_data
*drv
= priv
;
1029 struct test_client_socket
*cli
;
1030 struct test_driver_bss
*bss
;
1032 wpa_printf(MSG_DEBUG
, "%s(ifname=%s addr=" MACSTR
" aid=%d "
1033 "capability=0x%x flags=0x%x listen_interval=%d)",
1034 __func__
, ifname
, MAC2STR(params
->addr
), params
->aid
,
1035 params
->capability
, params
->flags
,
1036 params
->listen_interval
);
1037 wpa_hexdump(MSG_DEBUG
, "test_driver_sta_add - supp_rates",
1038 params
->supp_rates
, params
->supp_rates_len
);
1042 if (os_memcmp(cli
->addr
, params
->addr
, ETH_ALEN
) == 0)
1047 wpa_printf(MSG_DEBUG
, "%s: no matching client entry",
1052 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
1053 if (strcmp(ifname
, bss
->ifname
) == 0)
1057 wpa_printf(MSG_DEBUG
, "%s: No matching interface found from "
1058 "configured BSSes", __func__
);
1068 static void * test_driver_init(struct hostapd_data
*hapd
,
1069 struct wpa_init_params
*params
)
1071 struct test_driver_data
*drv
;
1072 struct sockaddr_un addr_un
;
1073 struct sockaddr_in addr_in
;
1074 struct sockaddr
*addr
;
1077 drv
= os_zalloc(sizeof(struct test_driver_data
));
1079 printf("Could not allocate memory for test driver data\n");
1082 drv
->bss
= os_zalloc(sizeof(*drv
->bss
));
1083 if (drv
->bss
== NULL
) {
1084 printf("Could not allocate memory for test driver BSS data\n");
1091 /* Generate a MAC address to help testing with multiple APs */
1092 hapd
->own_addr
[0] = 0x02; /* locally administered */
1093 sha1_prf((const u8
*) params
->ifname
, strlen(params
->ifname
),
1094 "hostapd test bssid generation",
1095 params
->ssid
, params
->ssid_len
,
1096 hapd
->own_addr
+ 1, ETH_ALEN
- 1);
1098 os_strlcpy(drv
->bss
->ifname
, params
->ifname
, IFNAMSIZ
);
1099 memcpy(drv
->bss
->bssid
, hapd
->own_addr
, ETH_ALEN
);
1101 if (params
->test_socket
) {
1102 if (os_strlen(params
->test_socket
) >=
1103 sizeof(addr_un
.sun_path
)) {
1104 printf("Too long test_socket path\n");
1105 test_driver_free_priv(drv
);
1108 if (strncmp(params
->test_socket
, "DIR:", 4) == 0) {
1109 size_t len
= strlen(params
->test_socket
) + 30;
1110 drv
->socket_dir
= strdup(params
->test_socket
+ 4);
1111 drv
->own_socket_path
= malloc(len
);
1112 if (drv
->own_socket_path
) {
1113 snprintf(drv
->own_socket_path
, len
,
1115 params
->test_socket
+ 4,
1116 MAC2STR(hapd
->own_addr
));
1118 } else if (strncmp(params
->test_socket
, "UDP:", 4) == 0) {
1119 drv
->udp_port
= atoi(params
->test_socket
+ 4);
1121 drv
->own_socket_path
= strdup(params
->test_socket
);
1123 if (drv
->own_socket_path
== NULL
&& drv
->udp_port
== 0) {
1124 test_driver_free_priv(drv
);
1128 drv
->test_socket
= socket(drv
->udp_port
? PF_INET
: PF_UNIX
,
1130 if (drv
->test_socket
< 0) {
1132 test_driver_free_priv(drv
);
1136 if (drv
->udp_port
) {
1137 os_memset(&addr_in
, 0, sizeof(addr_in
));
1138 addr_in
.sin_family
= AF_INET
;
1139 addr_in
.sin_port
= htons(drv
->udp_port
);
1140 addr
= (struct sockaddr
*) &addr_in
;
1141 alen
= sizeof(addr_in
);
1143 os_memset(&addr_un
, 0, sizeof(addr_un
));
1144 addr_un
.sun_family
= AF_UNIX
;
1145 os_strlcpy(addr_un
.sun_path
, drv
->own_socket_path
,
1146 sizeof(addr_un
.sun_path
));
1147 addr
= (struct sockaddr
*) &addr_un
;
1148 alen
= sizeof(addr_un
);
1150 if (bind(drv
->test_socket
, addr
, alen
) < 0) {
1151 perror("bind(PF_UNIX)");
1152 close(drv
->test_socket
);
1153 if (drv
->own_socket_path
)
1154 unlink(drv
->own_socket_path
);
1155 test_driver_free_priv(drv
);
1158 eloop_register_read_sock(drv
->test_socket
,
1159 test_driver_receive_unix
, drv
, NULL
);
1161 drv
->test_socket
= -1;
1167 static void test_driver_deinit(void *priv
)
1169 struct test_driver_data
*drv
= priv
;
1170 struct test_client_socket
*cli
, *prev
;
1179 if (drv
->test_socket
>= 0) {
1180 eloop_unregister_read_sock(drv
->test_socket
);
1181 close(drv
->test_socket
);
1182 if (drv
->own_socket_path
)
1183 unlink(drv
->own_socket_path
);
1186 /* There should be only one BSS remaining at this point. */
1187 if (drv
->bss
== NULL
)
1188 wpa_printf(MSG_ERROR
, "%s: drv->bss == NULL", __func__
);
1189 else if (drv
->bss
->next
)
1190 wpa_printf(MSG_ERROR
, "%s: drv->bss->next != NULL", __func__
);
1192 test_driver_free_priv(drv
);
1197 static void wpa_driver_test_poll(void *eloop_ctx
, void *timeout_ctx
)
1199 struct wpa_driver_test_data
*drv
= eloop_ctx
;
1201 #ifdef DRIVER_TEST_UNIX
1202 if (drv
->associated
&& drv
->hostapd_addr_set
) {
1204 if (stat(drv
->hostapd_addr
.sun_path
, &st
) < 0) {
1205 wpa_printf(MSG_DEBUG
, "%s: lost connection to AP: %s",
1206 __func__
, strerror(errno
));
1207 drv
->associated
= 0;
1208 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1211 #endif /* DRIVER_TEST_UNIX */
1213 eloop_register_timeout(1, 0, wpa_driver_test_poll
, drv
, NULL
);
1217 static int wpa_driver_test_set_wpa(void *priv
, int enabled
)
1219 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, enabled
);
1224 static void wpa_driver_test_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
1226 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
1227 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
1231 #ifdef DRIVER_TEST_UNIX
1232 static void wpa_driver_scan_dir(struct wpa_driver_test_data
*drv
,
1235 struct dirent
*dent
;
1237 struct sockaddr_un addr
;
1238 char cmd
[512], *pos
, *end
;
1241 dir
= opendir(path
);
1245 end
= cmd
+ sizeof(cmd
);
1247 ret
= os_snprintf(pos
, end
- pos
, "SCAN " MACSTR
,
1248 MAC2STR(drv
->own_addr
));
1249 if (ret
>= 0 && ret
< end
- pos
)
1251 if (drv
->probe_req_ie
) {
1252 ret
= os_snprintf(pos
, end
- pos
, " ");
1253 if (ret
>= 0 && ret
< end
- pos
)
1255 pos
+= wpa_snprintf_hex(pos
, end
- pos
, drv
->probe_req_ie
,
1256 drv
->probe_req_ie_len
);
1260 while ((dent
= readdir(dir
))) {
1261 if (os_strncmp(dent
->d_name
, "AP-", 3) != 0 &&
1262 os_strncmp(dent
->d_name
, "STA-", 4) != 0)
1264 if (drv
->own_socket_path
) {
1266 olen
= os_strlen(drv
->own_socket_path
);
1267 dlen
= os_strlen(dent
->d_name
);
1269 os_strcmp(dent
->d_name
,
1270 drv
->own_socket_path
+ olen
- dlen
) == 0)
1273 wpa_printf(MSG_DEBUG
, "%s: SCAN %s", __func__
, dent
->d_name
);
1275 os_memset(&addr
, 0, sizeof(addr
));
1276 addr
.sun_family
= AF_UNIX
;
1277 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s/%s",
1278 path
, dent
->d_name
);
1280 if (sendto(drv
->test_socket
, cmd
, os_strlen(cmd
), 0,
1281 (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
1282 perror("sendto(test_socket)");
1287 #endif /* DRIVER_TEST_UNIX */
1290 static int wpa_driver_test_scan(void *priv
,
1291 struct wpa_driver_scan_params
*params
)
1293 struct wpa_driver_test_data
*drv
= priv
;
1296 wpa_printf(MSG_DEBUG
, "%s: priv=%p", __func__
, priv
);
1297 for (i
= 0; i
< params
->num_ssids
; i
++)
1298 wpa_hexdump(MSG_DEBUG
, "Scan SSID",
1299 params
->ssids
[i
].ssid
, params
->ssids
[i
].ssid_len
);
1300 wpa_hexdump(MSG_DEBUG
, "Scan extra IE(s)",
1301 params
->extra_ies
, params
->extra_ies_len
);
1303 drv
->num_scanres
= 0;
1305 #ifdef DRIVER_TEST_UNIX
1306 if (drv
->test_socket
>= 0 && drv
->test_dir
)
1307 wpa_driver_scan_dir(drv
, drv
->test_dir
);
1309 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_set
&&
1310 sendto(drv
->test_socket
, "SCAN", 4, 0,
1311 (struct sockaddr
*) &drv
->hostapd_addr
,
1312 sizeof(drv
->hostapd_addr
)) < 0) {
1313 perror("sendto(test_socket)");
1315 #endif /* DRIVER_TEST_UNIX */
1317 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_udp_set
&&
1318 sendto(drv
->test_socket
, "SCAN", 4, 0,
1319 (struct sockaddr
*) &drv
->hostapd_addr_udp
,
1320 sizeof(drv
->hostapd_addr_udp
)) < 0) {
1321 perror("sendto(test_socket)");
1324 eloop_cancel_timeout(wpa_driver_test_scan_timeout
, drv
, drv
->ctx
);
1325 eloop_register_timeout(1, 0, wpa_driver_test_scan_timeout
, drv
,
1331 static struct wpa_scan_results
* wpa_driver_test_get_scan_results2(void *priv
)
1333 struct wpa_driver_test_data
*drv
= priv
;
1334 struct wpa_scan_results
*res
;
1337 res
= os_zalloc(sizeof(*res
));
1341 res
->res
= os_zalloc(drv
->num_scanres
* sizeof(struct wpa_scan_res
*));
1342 if (res
->res
== NULL
) {
1347 for (i
= 0; i
< drv
->num_scanres
; i
++) {
1348 struct wpa_scan_res
*r
;
1349 if (drv
->scanres
[i
] == NULL
)
1351 r
= os_malloc(sizeof(*r
) + drv
->scanres
[i
]->ie_len
);
1354 os_memcpy(r
, drv
->scanres
[i
],
1355 sizeof(*r
) + drv
->scanres
[i
]->ie_len
);
1356 res
->res
[res
->num
++] = r
;
1363 static int wpa_driver_test_set_key(void *priv
, wpa_alg alg
, const u8
*addr
,
1364 int key_idx
, int set_tx
,
1365 const u8
*seq
, size_t seq_len
,
1366 const u8
*key
, size_t key_len
)
1368 wpa_printf(MSG_DEBUG
, "%s: priv=%p alg=%d key_idx=%d set_tx=%d",
1369 __func__
, priv
, alg
, key_idx
, set_tx
);
1371 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
1374 wpa_hexdump(MSG_DEBUG
, " seq", seq
, seq_len
);
1377 wpa_hexdump(MSG_DEBUG
, " key", key
, key_len
);
1383 static int wpa_driver_test_associate(
1384 void *priv
, struct wpa_driver_associate_params
*params
)
1386 struct wpa_driver_test_data
*drv
= priv
;
1387 wpa_printf(MSG_DEBUG
, "%s: priv=%p freq=%d pairwise_suite=%d "
1388 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d",
1389 __func__
, priv
, params
->freq
, params
->pairwise_suite
,
1390 params
->group_suite
, params
->key_mgmt_suite
,
1391 params
->auth_alg
, params
->mode
);
1392 if (params
->bssid
) {
1393 wpa_printf(MSG_DEBUG
, " bssid=" MACSTR
,
1394 MAC2STR(params
->bssid
));
1397 wpa_hexdump_ascii(MSG_DEBUG
, " ssid",
1398 params
->ssid
, params
->ssid_len
);
1400 if (params
->wpa_ie
) {
1401 wpa_hexdump(MSG_DEBUG
, " wpa_ie",
1402 params
->wpa_ie
, params
->wpa_ie_len
);
1403 drv
->assoc_wpa_ie_len
= params
->wpa_ie_len
;
1404 if (drv
->assoc_wpa_ie_len
> sizeof(drv
->assoc_wpa_ie
))
1405 drv
->assoc_wpa_ie_len
= sizeof(drv
->assoc_wpa_ie
);
1406 os_memcpy(drv
->assoc_wpa_ie
, params
->wpa_ie
,
1407 drv
->assoc_wpa_ie_len
);
1409 drv
->assoc_wpa_ie_len
= 0;
1411 drv
->ibss
= params
->mode
== IEEE80211_MODE_IBSS
;
1412 drv
->privacy
= params
->key_mgmt_suite
&
1413 (WPA_KEY_MGMT_IEEE8021X
|
1415 WPA_KEY_MGMT_WPA_NONE
|
1416 WPA_KEY_MGMT_FT_IEEE8021X
|
1417 WPA_KEY_MGMT_FT_PSK
|
1418 WPA_KEY_MGMT_IEEE8021X_SHA256
|
1419 WPA_KEY_MGMT_PSK_SHA256
);
1420 if (params
->wep_key_len
[params
->wep_tx_keyidx
])
1423 #ifdef DRIVER_TEST_UNIX
1424 if (drv
->test_dir
&& params
->bssid
&&
1425 params
->mode
!= IEEE80211_MODE_IBSS
) {
1426 os_memset(&drv
->hostapd_addr
, 0, sizeof(drv
->hostapd_addr
));
1427 drv
->hostapd_addr
.sun_family
= AF_UNIX
;
1428 os_snprintf(drv
->hostapd_addr
.sun_path
,
1429 sizeof(drv
->hostapd_addr
.sun_path
),
1431 drv
->test_dir
, MAC2STR(params
->bssid
));
1432 drv
->hostapd_addr_set
= 1;
1434 #endif /* DRIVER_TEST_UNIX */
1436 if (drv
->test_socket
>= 0 &&
1437 (drv
->hostapd_addr_set
|| drv
->hostapd_addr_udp_set
)) {
1438 char cmd
[200], *pos
, *end
;
1440 end
= cmd
+ sizeof(cmd
);
1442 ret
= os_snprintf(pos
, end
- pos
, "ASSOC " MACSTR
" ",
1443 MAC2STR(drv
->own_addr
));
1444 if (ret
>= 0 && ret
< end
- pos
)
1446 pos
+= wpa_snprintf_hex(pos
, end
- pos
, params
->ssid
,
1448 ret
= os_snprintf(pos
, end
- pos
, " ");
1449 if (ret
>= 0 && ret
< end
- pos
)
1451 pos
+= wpa_snprintf_hex(pos
, end
- pos
, params
->wpa_ie
,
1452 params
->wpa_ie_len
);
1454 #ifdef DRIVER_TEST_UNIX
1455 if (drv
->hostapd_addr_set
&&
1456 sendto(drv
->test_socket
, cmd
, os_strlen(cmd
), 0,
1457 (struct sockaddr
*) &drv
->hostapd_addr
,
1458 sizeof(drv
->hostapd_addr
)) < 0) {
1459 perror("sendto(test_socket)");
1462 #endif /* DRIVER_TEST_UNIX */
1463 if (drv
->hostapd_addr_udp_set
&&
1464 sendto(drv
->test_socket
, cmd
, os_strlen(cmd
), 0,
1465 (struct sockaddr
*) &drv
->hostapd_addr_udp
,
1466 sizeof(drv
->hostapd_addr_udp
)) < 0) {
1467 perror("sendto(test_socket)");
1471 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
1472 drv
->ssid_len
= params
->ssid_len
;
1474 drv
->associated
= 1;
1475 if (params
->mode
== IEEE80211_MODE_IBSS
) {
1476 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
1477 drv
->ssid_len
= params
->ssid_len
;
1479 os_memcpy(drv
->bssid
, params
->bssid
, ETH_ALEN
);
1481 os_get_random(drv
->bssid
, ETH_ALEN
);
1482 drv
->bssid
[0] &= ~0x01;
1483 drv
->bssid
[0] |= 0x02;
1486 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1493 static int wpa_driver_test_get_bssid(void *priv
, u8
*bssid
)
1495 struct wpa_driver_test_data
*drv
= priv
;
1496 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
1501 static int wpa_driver_test_get_ssid(void *priv
, u8
*ssid
)
1503 struct wpa_driver_test_data
*drv
= priv
;
1504 os_memcpy(ssid
, drv
->ssid
, 32);
1505 return drv
->ssid_len
;
1509 static int wpa_driver_test_send_disassoc(struct wpa_driver_test_data
*drv
)
1511 #ifdef DRIVER_TEST_UNIX
1512 if (drv
->test_socket
>= 0 &&
1513 sendto(drv
->test_socket
, "DISASSOC", 8, 0,
1514 (struct sockaddr
*) &drv
->hostapd_addr
,
1515 sizeof(drv
->hostapd_addr
)) < 0) {
1516 perror("sendto(test_socket)");
1519 #endif /* DRIVER_TEST_UNIX */
1520 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_udp_set
&&
1521 sendto(drv
->test_socket
, "DISASSOC", 8, 0,
1522 (struct sockaddr
*) &drv
->hostapd_addr_udp
,
1523 sizeof(drv
->hostapd_addr_udp
)) < 0) {
1524 perror("sendto(test_socket)");
1531 static int wpa_driver_test_deauthenticate(void *priv
, const u8
*addr
,
1534 struct wpa_driver_test_data
*drv
= priv
;
1535 wpa_printf(MSG_DEBUG
, "%s addr=" MACSTR
" reason_code=%d",
1536 __func__
, MAC2STR(addr
), reason_code
);
1537 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1538 drv
->associated
= 0;
1539 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1540 return wpa_driver_test_send_disassoc(drv
);
1544 static int wpa_driver_test_disassociate(void *priv
, const u8
*addr
,
1547 struct wpa_driver_test_data
*drv
= priv
;
1548 wpa_printf(MSG_DEBUG
, "%s addr=" MACSTR
" reason_code=%d",
1549 __func__
, MAC2STR(addr
), reason_code
);
1550 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1551 drv
->associated
= 0;
1552 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1553 return wpa_driver_test_send_disassoc(drv
);
1557 static void wpa_driver_test_scanresp(struct wpa_driver_test_data
*drv
,
1558 struct sockaddr
*from
,
1562 struct wpa_scan_res
*res
;
1563 const char *pos
, *pos2
;
1565 u8
*ie_pos
, *ie_start
, *ie_end
;
1566 #define MAX_IE_LEN 1000
1568 wpa_printf(MSG_DEBUG
, "test_driver: SCANRESP %s", data
);
1569 if (drv
->num_scanres
>= MAX_SCAN_RESULTS
) {
1570 wpa_printf(MSG_DEBUG
, "test_driver: No room for the new scan "
1575 /* SCANRESP BSSID SSID IEs */
1577 res
= os_zalloc(sizeof(*res
) + MAX_IE_LEN
);
1580 ie_start
= ie_pos
= (u8
*) (res
+ 1);
1581 ie_end
= ie_pos
+ MAX_IE_LEN
;
1583 if (hwaddr_aton(data
, res
->bssid
)) {
1584 wpa_printf(MSG_DEBUG
, "test_driver: invalid BSSID in scanres");
1592 pos2
= os_strchr(pos
, ' ');
1594 wpa_printf(MSG_DEBUG
, "test_driver: invalid SSID termination "
1599 len
= (pos2
- pos
) / 2;
1603 * Generate SSID IE from the SSID field since this IE is not included
1604 * in the main IE field.
1606 *ie_pos
++ = WLAN_EID_SSID
;
1608 if (hexstr2bin(pos
, ie_pos
, len
) < 0) {
1609 wpa_printf(MSG_DEBUG
, "test_driver: invalid SSID in scanres");
1616 pos2
= os_strchr(pos
, ' ');
1618 len
= os_strlen(pos
) / 2;
1620 len
= (pos2
- pos
) / 2;
1621 if ((int) len
> ie_end
- ie_pos
)
1622 len
= ie_end
- ie_pos
;
1623 if (hexstr2bin(pos
, ie_pos
, len
) < 0) {
1624 wpa_printf(MSG_DEBUG
, "test_driver: invalid IEs in scanres");
1629 res
->ie_len
= ie_pos
- ie_start
;
1635 if (os_strstr(pos
, "PRIVACY"))
1636 res
->caps
|= IEEE80211_CAP_PRIVACY
;
1637 if (os_strstr(pos
, "IBSS"))
1638 res
->caps
|= IEEE80211_CAP_IBSS
;
1641 os_free(drv
->scanres
[drv
->num_scanres
]);
1642 drv
->scanres
[drv
->num_scanres
++] = res
;
1646 static void wpa_driver_test_assocresp(struct wpa_driver_test_data
*drv
,
1647 struct sockaddr
*from
,
1651 /* ASSOCRESP BSSID <res> */
1652 if (hwaddr_aton(data
, drv
->bssid
)) {
1653 wpa_printf(MSG_DEBUG
, "test_driver: invalid BSSID in "
1656 if (drv
->use_associnfo
) {
1657 union wpa_event_data event
;
1658 os_memset(&event
, 0, sizeof(event
));
1659 event
.assoc_info
.req_ies
= drv
->assoc_wpa_ie
;
1660 event
.assoc_info
.req_ies_len
= drv
->assoc_wpa_ie_len
;
1661 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOCINFO
, &event
);
1663 drv
->associated
= 1;
1664 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1668 static void wpa_driver_test_disassoc(struct wpa_driver_test_data
*drv
,
1669 struct sockaddr
*from
,
1672 drv
->associated
= 0;
1673 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1677 static void wpa_driver_test_eapol(struct wpa_driver_test_data
*drv
,
1678 struct sockaddr
*from
,
1680 const u8
*data
, size_t data_len
)
1682 const u8
*src
= drv
->bssid
;
1684 if (data_len
> 14) {
1685 /* Skip Ethernet header */
1686 src
= data
+ ETH_ALEN
;
1690 wpa_supplicant_rx_eapol(drv
->ctx
, src
, data
, data_len
);
1694 static void wpa_driver_test_mlme(struct wpa_driver_test_data
*drv
,
1695 struct sockaddr
*from
,
1697 const u8
*data
, size_t data_len
)
1699 #ifdef CONFIG_CLIENT_MLME
1700 struct ieee80211_rx_status rx_status
;
1701 os_memset(&rx_status
, 0, sizeof(rx_status
));
1702 wpa_supplicant_sta_rx(drv
->ctx
, data
, data_len
, &rx_status
);
1703 #endif /* CONFIG_CLIENT_MLME */
1707 static void wpa_driver_test_scan_cmd(struct wpa_driver_test_data
*drv
,
1708 struct sockaddr
*from
,
1710 const u8
*data
, size_t data_len
)
1712 char buf
[512], *pos
, *end
;
1715 /* data: optional [ STA-addr | ' ' | IEs(hex) ] */
1721 end
= buf
+ sizeof(buf
);
1723 /* reply: SCANRESP BSSID SSID IEs */
1724 ret
= snprintf(pos
, end
- pos
, "SCANRESP " MACSTR
" ",
1725 MAC2STR(drv
->bssid
));
1726 if (ret
< 0 || ret
>= end
- pos
)
1729 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
1730 drv
->ssid
, drv
->ssid_len
);
1731 ret
= snprintf(pos
, end
- pos
, " ");
1732 if (ret
< 0 || ret
>= end
- pos
)
1735 pos
+= wpa_snprintf_hex(pos
, end
- pos
, drv
->assoc_wpa_ie
,
1736 drv
->assoc_wpa_ie_len
);
1739 ret
= snprintf(pos
, end
- pos
, " PRIVACY");
1740 if (ret
< 0 || ret
>= end
- pos
)
1745 ret
= snprintf(pos
, end
- pos
, " IBSS");
1746 if (ret
< 0 || ret
>= end
- pos
)
1750 sendto(drv
->test_socket
, buf
, pos
- buf
, 0,
1751 (struct sockaddr
*) from
, fromlen
);
1755 static void wpa_driver_test_receive_unix(int sock
, void *eloop_ctx
,
1758 struct wpa_driver_test_data
*drv
= eloop_ctx
;
1761 struct sockaddr_storage from
;
1762 socklen_t fromlen
= sizeof(from
);
1763 const size_t buflen
= 2000;
1765 buf
= os_malloc(buflen
);
1768 res
= recvfrom(sock
, buf
, buflen
- 1, 0,
1769 (struct sockaddr
*) &from
, &fromlen
);
1771 perror("recvfrom(test_socket)");
1777 wpa_printf(MSG_DEBUG
, "test_driver: received %u bytes", res
);
1779 if (os_strncmp(buf
, "SCANRESP ", 9) == 0) {
1780 wpa_driver_test_scanresp(drv
, (struct sockaddr
*) &from
,
1782 } else if (os_strncmp(buf
, "ASSOCRESP ", 10) == 0) {
1783 wpa_driver_test_assocresp(drv
, (struct sockaddr
*) &from
,
1785 } else if (os_strcmp(buf
, "DISASSOC") == 0) {
1786 wpa_driver_test_disassoc(drv
, (struct sockaddr
*) &from
,
1788 } else if (os_strcmp(buf
, "DEAUTH") == 0) {
1789 wpa_driver_test_disassoc(drv
, (struct sockaddr
*) &from
,
1791 } else if (os_strncmp(buf
, "EAPOL ", 6) == 0) {
1792 wpa_driver_test_eapol(drv
, (struct sockaddr
*) &from
, fromlen
,
1793 (const u8
*) buf
+ 6, res
- 6);
1794 } else if (os_strncmp(buf
, "MLME ", 5) == 0) {
1795 wpa_driver_test_mlme(drv
, (struct sockaddr
*) &from
, fromlen
,
1796 (const u8
*) buf
+ 5, res
- 5);
1797 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
1798 wpa_driver_test_scan_cmd(drv
, (struct sockaddr
*) &from
,
1800 (const u8
*) buf
+ 5, res
- 5);
1802 wpa_hexdump_ascii(MSG_DEBUG
, "Unknown test_socket command",
1809 static void * wpa_driver_test_init2(void *ctx
, const char *ifname
,
1812 struct wpa_driver_test_data
*drv
;
1814 drv
= os_zalloc(sizeof(*drv
));
1817 drv
->global
= global_priv
;
1819 drv
->test_socket
= -1;
1821 /* Set dummy BSSID and SSID for testing. */
1822 drv
->bssid
[0] = 0x02;
1823 drv
->bssid
[1] = 0x00;
1824 drv
->bssid
[2] = 0x00;
1825 drv
->bssid
[3] = 0x00;
1826 drv
->bssid
[4] = 0x00;
1827 drv
->bssid
[5] = 0x01;
1828 os_memcpy(drv
->ssid
, "test", 5);
1831 /* Generate a MAC address to help testing with multiple STAs */
1832 drv
->own_addr
[0] = 0x02; /* locally administered */
1833 sha1_prf((const u8
*) ifname
, os_strlen(ifname
),
1834 "wpa_supplicant test mac addr generation",
1835 NULL
, 0, drv
->own_addr
+ 1, ETH_ALEN
- 1);
1836 eloop_register_timeout(1, 0, wpa_driver_test_poll
, drv
, NULL
);
1842 static void wpa_driver_test_close_test_socket(struct wpa_driver_test_data
*drv
)
1844 if (drv
->test_socket
>= 0) {
1845 eloop_unregister_read_sock(drv
->test_socket
);
1846 close(drv
->test_socket
);
1847 drv
->test_socket
= -1;
1850 if (drv
->own_socket_path
) {
1851 unlink(drv
->own_socket_path
);
1852 os_free(drv
->own_socket_path
);
1853 drv
->own_socket_path
= NULL
;
1858 static void wpa_driver_test_deinit(void *priv
)
1860 struct wpa_driver_test_data
*drv
= priv
;
1862 wpa_driver_test_close_test_socket(drv
);
1863 eloop_cancel_timeout(wpa_driver_test_scan_timeout
, drv
, drv
->ctx
);
1864 eloop_cancel_timeout(wpa_driver_test_poll
, drv
, NULL
);
1865 os_free(drv
->test_dir
);
1866 for (i
= 0; i
< MAX_SCAN_RESULTS
; i
++)
1867 os_free(drv
->scanres
[i
]);
1868 os_free(drv
->probe_req_ie
);
1873 static int wpa_driver_test_attach(struct wpa_driver_test_data
*drv
,
1876 #ifdef DRIVER_TEST_UNIX
1877 static unsigned int counter
= 0;
1878 struct sockaddr_un addr
;
1881 os_free(drv
->own_socket_path
);
1883 len
= os_strlen(dir
) + 30;
1884 drv
->own_socket_path
= os_malloc(len
);
1885 if (drv
->own_socket_path
== NULL
)
1887 os_snprintf(drv
->own_socket_path
, len
, "%s/STA-" MACSTR
,
1888 dir
, MAC2STR(drv
->own_addr
));
1890 drv
->own_socket_path
= os_malloc(100);
1891 if (drv
->own_socket_path
== NULL
)
1893 os_snprintf(drv
->own_socket_path
, 100,
1894 "/tmp/wpa_supplicant_test-%d-%d",
1895 getpid(), counter
++);
1898 drv
->test_socket
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
1899 if (drv
->test_socket
< 0) {
1900 perror("socket(PF_UNIX)");
1901 os_free(drv
->own_socket_path
);
1902 drv
->own_socket_path
= NULL
;
1906 os_memset(&addr
, 0, sizeof(addr
));
1907 addr
.sun_family
= AF_UNIX
;
1908 os_strlcpy(addr
.sun_path
, drv
->own_socket_path
, sizeof(addr
.sun_path
));
1909 if (bind(drv
->test_socket
, (struct sockaddr
*) &addr
,
1910 sizeof(addr
)) < 0) {
1911 perror("bind(PF_UNIX)");
1912 close(drv
->test_socket
);
1913 unlink(drv
->own_socket_path
);
1914 os_free(drv
->own_socket_path
);
1915 drv
->own_socket_path
= NULL
;
1919 eloop_register_read_sock(drv
->test_socket
,
1920 wpa_driver_test_receive_unix
, drv
, NULL
);
1923 #else /* DRIVER_TEST_UNIX */
1925 #endif /* DRIVER_TEST_UNIX */
1929 static int wpa_driver_test_attach_udp(struct wpa_driver_test_data
*drv
,
1934 pos
= os_strchr(dst
, ':');
1938 wpa_printf(MSG_DEBUG
, "%s: addr=%s port=%s", __func__
, dst
, pos
);
1940 drv
->test_socket
= socket(PF_INET
, SOCK_DGRAM
, 0);
1941 if (drv
->test_socket
< 0) {
1942 perror("socket(PF_INET)");
1946 os_memset(&drv
->hostapd_addr_udp
, 0, sizeof(drv
->hostapd_addr_udp
));
1947 drv
->hostapd_addr_udp
.sin_family
= AF_INET
;
1948 #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
1952 sscanf(dst
, "%d.%d.%d.%d", &a
[0], &a
[1], &a
[2], &a
[3]);
1953 pos
= (u8
*) &drv
->hostapd_addr_udp
.sin_addr
;
1959 #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1960 inet_aton(dst
, &drv
->hostapd_addr_udp
.sin_addr
);
1961 #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1962 drv
->hostapd_addr_udp
.sin_port
= htons(atoi(pos
));
1964 drv
->hostapd_addr_udp_set
= 1;
1966 eloop_register_read_sock(drv
->test_socket
,
1967 wpa_driver_test_receive_unix
, drv
, NULL
);
1973 static int wpa_driver_test_set_param(void *priv
, const char *param
)
1975 struct wpa_driver_test_data
*drv
= priv
;
1978 wpa_printf(MSG_DEBUG
, "%s: param='%s'", __func__
, param
);
1982 wpa_driver_test_close_test_socket(drv
);
1984 #ifdef DRIVER_TEST_UNIX
1985 pos
= os_strstr(param
, "test_socket=");
1991 pos2
= os_strchr(pos
, ' ');
1995 len
= os_strlen(pos
);
1996 if (len
> sizeof(drv
->hostapd_addr
.sun_path
))
1998 os_memset(&drv
->hostapd_addr
, 0, sizeof(drv
->hostapd_addr
));
1999 drv
->hostapd_addr
.sun_family
= AF_UNIX
;
2000 os_memcpy(drv
->hostapd_addr
.sun_path
, pos
, len
);
2001 drv
->hostapd_addr_set
= 1;
2003 #endif /* DRIVER_TEST_UNIX */
2005 pos
= os_strstr(param
, "test_dir=");
2008 os_free(drv
->test_dir
);
2009 drv
->test_dir
= os_strdup(pos
+ 9);
2010 if (drv
->test_dir
== NULL
)
2012 end
= os_strchr(drv
->test_dir
, ' ');
2015 if (wpa_driver_test_attach(drv
, drv
->test_dir
))
2018 pos
= os_strstr(param
, "test_udp=");
2021 dst
= os_strdup(pos
+ 9);
2024 epos
= os_strchr(dst
, ' ');
2027 if (wpa_driver_test_attach_udp(drv
, dst
))
2030 } else if (wpa_driver_test_attach(drv
, NULL
))
2034 if (os_strstr(param
, "use_associnfo=1")) {
2035 wpa_printf(MSG_DEBUG
, "test_driver: Use AssocInfo events");
2036 drv
->use_associnfo
= 1;
2039 #ifdef CONFIG_CLIENT_MLME
2040 if (os_strstr(param
, "use_mlme=1")) {
2041 wpa_printf(MSG_DEBUG
, "test_driver: Use internal MLME");
2044 #endif /* CONFIG_CLIENT_MLME */
2050 static const u8
* wpa_driver_test_get_mac_addr(void *priv
)
2052 struct wpa_driver_test_data
*drv
= priv
;
2053 wpa_printf(MSG_DEBUG
, "%s", __func__
);
2054 return drv
->own_addr
;
2058 static int wpa_driver_test_send_eapol(void *priv
, const u8
*dest
, u16 proto
,
2059 const u8
*data
, size_t data_len
)
2061 struct wpa_driver_test_data
*drv
= priv
;
2064 struct l2_ethhdr eth
;
2065 struct sockaddr
*addr
;
2067 #ifdef DRIVER_TEST_UNIX
2068 struct sockaddr_un addr_un
;
2069 #endif /* DRIVER_TEST_UNIX */
2071 wpa_hexdump(MSG_MSGDUMP
, "test_send_eapol TX frame", data
, data_len
);
2073 os_memset(ð
, 0, sizeof(eth
));
2074 os_memcpy(eth
.h_dest
, dest
, ETH_ALEN
);
2075 os_memcpy(eth
.h_source
, drv
->own_addr
, ETH_ALEN
);
2076 eth
.h_proto
= host_to_be16(proto
);
2078 msg_len
= 6 + sizeof(eth
) + data_len
;
2079 msg
= os_malloc(msg_len
);
2082 os_memcpy(msg
, "EAPOL ", 6);
2083 os_memcpy(msg
+ 6, ð
, sizeof(eth
));
2084 os_memcpy(msg
+ 6 + sizeof(eth
), data
, data_len
);
2086 if (os_memcmp(dest
, drv
->bssid
, ETH_ALEN
) == 0 ||
2087 drv
->test_dir
== NULL
) {
2088 if (drv
->hostapd_addr_udp_set
) {
2089 addr
= (struct sockaddr
*) &drv
->hostapd_addr_udp
;
2090 alen
= sizeof(drv
->hostapd_addr_udp
);
2092 #ifdef DRIVER_TEST_UNIX
2093 addr
= (struct sockaddr
*) &drv
->hostapd_addr
;
2094 alen
= sizeof(drv
->hostapd_addr
);
2095 #else /* DRIVER_TEST_UNIX */
2098 #endif /* DRIVER_TEST_UNIX */
2101 #ifdef DRIVER_TEST_UNIX
2103 os_memset(&addr_un
, 0, sizeof(addr_un
));
2104 addr_un
.sun_family
= AF_UNIX
;
2105 os_snprintf(addr_un
.sun_path
, sizeof(addr_un
.sun_path
),
2106 "%s/STA-" MACSTR
, drv
->test_dir
, MAC2STR(dest
));
2107 if (stat(addr_un
.sun_path
, &st
) < 0) {
2108 os_snprintf(addr_un
.sun_path
, sizeof(addr_un
.sun_path
),
2110 drv
->test_dir
, MAC2STR(dest
));
2112 addr
= (struct sockaddr
*) &addr_un
;
2113 alen
= sizeof(addr_un
);
2114 #else /* DRIVER_TEST_UNIX */
2117 #endif /* DRIVER_TEST_UNIX */
2120 if (sendto(drv
->test_socket
, msg
, msg_len
, 0, addr
, alen
) < 0) {
2121 perror("sendmsg(test_socket)");
2131 static int wpa_driver_test_get_capa(void *priv
, struct wpa_driver_capa
*capa
)
2133 struct wpa_driver_test_data
*drv
= priv
;
2134 os_memset(capa
, 0, sizeof(*capa
));
2135 capa
->key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2136 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2137 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2138 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
|
2139 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
|
2140 WPA_DRIVER_CAPA_KEY_MGMT_FT
|
2141 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
2142 capa
->enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2143 WPA_DRIVER_CAPA_ENC_WEP104
|
2144 WPA_DRIVER_CAPA_ENC_TKIP
|
2145 WPA_DRIVER_CAPA_ENC_CCMP
;
2146 capa
->auth
= WPA_DRIVER_AUTH_OPEN
|
2147 WPA_DRIVER_AUTH_SHARED
|
2148 WPA_DRIVER_AUTH_LEAP
;
2150 capa
->flags
|= WPA_DRIVER_FLAGS_USER_SPACE_MLME
;
2151 capa
->max_scan_ssids
= 2;
2157 static int wpa_driver_test_mlme_setprotection(void *priv
, const u8
*addr
,
2161 wpa_printf(MSG_DEBUG
, "%s: protect_type=%d key_type=%d",
2162 __func__
, protect_type
, key_type
);
2165 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
,
2166 __func__
, MAC2STR(addr
));
2173 #ifdef CONFIG_CLIENT_MLME
2174 static int wpa_driver_test_set_channel(void *priv
, hostapd_hw_mode phymode
,
2177 wpa_printf(MSG_DEBUG
, "%s: phymode=%d chan=%d freq=%d",
2178 __func__
, phymode
, chan
, freq
);
2183 static int wpa_driver_test_send_mlme(void *priv
, const u8
*data
,
2186 struct wpa_driver_test_data
*drv
= priv
;
2189 struct sockaddr_un addr
;
2191 struct dirent
*dent
;
2194 wpa_hexdump(MSG_MSGDUMP
, "test_send_mlme", data
, data_len
);
2199 io
[0].iov_base
= "MLME ";
2201 io
[1].iov_base
= (u8
*) data
;
2202 io
[1].iov_len
= data_len
;
2204 os_memset(&msg
, 0, sizeof(msg
));
2207 if (os_memcmp(dest
, drv
->bssid
, ETH_ALEN
) == 0 ||
2208 drv
->test_dir
== NULL
) {
2209 if (drv
->hostapd_addr_udp_set
) {
2210 msg
.msg_name
= &drv
->hostapd_addr_udp
;
2211 msg
.msg_namelen
= sizeof(drv
->hostapd_addr_udp
);
2213 #ifdef DRIVER_TEST_UNIX
2214 msg
.msg_name
= &drv
->hostapd_addr
;
2215 msg
.msg_namelen
= sizeof(drv
->hostapd_addr
);
2216 #endif /* DRIVER_TEST_UNIX */
2218 } else if (os_memcmp(dest
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0)
2220 dir
= opendir(drv
->test_dir
);
2223 while ((dent
= readdir(dir
))) {
2224 #ifdef _DIRENT_HAVE_D_TYPE
2225 /* Skip the file if it is not a socket.
2226 * Also accept DT_UNKNOWN (0) in case
2227 * the C library or underlying file
2228 * system does not support d_type. */
2229 if (dent
->d_type
!= DT_SOCK
&&
2230 dent
->d_type
!= DT_UNKNOWN
)
2232 #endif /* _DIRENT_HAVE_D_TYPE */
2233 if (os_strcmp(dent
->d_name
, ".") == 0 ||
2234 os_strcmp(dent
->d_name
, "..") == 0)
2236 wpa_printf(MSG_DEBUG
, "%s: Send broadcast MLME to %s",
2237 __func__
, dent
->d_name
);
2238 os_memset(&addr
, 0, sizeof(addr
));
2239 addr
.sun_family
= AF_UNIX
;
2240 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
2241 "%s/%s", drv
->test_dir
, dent
->d_name
);
2243 msg
.msg_name
= &addr
;
2244 msg
.msg_namelen
= sizeof(addr
);
2246 if (sendmsg(drv
->test_socket
, &msg
, 0) < 0)
2247 perror("sendmsg(test_socket)");
2253 os_memset(&addr
, 0, sizeof(addr
));
2254 addr
.sun_family
= AF_UNIX
;
2255 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
2256 "%s/AP-" MACSTR
, drv
->test_dir
, MAC2STR(dest
));
2257 if (stat(addr
.sun_path
, &st
) < 0) {
2258 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
2260 drv
->test_dir
, MAC2STR(dest
));
2262 msg
.msg_name
= &addr
;
2263 msg
.msg_namelen
= sizeof(addr
);
2266 if (sendmsg(drv
->test_socket
, &msg
, 0) < 0) {
2267 perror("sendmsg(test_socket)");
2275 static int wpa_driver_test_mlme_add_sta(void *priv
, const u8
*addr
,
2276 const u8
*supp_rates
,
2277 size_t supp_rates_len
)
2279 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
, __func__
, MAC2STR(addr
));
2284 static int wpa_driver_test_mlme_remove_sta(void *priv
, const u8
*addr
)
2286 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
, __func__
, MAC2STR(addr
));
2291 static int wpa_driver_test_set_ssid(void *priv
, const u8
*ssid
,
2294 wpa_printf(MSG_DEBUG
, "%s", __func__
);
2299 static int wpa_driver_test_set_bssid(void *priv
, const u8
*bssid
)
2301 wpa_printf(MSG_DEBUG
, "%s: bssid=" MACSTR
, __func__
, MAC2STR(bssid
));
2304 #endif /* CONFIG_CLIENT_MLME */
2307 static int wpa_driver_test_set_probe_req_ie(void *priv
, const u8
*ies
,
2310 struct wpa_driver_test_data
*drv
= priv
;
2312 os_free(drv
->probe_req_ie
);
2314 drv
->probe_req_ie
= os_malloc(ies_len
);
2315 if (drv
->probe_req_ie
== NULL
) {
2316 drv
->probe_req_ie_len
= 0;
2319 os_memcpy(drv
->probe_req_ie
, ies
, ies_len
);
2320 drv
->probe_req_ie_len
= ies_len
;
2322 drv
->probe_req_ie
= NULL
;
2323 drv
->probe_req_ie_len
= 0;
2329 static void * wpa_driver_test_global_init(void)
2331 struct wpa_driver_test_global
*global
;
2333 global
= os_zalloc(sizeof(*global
));
2338 static void wpa_driver_test_global_deinit(void *priv
)
2340 struct wpa_driver_test_global
*global
= priv
;
2345 static struct wpa_interface_info
*
2346 wpa_driver_test_get_interfaces(void *global_priv
)
2348 /* struct wpa_driver_test_global *global = priv; */
2349 struct wpa_interface_info
*iface
;
2351 iface
= os_zalloc(sizeof(*iface
));
2354 iface
->ifname
= os_strdup("sta0");
2355 iface
->desc
= os_strdup("test interface 0");
2356 iface
->drv_name
= "test";
2357 iface
->next
= os_zalloc(sizeof(*iface
));
2359 iface
->next
->ifname
= os_strdup("sta1");
2360 iface
->next
->desc
= os_strdup("test interface 1");
2361 iface
->next
->drv_name
= "test";
2367 #endif /* HOSTAPD */
2370 #if defined(HOSTAPD) || defined(CONFIG_CLIENT_MLME)
2371 static struct hostapd_hw_modes
*
2372 wpa_driver_test_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
2374 struct hostapd_hw_modes
*modes
;
2378 modes
= os_zalloc(*num_modes
* sizeof(struct hostapd_hw_modes
));
2381 modes
[0].mode
= HOSTAPD_MODE_IEEE80211G
;
2382 modes
[0].num_channels
= 1;
2383 modes
[0].num_rates
= 1;
2384 modes
[0].channels
= os_zalloc(sizeof(struct hostapd_channel_data
));
2385 modes
[0].rates
= os_zalloc(sizeof(struct hostapd_rate_data
));
2386 if (modes
[0].channels
== NULL
|| modes
[0].rates
== NULL
)
2388 modes
[0].channels
[0].chan
= 1;
2389 modes
[0].channels
[0].freq
= 2412;
2390 modes
[0].channels
[0].flag
= 0;
2391 modes
[0].rates
[0].rate
= 10;
2392 modes
[0].rates
[0].flags
= HOSTAPD_RATE_BASIC
| HOSTAPD_RATE_SUPPORTED
|
2393 HOSTAPD_RATE_CCK
| HOSTAPD_RATE_MANDATORY
;
2395 modes
[1].mode
= HOSTAPD_MODE_IEEE80211B
;
2396 modes
[1].num_channels
= 1;
2397 modes
[1].num_rates
= 1;
2398 modes
[1].channels
= os_zalloc(sizeof(struct hostapd_channel_data
));
2399 modes
[1].rates
= os_zalloc(sizeof(struct hostapd_rate_data
));
2400 if (modes
[1].channels
== NULL
|| modes
[1].rates
== NULL
)
2402 modes
[1].channels
[0].chan
= 1;
2403 modes
[1].channels
[0].freq
= 2412;
2404 modes
[1].channels
[0].flag
= 0;
2405 modes
[1].rates
[0].rate
= 10;
2406 modes
[1].rates
[0].flags
= HOSTAPD_RATE_BASIC
| HOSTAPD_RATE_SUPPORTED
|
2407 HOSTAPD_RATE_CCK
| HOSTAPD_RATE_MANDATORY
;
2409 modes
[2].mode
= HOSTAPD_MODE_IEEE80211A
;
2410 modes
[2].num_channels
= 1;
2411 modes
[2].num_rates
= 1;
2412 modes
[2].channels
= os_zalloc(sizeof(struct hostapd_channel_data
));
2413 modes
[2].rates
= os_zalloc(sizeof(struct hostapd_rate_data
));
2414 if (modes
[2].channels
== NULL
|| modes
[2].rates
== NULL
)
2416 modes
[2].channels
[0].chan
= 60;
2417 modes
[2].channels
[0].freq
= 5300;
2418 modes
[2].channels
[0].flag
= 0;
2419 modes
[2].rates
[0].rate
= 60;
2420 modes
[2].rates
[0].flags
= HOSTAPD_RATE_BASIC
| HOSTAPD_RATE_SUPPORTED
|
2421 HOSTAPD_RATE_MANDATORY
;
2428 for (i
= 0; i
< *num_modes
; i
++) {
2429 os_free(modes
[i
].channels
);
2430 os_free(modes
[i
].rates
);
2436 #endif /* HOSTAPD || CONFIG_CLIENT_MLME */
2439 const struct wpa_driver_ops wpa_driver_test_ops
= {
2441 "wpa_supplicant test driver",
2443 .hapd_init
= test_driver_init
,
2444 .hapd_deinit
= test_driver_deinit
,
2445 .hapd_send_eapol
= test_driver_send_eapol
,
2446 .send_mlme
= wpa_driver_test_send_mlme
,
2447 .set_generic_elem
= test_driver_set_generic_elem
,
2448 .sta_deauth
= test_driver_sta_deauth
,
2449 .sta_disassoc
= test_driver_sta_disassoc
,
2450 .get_hw_feature_data
= wpa_driver_test_get_hw_feature_data
,
2451 .bss_add
= test_driver_bss_add
,
2452 .bss_remove
= test_driver_bss_remove
,
2453 .if_add
= test_driver_if_add
,
2454 .if_update
= test_driver_if_update
,
2455 .if_remove
= test_driver_if_remove
,
2456 .valid_bss_mask
= test_driver_valid_bss_mask
,
2457 .hapd_set_ssid
= test_driver_set_ssid
,
2458 .set_privacy
= test_driver_set_privacy
,
2459 .hapd_set_key
= test_driver_set_key
,
2460 .set_sta_vlan
= test_driver_set_sta_vlan
,
2461 .sta_add
= test_driver_sta_add
,
2462 .send_ether
= test_driver_send_ether
,
2463 .set_wps_beacon_ie
= test_driver_set_wps_beacon_ie
,
2464 .set_wps_probe_resp_ie
= test_driver_set_wps_probe_resp_ie
,
2466 wpa_driver_test_get_bssid
,
2467 wpa_driver_test_get_ssid
,
2468 wpa_driver_test_set_wpa
,
2469 wpa_driver_test_set_key
,
2471 wpa_driver_test_deinit
,
2472 wpa_driver_test_set_param
,
2473 NULL
/* set_countermeasures */,
2474 NULL
/* set_drop_unencrypted */,
2476 NULL
/* get_scan_results */,
2477 wpa_driver_test_deauthenticate
,
2478 wpa_driver_test_disassociate
,
2479 wpa_driver_test_associate
,
2480 NULL
/* set_auth_alg */,
2481 NULL
/* add_pmkid */,
2482 NULL
/* remove_pmkid */,
2483 NULL
/* flush_pmkid */,
2484 wpa_driver_test_get_capa
,
2486 NULL
/* get_ifname */,
2487 wpa_driver_test_get_mac_addr
,
2488 wpa_driver_test_send_eapol
,
2489 NULL
/* set_operstate */,
2490 wpa_driver_test_mlme_setprotection
,
2491 #ifdef CONFIG_CLIENT_MLME
2492 wpa_driver_test_get_hw_feature_data
,
2493 wpa_driver_test_set_channel
,
2494 wpa_driver_test_set_ssid
,
2495 wpa_driver_test_set_bssid
,
2496 wpa_driver_test_send_mlme
,
2497 wpa_driver_test_mlme_add_sta
,
2498 wpa_driver_test_mlme_remove_sta
,
2499 #else /* CONFIG_CLIENT_MLME */
2500 NULL
/* get_hw_feature_data */,
2501 NULL
/* set_channel */,
2502 NULL
/* set_ssid */,
2503 NULL
/* set_bssid */,
2504 NULL
/* send_mlme */,
2505 NULL
/* mlme_add_sta */,
2506 NULL
/* mlme_remove_sta */,
2507 #endif /* CONFIG_CLIENT_MLME */
2508 NULL
/* update_ft_ies */,
2509 NULL
/* send_ft_action */,
2510 wpa_driver_test_get_scan_results2
,
2511 wpa_driver_test_set_probe_req_ie
,
2512 NULL
/* set_mode */,
2513 NULL
/* set_country */,
2514 wpa_driver_test_global_init
,
2515 wpa_driver_test_global_deinit
,
2516 wpa_driver_test_init2
,
2517 wpa_driver_test_get_interfaces
,
2518 wpa_driver_test_scan
,
2519 NULL
/* authenticate */,
2520 NULL
/* set_beacon */,
2521 NULL
/* set_beacon_int */,
2522 NULL
/* hapd_init */,
2523 NULL
/* hapd_deinit */,
2524 NULL
/* set_ieee8021x */,
2525 NULL
/* set_privacy */,
2526 NULL
/* hapd_set_key */,
2527 NULL
/* get_seqnum */,
2528 NULL
/* get_seqnum_igtk */,
2530 NULL
/* set_generic_elem */,
2531 NULL
/* read_sta_data */,
2532 NULL
/* hapd_send_eapol */,
2533 NULL
/* sta_deauth */,
2534 NULL
/* sta_disassoc */,
2535 NULL
/* sta_remove */,
2536 NULL
/* hapd_get_ssid */,
2537 NULL
/* hapd_set_ssid */,
2538 NULL
/* hapd_set_countermeasures */,
2540 NULL
/* get_inact_sec */,
2541 NULL
/* sta_clear_stats */,
2542 NULL
/* set_freq */,
2544 NULL
/* set_frag */,
2545 NULL
/* set_retry */,
2546 NULL
/* sta_set_flags */,
2547 NULL
/* set_rate_sets */,
2548 NULL
/* set_ieee80211d */,
2549 NULL
/* hapd_set_beacon */,
2550 NULL
/* set_internal_bridge */,
2551 NULL
/* set_broadcast_ssid */,
2552 NULL
/* set_cts_protect */,
2553 NULL
/* set_preamble */,
2554 NULL
/* set_short_slot_time */,
2555 NULL
/* set_tx_queue_params */,
2557 NULL
/* bss_remove */,
2558 NULL
/* valid_bss_mask */,
2559 NULL
/* passive_scan */,
2561 NULL
/* if_update */,
2562 NULL
/* if_remove */,
2563 NULL
/* set_sta_vlan */,
2565 NULL
/* send_ether */,
2566 NULL
/* set_radius_acl_auth */,
2567 NULL
/* set_radius_acl_expire */,
2568 NULL
/* set_ht_params */,
2569 NULL
/* set_wps_beacon_ie */,
2570 NULL
/* set_wps_probe_resp_ie */,
2571 NULL
/* get_neighbor_bss */
2572 #endif /* HOSTAPD */