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;
82 struct wpa_driver_test_global {
86 struct wpa_driver_test_data {
87 struct wpa_driver_test_global *global;
89 u8 own_addr[ETH_ALEN];
91 #ifdef DRIVER_TEST_UNIX
92 struct sockaddr_un hostapd_addr;
93 #endif /* DRIVER_TEST_UNIX */
95 struct sockaddr_in hostapd_addr_udp;
96 int hostapd_addr_udp_set;
97 char *own_socket_path;
102 #define MAX_SCAN_RESULTS 30
103 struct wpa_scan_res *scanres[MAX_SCAN_RESULTS];
107 size_t assoc_wpa_ie_len;
111 size_t probe_req_ie_len;
121 static void test_driver_free_bss(struct test_driver_bss *bss)
124 free(bss->wps_beacon_ie);
125 free(bss->wps_probe_resp_ie);
130 static void test_driver_free_priv(struct test_driver_data *drv)
132 struct test_driver_bss *bss, *prev;
141 test_driver_free_bss(prev);
143 free(drv->own_socket_path);
144 free(drv->socket_dir);
149 static struct test_client_socket *
150 test_driver_get_cli(struct test_driver_data *drv, struct sockaddr_un *from,
153 struct test_client_socket *cli = drv->cli;
156 if (cli->unlen == fromlen &&
157 strncmp(cli->un.sun_path, from->sun_path,
158 fromlen - sizeof(cli->un.sun_family)) == 0)
167 static int test_driver_send_eapol(void *priv, const u8 *addr, const u8 *data,
168 size_t data_len, int encrypt,
171 struct test_driver_data *drv = priv;
172 struct test_client_socket *cli;
175 struct l2_ethhdr eth;
177 if (drv->test_socket < 0)
182 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
188 wpa_printf(MSG_DEBUG, "%s: no destination client entry",
193 memcpy(eth.h_dest, addr, ETH_ALEN);
194 memcpy(eth.h_source, own_addr, ETH_ALEN);
195 eth.h_proto = host_to_be16(ETH_P_EAPOL);
197 io[0].iov_base = "EAPOL ";
199 io[1].iov_base = ð
200 io[1].iov_len = sizeof(eth);
201 io[2].iov_base = (u8 *) data;
202 io[2].iov_len = data_len;
204 memset(&msg, 0, sizeof(msg));
207 msg.msg_name = &cli->un;
208 msg.msg_namelen = cli->unlen;
209 return sendmsg(drv->test_socket, &msg, 0);
213 static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
214 u16 proto, const u8 *data, size_t data_len)
216 struct test_driver_data *drv = priv;
219 struct l2_ethhdr eth;
221 struct sockaddr_un addr;
224 int ret = 0, broadcast = 0, count = 0;
226 if (drv->test_socket < 0 || drv->socket_dir == NULL) {
227 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d "
229 __func__, drv->test_socket, drv->socket_dir);
233 broadcast = memcmp(dst, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
234 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dst));
236 memcpy(eth.h_dest, dst, ETH_ALEN);
237 memcpy(eth.h_source, src, ETH_ALEN);
238 eth.h_proto = host_to_be16(proto);
240 io[0].iov_base = "ETHER ";
242 io[1].iov_base = ð
243 io[1].iov_len = sizeof(eth);
244 io[2].iov_base = (u8 *) data;
245 io[2].iov_len = data_len;
247 memset(&msg, 0, sizeof(msg));
251 dir = opendir(drv->socket_dir);
253 perror("test_driver: opendir");
256 while ((dent = readdir(dir))) {
257 #ifdef _DIRENT_HAVE_D_TYPE
258 /* Skip the file if it is not a socket. Also accept
259 * DT_UNKNOWN (0) in case the C library or underlying file
260 * system does not support d_type. */
261 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
263 #endif /* _DIRENT_HAVE_D_TYPE */
264 if (strcmp(dent->d_name, ".") == 0 ||
265 strcmp(dent->d_name, "..") == 0)
268 memset(&addr, 0, sizeof(addr));
269 addr.sun_family = AF_UNIX;
270 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
271 drv->socket_dir, dent->d_name);
273 if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
275 if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
278 wpa_printf(MSG_DEBUG, "%s: Send ether frame to %s",
279 __func__, dent->d_name);
281 msg.msg_name = &addr;
282 msg.msg_namelen = sizeof(addr);
283 ret = sendmsg(drv->test_socket, &msg, 0);
285 perror("driver_test: sendmsg");
290 if (!broadcast && count == 0) {
291 wpa_printf(MSG_DEBUG, "%s: Destination " MACSTR " not found",
292 __func__, MAC2STR(dst));
300 static int test_driver_send_mgmt_frame(void *priv, const void *buf,
301 size_t len, int flags)
303 struct test_driver_data *drv = priv;
307 int ret = 0, broadcast = 0;
309 struct sockaddr_un addr;
312 struct ieee80211_hdr *hdr;
315 if (drv->test_socket < 0 || len < 10 || drv->socket_dir == NULL) {
316 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d len=%lu"
318 __func__, drv->test_socket, (unsigned long) len,
325 broadcast = memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
326 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dest));
328 io[0].iov_base = "MLME ";
330 io[1].iov_base = (void *) buf;
333 memset(&msg, 0, sizeof(msg));
337 dir = opendir(drv->socket_dir);
339 perror("test_driver: opendir");
342 while ((dent = readdir(dir))) {
343 #ifdef _DIRENT_HAVE_D_TYPE
344 /* Skip the file if it is not a socket. Also accept
345 * DT_UNKNOWN (0) in case the C library or underlying file
346 * system does not support d_type. */
347 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
349 #endif /* _DIRENT_HAVE_D_TYPE */
350 if (strcmp(dent->d_name, ".") == 0 ||
351 strcmp(dent->d_name, "..") == 0)
354 memset(&addr, 0, sizeof(addr));
355 addr.sun_family = AF_UNIX;
356 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
357 drv->socket_dir, dent->d_name);
359 if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
361 if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
364 wpa_printf(MSG_DEBUG, "%s: Send management frame to %s",
365 __func__, dent->d_name);
367 msg.msg_name = &addr;
368 msg.msg_namelen = sizeof(addr);
369 ret = sendmsg(drv->test_socket, &msg, 0);
371 perror("driver_test: sendmsg");
375 hdr = (struct ieee80211_hdr *) buf;
376 fc = le_to_host16(hdr->frame_control);
377 hostapd_mgmt_tx_cb(drv->hapd, (u8 *) buf, len, WLAN_FC_GET_STYPE(fc),
384 static void test_driver_scan(struct test_driver_data *drv,
385 struct sockaddr_un *from, socklen_t fromlen,
388 char buf[512], *pos, *end;
390 struct test_driver_bss *bss;
395 /* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
397 wpa_printf(MSG_DEBUG, "test_driver: SCAN");
401 hwaddr_aton(data + 1, sa)) {
402 wpa_printf(MSG_DEBUG, "test_driver: Unexpected SCAN "
410 ielen = os_strlen(data) / 2;
411 if (ielen > sizeof(ie))
413 if (hexstr2bin(data, ie, ielen) < 0)
416 wpa_printf(MSG_DEBUG, "test_driver: Scan from " MACSTR,
418 wpa_hexdump(MSG_MSGDUMP, "test_driver: scan IEs", ie, ielen);
420 hostapd_wps_probe_req_rx(drv->hapd, sa, ie, ielen);
423 for (bss = drv->bss; bss; bss = bss->next) {
425 end = buf + sizeof(buf);
427 /* reply: SCANRESP BSSID SSID IEs */
428 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
429 MAC2STR(bss->bssid));
430 if (ret < 0 || ret >= end - pos)
433 pos += wpa_snprintf_hex(pos, end - pos,
434 bss->ssid, bss->ssid_len);
435 ret = snprintf(pos, end - pos, " ");
436 if (ret < 0 || ret >= end - pos)
439 pos += wpa_snprintf_hex(pos, end - pos, bss->ie, bss->ielen);
440 pos += wpa_snprintf_hex(pos, end - pos, bss->wps_probe_resp_ie,
441 bss->wps_probe_resp_ie_len);
444 ret = snprintf(pos, end - pos, " PRIVACY");
445 if (ret < 0 || ret >= end - pos)
450 sendto(drv->test_socket, buf, pos - buf, 0,
451 (struct sockaddr *) from, fromlen);
456 static struct hostapd_data * test_driver_get_hapd(struct test_driver_data *drv,
457 struct test_driver_bss *bss)
459 struct hostapd_iface *iface = drv->hapd->iface;
460 struct hostapd_data *hapd = NULL;
464 wpa_printf(MSG_DEBUG, "%s: bss == NULL", __func__);
468 for (i = 0; i < iface->num_bss; i++) {
469 hapd = iface->bss[i];
470 if (memcmp(hapd->own_addr, bss->bssid, ETH_ALEN) == 0)
473 if (i == iface->num_bss) {
474 wpa_printf(MSG_DEBUG, "%s: no matching interface entry found "
475 "for BSSID " MACSTR, __func__, MAC2STR(bss->bssid));
483 static int test_driver_new_sta(struct test_driver_data *drv,
484 struct test_driver_bss *bss, const u8 *addr,
485 const u8 *ie, size_t ielen)
487 struct hostapd_data *hapd;
489 hapd = test_driver_get_hapd(drv, bss);
493 return hostapd_notif_assoc(hapd, addr, ie, ielen);
497 static void test_driver_assoc(struct test_driver_data *drv,
498 struct sockaddr_un *from, socklen_t fromlen,
501 struct test_client_socket *cli;
502 u8 ie[256], ssid[32];
503 size_t ielen, ssid_len = 0;
504 char *pos, *pos2, cmd[50];
505 struct test_driver_bss *bss;
507 /* data: STA-addr SSID(hex) IEs(hex) */
509 cli = os_zalloc(sizeof(*cli));
513 if (hwaddr_aton(data, cli->addr)) {
514 printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
522 pos2 = strchr(pos, ' ');
525 ssid_len = (pos2 - pos) / 2;
526 if (hexstr2bin(pos, ssid, ssid_len) < 0) {
527 wpa_printf(MSG_DEBUG, "%s: Invalid SSID", __func__);
531 wpa_hexdump_ascii(MSG_DEBUG, "test_driver_assoc: SSID",
535 ielen = strlen(pos) / 2;
536 if (ielen > sizeof(ie))
538 if (hexstr2bin(pos, ie, ielen) < 0)
542 for (bss = drv->bss; bss; bss = bss->next) {
543 if (bss->ssid_len == ssid_len &&
544 memcmp(bss->ssid, ssid, ssid_len) == 0)
548 wpa_printf(MSG_DEBUG, "%s: No matching SSID found from "
549 "configured BSSes", __func__);
555 memcpy(&cli->un, from, sizeof(cli->un));
556 cli->unlen = fromlen;
557 cli->next = drv->cli;
559 wpa_hexdump_ascii(MSG_DEBUG, "test_socket: ASSOC sun_path",
560 (const u8 *) cli->un.sun_path,
561 cli->unlen - sizeof(cli->un.sun_family));
563 snprintf(cmd, sizeof(cmd), "ASSOCRESP " MACSTR " 0",
564 MAC2STR(bss->bssid));
565 sendto(drv->test_socket, cmd, strlen(cmd), 0,
566 (struct sockaddr *) from, fromlen);
568 if (test_driver_new_sta(drv, bss, cli->addr, ie, ielen) < 0) {
569 wpa_printf(MSG_DEBUG, "test_driver: failed to add new STA");
574 static void test_driver_disassoc(struct test_driver_data *drv,
575 struct sockaddr_un *from, socklen_t fromlen)
577 struct test_client_socket *cli;
579 cli = test_driver_get_cli(drv, from, fromlen);
583 hostapd_notif_disassoc(drv->hapd, cli->addr);
587 static void test_driver_eapol(struct test_driver_data *drv,
588 struct sockaddr_un *from, socklen_t fromlen,
589 u8 *data, size_t datalen)
591 struct test_client_socket *cli;
593 /* Skip Ethernet header */
594 wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
595 MACSTR " proto=%04x",
596 MAC2STR(data), MAC2STR(data + ETH_ALEN),
597 WPA_GET_BE16(data + 2 * ETH_ALEN));
601 cli = test_driver_get_cli(drv, from, fromlen);
603 struct hostapd_data *hapd;
604 hapd = test_driver_get_hapd(drv, cli->bss);
607 hostapd_eapol_receive(hapd, cli->addr, data, datalen);
609 wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
615 static void test_driver_ether(struct test_driver_data *drv,
616 struct sockaddr_un *from, socklen_t fromlen,
617 u8 *data, size_t datalen)
619 struct l2_ethhdr *eth;
621 if (datalen < sizeof(*eth))
624 eth = (struct l2_ethhdr *) data;
625 wpa_printf(MSG_DEBUG, "test_driver: RX ETHER dst=" MACSTR " src="
626 MACSTR " proto=%04x",
627 MAC2STR(eth->h_dest), MAC2STR(eth->h_source),
628 be_to_host16(eth->h_proto));
630 #ifdef CONFIG_IEEE80211R
631 if (be_to_host16(eth->h_proto) == ETH_P_RRB) {
632 wpa_ft_rrb_rx(drv->hapd->wpa_auth, eth->h_source,
633 data + sizeof(*eth), datalen - sizeof(*eth));
635 #endif /* CONFIG_IEEE80211R */
639 static void test_driver_mlme(struct test_driver_data *drv,
640 struct sockaddr_un *from, socklen_t fromlen,
641 u8 *data, size_t datalen)
643 struct ieee80211_hdr *hdr;
646 hdr = (struct ieee80211_hdr *) data;
648 if (test_driver_get_cli(drv, from, fromlen) == NULL && datalen >= 16) {
649 struct test_client_socket *cli;
650 cli = os_zalloc(sizeof(*cli));
653 wpa_printf(MSG_DEBUG, "Adding client entry for " MACSTR,
654 MAC2STR(hdr->addr2));
655 memcpy(cli->addr, hdr->addr2, ETH_ALEN);
656 memcpy(&cli->un, from, sizeof(cli->un));
657 cli->unlen = fromlen;
658 cli->next = drv->cli;
662 wpa_hexdump(MSG_MSGDUMP, "test_driver_mlme: received frame",
664 fc = le_to_host16(hdr->frame_control);
665 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT) {
666 wpa_printf(MSG_ERROR, "%s: received non-mgmt frame",
670 hostapd_mgmt_rx(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
674 static void test_driver_receive_unix(int sock, void *eloop_ctx, void *sock_ctx)
676 struct test_driver_data *drv = eloop_ctx;
679 struct sockaddr_un from;
680 socklen_t fromlen = sizeof(from);
682 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
683 (struct sockaddr *) &from, &fromlen);
685 perror("recvfrom(test_socket)");
690 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
692 if (strncmp(buf, "SCAN", 4) == 0) {
693 test_driver_scan(drv, &from, fromlen, buf + 4);
694 } else if (strncmp(buf, "ASSOC ", 6) == 0) {
695 test_driver_assoc(drv, &from, fromlen, buf + 6);
696 } else if (strcmp(buf, "DISASSOC") == 0) {
697 test_driver_disassoc(drv, &from, fromlen);
698 } else if (strncmp(buf, "EAPOL ", 6) == 0) {
699 test_driver_eapol(drv, &from, fromlen, (u8 *) buf + 6,
701 } else if (strncmp(buf, "ETHER ", 6) == 0) {
702 test_driver_ether(drv, &from, fromlen, (u8 *) buf + 6,
704 } else if (strncmp(buf, "MLME ", 5) == 0) {
705 test_driver_mlme(drv, &from, fromlen, (u8 *) buf + 5, res - 5);
707 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
713 static struct test_driver_bss *
714 test_driver_get_bss(struct test_driver_data *drv, const char *ifname)
716 struct test_driver_bss *bss;
718 for (bss = drv->bss; bss; bss = bss->next) {
719 if (strcmp(bss->ifname, ifname) == 0)
726 static int test_driver_set_generic_elem(const char *ifname, void *priv,
727 const u8 *elem, size_t elem_len)
729 struct test_driver_data *drv = priv;
730 struct test_driver_bss *bss;
732 bss = test_driver_get_bss(drv, ifname);
744 bss->ie = malloc(elem_len);
745 if (bss->ie == NULL) {
750 memcpy(bss->ie, elem, elem_len);
751 bss->ielen = elem_len;
756 static int test_driver_set_wps_beacon_ie(const char *ifname, void *priv,
757 const u8 *ie, size_t len)
759 struct test_driver_data *drv = priv;
760 struct test_driver_bss *bss;
762 wpa_hexdump(MSG_DEBUG, "test_driver: Beacon WPS IE", ie, len);
763 bss = test_driver_get_bss(drv, ifname);
767 free(bss->wps_beacon_ie);
770 bss->wps_beacon_ie = NULL;
771 bss->wps_beacon_ie_len = 0;
775 bss->wps_beacon_ie = malloc(len);
776 if (bss->wps_beacon_ie == NULL) {
777 bss->wps_beacon_ie_len = 0;
781 memcpy(bss->wps_beacon_ie, ie, len);
782 bss->wps_beacon_ie_len = len;
787 static int test_driver_set_wps_probe_resp_ie(const char *ifname, void *priv,
788 const u8 *ie, size_t len)
790 struct test_driver_data *drv = priv;
791 struct test_driver_bss *bss;
793 wpa_hexdump(MSG_DEBUG, "test_driver: ProbeResp WPS IE", ie, len);
794 bss = test_driver_get_bss(drv, ifname);
798 free(bss->wps_probe_resp_ie);
801 bss->wps_probe_resp_ie = NULL;
802 bss->wps_probe_resp_ie_len = 0;
806 bss->wps_probe_resp_ie = malloc(len);
807 if (bss->wps_probe_resp_ie == NULL) {
808 bss->wps_probe_resp_ie_len = 0;
812 memcpy(bss->wps_probe_resp_ie, ie, len);
813 bss->wps_probe_resp_ie_len = len;
818 static int test_driver_sta_deauth(void *priv, const u8 *addr, int reason)
820 struct test_driver_data *drv = priv;
821 struct test_client_socket *cli;
823 if (drv->test_socket < 0)
828 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
836 return sendto(drv->test_socket, "DEAUTH", 6, 0,
837 (struct sockaddr *) &cli->un, cli->unlen);
841 static int test_driver_sta_disassoc(void *priv, const u8 *addr, int reason)
843 struct test_driver_data *drv = priv;
844 struct test_client_socket *cli;
846 if (drv->test_socket < 0)
851 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
859 return sendto(drv->test_socket, "DISASSOC", 8, 0,
860 (struct sockaddr *) &cli->un, cli->unlen);
864 static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
866 struct test_driver_data *drv = priv;
867 struct test_driver_bss *bss;
869 wpa_printf(MSG_DEBUG, "%s(ifname=%s bssid=" MACSTR ")",
870 __func__, ifname, MAC2STR(bssid));
872 bss = os_zalloc(sizeof(*bss));
876 os_strlcpy(bss->ifname, ifname, IFNAMSIZ);
877 memcpy(bss->bssid, bssid, ETH_ALEN);
879 bss->next = drv->bss;
886 static int test_driver_bss_remove(void *priv, const char *ifname)
888 struct test_driver_data *drv = priv;
889 struct test_driver_bss *bss, *prev;
890 struct test_client_socket *cli, *prev_c;
892 wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
894 for (prev = NULL, bss = drv->bss; bss; prev = bss, bss = bss->next) {
895 if (strcmp(bss->ifname, ifname) != 0)
899 prev->next = bss->next;
901 drv->bss = bss->next;
903 for (prev_c = NULL, cli = drv->cli; cli;
904 prev_c = cli, cli = cli->next) {
908 prev_c->next = cli->next;
910 drv->cli = cli->next;
915 test_driver_free_bss(bss);
923 static int test_driver_if_add(const char *iface, void *priv,
924 enum hostapd_driver_if_type type, char *ifname,
927 wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s)",
928 __func__, iface, type, ifname);
933 static int test_driver_if_update(void *priv, enum hostapd_driver_if_type type,
934 char *ifname, const u8 *addr)
936 wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
941 static int test_driver_if_remove(void *priv, enum hostapd_driver_if_type type,
942 const char *ifname, const u8 *addr)
944 wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
949 static int test_driver_valid_bss_mask(void *priv, const u8 *addr,
956 static int test_driver_set_ssid(const char *ifname, void *priv, const u8 *buf,
959 struct test_driver_data *drv = priv;
960 struct test_driver_bss *bss;
962 wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
963 wpa_hexdump_ascii(MSG_DEBUG, "test_driver_set_ssid: SSID", buf, len);
965 for (bss = drv->bss; bss; bss = bss->next) {
966 if (strcmp(bss->ifname, ifname) != 0)
969 if (len < 0 || (size_t) len > sizeof(bss->ssid))
972 memcpy(bss->ssid, buf, len);
982 static int test_driver_set_privacy(const char *ifname, void *priv, int enabled)
984 struct test_driver_data *drv = priv;
985 struct test_driver_bss *bss;
987 wpa_printf(MSG_DEBUG, "%s(ifname=%s enabled=%d)",
988 __func__, ifname, enabled);
990 for (bss = drv->bss; bss; bss = bss->next) {
991 if (strcmp(bss->ifname, ifname) != 0)
994 bss->privacy = enabled;
1003 static int test_driver_set_key(const char *iface, void *priv, wpa_alg alg,
1004 const u8 *addr, int key_idx, int set_tx,
1005 const u8 *seq, size_t seq_len,
1006 const u8 *key, size_t key_len)
1008 wpa_printf(MSG_DEBUG, "%s(iface=%s alg=%d idx=%d set_tx=%d)",
1009 __func__, iface, alg, key_idx, set_tx);
1011 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
1013 wpa_hexdump_key(MSG_DEBUG, " key", key, key_len);
1018 static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
1019 const char *ifname, int vlan_id)
1021 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " ifname=%s vlan_id=%d)",
1022 __func__, MAC2STR(addr), ifname, vlan_id);
1027 static int test_driver_sta_add(const char *ifname, void *priv,
1028 struct hostapd_sta_add_params *params)
1030 struct test_driver_data *drv = priv;
1031 struct test_client_socket *cli;
1032 struct test_driver_bss *bss;
1034 wpa_printf(MSG_DEBUG, "%s(ifname=%s addr=" MACSTR " aid=%d "
1035 "capability=0x%x flags=0x%x listen_interval=%d)",
1036 __func__, ifname, MAC2STR(params->addr), params->aid,
1037 params->capability, params->flags,
1038 params->listen_interval);
1039 wpa_hexdump(MSG_DEBUG, "test_driver_sta_add - supp_rates",
1040 params->supp_rates, params->supp_rates_len);
1044 if (os_memcmp(cli->addr, params->addr, ETH_ALEN) == 0)
1049 wpa_printf(MSG_DEBUG, "%s: no matching client entry",
1054 for (bss = drv->bss; bss; bss = bss->next) {
1055 if (strcmp(ifname, bss->ifname) == 0)
1059 wpa_printf(MSG_DEBUG, "%s: No matching interface found from "
1060 "configured BSSes", __func__);
1070 static void * test_driver_init(struct hostapd_data *hapd)
1072 struct test_driver_data *drv;
1073 struct sockaddr_un addr_un;
1074 struct sockaddr_in addr_in;
1075 struct sockaddr *addr;
1078 drv = os_zalloc(sizeof(struct test_driver_data));
1080 printf("Could not allocate memory for test driver data\n");
1083 drv->bss = os_zalloc(sizeof(*drv->bss));
1084 if (drv->bss == NULL) {
1085 printf("Could not allocate memory for test driver BSS data\n");
1092 /* Generate a MAC address to help testing with multiple APs */
1093 hapd->own_addr[0] = 0x02; /* locally administered */
1094 sha1_prf((const u8 *) hapd->conf->iface, strlen(hapd->conf->iface),
1095 "hostapd test bssid generation",
1096 (const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len,
1097 hapd->own_addr + 1, ETH_ALEN - 1);
1099 os_strlcpy(drv->bss->ifname, hapd->conf->iface, IFNAMSIZ);
1100 memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
1102 if (hapd->conf->test_socket) {
1103 if (strlen(hapd->conf->test_socket) >=
1104 sizeof(addr_un.sun_path)) {
1105 printf("Too long test_socket path\n");
1106 test_driver_free_priv(drv);
1109 if (strncmp(hapd->conf->test_socket, "DIR:", 4) == 0) {
1110 size_t len = strlen(hapd->conf->test_socket) + 30;
1111 drv->socket_dir = strdup(hapd->conf->test_socket + 4);
1112 drv->own_socket_path = malloc(len);
1113 if (drv->own_socket_path) {
1114 snprintf(drv->own_socket_path, len,
1116 hapd->conf->test_socket + 4,
1117 MAC2STR(hapd->own_addr));
1119 } else if (strncmp(hapd->conf->test_socket, "UDP:", 4) == 0) {
1120 drv->udp_port = atoi(hapd->conf->test_socket + 4);
1122 drv->own_socket_path = strdup(hapd->conf->test_socket);
1124 if (drv->own_socket_path == NULL && drv->udp_port == 0) {
1125 test_driver_free_priv(drv);
1129 drv->test_socket = socket(drv->udp_port ? PF_INET : PF_UNIX,
1131 if (drv->test_socket < 0) {
1133 test_driver_free_priv(drv);
1137 if (drv->udp_port) {
1138 os_memset(&addr_in, 0, sizeof(addr_in));
1139 addr_in.sin_family = AF_INET;
1140 addr_in.sin_port = htons(drv->udp_port);
1141 addr = (struct sockaddr *) &addr_in;
1142 alen = sizeof(addr_in);
1144 os_memset(&addr_un, 0, sizeof(addr_un));
1145 addr_un.sun_family = AF_UNIX;
1146 os_strlcpy(addr_un.sun_path, drv->own_socket_path,
1147 sizeof(addr_un.sun_path));
1148 addr = (struct sockaddr *) &addr_un;
1149 alen = sizeof(addr_un);
1151 if (bind(drv->test_socket, addr, alen) < 0) {
1152 perror("bind(PF_UNIX)");
1153 close(drv->test_socket);
1154 if (drv->own_socket_path)
1155 unlink(drv->own_socket_path);
1156 test_driver_free_priv(drv);
1159 eloop_register_read_sock(drv->test_socket,
1160 test_driver_receive_unix, drv, NULL);
1162 drv->test_socket = -1;
1168 static void test_driver_deinit(void *priv)
1170 struct test_driver_data *drv = priv;
1171 struct test_client_socket *cli, *prev;
1180 if (drv->test_socket >= 0) {
1181 eloop_unregister_read_sock(drv->test_socket);
1182 close(drv->test_socket);
1183 if (drv->own_socket_path)
1184 unlink(drv->own_socket_path);
1187 /* There should be only one BSS remaining at this point. */
1188 if (drv->bss == NULL)
1189 wpa_printf(MSG_ERROR, "%s: drv->bss == NULL", __func__);
1190 else if (drv->bss->next)
1191 wpa_printf(MSG_ERROR, "%s: drv->bss->next != NULL", __func__);
1193 test_driver_free_priv(drv);
1198 static void wpa_driver_test_poll(void *eloop_ctx, void *timeout_ctx)
1200 struct wpa_driver_test_data *drv = eloop_ctx;
1202 #ifdef DRIVER_TEST_UNIX
1203 if (drv->associated && drv->hostapd_addr_set) {
1205 if (stat(drv->hostapd_addr.sun_path, &st) < 0) {
1206 wpa_printf(MSG_DEBUG, "%s: lost connection to AP: %s",
1207 __func__, strerror(errno));
1208 drv->associated = 0;
1209 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1212 #endif /* DRIVER_TEST_UNIX */
1214 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
1218 static int wpa_driver_test_set_wpa(void *priv, int enabled)
1220 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
1225 static void wpa_driver_test_scan_timeout(void *eloop_ctx, void *timeout_ctx)
1227 wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
1228 wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
1232 #ifdef DRIVER_TEST_UNIX
1233 static void wpa_driver_scan_dir(struct wpa_driver_test_data *drv,
1236 struct dirent *dent;
1238 struct sockaddr_un addr;
1239 char cmd[512], *pos, *end;
1242 dir = opendir(path);
1246 end = cmd + sizeof(cmd);
1248 ret = os_snprintf(pos, end - pos, "SCAN " MACSTR,
1249 MAC2STR(drv->own_addr));
1250 if (ret >= 0 && ret < end - pos)
1252 if (drv->probe_req_ie) {
1253 ret = os_snprintf(pos, end - pos, " ");
1254 if (ret >= 0 && ret < end - pos)
1256 pos += wpa_snprintf_hex(pos, end - pos, drv->probe_req_ie,
1257 drv->probe_req_ie_len);
1261 while ((dent = readdir(dir))) {
1262 if (os_strncmp(dent->d_name, "AP-", 3) != 0 &&
1263 os_strncmp(dent->d_name, "STA-", 4) != 0)
1265 if (drv->own_socket_path) {
1267 olen = os_strlen(drv->own_socket_path);
1268 dlen = os_strlen(dent->d_name);
1270 os_strcmp(dent->d_name,
1271 drv->own_socket_path + olen - dlen) == 0)
1274 wpa_printf(MSG_DEBUG, "%s: SCAN %s", __func__, dent->d_name);
1276 os_memset(&addr, 0, sizeof(addr));
1277 addr.sun_family = AF_UNIX;
1278 os_snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
1279 path, dent->d_name);
1281 if (sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1282 (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1283 perror("sendto(test_socket)");
1288 #endif /* DRIVER_TEST_UNIX */
1291 static int wpa_driver_test_scan(void *priv,
1292 struct wpa_driver_scan_params *params)
1294 struct wpa_driver_test_data *drv = priv;
1297 wpa_printf(MSG_DEBUG, "%s: priv=%p", __func__, priv);
1298 for (i = 0; i < params->num_ssids; i++)
1299 wpa_hexdump(MSG_DEBUG, "Scan SSID",
1300 params->ssids[i].ssid, params->ssids[i].ssid_len);
1301 wpa_hexdump(MSG_DEBUG, "Scan extra IE(s)",
1302 params->extra_ies, params->extra_ies_len);
1304 drv->num_scanres = 0;
1306 #ifdef DRIVER_TEST_UNIX
1307 if (drv->test_socket >= 0 && drv->test_dir)
1308 wpa_driver_scan_dir(drv, drv->test_dir);
1310 if (drv->test_socket >= 0 && drv->hostapd_addr_set &&
1311 sendto(drv->test_socket, "SCAN", 4, 0,
1312 (struct sockaddr *) &drv->hostapd_addr,
1313 sizeof(drv->hostapd_addr)) < 0) {
1314 perror("sendto(test_socket)");
1316 #endif /* DRIVER_TEST_UNIX */
1318 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1319 sendto(drv->test_socket, "SCAN", 4, 0,
1320 (struct sockaddr *) &drv->hostapd_addr_udp,
1321 sizeof(drv->hostapd_addr_udp)) < 0) {
1322 perror("sendto(test_socket)");
1325 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
1326 eloop_register_timeout(1, 0, wpa_driver_test_scan_timeout, drv,
1332 static struct wpa_scan_results * wpa_driver_test_get_scan_results2(void *priv)
1334 struct wpa_driver_test_data *drv = priv;
1335 struct wpa_scan_results *res;
1338 res = os_zalloc(sizeof(*res));
1342 res->res = os_zalloc(drv->num_scanres * sizeof(struct wpa_scan_res *));
1343 if (res->res == NULL) {
1348 for (i = 0; i < drv->num_scanres; i++) {
1349 struct wpa_scan_res *r;
1350 if (drv->scanres[i] == NULL)
1352 r = os_malloc(sizeof(*r) + drv->scanres[i]->ie_len);
1355 os_memcpy(r, drv->scanres[i],
1356 sizeof(*r) + drv->scanres[i]->ie_len);
1357 res->res[res->num++] = r;
1364 static int wpa_driver_test_set_key(void *priv, wpa_alg alg, const u8 *addr,
1365 int key_idx, int set_tx,
1366 const u8 *seq, size_t seq_len,
1367 const u8 *key, size_t key_len)
1369 wpa_printf(MSG_DEBUG, "%s: priv=%p alg=%d key_idx=%d set_tx=%d",
1370 __func__, priv, alg, key_idx, set_tx);
1372 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
1375 wpa_hexdump(MSG_DEBUG, " seq", seq, seq_len);
1378 wpa_hexdump(MSG_DEBUG, " key", key, key_len);
1384 static int wpa_driver_test_associate(
1385 void *priv, struct wpa_driver_associate_params *params)
1387 struct wpa_driver_test_data *drv = priv;
1388 wpa_printf(MSG_DEBUG, "%s: priv=%p freq=%d pairwise_suite=%d "
1389 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d",
1390 __func__, priv, params->freq, params->pairwise_suite,
1391 params->group_suite, params->key_mgmt_suite,
1392 params->auth_alg, params->mode);
1393 if (params->bssid) {
1394 wpa_printf(MSG_DEBUG, " bssid=" MACSTR,
1395 MAC2STR(params->bssid));
1398 wpa_hexdump_ascii(MSG_DEBUG, " ssid",
1399 params->ssid, params->ssid_len);
1401 if (params->wpa_ie) {
1402 wpa_hexdump(MSG_DEBUG, " wpa_ie",
1403 params->wpa_ie, params->wpa_ie_len);
1404 drv->assoc_wpa_ie_len = params->wpa_ie_len;
1405 if (drv->assoc_wpa_ie_len > sizeof(drv->assoc_wpa_ie))
1406 drv->assoc_wpa_ie_len = sizeof(drv->assoc_wpa_ie);
1407 os_memcpy(drv->assoc_wpa_ie, params->wpa_ie,
1408 drv->assoc_wpa_ie_len);
1410 drv->assoc_wpa_ie_len = 0;
1412 drv->ibss = params->mode == IEEE80211_MODE_IBSS;
1413 drv->privacy = params->key_mgmt_suite &
1414 (WPA_KEY_MGMT_IEEE8021X |
1416 WPA_KEY_MGMT_WPA_NONE |
1417 WPA_KEY_MGMT_FT_IEEE8021X |
1418 WPA_KEY_MGMT_FT_PSK |
1419 WPA_KEY_MGMT_IEEE8021X_SHA256 |
1420 WPA_KEY_MGMT_PSK_SHA256);
1421 if (params->wep_key_len[params->wep_tx_keyidx])
1424 #ifdef DRIVER_TEST_UNIX
1425 if (drv->test_dir && params->bssid &&
1426 params->mode != IEEE80211_MODE_IBSS) {
1427 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
1428 drv->hostapd_addr.sun_family = AF_UNIX;
1429 os_snprintf(drv->hostapd_addr.sun_path,
1430 sizeof(drv->hostapd_addr.sun_path),
1432 drv->test_dir, MAC2STR(params->bssid));
1433 drv->hostapd_addr_set = 1;
1435 #endif /* DRIVER_TEST_UNIX */
1437 if (drv->test_socket >= 0 &&
1438 (drv->hostapd_addr_set || drv->hostapd_addr_udp_set)) {
1439 char cmd[200], *pos, *end;
1441 end = cmd + sizeof(cmd);
1443 ret = os_snprintf(pos, end - pos, "ASSOC " MACSTR " ",
1444 MAC2STR(drv->own_addr));
1445 if (ret >= 0 && ret < end - pos)
1447 pos += wpa_snprintf_hex(pos, end - pos, params->ssid,
1449 ret = os_snprintf(pos, end - pos, " ");
1450 if (ret >= 0 && ret < end - pos)
1452 pos += wpa_snprintf_hex(pos, end - pos, params->wpa_ie,
1453 params->wpa_ie_len);
1455 #ifdef DRIVER_TEST_UNIX
1456 if (drv->hostapd_addr_set &&
1457 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1458 (struct sockaddr *) &drv->hostapd_addr,
1459 sizeof(drv->hostapd_addr)) < 0) {
1460 perror("sendto(test_socket)");
1463 #endif /* DRIVER_TEST_UNIX */
1464 if (drv->hostapd_addr_udp_set &&
1465 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1466 (struct sockaddr *) &drv->hostapd_addr_udp,
1467 sizeof(drv->hostapd_addr_udp)) < 0) {
1468 perror("sendto(test_socket)");
1472 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1473 drv->ssid_len = params->ssid_len;
1475 drv->associated = 1;
1476 if (params->mode == IEEE80211_MODE_IBSS) {
1477 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1478 drv->ssid_len = params->ssid_len;
1480 os_memcpy(drv->bssid, params->bssid, ETH_ALEN);
1482 os_get_random(drv->bssid, ETH_ALEN);
1483 drv->bssid[0] &= ~0x01;
1484 drv->bssid[0] |= 0x02;
1487 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1494 static int wpa_driver_test_get_bssid(void *priv, u8 *bssid)
1496 struct wpa_driver_test_data *drv = priv;
1497 os_memcpy(bssid, drv->bssid, ETH_ALEN);
1502 static int wpa_driver_test_get_ssid(void *priv, u8 *ssid)
1504 struct wpa_driver_test_data *drv = priv;
1505 os_memcpy(ssid, drv->ssid, 32);
1506 return drv->ssid_len;
1510 static int wpa_driver_test_send_disassoc(struct wpa_driver_test_data *drv)
1512 #ifdef DRIVER_TEST_UNIX
1513 if (drv->test_socket >= 0 &&
1514 sendto(drv->test_socket, "DISASSOC", 8, 0,
1515 (struct sockaddr *) &drv->hostapd_addr,
1516 sizeof(drv->hostapd_addr)) < 0) {
1517 perror("sendto(test_socket)");
1520 #endif /* DRIVER_TEST_UNIX */
1521 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1522 sendto(drv->test_socket, "DISASSOC", 8, 0,
1523 (struct sockaddr *) &drv->hostapd_addr_udp,
1524 sizeof(drv->hostapd_addr_udp)) < 0) {
1525 perror("sendto(test_socket)");
1532 static int wpa_driver_test_deauthenticate(void *priv, const u8 *addr,
1535 struct wpa_driver_test_data *drv = priv;
1536 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1537 __func__, MAC2STR(addr), reason_code);
1538 os_memset(drv->bssid, 0, ETH_ALEN);
1539 drv->associated = 0;
1540 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1541 return wpa_driver_test_send_disassoc(drv);
1545 static int wpa_driver_test_disassociate(void *priv, const u8 *addr,
1548 struct wpa_driver_test_data *drv = priv;
1549 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1550 __func__, MAC2STR(addr), reason_code);
1551 os_memset(drv->bssid, 0, ETH_ALEN);
1552 drv->associated = 0;
1553 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1554 return wpa_driver_test_send_disassoc(drv);
1558 static void wpa_driver_test_scanresp(struct wpa_driver_test_data *drv,
1559 struct sockaddr *from,
1563 struct wpa_scan_res *res;
1564 const char *pos, *pos2;
1566 u8 *ie_pos, *ie_start, *ie_end;
1567 #define MAX_IE_LEN 1000
1569 wpa_printf(MSG_DEBUG, "test_driver: SCANRESP %s", data);
1570 if (drv->num_scanres >= MAX_SCAN_RESULTS) {
1571 wpa_printf(MSG_DEBUG, "test_driver: No room for the new scan "
1576 /* SCANRESP BSSID SSID IEs */
1578 res = os_zalloc(sizeof(*res) + MAX_IE_LEN);
1581 ie_start = ie_pos = (u8 *) (res + 1);
1582 ie_end = ie_pos + MAX_IE_LEN;
1584 if (hwaddr_aton(data, res->bssid)) {
1585 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in scanres");
1593 pos2 = os_strchr(pos, ' ');
1595 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID termination "
1600 len = (pos2 - pos) / 2;
1604 * Generate SSID IE from the SSID field since this IE is not included
1605 * in the main IE field.
1607 *ie_pos++ = WLAN_EID_SSID;
1609 if (hexstr2bin(pos, ie_pos, len) < 0) {
1610 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID in scanres");
1617 pos2 = os_strchr(pos, ' ');
1619 len = os_strlen(pos) / 2;
1621 len = (pos2 - pos) / 2;
1622 if ((int) len > ie_end - ie_pos)
1623 len = ie_end - ie_pos;
1624 if (hexstr2bin(pos, ie_pos, len) < 0) {
1625 wpa_printf(MSG_DEBUG, "test_driver: invalid IEs in scanres");
1630 res->ie_len = ie_pos - ie_start;
1636 if (os_strstr(pos, "PRIVACY"))
1637 res->caps |= IEEE80211_CAP_PRIVACY;
1638 if (os_strstr(pos, "IBSS"))
1639 res->caps |= IEEE80211_CAP_IBSS;
1642 os_free(drv->scanres[drv->num_scanres]);
1643 drv->scanres[drv->num_scanres++] = res;
1647 static void wpa_driver_test_assocresp(struct wpa_driver_test_data *drv,
1648 struct sockaddr *from,
1652 /* ASSOCRESP BSSID <res> */
1653 if (hwaddr_aton(data, drv->bssid)) {
1654 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in "
1657 if (drv->use_associnfo) {
1658 union wpa_event_data event;
1659 os_memset(&event, 0, sizeof(event));
1660 event.assoc_info.req_ies = drv->assoc_wpa_ie;
1661 event.assoc_info.req_ies_len = drv->assoc_wpa_ie_len;
1662 wpa_supplicant_event(drv->ctx, EVENT_ASSOCINFO, &event);
1664 drv->associated = 1;
1665 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1669 static void wpa_driver_test_disassoc(struct wpa_driver_test_data *drv,
1670 struct sockaddr *from,
1673 drv->associated = 0;
1674 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1678 static void wpa_driver_test_eapol(struct wpa_driver_test_data *drv,
1679 struct sockaddr *from,
1681 const u8 *data, size_t data_len)
1683 const u8 *src = drv->bssid;
1685 if (data_len > 14) {
1686 /* Skip Ethernet header */
1687 src = data + ETH_ALEN;
1691 wpa_supplicant_rx_eapol(drv->ctx, src, data, data_len);
1695 static void wpa_driver_test_mlme(struct wpa_driver_test_data *drv,
1696 struct sockaddr *from,
1698 const u8 *data, size_t data_len)
1700 #ifdef CONFIG_CLIENT_MLME
1701 struct ieee80211_rx_status rx_status;
1702 os_memset(&rx_status, 0, sizeof(rx_status));
1703 wpa_supplicant_sta_rx(drv->ctx, data, data_len, &rx_status);
1704 #endif /* CONFIG_CLIENT_MLME */
1708 static void wpa_driver_test_scan_cmd(struct wpa_driver_test_data *drv,
1709 struct sockaddr *from,
1711 const u8 *data, size_t data_len)
1713 char buf[512], *pos, *end;
1716 /* data: optional [ STA-addr | ' ' | IEs(hex) ] */
1722 end = buf + sizeof(buf);
1724 /* reply: SCANRESP BSSID SSID IEs */
1725 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
1726 MAC2STR(drv->bssid));
1727 if (ret < 0 || ret >= end - pos)
1730 pos += wpa_snprintf_hex(pos, end - pos,
1731 drv->ssid, drv->ssid_len);
1732 ret = snprintf(pos, end - pos, " ");
1733 if (ret < 0 || ret >= end - pos)
1736 pos += wpa_snprintf_hex(pos, end - pos, drv->assoc_wpa_ie,
1737 drv->assoc_wpa_ie_len);
1740 ret = snprintf(pos, end - pos, " PRIVACY");
1741 if (ret < 0 || ret >= end - pos)
1746 ret = snprintf(pos, end - pos, " IBSS");
1747 if (ret < 0 || ret >= end - pos)
1751 sendto(drv->test_socket, buf, pos - buf, 0,
1752 (struct sockaddr *) from, fromlen);
1756 static void wpa_driver_test_receive_unix(int sock, void *eloop_ctx,
1759 struct wpa_driver_test_data *drv = eloop_ctx;
1762 struct sockaddr_storage from;
1763 socklen_t fromlen = sizeof(from);
1764 const size_t buflen = 2000;
1766 buf = os_malloc(buflen);
1769 res = recvfrom(sock, buf, buflen - 1, 0,
1770 (struct sockaddr *) &from, &fromlen);
1772 perror("recvfrom(test_socket)");
1778 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
1780 if (os_strncmp(buf, "SCANRESP ", 9) == 0) {
1781 wpa_driver_test_scanresp(drv, (struct sockaddr *) &from,
1783 } else if (os_strncmp(buf, "ASSOCRESP ", 10) == 0) {
1784 wpa_driver_test_assocresp(drv, (struct sockaddr *) &from,
1786 } else if (os_strcmp(buf, "DISASSOC") == 0) {
1787 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1789 } else if (os_strcmp(buf, "DEAUTH") == 0) {
1790 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1792 } else if (os_strncmp(buf, "EAPOL ", 6) == 0) {
1793 wpa_driver_test_eapol(drv, (struct sockaddr *) &from, fromlen,
1794 (const u8 *) buf + 6, res - 6);
1795 } else if (os_strncmp(buf, "MLME ", 5) == 0) {
1796 wpa_driver_test_mlme(drv, (struct sockaddr *) &from, fromlen,
1797 (const u8 *) buf + 5, res - 5);
1798 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
1799 wpa_driver_test_scan_cmd(drv, (struct sockaddr *) &from,
1801 (const u8 *) buf + 5, res - 5);
1803 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
1810 static void * wpa_driver_test_init2(void *ctx, const char *ifname,
1813 struct wpa_driver_test_data *drv;
1815 drv = os_zalloc(sizeof(*drv));
1818 drv->global = global_priv;
1820 drv->test_socket = -1;
1822 /* Set dummy BSSID and SSID for testing. */
1823 drv->bssid[0] = 0x02;
1824 drv->bssid[1] = 0x00;
1825 drv->bssid[2] = 0x00;
1826 drv->bssid[3] = 0x00;
1827 drv->bssid[4] = 0x00;
1828 drv->bssid[5] = 0x01;
1829 os_memcpy(drv->ssid, "test", 5);
1832 /* Generate a MAC address to help testing with multiple STAs */
1833 drv->own_addr[0] = 0x02; /* locally administered */
1834 sha1_prf((const u8 *) ifname, os_strlen(ifname),
1835 "wpa_supplicant test mac addr generation",
1836 NULL, 0, drv->own_addr + 1, ETH_ALEN - 1);
1837 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
1843 static void wpa_driver_test_close_test_socket(struct wpa_driver_test_data *drv)
1845 if (drv->test_socket >= 0) {
1846 eloop_unregister_read_sock(drv->test_socket);
1847 close(drv->test_socket);
1848 drv->test_socket = -1;
1851 if (drv->own_socket_path) {
1852 unlink(drv->own_socket_path);
1853 os_free(drv->own_socket_path);
1854 drv->own_socket_path = NULL;
1859 static void wpa_driver_test_deinit(void *priv)
1861 struct wpa_driver_test_data *drv = priv;
1863 wpa_driver_test_close_test_socket(drv);
1864 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
1865 eloop_cancel_timeout(wpa_driver_test_poll, drv, NULL);
1866 os_free(drv->test_dir);
1867 for (i = 0; i < MAX_SCAN_RESULTS; i++)
1868 os_free(drv->scanres[i]);
1869 os_free(drv->probe_req_ie);
1874 static int wpa_driver_test_attach(struct wpa_driver_test_data *drv,
1877 #ifdef DRIVER_TEST_UNIX
1878 static unsigned int counter = 0;
1879 struct sockaddr_un addr;
1882 os_free(drv->own_socket_path);
1884 len = os_strlen(dir) + 30;
1885 drv->own_socket_path = os_malloc(len);
1886 if (drv->own_socket_path == NULL)
1888 os_snprintf(drv->own_socket_path, len, "%s/STA-" MACSTR,
1889 dir, MAC2STR(drv->own_addr));
1891 drv->own_socket_path = os_malloc(100);
1892 if (drv->own_socket_path == NULL)
1894 os_snprintf(drv->own_socket_path, 100,
1895 "/tmp/wpa_supplicant_test-%d-%d",
1896 getpid(), counter++);
1899 drv->test_socket = socket(PF_UNIX, SOCK_DGRAM, 0);
1900 if (drv->test_socket < 0) {
1901 perror("socket(PF_UNIX)");
1902 os_free(drv->own_socket_path);
1903 drv->own_socket_path = NULL;
1907 os_memset(&addr, 0, sizeof(addr));
1908 addr.sun_family = AF_UNIX;
1909 os_strlcpy(addr.sun_path, drv->own_socket_path, sizeof(addr.sun_path));
1910 if (bind(drv->test_socket, (struct sockaddr *) &addr,
1911 sizeof(addr)) < 0) {
1912 perror("bind(PF_UNIX)");
1913 close(drv->test_socket);
1914 unlink(drv->own_socket_path);
1915 os_free(drv->own_socket_path);
1916 drv->own_socket_path = NULL;
1920 eloop_register_read_sock(drv->test_socket,
1921 wpa_driver_test_receive_unix, drv, NULL);
1924 #else /* DRIVER_TEST_UNIX */
1926 #endif /* DRIVER_TEST_UNIX */
1930 static int wpa_driver_test_attach_udp(struct wpa_driver_test_data *drv,
1935 pos = os_strchr(dst, ':');
1939 wpa_printf(MSG_DEBUG, "%s: addr=%s port=%s", __func__, dst, pos);
1941 drv->test_socket = socket(PF_INET, SOCK_DGRAM, 0);
1942 if (drv->test_socket < 0) {
1943 perror("socket(PF_INET)");
1947 os_memset(&drv->hostapd_addr_udp, 0, sizeof(drv->hostapd_addr_udp));
1948 drv->hostapd_addr_udp.sin_family = AF_INET;
1949 #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
1953 sscanf(dst, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
1954 pos = (u8 *) &drv->hostapd_addr_udp.sin_addr;
1960 #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1961 inet_aton(dst, &drv->hostapd_addr_udp.sin_addr);
1962 #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1963 drv->hostapd_addr_udp.sin_port = htons(atoi(pos));
1965 drv->hostapd_addr_udp_set = 1;
1967 eloop_register_read_sock(drv->test_socket,
1968 wpa_driver_test_receive_unix, drv, NULL);
1974 static int wpa_driver_test_set_param(void *priv, const char *param)
1976 struct wpa_driver_test_data *drv = priv;
1979 wpa_printf(MSG_DEBUG, "%s: param='%s'", __func__, param);
1983 wpa_driver_test_close_test_socket(drv);
1985 #ifdef DRIVER_TEST_UNIX
1986 pos = os_strstr(param, "test_socket=");
1992 pos2 = os_strchr(pos, ' ');
1996 len = os_strlen(pos);
1997 if (len > sizeof(drv->hostapd_addr.sun_path))
1999 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
2000 drv->hostapd_addr.sun_family = AF_UNIX;
2001 os_memcpy(drv->hostapd_addr.sun_path, pos, len);
2002 drv->hostapd_addr_set = 1;
2004 #endif /* DRIVER_TEST_UNIX */
2006 pos = os_strstr(param, "test_dir=");
2009 os_free(drv->test_dir);
2010 drv->test_dir = os_strdup(pos + 9);
2011 if (drv->test_dir == NULL)
2013 end = os_strchr(drv->test_dir, ' ');
2016 if (wpa_driver_test_attach(drv, drv->test_dir))
2019 pos = os_strstr(param, "test_udp=");
2022 dst = os_strdup(pos + 9);
2025 epos = os_strchr(dst, ' ');
2028 if (wpa_driver_test_attach_udp(drv, dst))
2031 } else if (wpa_driver_test_attach(drv, NULL))
2035 if (os_strstr(param, "use_associnfo=1")) {
2036 wpa_printf(MSG_DEBUG, "test_driver: Use AssocInfo events");
2037 drv->use_associnfo = 1;
2040 #ifdef CONFIG_CLIENT_MLME
2041 if (os_strstr(param, "use_mlme=1")) {
2042 wpa_printf(MSG_DEBUG, "test_driver: Use internal MLME");
2045 #endif /* CONFIG_CLIENT_MLME */
2051 static const u8 * wpa_driver_test_get_mac_addr(void *priv)
2053 struct wpa_driver_test_data *drv = priv;
2054 wpa_printf(MSG_DEBUG, "%s", __func__);
2055 return drv->own_addr;
2059 static int wpa_driver_test_send_eapol(void *priv, const u8 *dest, u16 proto,
2060 const u8 *data, size_t data_len)
2062 struct wpa_driver_test_data *drv = priv;
2065 struct l2_ethhdr eth;
2066 struct sockaddr *addr;
2068 #ifdef DRIVER_TEST_UNIX
2069 struct sockaddr_un addr_un;
2070 #endif /* DRIVER_TEST_UNIX */
2072 wpa_hexdump(MSG_MSGDUMP, "test_send_eapol TX frame", data, data_len);
2074 os_memset(ð, 0, sizeof(eth));
2075 os_memcpy(eth.h_dest, dest, ETH_ALEN);
2076 os_memcpy(eth.h_source, drv->own_addr, ETH_ALEN);
2077 eth.h_proto = host_to_be16(proto);
2079 msg_len = 6 + sizeof(eth) + data_len;
2080 msg = os_malloc(msg_len);
2083 os_memcpy(msg, "EAPOL ", 6);
2084 os_memcpy(msg + 6, ð, sizeof(eth));
2085 os_memcpy(msg + 6 + sizeof(eth), data, data_len);
2087 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
2088 drv->test_dir == NULL) {
2089 if (drv->hostapd_addr_udp_set) {
2090 addr = (struct sockaddr *) &drv->hostapd_addr_udp;
2091 alen = sizeof(drv->hostapd_addr_udp);
2093 #ifdef DRIVER_TEST_UNIX
2094 addr = (struct sockaddr *) &drv->hostapd_addr;
2095 alen = sizeof(drv->hostapd_addr);
2096 #else /* DRIVER_TEST_UNIX */
2099 #endif /* DRIVER_TEST_UNIX */
2102 #ifdef DRIVER_TEST_UNIX
2104 os_memset(&addr_un, 0, sizeof(addr_un));
2105 addr_un.sun_family = AF_UNIX;
2106 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2107 "%s/STA-" MACSTR, drv->test_dir, MAC2STR(dest));
2108 if (stat(addr_un.sun_path, &st) < 0) {
2109 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2111 drv->test_dir, MAC2STR(dest));
2113 addr = (struct sockaddr *) &addr_un;
2114 alen = sizeof(addr_un);
2115 #else /* DRIVER_TEST_UNIX */
2118 #endif /* DRIVER_TEST_UNIX */
2121 if (sendto(drv->test_socket, msg, msg_len, 0, addr, alen) < 0) {
2122 perror("sendmsg(test_socket)");
2132 static int wpa_driver_test_get_capa(void *priv, struct wpa_driver_capa *capa)
2134 struct wpa_driver_test_data *drv = priv;
2135 os_memset(capa, 0, sizeof(*capa));
2136 capa->key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2137 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2138 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2139 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
2140 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE |
2141 WPA_DRIVER_CAPA_KEY_MGMT_FT |
2142 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2143 capa->enc = WPA_DRIVER_CAPA_ENC_WEP40 |
2144 WPA_DRIVER_CAPA_ENC_WEP104 |
2145 WPA_DRIVER_CAPA_ENC_TKIP |
2146 WPA_DRIVER_CAPA_ENC_CCMP;
2147 capa->auth = WPA_DRIVER_AUTH_OPEN |
2148 WPA_DRIVER_AUTH_SHARED |
2149 WPA_DRIVER_AUTH_LEAP;
2151 capa->flags |= WPA_DRIVER_FLAGS_USER_SPACE_MLME;
2152 capa->max_scan_ssids = 2;
2158 static int wpa_driver_test_mlme_setprotection(void *priv, const u8 *addr,
2162 wpa_printf(MSG_DEBUG, "%s: protect_type=%d key_type=%d",
2163 __func__, protect_type, key_type);
2166 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR,
2167 __func__, MAC2STR(addr));
2174 #ifdef CONFIG_CLIENT_MLME
2175 static int wpa_driver_test_set_channel(void *priv, hostapd_hw_mode phymode,
2178 wpa_printf(MSG_DEBUG, "%s: phymode=%d chan=%d freq=%d",
2179 __func__, phymode, chan, freq);
2184 static int wpa_driver_test_send_mlme(void *priv, const u8 *data,
2187 struct wpa_driver_test_data *drv = priv;
2190 struct sockaddr_un addr;
2192 struct dirent *dent;
2195 wpa_hexdump(MSG_MSGDUMP, "test_send_mlme", data, data_len);
2200 io[0].iov_base = "MLME ";
2202 io[1].iov_base = (u8 *) data;
2203 io[1].iov_len = data_len;
2205 os_memset(&msg, 0, sizeof(msg));
2208 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
2209 drv->test_dir == NULL) {
2210 if (drv->hostapd_addr_udp_set) {
2211 msg.msg_name = &drv->hostapd_addr_udp;
2212 msg.msg_namelen = sizeof(drv->hostapd_addr_udp);
2214 #ifdef DRIVER_TEST_UNIX
2215 msg.msg_name = &drv->hostapd_addr;
2216 msg.msg_namelen = sizeof(drv->hostapd_addr);
2217 #endif /* DRIVER_TEST_UNIX */
2219 } else if (os_memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0)
2221 dir = opendir(drv->test_dir);
2224 while ((dent = readdir(dir))) {
2225 #ifdef _DIRENT_HAVE_D_TYPE
2226 /* Skip the file if it is not a socket.
2227 * Also accept DT_UNKNOWN (0) in case
2228 * the C library or underlying file
2229 * system does not support d_type. */
2230 if (dent->d_type != DT_SOCK &&
2231 dent->d_type != DT_UNKNOWN)
2233 #endif /* _DIRENT_HAVE_D_TYPE */
2234 if (os_strcmp(dent->d_name, ".") == 0 ||
2235 os_strcmp(dent->d_name, "..") == 0)
2237 wpa_printf(MSG_DEBUG, "%s: Send broadcast MLME to %s",
2238 __func__, dent->d_name);
2239 os_memset(&addr, 0, sizeof(addr));
2240 addr.sun_family = AF_UNIX;
2241 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2242 "%s/%s", drv->test_dir, dent->d_name);
2244 msg.msg_name = &addr;
2245 msg.msg_namelen = sizeof(addr);
2247 if (sendmsg(drv->test_socket, &msg, 0) < 0)
2248 perror("sendmsg(test_socket)");
2254 os_memset(&addr, 0, sizeof(addr));
2255 addr.sun_family = AF_UNIX;
2256 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2257 "%s/AP-" MACSTR, drv->test_dir, MAC2STR(dest));
2258 if (stat(addr.sun_path, &st) < 0) {
2259 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2261 drv->test_dir, MAC2STR(dest));
2263 msg.msg_name = &addr;
2264 msg.msg_namelen = sizeof(addr);
2267 if (sendmsg(drv->test_socket, &msg, 0) < 0) {
2268 perror("sendmsg(test_socket)");
2276 static int wpa_driver_test_mlme_add_sta(void *priv, const u8 *addr,
2277 const u8 *supp_rates,
2278 size_t supp_rates_len)
2280 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2285 static int wpa_driver_test_mlme_remove_sta(void *priv, const u8 *addr)
2287 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2292 static int wpa_driver_test_set_ssid(void *priv, const u8 *ssid,
2295 wpa_printf(MSG_DEBUG, "%s", __func__);
2300 static int wpa_driver_test_set_bssid(void *priv, const u8 *bssid)
2302 wpa_printf(MSG_DEBUG, "%s: bssid=" MACSTR, __func__, MAC2STR(bssid));
2305 #endif /* CONFIG_CLIENT_MLME */
2308 static int wpa_driver_test_set_probe_req_ie(void *priv, const u8 *ies,
2311 struct wpa_driver_test_data *drv = priv;
2313 os_free(drv->probe_req_ie);
2315 drv->probe_req_ie = os_malloc(ies_len);
2316 if (drv->probe_req_ie == NULL) {
2317 drv->probe_req_ie_len = 0;
2320 os_memcpy(drv->probe_req_ie, ies, ies_len);
2321 drv->probe_req_ie_len = ies_len;
2323 drv->probe_req_ie = NULL;
2324 drv->probe_req_ie_len = 0;
2330 static void * wpa_driver_test_global_init(void)
2332 struct wpa_driver_test_global *global;
2334 global = os_zalloc(sizeof(*global));
2339 static void wpa_driver_test_global_deinit(void *priv)
2341 struct wpa_driver_test_global *global = priv;
2346 static struct wpa_interface_info *
2347 wpa_driver_test_get_interfaces(void *global_priv)
2349 /* struct wpa_driver_test_global *global = priv; */
2350 struct wpa_interface_info *iface;
2352 iface = os_zalloc(sizeof(*iface));
2355 iface->ifname = os_strdup("sta0");
2356 iface->desc = os_strdup("test interface 0");
2357 iface->drv_name = "test";
2358 iface->next = os_zalloc(sizeof(*iface));
2360 iface->next->ifname = os_strdup("sta1");
2361 iface->next->desc = os_strdup("test interface 1");
2362 iface->next->drv_name = "test";
2368 #endif /* HOSTAPD */
2371 #if defined(HOSTAPD) || defined(CONFIG_CLIENT_MLME)
2372 static struct hostapd_hw_modes *
2373 wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
2375 struct hostapd_hw_modes *modes;
2379 modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
2382 modes[0].mode = HOSTAPD_MODE_IEEE80211G;
2383 modes[0].num_channels = 1;
2384 modes[0].num_rates = 1;
2385 modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2386 modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2387 if (modes[0].channels == NULL || modes[0].rates == NULL)
2389 modes[0].channels[0].chan = 1;
2390 modes[0].channels[0].freq = 2412;
2391 modes[0].channels[0].flag = 0;
2392 modes[0].rates[0].rate = 10;
2393 modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2394 HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
2396 modes[1].mode = HOSTAPD_MODE_IEEE80211B;
2397 modes[1].num_channels = 1;
2398 modes[1].num_rates = 1;
2399 modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2400 modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2401 if (modes[1].channels == NULL || modes[1].rates == NULL)
2403 modes[1].channels[0].chan = 1;
2404 modes[1].channels[0].freq = 2412;
2405 modes[1].channels[0].flag = 0;
2406 modes[1].rates[0].rate = 10;
2407 modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2408 HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
2410 modes[2].mode = HOSTAPD_MODE_IEEE80211A;
2411 modes[2].num_channels = 1;
2412 modes[2].num_rates = 1;
2413 modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2414 modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2415 if (modes[2].channels == NULL || modes[2].rates == NULL)
2417 modes[2].channels[0].chan = 60;
2418 modes[2].channels[0].freq = 5300;
2419 modes[2].channels[0].flag = 0;
2420 modes[2].rates[0].rate = 60;
2421 modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2422 HOSTAPD_RATE_MANDATORY;
2429 for (i = 0; i < *num_modes; i++) {
2430 os_free(modes[i].channels);
2431 os_free(modes[i].rates);
2437 #endif /* HOSTAPD || CONFIG_CLIENT_MLME */
2440 const struct wpa_driver_ops wpa_driver_test_ops = {
2442 "wpa_supplicant test driver",
2444 .hapd_init = test_driver_init,
2445 .hapd_deinit = test_driver_deinit,
2446 .hapd_send_eapol = test_driver_send_eapol,
2447 .send_mgmt_frame = test_driver_send_mgmt_frame,
2448 .set_generic_elem = test_driver_set_generic_elem,
2449 .sta_deauth = test_driver_sta_deauth,
2450 .sta_disassoc = test_driver_sta_disassoc,
2451 .get_hw_feature_data = wpa_driver_test_get_hw_feature_data,
2452 .bss_add = test_driver_bss_add,
2453 .bss_remove = test_driver_bss_remove,
2454 .if_add = test_driver_if_add,
2455 .if_update = test_driver_if_update,
2456 .if_remove = test_driver_if_remove,
2457 .valid_bss_mask = test_driver_valid_bss_mask,
2458 .hapd_set_ssid = test_driver_set_ssid,
2459 .set_privacy = test_driver_set_privacy,
2460 .hapd_set_key = test_driver_set_key,
2461 .set_sta_vlan = test_driver_set_sta_vlan,
2462 .sta_add = test_driver_sta_add,
2463 .send_ether = test_driver_send_ether,
2464 .set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
2465 .set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
2467 wpa_driver_test_get_bssid,
2468 wpa_driver_test_get_ssid,
2469 wpa_driver_test_set_wpa,
2470 wpa_driver_test_set_key,
2472 wpa_driver_test_deinit,
2473 wpa_driver_test_set_param,
2474 NULL /* set_countermeasures */,
2475 NULL /* set_drop_unencrypted */,
2477 NULL /* get_scan_results */,
2478 wpa_driver_test_deauthenticate,
2479 wpa_driver_test_disassociate,
2480 wpa_driver_test_associate,
2481 NULL /* set_auth_alg */,
2482 NULL /* add_pmkid */,
2483 NULL /* remove_pmkid */,
2484 NULL /* flush_pmkid */,
2485 wpa_driver_test_get_capa,
2487 NULL /* get_ifname */,
2488 wpa_driver_test_get_mac_addr,
2489 wpa_driver_test_send_eapol,
2490 NULL /* set_operstate */,
2491 wpa_driver_test_mlme_setprotection,
2492 #ifdef CONFIG_CLIENT_MLME
2493 wpa_driver_test_get_hw_feature_data,
2494 wpa_driver_test_set_channel,
2495 wpa_driver_test_set_ssid,
2496 wpa_driver_test_set_bssid,
2497 wpa_driver_test_send_mlme,
2498 wpa_driver_test_mlme_add_sta,
2499 wpa_driver_test_mlme_remove_sta,
2500 #else /* CONFIG_CLIENT_MLME */
2501 NULL /* get_hw_feature_data */,
2502 NULL /* set_channel */,
2503 NULL /* set_ssid */,
2504 NULL /* set_bssid */,
2505 NULL /* send_mlme */,
2506 NULL /* mlme_add_sta */,
2507 NULL /* mlme_remove_sta */,
2508 #endif /* CONFIG_CLIENT_MLME */
2509 NULL /* update_ft_ies */,
2510 NULL /* send_ft_action */,
2511 wpa_driver_test_get_scan_results2,
2512 wpa_driver_test_set_probe_req_ie,
2513 NULL /* set_mode */,
2514 NULL /* set_country */,
2515 wpa_driver_test_global_init,
2516 wpa_driver_test_global_deinit,
2517 wpa_driver_test_init2,
2518 wpa_driver_test_get_interfaces,
2519 wpa_driver_test_scan,
2520 NULL /* authenticate */,
2521 NULL /* set_beacon */,
2522 NULL /* set_beacon_int */,
2523 NULL /* hapd_init */,
2524 NULL /* init_bssid */,
2525 NULL /* hapd_deinit */,
2526 NULL /* set_ieee8021x */,
2527 NULL /* set_privacy */,
2528 NULL /* hapd_set_key */,
2529 NULL /* get_seqnum */,
2530 NULL /* get_seqnum_igtk */,
2532 NULL /* set_generic_elem */,
2533 NULL /* read_sta_data */,
2534 NULL /* hapd_send_eapol */,
2535 NULL /* sta_deauth */,
2536 NULL /* sta_disassoc */,
2537 NULL /* sta_remove */,
2538 NULL /* hapd_get_ssid */,
2539 NULL /* hapd_set_ssid */,
2540 NULL /* hapd_set_countermeasures */,
2541 NULL /* send_mgmt_frame */,
2543 NULL /* get_inact_sec */,
2544 NULL /* sta_clear_stats */,
2545 NULL /* set_freq */,
2547 NULL /* set_frag */,
2548 NULL /* set_retry */,
2549 NULL /* sta_set_flags */,
2550 NULL /* set_rate_sets */,
2551 NULL /* hapd_set_country */,
2552 NULL /* set_ieee80211d */,
2553 NULL /* hapd_set_beacon */,
2554 NULL /* set_internal_bridge */,
2555 NULL /* hapd_set_beacon_int */,
2556 NULL /* set_broadcast_ssid */,
2557 NULL /* set_cts_protect */,
2558 NULL /* set_preamble */,
2559 NULL /* set_short_slot_time */,
2560 NULL /* set_tx_queue_params */,
2562 NULL /* bss_remove */,
2563 NULL /* valid_bss_mask */,
2564 NULL /* passive_scan */,
2566 NULL /* if_update */,
2567 NULL /* if_remove */,
2568 NULL /* set_sta_vlan */,
2570 NULL /* send_ether */,
2571 NULL /* set_radius_acl_auth */,
2572 NULL /* set_radius_acl_expire */,
2573 NULL /* set_ht_params */,
2574 NULL /* set_wps_beacon_ie */,
2575 NULL /* set_wps_probe_resp_ie */,
2576 NULL /* get_neighbor_bss */
2577 #endif /* HOSTAPD */