/*
* windows backend for libusb 1.0
* Copyright © 2009-2012 Pete Batard <pete@akeo.ie>
* Copyright © 2016-2018 Chris Dickens <christopher.a.dickens@gmail.com>
* With contributions from Michael Plante, Orin Eman et al.
* Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
* HID Reports IOCTLs inspired from HIDAPI by Alan Ott, Signal 11 Software
* Hash table functions adapted from glibc, by Ulrich Drepper et al.
* Major code testing contribution by Xiaofan Chen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <windows.h>
#include <setupapi.h>
#include <ctype.h>
#include <stdio.h>
#include "libusbi.h"
#include "windows_winusb.h"
#define HANDLE_VALID(h) (((h) != NULL) && ((h) != INVALID_HANDLE_VALUE))
// The below macro is used in conjunction with safe loops.
#define LOOP_BREAK(err) \
{ \
r = err; \
continue; \
}
// WinUSB-like API prototypes
static bool winusbx_init(struct libusb_context *ctx);
static void winusbx_exit(void);
static int winusbx_open(int sub_api, struct libusb_device_handle *dev_handle);
static void winusbx_close(int sub_api, struct libusb_device_handle *dev_handle);
static int winusbx_configure_endpoints(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
static int winusbx_release_interface(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
static int winusbx_submit_control_transfer(int sub_api, struct usbi_transfer *itransfer);
static int winusbx_set_interface_altsetting(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface, uint8_t altsetting);
static int winusbx_submit_iso_transfer(int sub_api, struct usbi_transfer *itransfer);
static int winusbx_submit_bulk_transfer(int sub_api, struct usbi_transfer *itransfer);
static int winusbx_clear_halt(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint);
static int winusbx_cancel_transfer(int sub_api, struct usbi_transfer *itransfer);
static int winusbx_reset_device(int sub_api, struct libusb_device_handle *dev_handle);
static enum libusb_transfer_status winusbx_copy_transfer_data(int sub_api, struct usbi_transfer *itransfer, DWORD length);
// HID API prototypes
static bool hid_init(struct libusb_context *ctx);
static void hid_exit(void);
static int hid_open(int sub_api, struct libusb_device_handle *dev_handle);
static void hid_close(int sub_api, struct libusb_device_handle *dev_handle);
static int hid_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
static int hid_release_interface(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
static int hid_set_interface_altsetting(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface, uint8_t altsetting);
static int hid_submit_control_transfer(int sub_api, struct usbi_transfer *itransfer);
static int hid_submit_bulk_transfer(int sub_api, struct usbi_transfer *itransfer);
static int hid_clear_halt(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint);
static int hid_reset_device(int sub_api, struct libusb_device_handle *dev_handle);
static enum libusb_transfer_status hid_copy_transfer_data(int sub_api, struct usbi_transfer *itransfer, DWORD length);
// Composite API prototypes
static int composite_open(int sub_api, struct libusb_device_handle *dev_handle);
static void composite_close(int sub_api, struct libusb_device_handle *dev_handle);
static int composite_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
static int composite_set_interface_altsetting(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface, uint8_t altsetting);
static int composite_release_interface(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
static int composite_submit_control_transfer(int sub_api, struct usbi_transfer *itransfer);
static int composite_submit_bulk_transfer(int sub_api, struct usbi_transfer *itransfer);
static int composite_submit_iso_transfer(int sub_api, struct usbi_transfer *itransfer);
static int composite_clear_halt(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint);
static int composite_cancel_transfer(int sub_api, struct usbi_transfer *itransfer);
static int composite_reset_device(int sub_api, struct libusb_device_handle *dev_handle);
static enum libusb_transfer_status composite_copy_transfer_data(int sub_api, struct usbi_transfer *itransfer, DWORD length);
static usbi_mutex_t autoclaim_lock;
// API globals
static struct winusb_interface WinUSBX[SUB_API_MAX];
#define CHECK_WINUSBX_AVAILABLE(sub_api) \
do { \
if (sub_api == SUB_API_NOTSET) \
sub_api = priv->sub_api; \
if (WinUSBX[sub_api].hDll == NULL) \
return LIBUSB_ERROR_ACCESS; \
} while (0)
#define CHECK_HID_AVAILABLE \
do { \
if (DLL_HANDLE_NAME(hid) == NULL) \
return LIBUSB_ERROR_ACCESS; \
} while (0)
#if defined(ENABLE_LOGGING)
static const char *guid_to_string(const GUID *guid, char guid_string[MAX_GUID_STRING_LENGTH])
{
if (guid == NULL) {
guid_string[0] = '\0';
return guid_string;
}
sprintf(guid_string, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
(unsigned int)guid->Data1, guid->Data2, guid->Data3,
guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
return guid_string;
}
#endif
static bool string_to_guid(const char guid_string[MAX_GUID_STRING_LENGTH], GUID *guid)
{
unsigned short tmp[4];
int num_chars = -1;
char extra;
int r;
// Unfortunately MinGW complains that '%hhx' is not a valid format specifier,
// even though Visual Studio 2013 and later support it. Rather than complicating
// the logic in this function with '#ifdef's, use a temporary array on the stack
// to store the conversions.
r = sscanf(guid_string, "{%8x-%4hx-%4hx-%4hx-%4hx%4hx%4hx}%n%c",
(unsigned int *)&guid->Data1, &guid->Data2, &guid->Data3,
&tmp[0], &tmp[1], &tmp[2], &tmp[3], &num_chars, &extra);
if ((r != 7) || (num_chars != 38))
return false;
// Extract the bytes from the 2-byte shorts
guid->Data4[0] = (unsigned char)((tmp[0] >> 8) & 0xFF);
guid->Data4[1] = (unsigned char)(tmp[0] & 0xFF);
guid->Data4[2] = (unsigned char)((tmp[1] >> 8) & 0xFF);
guid->Data4[3] = (unsigned char)(tmp[1] & 0xFF);
guid->Data4[4] = (unsigned char)((tmp[2] >> 8) & 0xFF);
guid->Data4[5] = (unsigned char)(tmp[2] & 0xFF);
guid->Data4[6] = (unsigned char)((tmp[3] >> 8) & 0xFF);
guid->Data4[7] = (unsigned char)(tmp[3] & 0xFF);
return true;
}
/*
* Normalize Microsoft's paths: return a duplicate of the given path
* with all characters converted to uppercase
*/
static char *normalize_path(const char *path)
{
char *ret_path = _strdup(path);
char *p;
if (ret_path == NULL)
return NULL;
for (p = ret_path; *p != '\0'; p++)
*p = (char)toupper((unsigned char)*p);
return ret_path;
}
/*
* Cfgmgr32, AdvAPI32, OLE32 and SetupAPI DLL functions
*/
static bool init_dlls(struct libusb_context *ctx)
{
DLL_GET_HANDLE(ctx, Cfgmgr32);
DLL_LOAD_FUNC(Cfgmgr32, CM_Get_Parent, true);
DLL_LOAD_FUNC(Cfgmgr32, CM_Get_Child, true);
// Prefixed to avoid conflict with he
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Debian 10 下 Qt 5.12.3 使用libusb 1.0.26源码工程示例 在源码移植过程中,注释掉部分功能,如下 注释掉了一个线程等待函数 注释掉了部分获取系统时间函数, 注释掉了部分断言宏 目前以编译通过,且测试 libusb_init(NULL)没有问题
资源推荐
资源详情
资源评论
收起资源包目录
Qt_libusb_1.0.26_Demo.rar (51个子文件)
libusbDemo
libusbDemo.pro.user 18KB
main.cpp 172B
mainwindow.ui 536B
libusb
config.h 4KB
libusb.h 74KB
version.h 431B
Makefile.am.extra 754B
descriptor.c 34KB
version_nano.h 26B
os
linux_usbfs.c 77KB
windows_winusb.h 24KB
openbsd_usb.c 17KB
linux_netlink.c 10KB
darwin_usb.h 7KB
darwin_usb.c 96KB
threads_posix.c 3KB
null_usb.c 3KB
haiku_pollfs.cpp 7KB
linux_usbfs.h 6KB
haiku_usb_raw.cpp 7KB
events_windows.h 1KB
events_windows.c 7KB
haiku_usb_backend.cpp 16KB
linux_udev.c 8KB
sunos_usb.c 43KB
threads_windows.h 3KB
haiku_usb.h 3KB
windows_common.c 29KB
windows_usbdk.h 3KB
windows_usbdk.c 23KB
events_posix.h 2KB
sunos_usb.h 2KB
windows_common.h 14KB
haiku_usb_raw.h 4KB
netbsd_usb.c 15KB
threads_windows.c 1KB
events_posix.c 8KB
threads_posix.h 3KB
windows_winusb.c 163KB
Makefile.am 2KB
sync.c 12KB
libusb-1.0.rc 2KB
core.c 93KB
libusbi.h 50KB
strerror.c 8KB
io.c 108KB
hotplug.c 15KB
libusb-1.0.def 8KB
mainwindow.cpp 301B
mainwindow.h 323B
libusbDemo.pro 1KB
共 51 条
- 1
资源评论
- zyy8905082023-01-26资源很受用,资源主总结的很全面,内容与描述一致,解决了我当下的问题。
- cbq18002023-12-21资源很好用,有较大的参考价值,资源不错,支持一下。
DreamLife.
- 粉丝: 3w+
- 资源: 75
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功