Lines Matching +full:dev +full:- +full:handle

2  * Copyright (c) 2019-2022 Yubico AB. All rights reserved.
3 * Use of this source code is governed by a BSD-style
5 * SPDX-License-Identifier: BSD-2-Clause
37 HANDLE dev; member
46 is_fido(HANDLE dev) in is_fido() argument
52 if (HidD_GetPreparsedData(dev, &data) == false) { in is_fido()
71 get_report_len(HANDLE dev, int dir, size_t *report_len) in get_report_len() argument
76 int ok = -1; in get_report_len()
78 if (HidD_GetPreparsedData(dev, &data) == false) { in get_report_len()
107 get_id(HANDLE dev, int16_t *vendor_id, int16_t *product_id) in get_id() argument
113 if (HidD_GetAttributes(dev, &attr) == false) { in get_id()
115 return (-1); in get_id()
125 get_manufacturer(HANDLE dev, char **manufacturer) in get_manufacturer() argument
129 int ok = -1; in get_manufacturer()
133 if (HidD_GetManufacturerString(dev, &buf, sizeof(buf)) == false) { in get_manufacturer()
139 -1, NULL, 0, NULL, NULL)) <= 0 || utf8_len > 128) { in get_manufacturer()
149 if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, buf, -1, in get_manufacturer()
166 get_product(HANDLE dev, char **product) in get_product() argument
170 int ok = -1; in get_product()
174 if (HidD_GetProductString(dev, &buf, sizeof(buf)) == false) { in get_product()
180 -1, NULL, 0, NULL, NULL)) <= 0 || utf8_len > 128) { in get_product()
190 if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, buf, -1, in get_product()
233 ifdetail->cbSize = sizeof(*ifdetail); in get_path()
242 if ((path = strdup(ifdetail->DevicePath)) == NULL) { in get_path()
302 HANDLE dev = INVALID_HANDLE_VALUE; in copy_info() local
303 int ok = -1; in copy_info()
307 if ((di->path = get_path(devinfo, ifdata)) == NULL) { in copy_info()
312 fido_log_debug("%s: path=%s", __func__, di->path); in copy_info()
321 dev = CreateFileA(di->path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, in copy_info()
323 if (dev == INVALID_HANDLE_VALUE) { in copy_info()
328 if (is_fido(dev) == false) { in copy_info()
333 if (get_id(dev, &di->vendor_id, &di->product_id) < 0) { in copy_info()
338 if (get_manufacturer(dev, &di->manufacturer) < 0) { in copy_info()
340 di->manufacturer = strdup(""); in copy_info()
343 if (get_product(dev, &di->product) < 0) { in copy_info()
345 di->product = strdup(""); in copy_info()
348 if (di->manufacturer == NULL || di->product == NULL) { in copy_info()
355 if (dev != INVALID_HANDLE_VALUE) in copy_info()
356 CloseHandle(dev); in copy_info()
359 free(di->path); in copy_info()
360 free(di->manufacturer); in copy_info()
361 free(di->product); in copy_info()
422 ctx->dev = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, in fido_hid_open()
426 if (ctx->dev == INVALID_HANDLE_VALUE) { in fido_hid_open()
431 if ((ctx->overlap.hEvent = CreateEventA(NULL, FALSE, FALSE, in fido_hid_open()
438 if (get_report_len(ctx->dev, 0, &ctx->report_in_len) < 0 || in fido_hid_open()
439 get_report_len(ctx->dev, 1, &ctx->report_out_len) < 0) { in fido_hid_open()
449 fido_hid_close(void *handle) in fido_hid_close() argument
451 struct hid_win *ctx = handle; in fido_hid_close()
453 if (ctx->overlap.hEvent != NULL) { in fido_hid_close()
454 if (ctx->report_pending) { in fido_hid_close()
456 if (CancelIoEx(ctx->dev, &ctx->overlap) == 0) in fido_hid_close()
460 CloseHandle(ctx->overlap.hEvent); in fido_hid_close()
463 explicit_bzero(ctx->report, sizeof(ctx->report)); in fido_hid_close()
464 CloseHandle(ctx->dev); in fido_hid_close()
469 fido_hid_set_sigmask(void *handle, const fido_sigset_t *sigmask) in fido_hid_set_sigmask() argument
471 (void)handle; in fido_hid_set_sigmask()
478 fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms) in fido_hid_read() argument
480 struct hid_win *ctx = handle; in fido_hid_read()
483 if (len != ctx->report_in_len - 1 || len > sizeof(ctx->report) - 1) { in fido_hid_read()
485 return (-1); in fido_hid_read()
488 if (ctx->report_pending == 0) { in fido_hid_read()
489 memset(&ctx->report, 0, sizeof(ctx->report)); in fido_hid_read()
490 ResetEvent(ctx->overlap.hEvent); in fido_hid_read()
491 if (ReadFile(ctx->dev, ctx->report, (DWORD)(len + 1), &n, in fido_hid_read()
492 &ctx->overlap) == 0 && GetLastError() != ERROR_IO_PENDING) { in fido_hid_read()
493 CancelIo(ctx->dev); in fido_hid_read()
495 return (-1); in fido_hid_read()
497 ctx->report_pending = 1; in fido_hid_read()
500 if (ms > -1 && WaitForSingleObject(ctx->overlap.hEvent, in fido_hid_read()
504 ctx->report_pending = 0; in fido_hid_read()
506 if (GetOverlappedResult(ctx->dev, &ctx->overlap, &n, TRUE) == 0) { in fido_hid_read()
508 return (-1); in fido_hid_read()
514 return (-1); in fido_hid_read()
517 memcpy(buf, ctx->report + 1, len); in fido_hid_read()
518 explicit_bzero(ctx->report, sizeof(ctx->report)); in fido_hid_read()
524 fido_hid_write(void *handle, const unsigned char *buf, size_t len) in fido_hid_write() argument
526 struct hid_win *ctx = handle; in fido_hid_write()
532 if (len != ctx->report_out_len) { in fido_hid_write()
534 return (-1); in fido_hid_write()
537 if (WriteFile(ctx->dev, buf, (DWORD)len, NULL, &overlap) == 0 && in fido_hid_write()
540 return (-1); in fido_hid_write()
543 if (GetOverlappedResult(ctx->dev, &overlap, &n, TRUE) == 0) { in fido_hid_write()
545 return (-1); in fido_hid_write()
551 return (-1); in fido_hid_write()
558 fido_hid_report_in_len(void *handle) in fido_hid_report_in_len() argument
560 struct hid_win *ctx = handle; in fido_hid_report_in_len()
562 return (ctx->report_in_len - 1); in fido_hid_report_in_len()
566 fido_hid_report_out_len(void *handle) in fido_hid_report_out_len() argument
568 struct hid_win *ctx = handle; in fido_hid_report_out_len()
570 return (ctx->report_out_len - 1); in fido_hid_report_out_len()