Use generic driver event notification for AP mode assoc/disassoc
[hostap-gosc2009.git] / src / drivers / driver_test.c
blob818c197183ea3774bc7f9a4173aa0ca1a9f080e7
1 /*
2 * Testing driver interface for a simulated network driver
3 * Copyright (c) 2004-2009, 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
10 * license.
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
18 #include <winsock2.h>
19 #endif /* CONFIG_NATIVE_WINDOWS */
21 #include "utils/includes.h"
23 #ifndef CONFIG_NATIVE_WINDOWS
24 #include <sys/un.h>
25 #include <dirent.h>
26 #include <sys/stat.h>
27 #define DRIVER_TEST_UNIX
28 #endif /* CONFIG_NATIVE_WINDOWS */
30 #include "utils/common.h"
31 #include "utils/eloop.h"
32 #include "utils/trace.h"
33 #include "common/ieee802_11_defs.h"
34 #include "crypto/sha1.h"
35 #include "l2_packet/l2_packet.h"
36 #include "driver.h"
39 struct test_client_socket {
40 struct test_client_socket *next;
41 u8 addr[ETH_ALEN];
42 struct sockaddr_un un;
43 socklen_t unlen;
44 struct test_driver_bss *bss;
47 struct test_driver_bss {
48 struct test_driver_bss *next;
49 void *bss_ctx;
50 char ifname[IFNAMSIZ + 1];
51 u8 bssid[ETH_ALEN];
52 u8 *ie;
53 size_t ielen;
54 u8 *wps_beacon_ie;
55 size_t wps_beacon_ie_len;
56 u8 *wps_probe_resp_ie;
57 size_t wps_probe_resp_ie_len;
58 u8 ssid[32];
59 size_t ssid_len;
60 int privacy;
63 struct wpa_driver_test_global {
64 int bss_add_used;
65 u8 req_addr[ETH_ALEN];
68 struct wpa_driver_test_data {
69 struct wpa_driver_test_global *global;
70 void *ctx;
71 WPA_TRACE_REF(ctx);
72 char ifname[IFNAMSIZ + 1];
73 u8 own_addr[ETH_ALEN];
74 int test_socket;
75 #ifdef DRIVER_TEST_UNIX
76 struct sockaddr_un hostapd_addr;
77 #endif /* DRIVER_TEST_UNIX */
78 int hostapd_addr_set;
79 struct sockaddr_in hostapd_addr_udp;
80 int hostapd_addr_udp_set;
81 char *own_socket_path;
82 char *test_dir;
83 u8 bssid[ETH_ALEN];
84 u8 ssid[32];
85 size_t ssid_len;
86 #define MAX_SCAN_RESULTS 30
87 struct wpa_scan_res *scanres[MAX_SCAN_RESULTS];
88 size_t num_scanres;
89 int use_associnfo;
90 u8 assoc_wpa_ie[80];
91 size_t assoc_wpa_ie_len;
92 int use_mlme;
93 int associated;
94 u8 *probe_req_ie;
95 size_t probe_req_ie_len;
96 int ibss;
97 int privacy;
98 int ap;
100 struct test_client_socket *cli;
101 struct test_driver_bss *bss;
102 int udp_port;
104 int alloc_iface_idx;
106 int probe_req_report;
107 unsigned int remain_on_channel_freq;
108 unsigned int remain_on_channel_duration;
110 int current_freq;
114 static void wpa_driver_test_deinit(void *priv);
115 static int wpa_driver_test_attach(struct wpa_driver_test_data *drv,
116 const char *dir, int ap);
117 static void wpa_driver_test_close_test_socket(
118 struct wpa_driver_test_data *drv);
119 static void test_remain_on_channel_timeout(void *eloop_ctx, void *timeout_ctx);
122 static void test_driver_free_bss(struct test_driver_bss *bss)
124 os_free(bss->ie);
125 os_free(bss->wps_beacon_ie);
126 os_free(bss->wps_probe_resp_ie);
127 os_free(bss);
131 static void test_driver_free_bsses(struct wpa_driver_test_data *drv)
133 struct test_driver_bss *bss, *prev_bss;
135 bss = drv->bss;
136 while (bss) {
137 prev_bss = bss;
138 bss = bss->next;
139 test_driver_free_bss(prev_bss);
142 drv->bss = NULL;
146 static struct test_client_socket *
147 test_driver_get_cli(struct wpa_driver_test_data *drv, struct sockaddr_un *from,
148 socklen_t fromlen)
150 struct test_client_socket *cli = drv->cli;
152 while (cli) {
153 if (cli->unlen == fromlen &&
154 strncmp(cli->un.sun_path, from->sun_path,
155 fromlen - sizeof(cli->un.sun_family)) == 0)
156 return cli;
157 cli = cli->next;
160 return NULL;
164 static int test_driver_send_eapol(void *priv, const u8 *addr, const u8 *data,
165 size_t data_len, int encrypt,
166 const u8 *own_addr)
168 struct wpa_driver_test_data *drv = priv;
169 struct test_client_socket *cli;
170 struct msghdr msg;
171 struct iovec io[3];
172 struct l2_ethhdr eth;
174 if (drv->test_socket < 0)
175 return -1;
177 cli = drv->cli;
178 while (cli) {
179 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
180 break;
181 cli = cli->next;
184 if (!cli) {
185 wpa_printf(MSG_DEBUG, "%s: no destination client entry",
186 __func__);
187 return -1;
190 memcpy(eth.h_dest, addr, ETH_ALEN);
191 memcpy(eth.h_source, own_addr, ETH_ALEN);
192 eth.h_proto = host_to_be16(ETH_P_EAPOL);
194 io[0].iov_base = "EAPOL ";
195 io[0].iov_len = 6;
196 io[1].iov_base = &eth;
197 io[1].iov_len = sizeof(eth);
198 io[2].iov_base = (u8 *) data;
199 io[2].iov_len = data_len;
201 memset(&msg, 0, sizeof(msg));
202 msg.msg_iov = io;
203 msg.msg_iovlen = 3;
204 msg.msg_name = &cli->un;
205 msg.msg_namelen = cli->unlen;
206 return sendmsg(drv->test_socket, &msg, 0);
210 static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
211 u16 proto, const u8 *data, size_t data_len)
213 struct wpa_driver_test_data *drv = priv;
214 struct msghdr msg;
215 struct iovec io[3];
216 struct l2_ethhdr eth;
217 char desttxt[30];
218 struct sockaddr_un addr;
219 struct dirent *dent;
220 DIR *dir;
221 int ret = 0, broadcast = 0, count = 0;
223 if (drv->test_socket < 0 || drv->test_dir == NULL) {
224 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d "
225 "test_dir=%p)",
226 __func__, drv->test_socket, drv->test_dir);
227 return -1;
230 broadcast = memcmp(dst, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
231 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dst));
233 memcpy(eth.h_dest, dst, ETH_ALEN);
234 memcpy(eth.h_source, src, ETH_ALEN);
235 eth.h_proto = host_to_be16(proto);
237 io[0].iov_base = "ETHER ";
238 io[0].iov_len = 6;
239 io[1].iov_base = &eth;
240 io[1].iov_len = sizeof(eth);
241 io[2].iov_base = (u8 *) data;
242 io[2].iov_len = data_len;
244 memset(&msg, 0, sizeof(msg));
245 msg.msg_iov = io;
246 msg.msg_iovlen = 3;
248 dir = opendir(drv->test_dir);
249 if (dir == NULL) {
250 perror("test_driver: opendir");
251 return -1;
253 while ((dent = readdir(dir))) {
254 #ifdef _DIRENT_HAVE_D_TYPE
255 /* Skip the file if it is not a socket. Also accept
256 * DT_UNKNOWN (0) in case the C library or underlying file
257 * system does not support d_type. */
258 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
259 continue;
260 #endif /* _DIRENT_HAVE_D_TYPE */
261 if (strcmp(dent->d_name, ".") == 0 ||
262 strcmp(dent->d_name, "..") == 0)
263 continue;
265 memset(&addr, 0, sizeof(addr));
266 addr.sun_family = AF_UNIX;
267 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
268 drv->test_dir, dent->d_name);
270 if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
271 continue;
272 if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
273 continue;
275 wpa_printf(MSG_DEBUG, "%s: Send ether frame to %s",
276 __func__, dent->d_name);
278 msg.msg_name = &addr;
279 msg.msg_namelen = sizeof(addr);
280 ret = sendmsg(drv->test_socket, &msg, 0);
281 if (ret < 0)
282 perror("driver_test: sendmsg");
283 count++;
285 closedir(dir);
287 if (!broadcast && count == 0) {
288 wpa_printf(MSG_DEBUG, "%s: Destination " MACSTR " not found",
289 __func__, MAC2STR(dst));
290 return -1;
293 return ret;
297 static int wpa_driver_test_send_mlme(void *priv, const u8 *data,
298 size_t data_len)
300 struct wpa_driver_test_data *drv = priv;
301 struct msghdr msg;
302 struct iovec io[2];
303 const u8 *dest;
304 struct sockaddr_un addr;
305 struct dirent *dent;
306 DIR *dir;
307 int broadcast;
308 int ret = 0;
309 struct ieee80211_hdr *hdr;
310 u16 fc;
311 char cmd[50];
312 int freq;
313 #ifdef HOSTAPD
314 char desttxt[30];
315 #endif /* HOSTAPD */
316 union wpa_event_data event;
318 wpa_hexdump(MSG_MSGDUMP, "test_send_mlme", data, data_len);
319 if (drv->test_socket < 0 || data_len < 10) {
320 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d len=%lu"
321 " test_dir=%p)",
322 __func__, drv->test_socket,
323 (unsigned long) data_len,
324 drv->test_dir);
325 return -1;
328 dest = data + 4;
329 broadcast = os_memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
331 #ifdef HOSTAPD
332 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dest));
333 #endif /* HOSTAPD */
335 if (drv->remain_on_channel_freq)
336 freq = drv->remain_on_channel_freq;
337 else
338 freq = drv->current_freq;
339 wpa_printf(MSG_DEBUG, "test_driver(%s): MLME TX on freq %d MHz",
340 drv->ifname, freq);
341 os_snprintf(cmd, sizeof(cmd), "MLME freq=%d ", freq);
342 io[0].iov_base = cmd;
343 io[0].iov_len = os_strlen(cmd);
344 io[1].iov_base = (void *) data;
345 io[1].iov_len = data_len;
347 os_memset(&msg, 0, sizeof(msg));
348 msg.msg_iov = io;
349 msg.msg_iovlen = 2;
351 #ifdef HOSTAPD
352 if (drv->test_dir == NULL) {
353 wpa_printf(MSG_DEBUG, "%s: test_dir == NULL", __func__);
354 return -1;
357 dir = opendir(drv->test_dir);
358 if (dir == NULL) {
359 perror("test_driver: opendir");
360 return -1;
362 while ((dent = readdir(dir))) {
363 #ifdef _DIRENT_HAVE_D_TYPE
364 /* Skip the file if it is not a socket. Also accept
365 * DT_UNKNOWN (0) in case the C library or underlying file
366 * system does not support d_type. */
367 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
368 continue;
369 #endif /* _DIRENT_HAVE_D_TYPE */
370 if (os_strcmp(dent->d_name, ".") == 0 ||
371 os_strcmp(dent->d_name, "..") == 0)
372 continue;
374 os_memset(&addr, 0, sizeof(addr));
375 addr.sun_family = AF_UNIX;
376 os_snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
377 drv->test_dir, dent->d_name);
379 if (os_strcmp(addr.sun_path, drv->own_socket_path) == 0)
380 continue;
381 if (!broadcast && os_strstr(dent->d_name, desttxt) == NULL)
382 continue;
384 wpa_printf(MSG_DEBUG, "%s: Send management frame to %s",
385 __func__, dent->d_name);
387 msg.msg_name = &addr;
388 msg.msg_namelen = sizeof(addr);
389 ret = sendmsg(drv->test_socket, &msg, 0);
390 if (ret < 0)
391 perror("driver_test: sendmsg(test_socket)");
393 closedir(dir);
394 #else /* HOSTAPD */
396 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
397 drv->test_dir == NULL) {
398 if (drv->hostapd_addr_udp_set) {
399 msg.msg_name = &drv->hostapd_addr_udp;
400 msg.msg_namelen = sizeof(drv->hostapd_addr_udp);
401 } else {
402 #ifdef DRIVER_TEST_UNIX
403 msg.msg_name = &drv->hostapd_addr;
404 msg.msg_namelen = sizeof(drv->hostapd_addr);
405 #endif /* DRIVER_TEST_UNIX */
407 } else if (broadcast) {
408 dir = opendir(drv->test_dir);
409 if (dir == NULL)
410 return -1;
411 while ((dent = readdir(dir))) {
412 #ifdef _DIRENT_HAVE_D_TYPE
413 /* Skip the file if it is not a socket.
414 * Also accept DT_UNKNOWN (0) in case
415 * the C library or underlying file
416 * system does not support d_type. */
417 if (dent->d_type != DT_SOCK &&
418 dent->d_type != DT_UNKNOWN)
419 continue;
420 #endif /* _DIRENT_HAVE_D_TYPE */
421 if (os_strcmp(dent->d_name, ".") == 0 ||
422 os_strcmp(dent->d_name, "..") == 0)
423 continue;
424 wpa_printf(MSG_DEBUG, "%s: Send broadcast MLME to %s",
425 __func__, dent->d_name);
426 os_memset(&addr, 0, sizeof(addr));
427 addr.sun_family = AF_UNIX;
428 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
429 "%s/%s", drv->test_dir, dent->d_name);
431 msg.msg_name = &addr;
432 msg.msg_namelen = sizeof(addr);
434 ret = sendmsg(drv->test_socket, &msg, 0);
435 if (ret < 0)
436 perror("driver_test: sendmsg(test_socket)");
438 closedir(dir);
439 return ret;
440 } else {
441 struct stat st;
442 os_memset(&addr, 0, sizeof(addr));
443 addr.sun_family = AF_UNIX;
444 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
445 "%s/AP-" MACSTR, drv->test_dir, MAC2STR(dest));
446 if (stat(addr.sun_path, &st) < 0) {
447 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
448 "%s/STA-" MACSTR,
449 drv->test_dir, MAC2STR(dest));
451 msg.msg_name = &addr;
452 msg.msg_namelen = sizeof(addr);
455 if (sendmsg(drv->test_socket, &msg, 0) < 0) {
456 perror("sendmsg(test_socket)");
457 return -1;
459 #endif /* HOSTAPD */
461 hdr = (struct ieee80211_hdr *) data;
462 fc = le_to_host16(hdr->frame_control);
464 os_memset(&event, 0, sizeof(event));
465 event.tx_status.type = WLAN_FC_GET_TYPE(fc);
466 event.tx_status.stype = WLAN_FC_GET_STYPE(fc);
467 event.tx_status.dst = hdr->addr1;
468 event.tx_status.data = data;
469 event.tx_status.data_len = data_len;
470 event.tx_status.ack = ret >= 0;
471 wpa_supplicant_event(drv->ctx, EVENT_TX_STATUS, &event);
473 return ret;
477 static void test_driver_scan(struct wpa_driver_test_data *drv,
478 struct sockaddr_un *from, socklen_t fromlen,
479 char *data)
481 char buf[512], *pos, *end;
482 int ret;
483 struct test_driver_bss *bss;
484 u8 sa[ETH_ALEN];
485 u8 ie[512];
486 size_t ielen;
487 union wpa_event_data event;
489 /* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
491 wpa_printf(MSG_DEBUG, "test_driver: SCAN");
493 if (*data) {
494 if (*data != ' ' ||
495 hwaddr_aton(data + 1, sa)) {
496 wpa_printf(MSG_DEBUG, "test_driver: Unexpected SCAN "
497 "command format");
498 return;
501 data += 18;
502 while (*data == ' ')
503 data++;
504 ielen = os_strlen(data) / 2;
505 if (ielen > sizeof(ie))
506 ielen = sizeof(ie);
507 if (hexstr2bin(data, ie, ielen) < 0)
508 ielen = 0;
510 wpa_printf(MSG_DEBUG, "test_driver: Scan from " MACSTR,
511 MAC2STR(sa));
512 wpa_hexdump(MSG_MSGDUMP, "test_driver: scan IEs", ie, ielen);
514 os_memset(&event, 0, sizeof(event));
515 event.rx_probe_req.sa = sa;
516 event.rx_probe_req.ie = ie;
517 event.rx_probe_req.ie_len = ielen;
518 wpa_supplicant_event(drv->ctx, EVENT_RX_PROBE_REQ, &event);
521 for (bss = drv->bss; bss; bss = bss->next) {
522 pos = buf;
523 end = buf + sizeof(buf);
525 /* reply: SCANRESP BSSID SSID IEs */
526 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
527 MAC2STR(bss->bssid));
528 if (ret < 0 || ret >= end - pos)
529 return;
530 pos += ret;
531 pos += wpa_snprintf_hex(pos, end - pos,
532 bss->ssid, bss->ssid_len);
533 ret = snprintf(pos, end - pos, " ");
534 if (ret < 0 || ret >= end - pos)
535 return;
536 pos += ret;
537 pos += wpa_snprintf_hex(pos, end - pos, bss->ie, bss->ielen);
538 pos += wpa_snprintf_hex(pos, end - pos, bss->wps_probe_resp_ie,
539 bss->wps_probe_resp_ie_len);
541 if (bss->privacy) {
542 ret = snprintf(pos, end - pos, " PRIVACY");
543 if (ret < 0 || ret >= end - pos)
544 return;
545 pos += ret;
548 sendto(drv->test_socket, buf, pos - buf, 0,
549 (struct sockaddr *) from, fromlen);
554 static void test_driver_assoc(struct wpa_driver_test_data *drv,
555 struct sockaddr_un *from, socklen_t fromlen,
556 char *data)
558 struct test_client_socket *cli;
559 u8 ie[256], ssid[32];
560 size_t ielen, ssid_len = 0;
561 char *pos, *pos2, cmd[50];
562 struct test_driver_bss *bss;
564 /* data: STA-addr SSID(hex) IEs(hex) */
566 cli = os_zalloc(sizeof(*cli));
567 if (cli == NULL)
568 return;
570 if (hwaddr_aton(data, cli->addr)) {
571 printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
572 data);
573 os_free(cli);
574 return;
576 pos = data + 17;
577 while (*pos == ' ')
578 pos++;
579 pos2 = strchr(pos, ' ');
580 ielen = 0;
581 if (pos2) {
582 ssid_len = (pos2 - pos) / 2;
583 if (hexstr2bin(pos, ssid, ssid_len) < 0) {
584 wpa_printf(MSG_DEBUG, "%s: Invalid SSID", __func__);
585 os_free(cli);
586 return;
588 wpa_hexdump_ascii(MSG_DEBUG, "test_driver_assoc: SSID",
589 ssid, ssid_len);
591 pos = pos2 + 1;
592 ielen = strlen(pos) / 2;
593 if (ielen > sizeof(ie))
594 ielen = sizeof(ie);
595 if (hexstr2bin(pos, ie, ielen) < 0)
596 ielen = 0;
599 for (bss = drv->bss; bss; bss = bss->next) {
600 if (bss->ssid_len == ssid_len &&
601 memcmp(bss->ssid, ssid, ssid_len) == 0)
602 break;
604 if (bss == NULL) {
605 wpa_printf(MSG_DEBUG, "%s: No matching SSID found from "
606 "configured BSSes", __func__);
607 os_free(cli);
608 return;
611 cli->bss = bss;
612 memcpy(&cli->un, from, sizeof(cli->un));
613 cli->unlen = fromlen;
614 cli->next = drv->cli;
615 drv->cli = cli;
616 wpa_hexdump_ascii(MSG_DEBUG, "test_socket: ASSOC sun_path",
617 (const u8 *) cli->un.sun_path,
618 cli->unlen - sizeof(cli->un.sun_family));
620 snprintf(cmd, sizeof(cmd), "ASSOCRESP " MACSTR " 0",
621 MAC2STR(bss->bssid));
622 sendto(drv->test_socket, cmd, strlen(cmd), 0,
623 (struct sockaddr *) from, fromlen);
625 drv_event_assoc(bss->bss_ctx, cli->addr, ie, ielen);
629 static void test_driver_disassoc(struct wpa_driver_test_data *drv,
630 struct sockaddr_un *from, socklen_t fromlen)
632 struct test_client_socket *cli;
634 cli = test_driver_get_cli(drv, from, fromlen);
635 if (!cli)
636 return;
638 drv_event_disassoc(drv->ctx, cli->addr);
642 static void test_driver_eapol(struct wpa_driver_test_data *drv,
643 struct sockaddr_un *from, socklen_t fromlen,
644 u8 *data, size_t datalen)
646 #ifdef HOSTAPD
647 struct test_client_socket *cli;
648 #endif /* HOSTAPD */
649 const u8 *src = NULL;
650 union wpa_event_data event;
651 void *ctx;
653 if (datalen > 14) {
654 /* Skip Ethernet header */
655 src = data + ETH_ALEN;
656 wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
657 MACSTR " proto=%04x",
658 MAC2STR(data), MAC2STR(src),
659 WPA_GET_BE16(data + 2 * ETH_ALEN));
660 data += 14;
661 datalen -= 14;
664 os_memset(&event, 0, sizeof(event));
665 event.eapol_rx.data = data;
666 event.eapol_rx.data_len = datalen;
668 #ifdef HOSTAPD
669 cli = test_driver_get_cli(drv, from, fromlen);
670 if (cli) {
671 event.eapol_rx.src = cli->addr;
672 ctx = cli->bss->bss_ctx;
673 } else {
674 wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
675 "client");
676 return;
678 #else /* HOSTAPD */
679 if (src) {
680 event.eapol_rx.src = src;
681 ctx = drv->ctx;
682 } else
683 return;
684 #endif /* HOSTAPD */
686 wpa_supplicant_event(ctx, EVENT_EAPOL_RX, &event);
690 static void test_driver_ether(struct wpa_driver_test_data *drv,
691 struct sockaddr_un *from, socklen_t fromlen,
692 u8 *data, size_t datalen)
694 struct l2_ethhdr *eth;
696 if (datalen < sizeof(*eth))
697 return;
699 eth = (struct l2_ethhdr *) data;
700 wpa_printf(MSG_DEBUG, "test_driver: RX ETHER dst=" MACSTR " src="
701 MACSTR " proto=%04x",
702 MAC2STR(eth->h_dest), MAC2STR(eth->h_source),
703 be_to_host16(eth->h_proto));
705 #ifdef CONFIG_IEEE80211R
706 if (be_to_host16(eth->h_proto) == ETH_P_RRB) {
707 union wpa_event_data ev;
708 os_memset(&ev, 0, sizeof(ev));
709 ev.ft_rrb_rx.src = eth->h_source;
710 ev.ft_rrb_rx.data = data + sizeof(*eth);
711 ev.ft_rrb_rx.data_len = datalen - sizeof(*eth);
713 #endif /* CONFIG_IEEE80211R */
717 static void test_driver_mlme(struct wpa_driver_test_data *drv,
718 struct sockaddr_un *from, socklen_t fromlen,
719 u8 *data, size_t datalen)
721 struct ieee80211_hdr *hdr;
722 u16 fc;
723 union wpa_event_data event;
724 int freq = 0, own_freq;
726 if (datalen > 6 && os_memcmp(data, "freq=", 5) == 0) {
727 size_t pos;
728 for (pos = 5; pos < datalen; pos++) {
729 if (data[pos] == ' ')
730 break;
732 if (pos < datalen) {
733 freq = atoi((const char *) &data[5]);
734 wpa_printf(MSG_DEBUG, "test_driver(%s): MLME RX on "
735 "freq %d MHz", drv->ifname, freq);
736 pos++;
737 data += pos;
738 datalen -= pos;
742 if (drv->remain_on_channel_freq)
743 own_freq = drv->remain_on_channel_freq;
744 else
745 own_freq = drv->current_freq;
747 if (freq && own_freq && freq != own_freq) {
748 wpa_printf(MSG_DEBUG, "test_driver(%s): Ignore MLME RX on "
749 "another frequency %d MHz (own %d MHz)",
750 drv->ifname, freq, own_freq);
751 return;
754 hdr = (struct ieee80211_hdr *) data;
756 if (test_driver_get_cli(drv, from, fromlen) == NULL && datalen >= 16) {
757 struct test_client_socket *cli;
758 cli = os_zalloc(sizeof(*cli));
759 if (cli == NULL)
760 return;
761 wpa_printf(MSG_DEBUG, "Adding client entry for " MACSTR,
762 MAC2STR(hdr->addr2));
763 memcpy(cli->addr, hdr->addr2, ETH_ALEN);
764 memcpy(&cli->un, from, sizeof(cli->un));
765 cli->unlen = fromlen;
766 cli->next = drv->cli;
767 drv->cli = cli;
770 wpa_hexdump(MSG_MSGDUMP, "test_driver_mlme: received frame",
771 data, datalen);
772 fc = le_to_host16(hdr->frame_control);
773 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT) {
774 wpa_printf(MSG_ERROR, "%s: received non-mgmt frame",
775 __func__);
776 return;
779 os_memset(&event, 0, sizeof(event));
780 event.rx_mgmt.frame = data;
781 event.rx_mgmt.frame_len = datalen;
782 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
786 static void test_driver_receive_unix(int sock, void *eloop_ctx, void *sock_ctx)
788 struct wpa_driver_test_data *drv = eloop_ctx;
789 char buf[2000];
790 int res;
791 struct sockaddr_un from;
792 socklen_t fromlen = sizeof(from);
794 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
795 (struct sockaddr *) &from, &fromlen);
796 if (res < 0) {
797 perror("recvfrom(test_socket)");
798 return;
800 buf[res] = '\0';
802 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
804 if (strncmp(buf, "SCAN", 4) == 0) {
805 test_driver_scan(drv, &from, fromlen, buf + 4);
806 } else if (strncmp(buf, "ASSOC ", 6) == 0) {
807 test_driver_assoc(drv, &from, fromlen, buf + 6);
808 } else if (strcmp(buf, "DISASSOC") == 0) {
809 test_driver_disassoc(drv, &from, fromlen);
810 } else if (strncmp(buf, "EAPOL ", 6) == 0) {
811 test_driver_eapol(drv, &from, fromlen, (u8 *) buf + 6,
812 res - 6);
813 } else if (strncmp(buf, "ETHER ", 6) == 0) {
814 test_driver_ether(drv, &from, fromlen, (u8 *) buf + 6,
815 res - 6);
816 } else if (strncmp(buf, "MLME ", 5) == 0) {
817 test_driver_mlme(drv, &from, fromlen, (u8 *) buf + 5, res - 5);
818 } else {
819 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
820 (u8 *) buf, res);
825 static struct test_driver_bss *
826 test_driver_get_bss(struct wpa_driver_test_data *drv, const char *ifname)
828 struct test_driver_bss *bss;
830 for (bss = drv->bss; bss; bss = bss->next) {
831 if (os_strcmp(bss->ifname, ifname) == 0)
832 return bss;
834 return NULL;
838 static int test_driver_set_generic_elem(const char *ifname, void *priv,
839 const u8 *elem, size_t elem_len)
841 struct wpa_driver_test_data *drv = priv;
842 struct test_driver_bss *bss;
844 bss = test_driver_get_bss(drv, ifname);
845 if (bss == NULL)
846 return -1;
848 os_free(bss->ie);
850 if (elem == NULL) {
851 bss->ie = NULL;
852 bss->ielen = 0;
853 return 0;
856 bss->ie = os_malloc(elem_len);
857 if (bss->ie == NULL) {
858 bss->ielen = 0;
859 return -1;
862 memcpy(bss->ie, elem, elem_len);
863 bss->ielen = elem_len;
864 return 0;
868 static int test_driver_set_ap_wps_ie(const char *ifname, void *priv,
869 const struct wpabuf *beacon,
870 const struct wpabuf *proberesp)
872 struct wpa_driver_test_data *drv = priv;
873 struct test_driver_bss *bss;
875 bss = test_driver_get_bss(drv, ifname);
876 if (bss == NULL)
877 return -1;
879 if (beacon == NULL)
880 wpa_printf(MSG_DEBUG, "test_driver: Clear Beacon WPS IE");
881 else
882 wpa_hexdump_buf(MSG_DEBUG, "test_driver: Beacon WPS IE",
883 beacon);
885 os_free(bss->wps_beacon_ie);
887 if (beacon == NULL) {
888 bss->wps_beacon_ie = NULL;
889 bss->wps_beacon_ie_len = 0;
890 } else {
891 bss->wps_beacon_ie = os_malloc(wpabuf_len(beacon));
892 if (bss->wps_beacon_ie == NULL) {
893 bss->wps_beacon_ie_len = 0;
894 return -1;
897 os_memcpy(bss->wps_beacon_ie, wpabuf_head(beacon),
898 wpabuf_len(beacon));
899 bss->wps_beacon_ie_len = wpabuf_len(beacon);
902 if (proberesp == NULL)
903 wpa_printf(MSG_DEBUG, "test_driver: Clear Probe Response WPS "
904 "IE");
905 else
906 wpa_hexdump_buf(MSG_DEBUG, "test_driver: Probe Response WPS "
907 "IE", proberesp);
909 os_free(bss->wps_probe_resp_ie);
911 if (proberesp == NULL) {
912 bss->wps_probe_resp_ie = NULL;
913 bss->wps_probe_resp_ie_len = 0;
914 } else {
915 bss->wps_probe_resp_ie = os_malloc(wpabuf_len(proberesp));
916 if (bss->wps_probe_resp_ie == NULL) {
917 bss->wps_probe_resp_ie_len = 0;
918 return -1;
921 os_memcpy(bss->wps_probe_resp_ie, wpabuf_head(proberesp),
922 wpabuf_len(proberesp));
923 bss->wps_probe_resp_ie_len = wpabuf_len(proberesp);
926 return 0;
930 static int test_driver_sta_deauth(void *priv, const u8 *own_addr,
931 const u8 *addr, int reason)
933 struct wpa_driver_test_data *drv = priv;
934 struct test_client_socket *cli;
936 if (drv->test_socket < 0)
937 return -1;
939 cli = drv->cli;
940 while (cli) {
941 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
942 break;
943 cli = cli->next;
946 if (!cli)
947 return -1;
949 return sendto(drv->test_socket, "DEAUTH", 6, 0,
950 (struct sockaddr *) &cli->un, cli->unlen);
954 static int test_driver_sta_disassoc(void *priv, const u8 *own_addr,
955 const u8 *addr, int reason)
957 struct wpa_driver_test_data *drv = priv;
958 struct test_client_socket *cli;
960 if (drv->test_socket < 0)
961 return -1;
963 cli = drv->cli;
964 while (cli) {
965 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
966 break;
967 cli = cli->next;
970 if (!cli)
971 return -1;
973 return sendto(drv->test_socket, "DISASSOC", 8, 0,
974 (struct sockaddr *) &cli->un, cli->unlen);
978 static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid,
979 void *bss_ctx)
981 struct wpa_driver_test_data *drv = priv;
982 struct test_driver_bss *bss;
984 wpa_printf(MSG_DEBUG, "%s(ifname=%s bssid=" MACSTR ")",
985 __func__, ifname, MAC2STR(bssid));
987 bss = os_zalloc(sizeof(*bss));
988 if (bss == NULL)
989 return -1;
991 bss->bss_ctx = bss_ctx;
992 os_strlcpy(bss->ifname, ifname, IFNAMSIZ);
993 memcpy(bss->bssid, bssid, ETH_ALEN);
995 bss->next = drv->bss;
996 drv->bss = bss;
997 drv->global->bss_add_used = 1;
998 os_memcpy(drv->global->req_addr, bssid, ETH_ALEN);
1000 return 0;
1004 static int test_driver_bss_remove(void *priv, const char *ifname)
1006 struct wpa_driver_test_data *drv = priv;
1007 struct test_driver_bss *bss, *prev;
1008 struct test_client_socket *cli, *prev_c;
1010 wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
1012 for (prev = NULL, bss = drv->bss; bss; prev = bss, bss = bss->next) {
1013 if (strcmp(bss->ifname, ifname) != 0)
1014 continue;
1016 if (prev)
1017 prev->next = bss->next;
1018 else
1019 drv->bss = bss->next;
1021 for (prev_c = NULL, cli = drv->cli; cli;
1022 prev_c = cli, cli = cli->next) {
1023 if (cli->bss != bss)
1024 continue;
1025 if (prev_c)
1026 prev_c->next = cli->next;
1027 else
1028 drv->cli = cli->next;
1029 os_free(cli);
1030 break;
1033 test_driver_free_bss(bss);
1034 return 0;
1037 return -1;
1041 static int test_driver_if_add(const char *iface, void *priv,
1042 enum wpa_driver_if_type type, const char *ifname,
1043 const u8 *addr, void *bss_ctx)
1045 wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s bss_ctx=%p)",
1046 __func__, iface, type, ifname, bss_ctx);
1047 if (type == WPA_IF_AP_BSS)
1048 return test_driver_bss_add(priv, ifname, addr, bss_ctx);
1049 return 0;
1053 static int test_driver_if_remove(void *priv, enum wpa_driver_if_type type,
1054 const char *ifname)
1056 wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
1057 if (type == WPA_IF_AP_BSS)
1058 return test_driver_bss_remove(priv, ifname);
1059 return 0;
1063 static int test_driver_valid_bss_mask(void *priv, const u8 *addr,
1064 const u8 *mask)
1066 return 0;
1070 static int test_driver_set_ssid(const char *ifname, void *priv, const u8 *buf,
1071 int len)
1073 struct wpa_driver_test_data *drv = priv;
1074 struct test_driver_bss *bss;
1076 wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
1077 wpa_hexdump_ascii(MSG_DEBUG, "test_driver_set_ssid: SSID", buf, len);
1079 bss = test_driver_get_bss(drv, ifname);
1080 if (bss == NULL) {
1081 wpa_printf(MSG_DEBUG, "%s(ifname=%s): failed to find BSS data",
1082 __func__, ifname);
1083 return -1;
1086 if (len < 0 || (size_t) len > sizeof(bss->ssid))
1087 return -1;
1089 os_memcpy(bss->ssid, buf, len);
1090 bss->ssid_len = len;
1092 return 0;
1096 static int test_driver_set_privacy(const char *ifname, void *priv, int enabled)
1098 struct wpa_driver_test_data *drv = priv;
1099 struct test_driver_bss *bss;
1101 wpa_printf(MSG_DEBUG, "%s(ifname=%s enabled=%d)",
1102 __func__, ifname, enabled);
1104 bss = test_driver_get_bss(drv, ifname);
1105 if (bss == NULL)
1106 return -1;
1108 bss->privacy = enabled;
1110 return 0;
1114 static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
1115 const char *ifname, int vlan_id)
1117 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " ifname=%s vlan_id=%d)",
1118 __func__, MAC2STR(addr), ifname, vlan_id);
1119 return 0;
1123 static int test_driver_sta_add(const char *ifname, void *priv,
1124 struct hostapd_sta_add_params *params)
1126 struct wpa_driver_test_data *drv = priv;
1127 struct test_client_socket *cli;
1128 struct test_driver_bss *bss;
1130 wpa_printf(MSG_DEBUG, "%s(ifname=%s addr=" MACSTR " aid=%d "
1131 "capability=0x%x listen_interval=%d)",
1132 __func__, ifname, MAC2STR(params->addr), params->aid,
1133 params->capability, params->listen_interval);
1134 wpa_hexdump(MSG_DEBUG, "test_driver_sta_add - supp_rates",
1135 params->supp_rates, params->supp_rates_len);
1137 cli = drv->cli;
1138 while (cli) {
1139 if (os_memcmp(cli->addr, params->addr, ETH_ALEN) == 0)
1140 break;
1141 cli = cli->next;
1143 if (!cli) {
1144 wpa_printf(MSG_DEBUG, "%s: no matching client entry",
1145 __func__);
1146 return -1;
1149 bss = test_driver_get_bss(drv, ifname);
1150 if (bss == NULL) {
1151 wpa_printf(MSG_DEBUG, "%s: No matching interface found from "
1152 "configured BSSes", __func__);
1153 return -1;
1156 cli->bss = bss;
1158 return 0;
1162 static struct wpa_driver_test_data * test_alloc_data(void *ctx,
1163 const char *ifname)
1165 struct wpa_driver_test_data *drv;
1167 drv = os_zalloc(sizeof(struct wpa_driver_test_data));
1168 if (drv == NULL) {
1169 wpa_printf(MSG_ERROR, "Could not allocate memory for test "
1170 "driver data");
1171 return NULL;
1174 drv->ctx = ctx;
1175 wpa_trace_add_ref(drv, ctx, ctx);
1176 os_strlcpy(drv->ifname, ifname, IFNAMSIZ);
1178 /* Generate a MAC address to help testing with multiple STAs */
1179 drv->own_addr[0] = 0x02; /* locally administered */
1180 sha1_prf((const u8 *) ifname, os_strlen(ifname),
1181 "test mac addr generation",
1182 NULL, 0, drv->own_addr + 1, ETH_ALEN - 1);
1184 return drv;
1188 static void * test_driver_init(struct hostapd_data *hapd,
1189 struct wpa_init_params *params)
1191 struct wpa_driver_test_data *drv;
1192 struct sockaddr_un addr_un;
1193 struct sockaddr_in addr_in;
1194 struct sockaddr *addr;
1195 socklen_t alen;
1197 drv = test_alloc_data(hapd, params->ifname);
1198 if (drv == NULL)
1199 return NULL;
1200 drv->ap = 1;
1201 drv->bss = os_zalloc(sizeof(*drv->bss));
1202 if (drv->bss == NULL) {
1203 wpa_printf(MSG_ERROR, "Could not allocate memory for test "
1204 "driver BSS data");
1205 os_free(drv);
1206 return NULL;
1209 drv->bss->bss_ctx = hapd;
1210 os_strlcpy(drv->bss->ifname, params->ifname, IFNAMSIZ);
1211 os_memcpy(drv->bss->bssid, drv->own_addr, ETH_ALEN);
1212 os_memcpy(params->own_addr, drv->own_addr, ETH_ALEN);
1214 if (params->test_socket) {
1215 if (os_strlen(params->test_socket) >=
1216 sizeof(addr_un.sun_path)) {
1217 printf("Too long test_socket path\n");
1218 wpa_driver_test_deinit(drv);
1219 return NULL;
1221 if (strncmp(params->test_socket, "DIR:", 4) == 0) {
1222 size_t len = strlen(params->test_socket) + 30;
1223 drv->test_dir = os_strdup(params->test_socket + 4);
1224 drv->own_socket_path = os_malloc(len);
1225 if (drv->own_socket_path) {
1226 snprintf(drv->own_socket_path, len,
1227 "%s/AP-" MACSTR,
1228 params->test_socket + 4,
1229 MAC2STR(params->own_addr));
1231 } else if (strncmp(params->test_socket, "UDP:", 4) == 0) {
1232 drv->udp_port = atoi(params->test_socket + 4);
1233 } else {
1234 drv->own_socket_path = os_strdup(params->test_socket);
1236 if (drv->own_socket_path == NULL && drv->udp_port == 0) {
1237 wpa_driver_test_deinit(drv);
1238 return NULL;
1241 drv->test_socket = socket(drv->udp_port ? PF_INET : PF_UNIX,
1242 SOCK_DGRAM, 0);
1243 if (drv->test_socket < 0) {
1244 perror("socket");
1245 wpa_driver_test_deinit(drv);
1246 return NULL;
1249 if (drv->udp_port) {
1250 os_memset(&addr_in, 0, sizeof(addr_in));
1251 addr_in.sin_family = AF_INET;
1252 addr_in.sin_port = htons(drv->udp_port);
1253 addr = (struct sockaddr *) &addr_in;
1254 alen = sizeof(addr_in);
1255 } else {
1256 os_memset(&addr_un, 0, sizeof(addr_un));
1257 addr_un.sun_family = AF_UNIX;
1258 os_strlcpy(addr_un.sun_path, drv->own_socket_path,
1259 sizeof(addr_un.sun_path));
1260 addr = (struct sockaddr *) &addr_un;
1261 alen = sizeof(addr_un);
1263 if (bind(drv->test_socket, addr, alen) < 0) {
1264 perror("bind(PF_UNIX)");
1265 close(drv->test_socket);
1266 if (drv->own_socket_path)
1267 unlink(drv->own_socket_path);
1268 wpa_driver_test_deinit(drv);
1269 return NULL;
1271 eloop_register_read_sock(drv->test_socket,
1272 test_driver_receive_unix, drv, NULL);
1273 } else
1274 drv->test_socket = -1;
1276 return drv;
1280 static void wpa_driver_test_poll(void *eloop_ctx, void *timeout_ctx)
1282 struct wpa_driver_test_data *drv = eloop_ctx;
1284 #ifdef DRIVER_TEST_UNIX
1285 if (drv->associated && drv->hostapd_addr_set) {
1286 struct stat st;
1287 if (stat(drv->hostapd_addr.sun_path, &st) < 0) {
1288 wpa_printf(MSG_DEBUG, "%s: lost connection to AP: %s",
1289 __func__, strerror(errno));
1290 drv->associated = 0;
1291 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1294 #endif /* DRIVER_TEST_UNIX */
1296 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
1300 static void wpa_driver_test_scan_timeout(void *eloop_ctx, void *timeout_ctx)
1302 wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
1303 wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
1307 #ifdef DRIVER_TEST_UNIX
1308 static void wpa_driver_scan_dir(struct wpa_driver_test_data *drv,
1309 const char *path)
1311 struct dirent *dent;
1312 DIR *dir;
1313 struct sockaddr_un addr;
1314 char cmd[512], *pos, *end;
1315 int ret;
1317 dir = opendir(path);
1318 if (dir == NULL)
1319 return;
1321 end = cmd + sizeof(cmd);
1322 pos = cmd;
1323 ret = os_snprintf(pos, end - pos, "SCAN " MACSTR,
1324 MAC2STR(drv->own_addr));
1325 if (ret >= 0 && ret < end - pos)
1326 pos += ret;
1327 if (drv->probe_req_ie) {
1328 ret = os_snprintf(pos, end - pos, " ");
1329 if (ret >= 0 && ret < end - pos)
1330 pos += ret;
1331 pos += wpa_snprintf_hex(pos, end - pos, drv->probe_req_ie,
1332 drv->probe_req_ie_len);
1334 end[-1] = '\0';
1336 while ((dent = readdir(dir))) {
1337 if (os_strncmp(dent->d_name, "AP-", 3) != 0 &&
1338 os_strncmp(dent->d_name, "STA-", 4) != 0)
1339 continue;
1340 if (drv->own_socket_path) {
1341 size_t olen, dlen;
1342 olen = os_strlen(drv->own_socket_path);
1343 dlen = os_strlen(dent->d_name);
1344 if (olen >= dlen &&
1345 os_strcmp(dent->d_name,
1346 drv->own_socket_path + olen - dlen) == 0)
1347 continue;
1349 wpa_printf(MSG_DEBUG, "%s: SCAN %s", __func__, dent->d_name);
1351 os_memset(&addr, 0, sizeof(addr));
1352 addr.sun_family = AF_UNIX;
1353 os_snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
1354 path, dent->d_name);
1356 if (sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1357 (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1358 perror("sendto(test_socket)");
1361 closedir(dir);
1363 #endif /* DRIVER_TEST_UNIX */
1366 static int wpa_driver_test_scan(void *priv,
1367 struct wpa_driver_scan_params *params)
1369 struct wpa_driver_test_data *drv = priv;
1370 size_t i;
1372 wpa_printf(MSG_DEBUG, "%s: priv=%p", __func__, priv);
1374 os_free(drv->probe_req_ie);
1375 if (params->extra_ies) {
1376 drv->probe_req_ie = os_malloc(params->extra_ies_len);
1377 if (drv->probe_req_ie == NULL) {
1378 drv->probe_req_ie_len = 0;
1379 return -1;
1381 os_memcpy(drv->probe_req_ie, params->extra_ies,
1382 params->extra_ies_len);
1383 drv->probe_req_ie_len = params->extra_ies_len;
1384 } else {
1385 drv->probe_req_ie = NULL;
1386 drv->probe_req_ie_len = 0;
1389 for (i = 0; i < params->num_ssids; i++)
1390 wpa_hexdump(MSG_DEBUG, "Scan SSID",
1391 params->ssids[i].ssid, params->ssids[i].ssid_len);
1392 wpa_hexdump(MSG_DEBUG, "Scan extra IE(s)",
1393 params->extra_ies, params->extra_ies_len);
1395 drv->num_scanres = 0;
1397 #ifdef DRIVER_TEST_UNIX
1398 if (drv->test_socket >= 0 && drv->test_dir)
1399 wpa_driver_scan_dir(drv, drv->test_dir);
1401 if (drv->test_socket >= 0 && drv->hostapd_addr_set &&
1402 sendto(drv->test_socket, "SCAN", 4, 0,
1403 (struct sockaddr *) &drv->hostapd_addr,
1404 sizeof(drv->hostapd_addr)) < 0) {
1405 perror("sendto(test_socket)");
1407 #endif /* DRIVER_TEST_UNIX */
1409 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1410 sendto(drv->test_socket, "SCAN", 4, 0,
1411 (struct sockaddr *) &drv->hostapd_addr_udp,
1412 sizeof(drv->hostapd_addr_udp)) < 0) {
1413 perror("sendto(test_socket)");
1416 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
1417 eloop_register_timeout(1, 0, wpa_driver_test_scan_timeout, drv,
1418 drv->ctx);
1419 return 0;
1423 static struct wpa_scan_results * wpa_driver_test_get_scan_results2(void *priv)
1425 struct wpa_driver_test_data *drv = priv;
1426 struct wpa_scan_results *res;
1427 size_t i;
1429 res = os_zalloc(sizeof(*res));
1430 if (res == NULL)
1431 return NULL;
1433 res->res = os_zalloc(drv->num_scanres * sizeof(struct wpa_scan_res *));
1434 if (res->res == NULL) {
1435 os_free(res);
1436 return NULL;
1439 for (i = 0; i < drv->num_scanres; i++) {
1440 struct wpa_scan_res *r;
1441 if (drv->scanres[i] == NULL)
1442 continue;
1443 r = os_malloc(sizeof(*r) + drv->scanres[i]->ie_len);
1444 if (r == NULL)
1445 break;
1446 os_memcpy(r, drv->scanres[i],
1447 sizeof(*r) + drv->scanres[i]->ie_len);
1448 res->res[res->num++] = r;
1451 return res;
1455 static int wpa_driver_test_set_key(const char *ifname, void *priv,
1456 enum wpa_alg alg, const u8 *addr,
1457 int key_idx, int set_tx,
1458 const u8 *seq, size_t seq_len,
1459 const u8 *key, size_t key_len)
1461 wpa_printf(MSG_DEBUG, "%s: ifname=%s priv=%p alg=%d key_idx=%d "
1462 "set_tx=%d",
1463 __func__, ifname, priv, alg, key_idx, set_tx);
1464 if (addr)
1465 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
1466 if (seq)
1467 wpa_hexdump(MSG_DEBUG, " seq", seq, seq_len);
1468 if (key)
1469 wpa_hexdump_key(MSG_DEBUG, " key", key, key_len);
1470 return 0;
1474 static int wpa_driver_update_mode(struct wpa_driver_test_data *drv, int ap)
1476 if (ap && !drv->ap) {
1477 wpa_driver_test_close_test_socket(drv);
1478 wpa_driver_test_attach(drv, drv->test_dir, 1);
1479 drv->ap = 1;
1480 } else if (!ap && drv->ap) {
1481 wpa_driver_test_close_test_socket(drv);
1482 wpa_driver_test_attach(drv, drv->test_dir, 0);
1483 drv->ap = 0;
1486 return 0;
1490 static int wpa_driver_test_associate(
1491 void *priv, struct wpa_driver_associate_params *params)
1493 struct wpa_driver_test_data *drv = priv;
1494 wpa_printf(MSG_DEBUG, "%s: priv=%p freq=%d pairwise_suite=%d "
1495 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d",
1496 __func__, priv, params->freq, params->pairwise_suite,
1497 params->group_suite, params->key_mgmt_suite,
1498 params->auth_alg, params->mode);
1499 if (params->bssid) {
1500 wpa_printf(MSG_DEBUG, " bssid=" MACSTR,
1501 MAC2STR(params->bssid));
1503 if (params->ssid) {
1504 wpa_hexdump_ascii(MSG_DEBUG, " ssid",
1505 params->ssid, params->ssid_len);
1507 if (params->wpa_ie) {
1508 wpa_hexdump(MSG_DEBUG, " wpa_ie",
1509 params->wpa_ie, params->wpa_ie_len);
1510 drv->assoc_wpa_ie_len = params->wpa_ie_len;
1511 if (drv->assoc_wpa_ie_len > sizeof(drv->assoc_wpa_ie))
1512 drv->assoc_wpa_ie_len = sizeof(drv->assoc_wpa_ie);
1513 os_memcpy(drv->assoc_wpa_ie, params->wpa_ie,
1514 drv->assoc_wpa_ie_len);
1515 } else
1516 drv->assoc_wpa_ie_len = 0;
1518 wpa_driver_update_mode(drv, params->mode == IEEE80211_MODE_AP);
1520 drv->ibss = params->mode == IEEE80211_MODE_IBSS;
1521 drv->privacy = params->key_mgmt_suite &
1522 (WPA_KEY_MGMT_IEEE8021X |
1523 WPA_KEY_MGMT_PSK |
1524 WPA_KEY_MGMT_WPA_NONE |
1525 WPA_KEY_MGMT_FT_IEEE8021X |
1526 WPA_KEY_MGMT_FT_PSK |
1527 WPA_KEY_MGMT_IEEE8021X_SHA256 |
1528 WPA_KEY_MGMT_PSK_SHA256);
1529 if (params->wep_key_len[params->wep_tx_keyidx])
1530 drv->privacy = 1;
1532 #ifdef DRIVER_TEST_UNIX
1533 if (drv->test_dir && params->bssid &&
1534 params->mode != IEEE80211_MODE_IBSS) {
1535 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
1536 drv->hostapd_addr.sun_family = AF_UNIX;
1537 os_snprintf(drv->hostapd_addr.sun_path,
1538 sizeof(drv->hostapd_addr.sun_path),
1539 "%s/AP-" MACSTR,
1540 drv->test_dir, MAC2STR(params->bssid));
1541 drv->hostapd_addr_set = 1;
1543 #endif /* DRIVER_TEST_UNIX */
1545 if (params->mode == IEEE80211_MODE_AP) {
1546 struct test_driver_bss *bss;
1547 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1548 drv->ssid_len = params->ssid_len;
1550 test_driver_free_bsses(drv);
1551 bss = drv->bss = os_zalloc(sizeof(*drv->bss));
1552 if (bss == NULL)
1553 return -1;
1554 os_strlcpy(bss->ifname, drv->ifname, IFNAMSIZ);
1555 os_memcpy(bss->bssid, drv->own_addr, ETH_ALEN);
1556 os_memcpy(bss->ssid, params->ssid, params->ssid_len);
1557 bss->ssid_len = params->ssid_len;
1558 bss->privacy = drv->privacy;
1559 if (params->wpa_ie && params->wpa_ie_len) {
1560 bss->ie = os_malloc(params->wpa_ie_len);
1561 if (bss->ie) {
1562 os_memcpy(bss->ie, params->wpa_ie,
1563 params->wpa_ie_len);
1564 bss->ielen = params->wpa_ie_len;
1567 } else if (drv->test_socket >= 0 &&
1568 (drv->hostapd_addr_set || drv->hostapd_addr_udp_set)) {
1569 char cmd[200], *pos, *end;
1570 int ret;
1571 end = cmd + sizeof(cmd);
1572 pos = cmd;
1573 ret = os_snprintf(pos, end - pos, "ASSOC " MACSTR " ",
1574 MAC2STR(drv->own_addr));
1575 if (ret >= 0 && ret < end - pos)
1576 pos += ret;
1577 pos += wpa_snprintf_hex(pos, end - pos, params->ssid,
1578 params->ssid_len);
1579 ret = os_snprintf(pos, end - pos, " ");
1580 if (ret >= 0 && ret < end - pos)
1581 pos += ret;
1582 pos += wpa_snprintf_hex(pos, end - pos, params->wpa_ie,
1583 params->wpa_ie_len);
1584 end[-1] = '\0';
1585 #ifdef DRIVER_TEST_UNIX
1586 if (drv->hostapd_addr_set &&
1587 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1588 (struct sockaddr *) &drv->hostapd_addr,
1589 sizeof(drv->hostapd_addr)) < 0) {
1590 perror("sendto(test_socket)");
1591 return -1;
1593 #endif /* DRIVER_TEST_UNIX */
1594 if (drv->hostapd_addr_udp_set &&
1595 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1596 (struct sockaddr *) &drv->hostapd_addr_udp,
1597 sizeof(drv->hostapd_addr_udp)) < 0) {
1598 perror("sendto(test_socket)");
1599 return -1;
1602 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1603 drv->ssid_len = params->ssid_len;
1604 } else {
1605 drv->associated = 1;
1606 if (params->mode == IEEE80211_MODE_IBSS) {
1607 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1608 drv->ssid_len = params->ssid_len;
1609 if (params->bssid)
1610 os_memcpy(drv->bssid, params->bssid, ETH_ALEN);
1611 else {
1612 os_get_random(drv->bssid, ETH_ALEN);
1613 drv->bssid[0] &= ~0x01;
1614 drv->bssid[0] |= 0x02;
1617 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1620 return 0;
1624 static int wpa_driver_test_get_bssid(void *priv, u8 *bssid)
1626 struct wpa_driver_test_data *drv = priv;
1627 os_memcpy(bssid, drv->bssid, ETH_ALEN);
1628 return 0;
1632 static int wpa_driver_test_get_ssid(void *priv, u8 *ssid)
1634 struct wpa_driver_test_data *drv = priv;
1635 os_memcpy(ssid, drv->ssid, 32);
1636 return drv->ssid_len;
1640 static int wpa_driver_test_send_disassoc(struct wpa_driver_test_data *drv)
1642 #ifdef DRIVER_TEST_UNIX
1643 if (drv->test_socket >= 0 &&
1644 sendto(drv->test_socket, "DISASSOC", 8, 0,
1645 (struct sockaddr *) &drv->hostapd_addr,
1646 sizeof(drv->hostapd_addr)) < 0) {
1647 perror("sendto(test_socket)");
1648 return -1;
1650 #endif /* DRIVER_TEST_UNIX */
1651 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1652 sendto(drv->test_socket, "DISASSOC", 8, 0,
1653 (struct sockaddr *) &drv->hostapd_addr_udp,
1654 sizeof(drv->hostapd_addr_udp)) < 0) {
1655 perror("sendto(test_socket)");
1656 return -1;
1658 return 0;
1662 static int wpa_driver_test_deauthenticate(void *priv, const u8 *addr,
1663 int reason_code)
1665 struct wpa_driver_test_data *drv = priv;
1666 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1667 __func__, MAC2STR(addr), reason_code);
1668 os_memset(drv->bssid, 0, ETH_ALEN);
1669 drv->associated = 0;
1670 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1671 return wpa_driver_test_send_disassoc(drv);
1675 static int wpa_driver_test_disassociate(void *priv, const u8 *addr,
1676 int reason_code)
1678 struct wpa_driver_test_data *drv = priv;
1679 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1680 __func__, MAC2STR(addr), reason_code);
1681 os_memset(drv->bssid, 0, ETH_ALEN);
1682 drv->associated = 0;
1683 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1684 return wpa_driver_test_send_disassoc(drv);
1688 static void wpa_driver_test_scanresp(struct wpa_driver_test_data *drv,
1689 struct sockaddr *from,
1690 socklen_t fromlen,
1691 const char *data)
1693 struct wpa_scan_res *res;
1694 const char *pos, *pos2;
1695 size_t len;
1696 u8 *ie_pos, *ie_start, *ie_end;
1697 #define MAX_IE_LEN 1000
1699 wpa_printf(MSG_DEBUG, "test_driver: SCANRESP %s", data);
1700 if (drv->num_scanres >= MAX_SCAN_RESULTS) {
1701 wpa_printf(MSG_DEBUG, "test_driver: No room for the new scan "
1702 "result");
1703 return;
1706 /* SCANRESP BSSID SSID IEs */
1708 res = os_zalloc(sizeof(*res) + MAX_IE_LEN);
1709 if (res == NULL)
1710 return;
1711 ie_start = ie_pos = (u8 *) (res + 1);
1712 ie_end = ie_pos + MAX_IE_LEN;
1714 if (hwaddr_aton(data, res->bssid)) {
1715 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in scanres");
1716 os_free(res);
1717 return;
1720 pos = data + 17;
1721 while (*pos == ' ')
1722 pos++;
1723 pos2 = os_strchr(pos, ' ');
1724 if (pos2 == NULL) {
1725 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID termination "
1726 "in scanres");
1727 os_free(res);
1728 return;
1730 len = (pos2 - pos) / 2;
1731 if (len > 32)
1732 len = 32;
1734 * Generate SSID IE from the SSID field since this IE is not included
1735 * in the main IE field.
1737 *ie_pos++ = WLAN_EID_SSID;
1738 *ie_pos++ = len;
1739 if (hexstr2bin(pos, ie_pos, len) < 0) {
1740 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID in scanres");
1741 os_free(res);
1742 return;
1744 ie_pos += len;
1746 pos = pos2 + 1;
1747 pos2 = os_strchr(pos, ' ');
1748 if (pos2 == NULL)
1749 len = os_strlen(pos) / 2;
1750 else
1751 len = (pos2 - pos) / 2;
1752 if ((int) len > ie_end - ie_pos)
1753 len = ie_end - ie_pos;
1754 if (hexstr2bin(pos, ie_pos, len) < 0) {
1755 wpa_printf(MSG_DEBUG, "test_driver: invalid IEs in scanres");
1756 os_free(res);
1757 return;
1759 ie_pos += len;
1760 res->ie_len = ie_pos - ie_start;
1762 if (pos2) {
1763 pos = pos2 + 1;
1764 while (*pos == ' ')
1765 pos++;
1766 if (os_strstr(pos, "PRIVACY"))
1767 res->caps |= IEEE80211_CAP_PRIVACY;
1768 if (os_strstr(pos, "IBSS"))
1769 res->caps |= IEEE80211_CAP_IBSS;
1772 os_free(drv->scanres[drv->num_scanres]);
1773 drv->scanres[drv->num_scanres++] = res;
1777 static void wpa_driver_test_assocresp(struct wpa_driver_test_data *drv,
1778 struct sockaddr *from,
1779 socklen_t fromlen,
1780 const char *data)
1782 /* ASSOCRESP BSSID <res> */
1783 if (hwaddr_aton(data, drv->bssid)) {
1784 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in "
1785 "assocresp");
1787 if (drv->use_associnfo) {
1788 union wpa_event_data event;
1789 os_memset(&event, 0, sizeof(event));
1790 event.assoc_info.req_ies = drv->assoc_wpa_ie;
1791 event.assoc_info.req_ies_len = drv->assoc_wpa_ie_len;
1792 wpa_supplicant_event(drv->ctx, EVENT_ASSOCINFO, &event);
1794 drv->associated = 1;
1795 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1799 static void wpa_driver_test_disassoc(struct wpa_driver_test_data *drv,
1800 struct sockaddr *from,
1801 socklen_t fromlen)
1803 drv->associated = 0;
1804 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1808 static void wpa_driver_test_eapol(struct wpa_driver_test_data *drv,
1809 struct sockaddr *from,
1810 socklen_t fromlen,
1811 const u8 *data, size_t data_len)
1813 const u8 *src = drv->bssid;
1814 union wpa_event_data event;
1816 if (data_len > 14) {
1817 /* Skip Ethernet header */
1818 src = data + ETH_ALEN;
1819 data += 14;
1820 data_len -= 14;
1823 os_memset(&event, 0, sizeof(event));
1824 event.eapol_rx.src = src;
1825 event.eapol_rx.data = data;
1826 event.eapol_rx.data_len = data_len;
1827 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_RX, &event);
1831 static void wpa_driver_test_mlme(struct wpa_driver_test_data *drv,
1832 struct sockaddr *from,
1833 socklen_t fromlen,
1834 const u8 *data, size_t data_len)
1836 int freq = 0, own_freq;
1837 union wpa_event_data event;
1839 if (data_len > 6 && os_memcmp(data, "freq=", 5) == 0) {
1840 size_t pos;
1841 for (pos = 5; pos < data_len; pos++) {
1842 if (data[pos] == ' ')
1843 break;
1845 if (pos < data_len) {
1846 freq = atoi((const char *) &data[5]);
1847 wpa_printf(MSG_DEBUG, "test_driver(%s): MLME RX on "
1848 "freq %d MHz", drv->ifname, freq);
1849 pos++;
1850 data += pos;
1851 data_len -= pos;
1855 if (drv->remain_on_channel_freq)
1856 own_freq = drv->remain_on_channel_freq;
1857 else
1858 own_freq = drv->current_freq;
1860 if (freq && own_freq && freq != own_freq) {
1861 wpa_printf(MSG_DEBUG, "test_driver(%s): Ignore MLME RX on "
1862 "another frequency %d MHz (own %d MHz)",
1863 drv->ifname, freq, own_freq);
1864 return;
1867 os_memset(&event, 0, sizeof(event));
1868 event.mlme_rx.buf = data;
1869 event.mlme_rx.len = data_len;
1870 event.mlme_rx.freq = freq;
1871 wpa_supplicant_event(drv->ctx, EVENT_MLME_RX, &event);
1873 if (drv->probe_req_report && data_len >= 24) {
1874 const struct ieee80211_mgmt *mgmt;
1875 u16 fc;
1877 mgmt = (const struct ieee80211_mgmt *) data;
1878 fc = le_to_host16(mgmt->frame_control);
1879 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1880 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ) {
1881 os_memset(&event, 0, sizeof(event));
1882 event.rx_probe_req.sa = mgmt->sa;
1883 event.rx_probe_req.ie = mgmt->u.probe_req.variable;
1884 event.rx_probe_req.ie_len =
1885 data_len - (mgmt->u.probe_req.variable - data);
1886 wpa_supplicant_event(drv->ctx, EVENT_RX_PROBE_REQ,
1887 &event);
1893 static void wpa_driver_test_scan_cmd(struct wpa_driver_test_data *drv,
1894 struct sockaddr *from,
1895 socklen_t fromlen,
1896 const u8 *data, size_t data_len)
1898 char buf[512], *pos, *end;
1899 int ret;
1901 /* data: optional [ STA-addr | ' ' | IEs(hex) ] */
1903 if (!drv->ibss)
1904 return;
1906 pos = buf;
1907 end = buf + sizeof(buf);
1909 /* reply: SCANRESP BSSID SSID IEs */
1910 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
1911 MAC2STR(drv->bssid));
1912 if (ret < 0 || ret >= end - pos)
1913 return;
1914 pos += ret;
1915 pos += wpa_snprintf_hex(pos, end - pos,
1916 drv->ssid, drv->ssid_len);
1917 ret = snprintf(pos, end - pos, " ");
1918 if (ret < 0 || ret >= end - pos)
1919 return;
1920 pos += ret;
1921 pos += wpa_snprintf_hex(pos, end - pos, drv->assoc_wpa_ie,
1922 drv->assoc_wpa_ie_len);
1924 if (drv->privacy) {
1925 ret = snprintf(pos, end - pos, " PRIVACY");
1926 if (ret < 0 || ret >= end - pos)
1927 return;
1928 pos += ret;
1931 ret = snprintf(pos, end - pos, " IBSS");
1932 if (ret < 0 || ret >= end - pos)
1933 return;
1934 pos += ret;
1936 sendto(drv->test_socket, buf, pos - buf, 0,
1937 (struct sockaddr *) from, fromlen);
1941 static void wpa_driver_test_receive_unix(int sock, void *eloop_ctx,
1942 void *sock_ctx)
1944 struct wpa_driver_test_data *drv = eloop_ctx;
1945 char *buf;
1946 int res;
1947 struct sockaddr_storage from;
1948 socklen_t fromlen = sizeof(from);
1949 const size_t buflen = 2000;
1951 if (drv->ap) {
1952 test_driver_receive_unix(sock, eloop_ctx, sock_ctx);
1953 return;
1956 buf = os_malloc(buflen);
1957 if (buf == NULL)
1958 return;
1959 res = recvfrom(sock, buf, buflen - 1, 0,
1960 (struct sockaddr *) &from, &fromlen);
1961 if (res < 0) {
1962 perror("recvfrom(test_socket)");
1963 os_free(buf);
1964 return;
1966 buf[res] = '\0';
1968 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
1970 if (os_strncmp(buf, "SCANRESP ", 9) == 0) {
1971 wpa_driver_test_scanresp(drv, (struct sockaddr *) &from,
1972 fromlen, buf + 9);
1973 } else if (os_strncmp(buf, "ASSOCRESP ", 10) == 0) {
1974 wpa_driver_test_assocresp(drv, (struct sockaddr *) &from,
1975 fromlen, buf + 10);
1976 } else if (os_strcmp(buf, "DISASSOC") == 0) {
1977 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1978 fromlen);
1979 } else if (os_strcmp(buf, "DEAUTH") == 0) {
1980 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1981 fromlen);
1982 } else if (os_strncmp(buf, "EAPOL ", 6) == 0) {
1983 wpa_driver_test_eapol(drv, (struct sockaddr *) &from, fromlen,
1984 (const u8 *) buf + 6, res - 6);
1985 } else if (os_strncmp(buf, "MLME ", 5) == 0) {
1986 wpa_driver_test_mlme(drv, (struct sockaddr *) &from, fromlen,
1987 (const u8 *) buf + 5, res - 5);
1988 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
1989 wpa_driver_test_scan_cmd(drv, (struct sockaddr *) &from,
1990 fromlen,
1991 (const u8 *) buf + 5, res - 5);
1992 } else {
1993 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
1994 (u8 *) buf, res);
1996 os_free(buf);
2000 static void * wpa_driver_test_init2(void *ctx, const char *ifname,
2001 void *global_priv)
2003 struct wpa_driver_test_data *drv;
2004 struct wpa_driver_test_global *global = global_priv;
2006 drv = test_alloc_data(ctx, ifname);
2007 if (drv == NULL)
2008 return NULL;
2009 drv->global = global_priv;
2010 drv->test_socket = -1;
2012 /* Set dummy BSSID and SSID for testing. */
2013 drv->bssid[0] = 0x02;
2014 drv->bssid[1] = 0x00;
2015 drv->bssid[2] = 0x00;
2016 drv->bssid[3] = 0x00;
2017 drv->bssid[4] = 0x00;
2018 drv->bssid[5] = 0x01;
2019 os_memcpy(drv->ssid, "test", 5);
2020 drv->ssid_len = 4;
2022 if (global->bss_add_used) {
2023 os_memcpy(drv->own_addr, global->req_addr, ETH_ALEN);
2024 global->bss_add_used = 0;
2027 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
2029 return drv;
2033 static void wpa_driver_test_close_test_socket(struct wpa_driver_test_data *drv)
2035 if (drv->test_socket >= 0) {
2036 eloop_unregister_read_sock(drv->test_socket);
2037 close(drv->test_socket);
2038 drv->test_socket = -1;
2041 if (drv->own_socket_path) {
2042 unlink(drv->own_socket_path);
2043 os_free(drv->own_socket_path);
2044 drv->own_socket_path = NULL;
2049 static void wpa_driver_test_deinit(void *priv)
2051 struct wpa_driver_test_data *drv = priv;
2052 struct test_client_socket *cli, *prev;
2053 int i;
2055 cli = drv->cli;
2056 while (cli) {
2057 prev = cli;
2058 cli = cli->next;
2059 os_free(prev);
2062 #ifdef HOSTAPD
2063 /* There should be only one BSS remaining at this point. */
2064 if (drv->bss == NULL)
2065 wpa_printf(MSG_ERROR, "%s: drv->bss == NULL", __func__);
2066 else if (drv->bss->next)
2067 wpa_printf(MSG_ERROR, "%s: drv->bss->next != NULL", __func__);
2068 #endif /* HOSTAPD */
2070 test_driver_free_bsses(drv);
2072 wpa_driver_test_close_test_socket(drv);
2073 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
2074 eloop_cancel_timeout(wpa_driver_test_poll, drv, NULL);
2075 eloop_cancel_timeout(test_remain_on_channel_timeout, drv, NULL);
2076 os_free(drv->test_dir);
2077 for (i = 0; i < MAX_SCAN_RESULTS; i++)
2078 os_free(drv->scanres[i]);
2079 os_free(drv->probe_req_ie);
2080 wpa_trace_remove_ref(drv, ctx, drv->ctx);
2081 os_free(drv);
2085 static int wpa_driver_test_attach(struct wpa_driver_test_data *drv,
2086 const char *dir, int ap)
2088 #ifdef DRIVER_TEST_UNIX
2089 static unsigned int counter = 0;
2090 struct sockaddr_un addr;
2091 size_t len;
2093 os_free(drv->own_socket_path);
2094 if (dir) {
2095 len = os_strlen(dir) + 30;
2096 drv->own_socket_path = os_malloc(len);
2097 if (drv->own_socket_path == NULL)
2098 return -1;
2099 os_snprintf(drv->own_socket_path, len, "%s/%s-" MACSTR,
2100 dir, ap ? "AP" : "STA", MAC2STR(drv->own_addr));
2101 } else {
2102 drv->own_socket_path = os_malloc(100);
2103 if (drv->own_socket_path == NULL)
2104 return -1;
2105 os_snprintf(drv->own_socket_path, 100,
2106 "/tmp/wpa_supplicant_test-%d-%d",
2107 getpid(), counter++);
2110 drv->test_socket = socket(PF_UNIX, SOCK_DGRAM, 0);
2111 if (drv->test_socket < 0) {
2112 perror("socket(PF_UNIX)");
2113 os_free(drv->own_socket_path);
2114 drv->own_socket_path = NULL;
2115 return -1;
2118 os_memset(&addr, 0, sizeof(addr));
2119 addr.sun_family = AF_UNIX;
2120 os_strlcpy(addr.sun_path, drv->own_socket_path, sizeof(addr.sun_path));
2121 if (bind(drv->test_socket, (struct sockaddr *) &addr,
2122 sizeof(addr)) < 0) {
2123 perror("bind(PF_UNIX)");
2124 close(drv->test_socket);
2125 unlink(drv->own_socket_path);
2126 os_free(drv->own_socket_path);
2127 drv->own_socket_path = NULL;
2128 return -1;
2131 eloop_register_read_sock(drv->test_socket,
2132 wpa_driver_test_receive_unix, drv, NULL);
2134 return 0;
2135 #else /* DRIVER_TEST_UNIX */
2136 return -1;
2137 #endif /* DRIVER_TEST_UNIX */
2141 static int wpa_driver_test_attach_udp(struct wpa_driver_test_data *drv,
2142 char *dst)
2144 char *pos;
2146 pos = os_strchr(dst, ':');
2147 if (pos == NULL)
2148 return -1;
2149 *pos++ = '\0';
2150 wpa_printf(MSG_DEBUG, "%s: addr=%s port=%s", __func__, dst, pos);
2152 drv->test_socket = socket(PF_INET, SOCK_DGRAM, 0);
2153 if (drv->test_socket < 0) {
2154 perror("socket(PF_INET)");
2155 return -1;
2158 os_memset(&drv->hostapd_addr_udp, 0, sizeof(drv->hostapd_addr_udp));
2159 drv->hostapd_addr_udp.sin_family = AF_INET;
2160 #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
2162 int a[4];
2163 u8 *pos;
2164 sscanf(dst, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
2165 pos = (u8 *) &drv->hostapd_addr_udp.sin_addr;
2166 *pos++ = a[0];
2167 *pos++ = a[1];
2168 *pos++ = a[2];
2169 *pos++ = a[3];
2171 #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
2172 inet_aton(dst, &drv->hostapd_addr_udp.sin_addr);
2173 #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
2174 drv->hostapd_addr_udp.sin_port = htons(atoi(pos));
2176 drv->hostapd_addr_udp_set = 1;
2178 eloop_register_read_sock(drv->test_socket,
2179 wpa_driver_test_receive_unix, drv, NULL);
2181 return 0;
2185 static int wpa_driver_test_set_param(void *priv, const char *param)
2187 struct wpa_driver_test_data *drv = priv;
2188 const char *pos;
2190 wpa_printf(MSG_DEBUG, "%s: param='%s'", __func__, param);
2191 if (param == NULL)
2192 return 0;
2194 wpa_driver_test_close_test_socket(drv);
2196 #ifdef DRIVER_TEST_UNIX
2197 pos = os_strstr(param, "test_socket=");
2198 if (pos) {
2199 const char *pos2;
2200 size_t len;
2202 pos += 12;
2203 pos2 = os_strchr(pos, ' ');
2204 if (pos2)
2205 len = pos2 - pos;
2206 else
2207 len = os_strlen(pos);
2208 if (len > sizeof(drv->hostapd_addr.sun_path))
2209 return -1;
2210 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
2211 drv->hostapd_addr.sun_family = AF_UNIX;
2212 os_memcpy(drv->hostapd_addr.sun_path, pos, len);
2213 drv->hostapd_addr_set = 1;
2215 #endif /* DRIVER_TEST_UNIX */
2217 pos = os_strstr(param, "test_dir=");
2218 if (pos) {
2219 char *end;
2220 os_free(drv->test_dir);
2221 drv->test_dir = os_strdup(pos + 9);
2222 if (drv->test_dir == NULL)
2223 return -1;
2224 end = os_strchr(drv->test_dir, ' ');
2225 if (end)
2226 *end = '\0';
2227 if (wpa_driver_test_attach(drv, drv->test_dir, 0))
2228 return -1;
2229 } else {
2230 pos = os_strstr(param, "test_udp=");
2231 if (pos) {
2232 char *dst, *epos;
2233 dst = os_strdup(pos + 9);
2234 if (dst == NULL)
2235 return -1;
2236 epos = os_strchr(dst, ' ');
2237 if (epos)
2238 *epos = '\0';
2239 if (wpa_driver_test_attach_udp(drv, dst))
2240 return -1;
2241 os_free(dst);
2242 } else if (wpa_driver_test_attach(drv, NULL, 0))
2243 return -1;
2246 if (os_strstr(param, "use_associnfo=1")) {
2247 wpa_printf(MSG_DEBUG, "test_driver: Use AssocInfo events");
2248 drv->use_associnfo = 1;
2251 #ifdef CONFIG_CLIENT_MLME
2252 if (os_strstr(param, "use_mlme=1")) {
2253 wpa_printf(MSG_DEBUG, "test_driver: Use internal MLME");
2254 drv->use_mlme = 1;
2256 #endif /* CONFIG_CLIENT_MLME */
2258 return 0;
2262 static const u8 * wpa_driver_test_get_mac_addr(void *priv)
2264 struct wpa_driver_test_data *drv = priv;
2265 wpa_printf(MSG_DEBUG, "%s", __func__);
2266 return drv->own_addr;
2270 static int wpa_driver_test_send_eapol(void *priv, const u8 *dest, u16 proto,
2271 const u8 *data, size_t data_len)
2273 struct wpa_driver_test_data *drv = priv;
2274 char *msg;
2275 size_t msg_len;
2276 struct l2_ethhdr eth;
2277 struct sockaddr *addr;
2278 socklen_t alen;
2279 #ifdef DRIVER_TEST_UNIX
2280 struct sockaddr_un addr_un;
2281 #endif /* DRIVER_TEST_UNIX */
2283 wpa_hexdump(MSG_MSGDUMP, "test_send_eapol TX frame", data, data_len);
2285 os_memset(&eth, 0, sizeof(eth));
2286 os_memcpy(eth.h_dest, dest, ETH_ALEN);
2287 os_memcpy(eth.h_source, drv->own_addr, ETH_ALEN);
2288 eth.h_proto = host_to_be16(proto);
2290 msg_len = 6 + sizeof(eth) + data_len;
2291 msg = os_malloc(msg_len);
2292 if (msg == NULL)
2293 return -1;
2294 os_memcpy(msg, "EAPOL ", 6);
2295 os_memcpy(msg + 6, &eth, sizeof(eth));
2296 os_memcpy(msg + 6 + sizeof(eth), data, data_len);
2298 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
2299 drv->test_dir == NULL) {
2300 if (drv->hostapd_addr_udp_set) {
2301 addr = (struct sockaddr *) &drv->hostapd_addr_udp;
2302 alen = sizeof(drv->hostapd_addr_udp);
2303 } else {
2304 #ifdef DRIVER_TEST_UNIX
2305 addr = (struct sockaddr *) &drv->hostapd_addr;
2306 alen = sizeof(drv->hostapd_addr);
2307 #else /* DRIVER_TEST_UNIX */
2308 os_free(msg);
2309 return -1;
2310 #endif /* DRIVER_TEST_UNIX */
2312 } else {
2313 #ifdef DRIVER_TEST_UNIX
2314 struct stat st;
2315 os_memset(&addr_un, 0, sizeof(addr_un));
2316 addr_un.sun_family = AF_UNIX;
2317 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2318 "%s/STA-" MACSTR, drv->test_dir, MAC2STR(dest));
2319 if (stat(addr_un.sun_path, &st) < 0) {
2320 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2321 "%s/AP-" MACSTR,
2322 drv->test_dir, MAC2STR(dest));
2324 addr = (struct sockaddr *) &addr_un;
2325 alen = sizeof(addr_un);
2326 #else /* DRIVER_TEST_UNIX */
2327 os_free(msg);
2328 return -1;
2329 #endif /* DRIVER_TEST_UNIX */
2332 if (sendto(drv->test_socket, msg, msg_len, 0, addr, alen) < 0) {
2333 perror("sendmsg(test_socket)");
2334 os_free(msg);
2335 return -1;
2338 os_free(msg);
2339 return 0;
2343 static int wpa_driver_test_get_capa(void *priv, struct wpa_driver_capa *capa)
2345 struct wpa_driver_test_data *drv = priv;
2346 os_memset(capa, 0, sizeof(*capa));
2347 capa->key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2348 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2349 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2350 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
2351 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE |
2352 WPA_DRIVER_CAPA_KEY_MGMT_FT |
2353 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2354 capa->enc = WPA_DRIVER_CAPA_ENC_WEP40 |
2355 WPA_DRIVER_CAPA_ENC_WEP104 |
2356 WPA_DRIVER_CAPA_ENC_TKIP |
2357 WPA_DRIVER_CAPA_ENC_CCMP;
2358 capa->auth = WPA_DRIVER_AUTH_OPEN |
2359 WPA_DRIVER_AUTH_SHARED |
2360 WPA_DRIVER_AUTH_LEAP;
2361 if (drv->use_mlme)
2362 capa->flags |= WPA_DRIVER_FLAGS_USER_SPACE_MLME;
2363 capa->flags |= WPA_DRIVER_FLAGS_AP;
2364 capa->max_scan_ssids = 2;
2366 return 0;
2370 static int wpa_driver_test_mlme_setprotection(void *priv, const u8 *addr,
2371 int protect_type,
2372 int key_type)
2374 wpa_printf(MSG_DEBUG, "%s: protect_type=%d key_type=%d",
2375 __func__, protect_type, key_type);
2377 if (addr) {
2378 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR,
2379 __func__, MAC2STR(addr));
2382 return 0;
2386 static int wpa_driver_test_set_channel(void *priv,
2387 enum hostapd_hw_mode phymode,
2388 int chan, int freq)
2390 struct wpa_driver_test_data *drv = priv;
2391 wpa_printf(MSG_DEBUG, "%s: phymode=%d chan=%d freq=%d",
2392 __func__, phymode, chan, freq);
2393 drv->current_freq = freq;
2394 return 0;
2398 static int wpa_driver_test_mlme_add_sta(void *priv, const u8 *addr,
2399 const u8 *supp_rates,
2400 size_t supp_rates_len)
2402 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2403 return 0;
2407 static int wpa_driver_test_mlme_remove_sta(void *priv, const u8 *addr)
2409 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2410 return 0;
2414 static int wpa_driver_test_set_ssid(void *priv, const u8 *ssid,
2415 size_t ssid_len)
2417 wpa_printf(MSG_DEBUG, "%s", __func__);
2418 return 0;
2422 static int wpa_driver_test_set_bssid(void *priv, const u8 *bssid)
2424 wpa_printf(MSG_DEBUG, "%s: bssid=" MACSTR, __func__, MAC2STR(bssid));
2425 return 0;
2429 static void * wpa_driver_test_global_init(void)
2431 struct wpa_driver_test_global *global;
2433 global = os_zalloc(sizeof(*global));
2434 return global;
2438 static void wpa_driver_test_global_deinit(void *priv)
2440 struct wpa_driver_test_global *global = priv;
2441 os_free(global);
2445 static struct wpa_interface_info *
2446 wpa_driver_test_get_interfaces(void *global_priv)
2448 /* struct wpa_driver_test_global *global = priv; */
2449 struct wpa_interface_info *iface;
2451 iface = os_zalloc(sizeof(*iface));
2452 if (iface == NULL)
2453 return iface;
2454 iface->ifname = os_strdup("sta0");
2455 iface->desc = os_strdup("test interface 0");
2456 iface->drv_name = "test";
2457 iface->next = os_zalloc(sizeof(*iface));
2458 if (iface->next) {
2459 iface->next->ifname = os_strdup("sta1");
2460 iface->next->desc = os_strdup("test interface 1");
2461 iface->next->drv_name = "test";
2464 return iface;
2468 static struct hostapd_hw_modes *
2469 wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
2471 struct hostapd_hw_modes *modes;
2472 size_t i;
2474 *num_modes = 3;
2475 *flags = 0;
2476 modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
2477 if (modes == NULL)
2478 return NULL;
2479 modes[0].mode = HOSTAPD_MODE_IEEE80211G;
2480 modes[0].num_channels = 11;
2481 modes[0].num_rates = 12;
2482 modes[0].channels =
2483 os_zalloc(11 * sizeof(struct hostapd_channel_data));
2484 modes[0].rates = os_zalloc(modes[0].num_rates * sizeof(int));
2485 if (modes[0].channels == NULL || modes[0].rates == NULL)
2486 goto fail;
2487 for (i = 0; i < 11; i++) {
2488 modes[0].channels[i].chan = i + 1;
2489 modes[0].channels[i].freq = 2412 + 5 * i;
2490 modes[0].channels[i].flag = 0;
2492 modes[0].rates[0] = 10;
2493 modes[0].rates[1] = 20;
2494 modes[0].rates[2] = 55;
2495 modes[0].rates[3] = 110;
2496 modes[0].rates[4] = 60;
2497 modes[0].rates[5] = 90;
2498 modes[0].rates[6] = 120;
2499 modes[0].rates[7] = 180;
2500 modes[0].rates[8] = 240;
2501 modes[0].rates[9] = 360;
2502 modes[0].rates[10] = 480;
2503 modes[0].rates[11] = 540;
2505 modes[1].mode = HOSTAPD_MODE_IEEE80211B;
2506 modes[1].num_channels = 11;
2507 modes[1].num_rates = 4;
2508 modes[1].channels =
2509 os_zalloc(11 * sizeof(struct hostapd_channel_data));
2510 modes[1].rates = os_zalloc(modes[1].num_rates * sizeof(int));
2511 if (modes[1].channels == NULL || modes[1].rates == NULL)
2512 goto fail;
2513 for (i = 0; i < 11; i++) {
2514 modes[1].channels[i].chan = i + 1;
2515 modes[1].channels[i].freq = 2412 + 5 * i;
2516 modes[1].channels[i].flag = 0;
2518 modes[1].rates[0] = 10;
2519 modes[1].rates[1] = 20;
2520 modes[1].rates[2] = 55;
2521 modes[1].rates[3] = 110;
2523 modes[2].mode = HOSTAPD_MODE_IEEE80211A;
2524 modes[2].num_channels = 1;
2525 modes[2].num_rates = 8;
2526 modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2527 modes[2].rates = os_zalloc(modes[2].num_rates * sizeof(int));
2528 if (modes[2].channels == NULL || modes[2].rates == NULL)
2529 goto fail;
2530 modes[2].channels[0].chan = 60;
2531 modes[2].channels[0].freq = 5300;
2532 modes[2].channels[0].flag = 0;
2533 modes[2].rates[0] = 60;
2534 modes[2].rates[1] = 90;
2535 modes[2].rates[2] = 120;
2536 modes[2].rates[3] = 180;
2537 modes[2].rates[4] = 240;
2538 modes[2].rates[5] = 360;
2539 modes[2].rates[6] = 480;
2540 modes[2].rates[7] = 540;
2542 return modes;
2544 fail:
2545 if (modes) {
2546 for (i = 0; i < *num_modes; i++) {
2547 os_free(modes[i].channels);
2548 os_free(modes[i].rates);
2550 os_free(modes);
2552 return NULL;
2556 static int wpa_driver_test_set_freq(void *priv,
2557 struct hostapd_freq_params *freq)
2559 struct wpa_driver_test_data *drv = priv;
2560 wpa_printf(MSG_DEBUG, "test: set_freq %u MHz", freq->freq);
2561 drv->current_freq = freq->freq;
2562 return 0;
2566 static int wpa_driver_test_send_action(void *priv, unsigned int freq,
2567 const u8 *dst, const u8 *src,
2568 const u8 *data, size_t data_len)
2570 struct wpa_driver_test_data *drv = priv;
2571 int ret = -1;
2572 u8 *buf;
2573 struct ieee80211_hdr *hdr;
2575 wpa_printf(MSG_DEBUG, "test: Send Action frame");
2577 if ((drv->remain_on_channel_freq &&
2578 freq != drv->remain_on_channel_freq) ||
2579 (drv->remain_on_channel_freq == 0 &&
2580 freq != (unsigned int) drv->current_freq)) {
2581 wpa_printf(MSG_DEBUG, "test: Reject Action frame TX on "
2582 "unexpected channel: freq=%u MHz (current_freq=%u "
2583 "MHz, remain-on-channel freq=%u MHz)",
2584 freq, drv->current_freq,
2585 drv->remain_on_channel_freq);
2586 return -1;
2589 buf = os_zalloc(24 + data_len);
2590 if (buf == NULL)
2591 return ret;
2592 os_memcpy(buf + 24, data, data_len);
2593 hdr = (struct ieee80211_hdr *) buf;
2594 hdr->frame_control =
2595 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
2596 os_memcpy(hdr->addr1, dst, ETH_ALEN);
2597 os_memcpy(hdr->addr2, src, ETH_ALEN);
2598 os_memcpy(hdr->addr3, "\xff\xff\xff\xff\xff\xff", ETH_ALEN);
2600 ret = wpa_driver_test_send_mlme(priv, buf, 24 + data_len);
2601 os_free(buf);
2602 return ret;
2606 static int wpa_driver_test_alloc_interface_addr(void *priv, u8 *addr)
2608 struct wpa_driver_test_data *drv = priv;
2609 drv->alloc_iface_idx++;
2610 addr[0] = 0x02; /* locally administered */
2611 sha1_prf(drv->own_addr, ETH_ALEN, "hostapd test addr generation",
2612 (const u8 *) &drv->alloc_iface_idx,
2613 sizeof(drv->alloc_iface_idx),
2614 addr + 1, ETH_ALEN - 1);
2615 return 0;
2619 static void wpa_driver_test_release_interface_addr(void *priv, const u8 *addr)
2624 static void test_remain_on_channel_timeout(void *eloop_ctx, void *timeout_ctx)
2626 struct wpa_driver_test_data *drv = eloop_ctx;
2627 union wpa_event_data data;
2629 wpa_printf(MSG_DEBUG, "test: Remain-on-channel timeout");
2631 os_memset(&data, 0, sizeof(data));
2632 data.remain_on_channel.freq = drv->remain_on_channel_freq;
2633 data.remain_on_channel.duration = drv->remain_on_channel_duration;
2634 wpa_supplicant_event(drv->ctx, EVENT_CANCEL_REMAIN_ON_CHANNEL, &data);
2636 drv->remain_on_channel_freq = 0;
2640 static int wpa_driver_test_remain_on_channel(void *priv, unsigned int freq,
2641 unsigned int duration)
2643 struct wpa_driver_test_data *drv = priv;
2644 union wpa_event_data data;
2646 wpa_printf(MSG_DEBUG, "%s(freq=%u, duration=%u)",
2647 __func__, freq, duration);
2648 if (drv->remain_on_channel_freq &&
2649 drv->remain_on_channel_freq != freq) {
2650 wpa_printf(MSG_DEBUG, "test: Refuse concurrent "
2651 "remain_on_channel request");
2652 return -1;
2655 drv->remain_on_channel_freq = freq;
2656 drv->remain_on_channel_duration = duration;
2657 eloop_cancel_timeout(test_remain_on_channel_timeout, drv, NULL);
2658 eloop_register_timeout(duration / 1000, (duration % 1000) * 1000,
2659 test_remain_on_channel_timeout, drv, NULL);
2661 os_memset(&data, 0, sizeof(data));
2662 data.remain_on_channel.freq = freq;
2663 data.remain_on_channel.duration = duration;
2664 wpa_supplicant_event(drv->ctx, EVENT_REMAIN_ON_CHANNEL, &data);
2666 return 0;
2670 static int wpa_driver_test_cancel_remain_on_channel(void *priv)
2672 struct wpa_driver_test_data *drv = priv;
2673 wpa_printf(MSG_DEBUG, "%s", __func__);
2674 if (!drv->remain_on_channel_freq)
2675 return -1;
2676 drv->remain_on_channel_freq = 0;
2677 eloop_cancel_timeout(test_remain_on_channel_timeout, drv, NULL);
2678 return 0;
2682 static int wpa_driver_test_probe_req_report(void *priv, int report)
2684 struct wpa_driver_test_data *drv = priv;
2685 wpa_printf(MSG_DEBUG, "%s(report=%d)", __func__, report);
2686 drv->probe_req_report = report;
2687 return 0;
2691 const struct wpa_driver_ops wpa_driver_test_ops = {
2692 "test",
2693 "wpa_supplicant test driver",
2694 .hapd_init = test_driver_init,
2695 .hapd_deinit = wpa_driver_test_deinit,
2696 .hapd_send_eapol = test_driver_send_eapol,
2697 .send_mlme = wpa_driver_test_send_mlme,
2698 .set_generic_elem = test_driver_set_generic_elem,
2699 .sta_deauth = test_driver_sta_deauth,
2700 .sta_disassoc = test_driver_sta_disassoc,
2701 .get_hw_feature_data = wpa_driver_test_get_hw_feature_data,
2702 .if_add = test_driver_if_add,
2703 .if_remove = test_driver_if_remove,
2704 .valid_bss_mask = test_driver_valid_bss_mask,
2705 .hapd_set_ssid = test_driver_set_ssid,
2706 .set_privacy = test_driver_set_privacy,
2707 .set_sta_vlan = test_driver_set_sta_vlan,
2708 .sta_add = test_driver_sta_add,
2709 .send_ether = test_driver_send_ether,
2710 .set_ap_wps_ie = test_driver_set_ap_wps_ie,
2711 .get_bssid = wpa_driver_test_get_bssid,
2712 .get_ssid = wpa_driver_test_get_ssid,
2713 .set_key = wpa_driver_test_set_key,
2714 .deinit = wpa_driver_test_deinit,
2715 .set_param = wpa_driver_test_set_param,
2716 .deauthenticate = wpa_driver_test_deauthenticate,
2717 .disassociate = wpa_driver_test_disassociate,
2718 .associate = wpa_driver_test_associate,
2719 .get_capa = wpa_driver_test_get_capa,
2720 .get_mac_addr = wpa_driver_test_get_mac_addr,
2721 .send_eapol = wpa_driver_test_send_eapol,
2722 .mlme_setprotection = wpa_driver_test_mlme_setprotection,
2723 .set_channel = wpa_driver_test_set_channel,
2724 .set_ssid = wpa_driver_test_set_ssid,
2725 .set_bssid = wpa_driver_test_set_bssid,
2726 .mlme_add_sta = wpa_driver_test_mlme_add_sta,
2727 .mlme_remove_sta = wpa_driver_test_mlme_remove_sta,
2728 .get_scan_results2 = wpa_driver_test_get_scan_results2,
2729 .global_init = wpa_driver_test_global_init,
2730 .global_deinit = wpa_driver_test_global_deinit,
2731 .init2 = wpa_driver_test_init2,
2732 .get_interfaces = wpa_driver_test_get_interfaces,
2733 .scan2 = wpa_driver_test_scan,
2734 .set_freq = wpa_driver_test_set_freq,
2735 .send_action = wpa_driver_test_send_action,
2736 .alloc_interface_addr = wpa_driver_test_alloc_interface_addr,
2737 .release_interface_addr = wpa_driver_test_release_interface_addr,
2738 .remain_on_channel = wpa_driver_test_remain_on_channel,
2739 .cancel_remain_on_channel = wpa_driver_test_cancel_remain_on_channel,
2740 .probe_req_report = wpa_driver_test_probe_req_report,