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/config.h"
42 #include "../../hostapd/wpa.h"
43 #include "../../hostapd/hw_features.h"
44 #include "../../hostapd/wps_hostapd.h"
47 struct test_client_socket
{
48 struct test_client_socket
*next
;
50 struct sockaddr_un un
;
52 struct test_driver_bss
*bss
;
55 struct test_driver_bss
{
56 struct test_driver_bss
*next
;
57 char ifname
[IFNAMSIZ
+ 1];
62 size_t wps_beacon_ie_len
;
63 u8
*wps_probe_resp_ie
;
64 size_t wps_probe_resp_ie_len
;
70 struct test_driver_data
{
71 struct hostapd_data
*hapd
;
72 struct test_client_socket
*cli
;
74 struct test_driver_bss
*bss
;
76 char *own_socket_path
;
81 static void test_driver_free_bss(struct test_driver_bss
*bss
)
84 free(bss
->wps_beacon_ie
);
85 free(bss
->wps_probe_resp_ie
);
90 static void test_driver_free_priv(struct test_driver_data
*drv
)
92 struct test_driver_bss
*bss
, *prev
;
101 test_driver_free_bss(prev
);
103 free(drv
->own_socket_path
);
104 free(drv
->socket_dir
);
109 static struct test_client_socket
*
110 test_driver_get_cli(struct test_driver_data
*drv
, struct sockaddr_un
*from
,
113 struct test_client_socket
*cli
= drv
->cli
;
116 if (cli
->unlen
== fromlen
&&
117 strncmp(cli
->un
.sun_path
, from
->sun_path
,
118 fromlen
- sizeof(cli
->un
.sun_family
)) == 0)
127 static int test_driver_send_eapol(void *priv
, const u8
*addr
, const u8
*data
,
128 size_t data_len
, int encrypt
,
131 struct test_driver_data
*drv
= priv
;
132 struct test_client_socket
*cli
;
135 struct l2_ethhdr eth
;
137 if (drv
->test_socket
< 0)
142 if (memcmp(cli
->addr
, addr
, ETH_ALEN
) == 0)
148 wpa_printf(MSG_DEBUG
, "%s: no destination client entry",
153 memcpy(eth
.h_dest
, addr
, ETH_ALEN
);
154 memcpy(eth
.h_source
, own_addr
, ETH_ALEN
);
155 eth
.h_proto
= host_to_be16(ETH_P_EAPOL
);
157 io
[0].iov_base
= "EAPOL ";
159 io
[1].iov_base
= ð
;
160 io
[1].iov_len
= sizeof(eth
);
161 io
[2].iov_base
= (u8
*) data
;
162 io
[2].iov_len
= data_len
;
164 memset(&msg
, 0, sizeof(msg
));
167 msg
.msg_name
= &cli
->un
;
168 msg
.msg_namelen
= cli
->unlen
;
169 return sendmsg(drv
->test_socket
, &msg
, 0);
173 static int test_driver_send_ether(void *priv
, const u8
*dst
, const u8
*src
,
174 u16 proto
, const u8
*data
, size_t data_len
)
176 struct test_driver_data
*drv
= priv
;
179 struct l2_ethhdr eth
;
181 struct sockaddr_un addr
;
184 int ret
= 0, broadcast
= 0, count
= 0;
186 if (drv
->test_socket
< 0 || drv
->socket_dir
== NULL
) {
187 wpa_printf(MSG_DEBUG
, "%s: invalid parameters (sock=%d "
189 __func__
, drv
->test_socket
, drv
->socket_dir
);
193 broadcast
= memcmp(dst
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0;
194 snprintf(desttxt
, sizeof(desttxt
), MACSTR
, MAC2STR(dst
));
196 memcpy(eth
.h_dest
, dst
, ETH_ALEN
);
197 memcpy(eth
.h_source
, src
, ETH_ALEN
);
198 eth
.h_proto
= host_to_be16(proto
);
200 io
[0].iov_base
= "ETHER ";
202 io
[1].iov_base
= ð
;
203 io
[1].iov_len
= sizeof(eth
);
204 io
[2].iov_base
= (u8
*) data
;
205 io
[2].iov_len
= data_len
;
207 memset(&msg
, 0, sizeof(msg
));
211 dir
= opendir(drv
->socket_dir
);
213 perror("test_driver: opendir");
216 while ((dent
= readdir(dir
))) {
217 #ifdef _DIRENT_HAVE_D_TYPE
218 /* Skip the file if it is not a socket. Also accept
219 * DT_UNKNOWN (0) in case the C library or underlying file
220 * system does not support d_type. */
221 if (dent
->d_type
!= DT_SOCK
&& dent
->d_type
!= DT_UNKNOWN
)
223 #endif /* _DIRENT_HAVE_D_TYPE */
224 if (strcmp(dent
->d_name
, ".") == 0 ||
225 strcmp(dent
->d_name
, "..") == 0)
228 memset(&addr
, 0, sizeof(addr
));
229 addr
.sun_family
= AF_UNIX
;
230 snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s/%s",
231 drv
->socket_dir
, dent
->d_name
);
233 if (strcmp(addr
.sun_path
, drv
->own_socket_path
) == 0)
235 if (!broadcast
&& strstr(dent
->d_name
, desttxt
) == NULL
)
238 wpa_printf(MSG_DEBUG
, "%s: Send ether frame to %s",
239 __func__
, dent
->d_name
);
241 msg
.msg_name
= &addr
;
242 msg
.msg_namelen
= sizeof(addr
);
243 ret
= sendmsg(drv
->test_socket
, &msg
, 0);
245 perror("driver_test: sendmsg");
250 if (!broadcast
&& count
== 0) {
251 wpa_printf(MSG_DEBUG
, "%s: Destination " MACSTR
" not found",
252 __func__
, MAC2STR(dst
));
260 static int test_driver_send_mgmt_frame(void *priv
, const void *buf
,
261 size_t len
, int flags
)
263 struct test_driver_data
*drv
= priv
;
267 int ret
= 0, broadcast
= 0;
269 struct sockaddr_un addr
;
272 struct ieee80211_hdr
*hdr
;
275 if (drv
->test_socket
< 0 || len
< 10 || drv
->socket_dir
== NULL
) {
276 wpa_printf(MSG_DEBUG
, "%s: invalid parameters (sock=%d len=%lu"
278 __func__
, drv
->test_socket
, (unsigned long) len
,
285 broadcast
= memcmp(dest
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0;
286 snprintf(desttxt
, sizeof(desttxt
), MACSTR
, MAC2STR(dest
));
288 io
[0].iov_base
= "MLME ";
290 io
[1].iov_base
= (void *) buf
;
293 memset(&msg
, 0, sizeof(msg
));
297 dir
= opendir(drv
->socket_dir
);
299 perror("test_driver: opendir");
302 while ((dent
= readdir(dir
))) {
303 #ifdef _DIRENT_HAVE_D_TYPE
304 /* Skip the file if it is not a socket. Also accept
305 * DT_UNKNOWN (0) in case the C library or underlying file
306 * system does not support d_type. */
307 if (dent
->d_type
!= DT_SOCK
&& dent
->d_type
!= DT_UNKNOWN
)
309 #endif /* _DIRENT_HAVE_D_TYPE */
310 if (strcmp(dent
->d_name
, ".") == 0 ||
311 strcmp(dent
->d_name
, "..") == 0)
314 memset(&addr
, 0, sizeof(addr
));
315 addr
.sun_family
= AF_UNIX
;
316 snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s/%s",
317 drv
->socket_dir
, dent
->d_name
);
319 if (strcmp(addr
.sun_path
, drv
->own_socket_path
) == 0)
321 if (!broadcast
&& strstr(dent
->d_name
, desttxt
) == NULL
)
324 wpa_printf(MSG_DEBUG
, "%s: Send management frame to %s",
325 __func__
, dent
->d_name
);
327 msg
.msg_name
= &addr
;
328 msg
.msg_namelen
= sizeof(addr
);
329 ret
= sendmsg(drv
->test_socket
, &msg
, 0);
331 perror("driver_test: sendmsg");
335 hdr
= (struct ieee80211_hdr
*) buf
;
336 fc
= le_to_host16(hdr
->frame_control
);
337 hostapd_mgmt_tx_cb(drv
->hapd
, (u8
*) buf
, len
, WLAN_FC_GET_STYPE(fc
),
344 static void test_driver_scan(struct test_driver_data
*drv
,
345 struct sockaddr_un
*from
, socklen_t fromlen
,
348 char buf
[512], *pos
, *end
;
350 struct test_driver_bss
*bss
;
355 /* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
357 wpa_printf(MSG_DEBUG
, "test_driver: SCAN");
361 hwaddr_aton(data
+ 1, sa
)) {
362 wpa_printf(MSG_DEBUG
, "test_driver: Unexpected SCAN "
370 ielen
= os_strlen(data
) / 2;
371 if (ielen
> sizeof(ie
))
373 if (hexstr2bin(data
, ie
, ielen
) < 0)
376 wpa_printf(MSG_DEBUG
, "test_driver: Scan from " MACSTR
,
378 wpa_hexdump(MSG_MSGDUMP
, "test_driver: scan IEs", ie
, ielen
);
380 hostapd_wps_probe_req_rx(drv
->hapd
, sa
, ie
, ielen
);
383 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
385 end
= buf
+ sizeof(buf
);
387 /* reply: SCANRESP BSSID SSID IEs */
388 ret
= snprintf(pos
, end
- pos
, "SCANRESP " MACSTR
" ",
389 MAC2STR(bss
->bssid
));
390 if (ret
< 0 || ret
>= end
- pos
)
393 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
394 bss
->ssid
, bss
->ssid_len
);
395 ret
= snprintf(pos
, end
- pos
, " ");
396 if (ret
< 0 || ret
>= end
- pos
)
399 pos
+= wpa_snprintf_hex(pos
, end
- pos
, bss
->ie
, bss
->ielen
);
400 pos
+= wpa_snprintf_hex(pos
, end
- pos
, bss
->wps_probe_resp_ie
,
401 bss
->wps_probe_resp_ie_len
);
404 ret
= snprintf(pos
, end
- pos
, " PRIVACY");
405 if (ret
< 0 || ret
>= end
- pos
)
410 sendto(drv
->test_socket
, buf
, pos
- buf
, 0,
411 (struct sockaddr
*) from
, fromlen
);
416 static struct hostapd_data
* test_driver_get_hapd(struct test_driver_data
*drv
,
417 struct test_driver_bss
*bss
)
419 struct hostapd_iface
*iface
= drv
->hapd
->iface
;
420 struct hostapd_data
*hapd
= NULL
;
424 wpa_printf(MSG_DEBUG
, "%s: bss == NULL", __func__
);
428 for (i
= 0; i
< iface
->num_bss
; i
++) {
429 hapd
= iface
->bss
[i
];
430 if (memcmp(hapd
->own_addr
, bss
->bssid
, ETH_ALEN
) == 0)
433 if (i
== iface
->num_bss
) {
434 wpa_printf(MSG_DEBUG
, "%s: no matching interface entry found "
435 "for BSSID " MACSTR
, __func__
, MAC2STR(bss
->bssid
));
443 static int test_driver_new_sta(struct test_driver_data
*drv
,
444 struct test_driver_bss
*bss
, const u8
*addr
,
445 const u8
*ie
, size_t ielen
)
447 struct hostapd_data
*hapd
;
449 hapd
= test_driver_get_hapd(drv
, bss
);
453 return hostapd_notif_assoc(hapd
, addr
, ie
, ielen
);
457 static void test_driver_assoc(struct test_driver_data
*drv
,
458 struct sockaddr_un
*from
, socklen_t fromlen
,
461 struct test_client_socket
*cli
;
462 u8 ie
[256], ssid
[32];
463 size_t ielen
, ssid_len
= 0;
464 char *pos
, *pos2
, cmd
[50];
465 struct test_driver_bss
*bss
;
467 /* data: STA-addr SSID(hex) IEs(hex) */
469 cli
= os_zalloc(sizeof(*cli
));
473 if (hwaddr_aton(data
, cli
->addr
)) {
474 printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
482 pos2
= strchr(pos
, ' ');
485 ssid_len
= (pos2
- pos
) / 2;
486 if (hexstr2bin(pos
, ssid
, ssid_len
) < 0) {
487 wpa_printf(MSG_DEBUG
, "%s: Invalid SSID", __func__
);
491 wpa_hexdump_ascii(MSG_DEBUG
, "test_driver_assoc: SSID",
495 ielen
= strlen(pos
) / 2;
496 if (ielen
> sizeof(ie
))
498 if (hexstr2bin(pos
, ie
, ielen
) < 0)
502 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
503 if (bss
->ssid_len
== ssid_len
&&
504 memcmp(bss
->ssid
, ssid
, ssid_len
) == 0)
508 wpa_printf(MSG_DEBUG
, "%s: No matching SSID found from "
509 "configured BSSes", __func__
);
515 memcpy(&cli
->un
, from
, sizeof(cli
->un
));
516 cli
->unlen
= fromlen
;
517 cli
->next
= drv
->cli
;
519 wpa_hexdump_ascii(MSG_DEBUG
, "test_socket: ASSOC sun_path",
520 (const u8
*) cli
->un
.sun_path
,
521 cli
->unlen
- sizeof(cli
->un
.sun_family
));
523 snprintf(cmd
, sizeof(cmd
), "ASSOCRESP " MACSTR
" 0",
524 MAC2STR(bss
->bssid
));
525 sendto(drv
->test_socket
, cmd
, strlen(cmd
), 0,
526 (struct sockaddr
*) from
, fromlen
);
528 if (test_driver_new_sta(drv
, bss
, cli
->addr
, ie
, ielen
) < 0) {
529 wpa_printf(MSG_DEBUG
, "test_driver: failed to add new STA");
534 static void test_driver_disassoc(struct test_driver_data
*drv
,
535 struct sockaddr_un
*from
, socklen_t fromlen
)
537 struct test_client_socket
*cli
;
539 cli
= test_driver_get_cli(drv
, from
, fromlen
);
543 hostapd_notif_disassoc(drv
->hapd
, cli
->addr
);
547 static void test_driver_eapol(struct test_driver_data
*drv
,
548 struct sockaddr_un
*from
, socklen_t fromlen
,
549 u8
*data
, size_t datalen
)
551 struct test_client_socket
*cli
;
553 /* Skip Ethernet header */
554 wpa_printf(MSG_DEBUG
, "test_driver: dst=" MACSTR
" src="
555 MACSTR
" proto=%04x",
556 MAC2STR(data
), MAC2STR(data
+ ETH_ALEN
),
557 WPA_GET_BE16(data
+ 2 * ETH_ALEN
));
561 cli
= test_driver_get_cli(drv
, from
, fromlen
);
563 struct hostapd_data
*hapd
;
564 hapd
= test_driver_get_hapd(drv
, cli
->bss
);
567 hostapd_eapol_receive(hapd
, cli
->addr
, data
, datalen
);
569 wpa_printf(MSG_DEBUG
, "test_socket: EAPOL from unknown "
575 static void test_driver_ether(struct test_driver_data
*drv
,
576 struct sockaddr_un
*from
, socklen_t fromlen
,
577 u8
*data
, size_t datalen
)
579 struct l2_ethhdr
*eth
;
581 if (datalen
< sizeof(*eth
))
584 eth
= (struct l2_ethhdr
*) data
;
585 wpa_printf(MSG_DEBUG
, "test_driver: RX ETHER dst=" MACSTR
" src="
586 MACSTR
" proto=%04x",
587 MAC2STR(eth
->h_dest
), MAC2STR(eth
->h_source
),
588 be_to_host16(eth
->h_proto
));
590 #ifdef CONFIG_IEEE80211R
591 if (be_to_host16(eth
->h_proto
) == ETH_P_RRB
) {
592 wpa_ft_rrb_rx(drv
->hapd
->wpa_auth
, eth
->h_source
,
593 data
+ sizeof(*eth
), datalen
- sizeof(*eth
));
595 #endif /* CONFIG_IEEE80211R */
599 static void test_driver_mlme(struct test_driver_data
*drv
,
600 struct sockaddr_un
*from
, socklen_t fromlen
,
601 u8
*data
, size_t datalen
)
603 struct ieee80211_hdr
*hdr
;
606 hdr
= (struct ieee80211_hdr
*) data
;
608 if (test_driver_get_cli(drv
, from
, fromlen
) == NULL
&& datalen
>= 16) {
609 struct test_client_socket
*cli
;
610 cli
= os_zalloc(sizeof(*cli
));
613 wpa_printf(MSG_DEBUG
, "Adding client entry for " MACSTR
,
614 MAC2STR(hdr
->addr2
));
615 memcpy(cli
->addr
, hdr
->addr2
, ETH_ALEN
);
616 memcpy(&cli
->un
, from
, sizeof(cli
->un
));
617 cli
->unlen
= fromlen
;
618 cli
->next
= drv
->cli
;
622 wpa_hexdump(MSG_MSGDUMP
, "test_driver_mlme: received frame",
624 fc
= le_to_host16(hdr
->frame_control
);
625 if (WLAN_FC_GET_TYPE(fc
) != WLAN_FC_TYPE_MGMT
) {
626 wpa_printf(MSG_ERROR
, "%s: received non-mgmt frame",
630 hostapd_mgmt_rx(drv
->hapd
, data
, datalen
, WLAN_FC_GET_STYPE(fc
), NULL
);
634 static void test_driver_receive_unix(int sock
, void *eloop_ctx
, void *sock_ctx
)
636 struct test_driver_data
*drv
= eloop_ctx
;
639 struct sockaddr_un from
;
640 socklen_t fromlen
= sizeof(from
);
642 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
643 (struct sockaddr
*) &from
, &fromlen
);
645 perror("recvfrom(test_socket)");
650 wpa_printf(MSG_DEBUG
, "test_driver: received %u bytes", res
);
652 if (strncmp(buf
, "SCAN", 4) == 0) {
653 test_driver_scan(drv
, &from
, fromlen
, buf
+ 4);
654 } else if (strncmp(buf
, "ASSOC ", 6) == 0) {
655 test_driver_assoc(drv
, &from
, fromlen
, buf
+ 6);
656 } else if (strcmp(buf
, "DISASSOC") == 0) {
657 test_driver_disassoc(drv
, &from
, fromlen
);
658 } else if (strncmp(buf
, "EAPOL ", 6) == 0) {
659 test_driver_eapol(drv
, &from
, fromlen
, (u8
*) buf
+ 6,
661 } else if (strncmp(buf
, "ETHER ", 6) == 0) {
662 test_driver_ether(drv
, &from
, fromlen
, (u8
*) buf
+ 6,
664 } else if (strncmp(buf
, "MLME ", 5) == 0) {
665 test_driver_mlme(drv
, &from
, fromlen
, (u8
*) buf
+ 5, res
- 5);
667 wpa_hexdump_ascii(MSG_DEBUG
, "Unknown test_socket command",
673 static struct test_driver_bss
*
674 test_driver_get_bss(struct test_driver_data
*drv
, const char *ifname
)
676 struct test_driver_bss
*bss
;
678 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
679 if (strcmp(bss
->ifname
, ifname
) == 0)
686 static int test_driver_set_generic_elem(const char *ifname
, void *priv
,
687 const u8
*elem
, size_t elem_len
)
689 struct test_driver_data
*drv
= priv
;
690 struct test_driver_bss
*bss
;
692 bss
= test_driver_get_bss(drv
, ifname
);
704 bss
->ie
= malloc(elem_len
);
705 if (bss
->ie
== NULL
) {
710 memcpy(bss
->ie
, elem
, elem_len
);
711 bss
->ielen
= elem_len
;
716 static int test_driver_set_wps_beacon_ie(const char *ifname
, void *priv
,
717 const u8
*ie
, size_t len
)
719 struct test_driver_data
*drv
= priv
;
720 struct test_driver_bss
*bss
;
722 wpa_hexdump(MSG_DEBUG
, "test_driver: Beacon WPS IE", ie
, len
);
723 bss
= test_driver_get_bss(drv
, ifname
);
727 free(bss
->wps_beacon_ie
);
730 bss
->wps_beacon_ie
= NULL
;
731 bss
->wps_beacon_ie_len
= 0;
735 bss
->wps_beacon_ie
= malloc(len
);
736 if (bss
->wps_beacon_ie
== NULL
) {
737 bss
->wps_beacon_ie_len
= 0;
741 memcpy(bss
->wps_beacon_ie
, ie
, len
);
742 bss
->wps_beacon_ie_len
= len
;
747 static int test_driver_set_wps_probe_resp_ie(const char *ifname
, void *priv
,
748 const u8
*ie
, size_t len
)
750 struct test_driver_data
*drv
= priv
;
751 struct test_driver_bss
*bss
;
753 wpa_hexdump(MSG_DEBUG
, "test_driver: ProbeResp WPS IE", ie
, len
);
754 bss
= test_driver_get_bss(drv
, ifname
);
758 free(bss
->wps_probe_resp_ie
);
761 bss
->wps_probe_resp_ie
= NULL
;
762 bss
->wps_probe_resp_ie_len
= 0;
766 bss
->wps_probe_resp_ie
= malloc(len
);
767 if (bss
->wps_probe_resp_ie
== NULL
) {
768 bss
->wps_probe_resp_ie_len
= 0;
772 memcpy(bss
->wps_probe_resp_ie
, ie
, len
);
773 bss
->wps_probe_resp_ie_len
= len
;
778 static int test_driver_sta_deauth(void *priv
, const u8
*addr
, int reason
)
780 struct test_driver_data
*drv
= priv
;
781 struct test_client_socket
*cli
;
783 if (drv
->test_socket
< 0)
788 if (memcmp(cli
->addr
, addr
, ETH_ALEN
) == 0)
796 return sendto(drv
->test_socket
, "DEAUTH", 6, 0,
797 (struct sockaddr
*) &cli
->un
, cli
->unlen
);
801 static int test_driver_sta_disassoc(void *priv
, const u8
*addr
, int reason
)
803 struct test_driver_data
*drv
= priv
;
804 struct test_client_socket
*cli
;
806 if (drv
->test_socket
< 0)
811 if (memcmp(cli
->addr
, addr
, ETH_ALEN
) == 0)
819 return sendto(drv
->test_socket
, "DISASSOC", 8, 0,
820 (struct sockaddr
*) &cli
->un
, cli
->unlen
);
824 static struct hostapd_hw_modes
*
825 test_driver_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
827 struct hostapd_hw_modes
*modes
;
831 modes
= os_zalloc(*num_modes
* sizeof(struct hostapd_hw_modes
));
834 modes
[0].mode
= HOSTAPD_MODE_IEEE80211G
;
835 modes
[0].num_channels
= 1;
836 modes
[0].num_rates
= 1;
837 modes
[0].channels
= os_zalloc(sizeof(struct hostapd_channel_data
));
838 modes
[0].rates
= os_zalloc(sizeof(struct hostapd_rate_data
));
839 if (modes
[0].channels
== NULL
|| modes
[0].rates
== NULL
) {
840 hostapd_free_hw_features(modes
, *num_modes
);
843 modes
[0].channels
[0].chan
= 1;
844 modes
[0].channels
[0].freq
= 2412;
845 modes
[0].channels
[0].flag
= 0;
846 modes
[0].rates
[0].rate
= 10;
847 modes
[0].rates
[0].flags
= HOSTAPD_RATE_BASIC
| HOSTAPD_RATE_SUPPORTED
|
848 HOSTAPD_RATE_CCK
| HOSTAPD_RATE_MANDATORY
;
850 modes
[1].mode
= HOSTAPD_MODE_IEEE80211B
;
851 modes
[1].num_channels
= 1;
852 modes
[1].num_rates
= 1;
853 modes
[1].channels
= os_zalloc(sizeof(struct hostapd_channel_data
));
854 modes
[1].rates
= os_zalloc(sizeof(struct hostapd_rate_data
));
855 if (modes
[1].channels
== NULL
|| modes
[1].rates
== NULL
) {
856 hostapd_free_hw_features(modes
, *num_modes
);
859 modes
[1].channels
[0].chan
= 1;
860 modes
[1].channels
[0].freq
= 2412;
861 modes
[1].channels
[0].flag
= 0;
862 modes
[1].rates
[0].rate
= 10;
863 modes
[1].rates
[0].flags
= HOSTAPD_RATE_BASIC
| HOSTAPD_RATE_SUPPORTED
|
864 HOSTAPD_RATE_CCK
| HOSTAPD_RATE_MANDATORY
;
866 modes
[2].mode
= HOSTAPD_MODE_IEEE80211A
;
867 modes
[2].num_channels
= 1;
868 modes
[2].num_rates
= 1;
869 modes
[2].channels
= os_zalloc(sizeof(struct hostapd_channel_data
));
870 modes
[2].rates
= os_zalloc(sizeof(struct hostapd_rate_data
));
871 if (modes
[2].channels
== NULL
|| modes
[2].rates
== NULL
) {
872 hostapd_free_hw_features(modes
, *num_modes
);
875 modes
[2].channels
[0].chan
= 60;
876 modes
[2].channels
[0].freq
= 5300;
877 modes
[2].channels
[0].flag
= 0;
878 modes
[2].rates
[0].rate
= 60;
879 modes
[2].rates
[0].flags
= HOSTAPD_RATE_BASIC
| HOSTAPD_RATE_SUPPORTED
|
880 HOSTAPD_RATE_MANDATORY
;
886 static int test_driver_bss_add(void *priv
, const char *ifname
, const u8
*bssid
)
888 struct test_driver_data
*drv
= priv
;
889 struct test_driver_bss
*bss
;
891 wpa_printf(MSG_DEBUG
, "%s(ifname=%s bssid=" MACSTR
")",
892 __func__
, ifname
, MAC2STR(bssid
));
894 bss
= os_zalloc(sizeof(*bss
));
898 os_strlcpy(bss
->ifname
, ifname
, IFNAMSIZ
);
899 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
901 bss
->next
= drv
->bss
;
908 static int test_driver_bss_remove(void *priv
, const char *ifname
)
910 struct test_driver_data
*drv
= priv
;
911 struct test_driver_bss
*bss
, *prev
;
912 struct test_client_socket
*cli
, *prev_c
;
914 wpa_printf(MSG_DEBUG
, "%s(ifname=%s)", __func__
, ifname
);
916 for (prev
= NULL
, bss
= drv
->bss
; bss
; prev
= bss
, bss
= bss
->next
) {
917 if (strcmp(bss
->ifname
, ifname
) != 0)
921 prev
->next
= bss
->next
;
923 drv
->bss
= bss
->next
;
925 for (prev_c
= NULL
, cli
= drv
->cli
; cli
;
926 prev_c
= cli
, cli
= cli
->next
) {
930 prev_c
->next
= cli
->next
;
932 drv
->cli
= cli
->next
;
937 test_driver_free_bss(bss
);
945 static int test_driver_if_add(const char *iface
, void *priv
,
946 enum hostapd_driver_if_type type
, char *ifname
,
949 wpa_printf(MSG_DEBUG
, "%s(iface=%s type=%d ifname=%s)",
950 __func__
, iface
, type
, ifname
);
955 static int test_driver_if_update(void *priv
, enum hostapd_driver_if_type type
,
956 char *ifname
, const u8
*addr
)
958 wpa_printf(MSG_DEBUG
, "%s(type=%d ifname=%s)", __func__
, type
, ifname
);
963 static int test_driver_if_remove(void *priv
, enum hostapd_driver_if_type type
,
964 const char *ifname
, const u8
*addr
)
966 wpa_printf(MSG_DEBUG
, "%s(type=%d ifname=%s)", __func__
, type
, ifname
);
971 static int test_driver_valid_bss_mask(void *priv
, const u8
*addr
,
978 static int test_driver_set_ssid(const char *ifname
, void *priv
, const u8
*buf
,
981 struct test_driver_data
*drv
= priv
;
982 struct test_driver_bss
*bss
;
984 wpa_printf(MSG_DEBUG
, "%s(ifname=%s)", __func__
, ifname
);
985 wpa_hexdump_ascii(MSG_DEBUG
, "test_driver_set_ssid: SSID", buf
, len
);
987 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
988 if (strcmp(bss
->ifname
, ifname
) != 0)
991 if (len
< 0 || (size_t) len
> sizeof(bss
->ssid
))
994 memcpy(bss
->ssid
, buf
, len
);
1004 static int test_driver_set_privacy(const char *ifname
, void *priv
, int enabled
)
1006 struct test_driver_data
*drv
= priv
;
1007 struct test_driver_bss
*bss
;
1009 wpa_printf(MSG_DEBUG
, "%s(ifname=%s enabled=%d)",
1010 __func__
, ifname
, enabled
);
1012 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
1013 if (strcmp(bss
->ifname
, ifname
) != 0)
1016 bss
->privacy
= enabled
;
1025 static int test_driver_set_key(const char *iface
, void *priv
, wpa_alg alg
,
1026 const u8
*addr
, int key_idx
, int set_tx
,
1027 const u8
*seq
, size_t seq_len
,
1028 const u8
*key
, size_t key_len
)
1030 wpa_printf(MSG_DEBUG
, "%s(iface=%s alg=%d idx=%d set_tx=%d)",
1031 __func__
, iface
, alg
, key_idx
, set_tx
);
1033 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
1035 wpa_hexdump_key(MSG_DEBUG
, " key", key
, key_len
);
1040 static int test_driver_set_sta_vlan(void *priv
, const u8
*addr
,
1041 const char *ifname
, int vlan_id
)
1043 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" ifname=%s vlan_id=%d)",
1044 __func__
, MAC2STR(addr
), ifname
, vlan_id
);
1049 static int test_driver_sta_add(const char *ifname
, void *priv
,
1050 struct hostapd_sta_add_params
*params
)
1052 struct test_driver_data
*drv
= priv
;
1053 struct test_client_socket
*cli
;
1054 struct test_driver_bss
*bss
;
1056 wpa_printf(MSG_DEBUG
, "%s(ifname=%s addr=" MACSTR
" aid=%d "
1057 "capability=0x%x flags=0x%x listen_interval=%d)",
1058 __func__
, ifname
, MAC2STR(params
->addr
), params
->aid
,
1059 params
->capability
, params
->flags
,
1060 params
->listen_interval
);
1061 wpa_hexdump(MSG_DEBUG
, "test_driver_sta_add - supp_rates",
1062 params
->supp_rates
, params
->supp_rates_len
);
1066 if (os_memcmp(cli
->addr
, params
->addr
, ETH_ALEN
) == 0)
1071 wpa_printf(MSG_DEBUG
, "%s: no matching client entry",
1076 for (bss
= drv
->bss
; bss
; bss
= bss
->next
) {
1077 if (strcmp(ifname
, bss
->ifname
) == 0)
1081 wpa_printf(MSG_DEBUG
, "%s: No matching interface found from "
1082 "configured BSSes", __func__
);
1092 static void * test_driver_init(struct hostapd_data
*hapd
)
1094 struct test_driver_data
*drv
;
1095 struct sockaddr_un addr_un
;
1096 struct sockaddr_in addr_in
;
1097 struct sockaddr
*addr
;
1100 drv
= os_zalloc(sizeof(struct test_driver_data
));
1102 printf("Could not allocate memory for test driver data\n");
1105 drv
->bss
= os_zalloc(sizeof(*drv
->bss
));
1106 if (drv
->bss
== NULL
) {
1107 printf("Could not allocate memory for test driver BSS data\n");
1114 /* Generate a MAC address to help testing with multiple APs */
1115 hapd
->own_addr
[0] = 0x02; /* locally administered */
1116 sha1_prf((const u8
*) hapd
->conf
->iface
, strlen(hapd
->conf
->iface
),
1117 "hostapd test bssid generation",
1118 (const u8
*) hapd
->conf
->ssid
.ssid
, hapd
->conf
->ssid
.ssid_len
,
1119 hapd
->own_addr
+ 1, ETH_ALEN
- 1);
1121 os_strlcpy(drv
->bss
->ifname
, hapd
->conf
->iface
, IFNAMSIZ
);
1122 memcpy(drv
->bss
->bssid
, hapd
->own_addr
, ETH_ALEN
);
1124 if (hapd
->conf
->test_socket
) {
1125 if (strlen(hapd
->conf
->test_socket
) >=
1126 sizeof(addr_un
.sun_path
)) {
1127 printf("Too long test_socket path\n");
1128 test_driver_free_priv(drv
);
1131 if (strncmp(hapd
->conf
->test_socket
, "DIR:", 4) == 0) {
1132 size_t len
= strlen(hapd
->conf
->test_socket
) + 30;
1133 drv
->socket_dir
= strdup(hapd
->conf
->test_socket
+ 4);
1134 drv
->own_socket_path
= malloc(len
);
1135 if (drv
->own_socket_path
) {
1136 snprintf(drv
->own_socket_path
, len
,
1138 hapd
->conf
->test_socket
+ 4,
1139 MAC2STR(hapd
->own_addr
));
1141 } else if (strncmp(hapd
->conf
->test_socket
, "UDP:", 4) == 0) {
1142 drv
->udp_port
= atoi(hapd
->conf
->test_socket
+ 4);
1144 drv
->own_socket_path
= strdup(hapd
->conf
->test_socket
);
1146 if (drv
->own_socket_path
== NULL
&& drv
->udp_port
== 0) {
1147 test_driver_free_priv(drv
);
1151 drv
->test_socket
= socket(drv
->udp_port
? PF_INET
: PF_UNIX
,
1153 if (drv
->test_socket
< 0) {
1155 test_driver_free_priv(drv
);
1159 if (drv
->udp_port
) {
1160 os_memset(&addr_in
, 0, sizeof(addr_in
));
1161 addr_in
.sin_family
= AF_INET
;
1162 addr_in
.sin_port
= htons(drv
->udp_port
);
1163 addr
= (struct sockaddr
*) &addr_in
;
1164 alen
= sizeof(addr_in
);
1166 os_memset(&addr_un
, 0, sizeof(addr_un
));
1167 addr_un
.sun_family
= AF_UNIX
;
1168 os_strlcpy(addr_un
.sun_path
, drv
->own_socket_path
,
1169 sizeof(addr_un
.sun_path
));
1170 addr
= (struct sockaddr
*) &addr_un
;
1171 alen
= sizeof(addr_un
);
1173 if (bind(drv
->test_socket
, addr
, alen
) < 0) {
1174 perror("bind(PF_UNIX)");
1175 close(drv
->test_socket
);
1176 if (drv
->own_socket_path
)
1177 unlink(drv
->own_socket_path
);
1178 test_driver_free_priv(drv
);
1181 eloop_register_read_sock(drv
->test_socket
,
1182 test_driver_receive_unix
, drv
, NULL
);
1184 drv
->test_socket
= -1;
1190 static void test_driver_deinit(void *priv
)
1192 struct test_driver_data
*drv
= priv
;
1193 struct test_client_socket
*cli
, *prev
;
1202 if (drv
->test_socket
>= 0) {
1203 eloop_unregister_read_sock(drv
->test_socket
);
1204 close(drv
->test_socket
);
1205 if (drv
->own_socket_path
)
1206 unlink(drv
->own_socket_path
);
1209 /* There should be only one BSS remaining at this point. */
1210 if (drv
->bss
== NULL
)
1211 wpa_printf(MSG_ERROR
, "%s: drv->bss == NULL", __func__
);
1212 else if (drv
->bss
->next
)
1213 wpa_printf(MSG_ERROR
, "%s: drv->bss->next != NULL", __func__
);
1215 test_driver_free_priv(drv
);
1219 const struct wpa_driver_ops wpa_driver_test_ops
= {
1221 .hapd_init
= test_driver_init
,
1222 .hapd_deinit
= test_driver_deinit
,
1223 .hapd_send_eapol
= test_driver_send_eapol
,
1224 .send_mgmt_frame
= test_driver_send_mgmt_frame
,
1225 .set_generic_elem
= test_driver_set_generic_elem
,
1226 .sta_deauth
= test_driver_sta_deauth
,
1227 .sta_disassoc
= test_driver_sta_disassoc
,
1228 .get_hw_feature_data
= test_driver_get_hw_feature_data
,
1229 .bss_add
= test_driver_bss_add
,
1230 .bss_remove
= test_driver_bss_remove
,
1231 .if_add
= test_driver_if_add
,
1232 .if_update
= test_driver_if_update
,
1233 .if_remove
= test_driver_if_remove
,
1234 .valid_bss_mask
= test_driver_valid_bss_mask
,
1235 .hapd_set_ssid
= test_driver_set_ssid
,
1236 .set_privacy
= test_driver_set_privacy
,
1237 .hapd_set_key
= test_driver_set_key
,
1238 .set_sta_vlan
= test_driver_set_sta_vlan
,
1239 .sta_add
= test_driver_sta_add
,
1240 .send_ether
= test_driver_send_ether
,
1241 .set_wps_beacon_ie
= test_driver_set_wps_beacon_ie
,
1242 .set_wps_probe_resp_ie
= test_driver_set_wps_probe_resp_ie
,
1247 struct wpa_driver_test_global
{
1251 struct wpa_driver_test_data
{
1252 struct wpa_driver_test_global
*global
;
1254 u8 own_addr
[ETH_ALEN
];
1256 #ifdef DRIVER_TEST_UNIX
1257 struct sockaddr_un hostapd_addr
;
1258 #endif /* DRIVER_TEST_UNIX */
1259 int hostapd_addr_set
;
1260 struct sockaddr_in hostapd_addr_udp
;
1261 int hostapd_addr_udp_set
;
1262 char *own_socket_path
;
1267 #define MAX_SCAN_RESULTS 30
1268 struct wpa_scan_res
*scanres
[MAX_SCAN_RESULTS
];
1271 u8 assoc_wpa_ie
[80];
1272 size_t assoc_wpa_ie_len
;
1276 size_t probe_req_ie_len
;
1282 static void wpa_driver_test_poll(void *eloop_ctx
, void *timeout_ctx
)
1284 struct wpa_driver_test_data
*drv
= eloop_ctx
;
1286 #ifdef DRIVER_TEST_UNIX
1287 if (drv
->associated
&& drv
->hostapd_addr_set
) {
1289 if (stat(drv
->hostapd_addr
.sun_path
, &st
) < 0) {
1290 wpa_printf(MSG_DEBUG
, "%s: lost connection to AP: %s",
1291 __func__
, strerror(errno
));
1292 drv
->associated
= 0;
1293 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1296 #endif /* DRIVER_TEST_UNIX */
1298 eloop_register_timeout(1, 0, wpa_driver_test_poll
, drv
, NULL
);
1302 static int wpa_driver_test_set_wpa(void *priv
, int enabled
)
1304 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, enabled
);
1309 static void wpa_driver_test_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
1311 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
1312 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
1316 #ifdef DRIVER_TEST_UNIX
1317 static void wpa_driver_scan_dir(struct wpa_driver_test_data
*drv
,
1320 struct dirent
*dent
;
1322 struct sockaddr_un addr
;
1323 char cmd
[512], *pos
, *end
;
1326 dir
= opendir(path
);
1330 end
= cmd
+ sizeof(cmd
);
1332 ret
= os_snprintf(pos
, end
- pos
, "SCAN " MACSTR
,
1333 MAC2STR(drv
->own_addr
));
1334 if (ret
>= 0 && ret
< end
- pos
)
1336 if (drv
->probe_req_ie
) {
1337 ret
= os_snprintf(pos
, end
- pos
, " ");
1338 if (ret
>= 0 && ret
< end
- pos
)
1340 pos
+= wpa_snprintf_hex(pos
, end
- pos
, drv
->probe_req_ie
,
1341 drv
->probe_req_ie_len
);
1345 while ((dent
= readdir(dir
))) {
1346 if (os_strncmp(dent
->d_name
, "AP-", 3) != 0 &&
1347 os_strncmp(dent
->d_name
, "STA-", 4) != 0)
1349 if (drv
->own_socket_path
) {
1351 olen
= os_strlen(drv
->own_socket_path
);
1352 dlen
= os_strlen(dent
->d_name
);
1354 os_strcmp(dent
->d_name
,
1355 drv
->own_socket_path
+ olen
- dlen
) == 0)
1358 wpa_printf(MSG_DEBUG
, "%s: SCAN %s", __func__
, dent
->d_name
);
1360 os_memset(&addr
, 0, sizeof(addr
));
1361 addr
.sun_family
= AF_UNIX
;
1362 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s/%s",
1363 path
, dent
->d_name
);
1365 if (sendto(drv
->test_socket
, cmd
, os_strlen(cmd
), 0,
1366 (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
1367 perror("sendto(test_socket)");
1372 #endif /* DRIVER_TEST_UNIX */
1375 static int wpa_driver_test_scan(void *priv
,
1376 struct wpa_driver_scan_params
*params
)
1378 struct wpa_driver_test_data
*drv
= priv
;
1381 wpa_printf(MSG_DEBUG
, "%s: priv=%p", __func__
, priv
);
1382 for (i
= 0; i
< params
->num_ssids
; i
++)
1383 wpa_hexdump(MSG_DEBUG
, "Scan SSID",
1384 params
->ssids
[i
].ssid
, params
->ssids
[i
].ssid_len
);
1385 wpa_hexdump(MSG_DEBUG
, "Scan extra IE(s)",
1386 params
->extra_ies
, params
->extra_ies_len
);
1388 drv
->num_scanres
= 0;
1390 #ifdef DRIVER_TEST_UNIX
1391 if (drv
->test_socket
>= 0 && drv
->test_dir
)
1392 wpa_driver_scan_dir(drv
, drv
->test_dir
);
1394 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_set
&&
1395 sendto(drv
->test_socket
, "SCAN", 4, 0,
1396 (struct sockaddr
*) &drv
->hostapd_addr
,
1397 sizeof(drv
->hostapd_addr
)) < 0) {
1398 perror("sendto(test_socket)");
1400 #endif /* DRIVER_TEST_UNIX */
1402 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_udp_set
&&
1403 sendto(drv
->test_socket
, "SCAN", 4, 0,
1404 (struct sockaddr
*) &drv
->hostapd_addr_udp
,
1405 sizeof(drv
->hostapd_addr_udp
)) < 0) {
1406 perror("sendto(test_socket)");
1409 eloop_cancel_timeout(wpa_driver_test_scan_timeout
, drv
, drv
->ctx
);
1410 eloop_register_timeout(1, 0, wpa_driver_test_scan_timeout
, drv
,
1416 static struct wpa_scan_results
* wpa_driver_test_get_scan_results2(void *priv
)
1418 struct wpa_driver_test_data
*drv
= priv
;
1419 struct wpa_scan_results
*res
;
1422 res
= os_zalloc(sizeof(*res
));
1426 res
->res
= os_zalloc(drv
->num_scanres
* sizeof(struct wpa_scan_res
*));
1427 if (res
->res
== NULL
) {
1432 for (i
= 0; i
< drv
->num_scanres
; i
++) {
1433 struct wpa_scan_res
*r
;
1434 if (drv
->scanres
[i
] == NULL
)
1436 r
= os_malloc(sizeof(*r
) + drv
->scanres
[i
]->ie_len
);
1439 os_memcpy(r
, drv
->scanres
[i
],
1440 sizeof(*r
) + drv
->scanres
[i
]->ie_len
);
1441 res
->res
[res
->num
++] = r
;
1448 static int wpa_driver_test_set_key(void *priv
, wpa_alg alg
, const u8
*addr
,
1449 int key_idx
, int set_tx
,
1450 const u8
*seq
, size_t seq_len
,
1451 const u8
*key
, size_t key_len
)
1453 wpa_printf(MSG_DEBUG
, "%s: priv=%p alg=%d key_idx=%d set_tx=%d",
1454 __func__
, priv
, alg
, key_idx
, set_tx
);
1456 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
1459 wpa_hexdump(MSG_DEBUG
, " seq", seq
, seq_len
);
1462 wpa_hexdump(MSG_DEBUG
, " key", key
, key_len
);
1468 static int wpa_driver_test_associate(
1469 void *priv
, struct wpa_driver_associate_params
*params
)
1471 struct wpa_driver_test_data
*drv
= priv
;
1472 wpa_printf(MSG_DEBUG
, "%s: priv=%p freq=%d pairwise_suite=%d "
1473 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d",
1474 __func__
, priv
, params
->freq
, params
->pairwise_suite
,
1475 params
->group_suite
, params
->key_mgmt_suite
,
1476 params
->auth_alg
, params
->mode
);
1477 if (params
->bssid
) {
1478 wpa_printf(MSG_DEBUG
, " bssid=" MACSTR
,
1479 MAC2STR(params
->bssid
));
1482 wpa_hexdump_ascii(MSG_DEBUG
, " ssid",
1483 params
->ssid
, params
->ssid_len
);
1485 if (params
->wpa_ie
) {
1486 wpa_hexdump(MSG_DEBUG
, " wpa_ie",
1487 params
->wpa_ie
, params
->wpa_ie_len
);
1488 drv
->assoc_wpa_ie_len
= params
->wpa_ie_len
;
1489 if (drv
->assoc_wpa_ie_len
> sizeof(drv
->assoc_wpa_ie
))
1490 drv
->assoc_wpa_ie_len
= sizeof(drv
->assoc_wpa_ie
);
1491 os_memcpy(drv
->assoc_wpa_ie
, params
->wpa_ie
,
1492 drv
->assoc_wpa_ie_len
);
1494 drv
->assoc_wpa_ie_len
= 0;
1496 drv
->ibss
= params
->mode
== IEEE80211_MODE_IBSS
;
1497 drv
->privacy
= params
->key_mgmt_suite
&
1498 (WPA_KEY_MGMT_IEEE8021X
|
1500 WPA_KEY_MGMT_WPA_NONE
|
1501 WPA_KEY_MGMT_FT_IEEE8021X
|
1502 WPA_KEY_MGMT_FT_PSK
|
1503 WPA_KEY_MGMT_IEEE8021X_SHA256
|
1504 WPA_KEY_MGMT_PSK_SHA256
);
1505 if (params
->wep_key_len
[params
->wep_tx_keyidx
])
1508 #ifdef DRIVER_TEST_UNIX
1509 if (drv
->test_dir
&& params
->bssid
&&
1510 params
->mode
!= IEEE80211_MODE_IBSS
) {
1511 os_memset(&drv
->hostapd_addr
, 0, sizeof(drv
->hostapd_addr
));
1512 drv
->hostapd_addr
.sun_family
= AF_UNIX
;
1513 os_snprintf(drv
->hostapd_addr
.sun_path
,
1514 sizeof(drv
->hostapd_addr
.sun_path
),
1516 drv
->test_dir
, MAC2STR(params
->bssid
));
1517 drv
->hostapd_addr_set
= 1;
1519 #endif /* DRIVER_TEST_UNIX */
1521 if (drv
->test_socket
>= 0 &&
1522 (drv
->hostapd_addr_set
|| drv
->hostapd_addr_udp_set
)) {
1523 char cmd
[200], *pos
, *end
;
1525 end
= cmd
+ sizeof(cmd
);
1527 ret
= os_snprintf(pos
, end
- pos
, "ASSOC " MACSTR
" ",
1528 MAC2STR(drv
->own_addr
));
1529 if (ret
>= 0 && ret
< end
- pos
)
1531 pos
+= wpa_snprintf_hex(pos
, end
- pos
, params
->ssid
,
1533 ret
= os_snprintf(pos
, end
- pos
, " ");
1534 if (ret
>= 0 && ret
< end
- pos
)
1536 pos
+= wpa_snprintf_hex(pos
, end
- pos
, params
->wpa_ie
,
1537 params
->wpa_ie_len
);
1539 #ifdef DRIVER_TEST_UNIX
1540 if (drv
->hostapd_addr_set
&&
1541 sendto(drv
->test_socket
, cmd
, os_strlen(cmd
), 0,
1542 (struct sockaddr
*) &drv
->hostapd_addr
,
1543 sizeof(drv
->hostapd_addr
)) < 0) {
1544 perror("sendto(test_socket)");
1547 #endif /* DRIVER_TEST_UNIX */
1548 if (drv
->hostapd_addr_udp_set
&&
1549 sendto(drv
->test_socket
, cmd
, os_strlen(cmd
), 0,
1550 (struct sockaddr
*) &drv
->hostapd_addr_udp
,
1551 sizeof(drv
->hostapd_addr_udp
)) < 0) {
1552 perror("sendto(test_socket)");
1556 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
1557 drv
->ssid_len
= params
->ssid_len
;
1559 drv
->associated
= 1;
1560 if (params
->mode
== IEEE80211_MODE_IBSS
) {
1561 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
1562 drv
->ssid_len
= params
->ssid_len
;
1564 os_memcpy(drv
->bssid
, params
->bssid
, ETH_ALEN
);
1566 os_get_random(drv
->bssid
, ETH_ALEN
);
1567 drv
->bssid
[0] &= ~0x01;
1568 drv
->bssid
[0] |= 0x02;
1571 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1578 static int wpa_driver_test_get_bssid(void *priv
, u8
*bssid
)
1580 struct wpa_driver_test_data
*drv
= priv
;
1581 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
1586 static int wpa_driver_test_get_ssid(void *priv
, u8
*ssid
)
1588 struct wpa_driver_test_data
*drv
= priv
;
1589 os_memcpy(ssid
, drv
->ssid
, 32);
1590 return drv
->ssid_len
;
1594 static int wpa_driver_test_send_disassoc(struct wpa_driver_test_data
*drv
)
1596 #ifdef DRIVER_TEST_UNIX
1597 if (drv
->test_socket
>= 0 &&
1598 sendto(drv
->test_socket
, "DISASSOC", 8, 0,
1599 (struct sockaddr
*) &drv
->hostapd_addr
,
1600 sizeof(drv
->hostapd_addr
)) < 0) {
1601 perror("sendto(test_socket)");
1604 #endif /* DRIVER_TEST_UNIX */
1605 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_udp_set
&&
1606 sendto(drv
->test_socket
, "DISASSOC", 8, 0,
1607 (struct sockaddr
*) &drv
->hostapd_addr_udp
,
1608 sizeof(drv
->hostapd_addr_udp
)) < 0) {
1609 perror("sendto(test_socket)");
1616 static int wpa_driver_test_deauthenticate(void *priv
, const u8
*addr
,
1619 struct wpa_driver_test_data
*drv
= priv
;
1620 wpa_printf(MSG_DEBUG
, "%s addr=" MACSTR
" reason_code=%d",
1621 __func__
, MAC2STR(addr
), reason_code
);
1622 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1623 drv
->associated
= 0;
1624 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1625 return wpa_driver_test_send_disassoc(drv
);
1629 static int wpa_driver_test_disassociate(void *priv
, const u8
*addr
,
1632 struct wpa_driver_test_data
*drv
= priv
;
1633 wpa_printf(MSG_DEBUG
, "%s addr=" MACSTR
" reason_code=%d",
1634 __func__
, MAC2STR(addr
), reason_code
);
1635 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1636 drv
->associated
= 0;
1637 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1638 return wpa_driver_test_send_disassoc(drv
);
1642 static void wpa_driver_test_scanresp(struct wpa_driver_test_data
*drv
,
1643 struct sockaddr
*from
,
1647 struct wpa_scan_res
*res
;
1648 const char *pos
, *pos2
;
1650 u8
*ie_pos
, *ie_start
, *ie_end
;
1651 #define MAX_IE_LEN 1000
1653 wpa_printf(MSG_DEBUG
, "test_driver: SCANRESP %s", data
);
1654 if (drv
->num_scanres
>= MAX_SCAN_RESULTS
) {
1655 wpa_printf(MSG_DEBUG
, "test_driver: No room for the new scan "
1660 /* SCANRESP BSSID SSID IEs */
1662 res
= os_zalloc(sizeof(*res
) + MAX_IE_LEN
);
1665 ie_start
= ie_pos
= (u8
*) (res
+ 1);
1666 ie_end
= ie_pos
+ MAX_IE_LEN
;
1668 if (hwaddr_aton(data
, res
->bssid
)) {
1669 wpa_printf(MSG_DEBUG
, "test_driver: invalid BSSID in scanres");
1677 pos2
= os_strchr(pos
, ' ');
1679 wpa_printf(MSG_DEBUG
, "test_driver: invalid SSID termination "
1684 len
= (pos2
- pos
) / 2;
1688 * Generate SSID IE from the SSID field since this IE is not included
1689 * in the main IE field.
1691 *ie_pos
++ = WLAN_EID_SSID
;
1693 if (hexstr2bin(pos
, ie_pos
, len
) < 0) {
1694 wpa_printf(MSG_DEBUG
, "test_driver: invalid SSID in scanres");
1701 pos2
= os_strchr(pos
, ' ');
1703 len
= os_strlen(pos
) / 2;
1705 len
= (pos2
- pos
) / 2;
1706 if ((int) len
> ie_end
- ie_pos
)
1707 len
= ie_end
- ie_pos
;
1708 if (hexstr2bin(pos
, ie_pos
, len
) < 0) {
1709 wpa_printf(MSG_DEBUG
, "test_driver: invalid IEs in scanres");
1714 res
->ie_len
= ie_pos
- ie_start
;
1720 if (os_strstr(pos
, "PRIVACY"))
1721 res
->caps
|= IEEE80211_CAP_PRIVACY
;
1722 if (os_strstr(pos
, "IBSS"))
1723 res
->caps
|= IEEE80211_CAP_IBSS
;
1726 os_free(drv
->scanres
[drv
->num_scanres
]);
1727 drv
->scanres
[drv
->num_scanres
++] = res
;
1731 static void wpa_driver_test_assocresp(struct wpa_driver_test_data
*drv
,
1732 struct sockaddr
*from
,
1736 /* ASSOCRESP BSSID <res> */
1737 if (hwaddr_aton(data
, drv
->bssid
)) {
1738 wpa_printf(MSG_DEBUG
, "test_driver: invalid BSSID in "
1741 if (drv
->use_associnfo
) {
1742 union wpa_event_data event
;
1743 os_memset(&event
, 0, sizeof(event
));
1744 event
.assoc_info
.req_ies
= drv
->assoc_wpa_ie
;
1745 event
.assoc_info
.req_ies_len
= drv
->assoc_wpa_ie_len
;
1746 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOCINFO
, &event
);
1748 drv
->associated
= 1;
1749 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1753 static void wpa_driver_test_disassoc(struct wpa_driver_test_data
*drv
,
1754 struct sockaddr
*from
,
1757 drv
->associated
= 0;
1758 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1762 static void wpa_driver_test_eapol(struct wpa_driver_test_data
*drv
,
1763 struct sockaddr
*from
,
1765 const u8
*data
, size_t data_len
)
1767 const u8
*src
= drv
->bssid
;
1769 if (data_len
> 14) {
1770 /* Skip Ethernet header */
1771 src
= data
+ ETH_ALEN
;
1775 wpa_supplicant_rx_eapol(drv
->ctx
, src
, data
, data_len
);
1779 static void wpa_driver_test_mlme(struct wpa_driver_test_data
*drv
,
1780 struct sockaddr
*from
,
1782 const u8
*data
, size_t data_len
)
1784 #ifdef CONFIG_CLIENT_MLME
1785 struct ieee80211_rx_status rx_status
;
1786 os_memset(&rx_status
, 0, sizeof(rx_status
));
1787 wpa_supplicant_sta_rx(drv
->ctx
, data
, data_len
, &rx_status
);
1788 #endif /* CONFIG_CLIENT_MLME */
1792 static void wpa_driver_test_scan_cmd(struct wpa_driver_test_data
*drv
,
1793 struct sockaddr
*from
,
1795 const u8
*data
, size_t data_len
)
1797 char buf
[512], *pos
, *end
;
1800 /* data: optional [ STA-addr | ' ' | IEs(hex) ] */
1806 end
= buf
+ sizeof(buf
);
1808 /* reply: SCANRESP BSSID SSID IEs */
1809 ret
= snprintf(pos
, end
- pos
, "SCANRESP " MACSTR
" ",
1810 MAC2STR(drv
->bssid
));
1811 if (ret
< 0 || ret
>= end
- pos
)
1814 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
1815 drv
->ssid
, drv
->ssid_len
);
1816 ret
= snprintf(pos
, end
- pos
, " ");
1817 if (ret
< 0 || ret
>= end
- pos
)
1820 pos
+= wpa_snprintf_hex(pos
, end
- pos
, drv
->assoc_wpa_ie
,
1821 drv
->assoc_wpa_ie_len
);
1824 ret
= snprintf(pos
, end
- pos
, " PRIVACY");
1825 if (ret
< 0 || ret
>= end
- pos
)
1830 ret
= snprintf(pos
, end
- pos
, " IBSS");
1831 if (ret
< 0 || ret
>= end
- pos
)
1835 sendto(drv
->test_socket
, buf
, pos
- buf
, 0,
1836 (struct sockaddr
*) from
, fromlen
);
1840 static void wpa_driver_test_receive_unix(int sock
, void *eloop_ctx
,
1843 struct wpa_driver_test_data
*drv
= eloop_ctx
;
1846 struct sockaddr_storage from
;
1847 socklen_t fromlen
= sizeof(from
);
1848 const size_t buflen
= 2000;
1850 buf
= os_malloc(buflen
);
1853 res
= recvfrom(sock
, buf
, buflen
- 1, 0,
1854 (struct sockaddr
*) &from
, &fromlen
);
1856 perror("recvfrom(test_socket)");
1862 wpa_printf(MSG_DEBUG
, "test_driver: received %u bytes", res
);
1864 if (os_strncmp(buf
, "SCANRESP ", 9) == 0) {
1865 wpa_driver_test_scanresp(drv
, (struct sockaddr
*) &from
,
1867 } else if (os_strncmp(buf
, "ASSOCRESP ", 10) == 0) {
1868 wpa_driver_test_assocresp(drv
, (struct sockaddr
*) &from
,
1870 } else if (os_strcmp(buf
, "DISASSOC") == 0) {
1871 wpa_driver_test_disassoc(drv
, (struct sockaddr
*) &from
,
1873 } else if (os_strcmp(buf
, "DEAUTH") == 0) {
1874 wpa_driver_test_disassoc(drv
, (struct sockaddr
*) &from
,
1876 } else if (os_strncmp(buf
, "EAPOL ", 6) == 0) {
1877 wpa_driver_test_eapol(drv
, (struct sockaddr
*) &from
, fromlen
,
1878 (const u8
*) buf
+ 6, res
- 6);
1879 } else if (os_strncmp(buf
, "MLME ", 5) == 0) {
1880 wpa_driver_test_mlme(drv
, (struct sockaddr
*) &from
, fromlen
,
1881 (const u8
*) buf
+ 5, res
- 5);
1882 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
1883 wpa_driver_test_scan_cmd(drv
, (struct sockaddr
*) &from
,
1885 (const u8
*) buf
+ 5, res
- 5);
1887 wpa_hexdump_ascii(MSG_DEBUG
, "Unknown test_socket command",
1894 static void * wpa_driver_test_init2(void *ctx
, const char *ifname
,
1897 struct wpa_driver_test_data
*drv
;
1899 drv
= os_zalloc(sizeof(*drv
));
1902 drv
->global
= global_priv
;
1904 drv
->test_socket
= -1;
1906 /* Set dummy BSSID and SSID for testing. */
1907 drv
->bssid
[0] = 0x02;
1908 drv
->bssid
[1] = 0x00;
1909 drv
->bssid
[2] = 0x00;
1910 drv
->bssid
[3] = 0x00;
1911 drv
->bssid
[4] = 0x00;
1912 drv
->bssid
[5] = 0x01;
1913 os_memcpy(drv
->ssid
, "test", 5);
1916 /* Generate a MAC address to help testing with multiple STAs */
1917 drv
->own_addr
[0] = 0x02; /* locally administered */
1918 sha1_prf((const u8
*) ifname
, os_strlen(ifname
),
1919 "wpa_supplicant test mac addr generation",
1920 NULL
, 0, drv
->own_addr
+ 1, ETH_ALEN
- 1);
1921 eloop_register_timeout(1, 0, wpa_driver_test_poll
, drv
, NULL
);
1927 static void wpa_driver_test_close_test_socket(struct wpa_driver_test_data
*drv
)
1929 if (drv
->test_socket
>= 0) {
1930 eloop_unregister_read_sock(drv
->test_socket
);
1931 close(drv
->test_socket
);
1932 drv
->test_socket
= -1;
1935 if (drv
->own_socket_path
) {
1936 unlink(drv
->own_socket_path
);
1937 os_free(drv
->own_socket_path
);
1938 drv
->own_socket_path
= NULL
;
1943 static void wpa_driver_test_deinit(void *priv
)
1945 struct wpa_driver_test_data
*drv
= priv
;
1947 wpa_driver_test_close_test_socket(drv
);
1948 eloop_cancel_timeout(wpa_driver_test_scan_timeout
, drv
, drv
->ctx
);
1949 eloop_cancel_timeout(wpa_driver_test_poll
, drv
, NULL
);
1950 os_free(drv
->test_dir
);
1951 for (i
= 0; i
< MAX_SCAN_RESULTS
; i
++)
1952 os_free(drv
->scanres
[i
]);
1953 os_free(drv
->probe_req_ie
);
1958 static int wpa_driver_test_attach(struct wpa_driver_test_data
*drv
,
1961 #ifdef DRIVER_TEST_UNIX
1962 static unsigned int counter
= 0;
1963 struct sockaddr_un addr
;
1966 os_free(drv
->own_socket_path
);
1968 len
= os_strlen(dir
) + 30;
1969 drv
->own_socket_path
= os_malloc(len
);
1970 if (drv
->own_socket_path
== NULL
)
1972 os_snprintf(drv
->own_socket_path
, len
, "%s/STA-" MACSTR
,
1973 dir
, MAC2STR(drv
->own_addr
));
1975 drv
->own_socket_path
= os_malloc(100);
1976 if (drv
->own_socket_path
== NULL
)
1978 os_snprintf(drv
->own_socket_path
, 100,
1979 "/tmp/wpa_supplicant_test-%d-%d",
1980 getpid(), counter
++);
1983 drv
->test_socket
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
1984 if (drv
->test_socket
< 0) {
1985 perror("socket(PF_UNIX)");
1986 os_free(drv
->own_socket_path
);
1987 drv
->own_socket_path
= NULL
;
1991 os_memset(&addr
, 0, sizeof(addr
));
1992 addr
.sun_family
= AF_UNIX
;
1993 os_strlcpy(addr
.sun_path
, drv
->own_socket_path
, sizeof(addr
.sun_path
));
1994 if (bind(drv
->test_socket
, (struct sockaddr
*) &addr
,
1995 sizeof(addr
)) < 0) {
1996 perror("bind(PF_UNIX)");
1997 close(drv
->test_socket
);
1998 unlink(drv
->own_socket_path
);
1999 os_free(drv
->own_socket_path
);
2000 drv
->own_socket_path
= NULL
;
2004 eloop_register_read_sock(drv
->test_socket
,
2005 wpa_driver_test_receive_unix
, drv
, NULL
);
2008 #else /* DRIVER_TEST_UNIX */
2010 #endif /* DRIVER_TEST_UNIX */
2014 static int wpa_driver_test_attach_udp(struct wpa_driver_test_data
*drv
,
2019 pos
= os_strchr(dst
, ':');
2023 wpa_printf(MSG_DEBUG
, "%s: addr=%s port=%s", __func__
, dst
, pos
);
2025 drv
->test_socket
= socket(PF_INET
, SOCK_DGRAM
, 0);
2026 if (drv
->test_socket
< 0) {
2027 perror("socket(PF_INET)");
2031 os_memset(&drv
->hostapd_addr_udp
, 0, sizeof(drv
->hostapd_addr_udp
));
2032 drv
->hostapd_addr_udp
.sin_family
= AF_INET
;
2033 #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
2037 sscanf(dst
, "%d.%d.%d.%d", &a
[0], &a
[1], &a
[2], &a
[3]);
2038 pos
= (u8
*) &drv
->hostapd_addr_udp
.sin_addr
;
2044 #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
2045 inet_aton(dst
, &drv
->hostapd_addr_udp
.sin_addr
);
2046 #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
2047 drv
->hostapd_addr_udp
.sin_port
= htons(atoi(pos
));
2049 drv
->hostapd_addr_udp_set
= 1;
2051 eloop_register_read_sock(drv
->test_socket
,
2052 wpa_driver_test_receive_unix
, drv
, NULL
);
2058 static int wpa_driver_test_set_param(void *priv
, const char *param
)
2060 struct wpa_driver_test_data
*drv
= priv
;
2063 wpa_printf(MSG_DEBUG
, "%s: param='%s'", __func__
, param
);
2067 wpa_driver_test_close_test_socket(drv
);
2069 #ifdef DRIVER_TEST_UNIX
2070 pos
= os_strstr(param
, "test_socket=");
2076 pos2
= os_strchr(pos
, ' ');
2080 len
= os_strlen(pos
);
2081 if (len
> sizeof(drv
->hostapd_addr
.sun_path
))
2083 os_memset(&drv
->hostapd_addr
, 0, sizeof(drv
->hostapd_addr
));
2084 drv
->hostapd_addr
.sun_family
= AF_UNIX
;
2085 os_memcpy(drv
->hostapd_addr
.sun_path
, pos
, len
);
2086 drv
->hostapd_addr_set
= 1;
2088 #endif /* DRIVER_TEST_UNIX */
2090 pos
= os_strstr(param
, "test_dir=");
2093 os_free(drv
->test_dir
);
2094 drv
->test_dir
= os_strdup(pos
+ 9);
2095 if (drv
->test_dir
== NULL
)
2097 end
= os_strchr(drv
->test_dir
, ' ');
2100 if (wpa_driver_test_attach(drv
, drv
->test_dir
))
2103 pos
= os_strstr(param
, "test_udp=");
2106 dst
= os_strdup(pos
+ 9);
2109 epos
= os_strchr(dst
, ' ');
2112 if (wpa_driver_test_attach_udp(drv
, dst
))
2115 } else if (wpa_driver_test_attach(drv
, NULL
))
2119 if (os_strstr(param
, "use_associnfo=1")) {
2120 wpa_printf(MSG_DEBUG
, "test_driver: Use AssocInfo events");
2121 drv
->use_associnfo
= 1;
2124 #ifdef CONFIG_CLIENT_MLME
2125 if (os_strstr(param
, "use_mlme=1")) {
2126 wpa_printf(MSG_DEBUG
, "test_driver: Use internal MLME");
2129 #endif /* CONFIG_CLIENT_MLME */
2135 static const u8
* wpa_driver_test_get_mac_addr(void *priv
)
2137 struct wpa_driver_test_data
*drv
= priv
;
2138 wpa_printf(MSG_DEBUG
, "%s", __func__
);
2139 return drv
->own_addr
;
2143 static int wpa_driver_test_send_eapol(void *priv
, const u8
*dest
, u16 proto
,
2144 const u8
*data
, size_t data_len
)
2146 struct wpa_driver_test_data
*drv
= priv
;
2149 struct l2_ethhdr eth
;
2150 struct sockaddr
*addr
;
2152 #ifdef DRIVER_TEST_UNIX
2153 struct sockaddr_un addr_un
;
2154 #endif /* DRIVER_TEST_UNIX */
2156 wpa_hexdump(MSG_MSGDUMP
, "test_send_eapol TX frame", data
, data_len
);
2158 os_memset(ð
, 0, sizeof(eth
));
2159 os_memcpy(eth
.h_dest
, dest
, ETH_ALEN
);
2160 os_memcpy(eth
.h_source
, drv
->own_addr
, ETH_ALEN
);
2161 eth
.h_proto
= host_to_be16(proto
);
2163 msg_len
= 6 + sizeof(eth
) + data_len
;
2164 msg
= os_malloc(msg_len
);
2167 os_memcpy(msg
, "EAPOL ", 6);
2168 os_memcpy(msg
+ 6, ð
, sizeof(eth
));
2169 os_memcpy(msg
+ 6 + sizeof(eth
), data
, data_len
);
2171 if (os_memcmp(dest
, drv
->bssid
, ETH_ALEN
) == 0 ||
2172 drv
->test_dir
== NULL
) {
2173 if (drv
->hostapd_addr_udp_set
) {
2174 addr
= (struct sockaddr
*) &drv
->hostapd_addr_udp
;
2175 alen
= sizeof(drv
->hostapd_addr_udp
);
2177 #ifdef DRIVER_TEST_UNIX
2178 addr
= (struct sockaddr
*) &drv
->hostapd_addr
;
2179 alen
= sizeof(drv
->hostapd_addr
);
2180 #else /* DRIVER_TEST_UNIX */
2183 #endif /* DRIVER_TEST_UNIX */
2186 #ifdef DRIVER_TEST_UNIX
2188 os_memset(&addr_un
, 0, sizeof(addr_un
));
2189 addr_un
.sun_family
= AF_UNIX
;
2190 os_snprintf(addr_un
.sun_path
, sizeof(addr_un
.sun_path
),
2191 "%s/STA-" MACSTR
, drv
->test_dir
, MAC2STR(dest
));
2192 if (stat(addr_un
.sun_path
, &st
) < 0) {
2193 os_snprintf(addr_un
.sun_path
, sizeof(addr_un
.sun_path
),
2195 drv
->test_dir
, MAC2STR(dest
));
2197 addr
= (struct sockaddr
*) &addr_un
;
2198 alen
= sizeof(addr_un
);
2199 #else /* DRIVER_TEST_UNIX */
2202 #endif /* DRIVER_TEST_UNIX */
2205 if (sendto(drv
->test_socket
, msg
, msg_len
, 0, addr
, alen
) < 0) {
2206 perror("sendmsg(test_socket)");
2216 static int wpa_driver_test_get_capa(void *priv
, struct wpa_driver_capa
*capa
)
2218 struct wpa_driver_test_data
*drv
= priv
;
2219 os_memset(capa
, 0, sizeof(*capa
));
2220 capa
->key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2221 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2222 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2223 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
|
2224 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
|
2225 WPA_DRIVER_CAPA_KEY_MGMT_FT
|
2226 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
2227 capa
->enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2228 WPA_DRIVER_CAPA_ENC_WEP104
|
2229 WPA_DRIVER_CAPA_ENC_TKIP
|
2230 WPA_DRIVER_CAPA_ENC_CCMP
;
2231 capa
->auth
= WPA_DRIVER_AUTH_OPEN
|
2232 WPA_DRIVER_AUTH_SHARED
|
2233 WPA_DRIVER_AUTH_LEAP
;
2235 capa
->flags
|= WPA_DRIVER_FLAGS_USER_SPACE_MLME
;
2236 capa
->max_scan_ssids
= 2;
2242 static int wpa_driver_test_mlme_setprotection(void *priv
, const u8
*addr
,
2246 wpa_printf(MSG_DEBUG
, "%s: protect_type=%d key_type=%d",
2247 __func__
, protect_type
, key_type
);
2250 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
,
2251 __func__
, MAC2STR(addr
));
2258 #ifdef CONFIG_CLIENT_MLME
2259 static struct hostapd_hw_modes
*
2260 wpa_driver_test_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
2262 struct hostapd_hw_modes
*modes
;
2266 modes
= os_zalloc(*num_modes
* sizeof(struct hostapd_hw_modes
));
2269 modes
[0].mode
= HOSTAPD_MODE_IEEE80211G
;
2270 modes
[0].num_channels
= 1;
2271 modes
[0].num_rates
= 1;
2272 modes
[0].channels
= os_zalloc(sizeof(struct hostapd_channel_data
));
2273 modes
[0].rates
= os_zalloc(sizeof(struct hostapd_rate_data
));
2274 if (modes
[0].channels
== NULL
|| modes
[0].rates
== NULL
) {
2275 wpa_supplicant_sta_free_hw_features(modes
, *num_modes
);
2278 modes
[0].channels
[0].chan
= 1;
2279 modes
[0].channels
[0].freq
= 2412;
2280 modes
[0].channels
[0].flag
= 0;
2281 modes
[0].rates
[0].rate
= 10;
2282 modes
[0].rates
[0].flags
= HOSTAPD_RATE_BASIC
| HOSTAPD_RATE_SUPPORTED
|
2283 HOSTAPD_RATE_CCK
| HOSTAPD_RATE_MANDATORY
;
2289 static int wpa_driver_test_set_channel(void *priv
, hostapd_hw_mode phymode
,
2292 wpa_printf(MSG_DEBUG
, "%s: phymode=%d chan=%d freq=%d",
2293 __func__
, phymode
, chan
, freq
);
2298 static int wpa_driver_test_send_mlme(void *priv
, const u8
*data
,
2301 struct wpa_driver_test_data
*drv
= priv
;
2304 struct sockaddr_un addr
;
2306 struct dirent
*dent
;
2309 wpa_hexdump(MSG_MSGDUMP
, "test_send_mlme", data
, data_len
);
2314 io
[0].iov_base
= "MLME ";
2316 io
[1].iov_base
= (u8
*) data
;
2317 io
[1].iov_len
= data_len
;
2319 os_memset(&msg
, 0, sizeof(msg
));
2322 if (os_memcmp(dest
, drv
->bssid
, ETH_ALEN
) == 0 ||
2323 drv
->test_dir
== NULL
) {
2324 if (drv
->hostapd_addr_udp_set
) {
2325 msg
.msg_name
= &drv
->hostapd_addr_udp
;
2326 msg
.msg_namelen
= sizeof(drv
->hostapd_addr_udp
);
2328 #ifdef DRIVER_TEST_UNIX
2329 msg
.msg_name
= &drv
->hostapd_addr
;
2330 msg
.msg_namelen
= sizeof(drv
->hostapd_addr
);
2331 #endif /* DRIVER_TEST_UNIX */
2333 } else if (os_memcmp(dest
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0)
2335 dir
= opendir(drv
->test_dir
);
2338 while ((dent
= readdir(dir
))) {
2339 #ifdef _DIRENT_HAVE_D_TYPE
2340 /* Skip the file if it is not a socket.
2341 * Also accept DT_UNKNOWN (0) in case
2342 * the C library or underlying file
2343 * system does not support d_type. */
2344 if (dent
->d_type
!= DT_SOCK
&&
2345 dent
->d_type
!= DT_UNKNOWN
)
2347 #endif /* _DIRENT_HAVE_D_TYPE */
2348 if (os_strcmp(dent
->d_name
, ".") == 0 ||
2349 os_strcmp(dent
->d_name
, "..") == 0)
2351 wpa_printf(MSG_DEBUG
, "%s: Send broadcast MLME to %s",
2352 __func__
, dent
->d_name
);
2353 os_memset(&addr
, 0, sizeof(addr
));
2354 addr
.sun_family
= AF_UNIX
;
2355 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
2356 "%s/%s", drv
->test_dir
, dent
->d_name
);
2358 msg
.msg_name
= &addr
;
2359 msg
.msg_namelen
= sizeof(addr
);
2361 if (sendmsg(drv
->test_socket
, &msg
, 0) < 0)
2362 perror("sendmsg(test_socket)");
2368 os_memset(&addr
, 0, sizeof(addr
));
2369 addr
.sun_family
= AF_UNIX
;
2370 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
2371 "%s/AP-" MACSTR
, drv
->test_dir
, MAC2STR(dest
));
2372 if (stat(addr
.sun_path
, &st
) < 0) {
2373 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
2375 drv
->test_dir
, MAC2STR(dest
));
2377 msg
.msg_name
= &addr
;
2378 msg
.msg_namelen
= sizeof(addr
);
2381 if (sendmsg(drv
->test_socket
, &msg
, 0) < 0) {
2382 perror("sendmsg(test_socket)");
2390 static int wpa_driver_test_mlme_add_sta(void *priv
, const u8
*addr
,
2391 const u8
*supp_rates
,
2392 size_t supp_rates_len
)
2394 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
, __func__
, MAC2STR(addr
));
2399 static int wpa_driver_test_mlme_remove_sta(void *priv
, const u8
*addr
)
2401 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
, __func__
, MAC2STR(addr
));
2406 static int wpa_driver_test_set_ssid(void *priv
, const u8
*ssid
,
2409 wpa_printf(MSG_DEBUG
, "%s", __func__
);
2414 static int wpa_driver_test_set_bssid(void *priv
, const u8
*bssid
)
2416 wpa_printf(MSG_DEBUG
, "%s: bssid=" MACSTR
, __func__
, MAC2STR(bssid
));
2419 #endif /* CONFIG_CLIENT_MLME */
2422 static int wpa_driver_test_set_probe_req_ie(void *priv
, const u8
*ies
,
2425 struct wpa_driver_test_data
*drv
= priv
;
2427 os_free(drv
->probe_req_ie
);
2429 drv
->probe_req_ie
= os_malloc(ies_len
);
2430 if (drv
->probe_req_ie
== NULL
) {
2431 drv
->probe_req_ie_len
= 0;
2434 os_memcpy(drv
->probe_req_ie
, ies
, ies_len
);
2435 drv
->probe_req_ie_len
= ies_len
;
2437 drv
->probe_req_ie
= NULL
;
2438 drv
->probe_req_ie_len
= 0;
2444 static void * wpa_driver_test_global_init(void)
2446 struct wpa_driver_test_global
*global
;
2448 global
= os_zalloc(sizeof(*global
));
2453 static void wpa_driver_test_global_deinit(void *priv
)
2455 struct wpa_driver_test_global
*global
= priv
;
2460 static struct wpa_interface_info
*
2461 wpa_driver_test_get_interfaces(void *global_priv
)
2463 /* struct wpa_driver_test_global *global = priv; */
2464 struct wpa_interface_info
*iface
;
2466 iface
= os_zalloc(sizeof(*iface
));
2469 iface
->ifname
= os_strdup("sta0");
2470 iface
->desc
= os_strdup("test interface 0");
2471 iface
->drv_name
= "test";
2472 iface
->next
= os_zalloc(sizeof(*iface
));
2474 iface
->next
->ifname
= os_strdup("sta1");
2475 iface
->next
->desc
= os_strdup("test interface 1");
2476 iface
->next
->drv_name
= "test";
2483 const struct wpa_driver_ops wpa_driver_test_ops
= {
2485 "wpa_supplicant test driver",
2486 wpa_driver_test_get_bssid
,
2487 wpa_driver_test_get_ssid
,
2488 wpa_driver_test_set_wpa
,
2489 wpa_driver_test_set_key
,
2491 wpa_driver_test_deinit
,
2492 wpa_driver_test_set_param
,
2493 NULL
/* set_countermeasures */,
2494 NULL
/* set_drop_unencrypted */,
2496 NULL
/* get_scan_results */,
2497 wpa_driver_test_deauthenticate
,
2498 wpa_driver_test_disassociate
,
2499 wpa_driver_test_associate
,
2500 NULL
/* set_auth_alg */,
2501 NULL
/* add_pmkid */,
2502 NULL
/* remove_pmkid */,
2503 NULL
/* flush_pmkid */,
2504 wpa_driver_test_get_capa
,
2506 NULL
/* get_ifname */,
2507 wpa_driver_test_get_mac_addr
,
2508 wpa_driver_test_send_eapol
,
2509 NULL
/* set_operstate */,
2510 wpa_driver_test_mlme_setprotection
,
2511 #ifdef CONFIG_CLIENT_MLME
2512 wpa_driver_test_get_hw_feature_data
,
2513 wpa_driver_test_set_channel
,
2514 wpa_driver_test_set_ssid
,
2515 wpa_driver_test_set_bssid
,
2516 wpa_driver_test_send_mlme
,
2517 wpa_driver_test_mlme_add_sta
,
2518 wpa_driver_test_mlme_remove_sta
,
2519 #else /* CONFIG_CLIENT_MLME */
2520 NULL
/* get_hw_feature_data */,
2521 NULL
/* set_channel */,
2522 NULL
/* set_ssid */,
2523 NULL
/* set_bssid */,
2524 NULL
/* send_mlme */,
2525 NULL
/* mlme_add_sta */,
2526 NULL
/* mlme_remove_sta */,
2527 #endif /* CONFIG_CLIENT_MLME */
2528 NULL
/* update_ft_ies */,
2529 NULL
/* send_ft_action */,
2530 wpa_driver_test_get_scan_results2
,
2531 wpa_driver_test_set_probe_req_ie
,
2532 NULL
/* set_mode */,
2533 NULL
/* set_country */,
2534 wpa_driver_test_global_init
,
2535 wpa_driver_test_global_deinit
,
2536 wpa_driver_test_init2
,
2537 wpa_driver_test_get_interfaces
,
2538 wpa_driver_test_scan
,
2539 NULL
/* authenticate */,
2540 NULL
/* set_beacon */,
2541 NULL
/* set_beacon_int */,
2542 NULL
/* hapd_init */,
2543 NULL
/* init_bssid */,
2544 NULL
/* hapd_deinit */,
2545 NULL
/* set_ieee8021x */,
2546 NULL
/* set_privacy */,
2547 NULL
/* hapd_set_key */,
2548 NULL
/* get_seqnum */,
2549 NULL
/* get_seqnum_igtk */,
2551 NULL
/* set_generic_elem */,
2552 NULL
/* read_sta_data */,
2553 NULL
/* hapd_send_eapol */,
2554 NULL
/* sta_deauth */,
2555 NULL
/* sta_disassoc */,
2556 NULL
/* sta_remove */,
2557 NULL
/* hapd_get_ssid */,
2558 NULL
/* hapd_set_ssid */,
2559 NULL
/* hapd_set_countermeasures */,
2560 NULL
/* send_mgmt_frame */,
2562 NULL
/* get_inact_sec */,
2563 NULL
/* sta_clear_stats */,
2564 NULL
/* set_freq */,
2566 NULL
/* set_frag */,
2567 NULL
/* set_retry */,
2568 NULL
/* sta_set_flags */,
2569 NULL
/* set_rate_sets */,
2570 NULL
/* hapd_set_country */,
2571 NULL
/* set_ieee80211d */,
2572 NULL
/* hapd_set_beacon */,
2573 NULL
/* set_internal_bridge */,
2574 NULL
/* hapd_set_beacon_int */,
2575 NULL
/* set_broadcast_ssid */,
2576 NULL
/* set_cts_protect */,
2577 NULL
/* set_preamble */,
2578 NULL
/* set_short_slot_time */,
2579 NULL
/* set_tx_queue_params */,
2581 NULL
/* bss_remove */,
2582 NULL
/* valid_bss_mask */,
2583 NULL
/* passive_scan */,
2584 NULL
/* hapd_get_hw_feature_data */,
2586 NULL
/* if_update */,
2587 NULL
/* if_remove */,
2588 NULL
/* set_sta_vlan */,
2590 NULL
/* send_ether */,
2591 NULL
/* set_radius_acl_auth */,
2592 NULL
/* set_radius_acl_expire */,
2593 NULL
/* set_ht_params */,
2594 NULL
/* set_wps_beacon_ie */,
2595 NULL
/* set_wps_probe_resp_ie */,
2596 NULL
/* get_neighbor_bss */
2599 #endif /* HOSTAPD */