2 * WPA Supplicant - testing driver interface
3 * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
22 #include "l2_packet/l2_packet.h"
25 #include "ieee802_11_defs.h"
28 struct wpa_driver_test_data
{
30 u8 own_addr
[ETH_ALEN
];
32 struct sockaddr_un hostapd_addr
;
34 char *own_socket_path
;
39 #define MAX_SCAN_RESULTS 30
40 struct wpa_scan_res
*scanres
[MAX_SCAN_RESULTS
];
44 size_t assoc_wpa_ie_len
;
50 static void wpa_driver_test_poll(void *eloop_ctx
, void *timeout_ctx
)
52 struct wpa_driver_test_data
*drv
= eloop_ctx
;
54 if (drv
->associated
&& drv
->hostapd_addr_set
) {
56 if (stat(drv
->hostapd_addr
.sun_path
, &st
) < 0) {
57 wpa_printf(MSG_DEBUG
, "%s: lost connection to AP: %s",
58 __func__
, strerror(errno
));
60 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
64 eloop_register_timeout(1, 0, wpa_driver_test_poll
, drv
, NULL
);
68 static int wpa_driver_test_set_wpa(void *priv
, int enabled
)
70 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, enabled
);
75 static void wpa_driver_test_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
77 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
78 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
82 static void wpa_driver_scan_dir(struct wpa_driver_test_data
*drv
,
87 struct sockaddr_un addr
;
93 while ((dent
= readdir(dir
))) {
94 if (os_strncmp(dent
->d_name
, "AP-", 3) != 0)
96 wpa_printf(MSG_DEBUG
, "%s: SCAN %s", __func__
, dent
->d_name
);
98 os_memset(&addr
, 0, sizeof(addr
));
99 addr
.sun_family
= AF_UNIX
;
100 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s/%s",
103 if (sendto(drv
->test_socket
, "SCAN", 4, 0,
104 (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
105 perror("sendto(test_socket)");
112 static int wpa_driver_test_scan(void *priv
, const u8
*ssid
, size_t ssid_len
)
114 struct wpa_driver_test_data
*drv
= priv
;
115 wpa_printf(MSG_DEBUG
, "%s: priv=%p", __func__
, priv
);
117 drv
->num_scanres
= 0;
119 if (drv
->test_socket
>= 0 && drv
->test_dir
)
120 wpa_driver_scan_dir(drv
, drv
->test_dir
);
122 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_set
&&
123 sendto(drv
->test_socket
, "SCAN", 4, 0,
124 (struct sockaddr
*) &drv
->hostapd_addr
,
125 sizeof(drv
->hostapd_addr
)) < 0) {
126 perror("sendto(test_socket)");
129 eloop_cancel_timeout(wpa_driver_test_scan_timeout
, drv
, drv
->ctx
);
130 eloop_register_timeout(1, 0, wpa_driver_test_scan_timeout
, drv
,
136 static struct wpa_scan_results
* wpa_driver_test_get_scan_results2(void *priv
)
138 struct wpa_driver_test_data
*drv
= priv
;
139 struct wpa_scan_results
*res
;
142 res
= os_zalloc(sizeof(*res
));
146 res
->res
= os_zalloc(drv
->num_scanres
* sizeof(struct wpa_scan_res
*));
147 if (res
->res
== NULL
) {
152 for (i
= 0; i
< drv
->num_scanres
; i
++) {
153 struct wpa_scan_res
*r
;
154 if (drv
->scanres
[i
] == NULL
)
156 r
= os_malloc(sizeof(*r
) + drv
->scanres
[i
]->ie_len
);
159 os_memcpy(r
, drv
->scanres
[i
],
160 sizeof(*r
) + drv
->scanres
[i
]->ie_len
);
161 res
->res
[res
->num
++] = r
;
168 static int wpa_driver_test_set_key(void *priv
, wpa_alg alg
, const u8
*addr
,
169 int key_idx
, int set_tx
,
170 const u8
*seq
, size_t seq_len
,
171 const u8
*key
, size_t key_len
)
173 wpa_printf(MSG_DEBUG
, "%s: priv=%p alg=%d key_idx=%d set_tx=%d",
174 __func__
, priv
, alg
, key_idx
, set_tx
);
176 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
179 wpa_hexdump(MSG_DEBUG
, " seq", seq
, seq_len
);
182 wpa_hexdump(MSG_DEBUG
, " key", key
, key_len
);
188 static int wpa_driver_test_associate(
189 void *priv
, struct wpa_driver_associate_params
*params
)
191 struct wpa_driver_test_data
*drv
= priv
;
192 wpa_printf(MSG_DEBUG
, "%s: priv=%p freq=%d pairwise_suite=%d "
193 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d",
194 __func__
, priv
, params
->freq
, params
->pairwise_suite
,
195 params
->group_suite
, params
->key_mgmt_suite
,
196 params
->auth_alg
, params
->mode
);
198 wpa_printf(MSG_DEBUG
, " bssid=" MACSTR
,
199 MAC2STR(params
->bssid
));
202 wpa_hexdump_ascii(MSG_DEBUG
, " ssid",
203 params
->ssid
, params
->ssid_len
);
205 if (params
->wpa_ie
) {
206 wpa_hexdump(MSG_DEBUG
, " wpa_ie",
207 params
->wpa_ie
, params
->wpa_ie_len
);
208 drv
->assoc_wpa_ie_len
= params
->wpa_ie_len
;
209 if (drv
->assoc_wpa_ie_len
> sizeof(drv
->assoc_wpa_ie
))
210 drv
->assoc_wpa_ie_len
= sizeof(drv
->assoc_wpa_ie
);
211 os_memcpy(drv
->assoc_wpa_ie
, params
->wpa_ie
,
212 drv
->assoc_wpa_ie_len
);
214 drv
->assoc_wpa_ie_len
= 0;
216 if (drv
->test_dir
&& params
->bssid
) {
217 os_memset(&drv
->hostapd_addr
, 0, sizeof(drv
->hostapd_addr
));
218 drv
->hostapd_addr
.sun_family
= AF_UNIX
;
219 os_snprintf(drv
->hostapd_addr
.sun_path
,
220 sizeof(drv
->hostapd_addr
.sun_path
),
222 drv
->test_dir
, MAC2STR(params
->bssid
));
223 drv
->hostapd_addr_set
= 1;
226 if (drv
->test_socket
>= 0 && drv
->hostapd_addr_set
) {
227 char cmd
[200], *pos
, *end
;
229 end
= cmd
+ sizeof(cmd
);
231 ret
= os_snprintf(pos
, end
- pos
, "ASSOC " MACSTR
" ",
232 MAC2STR(drv
->own_addr
));
233 if (ret
>= 0 && ret
< end
- pos
)
235 pos
+= wpa_snprintf_hex(pos
, end
- pos
, params
->ssid
,
237 ret
= os_snprintf(pos
, end
- pos
, " ");
238 if (ret
>= 0 && ret
< end
- pos
)
240 pos
+= wpa_snprintf_hex(pos
, end
- pos
, params
->wpa_ie
,
243 if (sendto(drv
->test_socket
, cmd
, os_strlen(cmd
), 0,
244 (struct sockaddr
*) &drv
->hostapd_addr
,
245 sizeof(drv
->hostapd_addr
)) < 0) {
246 perror("sendto(test_socket)");
250 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
251 drv
->ssid_len
= params
->ssid_len
;
254 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
261 static int wpa_driver_test_get_bssid(void *priv
, u8
*bssid
)
263 struct wpa_driver_test_data
*drv
= priv
;
264 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
269 static int wpa_driver_test_get_ssid(void *priv
, u8
*ssid
)
271 struct wpa_driver_test_data
*drv
= priv
;
272 os_memcpy(ssid
, drv
->ssid
, 32);
273 return drv
->ssid_len
;
277 static int wpa_driver_test_send_disassoc(struct wpa_driver_test_data
*drv
)
279 if (drv
->test_socket
>= 0 &&
280 sendto(drv
->test_socket
, "DISASSOC", 8, 0,
281 (struct sockaddr
*) &drv
->hostapd_addr
,
282 sizeof(drv
->hostapd_addr
)) < 0) {
283 perror("sendto(test_socket)");
290 static int wpa_driver_test_deauthenticate(void *priv
, const u8
*addr
,
293 struct wpa_driver_test_data
*drv
= priv
;
294 wpa_printf(MSG_DEBUG
, "%s addr=" MACSTR
" reason_code=%d",
295 __func__
, MAC2STR(addr
), reason_code
);
296 os_memset(drv
->bssid
, 0, ETH_ALEN
);
298 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
299 return wpa_driver_test_send_disassoc(drv
);
303 static int wpa_driver_test_disassociate(void *priv
, const u8
*addr
,
306 struct wpa_driver_test_data
*drv
= priv
;
307 wpa_printf(MSG_DEBUG
, "%s addr=" MACSTR
" reason_code=%d",
308 __func__
, MAC2STR(addr
), reason_code
);
309 os_memset(drv
->bssid
, 0, ETH_ALEN
);
311 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
312 return wpa_driver_test_send_disassoc(drv
);
316 static void wpa_driver_test_scanresp(struct wpa_driver_test_data
*drv
,
317 struct sockaddr_un
*from
,
321 struct wpa_scan_res
*res
;
322 const char *pos
, *pos2
;
324 u8
*ie_pos
, *ie_start
, *ie_end
;
325 #define MAX_IE_LEN 1000
327 wpa_printf(MSG_DEBUG
, "test_driver: SCANRESP %s", data
);
328 if (drv
->num_scanres
>= MAX_SCAN_RESULTS
) {
329 wpa_printf(MSG_DEBUG
, "test_driver: No room for the new scan "
334 /* SCANRESP BSSID SSID IEs */
336 res
= os_zalloc(sizeof(*res
) + MAX_IE_LEN
);
339 ie_start
= ie_pos
= (u8
*) (res
+ 1);
340 ie_end
= ie_pos
+ MAX_IE_LEN
;
342 if (hwaddr_aton(data
, res
->bssid
)) {
343 wpa_printf(MSG_DEBUG
, "test_driver: invalid BSSID in scanres");
351 pos2
= os_strchr(pos
, ' ');
353 wpa_printf(MSG_DEBUG
, "test_driver: invalid SSID termination "
358 len
= (pos2
- pos
) / 2;
362 * Generate SSID IE from the SSID field since this IE is not included
363 * in the main IE field.
365 *ie_pos
++ = WLAN_EID_SSID
;
367 if (hexstr2bin(pos
, ie_pos
, len
) < 0) {
368 wpa_printf(MSG_DEBUG
, "test_driver: invalid SSID in scanres");
375 pos2
= os_strchr(pos
, ' ');
377 len
= os_strlen(pos
) / 2;
379 len
= (pos2
- pos
) / 2;
380 if ((int) len
> ie_end
- ie_pos
)
381 len
= ie_end
- ie_pos
;
382 if (hexstr2bin(pos
, ie_pos
, len
) < 0) {
383 wpa_printf(MSG_DEBUG
, "test_driver: invalid IEs in scanres");
388 res
->ie_len
= ie_pos
- ie_start
;
394 if (os_strncmp(pos
, "PRIVACY", 7) == 0)
395 res
->caps
|= IEEE80211_CAP_PRIVACY
;
398 os_free(drv
->scanres
[drv
->num_scanres
]);
399 drv
->scanres
[drv
->num_scanres
++] = res
;
403 static void wpa_driver_test_assocresp(struct wpa_driver_test_data
*drv
,
404 struct sockaddr_un
*from
,
408 /* ASSOCRESP BSSID <res> */
409 if (hwaddr_aton(data
, drv
->bssid
)) {
410 wpa_printf(MSG_DEBUG
, "test_driver: invalid BSSID in "
413 if (drv
->use_associnfo
) {
414 union wpa_event_data event
;
415 os_memset(&event
, 0, sizeof(event
));
416 event
.assoc_info
.req_ies
= drv
->assoc_wpa_ie
;
417 event
.assoc_info
.req_ies_len
= drv
->assoc_wpa_ie_len
;
418 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOCINFO
, &event
);
421 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
425 static void wpa_driver_test_disassoc(struct wpa_driver_test_data
*drv
,
426 struct sockaddr_un
*from
,
430 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
434 static void wpa_driver_test_eapol(struct wpa_driver_test_data
*drv
,
435 struct sockaddr_un
*from
,
437 const u8
*data
, size_t data_len
)
439 const u8
*src
= drv
->bssid
;
442 /* Skip Ethernet header */
443 src
= data
+ ETH_ALEN
;
447 wpa_supplicant_rx_eapol(drv
->ctx
, src
, data
, data_len
);
451 static void wpa_driver_test_mlme(struct wpa_driver_test_data
*drv
,
452 struct sockaddr_un
*from
,
454 const u8
*data
, size_t data_len
)
456 struct ieee80211_rx_status rx_status
;
457 os_memset(&rx_status
, 0, sizeof(rx_status
));
458 wpa_supplicant_sta_rx(drv
->ctx
, data
, data_len
, &rx_status
);
462 static void wpa_driver_test_receive_unix(int sock
, void *eloop_ctx
,
465 struct wpa_driver_test_data
*drv
= eloop_ctx
;
468 struct sockaddr_un from
;
469 socklen_t fromlen
= sizeof(from
);
470 const size_t buflen
= 2000;
472 buf
= os_malloc(buflen
);
475 res
= recvfrom(sock
, buf
, buflen
- 1, 0,
476 (struct sockaddr
*) &from
, &fromlen
);
478 perror("recvfrom(test_socket)");
484 wpa_printf(MSG_DEBUG
, "test_driver: received %u bytes", res
);
486 if (os_strncmp(buf
, "SCANRESP ", 9) == 0) {
487 wpa_driver_test_scanresp(drv
, &from
, fromlen
, buf
+ 9);
488 } else if (os_strncmp(buf
, "ASSOCRESP ", 10) == 0) {
489 wpa_driver_test_assocresp(drv
, &from
, fromlen
, buf
+ 10);
490 } else if (os_strcmp(buf
, "DISASSOC") == 0) {
491 wpa_driver_test_disassoc(drv
, &from
, fromlen
);
492 } else if (os_strcmp(buf
, "DEAUTH") == 0) {
493 wpa_driver_test_disassoc(drv
, &from
, fromlen
);
494 } else if (os_strncmp(buf
, "EAPOL ", 6) == 0) {
495 wpa_driver_test_eapol(drv
, &from
, fromlen
,
496 (const u8
*) buf
+ 6, res
- 6);
497 } else if (os_strncmp(buf
, "MLME ", 5) == 0) {
498 wpa_driver_test_mlme(drv
, &from
, fromlen
,
499 (const u8
*) buf
+ 5, res
- 5);
501 wpa_hexdump_ascii(MSG_DEBUG
, "Unknown test_socket command",
508 static void * wpa_driver_test_init(void *ctx
, const char *ifname
)
510 struct wpa_driver_test_data
*drv
;
512 drv
= os_zalloc(sizeof(*drv
));
516 drv
->test_socket
= -1;
518 /* Set dummy BSSID and SSID for testing. */
519 drv
->bssid
[0] = 0x02;
520 drv
->bssid
[1] = 0x00;
521 drv
->bssid
[2] = 0x00;
522 drv
->bssid
[3] = 0x00;
523 drv
->bssid
[4] = 0x00;
524 drv
->bssid
[5] = 0x01;
525 os_memcpy(drv
->ssid
, "test", 5);
528 /* Generate a MAC address to help testing with multiple STAs */
529 drv
->own_addr
[0] = 0x02; /* locally administered */
530 sha1_prf((const u8
*) ifname
, os_strlen(ifname
),
531 "wpa_supplicant test mac addr generation",
532 NULL
, 0, drv
->own_addr
+ 1, ETH_ALEN
- 1);
533 eloop_register_timeout(1, 0, wpa_driver_test_poll
, drv
, NULL
);
539 static void wpa_driver_test_close_test_socket(struct wpa_driver_test_data
*drv
)
541 if (drv
->test_socket
>= 0) {
542 eloop_unregister_read_sock(drv
->test_socket
);
543 close(drv
->test_socket
);
544 drv
->test_socket
= -1;
547 if (drv
->own_socket_path
) {
548 unlink(drv
->own_socket_path
);
549 os_free(drv
->own_socket_path
);
550 drv
->own_socket_path
= NULL
;
555 static void wpa_driver_test_deinit(void *priv
)
557 struct wpa_driver_test_data
*drv
= priv
;
559 wpa_driver_test_close_test_socket(drv
);
560 eloop_cancel_timeout(wpa_driver_test_scan_timeout
, drv
, drv
->ctx
);
561 eloop_cancel_timeout(wpa_driver_test_poll
, drv
, NULL
);
562 os_free(drv
->test_dir
);
563 for (i
= 0; i
< MAX_SCAN_RESULTS
; i
++)
564 os_free(drv
->scanres
[i
]);
569 static int wpa_driver_test_attach(struct wpa_driver_test_data
*drv
,
572 static unsigned int counter
= 0;
573 struct sockaddr_un addr
;
576 os_free(drv
->own_socket_path
);
578 len
= os_strlen(dir
) + 30;
579 drv
->own_socket_path
= os_malloc(len
);
580 if (drv
->own_socket_path
== NULL
)
582 os_snprintf(drv
->own_socket_path
, len
, "%s/STA-" MACSTR
,
583 dir
, MAC2STR(drv
->own_addr
));
585 drv
->own_socket_path
= os_malloc(100);
586 if (drv
->own_socket_path
== NULL
)
588 os_snprintf(drv
->own_socket_path
, 100,
589 "/tmp/wpa_supplicant_test-%d-%d",
590 getpid(), counter
++);
593 drv
->test_socket
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
594 if (drv
->test_socket
< 0) {
595 perror("socket(PF_UNIX)");
596 os_free(drv
->own_socket_path
);
597 drv
->own_socket_path
= NULL
;
601 os_memset(&addr
, 0, sizeof(addr
));
602 addr
.sun_family
= AF_UNIX
;
603 os_strlcpy(addr
.sun_path
, drv
->own_socket_path
, sizeof(addr
.sun_path
));
604 if (bind(drv
->test_socket
, (struct sockaddr
*) &addr
,
606 perror("bind(PF_UNIX)");
607 close(drv
->test_socket
);
608 unlink(drv
->own_socket_path
);
609 os_free(drv
->own_socket_path
);
610 drv
->own_socket_path
= NULL
;
614 eloop_register_read_sock(drv
->test_socket
,
615 wpa_driver_test_receive_unix
, drv
, NULL
);
621 static int wpa_driver_test_set_param(void *priv
, const char *param
)
623 struct wpa_driver_test_data
*drv
= priv
;
624 const char *pos
, *pos2
;
627 wpa_printf(MSG_DEBUG
, "%s: param='%s'", __func__
, param
);
631 wpa_driver_test_close_test_socket(drv
);
632 pos
= os_strstr(param
, "test_socket=");
635 pos2
= os_strchr(pos
, ' ');
639 len
= os_strlen(pos
);
640 if (len
> sizeof(drv
->hostapd_addr
.sun_path
))
642 os_memset(&drv
->hostapd_addr
, 0, sizeof(drv
->hostapd_addr
));
643 drv
->hostapd_addr
.sun_family
= AF_UNIX
;
644 os_memcpy(drv
->hostapd_addr
.sun_path
, pos
, len
);
645 drv
->hostapd_addr_set
= 1;
648 pos
= os_strstr(param
, "test_dir=");
651 os_free(drv
->test_dir
);
652 drv
->test_dir
= os_strdup(pos
+ 9);
653 if (drv
->test_dir
== NULL
)
655 end
= os_strchr(drv
->test_dir
, ' ');
658 wpa_driver_test_attach(drv
, drv
->test_dir
);
660 wpa_driver_test_attach(drv
, NULL
);
662 if (os_strstr(param
, "use_associnfo=1")) {
663 wpa_printf(MSG_DEBUG
, "test_driver: Use AssocInfo events");
664 drv
->use_associnfo
= 1;
667 #ifdef CONFIG_CLIENT_MLME
668 if (os_strstr(param
, "use_mlme=1")) {
669 wpa_printf(MSG_DEBUG
, "test_driver: Use internal MLME");
672 #endif /* CONFIG_CLIENT_MLME */
678 static const u8
* wpa_driver_test_get_mac_addr(void *priv
)
680 struct wpa_driver_test_data
*drv
= priv
;
681 wpa_printf(MSG_DEBUG
, "%s", __func__
);
682 return drv
->own_addr
;
686 static int wpa_driver_test_send_eapol(void *priv
, const u8
*dest
, u16 proto
,
687 const u8
*data
, size_t data_len
)
689 struct wpa_driver_test_data
*drv
= priv
;
692 struct l2_ethhdr eth
;
693 struct sockaddr_un addr
;
695 wpa_hexdump(MSG_MSGDUMP
, "test_send_eapol TX frame", data
, data_len
);
697 os_memset(ð
, 0, sizeof(eth
));
698 os_memcpy(eth
.h_dest
, dest
, ETH_ALEN
);
699 os_memcpy(eth
.h_source
, drv
->own_addr
, ETH_ALEN
);
700 eth
.h_proto
= host_to_be16(proto
);
702 io
[0].iov_base
= "EAPOL ";
704 io
[1].iov_base
= (u8
*) ð
;
705 io
[1].iov_len
= sizeof(eth
);
706 io
[2].iov_base
= (u8
*) data
;
707 io
[2].iov_len
= data_len
;
709 os_memset(&msg
, 0, sizeof(msg
));
712 if (os_memcmp(dest
, drv
->bssid
, ETH_ALEN
) == 0 ||
713 drv
->test_dir
== NULL
) {
714 msg
.msg_name
= &drv
->hostapd_addr
;
715 msg
.msg_namelen
= sizeof(drv
->hostapd_addr
);
718 os_memset(&addr
, 0, sizeof(addr
));
719 addr
.sun_family
= AF_UNIX
;
720 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
721 "%s/STA-" MACSTR
, drv
->test_dir
, MAC2STR(dest
));
722 if (stat(addr
.sun_path
, &st
) < 0) {
723 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
725 drv
->test_dir
, MAC2STR(dest
));
727 msg
.msg_name
= &addr
;
728 msg
.msg_namelen
= sizeof(addr
);
731 if (sendmsg(drv
->test_socket
, &msg
, 0) < 0) {
732 perror("sendmsg(test_socket)");
740 static int wpa_driver_test_get_capa(void *priv
, struct wpa_driver_capa
*capa
)
742 struct wpa_driver_test_data
*drv
= priv
;
743 os_memset(capa
, 0, sizeof(*capa
));
744 capa
->key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
745 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
746 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
747 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
|
748 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
|
749 WPA_DRIVER_CAPA_KEY_MGMT_FT
|
750 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
751 capa
->enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
752 WPA_DRIVER_CAPA_ENC_WEP104
|
753 WPA_DRIVER_CAPA_ENC_TKIP
|
754 WPA_DRIVER_CAPA_ENC_CCMP
;
755 capa
->auth
= WPA_DRIVER_AUTH_OPEN
|
756 WPA_DRIVER_AUTH_SHARED
|
757 WPA_DRIVER_AUTH_LEAP
;
759 capa
->flags
|= WPA_DRIVER_FLAGS_USER_SPACE_MLME
;
765 static int wpa_driver_test_mlme_setprotection(void *priv
, const u8
*addr
,
769 wpa_printf(MSG_DEBUG
, "%s: protect_type=%d key_type=%d",
770 __func__
, protect_type
, key_type
);
773 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
,
774 __func__
, MAC2STR(addr
));
781 #ifdef CONFIG_CLIENT_MLME
782 static struct wpa_hw_modes
*
783 wpa_driver_test_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
785 struct wpa_hw_modes
*modes
;
789 modes
= os_zalloc(*num_modes
* sizeof(struct wpa_hw_modes
));
792 modes
[0].mode
= WPA_MODE_IEEE80211G
;
793 modes
[0].num_channels
= 1;
794 modes
[0].num_rates
= 1;
795 modes
[0].channels
= os_zalloc(sizeof(struct wpa_channel_data
));
796 modes
[0].rates
= os_zalloc(sizeof(struct wpa_rate_data
));
797 if (modes
[0].channels
== NULL
|| modes
[0].rates
== NULL
) {
798 wpa_supplicant_sta_free_hw_features(modes
, *num_modes
);
801 modes
[0].channels
[0].chan
= 1;
802 modes
[0].channels
[0].freq
= 2412;
803 modes
[0].channels
[0].flag
= WPA_CHAN_W_SCAN
| WPA_CHAN_W_ACTIVE_SCAN
;
804 modes
[0].rates
[0].rate
= 10;
805 modes
[0].rates
[0].flags
= WPA_RATE_BASIC
| WPA_RATE_SUPPORTED
|
806 WPA_RATE_CCK
| WPA_RATE_MANDATORY
;
812 int wpa_driver_test_set_channel(void *priv
, wpa_hw_mode phymode
, int chan
,
815 wpa_printf(MSG_DEBUG
, "%s: phymode=%d chan=%d freq=%d",
816 __func__
, phymode
, chan
, freq
);
821 static int wpa_driver_test_send_mlme(void *priv
, const u8
*data
,
824 struct wpa_driver_test_data
*drv
= priv
;
827 struct sockaddr_un addr
;
832 wpa_hexdump(MSG_MSGDUMP
, "test_send_mlme", data
, data_len
);
837 io
[0].iov_base
= "MLME ";
839 io
[1].iov_base
= (u8
*) data
;
840 io
[1].iov_len
= data_len
;
842 os_memset(&msg
, 0, sizeof(msg
));
845 if (os_memcmp(dest
, drv
->bssid
, ETH_ALEN
) == 0 ||
846 drv
->test_dir
== NULL
) {
847 msg
.msg_name
= &drv
->hostapd_addr
;
848 msg
.msg_namelen
= sizeof(drv
->hostapd_addr
);
849 } else if (os_memcmp(dest
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0)
851 dir
= opendir(drv
->test_dir
);
854 while ((dent
= readdir(dir
))) {
855 #ifdef _DIRENT_HAVE_D_TYPE
856 /* Skip the file if it is not a socket.
857 * Also accept DT_UNKNOWN (0) in case
858 * the C library or underlying file
859 * system does not support d_type. */
860 if (dent
->d_type
!= DT_SOCK
&&
861 dent
->d_type
!= DT_UNKNOWN
)
863 #endif /* _DIRENT_HAVE_D_TYPE */
864 if (os_strcmp(dent
->d_name
, ".") == 0 ||
865 os_strcmp(dent
->d_name
, "..") == 0)
867 wpa_printf(MSG_DEBUG
, "%s: Send broadcast MLME to %s",
868 __func__
, dent
->d_name
);
869 os_memset(&addr
, 0, sizeof(addr
));
870 addr
.sun_family
= AF_UNIX
;
871 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
872 "%s/%s", drv
->test_dir
, dent
->d_name
);
874 msg
.msg_name
= &addr
;
875 msg
.msg_namelen
= sizeof(addr
);
877 if (sendmsg(drv
->test_socket
, &msg
, 0) < 0)
878 perror("sendmsg(test_socket)");
884 os_memset(&addr
, 0, sizeof(addr
));
885 addr
.sun_family
= AF_UNIX
;
886 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
887 "%s/AP-" MACSTR
, drv
->test_dir
, MAC2STR(dest
));
888 if (stat(addr
.sun_path
, &st
) < 0) {
889 os_snprintf(addr
.sun_path
, sizeof(addr
.sun_path
),
891 drv
->test_dir
, MAC2STR(dest
));
893 msg
.msg_name
= &addr
;
894 msg
.msg_namelen
= sizeof(addr
);
897 if (sendmsg(drv
->test_socket
, &msg
, 0) < 0) {
898 perror("sendmsg(test_socket)");
906 static int wpa_driver_test_mlme_add_sta(void *priv
, const u8
*addr
,
907 const u8
*supp_rates
,
908 size_t supp_rates_len
)
910 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
, __func__
, MAC2STR(addr
));
915 static int wpa_driver_test_mlme_remove_sta(void *priv
, const u8
*addr
)
917 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
, __func__
, MAC2STR(addr
));
922 int wpa_driver_test_set_ssid(void *priv
, const u8
*ssid
, size_t ssid_len
)
924 wpa_printf(MSG_DEBUG
, "%s", __func__
);
929 int wpa_driver_test_set_bssid(void *priv
, const u8
*bssid
)
931 wpa_printf(MSG_DEBUG
, "%s: bssid=" MACSTR
, __func__
, MAC2STR(bssid
));
934 #endif /* CONFIG_CLIENT_MLME */
937 const struct wpa_driver_ops wpa_driver_test_ops
= {
939 "wpa_supplicant test driver",
940 wpa_driver_test_get_bssid
,
941 wpa_driver_test_get_ssid
,
942 wpa_driver_test_set_wpa
,
943 wpa_driver_test_set_key
,
944 wpa_driver_test_init
,
945 wpa_driver_test_deinit
,
946 wpa_driver_test_set_param
,
947 NULL
/* set_countermeasures */,
948 NULL
/* set_drop_unencrypted */,
949 wpa_driver_test_scan
,
950 NULL
/* get_scan_results */,
951 wpa_driver_test_deauthenticate
,
952 wpa_driver_test_disassociate
,
953 wpa_driver_test_associate
,
954 NULL
/* set_auth_alg */,
955 NULL
/* add_pmkid */,
956 NULL
/* remove_pmkid */,
957 NULL
/* flush_pmkid */,
958 wpa_driver_test_get_capa
,
960 NULL
/* get_ifname */,
961 wpa_driver_test_get_mac_addr
,
962 wpa_driver_test_send_eapol
,
963 NULL
/* set_operstate */,
964 wpa_driver_test_mlme_setprotection
,
965 #ifdef CONFIG_CLIENT_MLME
966 wpa_driver_test_get_hw_feature_data
,
967 wpa_driver_test_set_channel
,
968 wpa_driver_test_set_ssid
,
969 wpa_driver_test_set_bssid
,
970 wpa_driver_test_send_mlme
,
971 wpa_driver_test_mlme_add_sta
,
972 wpa_driver_test_mlme_remove_sta
,
973 #else /* CONFIG_CLIENT_MLME */
974 NULL
/* get_hw_feature_data */,
975 NULL
/* set_channel */,
977 NULL
/* set_bssid */,
978 NULL
/* send_mlme */,
979 NULL
/* mlme_add_sta */,
980 NULL
/* mlme_remove_sta */,
981 #endif /* CONFIG_CLIENT_MLME */
982 NULL
/* update_ft_ies */,
983 NULL
/* send_ft_action */,
984 wpa_driver_test_get_scan_results2
,
985 NULL
/* set_probe_req_ie */