2 * WPA Supplicant - testing driver interface
3 * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 /* Make sure we get winsock2.h for Windows build to get sockaddr_storage */
16 #include "build_config.h"
17 #ifdef CONFIG_NATIVE_WINDOWS
19 #endif /* CONFIG_NATIVE_WINDOWS */
23 #ifndef CONFIG_NATIVE_WINDOWS
27 #define DRIVER_TEST_UNIX
28 #endif /* CONFIG_NATIVE_WINDOWS */
32 #include "l2_packet/l2_packet.h"
35 #include "ieee802_11_defs.h"
40 #include "../../hostapd/hostapd.h"
41 #include "../../hostapd/wpa.h"
42 #include "../../hostapd/hw_features.h"
43 #include "../../hostapd/wps_hostapd.h"
46 struct test_client_socket {
47 struct test_client_socket *next;
49 struct sockaddr_un un;
51 struct test_driver_bss *bss;
54 struct test_driver_bss {
55 struct test_driver_bss *next;
56 char ifname[IFNAMSIZ + 1];
61 size_t wps_beacon_ie_len;
62 u8 *wps_probe_resp_ie;
63 size_t wps_probe_resp_ie_len;
69 struct test_driver_data {
70 struct hostapd_data *hapd;
71 struct test_client_socket *cli;
73 struct test_driver_bss *bss;
75 char *own_socket_path;
81 struct wpa_driver_test_global {
85 struct wpa_driver_test_data {
86 struct wpa_driver_test_global *global;
88 u8 own_addr[ETH_ALEN];
90 #ifdef DRIVER_TEST_UNIX
91 struct sockaddr_un hostapd_addr;
92 #endif /* DRIVER_TEST_UNIX */
94 struct sockaddr_in hostapd_addr_udp;
95 int hostapd_addr_udp_set;
96 char *own_socket_path;
101 #define MAX_SCAN_RESULTS 30
102 struct wpa_scan_res *scanres[MAX_SCAN_RESULTS];
106 size_t assoc_wpa_ie_len;
110 size_t probe_req_ie_len;
120 static void test_driver_free_bss(struct test_driver_bss *bss)
123 free(bss->wps_beacon_ie);
124 free(bss->wps_probe_resp_ie);
129 static void test_driver_free_priv(struct test_driver_data *drv)
131 struct test_driver_bss *bss, *prev;
140 test_driver_free_bss(prev);
142 free(drv->own_socket_path);
143 free(drv->socket_dir);
148 static struct test_client_socket *
149 test_driver_get_cli(struct test_driver_data *drv, struct sockaddr_un *from,
152 struct test_client_socket *cli = drv->cli;
155 if (cli->unlen == fromlen &&
156 strncmp(cli->un.sun_path, from->sun_path,
157 fromlen - sizeof(cli->un.sun_family)) == 0)
166 static int test_driver_send_eapol(void *priv, const u8 *addr, const u8 *data,
167 size_t data_len, int encrypt,
170 struct test_driver_data *drv = priv;
171 struct test_client_socket *cli;
174 struct l2_ethhdr eth;
176 if (drv->test_socket < 0)
181 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
187 wpa_printf(MSG_DEBUG, "%s: no destination client entry",
192 memcpy(eth.h_dest, addr, ETH_ALEN);
193 memcpy(eth.h_source, own_addr, ETH_ALEN);
194 eth.h_proto = host_to_be16(ETH_P_EAPOL);
196 io[0].iov_base = "EAPOL ";
198 io[1].iov_base = ð
199 io[1].iov_len = sizeof(eth);
200 io[2].iov_base = (u8 *) data;
201 io[2].iov_len = data_len;
203 memset(&msg, 0, sizeof(msg));
206 msg.msg_name = &cli->un;
207 msg.msg_namelen = cli->unlen;
208 return sendmsg(drv->test_socket, &msg, 0);
212 static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
213 u16 proto, const u8 *data, size_t data_len)
215 struct test_driver_data *drv = priv;
218 struct l2_ethhdr eth;
220 struct sockaddr_un addr;
223 int ret = 0, broadcast = 0, count = 0;
225 if (drv->test_socket < 0 || drv->socket_dir == NULL) {
226 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d "
228 __func__, drv->test_socket, drv->socket_dir);
232 broadcast = memcmp(dst, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
233 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dst));
235 memcpy(eth.h_dest, dst, ETH_ALEN);
236 memcpy(eth.h_source, src, ETH_ALEN);
237 eth.h_proto = host_to_be16(proto);
239 io[0].iov_base = "ETHER ";
241 io[1].iov_base = ð
242 io[1].iov_len = sizeof(eth);
243 io[2].iov_base = (u8 *) data;
244 io[2].iov_len = data_len;
246 memset(&msg, 0, sizeof(msg));
250 dir = opendir(drv->socket_dir);
252 perror("test_driver: opendir");
255 while ((dent = readdir(dir))) {
256 #ifdef _DIRENT_HAVE_D_TYPE
257 /* Skip the file if it is not a socket. Also accept
258 * DT_UNKNOWN (0) in case the C library or underlying file
259 * system does not support d_type. */
260 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
262 #endif /* _DIRENT_HAVE_D_TYPE */
263 if (strcmp(dent->d_name, ".") == 0 ||
264 strcmp(dent->d_name, "..") == 0)
267 memset(&addr, 0, sizeof(addr));
268 addr.sun_family = AF_UNIX;
269 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
270 drv->socket_dir, dent->d_name);
272 if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
274 if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
277 wpa_printf(MSG_DEBUG, "%s: Send ether frame to %s",
278 __func__, dent->d_name);
280 msg.msg_name = &addr;
281 msg.msg_namelen = sizeof(addr);
282 ret = sendmsg(drv->test_socket, &msg, 0);
284 perror("driver_test: sendmsg");
289 if (!broadcast && count == 0) {
290 wpa_printf(MSG_DEBUG, "%s: Destination " MACSTR " not found",
291 __func__, MAC2STR(dst));
299 static int wpa_driver_test_send_mlme(void *priv, const u8 *buf, size_t len)
301 struct test_driver_data *drv = priv;
305 int ret = 0, broadcast = 0;
307 struct sockaddr_un addr;
310 struct ieee80211_hdr *hdr;
313 if (drv->test_socket < 0 || len < 10 || drv->socket_dir == NULL) {
314 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d len=%lu"
316 __func__, drv->test_socket, (unsigned long) len,
323 broadcast = memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
324 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dest));
326 io[0].iov_base = "MLME ";
328 io[1].iov_base = (void *) buf;
331 memset(&msg, 0, sizeof(msg));
335 dir = opendir(drv->socket_dir);
337 perror("test_driver: opendir");
340 while ((dent = readdir(dir))) {
341 #ifdef _DIRENT_HAVE_D_TYPE
342 /* Skip the file if it is not a socket. Also accept
343 * DT_UNKNOWN (0) in case the C library or underlying file
344 * system does not support d_type. */
345 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
347 #endif /* _DIRENT_HAVE_D_TYPE */
348 if (strcmp(dent->d_name, ".") == 0 ||
349 strcmp(dent->d_name, "..") == 0)
352 memset(&addr, 0, sizeof(addr));
353 addr.sun_family = AF_UNIX;
354 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
355 drv->socket_dir, dent->d_name);
357 if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
359 if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
362 wpa_printf(MSG_DEBUG, "%s: Send management frame to %s",
363 __func__, dent->d_name);
365 msg.msg_name = &addr;
366 msg.msg_namelen = sizeof(addr);
367 ret = sendmsg(drv->test_socket, &msg, 0);
369 perror("driver_test: sendmsg");
373 hdr = (struct ieee80211_hdr *) buf;
374 fc = le_to_host16(hdr->frame_control);
375 hostapd_mgmt_tx_cb(drv->hapd, (u8 *) buf, len, WLAN_FC_GET_STYPE(fc),
382 static void test_driver_scan(struct test_driver_data *drv,
383 struct sockaddr_un *from, socklen_t fromlen,
386 char buf[512], *pos, *end;
388 struct test_driver_bss *bss;
393 /* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
395 wpa_printf(MSG_DEBUG, "test_driver: SCAN");
399 hwaddr_aton(data + 1, sa)) {
400 wpa_printf(MSG_DEBUG, "test_driver: Unexpected SCAN "
408 ielen = os_strlen(data) / 2;
409 if (ielen > sizeof(ie))
411 if (hexstr2bin(data, ie, ielen) < 0)
414 wpa_printf(MSG_DEBUG, "test_driver: Scan from " MACSTR,
416 wpa_hexdump(MSG_MSGDUMP, "test_driver: scan IEs", ie, ielen);
418 hostapd_wps_probe_req_rx(drv->hapd, sa, ie, ielen);
421 for (bss = drv->bss; bss; bss = bss->next) {
423 end = buf + sizeof(buf);
425 /* reply: SCANRESP BSSID SSID IEs */
426 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
427 MAC2STR(bss->bssid));
428 if (ret < 0 || ret >= end - pos)
431 pos += wpa_snprintf_hex(pos, end - pos,
432 bss->ssid, bss->ssid_len);
433 ret = snprintf(pos, end - pos, " ");
434 if (ret < 0 || ret >= end - pos)
437 pos += wpa_snprintf_hex(pos, end - pos, bss->ie, bss->ielen);
438 pos += wpa_snprintf_hex(pos, end - pos, bss->wps_probe_resp_ie,
439 bss->wps_probe_resp_ie_len);
442 ret = snprintf(pos, end - pos, " PRIVACY");
443 if (ret < 0 || ret >= end - pos)
448 sendto(drv->test_socket, buf, pos - buf, 0,
449 (struct sockaddr *) from, fromlen);
454 static struct hostapd_data * test_driver_get_hapd(struct test_driver_data *drv,
455 struct test_driver_bss *bss)
457 struct hostapd_iface *iface = drv->hapd->iface;
458 struct hostapd_data *hapd = NULL;
462 wpa_printf(MSG_DEBUG, "%s: bss == NULL", __func__);
466 for (i = 0; i < iface->num_bss; i++) {
467 hapd = iface->bss[i];
468 if (memcmp(hapd->own_addr, bss->bssid, ETH_ALEN) == 0)
471 if (i == iface->num_bss) {
472 wpa_printf(MSG_DEBUG, "%s: no matching interface entry found "
473 "for BSSID " MACSTR, __func__, MAC2STR(bss->bssid));
481 static int test_driver_new_sta(struct test_driver_data *drv,
482 struct test_driver_bss *bss, const u8 *addr,
483 const u8 *ie, size_t ielen)
485 struct hostapd_data *hapd;
487 hapd = test_driver_get_hapd(drv, bss);
491 return hostapd_notif_assoc(hapd, addr, ie, ielen);
495 static void test_driver_assoc(struct test_driver_data *drv,
496 struct sockaddr_un *from, socklen_t fromlen,
499 struct test_client_socket *cli;
500 u8 ie[256], ssid[32];
501 size_t ielen, ssid_len = 0;
502 char *pos, *pos2, cmd[50];
503 struct test_driver_bss *bss;
505 /* data: STA-addr SSID(hex) IEs(hex) */
507 cli = os_zalloc(sizeof(*cli));
511 if (hwaddr_aton(data, cli->addr)) {
512 printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
520 pos2 = strchr(pos, ' ');
523 ssid_len = (pos2 - pos) / 2;
524 if (hexstr2bin(pos, ssid, ssid_len) < 0) {
525 wpa_printf(MSG_DEBUG, "%s: Invalid SSID", __func__);
529 wpa_hexdump_ascii(MSG_DEBUG, "test_driver_assoc: SSID",
533 ielen = strlen(pos) / 2;
534 if (ielen > sizeof(ie))
536 if (hexstr2bin(pos, ie, ielen) < 0)
540 for (bss = drv->bss; bss; bss = bss->next) {
541 if (bss->ssid_len == ssid_len &&
542 memcmp(bss->ssid, ssid, ssid_len) == 0)
546 wpa_printf(MSG_DEBUG, "%s: No matching SSID found from "
547 "configured BSSes", __func__);
553 memcpy(&cli->un, from, sizeof(cli->un));
554 cli->unlen = fromlen;
555 cli->next = drv->cli;
557 wpa_hexdump_ascii(MSG_DEBUG, "test_socket: ASSOC sun_path",
558 (const u8 *) cli->un.sun_path,
559 cli->unlen - sizeof(cli->un.sun_family));
561 snprintf(cmd, sizeof(cmd), "ASSOCRESP " MACSTR " 0",
562 MAC2STR(bss->bssid));
563 sendto(drv->test_socket, cmd, strlen(cmd), 0,
564 (struct sockaddr *) from, fromlen);
566 if (test_driver_new_sta(drv, bss, cli->addr, ie, ielen) < 0) {
567 wpa_printf(MSG_DEBUG, "test_driver: failed to add new STA");
572 static void test_driver_disassoc(struct test_driver_data *drv,
573 struct sockaddr_un *from, socklen_t fromlen)
575 struct test_client_socket *cli;
577 cli = test_driver_get_cli(drv, from, fromlen);
581 hostapd_notif_disassoc(drv->hapd, cli->addr);
585 static void test_driver_eapol(struct test_driver_data *drv,
586 struct sockaddr_un *from, socklen_t fromlen,
587 u8 *data, size_t datalen)
589 struct test_client_socket *cli;
591 /* Skip Ethernet header */
592 wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
593 MACSTR " proto=%04x",
594 MAC2STR(data), MAC2STR(data + ETH_ALEN),
595 WPA_GET_BE16(data + 2 * ETH_ALEN));
599 cli = test_driver_get_cli(drv, from, fromlen);
601 struct hostapd_data *hapd;
602 hapd = test_driver_get_hapd(drv, cli->bss);
605 hostapd_eapol_receive(hapd, cli->addr, data, datalen);
607 wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
613 static void test_driver_ether(struct test_driver_data *drv,
614 struct sockaddr_un *from, socklen_t fromlen,
615 u8 *data, size_t datalen)
617 struct l2_ethhdr *eth;
619 if (datalen < sizeof(*eth))
622 eth = (struct l2_ethhdr *) data;
623 wpa_printf(MSG_DEBUG, "test_driver: RX ETHER dst=" MACSTR " src="
624 MACSTR " proto=%04x",
625 MAC2STR(eth->h_dest), MAC2STR(eth->h_source),
626 be_to_host16(eth->h_proto));
628 #ifdef CONFIG_IEEE80211R
629 if (be_to_host16(eth->h_proto) == ETH_P_RRB) {
630 wpa_ft_rrb_rx(drv->hapd->wpa_auth, eth->h_source,
631 data + sizeof(*eth), datalen - sizeof(*eth));
633 #endif /* CONFIG_IEEE80211R */
637 static void test_driver_mlme(struct test_driver_data *drv,
638 struct sockaddr_un *from, socklen_t fromlen,
639 u8 *data, size_t datalen)
641 struct ieee80211_hdr *hdr;
644 hdr = (struct ieee80211_hdr *) data;
646 if (test_driver_get_cli(drv, from, fromlen) == NULL && datalen >= 16) {
647 struct test_client_socket *cli;
648 cli = os_zalloc(sizeof(*cli));
651 wpa_printf(MSG_DEBUG, "Adding client entry for " MACSTR,
652 MAC2STR(hdr->addr2));
653 memcpy(cli->addr, hdr->addr2, ETH_ALEN);
654 memcpy(&cli->un, from, sizeof(cli->un));
655 cli->unlen = fromlen;
656 cli->next = drv->cli;
660 wpa_hexdump(MSG_MSGDUMP, "test_driver_mlme: received frame",
662 fc = le_to_host16(hdr->frame_control);
663 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT) {
664 wpa_printf(MSG_ERROR, "%s: received non-mgmt frame",
668 hostapd_mgmt_rx(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
672 static void test_driver_receive_unix(int sock, void *eloop_ctx, void *sock_ctx)
674 struct test_driver_data *drv = eloop_ctx;
677 struct sockaddr_un from;
678 socklen_t fromlen = sizeof(from);
680 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
681 (struct sockaddr *) &from, &fromlen);
683 perror("recvfrom(test_socket)");
688 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
690 if (strncmp(buf, "SCAN", 4) == 0) {
691 test_driver_scan(drv, &from, fromlen, buf + 4);
692 } else if (strncmp(buf, "ASSOC ", 6) == 0) {
693 test_driver_assoc(drv, &from, fromlen, buf + 6);
694 } else if (strcmp(buf, "DISASSOC") == 0) {
695 test_driver_disassoc(drv, &from, fromlen);
696 } else if (strncmp(buf, "EAPOL ", 6) == 0) {
697 test_driver_eapol(drv, &from, fromlen, (u8 *) buf + 6,
699 } else if (strncmp(buf, "ETHER ", 6) == 0) {
700 test_driver_ether(drv, &from, fromlen, (u8 *) buf + 6,
702 } else if (strncmp(buf, "MLME ", 5) == 0) {
703 test_driver_mlme(drv, &from, fromlen, (u8 *) buf + 5, res - 5);
705 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
711 static struct test_driver_bss *
712 test_driver_get_bss(struct test_driver_data *drv, const char *ifname)
714 struct test_driver_bss *bss;
716 for (bss = drv->bss; bss; bss = bss->next) {
717 if (strcmp(bss->ifname, ifname) == 0)
724 static int test_driver_set_generic_elem(const char *ifname, void *priv,
725 const u8 *elem, size_t elem_len)
727 struct test_driver_data *drv = priv;
728 struct test_driver_bss *bss;
730 bss = test_driver_get_bss(drv, ifname);
742 bss->ie = malloc(elem_len);
743 if (bss->ie == NULL) {
748 memcpy(bss->ie, elem, elem_len);
749 bss->ielen = elem_len;
754 static int test_driver_set_wps_beacon_ie(const char *ifname, void *priv,
755 const u8 *ie, size_t len)
757 struct test_driver_data *drv = priv;
758 struct test_driver_bss *bss;
760 wpa_hexdump(MSG_DEBUG, "test_driver: Beacon WPS IE", ie, len);
761 bss = test_driver_get_bss(drv, ifname);
765 free(bss->wps_beacon_ie);
768 bss->wps_beacon_ie = NULL;
769 bss->wps_beacon_ie_len = 0;
773 bss->wps_beacon_ie = malloc(len);
774 if (bss->wps_beacon_ie == NULL) {
775 bss->wps_beacon_ie_len = 0;
779 memcpy(bss->wps_beacon_ie, ie, len);
780 bss->wps_beacon_ie_len = len;
785 static int test_driver_set_wps_probe_resp_ie(const char *ifname, void *priv,
786 const u8 *ie, size_t len)
788 struct test_driver_data *drv = priv;
789 struct test_driver_bss *bss;
791 wpa_hexdump(MSG_DEBUG, "test_driver: ProbeResp WPS IE", ie, len);
792 bss = test_driver_get_bss(drv, ifname);
796 free(bss->wps_probe_resp_ie);
799 bss->wps_probe_resp_ie = NULL;
800 bss->wps_probe_resp_ie_len = 0;
804 bss->wps_probe_resp_ie = malloc(len);
805 if (bss->wps_probe_resp_ie == NULL) {
806 bss->wps_probe_resp_ie_len = 0;
810 memcpy(bss->wps_probe_resp_ie, ie, len);
811 bss->wps_probe_resp_ie_len = len;
816 static int test_driver_sta_deauth(void *priv, const u8 *own_addr,
817 const u8 *addr, int reason)
819 struct test_driver_data *drv = priv;
820 struct test_client_socket *cli;
822 if (drv->test_socket < 0)
827 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
835 return sendto(drv->test_socket, "DEAUTH", 6, 0,
836 (struct sockaddr *) &cli->un, cli->unlen);
840 static int test_driver_sta_disassoc(void *priv, const u8 *own_addr,
841 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,
1071 struct wpa_init_params *params)
1073 struct test_driver_data *drv;
1074 struct sockaddr_un addr_un;
1075 struct sockaddr_in addr_in;
1076 struct sockaddr *addr;
1079 drv = os_zalloc(sizeof(struct test_driver_data));
1081 printf("Could not allocate memory for test driver data\n");
1084 drv->bss = os_zalloc(sizeof(*drv->bss));
1085 if (drv->bss == NULL) {
1086 printf("Could not allocate memory for test driver BSS data\n");
1093 /* Generate a MAC address to help testing with multiple APs */
1094 hapd->own_addr[0] = 0x02; /* locally administered */
1095 sha1_prf((const u8 *) params->ifname, strlen(params->ifname),
1096 "hostapd test bssid generation",
1097 params->ssid, params->ssid_len,
1098 hapd->own_addr + 1, ETH_ALEN - 1);
1100 os_strlcpy(drv->bss->ifname, params->ifname, IFNAMSIZ);
1101 memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
1103 if (params->test_socket) {
1104 if (os_strlen(params->test_socket) >=
1105 sizeof(addr_un.sun_path)) {
1106 printf("Too long test_socket path\n");
1107 test_driver_free_priv(drv);
1110 if (strncmp(params->test_socket, "DIR:", 4) == 0) {
1111 size_t len = strlen(params->test_socket) + 30;
1112 drv->socket_dir = strdup(params->test_socket + 4);
1113 drv->own_socket_path = malloc(len);
1114 if (drv->own_socket_path) {
1115 snprintf(drv->own_socket_path, len,
1117 params->test_socket + 4,
1118 MAC2STR(hapd->own_addr));
1120 } else if (strncmp(params->test_socket, "UDP:", 4) == 0) {
1121 drv->udp_port = atoi(params->test_socket + 4);
1123 drv->own_socket_path = strdup(params->test_socket);
1125 if (drv->own_socket_path == NULL && drv->udp_port == 0) {
1126 test_driver_free_priv(drv);
1130 drv->test_socket = socket(drv->udp_port ? PF_INET : PF_UNIX,
1132 if (drv->test_socket < 0) {
1134 test_driver_free_priv(drv);
1138 if (drv->udp_port) {
1139 os_memset(&addr_in, 0, sizeof(addr_in));
1140 addr_in.sin_family = AF_INET;
1141 addr_in.sin_port = htons(drv->udp_port);
1142 addr = (struct sockaddr *) &addr_in;
1143 alen = sizeof(addr_in);
1145 os_memset(&addr_un, 0, sizeof(addr_un));
1146 addr_un.sun_family = AF_UNIX;
1147 os_strlcpy(addr_un.sun_path, drv->own_socket_path,
1148 sizeof(addr_un.sun_path));
1149 addr = (struct sockaddr *) &addr_un;
1150 alen = sizeof(addr_un);
1152 if (bind(drv->test_socket, addr, alen) < 0) {
1153 perror("bind(PF_UNIX)");
1154 close(drv->test_socket);
1155 if (drv->own_socket_path)
1156 unlink(drv->own_socket_path);
1157 test_driver_free_priv(drv);
1160 eloop_register_read_sock(drv->test_socket,
1161 test_driver_receive_unix, drv, NULL);
1163 drv->test_socket = -1;
1169 static void test_driver_deinit(void *priv)
1171 struct test_driver_data *drv = priv;
1172 struct test_client_socket *cli, *prev;
1181 if (drv->test_socket >= 0) {
1182 eloop_unregister_read_sock(drv->test_socket);
1183 close(drv->test_socket);
1184 if (drv->own_socket_path)
1185 unlink(drv->own_socket_path);
1188 /* There should be only one BSS remaining at this point. */
1189 if (drv->bss == NULL)
1190 wpa_printf(MSG_ERROR, "%s: drv->bss == NULL", __func__);
1191 else if (drv->bss->next)
1192 wpa_printf(MSG_ERROR, "%s: drv->bss->next != NULL", __func__);
1194 test_driver_free_priv(drv);
1199 static void wpa_driver_test_poll(void *eloop_ctx, void *timeout_ctx)
1201 struct wpa_driver_test_data *drv = eloop_ctx;
1203 #ifdef DRIVER_TEST_UNIX
1204 if (drv->associated && drv->hostapd_addr_set) {
1206 if (stat(drv->hostapd_addr.sun_path, &st) < 0) {
1207 wpa_printf(MSG_DEBUG, "%s: lost connection to AP: %s",
1208 __func__, strerror(errno));
1209 drv->associated = 0;
1210 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1213 #endif /* DRIVER_TEST_UNIX */
1215 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
1219 static int wpa_driver_test_set_wpa(void *priv, int enabled)
1221 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
1226 static void wpa_driver_test_scan_timeout(void *eloop_ctx, void *timeout_ctx)
1228 wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
1229 wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
1233 #ifdef DRIVER_TEST_UNIX
1234 static void wpa_driver_scan_dir(struct wpa_driver_test_data *drv,
1237 struct dirent *dent;
1239 struct sockaddr_un addr;
1240 char cmd[512], *pos, *end;
1243 dir = opendir(path);
1247 end = cmd + sizeof(cmd);
1249 ret = os_snprintf(pos, end - pos, "SCAN " MACSTR,
1250 MAC2STR(drv->own_addr));
1251 if (ret >= 0 && ret < end - pos)
1253 if (drv->probe_req_ie) {
1254 ret = os_snprintf(pos, end - pos, " ");
1255 if (ret >= 0 && ret < end - pos)
1257 pos += wpa_snprintf_hex(pos, end - pos, drv->probe_req_ie,
1258 drv->probe_req_ie_len);
1262 while ((dent = readdir(dir))) {
1263 if (os_strncmp(dent->d_name, "AP-", 3) != 0 &&
1264 os_strncmp(dent->d_name, "STA-", 4) != 0)
1266 if (drv->own_socket_path) {
1268 olen = os_strlen(drv->own_socket_path);
1269 dlen = os_strlen(dent->d_name);
1271 os_strcmp(dent->d_name,
1272 drv->own_socket_path + olen - dlen) == 0)
1275 wpa_printf(MSG_DEBUG, "%s: SCAN %s", __func__, dent->d_name);
1277 os_memset(&addr, 0, sizeof(addr));
1278 addr.sun_family = AF_UNIX;
1279 os_snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
1280 path, dent->d_name);
1282 if (sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1283 (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1284 perror("sendto(test_socket)");
1289 #endif /* DRIVER_TEST_UNIX */
1292 static int wpa_driver_test_scan(void *priv,
1293 struct wpa_driver_scan_params *params)
1295 struct wpa_driver_test_data *drv = priv;
1298 wpa_printf(MSG_DEBUG, "%s: priv=%p", __func__, priv);
1299 for (i = 0; i < params->num_ssids; i++)
1300 wpa_hexdump(MSG_DEBUG, "Scan SSID",
1301 params->ssids[i].ssid, params->ssids[i].ssid_len);
1302 wpa_hexdump(MSG_DEBUG, "Scan extra IE(s)",
1303 params->extra_ies, params->extra_ies_len);
1305 drv->num_scanres = 0;
1307 #ifdef DRIVER_TEST_UNIX
1308 if (drv->test_socket >= 0 && drv->test_dir)
1309 wpa_driver_scan_dir(drv, drv->test_dir);
1311 if (drv->test_socket >= 0 && drv->hostapd_addr_set &&
1312 sendto(drv->test_socket, "SCAN", 4, 0,
1313 (struct sockaddr *) &drv->hostapd_addr,
1314 sizeof(drv->hostapd_addr)) < 0) {
1315 perror("sendto(test_socket)");
1317 #endif /* DRIVER_TEST_UNIX */
1319 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1320 sendto(drv->test_socket, "SCAN", 4, 0,
1321 (struct sockaddr *) &drv->hostapd_addr_udp,
1322 sizeof(drv->hostapd_addr_udp)) < 0) {
1323 perror("sendto(test_socket)");
1326 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
1327 eloop_register_timeout(1, 0, wpa_driver_test_scan_timeout, drv,
1333 static struct wpa_scan_results * wpa_driver_test_get_scan_results2(void *priv)
1335 struct wpa_driver_test_data *drv = priv;
1336 struct wpa_scan_results *res;
1339 res = os_zalloc(sizeof(*res));
1343 res->res = os_zalloc(drv->num_scanres * sizeof(struct wpa_scan_res *));
1344 if (res->res == NULL) {
1349 for (i = 0; i < drv->num_scanres; i++) {
1350 struct wpa_scan_res *r;
1351 if (drv->scanres[i] == NULL)
1353 r = os_malloc(sizeof(*r) + drv->scanres[i]->ie_len);
1356 os_memcpy(r, drv->scanres[i],
1357 sizeof(*r) + drv->scanres[i]->ie_len);
1358 res->res[res->num++] = r;
1365 static int wpa_driver_test_set_key(void *priv, wpa_alg alg, const u8 *addr,
1366 int key_idx, int set_tx,
1367 const u8 *seq, size_t seq_len,
1368 const u8 *key, size_t key_len)
1370 wpa_printf(MSG_DEBUG, "%s: priv=%p alg=%d key_idx=%d set_tx=%d",
1371 __func__, priv, alg, key_idx, set_tx);
1373 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
1376 wpa_hexdump(MSG_DEBUG, " seq", seq, seq_len);
1379 wpa_hexdump(MSG_DEBUG, " key", key, key_len);
1385 static int wpa_driver_test_associate(
1386 void *priv, struct wpa_driver_associate_params *params)
1388 struct wpa_driver_test_data *drv = priv;
1389 wpa_printf(MSG_DEBUG, "%s: priv=%p freq=%d pairwise_suite=%d "
1390 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d",
1391 __func__, priv, params->freq, params->pairwise_suite,
1392 params->group_suite, params->key_mgmt_suite,
1393 params->auth_alg, params->mode);
1394 if (params->bssid) {
1395 wpa_printf(MSG_DEBUG, " bssid=" MACSTR,
1396 MAC2STR(params->bssid));
1399 wpa_hexdump_ascii(MSG_DEBUG, " ssid",
1400 params->ssid, params->ssid_len);
1402 if (params->wpa_ie) {
1403 wpa_hexdump(MSG_DEBUG, " wpa_ie",
1404 params->wpa_ie, params->wpa_ie_len);
1405 drv->assoc_wpa_ie_len = params->wpa_ie_len;
1406 if (drv->assoc_wpa_ie_len > sizeof(drv->assoc_wpa_ie))
1407 drv->assoc_wpa_ie_len = sizeof(drv->assoc_wpa_ie);
1408 os_memcpy(drv->assoc_wpa_ie, params->wpa_ie,
1409 drv->assoc_wpa_ie_len);
1411 drv->assoc_wpa_ie_len = 0;
1413 drv->ibss = params->mode == IEEE80211_MODE_IBSS;
1414 drv->privacy = params->key_mgmt_suite &
1415 (WPA_KEY_MGMT_IEEE8021X |
1417 WPA_KEY_MGMT_WPA_NONE |
1418 WPA_KEY_MGMT_FT_IEEE8021X |
1419 WPA_KEY_MGMT_FT_PSK |
1420 WPA_KEY_MGMT_IEEE8021X_SHA256 |
1421 WPA_KEY_MGMT_PSK_SHA256);
1422 if (params->wep_key_len[params->wep_tx_keyidx])
1425 #ifdef DRIVER_TEST_UNIX
1426 if (drv->test_dir && params->bssid &&
1427 params->mode != IEEE80211_MODE_IBSS) {
1428 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
1429 drv->hostapd_addr.sun_family = AF_UNIX;
1430 os_snprintf(drv->hostapd_addr.sun_path,
1431 sizeof(drv->hostapd_addr.sun_path),
1433 drv->test_dir, MAC2STR(params->bssid));
1434 drv->hostapd_addr_set = 1;
1436 #endif /* DRIVER_TEST_UNIX */
1438 if (drv->test_socket >= 0 &&
1439 (drv->hostapd_addr_set || drv->hostapd_addr_udp_set)) {
1440 char cmd[200], *pos, *end;
1442 end = cmd + sizeof(cmd);
1444 ret = os_snprintf(pos, end - pos, "ASSOC " MACSTR " ",
1445 MAC2STR(drv->own_addr));
1446 if (ret >= 0 && ret < end - pos)
1448 pos += wpa_snprintf_hex(pos, end - pos, params->ssid,
1450 ret = os_snprintf(pos, end - pos, " ");
1451 if (ret >= 0 && ret < end - pos)
1453 pos += wpa_snprintf_hex(pos, end - pos, params->wpa_ie,
1454 params->wpa_ie_len);
1456 #ifdef DRIVER_TEST_UNIX
1457 if (drv->hostapd_addr_set &&
1458 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1459 (struct sockaddr *) &drv->hostapd_addr,
1460 sizeof(drv->hostapd_addr)) < 0) {
1461 perror("sendto(test_socket)");
1464 #endif /* DRIVER_TEST_UNIX */
1465 if (drv->hostapd_addr_udp_set &&
1466 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1467 (struct sockaddr *) &drv->hostapd_addr_udp,
1468 sizeof(drv->hostapd_addr_udp)) < 0) {
1469 perror("sendto(test_socket)");
1473 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1474 drv->ssid_len = params->ssid_len;
1476 drv->associated = 1;
1477 if (params->mode == IEEE80211_MODE_IBSS) {
1478 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1479 drv->ssid_len = params->ssid_len;
1481 os_memcpy(drv->bssid, params->bssid, ETH_ALEN);
1483 os_get_random(drv->bssid, ETH_ALEN);
1484 drv->bssid[0] &= ~0x01;
1485 drv->bssid[0] |= 0x02;
1488 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1495 static int wpa_driver_test_get_bssid(void *priv, u8 *bssid)
1497 struct wpa_driver_test_data *drv = priv;
1498 os_memcpy(bssid, drv->bssid, ETH_ALEN);
1503 static int wpa_driver_test_get_ssid(void *priv, u8 *ssid)
1505 struct wpa_driver_test_data *drv = priv;
1506 os_memcpy(ssid, drv->ssid, 32);
1507 return drv->ssid_len;
1511 static int wpa_driver_test_send_disassoc(struct wpa_driver_test_data *drv)
1513 #ifdef DRIVER_TEST_UNIX
1514 if (drv->test_socket >= 0 &&
1515 sendto(drv->test_socket, "DISASSOC", 8, 0,
1516 (struct sockaddr *) &drv->hostapd_addr,
1517 sizeof(drv->hostapd_addr)) < 0) {
1518 perror("sendto(test_socket)");
1521 #endif /* DRIVER_TEST_UNIX */
1522 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1523 sendto(drv->test_socket, "DISASSOC", 8, 0,
1524 (struct sockaddr *) &drv->hostapd_addr_udp,
1525 sizeof(drv->hostapd_addr_udp)) < 0) {
1526 perror("sendto(test_socket)");
1533 static int wpa_driver_test_deauthenticate(void *priv, const u8 *addr,
1536 struct wpa_driver_test_data *drv = priv;
1537 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1538 __func__, MAC2STR(addr), reason_code);
1539 os_memset(drv->bssid, 0, ETH_ALEN);
1540 drv->associated = 0;
1541 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1542 return wpa_driver_test_send_disassoc(drv);
1546 static int wpa_driver_test_disassociate(void *priv, const u8 *addr,
1549 struct wpa_driver_test_data *drv = priv;
1550 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1551 __func__, MAC2STR(addr), reason_code);
1552 os_memset(drv->bssid, 0, ETH_ALEN);
1553 drv->associated = 0;
1554 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1555 return wpa_driver_test_send_disassoc(drv);
1559 static void wpa_driver_test_scanresp(struct wpa_driver_test_data *drv,
1560 struct sockaddr *from,
1564 struct wpa_scan_res *res;
1565 const char *pos, *pos2;
1567 u8 *ie_pos, *ie_start, *ie_end;
1568 #define MAX_IE_LEN 1000
1570 wpa_printf(MSG_DEBUG, "test_driver: SCANRESP %s", data);
1571 if (drv->num_scanres >= MAX_SCAN_RESULTS) {
1572 wpa_printf(MSG_DEBUG, "test_driver: No room for the new scan "
1577 /* SCANRESP BSSID SSID IEs */
1579 res = os_zalloc(sizeof(*res) + MAX_IE_LEN);
1582 ie_start = ie_pos = (u8 *) (res + 1);
1583 ie_end = ie_pos + MAX_IE_LEN;
1585 if (hwaddr_aton(data, res->bssid)) {
1586 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in scanres");
1594 pos2 = os_strchr(pos, ' ');
1596 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID termination "
1601 len = (pos2 - pos) / 2;
1605 * Generate SSID IE from the SSID field since this IE is not included
1606 * in the main IE field.
1608 *ie_pos++ = WLAN_EID_SSID;
1610 if (hexstr2bin(pos, ie_pos, len) < 0) {
1611 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID in scanres");
1618 pos2 = os_strchr(pos, ' ');
1620 len = os_strlen(pos) / 2;
1622 len = (pos2 - pos) / 2;
1623 if ((int) len > ie_end - ie_pos)
1624 len = ie_end - ie_pos;
1625 if (hexstr2bin(pos, ie_pos, len) < 0) {
1626 wpa_printf(MSG_DEBUG, "test_driver: invalid IEs in scanres");
1631 res->ie_len = ie_pos - ie_start;
1637 if (os_strstr(pos, "PRIVACY"))
1638 res->caps |= IEEE80211_CAP_PRIVACY;
1639 if (os_strstr(pos, "IBSS"))
1640 res->caps |= IEEE80211_CAP_IBSS;
1643 os_free(drv->scanres[drv->num_scanres]);
1644 drv->scanres[drv->num_scanres++] = res;
1648 static void wpa_driver_test_assocresp(struct wpa_driver_test_data *drv,
1649 struct sockaddr *from,
1653 /* ASSOCRESP BSSID <res> */
1654 if (hwaddr_aton(data, drv->bssid)) {
1655 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in "
1658 if (drv->use_associnfo) {
1659 union wpa_event_data event;
1660 os_memset(&event, 0, sizeof(event));
1661 event.assoc_info.req_ies = drv->assoc_wpa_ie;
1662 event.assoc_info.req_ies_len = drv->assoc_wpa_ie_len;
1663 wpa_supplicant_event(drv->ctx, EVENT_ASSOCINFO, &event);
1665 drv->associated = 1;
1666 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1670 static void wpa_driver_test_disassoc(struct wpa_driver_test_data *drv,
1671 struct sockaddr *from,
1674 drv->associated = 0;
1675 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1679 static void wpa_driver_test_eapol(struct wpa_driver_test_data *drv,
1680 struct sockaddr *from,
1682 const u8 *data, size_t data_len)
1684 const u8 *src = drv->bssid;
1686 if (data_len > 14) {
1687 /* Skip Ethernet header */
1688 src = data + ETH_ALEN;
1692 wpa_supplicant_rx_eapol(drv->ctx, src, data, data_len);
1696 static void wpa_driver_test_mlme(struct wpa_driver_test_data *drv,
1697 struct sockaddr *from,
1699 const u8 *data, size_t data_len)
1701 #ifdef CONFIG_CLIENT_MLME
1702 struct ieee80211_rx_status rx_status;
1703 os_memset(&rx_status, 0, sizeof(rx_status));
1704 wpa_supplicant_sta_rx(drv->ctx, data, data_len, &rx_status);
1705 #endif /* CONFIG_CLIENT_MLME */
1709 static void wpa_driver_test_scan_cmd(struct wpa_driver_test_data *drv,
1710 struct sockaddr *from,
1712 const u8 *data, size_t data_len)
1714 char buf[512], *pos, *end;
1717 /* data: optional [ STA-addr | ' ' | IEs(hex) ] */
1723 end = buf + sizeof(buf);
1725 /* reply: SCANRESP BSSID SSID IEs */
1726 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
1727 MAC2STR(drv->bssid));
1728 if (ret < 0 || ret >= end - pos)
1731 pos += wpa_snprintf_hex(pos, end - pos,
1732 drv->ssid, drv->ssid_len);
1733 ret = snprintf(pos, end - pos, " ");
1734 if (ret < 0 || ret >= end - pos)
1737 pos += wpa_snprintf_hex(pos, end - pos, drv->assoc_wpa_ie,
1738 drv->assoc_wpa_ie_len);
1741 ret = snprintf(pos, end - pos, " PRIVACY");
1742 if (ret < 0 || ret >= end - pos)
1747 ret = snprintf(pos, end - pos, " IBSS");
1748 if (ret < 0 || ret >= end - pos)
1752 sendto(drv->test_socket, buf, pos - buf, 0,
1753 (struct sockaddr *) from, fromlen);
1757 static void wpa_driver_test_receive_unix(int sock, void *eloop_ctx,
1760 struct wpa_driver_test_data *drv = eloop_ctx;
1763 struct sockaddr_storage from;
1764 socklen_t fromlen = sizeof(from);
1765 const size_t buflen = 2000;
1767 buf = os_malloc(buflen);
1770 res = recvfrom(sock, buf, buflen - 1, 0,
1771 (struct sockaddr *) &from, &fromlen);
1773 perror("recvfrom(test_socket)");
1779 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
1781 if (os_strncmp(buf, "SCANRESP ", 9) == 0) {
1782 wpa_driver_test_scanresp(drv, (struct sockaddr *) &from,
1784 } else if (os_strncmp(buf, "ASSOCRESP ", 10) == 0) {
1785 wpa_driver_test_assocresp(drv, (struct sockaddr *) &from,
1787 } else if (os_strcmp(buf, "DISASSOC") == 0) {
1788 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1790 } else if (os_strcmp(buf, "DEAUTH") == 0) {
1791 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1793 } else if (os_strncmp(buf, "EAPOL ", 6) == 0) {
1794 wpa_driver_test_eapol(drv, (struct sockaddr *) &from, fromlen,
1795 (const u8 *) buf + 6, res - 6);
1796 } else if (os_strncmp(buf, "MLME ", 5) == 0) {
1797 wpa_driver_test_mlme(drv, (struct sockaddr *) &from, fromlen,
1798 (const u8 *) buf + 5, res - 5);
1799 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
1800 wpa_driver_test_scan_cmd(drv, (struct sockaddr *) &from,
1802 (const u8 *) buf + 5, res - 5);
1804 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
1811 static void * wpa_driver_test_init2(void *ctx, const char *ifname,
1814 struct wpa_driver_test_data *drv;
1816 drv = os_zalloc(sizeof(*drv));
1819 drv->global = global_priv;
1821 drv->test_socket = -1;
1823 /* Set dummy BSSID and SSID for testing. */
1824 drv->bssid[0] = 0x02;
1825 drv->bssid[1] = 0x00;
1826 drv->bssid[2] = 0x00;
1827 drv->bssid[3] = 0x00;
1828 drv->bssid[4] = 0x00;
1829 drv->bssid[5] = 0x01;
1830 os_memcpy(drv->ssid, "test", 5);
1833 /* Generate a MAC address to help testing with multiple STAs */
1834 drv->own_addr[0] = 0x02; /* locally administered */
1835 sha1_prf((const u8 *) ifname, os_strlen(ifname),
1836 "wpa_supplicant test mac addr generation",
1837 NULL, 0, drv->own_addr + 1, ETH_ALEN - 1);
1838 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
1844 static void wpa_driver_test_close_test_socket(struct wpa_driver_test_data *drv)
1846 if (drv->test_socket >= 0) {
1847 eloop_unregister_read_sock(drv->test_socket);
1848 close(drv->test_socket);
1849 drv->test_socket = -1;
1852 if (drv->own_socket_path) {
1853 unlink(drv->own_socket_path);
1854 os_free(drv->own_socket_path);
1855 drv->own_socket_path = NULL;
1860 static void wpa_driver_test_deinit(void *priv)
1862 struct wpa_driver_test_data *drv = priv;
1864 wpa_driver_test_close_test_socket(drv);
1865 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
1866 eloop_cancel_timeout(wpa_driver_test_poll, drv, NULL);
1867 os_free(drv->test_dir);
1868 for (i = 0; i < MAX_SCAN_RESULTS; i++)
1869 os_free(drv->scanres[i]);
1870 os_free(drv->probe_req_ie);
1875 static int wpa_driver_test_attach(struct wpa_driver_test_data *drv,
1878 #ifdef DRIVER_TEST_UNIX
1879 static unsigned int counter = 0;
1880 struct sockaddr_un addr;
1883 os_free(drv->own_socket_path);
1885 len = os_strlen(dir) + 30;
1886 drv->own_socket_path = os_malloc(len);
1887 if (drv->own_socket_path == NULL)
1889 os_snprintf(drv->own_socket_path, len, "%s/STA-" MACSTR,
1890 dir, MAC2STR(drv->own_addr));
1892 drv->own_socket_path = os_malloc(100);
1893 if (drv->own_socket_path == NULL)
1895 os_snprintf(drv->own_socket_path, 100,
1896 "/tmp/wpa_supplicant_test-%d-%d",
1897 getpid(), counter++);
1900 drv->test_socket = socket(PF_UNIX, SOCK_DGRAM, 0);
1901 if (drv->test_socket < 0) {
1902 perror("socket(PF_UNIX)");
1903 os_free(drv->own_socket_path);
1904 drv->own_socket_path = NULL;
1908 os_memset(&addr, 0, sizeof(addr));
1909 addr.sun_family = AF_UNIX;
1910 os_strlcpy(addr.sun_path, drv->own_socket_path, sizeof(addr.sun_path));
1911 if (bind(drv->test_socket, (struct sockaddr *) &addr,
1912 sizeof(addr)) < 0) {
1913 perror("bind(PF_UNIX)");
1914 close(drv->test_socket);
1915 unlink(drv->own_socket_path);
1916 os_free(drv->own_socket_path);
1917 drv->own_socket_path = NULL;
1921 eloop_register_read_sock(drv->test_socket,
1922 wpa_driver_test_receive_unix, drv, NULL);
1925 #else /* DRIVER_TEST_UNIX */
1927 #endif /* DRIVER_TEST_UNIX */
1931 static int wpa_driver_test_attach_udp(struct wpa_driver_test_data *drv,
1936 pos = os_strchr(dst, ':');
1940 wpa_printf(MSG_DEBUG, "%s: addr=%s port=%s", __func__, dst, pos);
1942 drv->test_socket = socket(PF_INET, SOCK_DGRAM, 0);
1943 if (drv->test_socket < 0) {
1944 perror("socket(PF_INET)");
1948 os_memset(&drv->hostapd_addr_udp, 0, sizeof(drv->hostapd_addr_udp));
1949 drv->hostapd_addr_udp.sin_family = AF_INET;
1950 #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
1954 sscanf(dst, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
1955 pos = (u8 *) &drv->hostapd_addr_udp.sin_addr;
1961 #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1962 inet_aton(dst, &drv->hostapd_addr_udp.sin_addr);
1963 #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1964 drv->hostapd_addr_udp.sin_port = htons(atoi(pos));
1966 drv->hostapd_addr_udp_set = 1;
1968 eloop_register_read_sock(drv->test_socket,
1969 wpa_driver_test_receive_unix, drv, NULL);
1975 static int wpa_driver_test_set_param(void *priv, const char *param)
1977 struct wpa_driver_test_data *drv = priv;
1980 wpa_printf(MSG_DEBUG, "%s: param='%s'", __func__, param);
1984 wpa_driver_test_close_test_socket(drv);
1986 #ifdef DRIVER_TEST_UNIX
1987 pos = os_strstr(param, "test_socket=");
1993 pos2 = os_strchr(pos, ' ');
1997 len = os_strlen(pos);
1998 if (len > sizeof(drv->hostapd_addr.sun_path))
2000 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
2001 drv->hostapd_addr.sun_family = AF_UNIX;
2002 os_memcpy(drv->hostapd_addr.sun_path, pos, len);
2003 drv->hostapd_addr_set = 1;
2005 #endif /* DRIVER_TEST_UNIX */
2007 pos = os_strstr(param, "test_dir=");
2010 os_free(drv->test_dir);
2011 drv->test_dir = os_strdup(pos + 9);
2012 if (drv->test_dir == NULL)
2014 end = os_strchr(drv->test_dir, ' ');
2017 if (wpa_driver_test_attach(drv, drv->test_dir))
2020 pos = os_strstr(param, "test_udp=");
2023 dst = os_strdup(pos + 9);
2026 epos = os_strchr(dst, ' ');
2029 if (wpa_driver_test_attach_udp(drv, dst))
2032 } else if (wpa_driver_test_attach(drv, NULL))
2036 if (os_strstr(param, "use_associnfo=1")) {
2037 wpa_printf(MSG_DEBUG, "test_driver: Use AssocInfo events");
2038 drv->use_associnfo = 1;
2041 #ifdef CONFIG_CLIENT_MLME
2042 if (os_strstr(param, "use_mlme=1")) {
2043 wpa_printf(MSG_DEBUG, "test_driver: Use internal MLME");
2046 #endif /* CONFIG_CLIENT_MLME */
2052 static const u8 * wpa_driver_test_get_mac_addr(void *priv)
2054 struct wpa_driver_test_data *drv = priv;
2055 wpa_printf(MSG_DEBUG, "%s", __func__);
2056 return drv->own_addr;
2060 static int wpa_driver_test_send_eapol(void *priv, const u8 *dest, u16 proto,
2061 const u8 *data, size_t data_len)
2063 struct wpa_driver_test_data *drv = priv;
2066 struct l2_ethhdr eth;
2067 struct sockaddr *addr;
2069 #ifdef DRIVER_TEST_UNIX
2070 struct sockaddr_un addr_un;
2071 #endif /* DRIVER_TEST_UNIX */
2073 wpa_hexdump(MSG_MSGDUMP, "test_send_eapol TX frame", data, data_len);
2075 os_memset(ð, 0, sizeof(eth));
2076 os_memcpy(eth.h_dest, dest, ETH_ALEN);
2077 os_memcpy(eth.h_source, drv->own_addr, ETH_ALEN);
2078 eth.h_proto = host_to_be16(proto);
2080 msg_len = 6 + sizeof(eth) + data_len;
2081 msg = os_malloc(msg_len);
2084 os_memcpy(msg, "EAPOL ", 6);
2085 os_memcpy(msg + 6, ð, sizeof(eth));
2086 os_memcpy(msg + 6 + sizeof(eth), data, data_len);
2088 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
2089 drv->test_dir == NULL) {
2090 if (drv->hostapd_addr_udp_set) {
2091 addr = (struct sockaddr *) &drv->hostapd_addr_udp;
2092 alen = sizeof(drv->hostapd_addr_udp);
2094 #ifdef DRIVER_TEST_UNIX
2095 addr = (struct sockaddr *) &drv->hostapd_addr;
2096 alen = sizeof(drv->hostapd_addr);
2097 #else /* DRIVER_TEST_UNIX */
2100 #endif /* DRIVER_TEST_UNIX */
2103 #ifdef DRIVER_TEST_UNIX
2105 os_memset(&addr_un, 0, sizeof(addr_un));
2106 addr_un.sun_family = AF_UNIX;
2107 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2108 "%s/STA-" MACSTR, drv->test_dir, MAC2STR(dest));
2109 if (stat(addr_un.sun_path, &st) < 0) {
2110 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2112 drv->test_dir, MAC2STR(dest));
2114 addr = (struct sockaddr *) &addr_un;
2115 alen = sizeof(addr_un);
2116 #else /* DRIVER_TEST_UNIX */
2119 #endif /* DRIVER_TEST_UNIX */
2122 if (sendto(drv->test_socket, msg, msg_len, 0, addr, alen) < 0) {
2123 perror("sendmsg(test_socket)");
2133 static int wpa_driver_test_get_capa(void *priv, struct wpa_driver_capa *capa)
2135 struct wpa_driver_test_data *drv = priv;
2136 os_memset(capa, 0, sizeof(*capa));
2137 capa->key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2138 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2139 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2140 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
2141 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE |
2142 WPA_DRIVER_CAPA_KEY_MGMT_FT |
2143 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2144 capa->enc = WPA_DRIVER_CAPA_ENC_WEP40 |
2145 WPA_DRIVER_CAPA_ENC_WEP104 |
2146 WPA_DRIVER_CAPA_ENC_TKIP |
2147 WPA_DRIVER_CAPA_ENC_CCMP;
2148 capa->auth = WPA_DRIVER_AUTH_OPEN |
2149 WPA_DRIVER_AUTH_SHARED |
2150 WPA_DRIVER_AUTH_LEAP;
2152 capa->flags |= WPA_DRIVER_FLAGS_USER_SPACE_MLME;
2153 capa->max_scan_ssids = 2;
2159 static int wpa_driver_test_mlme_setprotection(void *priv, const u8 *addr,
2163 wpa_printf(MSG_DEBUG, "%s: protect_type=%d key_type=%d",
2164 __func__, protect_type, key_type);
2167 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR,
2168 __func__, MAC2STR(addr));
2175 #ifdef CONFIG_CLIENT_MLME
2176 static int wpa_driver_test_set_channel(void *priv, hostapd_hw_mode phymode,
2179 wpa_printf(MSG_DEBUG, "%s: phymode=%d chan=%d freq=%d",
2180 __func__, phymode, chan, freq);
2185 static int wpa_driver_test_send_mlme(void *priv, const u8 *data,
2188 struct wpa_driver_test_data *drv = priv;
2191 struct sockaddr_un addr;
2193 struct dirent *dent;
2196 wpa_hexdump(MSG_MSGDUMP, "test_send_mlme", data, data_len);
2201 io[0].iov_base = "MLME ";
2203 io[1].iov_base = (u8 *) data;
2204 io[1].iov_len = data_len;
2206 os_memset(&msg, 0, sizeof(msg));
2209 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
2210 drv->test_dir == NULL) {
2211 if (drv->hostapd_addr_udp_set) {
2212 msg.msg_name = &drv->hostapd_addr_udp;
2213 msg.msg_namelen = sizeof(drv->hostapd_addr_udp);
2215 #ifdef DRIVER_TEST_UNIX
2216 msg.msg_name = &drv->hostapd_addr;
2217 msg.msg_namelen = sizeof(drv->hostapd_addr);
2218 #endif /* DRIVER_TEST_UNIX */
2220 } else if (os_memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0)
2222 dir = opendir(drv->test_dir);
2225 while ((dent = readdir(dir))) {
2226 #ifdef _DIRENT_HAVE_D_TYPE
2227 /* Skip the file if it is not a socket.
2228 * Also accept DT_UNKNOWN (0) in case
2229 * the C library or underlying file
2230 * system does not support d_type. */
2231 if (dent->d_type != DT_SOCK &&
2232 dent->d_type != DT_UNKNOWN)
2234 #endif /* _DIRENT_HAVE_D_TYPE */
2235 if (os_strcmp(dent->d_name, ".") == 0 ||
2236 os_strcmp(dent->d_name, "..") == 0)
2238 wpa_printf(MSG_DEBUG, "%s: Send broadcast MLME to %s",
2239 __func__, dent->d_name);
2240 os_memset(&addr, 0, sizeof(addr));
2241 addr.sun_family = AF_UNIX;
2242 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2243 "%s/%s", drv->test_dir, dent->d_name);
2245 msg.msg_name = &addr;
2246 msg.msg_namelen = sizeof(addr);
2248 if (sendmsg(drv->test_socket, &msg, 0) < 0)
2249 perror("sendmsg(test_socket)");
2255 os_memset(&addr, 0, sizeof(addr));
2256 addr.sun_family = AF_UNIX;
2257 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2258 "%s/AP-" MACSTR, drv->test_dir, MAC2STR(dest));
2259 if (stat(addr.sun_path, &st) < 0) {
2260 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2262 drv->test_dir, MAC2STR(dest));
2264 msg.msg_name = &addr;
2265 msg.msg_namelen = sizeof(addr);
2268 if (sendmsg(drv->test_socket, &msg, 0) < 0) {
2269 perror("sendmsg(test_socket)");
2277 static int wpa_driver_test_mlme_add_sta(void *priv, const u8 *addr,
2278 const u8 *supp_rates,
2279 size_t supp_rates_len)
2281 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2286 static int wpa_driver_test_mlme_remove_sta(void *priv, const u8 *addr)
2288 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2293 static int wpa_driver_test_set_ssid(void *priv, const u8 *ssid,
2296 wpa_printf(MSG_DEBUG, "%s", __func__);
2301 static int wpa_driver_test_set_bssid(void *priv, const u8 *bssid)
2303 wpa_printf(MSG_DEBUG, "%s: bssid=" MACSTR, __func__, MAC2STR(bssid));
2306 #endif /* CONFIG_CLIENT_MLME */
2309 static int wpa_driver_test_set_probe_req_ie(void *priv, const u8 *ies,
2312 struct wpa_driver_test_data *drv = priv;
2314 os_free(drv->probe_req_ie);
2316 drv->probe_req_ie = os_malloc(ies_len);
2317 if (drv->probe_req_ie == NULL) {
2318 drv->probe_req_ie_len = 0;
2321 os_memcpy(drv->probe_req_ie, ies, ies_len);
2322 drv->probe_req_ie_len = ies_len;
2324 drv->probe_req_ie = NULL;
2325 drv->probe_req_ie_len = 0;
2331 static void * wpa_driver_test_global_init(void)
2333 struct wpa_driver_test_global *global;
2335 global = os_zalloc(sizeof(*global));
2340 static void wpa_driver_test_global_deinit(void *priv)
2342 struct wpa_driver_test_global *global = priv;
2347 static struct wpa_interface_info *
2348 wpa_driver_test_get_interfaces(void *global_priv)
2350 /* struct wpa_driver_test_global *global = priv; */
2351 struct wpa_interface_info *iface;
2353 iface = os_zalloc(sizeof(*iface));
2356 iface->ifname = os_strdup("sta0");
2357 iface->desc = os_strdup("test interface 0");
2358 iface->drv_name = "test";
2359 iface->next = os_zalloc(sizeof(*iface));
2361 iface->next->ifname = os_strdup("sta1");
2362 iface->next->desc = os_strdup("test interface 1");
2363 iface->next->drv_name = "test";
2369 #endif /* HOSTAPD */
2372 #if defined(HOSTAPD) || defined(CONFIG_CLIENT_MLME)
2373 static struct hostapd_hw_modes *
2374 wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
2376 struct hostapd_hw_modes *modes;
2380 modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
2383 modes[0].mode = HOSTAPD_MODE_IEEE80211G;
2384 modes[0].num_channels = 1;
2385 modes[0].num_rates = 1;
2386 modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2387 modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2388 if (modes[0].channels == NULL || modes[0].rates == NULL)
2390 modes[0].channels[0].chan = 1;
2391 modes[0].channels[0].freq = 2412;
2392 modes[0].channels[0].flag = 0;
2393 modes[0].rates[0].rate = 10;
2394 modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2395 HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
2397 modes[1].mode = HOSTAPD_MODE_IEEE80211B;
2398 modes[1].num_channels = 1;
2399 modes[1].num_rates = 1;
2400 modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2401 modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2402 if (modes[1].channels == NULL || modes[1].rates == NULL)
2404 modes[1].channels[0].chan = 1;
2405 modes[1].channels[0].freq = 2412;
2406 modes[1].channels[0].flag = 0;
2407 modes[1].rates[0].rate = 10;
2408 modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2409 HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
2411 modes[2].mode = HOSTAPD_MODE_IEEE80211A;
2412 modes[2].num_channels = 1;
2413 modes[2].num_rates = 1;
2414 modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2415 modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2416 if (modes[2].channels == NULL || modes[2].rates == NULL)
2418 modes[2].channels[0].chan = 60;
2419 modes[2].channels[0].freq = 5300;
2420 modes[2].channels[0].flag = 0;
2421 modes[2].rates[0].rate = 60;
2422 modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2423 HOSTAPD_RATE_MANDATORY;
2430 for (i = 0; i < *num_modes; i++) {
2431 os_free(modes[i].channels);
2432 os_free(modes[i].rates);
2438 #endif /* HOSTAPD || CONFIG_CLIENT_MLME */
2441 const struct wpa_driver_ops wpa_driver_test_ops = {
2443 "wpa_supplicant test driver",
2445 .hapd_init = test_driver_init,
2446 .hapd_deinit = test_driver_deinit,
2447 .hapd_send_eapol = test_driver_send_eapol,
2448 .send_mlme = wpa_driver_test_send_mlme,
2449 .set_generic_elem = test_driver_set_generic_elem,
2450 .sta_deauth = test_driver_sta_deauth,
2451 .sta_disassoc = test_driver_sta_disassoc,
2452 .get_hw_feature_data = wpa_driver_test_get_hw_feature_data,
2453 .bss_add = test_driver_bss_add,
2454 .bss_remove = test_driver_bss_remove,
2455 .if_add = test_driver_if_add,
2456 .if_update = test_driver_if_update,
2457 .if_remove = test_driver_if_remove,
2458 .valid_bss_mask = test_driver_valid_bss_mask,
2459 .hapd_set_ssid = test_driver_set_ssid,
2460 .set_privacy = test_driver_set_privacy,
2461 .hapd_set_key = test_driver_set_key,
2462 .set_sta_vlan = test_driver_set_sta_vlan,
2463 .sta_add = test_driver_sta_add,
2464 .send_ether = test_driver_send_ether,
2465 .set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
2466 .set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
2468 wpa_driver_test_get_bssid,
2469 wpa_driver_test_get_ssid,
2470 wpa_driver_test_set_wpa,
2471 wpa_driver_test_set_key,
2473 wpa_driver_test_deinit,
2474 wpa_driver_test_set_param,
2475 NULL /* set_countermeasures */,
2476 NULL /* set_drop_unencrypted */,
2478 NULL /* get_scan_results */,
2479 wpa_driver_test_deauthenticate,
2480 wpa_driver_test_disassociate,
2481 wpa_driver_test_associate,
2482 NULL /* set_auth_alg */,
2483 NULL /* add_pmkid */,
2484 NULL /* remove_pmkid */,
2485 NULL /* flush_pmkid */,
2486 wpa_driver_test_get_capa,
2488 NULL /* get_ifname */,
2489 wpa_driver_test_get_mac_addr,
2490 wpa_driver_test_send_eapol,
2491 NULL /* set_operstate */,
2492 wpa_driver_test_mlme_setprotection,
2493 #ifdef CONFIG_CLIENT_MLME
2494 wpa_driver_test_get_hw_feature_data,
2495 wpa_driver_test_set_channel,
2496 wpa_driver_test_set_ssid,
2497 wpa_driver_test_set_bssid,
2498 wpa_driver_test_send_mlme,
2499 wpa_driver_test_mlme_add_sta,
2500 wpa_driver_test_mlme_remove_sta,
2501 #else /* CONFIG_CLIENT_MLME */
2502 NULL /* get_hw_feature_data */,
2503 NULL /* set_channel */,
2504 NULL /* set_ssid */,
2505 NULL /* set_bssid */,
2506 NULL /* send_mlme */,
2507 NULL /* mlme_add_sta */,
2508 NULL /* mlme_remove_sta */,
2509 #endif /* CONFIG_CLIENT_MLME */
2510 NULL /* update_ft_ies */,
2511 NULL /* send_ft_action */,
2512 wpa_driver_test_get_scan_results2,
2513 wpa_driver_test_set_probe_req_ie,
2514 NULL /* set_mode */,
2515 NULL /* set_country */,
2516 wpa_driver_test_global_init,
2517 wpa_driver_test_global_deinit,
2518 wpa_driver_test_init2,
2519 wpa_driver_test_get_interfaces,
2520 wpa_driver_test_scan,
2521 NULL /* authenticate */,
2522 NULL /* set_beacon */,
2523 NULL /* set_beacon_int */,
2524 NULL /* hapd_init */,
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 */,
2542 NULL /* get_inact_sec */,
2543 NULL /* sta_clear_stats */,
2544 NULL /* set_freq */,
2546 NULL /* set_frag */,
2547 NULL /* set_retry */,
2548 NULL /* sta_set_flags */,
2549 NULL /* set_rate_sets */,
2550 NULL /* set_ieee80211d */,
2551 NULL /* hapd_set_beacon */,
2552 NULL /* set_internal_bridge */,
2553 NULL /* set_broadcast_ssid */,
2554 NULL /* set_cts_protect */,
2555 NULL /* set_preamble */,
2556 NULL /* set_short_slot_time */,
2557 NULL /* set_tx_queue_params */,
2559 NULL /* bss_remove */,
2560 NULL /* valid_bss_mask */,
2561 NULL /* passive_scan */,
2563 NULL /* if_update */,
2564 NULL /* if_remove */,
2565 NULL /* set_sta_vlan */,
2567 NULL /* send_ether */,
2568 NULL /* set_radius_acl_auth */,
2569 NULL /* set_radius_acl_expire */,
2570 NULL /* set_ht_params */,
2571 NULL /* set_wps_beacon_ie */,
2572 NULL /* set_wps_probe_resp_ie */
2573 #endif /* HOSTAPD */