]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/drivers/driver_test.c
Share management frame send driver op for hostapd and wpa_supplicant
[thirdparty/hostap.git] / src / drivers / driver_test.c
1 /*
2 * WPA Supplicant - testing driver interface
3 * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
4 *
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.
8 *
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
11 *
12 * See README and COPYING for more details.
13 */
14
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 */
20
21 #include "includes.h"
22
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 */
29
30 #include "common.h"
31 #include "driver.h"
32 #include "l2_packet/l2_packet.h"
33 #include "eloop.h"
34 #include "sha1.h"
35 #include "ieee802_11_defs.h"
36
37
38 #ifdef HOSTAPD
39
40 #include "../../hostapd/hostapd.h"
41 #include "../../hostapd/config.h"
42 #include "../../hostapd/wpa.h"
43 #include "../../hostapd/hw_features.h"
44 #include "../../hostapd/wps_hostapd.h"
45
46
47 struct test_client_socket {
48 struct test_client_socket *next;
49 u8 addr[ETH_ALEN];
50 struct sockaddr_un un;
51 socklen_t unlen;
52 struct test_driver_bss *bss;
53 };
54
55 struct test_driver_bss {
56 struct test_driver_bss *next;
57 char ifname[IFNAMSIZ + 1];
58 u8 bssid[ETH_ALEN];
59 u8 *ie;
60 size_t ielen;
61 u8 *wps_beacon_ie;
62 size_t wps_beacon_ie_len;
63 u8 *wps_probe_resp_ie;
64 size_t wps_probe_resp_ie_len;
65 u8 ssid[32];
66 size_t ssid_len;
67 int privacy;
68 };
69
70 struct test_driver_data {
71 struct hostapd_data *hapd;
72 struct test_client_socket *cli;
73 int test_socket;
74 struct test_driver_bss *bss;
75 char *socket_dir;
76 char *own_socket_path;
77 int udp_port;
78 };
79
80 #else /* HOSTAPD */
81
82 struct wpa_driver_test_global {
83 int dummy;
84 };
85
86 struct wpa_driver_test_data {
87 struct wpa_driver_test_global *global;
88 void *ctx;
89 u8 own_addr[ETH_ALEN];
90 int test_socket;
91 #ifdef DRIVER_TEST_UNIX
92 struct sockaddr_un hostapd_addr;
93 #endif /* DRIVER_TEST_UNIX */
94 int hostapd_addr_set;
95 struct sockaddr_in hostapd_addr_udp;
96 int hostapd_addr_udp_set;
97 char *own_socket_path;
98 char *test_dir;
99 u8 bssid[ETH_ALEN];
100 u8 ssid[32];
101 size_t ssid_len;
102 #define MAX_SCAN_RESULTS 30
103 struct wpa_scan_res *scanres[MAX_SCAN_RESULTS];
104 size_t num_scanres;
105 int use_associnfo;
106 u8 assoc_wpa_ie[80];
107 size_t assoc_wpa_ie_len;
108 int use_mlme;
109 int associated;
110 u8 *probe_req_ie;
111 size_t probe_req_ie_len;
112 int ibss;
113 int privacy;
114 };
115
116 #endif /* HOSTAPD */
117
118
119 #ifdef HOSTAPD
120
121 static void test_driver_free_bss(struct test_driver_bss *bss)
122 {
123 free(bss->ie);
124 free(bss->wps_beacon_ie);
125 free(bss->wps_probe_resp_ie);
126 free(bss);
127 }
128
129
130 static void test_driver_free_priv(struct test_driver_data *drv)
131 {
132 struct test_driver_bss *bss, *prev;
133
134 if (drv == NULL)
135 return;
136
137 bss = drv->bss;
138 while (bss) {
139 prev = bss;
140 bss = bss->next;
141 test_driver_free_bss(prev);
142 }
143 free(drv->own_socket_path);
144 free(drv->socket_dir);
145 free(drv);
146 }
147
148
149 static struct test_client_socket *
150 test_driver_get_cli(struct test_driver_data *drv, struct sockaddr_un *from,
151 socklen_t fromlen)
152 {
153 struct test_client_socket *cli = drv->cli;
154
155 while (cli) {
156 if (cli->unlen == fromlen &&
157 strncmp(cli->un.sun_path, from->sun_path,
158 fromlen - sizeof(cli->un.sun_family)) == 0)
159 return cli;
160 cli = cli->next;
161 }
162
163 return NULL;
164 }
165
166
167 static int test_driver_send_eapol(void *priv, const u8 *addr, const u8 *data,
168 size_t data_len, int encrypt,
169 const u8 *own_addr)
170 {
171 struct test_driver_data *drv = priv;
172 struct test_client_socket *cli;
173 struct msghdr msg;
174 struct iovec io[3];
175 struct l2_ethhdr eth;
176
177 if (drv->test_socket < 0)
178 return -1;
179
180 cli = drv->cli;
181 while (cli) {
182 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
183 break;
184 cli = cli->next;
185 }
186
187 if (!cli) {
188 wpa_printf(MSG_DEBUG, "%s: no destination client entry",
189 __func__);
190 return -1;
191 }
192
193 memcpy(eth.h_dest, addr, ETH_ALEN);
194 memcpy(eth.h_source, own_addr, ETH_ALEN);
195 eth.h_proto = host_to_be16(ETH_P_EAPOL);
196
197 io[0].iov_base = "EAPOL ";
198 io[0].iov_len = 6;
199 io[1].iov_base = &eth;
200 io[1].iov_len = sizeof(eth);
201 io[2].iov_base = (u8 *) data;
202 io[2].iov_len = data_len;
203
204 memset(&msg, 0, sizeof(msg));
205 msg.msg_iov = io;
206 msg.msg_iovlen = 3;
207 msg.msg_name = &cli->un;
208 msg.msg_namelen = cli->unlen;
209 return sendmsg(drv->test_socket, &msg, 0);
210 }
211
212
213 static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
214 u16 proto, const u8 *data, size_t data_len)
215 {
216 struct test_driver_data *drv = priv;
217 struct msghdr msg;
218 struct iovec io[3];
219 struct l2_ethhdr eth;
220 char desttxt[30];
221 struct sockaddr_un addr;
222 struct dirent *dent;
223 DIR *dir;
224 int ret = 0, broadcast = 0, count = 0;
225
226 if (drv->test_socket < 0 || drv->socket_dir == NULL) {
227 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d "
228 "socket_dir=%p)",
229 __func__, drv->test_socket, drv->socket_dir);
230 return -1;
231 }
232
233 broadcast = memcmp(dst, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
234 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dst));
235
236 memcpy(eth.h_dest, dst, ETH_ALEN);
237 memcpy(eth.h_source, src, ETH_ALEN);
238 eth.h_proto = host_to_be16(proto);
239
240 io[0].iov_base = "ETHER ";
241 io[0].iov_len = 6;
242 io[1].iov_base = &eth;
243 io[1].iov_len = sizeof(eth);
244 io[2].iov_base = (u8 *) data;
245 io[2].iov_len = data_len;
246
247 memset(&msg, 0, sizeof(msg));
248 msg.msg_iov = io;
249 msg.msg_iovlen = 3;
250
251 dir = opendir(drv->socket_dir);
252 if (dir == NULL) {
253 perror("test_driver: opendir");
254 return -1;
255 }
256 while ((dent = readdir(dir))) {
257 #ifdef _DIRENT_HAVE_D_TYPE
258 /* Skip the file if it is not a socket. Also accept
259 * DT_UNKNOWN (0) in case the C library or underlying file
260 * system does not support d_type. */
261 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
262 continue;
263 #endif /* _DIRENT_HAVE_D_TYPE */
264 if (strcmp(dent->d_name, ".") == 0 ||
265 strcmp(dent->d_name, "..") == 0)
266 continue;
267
268 memset(&addr, 0, sizeof(addr));
269 addr.sun_family = AF_UNIX;
270 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
271 drv->socket_dir, dent->d_name);
272
273 if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
274 continue;
275 if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
276 continue;
277
278 wpa_printf(MSG_DEBUG, "%s: Send ether frame to %s",
279 __func__, dent->d_name);
280
281 msg.msg_name = &addr;
282 msg.msg_namelen = sizeof(addr);
283 ret = sendmsg(drv->test_socket, &msg, 0);
284 if (ret < 0)
285 perror("driver_test: sendmsg");
286 count++;
287 }
288 closedir(dir);
289
290 if (!broadcast && count == 0) {
291 wpa_printf(MSG_DEBUG, "%s: Destination " MACSTR " not found",
292 __func__, MAC2STR(dst));
293 return -1;
294 }
295
296 return ret;
297 }
298
299
300 static int wpa_driver_test_send_mlme(void *priv, const u8 *buf, size_t len)
301 {
302 struct test_driver_data *drv = priv;
303 struct msghdr msg;
304 struct iovec io[2];
305 const u8 *dest;
306 int ret = 0, broadcast = 0;
307 char desttxt[30];
308 struct sockaddr_un addr;
309 struct dirent *dent;
310 DIR *dir;
311 struct ieee80211_hdr *hdr;
312 u16 fc;
313
314 if (drv->test_socket < 0 || len < 10 || drv->socket_dir == NULL) {
315 wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d len=%lu"
316 " socket_dir=%p)",
317 __func__, drv->test_socket, (unsigned long) len,
318 drv->socket_dir);
319 return -1;
320 }
321
322 dest = buf;
323 dest += 4;
324 broadcast = memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
325 snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dest));
326
327 io[0].iov_base = "MLME ";
328 io[0].iov_len = 5;
329 io[1].iov_base = (void *) buf;
330 io[1].iov_len = len;
331
332 memset(&msg, 0, sizeof(msg));
333 msg.msg_iov = io;
334 msg.msg_iovlen = 2;
335
336 dir = opendir(drv->socket_dir);
337 if (dir == NULL) {
338 perror("test_driver: opendir");
339 return -1;
340 }
341 while ((dent = readdir(dir))) {
342 #ifdef _DIRENT_HAVE_D_TYPE
343 /* Skip the file if it is not a socket. Also accept
344 * DT_UNKNOWN (0) in case the C library or underlying file
345 * system does not support d_type. */
346 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
347 continue;
348 #endif /* _DIRENT_HAVE_D_TYPE */
349 if (strcmp(dent->d_name, ".") == 0 ||
350 strcmp(dent->d_name, "..") == 0)
351 continue;
352
353 memset(&addr, 0, sizeof(addr));
354 addr.sun_family = AF_UNIX;
355 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
356 drv->socket_dir, dent->d_name);
357
358 if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
359 continue;
360 if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
361 continue;
362
363 wpa_printf(MSG_DEBUG, "%s: Send management frame to %s",
364 __func__, dent->d_name);
365
366 msg.msg_name = &addr;
367 msg.msg_namelen = sizeof(addr);
368 ret = sendmsg(drv->test_socket, &msg, 0);
369 if (ret < 0)
370 perror("driver_test: sendmsg");
371 }
372 closedir(dir);
373
374 hdr = (struct ieee80211_hdr *) buf;
375 fc = le_to_host16(hdr->frame_control);
376 hostapd_mgmt_tx_cb(drv->hapd, (u8 *) buf, len, WLAN_FC_GET_STYPE(fc),
377 ret >= 0);
378
379 return ret;
380 }
381
382
383 static void test_driver_scan(struct test_driver_data *drv,
384 struct sockaddr_un *from, socklen_t fromlen,
385 char *data)
386 {
387 char buf[512], *pos, *end;
388 int ret;
389 struct test_driver_bss *bss;
390 u8 sa[ETH_ALEN];
391 u8 ie[512];
392 size_t ielen;
393
394 /* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
395
396 wpa_printf(MSG_DEBUG, "test_driver: SCAN");
397
398 if (*data) {
399 if (*data != ' ' ||
400 hwaddr_aton(data + 1, sa)) {
401 wpa_printf(MSG_DEBUG, "test_driver: Unexpected SCAN "
402 "command format");
403 return;
404 }
405
406 data += 18;
407 while (*data == ' ')
408 data++;
409 ielen = os_strlen(data) / 2;
410 if (ielen > sizeof(ie))
411 ielen = sizeof(ie);
412 if (hexstr2bin(data, ie, ielen) < 0)
413 ielen = 0;
414
415 wpa_printf(MSG_DEBUG, "test_driver: Scan from " MACSTR,
416 MAC2STR(sa));
417 wpa_hexdump(MSG_MSGDUMP, "test_driver: scan IEs", ie, ielen);
418
419 hostapd_wps_probe_req_rx(drv->hapd, sa, ie, ielen);
420 }
421
422 for (bss = drv->bss; bss; bss = bss->next) {
423 pos = buf;
424 end = buf + sizeof(buf);
425
426 /* reply: SCANRESP BSSID SSID IEs */
427 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
428 MAC2STR(bss->bssid));
429 if (ret < 0 || ret >= end - pos)
430 return;
431 pos += ret;
432 pos += wpa_snprintf_hex(pos, end - pos,
433 bss->ssid, bss->ssid_len);
434 ret = snprintf(pos, end - pos, " ");
435 if (ret < 0 || ret >= end - pos)
436 return;
437 pos += ret;
438 pos += wpa_snprintf_hex(pos, end - pos, bss->ie, bss->ielen);
439 pos += wpa_snprintf_hex(pos, end - pos, bss->wps_probe_resp_ie,
440 bss->wps_probe_resp_ie_len);
441
442 if (bss->privacy) {
443 ret = snprintf(pos, end - pos, " PRIVACY");
444 if (ret < 0 || ret >= end - pos)
445 return;
446 pos += ret;
447 }
448
449 sendto(drv->test_socket, buf, pos - buf, 0,
450 (struct sockaddr *) from, fromlen);
451 }
452 }
453
454
455 static struct hostapd_data * test_driver_get_hapd(struct test_driver_data *drv,
456 struct test_driver_bss *bss)
457 {
458 struct hostapd_iface *iface = drv->hapd->iface;
459 struct hostapd_data *hapd = NULL;
460 size_t i;
461
462 if (bss == NULL) {
463 wpa_printf(MSG_DEBUG, "%s: bss == NULL", __func__);
464 return NULL;
465 }
466
467 for (i = 0; i < iface->num_bss; i++) {
468 hapd = iface->bss[i];
469 if (memcmp(hapd->own_addr, bss->bssid, ETH_ALEN) == 0)
470 break;
471 }
472 if (i == iface->num_bss) {
473 wpa_printf(MSG_DEBUG, "%s: no matching interface entry found "
474 "for BSSID " MACSTR, __func__, MAC2STR(bss->bssid));
475 return NULL;
476 }
477
478 return hapd;
479 }
480
481
482 static int test_driver_new_sta(struct test_driver_data *drv,
483 struct test_driver_bss *bss, const u8 *addr,
484 const u8 *ie, size_t ielen)
485 {
486 struct hostapd_data *hapd;
487
488 hapd = test_driver_get_hapd(drv, bss);
489 if (hapd == NULL)
490 return -1;
491
492 return hostapd_notif_assoc(hapd, addr, ie, ielen);
493 }
494
495
496 static void test_driver_assoc(struct test_driver_data *drv,
497 struct sockaddr_un *from, socklen_t fromlen,
498 char *data)
499 {
500 struct test_client_socket *cli;
501 u8 ie[256], ssid[32];
502 size_t ielen, ssid_len = 0;
503 char *pos, *pos2, cmd[50];
504 struct test_driver_bss *bss;
505
506 /* data: STA-addr SSID(hex) IEs(hex) */
507
508 cli = os_zalloc(sizeof(*cli));
509 if (cli == NULL)
510 return;
511
512 if (hwaddr_aton(data, cli->addr)) {
513 printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
514 data);
515 free(cli);
516 return;
517 }
518 pos = data + 17;
519 while (*pos == ' ')
520 pos++;
521 pos2 = strchr(pos, ' ');
522 ielen = 0;
523 if (pos2) {
524 ssid_len = (pos2 - pos) / 2;
525 if (hexstr2bin(pos, ssid, ssid_len) < 0) {
526 wpa_printf(MSG_DEBUG, "%s: Invalid SSID", __func__);
527 free(cli);
528 return;
529 }
530 wpa_hexdump_ascii(MSG_DEBUG, "test_driver_assoc: SSID",
531 ssid, ssid_len);
532
533 pos = pos2 + 1;
534 ielen = strlen(pos) / 2;
535 if (ielen > sizeof(ie))
536 ielen = sizeof(ie);
537 if (hexstr2bin(pos, ie, ielen) < 0)
538 ielen = 0;
539 }
540
541 for (bss = drv->bss; bss; bss = bss->next) {
542 if (bss->ssid_len == ssid_len &&
543 memcmp(bss->ssid, ssid, ssid_len) == 0)
544 break;
545 }
546 if (bss == NULL) {
547 wpa_printf(MSG_DEBUG, "%s: No matching SSID found from "
548 "configured BSSes", __func__);
549 free(cli);
550 return;
551 }
552
553 cli->bss = bss;
554 memcpy(&cli->un, from, sizeof(cli->un));
555 cli->unlen = fromlen;
556 cli->next = drv->cli;
557 drv->cli = cli;
558 wpa_hexdump_ascii(MSG_DEBUG, "test_socket: ASSOC sun_path",
559 (const u8 *) cli->un.sun_path,
560 cli->unlen - sizeof(cli->un.sun_family));
561
562 snprintf(cmd, sizeof(cmd), "ASSOCRESP " MACSTR " 0",
563 MAC2STR(bss->bssid));
564 sendto(drv->test_socket, cmd, strlen(cmd), 0,
565 (struct sockaddr *) from, fromlen);
566
567 if (test_driver_new_sta(drv, bss, cli->addr, ie, ielen) < 0) {
568 wpa_printf(MSG_DEBUG, "test_driver: failed to add new STA");
569 }
570 }
571
572
573 static void test_driver_disassoc(struct test_driver_data *drv,
574 struct sockaddr_un *from, socklen_t fromlen)
575 {
576 struct test_client_socket *cli;
577
578 cli = test_driver_get_cli(drv, from, fromlen);
579 if (!cli)
580 return;
581
582 hostapd_notif_disassoc(drv->hapd, cli->addr);
583 }
584
585
586 static void test_driver_eapol(struct test_driver_data *drv,
587 struct sockaddr_un *from, socklen_t fromlen,
588 u8 *data, size_t datalen)
589 {
590 struct test_client_socket *cli;
591 if (datalen > 14) {
592 /* Skip Ethernet header */
593 wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
594 MACSTR " proto=%04x",
595 MAC2STR(data), MAC2STR(data + ETH_ALEN),
596 WPA_GET_BE16(data + 2 * ETH_ALEN));
597 data += 14;
598 datalen -= 14;
599 }
600 cli = test_driver_get_cli(drv, from, fromlen);
601 if (cli) {
602 struct hostapd_data *hapd;
603 hapd = test_driver_get_hapd(drv, cli->bss);
604 if (hapd == NULL)
605 return;
606 hostapd_eapol_receive(hapd, cli->addr, data, datalen);
607 } else {
608 wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
609 "client");
610 }
611 }
612
613
614 static void test_driver_ether(struct test_driver_data *drv,
615 struct sockaddr_un *from, socklen_t fromlen,
616 u8 *data, size_t datalen)
617 {
618 struct l2_ethhdr *eth;
619
620 if (datalen < sizeof(*eth))
621 return;
622
623 eth = (struct l2_ethhdr *) data;
624 wpa_printf(MSG_DEBUG, "test_driver: RX ETHER dst=" MACSTR " src="
625 MACSTR " proto=%04x",
626 MAC2STR(eth->h_dest), MAC2STR(eth->h_source),
627 be_to_host16(eth->h_proto));
628
629 #ifdef CONFIG_IEEE80211R
630 if (be_to_host16(eth->h_proto) == ETH_P_RRB) {
631 wpa_ft_rrb_rx(drv->hapd->wpa_auth, eth->h_source,
632 data + sizeof(*eth), datalen - sizeof(*eth));
633 }
634 #endif /* CONFIG_IEEE80211R */
635 }
636
637
638 static void test_driver_mlme(struct test_driver_data *drv,
639 struct sockaddr_un *from, socklen_t fromlen,
640 u8 *data, size_t datalen)
641 {
642 struct ieee80211_hdr *hdr;
643 u16 fc;
644
645 hdr = (struct ieee80211_hdr *) data;
646
647 if (test_driver_get_cli(drv, from, fromlen) == NULL && datalen >= 16) {
648 struct test_client_socket *cli;
649 cli = os_zalloc(sizeof(*cli));
650 if (cli == NULL)
651 return;
652 wpa_printf(MSG_DEBUG, "Adding client entry for " MACSTR,
653 MAC2STR(hdr->addr2));
654 memcpy(cli->addr, hdr->addr2, ETH_ALEN);
655 memcpy(&cli->un, from, sizeof(cli->un));
656 cli->unlen = fromlen;
657 cli->next = drv->cli;
658 drv->cli = cli;
659 }
660
661 wpa_hexdump(MSG_MSGDUMP, "test_driver_mlme: received frame",
662 data, datalen);
663 fc = le_to_host16(hdr->frame_control);
664 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT) {
665 wpa_printf(MSG_ERROR, "%s: received non-mgmt frame",
666 __func__);
667 return;
668 }
669 hostapd_mgmt_rx(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
670 }
671
672
673 static void test_driver_receive_unix(int sock, void *eloop_ctx, void *sock_ctx)
674 {
675 struct test_driver_data *drv = eloop_ctx;
676 char buf[2000];
677 int res;
678 struct sockaddr_un from;
679 socklen_t fromlen = sizeof(from);
680
681 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
682 (struct sockaddr *) &from, &fromlen);
683 if (res < 0) {
684 perror("recvfrom(test_socket)");
685 return;
686 }
687 buf[res] = '\0';
688
689 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
690
691 if (strncmp(buf, "SCAN", 4) == 0) {
692 test_driver_scan(drv, &from, fromlen, buf + 4);
693 } else if (strncmp(buf, "ASSOC ", 6) == 0) {
694 test_driver_assoc(drv, &from, fromlen, buf + 6);
695 } else if (strcmp(buf, "DISASSOC") == 0) {
696 test_driver_disassoc(drv, &from, fromlen);
697 } else if (strncmp(buf, "EAPOL ", 6) == 0) {
698 test_driver_eapol(drv, &from, fromlen, (u8 *) buf + 6,
699 res - 6);
700 } else if (strncmp(buf, "ETHER ", 6) == 0) {
701 test_driver_ether(drv, &from, fromlen, (u8 *) buf + 6,
702 res - 6);
703 } else if (strncmp(buf, "MLME ", 5) == 0) {
704 test_driver_mlme(drv, &from, fromlen, (u8 *) buf + 5, res - 5);
705 } else {
706 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
707 (u8 *) buf, res);
708 }
709 }
710
711
712 static struct test_driver_bss *
713 test_driver_get_bss(struct test_driver_data *drv, const char *ifname)
714 {
715 struct test_driver_bss *bss;
716
717 for (bss = drv->bss; bss; bss = bss->next) {
718 if (strcmp(bss->ifname, ifname) == 0)
719 return bss;
720 }
721 return NULL;
722 }
723
724
725 static int test_driver_set_generic_elem(const char *ifname, void *priv,
726 const u8 *elem, size_t elem_len)
727 {
728 struct test_driver_data *drv = priv;
729 struct test_driver_bss *bss;
730
731 bss = test_driver_get_bss(drv, ifname);
732 if (bss == NULL)
733 return -1;
734
735 free(bss->ie);
736
737 if (elem == NULL) {
738 bss->ie = NULL;
739 bss->ielen = 0;
740 return 0;
741 }
742
743 bss->ie = malloc(elem_len);
744 if (bss->ie == NULL) {
745 bss->ielen = 0;
746 return -1;
747 }
748
749 memcpy(bss->ie, elem, elem_len);
750 bss->ielen = elem_len;
751 return 0;
752 }
753
754
755 static int test_driver_set_wps_beacon_ie(const char *ifname, void *priv,
756 const u8 *ie, size_t len)
757 {
758 struct test_driver_data *drv = priv;
759 struct test_driver_bss *bss;
760
761 wpa_hexdump(MSG_DEBUG, "test_driver: Beacon WPS IE", ie, len);
762 bss = test_driver_get_bss(drv, ifname);
763 if (bss == NULL)
764 return -1;
765
766 free(bss->wps_beacon_ie);
767
768 if (ie == NULL) {
769 bss->wps_beacon_ie = NULL;
770 bss->wps_beacon_ie_len = 0;
771 return 0;
772 }
773
774 bss->wps_beacon_ie = malloc(len);
775 if (bss->wps_beacon_ie == NULL) {
776 bss->wps_beacon_ie_len = 0;
777 return -1;
778 }
779
780 memcpy(bss->wps_beacon_ie, ie, len);
781 bss->wps_beacon_ie_len = len;
782 return 0;
783 }
784
785
786 static int test_driver_set_wps_probe_resp_ie(const char *ifname, void *priv,
787 const u8 *ie, size_t len)
788 {
789 struct test_driver_data *drv = priv;
790 struct test_driver_bss *bss;
791
792 wpa_hexdump(MSG_DEBUG, "test_driver: ProbeResp WPS IE", ie, len);
793 bss = test_driver_get_bss(drv, ifname);
794 if (bss == NULL)
795 return -1;
796
797 free(bss->wps_probe_resp_ie);
798
799 if (ie == NULL) {
800 bss->wps_probe_resp_ie = NULL;
801 bss->wps_probe_resp_ie_len = 0;
802 return 0;
803 }
804
805 bss->wps_probe_resp_ie = malloc(len);
806 if (bss->wps_probe_resp_ie == NULL) {
807 bss->wps_probe_resp_ie_len = 0;
808 return -1;
809 }
810
811 memcpy(bss->wps_probe_resp_ie, ie, len);
812 bss->wps_probe_resp_ie_len = len;
813 return 0;
814 }
815
816
817 static int test_driver_sta_deauth(void *priv, const u8 *addr, int reason)
818 {
819 struct test_driver_data *drv = priv;
820 struct test_client_socket *cli;
821
822 if (drv->test_socket < 0)
823 return -1;
824
825 cli = drv->cli;
826 while (cli) {
827 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
828 break;
829 cli = cli->next;
830 }
831
832 if (!cli)
833 return -1;
834
835 return sendto(drv->test_socket, "DEAUTH", 6, 0,
836 (struct sockaddr *) &cli->un, cli->unlen);
837 }
838
839
840 static int test_driver_sta_disassoc(void *priv, const u8 *addr, int reason)
841 {
842 struct test_driver_data *drv = priv;
843 struct test_client_socket *cli;
844
845 if (drv->test_socket < 0)
846 return -1;
847
848 cli = drv->cli;
849 while (cli) {
850 if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
851 break;
852 cli = cli->next;
853 }
854
855 if (!cli)
856 return -1;
857
858 return sendto(drv->test_socket, "DISASSOC", 8, 0,
859 (struct sockaddr *) &cli->un, cli->unlen);
860 }
861
862
863 static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
864 {
865 struct test_driver_data *drv = priv;
866 struct test_driver_bss *bss;
867
868 wpa_printf(MSG_DEBUG, "%s(ifname=%s bssid=" MACSTR ")",
869 __func__, ifname, MAC2STR(bssid));
870
871 bss = os_zalloc(sizeof(*bss));
872 if (bss == NULL)
873 return -1;
874
875 os_strlcpy(bss->ifname, ifname, IFNAMSIZ);
876 memcpy(bss->bssid, bssid, ETH_ALEN);
877
878 bss->next = drv->bss;
879 drv->bss = bss;
880
881 return 0;
882 }
883
884
885 static int test_driver_bss_remove(void *priv, const char *ifname)
886 {
887 struct test_driver_data *drv = priv;
888 struct test_driver_bss *bss, *prev;
889 struct test_client_socket *cli, *prev_c;
890
891 wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
892
893 for (prev = NULL, bss = drv->bss; bss; prev = bss, bss = bss->next) {
894 if (strcmp(bss->ifname, ifname) != 0)
895 continue;
896
897 if (prev)
898 prev->next = bss->next;
899 else
900 drv->bss = bss->next;
901
902 for (prev_c = NULL, cli = drv->cli; cli;
903 prev_c = cli, cli = cli->next) {
904 if (cli->bss != bss)
905 continue;
906 if (prev_c)
907 prev_c->next = cli->next;
908 else
909 drv->cli = cli->next;
910 free(cli);
911 break;
912 }
913
914 test_driver_free_bss(bss);
915 return 0;
916 }
917
918 return -1;
919 }
920
921
922 static int test_driver_if_add(const char *iface, void *priv,
923 enum hostapd_driver_if_type type, char *ifname,
924 const u8 *addr)
925 {
926 wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s)",
927 __func__, iface, type, ifname);
928 return 0;
929 }
930
931
932 static int test_driver_if_update(void *priv, enum hostapd_driver_if_type type,
933 char *ifname, const u8 *addr)
934 {
935 wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
936 return 0;
937 }
938
939
940 static int test_driver_if_remove(void *priv, enum hostapd_driver_if_type type,
941 const char *ifname, const u8 *addr)
942 {
943 wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
944 return 0;
945 }
946
947
948 static int test_driver_valid_bss_mask(void *priv, const u8 *addr,
949 const u8 *mask)
950 {
951 return 0;
952 }
953
954
955 static int test_driver_set_ssid(const char *ifname, void *priv, const u8 *buf,
956 int len)
957 {
958 struct test_driver_data *drv = priv;
959 struct test_driver_bss *bss;
960
961 wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
962 wpa_hexdump_ascii(MSG_DEBUG, "test_driver_set_ssid: SSID", buf, len);
963
964 for (bss = drv->bss; bss; bss = bss->next) {
965 if (strcmp(bss->ifname, ifname) != 0)
966 continue;
967
968 if (len < 0 || (size_t) len > sizeof(bss->ssid))
969 return -1;
970
971 memcpy(bss->ssid, buf, len);
972 bss->ssid_len = len;
973
974 return 0;
975 }
976
977 return -1;
978 }
979
980
981 static int test_driver_set_privacy(const char *ifname, void *priv, int enabled)
982 {
983 struct test_driver_data *drv = priv;
984 struct test_driver_bss *bss;
985
986 wpa_printf(MSG_DEBUG, "%s(ifname=%s enabled=%d)",
987 __func__, ifname, enabled);
988
989 for (bss = drv->bss; bss; bss = bss->next) {
990 if (strcmp(bss->ifname, ifname) != 0)
991 continue;
992
993 bss->privacy = enabled;
994
995 return 0;
996 }
997
998 return -1;
999 }
1000
1001
1002 static int test_driver_set_key(const char *iface, void *priv, wpa_alg alg,
1003 const u8 *addr, int key_idx, int set_tx,
1004 const u8 *seq, size_t seq_len,
1005 const u8 *key, size_t key_len)
1006 {
1007 wpa_printf(MSG_DEBUG, "%s(iface=%s alg=%d idx=%d set_tx=%d)",
1008 __func__, iface, alg, key_idx, set_tx);
1009 if (addr)
1010 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
1011 if (key)
1012 wpa_hexdump_key(MSG_DEBUG, " key", key, key_len);
1013 return 0;
1014 }
1015
1016
1017 static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
1018 const char *ifname, int vlan_id)
1019 {
1020 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " ifname=%s vlan_id=%d)",
1021 __func__, MAC2STR(addr), ifname, vlan_id);
1022 return 0;
1023 }
1024
1025
1026 static int test_driver_sta_add(const char *ifname, void *priv,
1027 struct hostapd_sta_add_params *params)
1028 {
1029 struct test_driver_data *drv = priv;
1030 struct test_client_socket *cli;
1031 struct test_driver_bss *bss;
1032
1033 wpa_printf(MSG_DEBUG, "%s(ifname=%s addr=" MACSTR " aid=%d "
1034 "capability=0x%x flags=0x%x listen_interval=%d)",
1035 __func__, ifname, MAC2STR(params->addr), params->aid,
1036 params->capability, params->flags,
1037 params->listen_interval);
1038 wpa_hexdump(MSG_DEBUG, "test_driver_sta_add - supp_rates",
1039 params->supp_rates, params->supp_rates_len);
1040
1041 cli = drv->cli;
1042 while (cli) {
1043 if (os_memcmp(cli->addr, params->addr, ETH_ALEN) == 0)
1044 break;
1045 cli = cli->next;
1046 }
1047 if (!cli) {
1048 wpa_printf(MSG_DEBUG, "%s: no matching client entry",
1049 __func__);
1050 return -1;
1051 }
1052
1053 for (bss = drv->bss; bss; bss = bss->next) {
1054 if (strcmp(ifname, bss->ifname) == 0)
1055 break;
1056 }
1057 if (bss == NULL) {
1058 wpa_printf(MSG_DEBUG, "%s: No matching interface found from "
1059 "configured BSSes", __func__);
1060 return -1;
1061 }
1062
1063 cli->bss = bss;
1064
1065 return 0;
1066 }
1067
1068
1069 static void * test_driver_init(struct hostapd_data *hapd)
1070 {
1071 struct test_driver_data *drv;
1072 struct sockaddr_un addr_un;
1073 struct sockaddr_in addr_in;
1074 struct sockaddr *addr;
1075 socklen_t alen;
1076
1077 drv = os_zalloc(sizeof(struct test_driver_data));
1078 if (drv == NULL) {
1079 printf("Could not allocate memory for test driver data\n");
1080 return NULL;
1081 }
1082 drv->bss = os_zalloc(sizeof(*drv->bss));
1083 if (drv->bss == NULL) {
1084 printf("Could not allocate memory for test driver BSS data\n");
1085 free(drv);
1086 return NULL;
1087 }
1088
1089 drv->hapd = hapd;
1090
1091 /* Generate a MAC address to help testing with multiple APs */
1092 hapd->own_addr[0] = 0x02; /* locally administered */
1093 sha1_prf((const u8 *) hapd->conf->iface, strlen(hapd->conf->iface),
1094 "hostapd test bssid generation",
1095 (const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len,
1096 hapd->own_addr + 1, ETH_ALEN - 1);
1097
1098 os_strlcpy(drv->bss->ifname, hapd->conf->iface, IFNAMSIZ);
1099 memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
1100
1101 if (hapd->conf->test_socket) {
1102 if (strlen(hapd->conf->test_socket) >=
1103 sizeof(addr_un.sun_path)) {
1104 printf("Too long test_socket path\n");
1105 test_driver_free_priv(drv);
1106 return NULL;
1107 }
1108 if (strncmp(hapd->conf->test_socket, "DIR:", 4) == 0) {
1109 size_t len = strlen(hapd->conf->test_socket) + 30;
1110 drv->socket_dir = strdup(hapd->conf->test_socket + 4);
1111 drv->own_socket_path = malloc(len);
1112 if (drv->own_socket_path) {
1113 snprintf(drv->own_socket_path, len,
1114 "%s/AP-" MACSTR,
1115 hapd->conf->test_socket + 4,
1116 MAC2STR(hapd->own_addr));
1117 }
1118 } else if (strncmp(hapd->conf->test_socket, "UDP:", 4) == 0) {
1119 drv->udp_port = atoi(hapd->conf->test_socket + 4);
1120 } else {
1121 drv->own_socket_path = strdup(hapd->conf->test_socket);
1122 }
1123 if (drv->own_socket_path == NULL && drv->udp_port == 0) {
1124 test_driver_free_priv(drv);
1125 return NULL;
1126 }
1127
1128 drv->test_socket = socket(drv->udp_port ? PF_INET : PF_UNIX,
1129 SOCK_DGRAM, 0);
1130 if (drv->test_socket < 0) {
1131 perror("socket");
1132 test_driver_free_priv(drv);
1133 return NULL;
1134 }
1135
1136 if (drv->udp_port) {
1137 os_memset(&addr_in, 0, sizeof(addr_in));
1138 addr_in.sin_family = AF_INET;
1139 addr_in.sin_port = htons(drv->udp_port);
1140 addr = (struct sockaddr *) &addr_in;
1141 alen = sizeof(addr_in);
1142 } else {
1143 os_memset(&addr_un, 0, sizeof(addr_un));
1144 addr_un.sun_family = AF_UNIX;
1145 os_strlcpy(addr_un.sun_path, drv->own_socket_path,
1146 sizeof(addr_un.sun_path));
1147 addr = (struct sockaddr *) &addr_un;
1148 alen = sizeof(addr_un);
1149 }
1150 if (bind(drv->test_socket, addr, alen) < 0) {
1151 perror("bind(PF_UNIX)");
1152 close(drv->test_socket);
1153 if (drv->own_socket_path)
1154 unlink(drv->own_socket_path);
1155 test_driver_free_priv(drv);
1156 return NULL;
1157 }
1158 eloop_register_read_sock(drv->test_socket,
1159 test_driver_receive_unix, drv, NULL);
1160 } else
1161 drv->test_socket = -1;
1162
1163 return drv;
1164 }
1165
1166
1167 static void test_driver_deinit(void *priv)
1168 {
1169 struct test_driver_data *drv = priv;
1170 struct test_client_socket *cli, *prev;
1171
1172 cli = drv->cli;
1173 while (cli) {
1174 prev = cli;
1175 cli = cli->next;
1176 free(prev);
1177 }
1178
1179 if (drv->test_socket >= 0) {
1180 eloop_unregister_read_sock(drv->test_socket);
1181 close(drv->test_socket);
1182 if (drv->own_socket_path)
1183 unlink(drv->own_socket_path);
1184 }
1185
1186 /* There should be only one BSS remaining at this point. */
1187 if (drv->bss == NULL)
1188 wpa_printf(MSG_ERROR, "%s: drv->bss == NULL", __func__);
1189 else if (drv->bss->next)
1190 wpa_printf(MSG_ERROR, "%s: drv->bss->next != NULL", __func__);
1191
1192 test_driver_free_priv(drv);
1193 }
1194
1195 #else /* HOSTAPD */
1196
1197 static void wpa_driver_test_poll(void *eloop_ctx, void *timeout_ctx)
1198 {
1199 struct wpa_driver_test_data *drv = eloop_ctx;
1200
1201 #ifdef DRIVER_TEST_UNIX
1202 if (drv->associated && drv->hostapd_addr_set) {
1203 struct stat st;
1204 if (stat(drv->hostapd_addr.sun_path, &st) < 0) {
1205 wpa_printf(MSG_DEBUG, "%s: lost connection to AP: %s",
1206 __func__, strerror(errno));
1207 drv->associated = 0;
1208 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1209 }
1210 }
1211 #endif /* DRIVER_TEST_UNIX */
1212
1213 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
1214 }
1215
1216
1217 static int wpa_driver_test_set_wpa(void *priv, int enabled)
1218 {
1219 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
1220 return 0;
1221 }
1222
1223
1224 static void wpa_driver_test_scan_timeout(void *eloop_ctx, void *timeout_ctx)
1225 {
1226 wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
1227 wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
1228 }
1229
1230
1231 #ifdef DRIVER_TEST_UNIX
1232 static void wpa_driver_scan_dir(struct wpa_driver_test_data *drv,
1233 const char *path)
1234 {
1235 struct dirent *dent;
1236 DIR *dir;
1237 struct sockaddr_un addr;
1238 char cmd[512], *pos, *end;
1239 int ret;
1240
1241 dir = opendir(path);
1242 if (dir == NULL)
1243 return;
1244
1245 end = cmd + sizeof(cmd);
1246 pos = cmd;
1247 ret = os_snprintf(pos, end - pos, "SCAN " MACSTR,
1248 MAC2STR(drv->own_addr));
1249 if (ret >= 0 && ret < end - pos)
1250 pos += ret;
1251 if (drv->probe_req_ie) {
1252 ret = os_snprintf(pos, end - pos, " ");
1253 if (ret >= 0 && ret < end - pos)
1254 pos += ret;
1255 pos += wpa_snprintf_hex(pos, end - pos, drv->probe_req_ie,
1256 drv->probe_req_ie_len);
1257 }
1258 end[-1] = '\0';
1259
1260 while ((dent = readdir(dir))) {
1261 if (os_strncmp(dent->d_name, "AP-", 3) != 0 &&
1262 os_strncmp(dent->d_name, "STA-", 4) != 0)
1263 continue;
1264 if (drv->own_socket_path) {
1265 size_t olen, dlen;
1266 olen = os_strlen(drv->own_socket_path);
1267 dlen = os_strlen(dent->d_name);
1268 if (olen >= dlen &&
1269 os_strcmp(dent->d_name,
1270 drv->own_socket_path + olen - dlen) == 0)
1271 continue;
1272 }
1273 wpa_printf(MSG_DEBUG, "%s: SCAN %s", __func__, dent->d_name);
1274
1275 os_memset(&addr, 0, sizeof(addr));
1276 addr.sun_family = AF_UNIX;
1277 os_snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
1278 path, dent->d_name);
1279
1280 if (sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1281 (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1282 perror("sendto(test_socket)");
1283 }
1284 }
1285 closedir(dir);
1286 }
1287 #endif /* DRIVER_TEST_UNIX */
1288
1289
1290 static int wpa_driver_test_scan(void *priv,
1291 struct wpa_driver_scan_params *params)
1292 {
1293 struct wpa_driver_test_data *drv = priv;
1294 size_t i;
1295
1296 wpa_printf(MSG_DEBUG, "%s: priv=%p", __func__, priv);
1297 for (i = 0; i < params->num_ssids; i++)
1298 wpa_hexdump(MSG_DEBUG, "Scan SSID",
1299 params->ssids[i].ssid, params->ssids[i].ssid_len);
1300 wpa_hexdump(MSG_DEBUG, "Scan extra IE(s)",
1301 params->extra_ies, params->extra_ies_len);
1302
1303 drv->num_scanres = 0;
1304
1305 #ifdef DRIVER_TEST_UNIX
1306 if (drv->test_socket >= 0 && drv->test_dir)
1307 wpa_driver_scan_dir(drv, drv->test_dir);
1308
1309 if (drv->test_socket >= 0 && drv->hostapd_addr_set &&
1310 sendto(drv->test_socket, "SCAN", 4, 0,
1311 (struct sockaddr *) &drv->hostapd_addr,
1312 sizeof(drv->hostapd_addr)) < 0) {
1313 perror("sendto(test_socket)");
1314 }
1315 #endif /* DRIVER_TEST_UNIX */
1316
1317 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1318 sendto(drv->test_socket, "SCAN", 4, 0,
1319 (struct sockaddr *) &drv->hostapd_addr_udp,
1320 sizeof(drv->hostapd_addr_udp)) < 0) {
1321 perror("sendto(test_socket)");
1322 }
1323
1324 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
1325 eloop_register_timeout(1, 0, wpa_driver_test_scan_timeout, drv,
1326 drv->ctx);
1327 return 0;
1328 }
1329
1330
1331 static struct wpa_scan_results * wpa_driver_test_get_scan_results2(void *priv)
1332 {
1333 struct wpa_driver_test_data *drv = priv;
1334 struct wpa_scan_results *res;
1335 size_t i;
1336
1337 res = os_zalloc(sizeof(*res));
1338 if (res == NULL)
1339 return NULL;
1340
1341 res->res = os_zalloc(drv->num_scanres * sizeof(struct wpa_scan_res *));
1342 if (res->res == NULL) {
1343 os_free(res);
1344 return NULL;
1345 }
1346
1347 for (i = 0; i < drv->num_scanres; i++) {
1348 struct wpa_scan_res *r;
1349 if (drv->scanres[i] == NULL)
1350 continue;
1351 r = os_malloc(sizeof(*r) + drv->scanres[i]->ie_len);
1352 if (r == NULL)
1353 break;
1354 os_memcpy(r, drv->scanres[i],
1355 sizeof(*r) + drv->scanres[i]->ie_len);
1356 res->res[res->num++] = r;
1357 }
1358
1359 return res;
1360 }
1361
1362
1363 static int wpa_driver_test_set_key(void *priv, wpa_alg alg, const u8 *addr,
1364 int key_idx, int set_tx,
1365 const u8 *seq, size_t seq_len,
1366 const u8 *key, size_t key_len)
1367 {
1368 wpa_printf(MSG_DEBUG, "%s: priv=%p alg=%d key_idx=%d set_tx=%d",
1369 __func__, priv, alg, key_idx, set_tx);
1370 if (addr) {
1371 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
1372 }
1373 if (seq) {
1374 wpa_hexdump(MSG_DEBUG, " seq", seq, seq_len);
1375 }
1376 if (key) {
1377 wpa_hexdump(MSG_DEBUG, " key", key, key_len);
1378 }
1379 return 0;
1380 }
1381
1382
1383 static int wpa_driver_test_associate(
1384 void *priv, struct wpa_driver_associate_params *params)
1385 {
1386 struct wpa_driver_test_data *drv = priv;
1387 wpa_printf(MSG_DEBUG, "%s: priv=%p freq=%d pairwise_suite=%d "
1388 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d",
1389 __func__, priv, params->freq, params->pairwise_suite,
1390 params->group_suite, params->key_mgmt_suite,
1391 params->auth_alg, params->mode);
1392 if (params->bssid) {
1393 wpa_printf(MSG_DEBUG, " bssid=" MACSTR,
1394 MAC2STR(params->bssid));
1395 }
1396 if (params->ssid) {
1397 wpa_hexdump_ascii(MSG_DEBUG, " ssid",
1398 params->ssid, params->ssid_len);
1399 }
1400 if (params->wpa_ie) {
1401 wpa_hexdump(MSG_DEBUG, " wpa_ie",
1402 params->wpa_ie, params->wpa_ie_len);
1403 drv->assoc_wpa_ie_len = params->wpa_ie_len;
1404 if (drv->assoc_wpa_ie_len > sizeof(drv->assoc_wpa_ie))
1405 drv->assoc_wpa_ie_len = sizeof(drv->assoc_wpa_ie);
1406 os_memcpy(drv->assoc_wpa_ie, params->wpa_ie,
1407 drv->assoc_wpa_ie_len);
1408 } else
1409 drv->assoc_wpa_ie_len = 0;
1410
1411 drv->ibss = params->mode == IEEE80211_MODE_IBSS;
1412 drv->privacy = params->key_mgmt_suite &
1413 (WPA_KEY_MGMT_IEEE8021X |
1414 WPA_KEY_MGMT_PSK |
1415 WPA_KEY_MGMT_WPA_NONE |
1416 WPA_KEY_MGMT_FT_IEEE8021X |
1417 WPA_KEY_MGMT_FT_PSK |
1418 WPA_KEY_MGMT_IEEE8021X_SHA256 |
1419 WPA_KEY_MGMT_PSK_SHA256);
1420 if (params->wep_key_len[params->wep_tx_keyidx])
1421 drv->privacy = 1;
1422
1423 #ifdef DRIVER_TEST_UNIX
1424 if (drv->test_dir && params->bssid &&
1425 params->mode != IEEE80211_MODE_IBSS) {
1426 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
1427 drv->hostapd_addr.sun_family = AF_UNIX;
1428 os_snprintf(drv->hostapd_addr.sun_path,
1429 sizeof(drv->hostapd_addr.sun_path),
1430 "%s/AP-" MACSTR,
1431 drv->test_dir, MAC2STR(params->bssid));
1432 drv->hostapd_addr_set = 1;
1433 }
1434 #endif /* DRIVER_TEST_UNIX */
1435
1436 if (drv->test_socket >= 0 &&
1437 (drv->hostapd_addr_set || drv->hostapd_addr_udp_set)) {
1438 char cmd[200], *pos, *end;
1439 int ret;
1440 end = cmd + sizeof(cmd);
1441 pos = cmd;
1442 ret = os_snprintf(pos, end - pos, "ASSOC " MACSTR " ",
1443 MAC2STR(drv->own_addr));
1444 if (ret >= 0 && ret < end - pos)
1445 pos += ret;
1446 pos += wpa_snprintf_hex(pos, end - pos, params->ssid,
1447 params->ssid_len);
1448 ret = os_snprintf(pos, end - pos, " ");
1449 if (ret >= 0 && ret < end - pos)
1450 pos += ret;
1451 pos += wpa_snprintf_hex(pos, end - pos, params->wpa_ie,
1452 params->wpa_ie_len);
1453 end[-1] = '\0';
1454 #ifdef DRIVER_TEST_UNIX
1455 if (drv->hostapd_addr_set &&
1456 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1457 (struct sockaddr *) &drv->hostapd_addr,
1458 sizeof(drv->hostapd_addr)) < 0) {
1459 perror("sendto(test_socket)");
1460 return -1;
1461 }
1462 #endif /* DRIVER_TEST_UNIX */
1463 if (drv->hostapd_addr_udp_set &&
1464 sendto(drv->test_socket, cmd, os_strlen(cmd), 0,
1465 (struct sockaddr *) &drv->hostapd_addr_udp,
1466 sizeof(drv->hostapd_addr_udp)) < 0) {
1467 perror("sendto(test_socket)");
1468 return -1;
1469 }
1470
1471 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1472 drv->ssid_len = params->ssid_len;
1473 } else {
1474 drv->associated = 1;
1475 if (params->mode == IEEE80211_MODE_IBSS) {
1476 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
1477 drv->ssid_len = params->ssid_len;
1478 if (params->bssid)
1479 os_memcpy(drv->bssid, params->bssid, ETH_ALEN);
1480 else {
1481 os_get_random(drv->bssid, ETH_ALEN);
1482 drv->bssid[0] &= ~0x01;
1483 drv->bssid[0] |= 0x02;
1484 }
1485 }
1486 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1487 }
1488
1489 return 0;
1490 }
1491
1492
1493 static int wpa_driver_test_get_bssid(void *priv, u8 *bssid)
1494 {
1495 struct wpa_driver_test_data *drv = priv;
1496 os_memcpy(bssid, drv->bssid, ETH_ALEN);
1497 return 0;
1498 }
1499
1500
1501 static int wpa_driver_test_get_ssid(void *priv, u8 *ssid)
1502 {
1503 struct wpa_driver_test_data *drv = priv;
1504 os_memcpy(ssid, drv->ssid, 32);
1505 return drv->ssid_len;
1506 }
1507
1508
1509 static int wpa_driver_test_send_disassoc(struct wpa_driver_test_data *drv)
1510 {
1511 #ifdef DRIVER_TEST_UNIX
1512 if (drv->test_socket >= 0 &&
1513 sendto(drv->test_socket, "DISASSOC", 8, 0,
1514 (struct sockaddr *) &drv->hostapd_addr,
1515 sizeof(drv->hostapd_addr)) < 0) {
1516 perror("sendto(test_socket)");
1517 return -1;
1518 }
1519 #endif /* DRIVER_TEST_UNIX */
1520 if (drv->test_socket >= 0 && drv->hostapd_addr_udp_set &&
1521 sendto(drv->test_socket, "DISASSOC", 8, 0,
1522 (struct sockaddr *) &drv->hostapd_addr_udp,
1523 sizeof(drv->hostapd_addr_udp)) < 0) {
1524 perror("sendto(test_socket)");
1525 return -1;
1526 }
1527 return 0;
1528 }
1529
1530
1531 static int wpa_driver_test_deauthenticate(void *priv, const u8 *addr,
1532 int reason_code)
1533 {
1534 struct wpa_driver_test_data *drv = priv;
1535 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1536 __func__, MAC2STR(addr), reason_code);
1537 os_memset(drv->bssid, 0, ETH_ALEN);
1538 drv->associated = 0;
1539 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1540 return wpa_driver_test_send_disassoc(drv);
1541 }
1542
1543
1544 static int wpa_driver_test_disassociate(void *priv, const u8 *addr,
1545 int reason_code)
1546 {
1547 struct wpa_driver_test_data *drv = priv;
1548 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d",
1549 __func__, MAC2STR(addr), reason_code);
1550 os_memset(drv->bssid, 0, ETH_ALEN);
1551 drv->associated = 0;
1552 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1553 return wpa_driver_test_send_disassoc(drv);
1554 }
1555
1556
1557 static void wpa_driver_test_scanresp(struct wpa_driver_test_data *drv,
1558 struct sockaddr *from,
1559 socklen_t fromlen,
1560 const char *data)
1561 {
1562 struct wpa_scan_res *res;
1563 const char *pos, *pos2;
1564 size_t len;
1565 u8 *ie_pos, *ie_start, *ie_end;
1566 #define MAX_IE_LEN 1000
1567
1568 wpa_printf(MSG_DEBUG, "test_driver: SCANRESP %s", data);
1569 if (drv->num_scanres >= MAX_SCAN_RESULTS) {
1570 wpa_printf(MSG_DEBUG, "test_driver: No room for the new scan "
1571 "result");
1572 return;
1573 }
1574
1575 /* SCANRESP BSSID SSID IEs */
1576
1577 res = os_zalloc(sizeof(*res) + MAX_IE_LEN);
1578 if (res == NULL)
1579 return;
1580 ie_start = ie_pos = (u8 *) (res + 1);
1581 ie_end = ie_pos + MAX_IE_LEN;
1582
1583 if (hwaddr_aton(data, res->bssid)) {
1584 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in scanres");
1585 os_free(res);
1586 return;
1587 }
1588
1589 pos = data + 17;
1590 while (*pos == ' ')
1591 pos++;
1592 pos2 = os_strchr(pos, ' ');
1593 if (pos2 == NULL) {
1594 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID termination "
1595 "in scanres");
1596 os_free(res);
1597 return;
1598 }
1599 len = (pos2 - pos) / 2;
1600 if (len > 32)
1601 len = 32;
1602 /*
1603 * Generate SSID IE from the SSID field since this IE is not included
1604 * in the main IE field.
1605 */
1606 *ie_pos++ = WLAN_EID_SSID;
1607 *ie_pos++ = len;
1608 if (hexstr2bin(pos, ie_pos, len) < 0) {
1609 wpa_printf(MSG_DEBUG, "test_driver: invalid SSID in scanres");
1610 os_free(res);
1611 return;
1612 }
1613 ie_pos += len;
1614
1615 pos = pos2 + 1;
1616 pos2 = os_strchr(pos, ' ');
1617 if (pos2 == NULL)
1618 len = os_strlen(pos) / 2;
1619 else
1620 len = (pos2 - pos) / 2;
1621 if ((int) len > ie_end - ie_pos)
1622 len = ie_end - ie_pos;
1623 if (hexstr2bin(pos, ie_pos, len) < 0) {
1624 wpa_printf(MSG_DEBUG, "test_driver: invalid IEs in scanres");
1625 os_free(res);
1626 return;
1627 }
1628 ie_pos += len;
1629 res->ie_len = ie_pos - ie_start;
1630
1631 if (pos2) {
1632 pos = pos2 + 1;
1633 while (*pos == ' ')
1634 pos++;
1635 if (os_strstr(pos, "PRIVACY"))
1636 res->caps |= IEEE80211_CAP_PRIVACY;
1637 if (os_strstr(pos, "IBSS"))
1638 res->caps |= IEEE80211_CAP_IBSS;
1639 }
1640
1641 os_free(drv->scanres[drv->num_scanres]);
1642 drv->scanres[drv->num_scanres++] = res;
1643 }
1644
1645
1646 static void wpa_driver_test_assocresp(struct wpa_driver_test_data *drv,
1647 struct sockaddr *from,
1648 socklen_t fromlen,
1649 const char *data)
1650 {
1651 /* ASSOCRESP BSSID <res> */
1652 if (hwaddr_aton(data, drv->bssid)) {
1653 wpa_printf(MSG_DEBUG, "test_driver: invalid BSSID in "
1654 "assocresp");
1655 }
1656 if (drv->use_associnfo) {
1657 union wpa_event_data event;
1658 os_memset(&event, 0, sizeof(event));
1659 event.assoc_info.req_ies = drv->assoc_wpa_ie;
1660 event.assoc_info.req_ies_len = drv->assoc_wpa_ie_len;
1661 wpa_supplicant_event(drv->ctx, EVENT_ASSOCINFO, &event);
1662 }
1663 drv->associated = 1;
1664 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
1665 }
1666
1667
1668 static void wpa_driver_test_disassoc(struct wpa_driver_test_data *drv,
1669 struct sockaddr *from,
1670 socklen_t fromlen)
1671 {
1672 drv->associated = 0;
1673 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
1674 }
1675
1676
1677 static void wpa_driver_test_eapol(struct wpa_driver_test_data *drv,
1678 struct sockaddr *from,
1679 socklen_t fromlen,
1680 const u8 *data, size_t data_len)
1681 {
1682 const u8 *src = drv->bssid;
1683
1684 if (data_len > 14) {
1685 /* Skip Ethernet header */
1686 src = data + ETH_ALEN;
1687 data += 14;
1688 data_len -= 14;
1689 }
1690 wpa_supplicant_rx_eapol(drv->ctx, src, data, data_len);
1691 }
1692
1693
1694 static void wpa_driver_test_mlme(struct wpa_driver_test_data *drv,
1695 struct sockaddr *from,
1696 socklen_t fromlen,
1697 const u8 *data, size_t data_len)
1698 {
1699 #ifdef CONFIG_CLIENT_MLME
1700 struct ieee80211_rx_status rx_status;
1701 os_memset(&rx_status, 0, sizeof(rx_status));
1702 wpa_supplicant_sta_rx(drv->ctx, data, data_len, &rx_status);
1703 #endif /* CONFIG_CLIENT_MLME */
1704 }
1705
1706
1707 static void wpa_driver_test_scan_cmd(struct wpa_driver_test_data *drv,
1708 struct sockaddr *from,
1709 socklen_t fromlen,
1710 const u8 *data, size_t data_len)
1711 {
1712 char buf[512], *pos, *end;
1713 int ret;
1714
1715 /* data: optional [ STA-addr | ' ' | IEs(hex) ] */
1716
1717 if (!drv->ibss)
1718 return;
1719
1720 pos = buf;
1721 end = buf + sizeof(buf);
1722
1723 /* reply: SCANRESP BSSID SSID IEs */
1724 ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
1725 MAC2STR(drv->bssid));
1726 if (ret < 0 || ret >= end - pos)
1727 return;
1728 pos += ret;
1729 pos += wpa_snprintf_hex(pos, end - pos,
1730 drv->ssid, drv->ssid_len);
1731 ret = snprintf(pos, end - pos, " ");
1732 if (ret < 0 || ret >= end - pos)
1733 return;
1734 pos += ret;
1735 pos += wpa_snprintf_hex(pos, end - pos, drv->assoc_wpa_ie,
1736 drv->assoc_wpa_ie_len);
1737
1738 if (drv->privacy) {
1739 ret = snprintf(pos, end - pos, " PRIVACY");
1740 if (ret < 0 || ret >= end - pos)
1741 return;
1742 pos += ret;
1743 }
1744
1745 ret = snprintf(pos, end - pos, " IBSS");
1746 if (ret < 0 || ret >= end - pos)
1747 return;
1748 pos += ret;
1749
1750 sendto(drv->test_socket, buf, pos - buf, 0,
1751 (struct sockaddr *) from, fromlen);
1752 }
1753
1754
1755 static void wpa_driver_test_receive_unix(int sock, void *eloop_ctx,
1756 void *sock_ctx)
1757 {
1758 struct wpa_driver_test_data *drv = eloop_ctx;
1759 char *buf;
1760 int res;
1761 struct sockaddr_storage from;
1762 socklen_t fromlen = sizeof(from);
1763 const size_t buflen = 2000;
1764
1765 buf = os_malloc(buflen);
1766 if (buf == NULL)
1767 return;
1768 res = recvfrom(sock, buf, buflen - 1, 0,
1769 (struct sockaddr *) &from, &fromlen);
1770 if (res < 0) {
1771 perror("recvfrom(test_socket)");
1772 os_free(buf);
1773 return;
1774 }
1775 buf[res] = '\0';
1776
1777 wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
1778
1779 if (os_strncmp(buf, "SCANRESP ", 9) == 0) {
1780 wpa_driver_test_scanresp(drv, (struct sockaddr *) &from,
1781 fromlen, buf + 9);
1782 } else if (os_strncmp(buf, "ASSOCRESP ", 10) == 0) {
1783 wpa_driver_test_assocresp(drv, (struct sockaddr *) &from,
1784 fromlen, buf + 10);
1785 } else if (os_strcmp(buf, "DISASSOC") == 0) {
1786 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1787 fromlen);
1788 } else if (os_strcmp(buf, "DEAUTH") == 0) {
1789 wpa_driver_test_disassoc(drv, (struct sockaddr *) &from,
1790 fromlen);
1791 } else if (os_strncmp(buf, "EAPOL ", 6) == 0) {
1792 wpa_driver_test_eapol(drv, (struct sockaddr *) &from, fromlen,
1793 (const u8 *) buf + 6, res - 6);
1794 } else if (os_strncmp(buf, "MLME ", 5) == 0) {
1795 wpa_driver_test_mlme(drv, (struct sockaddr *) &from, fromlen,
1796 (const u8 *) buf + 5, res - 5);
1797 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
1798 wpa_driver_test_scan_cmd(drv, (struct sockaddr *) &from,
1799 fromlen,
1800 (const u8 *) buf + 5, res - 5);
1801 } else {
1802 wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
1803 (u8 *) buf, res);
1804 }
1805 os_free(buf);
1806 }
1807
1808
1809 static void * wpa_driver_test_init2(void *ctx, const char *ifname,
1810 void *global_priv)
1811 {
1812 struct wpa_driver_test_data *drv;
1813
1814 drv = os_zalloc(sizeof(*drv));
1815 if (drv == NULL)
1816 return NULL;
1817 drv->global = global_priv;
1818 drv->ctx = ctx;
1819 drv->test_socket = -1;
1820
1821 /* Set dummy BSSID and SSID for testing. */
1822 drv->bssid[0] = 0x02;
1823 drv->bssid[1] = 0x00;
1824 drv->bssid[2] = 0x00;
1825 drv->bssid[3] = 0x00;
1826 drv->bssid[4] = 0x00;
1827 drv->bssid[5] = 0x01;
1828 os_memcpy(drv->ssid, "test", 5);
1829 drv->ssid_len = 4;
1830
1831 /* Generate a MAC address to help testing with multiple STAs */
1832 drv->own_addr[0] = 0x02; /* locally administered */
1833 sha1_prf((const u8 *) ifname, os_strlen(ifname),
1834 "wpa_supplicant test mac addr generation",
1835 NULL, 0, drv->own_addr + 1, ETH_ALEN - 1);
1836 eloop_register_timeout(1, 0, wpa_driver_test_poll, drv, NULL);
1837
1838 return drv;
1839 }
1840
1841
1842 static void wpa_driver_test_close_test_socket(struct wpa_driver_test_data *drv)
1843 {
1844 if (drv->test_socket >= 0) {
1845 eloop_unregister_read_sock(drv->test_socket);
1846 close(drv->test_socket);
1847 drv->test_socket = -1;
1848 }
1849
1850 if (drv->own_socket_path) {
1851 unlink(drv->own_socket_path);
1852 os_free(drv->own_socket_path);
1853 drv->own_socket_path = NULL;
1854 }
1855 }
1856
1857
1858 static void wpa_driver_test_deinit(void *priv)
1859 {
1860 struct wpa_driver_test_data *drv = priv;
1861 int i;
1862 wpa_driver_test_close_test_socket(drv);
1863 eloop_cancel_timeout(wpa_driver_test_scan_timeout, drv, drv->ctx);
1864 eloop_cancel_timeout(wpa_driver_test_poll, drv, NULL);
1865 os_free(drv->test_dir);
1866 for (i = 0; i < MAX_SCAN_RESULTS; i++)
1867 os_free(drv->scanres[i]);
1868 os_free(drv->probe_req_ie);
1869 os_free(drv);
1870 }
1871
1872
1873 static int wpa_driver_test_attach(struct wpa_driver_test_data *drv,
1874 const char *dir)
1875 {
1876 #ifdef DRIVER_TEST_UNIX
1877 static unsigned int counter = 0;
1878 struct sockaddr_un addr;
1879 size_t len;
1880
1881 os_free(drv->own_socket_path);
1882 if (dir) {
1883 len = os_strlen(dir) + 30;
1884 drv->own_socket_path = os_malloc(len);
1885 if (drv->own_socket_path == NULL)
1886 return -1;
1887 os_snprintf(drv->own_socket_path, len, "%s/STA-" MACSTR,
1888 dir, MAC2STR(drv->own_addr));
1889 } else {
1890 drv->own_socket_path = os_malloc(100);
1891 if (drv->own_socket_path == NULL)
1892 return -1;
1893 os_snprintf(drv->own_socket_path, 100,
1894 "/tmp/wpa_supplicant_test-%d-%d",
1895 getpid(), counter++);
1896 }
1897
1898 drv->test_socket = socket(PF_UNIX, SOCK_DGRAM, 0);
1899 if (drv->test_socket < 0) {
1900 perror("socket(PF_UNIX)");
1901 os_free(drv->own_socket_path);
1902 drv->own_socket_path = NULL;
1903 return -1;
1904 }
1905
1906 os_memset(&addr, 0, sizeof(addr));
1907 addr.sun_family = AF_UNIX;
1908 os_strlcpy(addr.sun_path, drv->own_socket_path, sizeof(addr.sun_path));
1909 if (bind(drv->test_socket, (struct sockaddr *) &addr,
1910 sizeof(addr)) < 0) {
1911 perror("bind(PF_UNIX)");
1912 close(drv->test_socket);
1913 unlink(drv->own_socket_path);
1914 os_free(drv->own_socket_path);
1915 drv->own_socket_path = NULL;
1916 return -1;
1917 }
1918
1919 eloop_register_read_sock(drv->test_socket,
1920 wpa_driver_test_receive_unix, drv, NULL);
1921
1922 return 0;
1923 #else /* DRIVER_TEST_UNIX */
1924 return -1;
1925 #endif /* DRIVER_TEST_UNIX */
1926 }
1927
1928
1929 static int wpa_driver_test_attach_udp(struct wpa_driver_test_data *drv,
1930 char *dst)
1931 {
1932 char *pos;
1933
1934 pos = os_strchr(dst, ':');
1935 if (pos == NULL)
1936 return -1;
1937 *pos++ = '\0';
1938 wpa_printf(MSG_DEBUG, "%s: addr=%s port=%s", __func__, dst, pos);
1939
1940 drv->test_socket = socket(PF_INET, SOCK_DGRAM, 0);
1941 if (drv->test_socket < 0) {
1942 perror("socket(PF_INET)");
1943 return -1;
1944 }
1945
1946 os_memset(&drv->hostapd_addr_udp, 0, sizeof(drv->hostapd_addr_udp));
1947 drv->hostapd_addr_udp.sin_family = AF_INET;
1948 #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
1949 {
1950 int a[4];
1951 u8 *pos;
1952 sscanf(dst, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
1953 pos = (u8 *) &drv->hostapd_addr_udp.sin_addr;
1954 *pos++ = a[0];
1955 *pos++ = a[1];
1956 *pos++ = a[2];
1957 *pos++ = a[3];
1958 }
1959 #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1960 inet_aton(dst, &drv->hostapd_addr_udp.sin_addr);
1961 #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
1962 drv->hostapd_addr_udp.sin_port = htons(atoi(pos));
1963
1964 drv->hostapd_addr_udp_set = 1;
1965
1966 eloop_register_read_sock(drv->test_socket,
1967 wpa_driver_test_receive_unix, drv, NULL);
1968
1969 return 0;
1970 }
1971
1972
1973 static int wpa_driver_test_set_param(void *priv, const char *param)
1974 {
1975 struct wpa_driver_test_data *drv = priv;
1976 const char *pos;
1977
1978 wpa_printf(MSG_DEBUG, "%s: param='%s'", __func__, param);
1979 if (param == NULL)
1980 return 0;
1981
1982 wpa_driver_test_close_test_socket(drv);
1983
1984 #ifdef DRIVER_TEST_UNIX
1985 pos = os_strstr(param, "test_socket=");
1986 if (pos) {
1987 const char *pos2;
1988 size_t len;
1989
1990 pos += 12;
1991 pos2 = os_strchr(pos, ' ');
1992 if (pos2)
1993 len = pos2 - pos;
1994 else
1995 len = os_strlen(pos);
1996 if (len > sizeof(drv->hostapd_addr.sun_path))
1997 return -1;
1998 os_memset(&drv->hostapd_addr, 0, sizeof(drv->hostapd_addr));
1999 drv->hostapd_addr.sun_family = AF_UNIX;
2000 os_memcpy(drv->hostapd_addr.sun_path, pos, len);
2001 drv->hostapd_addr_set = 1;
2002 }
2003 #endif /* DRIVER_TEST_UNIX */
2004
2005 pos = os_strstr(param, "test_dir=");
2006 if (pos) {
2007 char *end;
2008 os_free(drv->test_dir);
2009 drv->test_dir = os_strdup(pos + 9);
2010 if (drv->test_dir == NULL)
2011 return -1;
2012 end = os_strchr(drv->test_dir, ' ');
2013 if (end)
2014 *end = '\0';
2015 if (wpa_driver_test_attach(drv, drv->test_dir))
2016 return -1;
2017 } else {
2018 pos = os_strstr(param, "test_udp=");
2019 if (pos) {
2020 char *dst, *epos;
2021 dst = os_strdup(pos + 9);
2022 if (dst == NULL)
2023 return -1;
2024 epos = os_strchr(dst, ' ');
2025 if (epos)
2026 *epos = '\0';
2027 if (wpa_driver_test_attach_udp(drv, dst))
2028 return -1;
2029 os_free(dst);
2030 } else if (wpa_driver_test_attach(drv, NULL))
2031 return -1;
2032 }
2033
2034 if (os_strstr(param, "use_associnfo=1")) {
2035 wpa_printf(MSG_DEBUG, "test_driver: Use AssocInfo events");
2036 drv->use_associnfo = 1;
2037 }
2038
2039 #ifdef CONFIG_CLIENT_MLME
2040 if (os_strstr(param, "use_mlme=1")) {
2041 wpa_printf(MSG_DEBUG, "test_driver: Use internal MLME");
2042 drv->use_mlme = 1;
2043 }
2044 #endif /* CONFIG_CLIENT_MLME */
2045
2046 return 0;
2047 }
2048
2049
2050 static const u8 * wpa_driver_test_get_mac_addr(void *priv)
2051 {
2052 struct wpa_driver_test_data *drv = priv;
2053 wpa_printf(MSG_DEBUG, "%s", __func__);
2054 return drv->own_addr;
2055 }
2056
2057
2058 static int wpa_driver_test_send_eapol(void *priv, const u8 *dest, u16 proto,
2059 const u8 *data, size_t data_len)
2060 {
2061 struct wpa_driver_test_data *drv = priv;
2062 char *msg;
2063 size_t msg_len;
2064 struct l2_ethhdr eth;
2065 struct sockaddr *addr;
2066 socklen_t alen;
2067 #ifdef DRIVER_TEST_UNIX
2068 struct sockaddr_un addr_un;
2069 #endif /* DRIVER_TEST_UNIX */
2070
2071 wpa_hexdump(MSG_MSGDUMP, "test_send_eapol TX frame", data, data_len);
2072
2073 os_memset(&eth, 0, sizeof(eth));
2074 os_memcpy(eth.h_dest, dest, ETH_ALEN);
2075 os_memcpy(eth.h_source, drv->own_addr, ETH_ALEN);
2076 eth.h_proto = host_to_be16(proto);
2077
2078 msg_len = 6 + sizeof(eth) + data_len;
2079 msg = os_malloc(msg_len);
2080 if (msg == NULL)
2081 return -1;
2082 os_memcpy(msg, "EAPOL ", 6);
2083 os_memcpy(msg + 6, &eth, sizeof(eth));
2084 os_memcpy(msg + 6 + sizeof(eth), data, data_len);
2085
2086 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
2087 drv->test_dir == NULL) {
2088 if (drv->hostapd_addr_udp_set) {
2089 addr = (struct sockaddr *) &drv->hostapd_addr_udp;
2090 alen = sizeof(drv->hostapd_addr_udp);
2091 } else {
2092 #ifdef DRIVER_TEST_UNIX
2093 addr = (struct sockaddr *) &drv->hostapd_addr;
2094 alen = sizeof(drv->hostapd_addr);
2095 #else /* DRIVER_TEST_UNIX */
2096 os_free(msg);
2097 return -1;
2098 #endif /* DRIVER_TEST_UNIX */
2099 }
2100 } else {
2101 #ifdef DRIVER_TEST_UNIX
2102 struct stat st;
2103 os_memset(&addr_un, 0, sizeof(addr_un));
2104 addr_un.sun_family = AF_UNIX;
2105 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2106 "%s/STA-" MACSTR, drv->test_dir, MAC2STR(dest));
2107 if (stat(addr_un.sun_path, &st) < 0) {
2108 os_snprintf(addr_un.sun_path, sizeof(addr_un.sun_path),
2109 "%s/AP-" MACSTR,
2110 drv->test_dir, MAC2STR(dest));
2111 }
2112 addr = (struct sockaddr *) &addr_un;
2113 alen = sizeof(addr_un);
2114 #else /* DRIVER_TEST_UNIX */
2115 os_free(msg);
2116 return -1;
2117 #endif /* DRIVER_TEST_UNIX */
2118 }
2119
2120 if (sendto(drv->test_socket, msg, msg_len, 0, addr, alen) < 0) {
2121 perror("sendmsg(test_socket)");
2122 os_free(msg);
2123 return -1;
2124 }
2125
2126 os_free(msg);
2127 return 0;
2128 }
2129
2130
2131 static int wpa_driver_test_get_capa(void *priv, struct wpa_driver_capa *capa)
2132 {
2133 struct wpa_driver_test_data *drv = priv;
2134 os_memset(capa, 0, sizeof(*capa));
2135 capa->key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2136 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2137 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2138 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
2139 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE |
2140 WPA_DRIVER_CAPA_KEY_MGMT_FT |
2141 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2142 capa->enc = WPA_DRIVER_CAPA_ENC_WEP40 |
2143 WPA_DRIVER_CAPA_ENC_WEP104 |
2144 WPA_DRIVER_CAPA_ENC_TKIP |
2145 WPA_DRIVER_CAPA_ENC_CCMP;
2146 capa->auth = WPA_DRIVER_AUTH_OPEN |
2147 WPA_DRIVER_AUTH_SHARED |
2148 WPA_DRIVER_AUTH_LEAP;
2149 if (drv->use_mlme)
2150 capa->flags |= WPA_DRIVER_FLAGS_USER_SPACE_MLME;
2151 capa->max_scan_ssids = 2;
2152
2153 return 0;
2154 }
2155
2156
2157 static int wpa_driver_test_mlme_setprotection(void *priv, const u8 *addr,
2158 int protect_type,
2159 int key_type)
2160 {
2161 wpa_printf(MSG_DEBUG, "%s: protect_type=%d key_type=%d",
2162 __func__, protect_type, key_type);
2163
2164 if (addr) {
2165 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR,
2166 __func__, MAC2STR(addr));
2167 }
2168
2169 return 0;
2170 }
2171
2172
2173 #ifdef CONFIG_CLIENT_MLME
2174 static int wpa_driver_test_set_channel(void *priv, hostapd_hw_mode phymode,
2175 int chan, int freq)
2176 {
2177 wpa_printf(MSG_DEBUG, "%s: phymode=%d chan=%d freq=%d",
2178 __func__, phymode, chan, freq);
2179 return 0;
2180 }
2181
2182
2183 static int wpa_driver_test_send_mlme(void *priv, const u8 *data,
2184 size_t data_len)
2185 {
2186 struct wpa_driver_test_data *drv = priv;
2187 struct msghdr msg;
2188 struct iovec io[2];
2189 struct sockaddr_un addr;
2190 const u8 *dest;
2191 struct dirent *dent;
2192 DIR *dir;
2193
2194 wpa_hexdump(MSG_MSGDUMP, "test_send_mlme", data, data_len);
2195 if (data_len < 10)
2196 return -1;
2197 dest = data + 4;
2198
2199 io[0].iov_base = "MLME ";
2200 io[0].iov_len = 5;
2201 io[1].iov_base = (u8 *) data;
2202 io[1].iov_len = data_len;
2203
2204 os_memset(&msg, 0, sizeof(msg));
2205 msg.msg_iov = io;
2206 msg.msg_iovlen = 2;
2207 if (os_memcmp(dest, drv->bssid, ETH_ALEN) == 0 ||
2208 drv->test_dir == NULL) {
2209 if (drv->hostapd_addr_udp_set) {
2210 msg.msg_name = &drv->hostapd_addr_udp;
2211 msg.msg_namelen = sizeof(drv->hostapd_addr_udp);
2212 } else {
2213 #ifdef DRIVER_TEST_UNIX
2214 msg.msg_name = &drv->hostapd_addr;
2215 msg.msg_namelen = sizeof(drv->hostapd_addr);
2216 #endif /* DRIVER_TEST_UNIX */
2217 }
2218 } else if (os_memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0)
2219 {
2220 dir = opendir(drv->test_dir);
2221 if (dir == NULL)
2222 return -1;
2223 while ((dent = readdir(dir))) {
2224 #ifdef _DIRENT_HAVE_D_TYPE
2225 /* Skip the file if it is not a socket.
2226 * Also accept DT_UNKNOWN (0) in case
2227 * the C library or underlying file
2228 * system does not support d_type. */
2229 if (dent->d_type != DT_SOCK &&
2230 dent->d_type != DT_UNKNOWN)
2231 continue;
2232 #endif /* _DIRENT_HAVE_D_TYPE */
2233 if (os_strcmp(dent->d_name, ".") == 0 ||
2234 os_strcmp(dent->d_name, "..") == 0)
2235 continue;
2236 wpa_printf(MSG_DEBUG, "%s: Send broadcast MLME to %s",
2237 __func__, dent->d_name);
2238 os_memset(&addr, 0, sizeof(addr));
2239 addr.sun_family = AF_UNIX;
2240 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2241 "%s/%s", drv->test_dir, dent->d_name);
2242
2243 msg.msg_name = &addr;
2244 msg.msg_namelen = sizeof(addr);
2245
2246 if (sendmsg(drv->test_socket, &msg, 0) < 0)
2247 perror("sendmsg(test_socket)");
2248 }
2249 closedir(dir);
2250 return 0;
2251 } else {
2252 struct stat st;
2253 os_memset(&addr, 0, sizeof(addr));
2254 addr.sun_family = AF_UNIX;
2255 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2256 "%s/AP-" MACSTR, drv->test_dir, MAC2STR(dest));
2257 if (stat(addr.sun_path, &st) < 0) {
2258 os_snprintf(addr.sun_path, sizeof(addr.sun_path),
2259 "%s/STA-" MACSTR,
2260 drv->test_dir, MAC2STR(dest));
2261 }
2262 msg.msg_name = &addr;
2263 msg.msg_namelen = sizeof(addr);
2264 }
2265
2266 if (sendmsg(drv->test_socket, &msg, 0) < 0) {
2267 perror("sendmsg(test_socket)");
2268 return -1;
2269 }
2270
2271 return 0;
2272 }
2273
2274
2275 static int wpa_driver_test_mlme_add_sta(void *priv, const u8 *addr,
2276 const u8 *supp_rates,
2277 size_t supp_rates_len)
2278 {
2279 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2280 return 0;
2281 }
2282
2283
2284 static int wpa_driver_test_mlme_remove_sta(void *priv, const u8 *addr)
2285 {
2286 wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, MAC2STR(addr));
2287 return 0;
2288 }
2289
2290
2291 static int wpa_driver_test_set_ssid(void *priv, const u8 *ssid,
2292 size_t ssid_len)
2293 {
2294 wpa_printf(MSG_DEBUG, "%s", __func__);
2295 return 0;
2296 }
2297
2298
2299 static int wpa_driver_test_set_bssid(void *priv, const u8 *bssid)
2300 {
2301 wpa_printf(MSG_DEBUG, "%s: bssid=" MACSTR, __func__, MAC2STR(bssid));
2302 return 0;
2303 }
2304 #endif /* CONFIG_CLIENT_MLME */
2305
2306
2307 static int wpa_driver_test_set_probe_req_ie(void *priv, const u8 *ies,
2308 size_t ies_len)
2309 {
2310 struct wpa_driver_test_data *drv = priv;
2311
2312 os_free(drv->probe_req_ie);
2313 if (ies) {
2314 drv->probe_req_ie = os_malloc(ies_len);
2315 if (drv->probe_req_ie == NULL) {
2316 drv->probe_req_ie_len = 0;
2317 return -1;
2318 }
2319 os_memcpy(drv->probe_req_ie, ies, ies_len);
2320 drv->probe_req_ie_len = ies_len;
2321 } else {
2322 drv->probe_req_ie = NULL;
2323 drv->probe_req_ie_len = 0;
2324 }
2325 return 0;
2326 }
2327
2328
2329 static void * wpa_driver_test_global_init(void)
2330 {
2331 struct wpa_driver_test_global *global;
2332
2333 global = os_zalloc(sizeof(*global));
2334 return global;
2335 }
2336
2337
2338 static void wpa_driver_test_global_deinit(void *priv)
2339 {
2340 struct wpa_driver_test_global *global = priv;
2341 os_free(global);
2342 }
2343
2344
2345 static struct wpa_interface_info *
2346 wpa_driver_test_get_interfaces(void *global_priv)
2347 {
2348 /* struct wpa_driver_test_global *global = priv; */
2349 struct wpa_interface_info *iface;
2350
2351 iface = os_zalloc(sizeof(*iface));
2352 if (iface == NULL)
2353 return iface;
2354 iface->ifname = os_strdup("sta0");
2355 iface->desc = os_strdup("test interface 0");
2356 iface->drv_name = "test";
2357 iface->next = os_zalloc(sizeof(*iface));
2358 if (iface->next) {
2359 iface->next->ifname = os_strdup("sta1");
2360 iface->next->desc = os_strdup("test interface 1");
2361 iface->next->drv_name = "test";
2362 }
2363
2364 return iface;
2365 }
2366
2367 #endif /* HOSTAPD */
2368
2369
2370 #if defined(HOSTAPD) || defined(CONFIG_CLIENT_MLME)
2371 static struct hostapd_hw_modes *
2372 wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
2373 {
2374 struct hostapd_hw_modes *modes;
2375
2376 *num_modes = 3;
2377 *flags = 0;
2378 modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
2379 if (modes == NULL)
2380 return NULL;
2381 modes[0].mode = HOSTAPD_MODE_IEEE80211G;
2382 modes[0].num_channels = 1;
2383 modes[0].num_rates = 1;
2384 modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2385 modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2386 if (modes[0].channels == NULL || modes[0].rates == NULL)
2387 goto fail;
2388 modes[0].channels[0].chan = 1;
2389 modes[0].channels[0].freq = 2412;
2390 modes[0].channels[0].flag = 0;
2391 modes[0].rates[0].rate = 10;
2392 modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2393 HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
2394
2395 modes[1].mode = HOSTAPD_MODE_IEEE80211B;
2396 modes[1].num_channels = 1;
2397 modes[1].num_rates = 1;
2398 modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2399 modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2400 if (modes[1].channels == NULL || modes[1].rates == NULL)
2401 goto fail;
2402 modes[1].channels[0].chan = 1;
2403 modes[1].channels[0].freq = 2412;
2404 modes[1].channels[0].flag = 0;
2405 modes[1].rates[0].rate = 10;
2406 modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2407 HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
2408
2409 modes[2].mode = HOSTAPD_MODE_IEEE80211A;
2410 modes[2].num_channels = 1;
2411 modes[2].num_rates = 1;
2412 modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
2413 modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
2414 if (modes[2].channels == NULL || modes[2].rates == NULL)
2415 goto fail;
2416 modes[2].channels[0].chan = 60;
2417 modes[2].channels[0].freq = 5300;
2418 modes[2].channels[0].flag = 0;
2419 modes[2].rates[0].rate = 60;
2420 modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
2421 HOSTAPD_RATE_MANDATORY;
2422
2423 return modes;
2424
2425 fail:
2426 if (modes) {
2427 size_t i;
2428 for (i = 0; i < *num_modes; i++) {
2429 os_free(modes[i].channels);
2430 os_free(modes[i].rates);
2431 }
2432 os_free(modes);
2433 }
2434 return NULL;
2435 }
2436 #endif /* HOSTAPD || CONFIG_CLIENT_MLME */
2437
2438
2439 const struct wpa_driver_ops wpa_driver_test_ops = {
2440 "test",
2441 "wpa_supplicant test driver",
2442 #ifdef HOSTAPD
2443 .hapd_init = test_driver_init,
2444 .hapd_deinit = test_driver_deinit,
2445 .hapd_send_eapol = test_driver_send_eapol,
2446 .send_mlme = wpa_driver_test_send_mlme,
2447 .set_generic_elem = test_driver_set_generic_elem,
2448 .sta_deauth = test_driver_sta_deauth,
2449 .sta_disassoc = test_driver_sta_disassoc,
2450 .get_hw_feature_data = wpa_driver_test_get_hw_feature_data,
2451 .bss_add = test_driver_bss_add,
2452 .bss_remove = test_driver_bss_remove,
2453 .if_add = test_driver_if_add,
2454 .if_update = test_driver_if_update,
2455 .if_remove = test_driver_if_remove,
2456 .valid_bss_mask = test_driver_valid_bss_mask,
2457 .hapd_set_ssid = test_driver_set_ssid,
2458 .set_privacy = test_driver_set_privacy,
2459 .hapd_set_key = test_driver_set_key,
2460 .set_sta_vlan = test_driver_set_sta_vlan,
2461 .sta_add = test_driver_sta_add,
2462 .send_ether = test_driver_send_ether,
2463 .set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
2464 .set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
2465 #else /* HOSTAPD */
2466 wpa_driver_test_get_bssid,
2467 wpa_driver_test_get_ssid,
2468 wpa_driver_test_set_wpa,
2469 wpa_driver_test_set_key,
2470 NULL /* init */,
2471 wpa_driver_test_deinit,
2472 wpa_driver_test_set_param,
2473 NULL /* set_countermeasures */,
2474 NULL /* set_drop_unencrypted */,
2475 NULL /* scan */,
2476 NULL /* get_scan_results */,
2477 wpa_driver_test_deauthenticate,
2478 wpa_driver_test_disassociate,
2479 wpa_driver_test_associate,
2480 NULL /* set_auth_alg */,
2481 NULL /* add_pmkid */,
2482 NULL /* remove_pmkid */,
2483 NULL /* flush_pmkid */,
2484 wpa_driver_test_get_capa,
2485 NULL /* poll */,
2486 NULL /* get_ifname */,
2487 wpa_driver_test_get_mac_addr,
2488 wpa_driver_test_send_eapol,
2489 NULL /* set_operstate */,
2490 wpa_driver_test_mlme_setprotection,
2491 #ifdef CONFIG_CLIENT_MLME
2492 wpa_driver_test_get_hw_feature_data,
2493 wpa_driver_test_set_channel,
2494 wpa_driver_test_set_ssid,
2495 wpa_driver_test_set_bssid,
2496 wpa_driver_test_send_mlme,
2497 wpa_driver_test_mlme_add_sta,
2498 wpa_driver_test_mlme_remove_sta,
2499 #else /* CONFIG_CLIENT_MLME */
2500 NULL /* get_hw_feature_data */,
2501 NULL /* set_channel */,
2502 NULL /* set_ssid */,
2503 NULL /* set_bssid */,
2504 NULL /* send_mlme */,
2505 NULL /* mlme_add_sta */,
2506 NULL /* mlme_remove_sta */,
2507 #endif /* CONFIG_CLIENT_MLME */
2508 NULL /* update_ft_ies */,
2509 NULL /* send_ft_action */,
2510 wpa_driver_test_get_scan_results2,
2511 wpa_driver_test_set_probe_req_ie,
2512 NULL /* set_mode */,
2513 NULL /* set_country */,
2514 wpa_driver_test_global_init,
2515 wpa_driver_test_global_deinit,
2516 wpa_driver_test_init2,
2517 wpa_driver_test_get_interfaces,
2518 wpa_driver_test_scan,
2519 NULL /* authenticate */,
2520 NULL /* set_beacon */,
2521 NULL /* set_beacon_int */,
2522 NULL /* hapd_init */,
2523 NULL /* init_bssid */,
2524 NULL /* hapd_deinit */,
2525 NULL /* set_ieee8021x */,
2526 NULL /* set_privacy */,
2527 NULL /* hapd_set_key */,
2528 NULL /* get_seqnum */,
2529 NULL /* get_seqnum_igtk */,
2530 NULL /* flush */,
2531 NULL /* set_generic_elem */,
2532 NULL /* read_sta_data */,
2533 NULL /* hapd_send_eapol */,
2534 NULL /* sta_deauth */,
2535 NULL /* sta_disassoc */,
2536 NULL /* sta_remove */,
2537 NULL /* hapd_get_ssid */,
2538 NULL /* hapd_set_ssid */,
2539 NULL /* hapd_set_countermeasures */,
2540 NULL /* sta_add */,
2541 NULL /* get_inact_sec */,
2542 NULL /* sta_clear_stats */,
2543 NULL /* set_freq */,
2544 NULL /* set_rts */,
2545 NULL /* set_frag */,
2546 NULL /* set_retry */,
2547 NULL /* sta_set_flags */,
2548 NULL /* set_rate_sets */,
2549 NULL /* hapd_set_country */,
2550 NULL /* set_ieee80211d */,
2551 NULL /* hapd_set_beacon */,
2552 NULL /* set_internal_bridge */,
2553 NULL /* hapd_set_beacon_int */,
2554 NULL /* set_broadcast_ssid */,
2555 NULL /* set_cts_protect */,
2556 NULL /* set_preamble */,
2557 NULL /* set_short_slot_time */,
2558 NULL /* set_tx_queue_params */,
2559 NULL /* bss_add */,
2560 NULL /* bss_remove */,
2561 NULL /* valid_bss_mask */,
2562 NULL /* passive_scan */,
2563 NULL /* if_add */,
2564 NULL /* if_update */,
2565 NULL /* if_remove */,
2566 NULL /* set_sta_vlan */,
2567 NULL /* commit */,
2568 NULL /* send_ether */,
2569 NULL /* set_radius_acl_auth */,
2570 NULL /* set_radius_acl_expire */,
2571 NULL /* set_ht_params */,
2572 NULL /* set_wps_beacon_ie */,
2573 NULL /* set_wps_probe_resp_ie */,
2574 NULL /* get_neighbor_bss */
2575 #endif /* HOSTAPD */
2576 };