diff --git a/OpenRGB.pro b/OpenRGB.pro index e68bdd13..05dd413f 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -239,7 +239,7 @@ win32:INCLUDEPATH += dependencies/display-library/include \ dependencies/hidapi/hidapi \ dependencies/winring0/include \ - dependencies/libusb-1.0.22/include/libusb-1.0 \ + dependencies/libusb-1.0.27/include \ dependencies/mbedtls-2.24.0/include \ dependencies/NVFC \ wmi/ \ @@ -363,7 +363,7 @@ win32:contains(QMAKE_TARGET.arch, x86_64) { -lws2_32 \ -liphlpapi \ -L"$$PWD/dependencies/winring0/x64/" -lWinRing0x64 \ - -L"$$PWD/dependencies/libusb-1.0.22/MS64/dll" -llibusb-1.0 \ + -L"$$PWD/dependencies/libusb-1.0.27/VS2019/MS64/dll" -llibusb-1.0 \ -L"$$PWD/dependencies/hidapi-win/x64/" -lhidapi \ } @@ -372,7 +372,7 @@ win32:contains(QMAKE_TARGET.arch, x86) { -lws2_32 \ -liphlpapi \ -L"$$PWD/dependencies/winring0/Win32/" -lWinRing0 \ - -L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0 \ + -L"$$PWD/dependencies/libusb-1.0.27/VS2019/MS32/dll" -llibusb-1.0 \ -L"$$PWD/dependencies/hidapi-win/x86/" -lhidapi \ } @@ -411,10 +411,10 @@ win32:UI_DIR = _intermediate_$$DESTDIR/.ui #-----------------------------------------------------------------------------------------------# win32:contains(QMAKE_TARGET.arch, x86_64) { - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/x64/WinRing0x64.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/x64/WinRing0x64.sys )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.dll)\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/hidapi-win/x64/hidapi.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/x64/WinRing0x64.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/x64/WinRing0x64.sys )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.dll)\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/hidapi-win/x64/hidapi.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) first.depends = $(first) copydata export(first.depends) export(copydata.commands) @@ -422,11 +422,11 @@ win32:contains(QMAKE_TARGET.arch, x86_64) { } win32:contains(QMAKE_TARGET.arch, x86) { - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/Win32/WinRing0.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/Win32/WinRing0.sys )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/x64/WinRing0x64.sys )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.dll)\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) - copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/hidapi-win/x86/hidapi.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/Win32/WinRing0.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/Win32/WinRing0.sys )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/winring0/x64/WinRing0x64.sys )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.dll)\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) + copydata.commands += $(COPY_FILE) \"$$shell_path($$PWD/dependencies/hidapi-win/x86/hidapi.dll )\" \"$$shell_path($$DESTDIR)\" $$escape_expand(\n\t) first.depends = $(first) copydata export(first.depends) diff --git a/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.dll deleted file mode 100644 index 107ff42f..00000000 Binary files a/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.dll and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.lib b/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.lib deleted file mode 100644 index 35b4d637..00000000 Binary files a/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.lib and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.pdb b/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.pdb deleted file mode 100644 index abf5ccc7..00000000 Binary files a/dependencies/libusb-1.0.22/MS32/dll/libusb-1.0.pdb and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MS32/static/libusb-1.0.lib b/dependencies/libusb-1.0.22/MS32/static/libusb-1.0.lib deleted file mode 100644 index 641666d5..00000000 Binary files a/dependencies/libusb-1.0.22/MS32/static/libusb-1.0.lib and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.dll deleted file mode 100644 index 47c2f2af..00000000 Binary files a/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.dll and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.lib b/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.lib deleted file mode 100644 index 69a0bbe8..00000000 Binary files a/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.lib and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.pdb b/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.pdb deleted file mode 100644 index ac2b82f6..00000000 Binary files a/dependencies/libusb-1.0.22/MS64/dll/libusb-1.0.pdb and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MS64/static/libusb-1.0.lib b/dependencies/libusb-1.0.22/MS64/static/libusb-1.0.lib deleted file mode 100644 index 70111c3f..00000000 Binary files a/dependencies/libusb-1.0.22/MS64/static/libusb-1.0.lib and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MinGW32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.22/MinGW32/dll/libusb-1.0.dll deleted file mode 100644 index a45ab475..00000000 Binary files a/dependencies/libusb-1.0.22/MinGW32/dll/libusb-1.0.dll and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MinGW32/dll/libusb-1.0.dll.a b/dependencies/libusb-1.0.22/MinGW32/dll/libusb-1.0.dll.a deleted file mode 100644 index 7bde6f93..00000000 Binary files a/dependencies/libusb-1.0.22/MinGW32/dll/libusb-1.0.dll.a and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MinGW32/static/libusb-1.0.a b/dependencies/libusb-1.0.22/MinGW32/static/libusb-1.0.a deleted file mode 100644 index fd7d1f3a..00000000 Binary files a/dependencies/libusb-1.0.22/MinGW32/static/libusb-1.0.a and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MinGW64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.22/MinGW64/dll/libusb-1.0.dll deleted file mode 100644 index e9bafe02..00000000 Binary files a/dependencies/libusb-1.0.22/MinGW64/dll/libusb-1.0.dll and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MinGW64/dll/libusb-1.0.dll.a b/dependencies/libusb-1.0.22/MinGW64/dll/libusb-1.0.dll.a deleted file mode 100644 index 0f38f16f..00000000 Binary files a/dependencies/libusb-1.0.22/MinGW64/dll/libusb-1.0.dll.a and /dev/null differ diff --git a/dependencies/libusb-1.0.22/MinGW64/static/libusb-1.0.a b/dependencies/libusb-1.0.22/MinGW64/static/libusb-1.0.a deleted file mode 100644 index dc153065..00000000 Binary files a/dependencies/libusb-1.0.22/MinGW64/static/libusb-1.0.a and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin32/fxload.exe b/dependencies/libusb-1.0.22/examples/bin32/fxload.exe deleted file mode 100644 index a7a72664..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin32/fxload.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin32/listdevs.exe b/dependencies/libusb-1.0.22/examples/bin32/listdevs.exe deleted file mode 100644 index e3f5dd69..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin32/listdevs.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin32/testlibusb.exe b/dependencies/libusb-1.0.22/examples/bin32/testlibusb.exe deleted file mode 100644 index fc3b4c36..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin32/testlibusb.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin32/xusb.exe b/dependencies/libusb-1.0.22/examples/bin32/xusb.exe deleted file mode 100644 index 28ae0cc5..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin32/xusb.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin64/fxload.exe b/dependencies/libusb-1.0.22/examples/bin64/fxload.exe deleted file mode 100644 index 3afe3d95..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin64/fxload.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin64/listdevs.exe b/dependencies/libusb-1.0.22/examples/bin64/listdevs.exe deleted file mode 100644 index c1bf03e2..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin64/listdevs.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin64/testlibusb.exe b/dependencies/libusb-1.0.22/examples/bin64/testlibusb.exe deleted file mode 100644 index ee77e61f..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin64/testlibusb.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/bin64/xusb.exe b/dependencies/libusb-1.0.22/examples/bin64/xusb.exe deleted file mode 100644 index e352444d..00000000 Binary files a/dependencies/libusb-1.0.22/examples/bin64/xusb.exe and /dev/null differ diff --git a/dependencies/libusb-1.0.22/examples/source/stdint.h b/dependencies/libusb-1.0.22/examples/source/stdint.h deleted file mode 100644 index 00988d9b..00000000 --- a/dependencies/libusb-1.0.22/examples/source/stdint.h +++ /dev/null @@ -1,256 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file was originally part of the w64 mingw-runtime package. - */ - -/* ISO C9x 7.18 Integer types - * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794) - * - * THIS SOFTWARE IS NOT COPYRIGHTED - * - * Contributor: Danny Smith - * Modified for libusb/MSVC: Pete Batard - * - * This source code is offered for use in the public domain. You may - * use, modify or distribute it freely. - * - * This code is distributed in the hope that it will be useful but - * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY - * DISCLAIMED. This includes but is not limited to warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Date: 2010-04-02 - */ - -#ifndef _MSC_VER -#error This header should only be used with Microsoft compilers -#endif - -#ifndef _STDINT_H -#define _STDINT_H - -#ifndef _INTPTR_T_DEFINED -#define _INTPTR_T_DEFINED -#ifndef __intptr_t_defined -#define __intptr_t_defined -#undef intptr_t -#ifdef _WIN64 - typedef __int64 intptr_t; -#else - typedef int intptr_t; -#endif /* _WIN64 */ -#endif /* __intptr_t_defined */ -#endif /* _INTPTR_T_DEFINED */ - -#ifndef _UINTPTR_T_DEFINED -#define _UINTPTR_T_DEFINED -#ifndef __uintptr_t_defined -#define __uintptr_t_defined -#undef uintptr_t -#ifdef _WIN64 - typedef unsigned __int64 uintptr_t; -#else - typedef unsigned int uintptr_t; -#endif /* _WIN64 */ -#endif /* __uintptr_t_defined */ -#endif /* _UINTPTR_T_DEFINED */ - -#ifndef _PTRDIFF_T_DEFINED -#define _PTRDIFF_T_DEFINED -#ifndef _PTRDIFF_T_ -#define _PTRDIFF_T_ -#undef ptrdiff_t -#ifdef _WIN64 - typedef __int64 ptrdiff_t; -#else - typedef int ptrdiff_t; -#endif /* _WIN64 */ -#endif /* _PTRDIFF_T_ */ -#endif /* _PTRDIFF_T_DEFINED */ - -#ifndef _WCHAR_T_DEFINED -#define _WCHAR_T_DEFINED -#ifndef __cplusplus - typedef unsigned short wchar_t; -#endif /* C++ */ -#endif /* _WCHAR_T_DEFINED */ - -#ifndef _WCTYPE_T_DEFINED -#define _WCTYPE_T_DEFINED -#ifndef _WINT_T -#define _WINT_T - typedef unsigned short wint_t; - typedef unsigned short wctype_t; -#endif /* _WINT_T */ -#endif /* _WCTYPE_T_DEFINED */ - -/* 7.18.1.1 Exact-width integer types */ -typedef __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; - -/* 7.18.1.2 Minimum-width integer types */ -typedef signed char int_least8_t; -typedef unsigned char uint_least8_t; -typedef short int_least16_t; -typedef unsigned short uint_least16_t; -typedef int int_least32_t; -typedef unsigned uint_least32_t; -typedef __int64 int_least64_t; -typedef unsigned __int64 uint_least64_t; - -/* 7.18.1.3 Fastest minimum-width integer types - * Not actually guaranteed to be fastest for all purposes - * Here we use the exact-width types for 8 and 16-bit ints. - */ -typedef __int8 int_fast8_t; -typedef unsigned __int8 uint_fast8_t; -typedef __int16 int_fast16_t; -typedef unsigned __int16 uint_fast16_t; -typedef __int32 int_fast32_t; -typedef unsigned __int32 uint_fast32_t; -typedef __int64 int_fast64_t; -typedef unsigned __int64 uint_fast64_t; - -/* 7.18.1.5 Greatest-width integer types */ -typedef __int64 intmax_t; -typedef unsigned __int64 uintmax_t; - -/* 7.18.2 Limits of specified-width integer types */ - -/* 7.18.2.1 Limits of exact-width integer types */ -#define INT8_MIN (-128) -#define INT16_MIN (-32768) -#define INT32_MIN (-2147483647 - 1) -#define INT64_MIN (-9223372036854775807LL - 1) - -#define INT8_MAX 127 -#define INT16_MAX 32767 -#define INT32_MAX 2147483647 -#define INT64_MAX 9223372036854775807LL - -#define UINT8_MAX 255 -#define UINT16_MAX 65535 -#define UINT32_MAX 0xffffffffU /* 4294967295U */ -#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ - -/* 7.18.2.2 Limits of minimum-width integer types */ -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST64_MIN INT64_MIN - -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MAX INT64_MAX - -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -/* 7.18.2.3 Limits of fastest minimum-width integer types */ -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST64_MIN INT64_MIN - -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -/* 7.18.2.4 Limits of integer types capable of holding - object pointers */ -#ifdef _WIN64 -#define INTPTR_MIN INT64_MIN -#define INTPTR_MAX INT64_MAX -#define UINTPTR_MAX UINT64_MAX -#else -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#endif - -/* 7.18.2.5 Limits of greatest-width integer types */ -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -/* 7.18.3 Limits of other integer types */ -#ifdef _WIN64 -#define PTRDIFF_MIN INT64_MIN -#define PTRDIFF_MAX INT64_MAX -#else -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX -#endif - -#define SIG_ATOMIC_MIN INT32_MIN -#define SIG_ATOMIC_MAX INT32_MAX - -#ifndef SIZE_MAX -#ifdef _WIN64 -#define SIZE_MAX UINT64_MAX -#else -#define SIZE_MAX UINT32_MAX -#endif -#endif - -#ifndef WCHAR_MIN /* also in wchar.h */ -#define WCHAR_MIN 0U -#define WCHAR_MAX 0xffffU -#endif - -/* - * wint_t is unsigned short for compatibility with MS runtime - */ -#define WINT_MIN 0U -#define WINT_MAX 0xffffU - - -/* 7.18.4 Macros for integer constants */ - -/* 7.18.4.1 Macros for minimum-width integer constants - - Accoding to Douglas Gwyn : - "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC - 9899:1999 as initially published, the expansion was required - to be an integer constant of precisely matching type, which - is impossible to accomplish for the shorter types on most - platforms, because C99 provides no standard way to designate - an integer constant with width less than that of type int. - TC1 changed this to require just an integer constant - *expression* with *promoted* type." - - The trick used here is from Clive D W Feather. -*/ - -#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val)) -#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val)) -#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val)) -/* The 'trick' doesn't work in C89 for long long because, without - suffix, (val) will be evaluated as int, not intmax_t */ -#define INT64_C(val) val##i64 - -#define UINT8_C(val) (val) -#define UINT16_C(val) (val) -#define UINT32_C(val) (val##i32) -#define UINT64_C(val) val##ui64 - -/* 7.18.4.2 Macros for greatest-width integer constants */ -#define INTMAX_C(val) val##i64 -#define UINTMAX_C(val) val##ui64 - -#endif diff --git a/dependencies/libusb-1.0.22/examples/source/testlibusb.c b/dependencies/libusb-1.0.22/examples/source/testlibusb.c deleted file mode 100644 index f844aaf8..00000000 --- a/dependencies/libusb-1.0.22/examples/source/testlibusb.c +++ /dev/null @@ -1,277 +0,0 @@ -/* -* Test suite program based of libusb-0.1-compat testlibusb -* Copyright (c) 2013 Nathan Hjelm -* -* 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 -#include -#include "libusb.h" - -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define snprintf _snprintf -#endif - -int verbose = 0; - -static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp) -{ - printf(" USB 3.0 Endpoint Companion:\n"); - printf(" bMaxBurst: %d\n", ep_comp->bMaxBurst); - printf(" bmAttributes: 0x%02x\n", ep_comp->bmAttributes); - printf(" wBytesPerInterval: %d\n", ep_comp->wBytesPerInterval); -} - -static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint) -{ - int i, ret; - - printf(" Endpoint:\n"); - printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress); - printf(" bmAttributes: %02xh\n", endpoint->bmAttributes); - printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize); - printf(" bInterval: %d\n", endpoint->bInterval); - printf(" bRefresh: %d\n", endpoint->bRefresh); - printf(" bSynchAddress: %d\n", endpoint->bSynchAddress); - - for (i = 0; i < endpoint->extra_length;) { - if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) { - struct libusb_ss_endpoint_companion_descriptor *ep_comp; - - ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp); - if (LIBUSB_SUCCESS != ret) { - continue; - } - - print_endpoint_comp(ep_comp); - - libusb_free_ss_endpoint_companion_descriptor(ep_comp); - } - - i += endpoint->extra[i]; - } -} - -static void print_altsetting(const struct libusb_interface_descriptor *interface) -{ - uint8_t i; - - printf(" Interface:\n"); - printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber); - printf(" bAlternateSetting: %d\n", interface->bAlternateSetting); - printf(" bNumEndpoints: %d\n", interface->bNumEndpoints); - printf(" bInterfaceClass: %d\n", interface->bInterfaceClass); - printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass); - printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol); - printf(" iInterface: %d\n", interface->iInterface); - - for (i = 0; i < interface->bNumEndpoints; i++) - print_endpoint(&interface->endpoint[i]); -} - -static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap) -{ - printf(" USB 2.0 Extension Capabilities:\n"); - printf(" bDevCapabilityType: %d\n", usb_2_0_ext_cap->bDevCapabilityType); - printf(" bmAttributes: 0x%x\n", usb_2_0_ext_cap->bmAttributes); -} - -static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap) -{ - printf(" USB 3.0 Capabilities:\n"); - printf(" bDevCapabilityType: %d\n", ss_usb_cap->bDevCapabilityType); - printf(" bmAttributes: 0x%x\n", ss_usb_cap->bmAttributes); - printf(" wSpeedSupported: 0x%x\n", ss_usb_cap->wSpeedSupported); - printf(" bFunctionalitySupport: %d\n", ss_usb_cap->bFunctionalitySupport); - printf(" bU1devExitLat: %d\n", ss_usb_cap->bU1DevExitLat); - printf(" bU2devExitLat: %d\n", ss_usb_cap->bU2DevExitLat); -} - -static void print_bos(libusb_device_handle *handle) -{ - struct libusb_bos_descriptor *bos; - int ret; - - ret = libusb_get_bos_descriptor(handle, &bos); - if (0 > ret) { - return; - } - - printf(" Binary Object Store (BOS):\n"); - printf(" wTotalLength: %d\n", bos->wTotalLength); - printf(" bNumDeviceCaps: %d\n", bos->bNumDeviceCaps); - - if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) { - - struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension; - ret = libusb_get_usb_2_0_extension_descriptor(NULL, bos->dev_capability[0],&usb_2_0_extension); - if (0 > ret) { - return; - } - - print_2_0_ext_cap(usb_2_0_extension); - libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension); - } - - if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) { - - struct libusb_ss_usb_device_capability_descriptor *dev_cap; - ret = libusb_get_ss_usb_device_capability_descriptor(NULL, bos->dev_capability[0],&dev_cap); - if (0 > ret) { - return; - } - - print_ss_usb_cap(dev_cap); - libusb_free_ss_usb_device_capability_descriptor(dev_cap); - } - - libusb_free_bos_descriptor(bos); -} - -static void print_interface(const struct libusb_interface *interface) -{ - int i; - - for (i = 0; i < interface->num_altsetting; i++) - print_altsetting(&interface->altsetting[i]); -} - -static void print_configuration(struct libusb_config_descriptor *config) -{ - uint8_t i; - - printf(" Configuration:\n"); - printf(" wTotalLength: %d\n", config->wTotalLength); - printf(" bNumInterfaces: %d\n", config->bNumInterfaces); - printf(" bConfigurationValue: %d\n", config->bConfigurationValue); - printf(" iConfiguration: %d\n", config->iConfiguration); - printf(" bmAttributes: %02xh\n", config->bmAttributes); - printf(" MaxPower: %d\n", config->MaxPower); - - for (i = 0; i < config->bNumInterfaces; i++) - print_interface(&config->interface[i]); -} - -static int print_device(libusb_device *dev, int level) -{ - struct libusb_device_descriptor desc; - libusb_device_handle *handle = NULL; - char description[256]; - char string[256]; - int ret; - uint8_t i; - - ret = libusb_get_device_descriptor(dev, &desc); - if (ret < 0) { - fprintf(stderr, "failed to get device descriptor"); - return -1; - } - - ret = libusb_open(dev, &handle); - if (LIBUSB_SUCCESS == ret) { - if (desc.iManufacturer) { - ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string)); - if (ret > 0) - snprintf(description, sizeof(description), "%s - ", string); - else - snprintf(description, sizeof(description), "%04X - ", - desc.idVendor); - } - else - snprintf(description, sizeof(description), "%04X - ", - desc.idVendor); - - if (desc.iProduct) { - ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string)); - if (ret > 0) - snprintf(description + strlen(description), sizeof(description) - - strlen(description), "%s", string); - else - snprintf(description + strlen(description), sizeof(description) - - strlen(description), "%04X", desc.idProduct); - } - else - snprintf(description + strlen(description), sizeof(description) - - strlen(description), "%04X", desc.idProduct); - } - else { - snprintf(description, sizeof(description), "%04X - %04X", - desc.idVendor, desc.idProduct); - } - - printf("%.*sDev (bus %d, device %d): %s\n", level * 2, " ", - libusb_get_bus_number(dev), libusb_get_device_address(dev), description); - - if (handle && verbose) { - if (desc.iSerialNumber) { - ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string)); - if (ret > 0) - printf("%.*s - Serial Number: %s\n", level * 2, - " ", string); - } - } - - if (verbose) { - for (i = 0; i < desc.bNumConfigurations; i++) { - struct libusb_config_descriptor *config; - ret = libusb_get_config_descriptor(dev, i, &config); - if (LIBUSB_SUCCESS != ret) { - printf(" Couldn't retrieve descriptors\n"); - continue; - } - - print_configuration(config); - - libusb_free_config_descriptor(config); - } - - if (handle && desc.bcdUSB >= 0x0201) { - print_bos(handle); - } - } - - if (handle) - libusb_close(handle); - - return 0; -} - -int main(int argc, char *argv[]) -{ - libusb_device **devs; - ssize_t cnt; - int r, i; - - if (argc > 1 && !strcmp(argv[1], "-v")) - verbose = 1; - - r = libusb_init(NULL); - if (r < 0) - return r; - - cnt = libusb_get_device_list(NULL, &devs); - if (cnt < 0) - return (int)cnt; - - for (i = 0; devs[i]; ++i) { - print_device(devs[i], 0); - } - - libusb_free_device_list(devs, 1); - - libusb_exit(NULL); - return 0; -} diff --git a/dependencies/libusb-1.0.27/MinGW32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/MinGW32/dll/libusb-1.0.dll new file mode 100644 index 00000000..034520ab Binary files /dev/null and b/dependencies/libusb-1.0.27/MinGW32/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/MinGW64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/MinGW64/dll/libusb-1.0.dll new file mode 100644 index 00000000..4f8ecc0f Binary files /dev/null and b/dependencies/libusb-1.0.27/MinGW64/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.22/README.txt b/dependencies/libusb-1.0.27/README.txt similarity index 71% rename from dependencies/libusb-1.0.22/README.txt rename to dependencies/libusb-1.0.27/README.txt index 2ad83959..da87bf54 100644 --- a/dependencies/libusb-1.0.22/README.txt +++ b/dependencies/libusb-1.0.27/README.txt @@ -1,9 +1,12 @@ - libusb 1.0 Windows binary snapshot - README + libusb 1.0 Windows binaries - README - ********************************************************************* - * The latest version of this snapshot can always be downloaded at: * - * https://sourceforge.net/projects/libusb/files/ * - ********************************************************************* + ***************************************************************** + * The latest version can always be downloaded at: * + * https://github.com/libusb/libusb/releases * + ***************************************************************** + +Note: Binaries are provided as-is and may not work for your toolchain. +In that case, please build libusb from source using your own toolchain. o Visual Studio: - Open existing or create a new project for your application @@ -24,24 +27,6 @@ o Visual Studio: remember that you need to have a copy of the DLL either in the runtime directory or in system32 -o WDK/DDK: - - The following is an example of a sources files that you can use to compile - a libusb 1.0 based console application. In this sample ..\libusb\ is the - directory where you would have copied libusb.h as well as the relevant - libusb-1.0.lib - - TARGETNAME=your_app - TARGETTYPE=PROGRAM - USE_MSVCRT=1 - UMTYPE=console - INCLUDES=..\libusb;$(DDK_INC_PATH) - TARGETLIBS=..\libusb\libusb-1.0.lib - SOURCES=your_app.c - - - Note that if you plan to use libCMT instead of MSVCRT (USE_LIBCMT=1 instead - of USE_MSVCRT=1), you will need to recompile libusb to use libCMT. This can - easily be achieved, in the DDK environment, by running 'ddk_build /MT' - o MinGW/cygwin - Copy libusb.h, from include/libusb-1.0/ to your default include directory, and copy the MinGW32/ or MinGW64/ .a files to your default library directory. @@ -55,6 +40,9 @@ o Additional information: - For some libusb samples (including source), please have a look in examples/ - For additional information on the libusb 1.0 Windows backend please visit: http://windows.libusb.info + - Using the UsbDk backend is now a run-time choice rather than a compile-time + choice. For additional information, including example usage, please visit: + http://windows.libusb.info/#Driver_Installation - The MinGW and MS generated DLLs are fully interchangeable, provided that you use the import libs provided or generate one from the .def also provided. - If you find any issue, please visit http://libusb.info/ and check the diff --git a/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.dll new file mode 100644 index 00000000..0b81c48a Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.exp new file mode 100644 index 00000000..b90cec1e Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.lib new file mode 100644 index 00000000..4a34d5f1 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS32/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2013/MS32/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2013/MS32/static/libusb-1.0.lib new file mode 100644 index 00000000..5f9da433 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS32/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.dll new file mode 100644 index 00000000..7ae7da61 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.exp new file mode 100644 index 00000000..e982175c Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.lib new file mode 100644 index 00000000..461b176c Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS64/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2013/MS64/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2013/MS64/static/libusb-1.0.lib new file mode 100644 index 00000000..2c15733d Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2013/MS64/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.dll new file mode 100644 index 00000000..7d982843 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.exp new file mode 100644 index 00000000..455e1b5f Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.lib new file mode 100644 index 00000000..cd531a5d Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS32/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS32/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2015/MS32/static/libusb-1.0.lib new file mode 100644 index 00000000..d03b56fb Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS32/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.dll new file mode 100644 index 00000000..a354dcde Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.exp new file mode 100644 index 00000000..1242290c Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.lib new file mode 100644 index 00000000..6e319ee3 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS64/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2015/MS64/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2015/MS64/static/libusb-1.0.lib new file mode 100644 index 00000000..ea673c6c Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2015/MS64/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.dll new file mode 100644 index 00000000..e6cac174 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.exp new file mode 100644 index 00000000..5eb3e89c Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.lib new file mode 100644 index 00000000..8cc08d31 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS32/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS32/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2017/MS32/static/libusb-1.0.lib new file mode 100644 index 00000000..fb2955fb Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS32/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.dll new file mode 100644 index 00000000..b439bfbf Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.exp new file mode 100644 index 00000000..4aeda0ad Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.lib new file mode 100644 index 00000000..4959fb6c Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS64/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2017/MS64/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2017/MS64/static/libusb-1.0.lib new file mode 100644 index 00000000..13d1e47b Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2017/MS64/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.dll new file mode 100644 index 00000000..784e6578 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.exp new file mode 100644 index 00000000..6bac15df Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.lib new file mode 100644 index 00000000..7a02a3d6 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS32/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS32/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2019/MS32/static/libusb-1.0.lib new file mode 100644 index 00000000..e52d86ff Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS32/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.dll new file mode 100644 index 00000000..0ad0e25b Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.exp new file mode 100644 index 00000000..4b1a79e2 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.lib new file mode 100644 index 00000000..e08fb6b7 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS64/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2019/MS64/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2019/MS64/static/libusb-1.0.lib new file mode 100644 index 00000000..c481bcd6 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2019/MS64/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.dll new file mode 100644 index 00000000..1f334c2b Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.exp new file mode 100644 index 00000000..f35c2750 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.lib new file mode 100644 index 00000000..12b8eb3d Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS32/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS32/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2022/MS32/static/libusb-1.0.lib new file mode 100644 index 00000000..4055ba7e Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS32/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.dll b/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.dll new file mode 100644 index 00000000..4cc14220 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.dll differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.exp b/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.exp new file mode 100644 index 00000000..50bb1e6a Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.exp differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.lib new file mode 100644 index 00000000..2e3d87e0 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS64/dll/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/VS2022/MS64/static/libusb-1.0.lib b/dependencies/libusb-1.0.27/VS2022/MS64/static/libusb-1.0.lib new file mode 100644 index 00000000..60129249 Binary files /dev/null and b/dependencies/libusb-1.0.27/VS2022/MS64/static/libusb-1.0.lib differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/dpfp.exe b/dependencies/libusb-1.0.27/examples/bin32/dpfp.exe new file mode 100644 index 00000000..c89ce7c4 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/dpfp.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/dpfp_threaded.exe b/dependencies/libusb-1.0.27/examples/bin32/dpfp_threaded.exe new file mode 100644 index 00000000..95ea65b0 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/dpfp_threaded.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/fxload.exe b/dependencies/libusb-1.0.27/examples/bin32/fxload.exe new file mode 100644 index 00000000..42923b40 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/fxload.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/hotplugtest.exe b/dependencies/libusb-1.0.27/examples/bin32/hotplugtest.exe new file mode 100644 index 00000000..525c4092 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/hotplugtest.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/init_context.exe b/dependencies/libusb-1.0.27/examples/bin32/init_context.exe new file mode 100644 index 00000000..ad55a19f Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/init_context.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/listdevs.exe b/dependencies/libusb-1.0.27/examples/bin32/listdevs.exe new file mode 100644 index 00000000..0c2911f3 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/listdevs.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/sam3u_benchmark.exe b/dependencies/libusb-1.0.27/examples/bin32/sam3u_benchmark.exe new file mode 100644 index 00000000..edb6e0aa Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/sam3u_benchmark.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/set_option.exe b/dependencies/libusb-1.0.27/examples/bin32/set_option.exe new file mode 100644 index 00000000..629be763 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/set_option.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/stress.exe b/dependencies/libusb-1.0.27/examples/bin32/stress.exe new file mode 100644 index 00000000..c8f000d1 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/stress.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/stress_mt.exe b/dependencies/libusb-1.0.27/examples/bin32/stress_mt.exe new file mode 100644 index 00000000..435eb5ee Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/stress_mt.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/testlibusb.exe b/dependencies/libusb-1.0.27/examples/bin32/testlibusb.exe new file mode 100644 index 00000000..fc51afce Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/testlibusb.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin32/xusb.exe b/dependencies/libusb-1.0.27/examples/bin32/xusb.exe new file mode 100644 index 00000000..dc652750 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin32/xusb.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/dpfp.exe b/dependencies/libusb-1.0.27/examples/bin64/dpfp.exe new file mode 100644 index 00000000..bfc91199 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/dpfp.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/dpfp_threaded.exe b/dependencies/libusb-1.0.27/examples/bin64/dpfp_threaded.exe new file mode 100644 index 00000000..b4336177 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/dpfp_threaded.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/fxload.exe b/dependencies/libusb-1.0.27/examples/bin64/fxload.exe new file mode 100644 index 00000000..22b005c8 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/fxload.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/hotplugtest.exe b/dependencies/libusb-1.0.27/examples/bin64/hotplugtest.exe new file mode 100644 index 00000000..b0cd01ce Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/hotplugtest.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/init_context.exe b/dependencies/libusb-1.0.27/examples/bin64/init_context.exe new file mode 100644 index 00000000..b1184457 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/init_context.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/listdevs.exe b/dependencies/libusb-1.0.27/examples/bin64/listdevs.exe new file mode 100644 index 00000000..8ab981b0 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/listdevs.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/sam3u_benchmark.exe b/dependencies/libusb-1.0.27/examples/bin64/sam3u_benchmark.exe new file mode 100644 index 00000000..7066086d Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/sam3u_benchmark.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/set_option.exe b/dependencies/libusb-1.0.27/examples/bin64/set_option.exe new file mode 100644 index 00000000..ad009061 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/set_option.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/stress.exe b/dependencies/libusb-1.0.27/examples/bin64/stress.exe new file mode 100644 index 00000000..26f6e589 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/stress.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/stress_mt.exe b/dependencies/libusb-1.0.27/examples/bin64/stress_mt.exe new file mode 100644 index 00000000..a2d3c409 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/stress_mt.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/testlibusb.exe b/dependencies/libusb-1.0.27/examples/bin64/testlibusb.exe new file mode 100644 index 00000000..9b8d03ee Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/testlibusb.exe differ diff --git a/dependencies/libusb-1.0.27/examples/bin64/xusb.exe b/dependencies/libusb-1.0.27/examples/bin64/xusb.exe new file mode 100644 index 00000000..0cd01f86 Binary files /dev/null and b/dependencies/libusb-1.0.27/examples/bin64/xusb.exe differ diff --git a/dependencies/libusb-1.0.27/examples/source/dpfp.c b/dependencies/libusb-1.0.27/examples/source/dpfp.c new file mode 100644 index 00000000..2949383a --- /dev/null +++ b/dependencies/libusb-1.0.27/examples/source/dpfp.c @@ -0,0 +1,711 @@ +/* + * libusb example program to manipulate U.are.U 4000B fingerprint scanner. + * Copyright © 2007 Daniel Drake + * Copyright © 2016 Nathan Hjelm + * Copyright © 2020 Chris Dickens + * + * Basic image capture program only, does not consider the powerup quirks or + * the fact that image encryption may be enabled. Not expected to work + * flawlessly all of the time. + * + * 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 + +#include +#include +#include +#include +#include + +#include "libusb.h" + +#if defined(_MSC_VER) +#define snprintf _snprintf +#endif + +#if defined(DPFP_THREADED) +#if defined(PLATFORM_POSIX) +#include +#include +#include +#include + +#define THREAD_RETURN_VALUE NULL +typedef sem_t * semaphore_t; +typedef pthread_t thread_t; + +static inline semaphore_t semaphore_create(void) +{ + sem_t *semaphore; + char name[50]; + + snprintf(name, sizeof(name), "/org.libusb.example.dpfp_threaded:%d", (int)getpid()); + semaphore = sem_open(name, O_CREAT | O_EXCL, 0, 0); + if (semaphore == SEM_FAILED) + return NULL; + /* Remove semaphore so that it does not persist after process exits */ + (void)sem_unlink(name); + return semaphore; +} + +static inline void semaphore_give(semaphore_t semaphore) +{ + (void)sem_post(semaphore); +} + +static inline void semaphore_take(semaphore_t semaphore) +{ + (void)sem_wait(semaphore); +} + +static inline void semaphore_destroy(semaphore_t semaphore) +{ + (void)sem_close(semaphore); +} + +static inline int thread_create(thread_t *thread, + void *(*thread_entry)(void *arg), void *arg) +{ + return pthread_create(thread, NULL, thread_entry, arg) == 0 ? 0 : -1; +} + +static inline void thread_join(thread_t thread) +{ + (void)pthread_join(thread, NULL); +} +#elif defined(PLATFORM_WINDOWS) +#define THREAD_RETURN_VALUE 0 +typedef HANDLE semaphore_t; +typedef HANDLE thread_t; + +#if defined(__CYGWIN__) +typedef DWORD thread_return_t; +#else +#include +typedef unsigned thread_return_t; +#endif + +static inline semaphore_t semaphore_create(void) +{ + return CreateSemaphore(NULL, 0, 1, NULL); +} + +static inline void semaphore_give(semaphore_t semaphore) +{ + (void)ReleaseSemaphore(semaphore, 1, NULL); +} + +static inline void semaphore_take(semaphore_t semaphore) +{ + (void)WaitForSingleObject(semaphore, INFINITE); +} + +static inline void semaphore_destroy(semaphore_t semaphore) +{ + (void)CloseHandle(semaphore); +} + +static inline int thread_create(thread_t *thread, + thread_return_t (__stdcall *thread_entry)(void *arg), void *arg) +{ +#if defined(__CYGWIN__) + *thread = CreateThread(NULL, 0, thread_entry, arg, 0, NULL); +#else + *thread = (HANDLE)_beginthreadex(NULL, 0, thread_entry, arg, 0, NULL); +#endif + return *thread != NULL ? 0 : -1; +} + +static inline void thread_join(thread_t thread) +{ + (void)WaitForSingleObject(thread, INFINITE); + (void)CloseHandle(thread); +} +#endif +#endif + +#define EP_INTR (1 | LIBUSB_ENDPOINT_IN) +#define EP_DATA (2 | LIBUSB_ENDPOINT_IN) +#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN) +#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT) +#define USB_RQ 0x04 +#define INTR_LENGTH 64 + +enum { + MODE_INIT = 0x00, + MODE_AWAIT_FINGER_ON = 0x10, + MODE_AWAIT_FINGER_OFF = 0x12, + MODE_CAPTURE = 0x20, + MODE_SHUT_UP = 0x30, + MODE_READY = 0x80, +}; + +static int next_state(void); + +enum { + STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON = 1, + STATE_AWAIT_IRQ_FINGER_DETECTED, + STATE_AWAIT_MODE_CHANGE_CAPTURE, + STATE_AWAIT_IMAGE, + STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF, + STATE_AWAIT_IRQ_FINGER_REMOVED, +}; + +static int state = 0; +static libusb_device_handle *devh = NULL; +static unsigned char imgbuf[0x1b340]; +static unsigned char irqbuf[INTR_LENGTH]; +static struct libusb_transfer *img_transfer = NULL; +static struct libusb_transfer *irq_transfer = NULL; +static int img_idx = 0; +static volatile sig_atomic_t do_exit = 0; + +#if defined(DPFP_THREADED) +static semaphore_t exit_semaphore; +static thread_t poll_thread; +#endif + +static void request_exit(sig_atomic_t code) +{ + do_exit = code; +#if defined(DPFP_THREADED) + semaphore_give(exit_semaphore); +#endif +} + +#if defined(DPFP_THREADED) +#if defined(PLATFORM_POSIX) +static void *poll_thread_main(void *arg) +#elif defined(PLATFORM_WINDOWS) +static thread_return_t __stdcall poll_thread_main(void *arg) +#endif +{ + (void)arg; + + printf("poll thread running\n"); + + while (!do_exit) { + struct timeval tv = { 1, 0 }; + int r; + + r = libusb_handle_events_timeout(NULL, &tv); + if (r < 0) { + request_exit(2); + break; + } + } + + printf("poll thread shutting down\n"); + return THREAD_RETURN_VALUE; +} +#endif + +static int find_dpfp_device(void) +{ + devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a); + if (!devh) { + errno = ENODEV; + return -1; + } + return 0; +} + +static int print_f0_data(void) +{ + unsigned char data[0x10]; + size_t i; + int r; + + r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0xf0, 0, data, + sizeof(data), 0); + if (r < 0) { + fprintf(stderr, "F0 error %d\n", r); + return r; + } + if (r < (int)sizeof(data)) { + fprintf(stderr, "short read (%d)\n", r); + return -1; + } + + printf("F0 data:"); + for (i = 0; i < sizeof(data); i++) + printf(" %02x", data[i]); + printf("\n"); + return 0; +} + +static int get_hwstat(unsigned char *status) +{ + int r; + + r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0x07, 0, status, 1, 0); + if (r < 0) { + fprintf(stderr, "read hwstat error %d\n", r); + return r; + } + if (r < 1) { + fprintf(stderr, "short read (%d)\n", r); + return -1; + } + + printf("hwstat reads %02x\n", *status); + return 0; +} + +static int set_hwstat(unsigned char data) +{ + int r; + + printf("set hwstat to %02x\n", data); + r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x07, 0, &data, 1, 0); + if (r < 0) { + fprintf(stderr, "set hwstat error %d\n", r); + return r; + } + if (r < 1) { + fprintf(stderr, "short write (%d)\n", r); + return -1; + } + + return 0; +} + +static int set_mode(unsigned char data) +{ + int r; + + printf("set mode %02x\n", data); + r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x4e, 0, &data, 1, 0); + if (r < 0) { + fprintf(stderr, "set mode error %d\n", r); + return r; + } + if (r < 1) { + fprintf(stderr, "short write (%d)\n", r); + return -1; + } + + return 0; +} + +static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer) +{ + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fprintf(stderr, "mode change transfer not completed!\n"); + request_exit(2); + } + + printf("async cb_mode_changed length=%d actual_length=%d\n", + transfer->length, transfer->actual_length); + if (next_state() < 0) + request_exit(2); +} + +static int set_mode_async(unsigned char data) +{ + unsigned char *buf = malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); + struct libusb_transfer *transfer; + + if (!buf) { + errno = ENOMEM; + return -1; + } + + transfer = libusb_alloc_transfer(0); + if (!transfer) { + free(buf); + errno = ENOMEM; + return -1; + } + + printf("async set mode %02x\n", data); + libusb_fill_control_setup(buf, CTRL_OUT, USB_RQ, 0x4e, 0, 1); + buf[LIBUSB_CONTROL_SETUP_SIZE] = data; + libusb_fill_control_transfer(transfer, devh, buf, cb_mode_changed, NULL, + 1000); + + transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK + | LIBUSB_TRANSFER_FREE_BUFFER | LIBUSB_TRANSFER_FREE_TRANSFER; + return libusb_submit_transfer(transfer); +} + +static int do_sync_intr(unsigned char *data) +{ + int r; + int transferred; + + r = libusb_interrupt_transfer(devh, EP_INTR, data, INTR_LENGTH, + &transferred, 1000); + if (r < 0) { + fprintf(stderr, "intr error %d\n", r); + return r; + } + if (transferred < INTR_LENGTH) { + fprintf(stderr, "short read (%d)\n", r); + return -1; + } + + printf("recv interrupt %04x\n", *((uint16_t *)data)); + return 0; +} + +static int sync_intr(unsigned char type) +{ + int r; + unsigned char data[INTR_LENGTH]; + + while (1) { + r = do_sync_intr(data); + if (r < 0) + return r; + if (data[0] == type) + return 0; + } +} + +static int save_to_file(unsigned char *data) +{ + FILE *f; + char filename[64]; + + snprintf(filename, sizeof(filename), "finger%d.pgm", img_idx++); + f = fopen(filename, "w"); + if (!f) + return -1; + + fputs("P5 384 289 255 ", f); + (void)fwrite(data + 64, 1, 384*289, f); + fclose(f); + printf("saved image to %s\n", filename); + return 0; +} + +static int next_state(void) +{ + int r = 0; + + printf("old state: %d\n", state); + switch (state) { + case STATE_AWAIT_IRQ_FINGER_REMOVED: + state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON; + r = set_mode_async(MODE_AWAIT_FINGER_ON); + break; + case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON: + state = STATE_AWAIT_IRQ_FINGER_DETECTED; + break; + case STATE_AWAIT_IRQ_FINGER_DETECTED: + state = STATE_AWAIT_MODE_CHANGE_CAPTURE; + r = set_mode_async(MODE_CAPTURE); + break; + case STATE_AWAIT_MODE_CHANGE_CAPTURE: + state = STATE_AWAIT_IMAGE; + break; + case STATE_AWAIT_IMAGE: + state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF; + r = set_mode_async(MODE_AWAIT_FINGER_OFF); + break; + case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF: + state = STATE_AWAIT_IRQ_FINGER_REMOVED; + break; + default: + printf("unrecognised state %d\n", state); + } + if (r < 0) { + fprintf(stderr, "error detected changing state\n"); + return r; + } + + printf("new state: %d\n", state); + return 0; +} + +static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer) +{ + unsigned char irqtype = transfer->buffer[0]; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fprintf(stderr, "irq transfer status %d?\n", transfer->status); + goto err_free_transfer; + } + + printf("IRQ callback %02x\n", irqtype); + switch (state) { + case STATE_AWAIT_IRQ_FINGER_DETECTED: + if (irqtype == 0x01) { + if (next_state() < 0) + goto err_free_transfer; + } else { + printf("finger-on-sensor detected in wrong state!\n"); + } + break; + case STATE_AWAIT_IRQ_FINGER_REMOVED: + if (irqtype == 0x02) { + if (next_state() < 0) + goto err_free_transfer; + } else { + printf("finger-on-sensor detected in wrong state!\n"); + } + break; + } + if (libusb_submit_transfer(irq_transfer) < 0) + goto err_free_transfer; + + return; + +err_free_transfer: + libusb_free_transfer(transfer); + irq_transfer = NULL; + request_exit(2); +} + +static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer) +{ + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fprintf(stderr, "img transfer status %d?\n", transfer->status); + goto err_free_transfer; + } + + printf("Image callback\n"); + save_to_file(imgbuf); + if (next_state() < 0) + goto err_free_transfer; + + if (libusb_submit_transfer(img_transfer) < 0) + goto err_free_transfer; + + return; + +err_free_transfer: + libusb_free_transfer(transfer); + img_transfer = NULL; + request_exit(2); +} + +static int init_capture(void) +{ + int r; + + r = libusb_submit_transfer(irq_transfer); + if (r < 0) + return r; + + r = libusb_submit_transfer(img_transfer); + if (r < 0) { + libusb_cancel_transfer(irq_transfer); + while (irq_transfer) + if (libusb_handle_events(NULL) < 0) + break; + return r; + } + + /* start state machine */ + state = STATE_AWAIT_IRQ_FINGER_REMOVED; + return next_state(); +} + +static int do_init(void) +{ + unsigned char status; + int r; + + r = get_hwstat(&status); + if (r < 0) + return r; + + if (!(status & 0x80)) { + r = set_hwstat(status | 0x80); + if (r < 0) + return r; + r = get_hwstat(&status); + if (r < 0) + return r; + } + + status &= ~0x80; + r = set_hwstat(status); + if (r < 0) + return r; + + r = get_hwstat(&status); + if (r < 0) + return r; + + r = sync_intr(0x56); + if (r < 0) + return r; + + return 0; +} + +static int alloc_transfers(void) +{ + img_transfer = libusb_alloc_transfer(0); + if (!img_transfer) { + errno = ENOMEM; + return -1; + } + + irq_transfer = libusb_alloc_transfer(0); + if (!irq_transfer) { + errno = ENOMEM; + return -1; + } + + libusb_fill_bulk_transfer(img_transfer, devh, EP_DATA, imgbuf, + sizeof(imgbuf), cb_img, NULL, 0); + libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR, irqbuf, + sizeof(irqbuf), cb_irq, NULL, 0); + + return 0; +} + +static void sighandler(int signum) +{ + (void)signum; + + request_exit(1); +} + +static void setup_signals(void) +{ +#if defined(PLATFORM_POSIX) + struct sigaction sigact; + + sigact.sa_handler = sighandler; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + (void)sigaction(SIGINT, &sigact, NULL); + (void)sigaction(SIGTERM, &sigact, NULL); + (void)sigaction(SIGQUIT, &sigact, NULL); +#else + (void)signal(SIGINT, sighandler); + (void)signal(SIGTERM, sighandler); +#endif +} + +int main(void) +{ + int r; + + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); + if (r < 0) { + fprintf(stderr, "failed to initialise libusb %d - %s\n", r, libusb_strerror(r)); + exit(1); + } + + r = find_dpfp_device(); + if (r < 0) { + fprintf(stderr, "Could not find/open device\n"); + goto out; + } + + r = libusb_claim_interface(devh, 0); + if (r < 0) { + fprintf(stderr, "claim interface error %d - %s\n", r, libusb_strerror(r)); + goto out; + } + printf("claimed interface\n"); + + r = print_f0_data(); + if (r < 0) + goto out_release; + + r = do_init(); + if (r < 0) + goto out_deinit; + + /* async from here onwards */ + setup_signals(); + + r = alloc_transfers(); + if (r < 0) + goto out_deinit; + +#if defined(DPFP_THREADED) + exit_semaphore = semaphore_create(); + if (!exit_semaphore) { + fprintf(stderr, "failed to initialise semaphore\n"); + goto out_deinit; + } + + r = thread_create(&poll_thread, poll_thread_main, NULL); + if (r) { + semaphore_destroy(exit_semaphore); + goto out_deinit; + } + + r = init_capture(); + if (r < 0) + request_exit(2); + + while (!do_exit) + semaphore_take(exit_semaphore); +#else + r = init_capture(); + if (r < 0) + goto out_deinit; + + while (!do_exit) { + r = libusb_handle_events(NULL); + if (r < 0) + request_exit(2); + } +#endif + + printf("shutting down...\n"); + +#if defined(DPFP_THREADED) + thread_join(poll_thread); + semaphore_destroy(exit_semaphore); +#endif + + if (img_transfer) { + r = libusb_cancel_transfer(img_transfer); + if (r < 0) + fprintf(stderr, "failed to cancel transfer %d - %s\n", r, libusb_strerror(r)); + } + + if (irq_transfer) { + r = libusb_cancel_transfer(irq_transfer); + if (r < 0) + fprintf(stderr, "failed to cancel transfer %d - %s\n", r, libusb_strerror(r)); + } + + while (img_transfer || irq_transfer) { + if (libusb_handle_events(NULL) < 0) + break; + } + + if (do_exit == 1) + r = 0; + else + r = 1; + +out_deinit: + if (img_transfer) + libusb_free_transfer(img_transfer); + if (irq_transfer) + libusb_free_transfer(irq_transfer); + set_mode(0); + set_hwstat(0x80); +out_release: + libusb_release_interface(devh, 0); +out: + libusb_close(devh); + libusb_exit(NULL); + return r >= 0 ? r : -r; +} diff --git a/dependencies/libusb-1.0.22/examples/source/ezusb.c b/dependencies/libusb-1.0.27/examples/source/ezusb.c similarity index 98% rename from dependencies/libusb-1.0.22/examples/source/ezusb.c rename to dependencies/libusb-1.0.27/examples/source/ezusb.c index e3b488d3..4bed12a4 100644 --- a/dependencies/libusb-1.0.22/examples/source/ezusb.c +++ b/dependencies/libusb-1.0.27/examples/source/ezusb.c @@ -20,6 +20,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ + +#include + #include #include #include @@ -29,9 +32,6 @@ #include "libusb.h" #include "ezusb.h" -extern void logerror(const char *format, ...) - __attribute__ ((format(printf, 1, 2))); - /* * This file contains functions for uploading firmware into Cypress * EZ-USB microcontrollers. These chips use control endpoint 0 and vendor @@ -139,7 +139,11 @@ static int ezusb_write(libusb_device_handle *device, const char *label, else logerror("%s ==> %d\n", label, status); } - return (status < 0) ? -EIO : 0; + if (status < 0) { + errno = EIO; + return -1; + } + return 0; } /* @@ -162,7 +166,11 @@ static int ezusb_read(libusb_device_handle *device, const char *label, else logerror("%s ==> %d\n", label, status); } - return (status < 0) ? -EIO : 0; + if (status < 0) { + errno = EIO; + return -1; + } + return 0; } /* @@ -195,7 +203,7 @@ static bool ezusb_cpucs(libusb_device_handle *device, uint32_t addr, bool doRun) } /* - * Send an FX3 jumpt to address command + * Send an FX3 jump to address command * Returns false on error. */ static bool ezusb_fx3_jump(libusb_device_handle *device, uint32_t addr) @@ -299,7 +307,7 @@ static int parse_ihex(FILE *image, void *context, /* Read the target offset (address up to 64KB) */ tmp = buf[7]; buf[7] = 0; - off = (int)strtoul(buf+3, NULL, 16); + off = (unsigned int)strtoul(buf+3, NULL, 16); buf[7] = tmp; /* Initialize data_addr */ @@ -514,7 +522,8 @@ static int ram_poke(void *context, uint32_t addr, bool external, if (external) { logerror("can't write %u bytes external memory at 0x%08x\n", (unsigned)len, addr); - return -EINVAL; + errno = EINVAL; + return -1; } break; case skip_internal: /* CPU must be running */ @@ -538,7 +547,8 @@ static int ram_poke(void *context, uint32_t addr, bool external, case _undef: default: logerror("bug\n"); - return -EDOM; + errno = EDOM; + return -1; } ctx->total += len; diff --git a/dependencies/libusb-1.0.22/examples/source/ezusb.h b/dependencies/libusb-1.0.27/examples/source/ezusb.h similarity index 93% rename from dependencies/libusb-1.0.22/examples/source/ezusb.h rename to dependencies/libusb-1.0.27/examples/source/ezusb.h index 129bc9af..62062c41 100644 --- a/dependencies/libusb-1.0.22/examples/source/ezusb.h +++ b/dependencies/libusb-1.0.27/examples/source/ezusb.h @@ -20,23 +20,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#if !defined(_MSC_VER) + +#include + #include -#else -#define __attribute__(x) -#if !defined(bool) -#define bool int -#endif -#if !defined(true) -#define true (1 == 1) -#endif -#if !defined(false) -#define false (!true) -#endif -#if defined(_PREFAST_) -#pragma warning(disable:28193) -#endif -#endif #define FX_TYPE_UNDEFINED -1 #define FX_TYPE_AN21 0 /* Original AnchorChips parts */ @@ -59,7 +46,7 @@ extern "C" { #endif -/* +/* * Automatically identified devices (VID, PID, type, designation). * TODO: Could use some validation. Also where's the FX2? */ @@ -113,6 +100,8 @@ extern int ezusb_load_eeprom(libusb_device_handle *device, /* Verbosity level (default 1). Can be increased or decreased with options v/q */ extern int verbose; +extern void logerror(const char *format, ...) PRINTF_FORMAT(1, 2); + #ifdef __cplusplus } #endif diff --git a/dependencies/libusb-1.0.22/examples/source/fxload.c b/dependencies/libusb-1.0.27/examples/source/fxload.c similarity index 97% rename from dependencies/libusb-1.0.22/examples/source/fxload.c rename to dependencies/libusb-1.0.27/examples/source/fxload.c index 1cea9c30..25260833 100644 --- a/dependencies/libusb-1.0.22/examples/source/fxload.c +++ b/dependencies/libusb-1.0.27/examples/source/fxload.c @@ -21,6 +21,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +#include + #include #include #include @@ -32,7 +34,7 @@ #include "libusb.h" #include "ezusb.h" -#if !defined(_WIN32) || defined(__CYGWIN__ ) +#if !defined(_WIN32) || defined(__CYGWIN__) #include static bool dosyslog = false; #include @@ -47,15 +49,12 @@ static bool dosyslog = false; #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) #endif -void logerror(const char *format, ...) - __attribute__ ((format (__printf__, 1, 2))); - void logerror(const char *format, ...) { va_list ap; va_start(ap, format); -#if !defined(_WIN32) || defined(__CYGWIN__ ) +#if !defined(_WIN32) || defined(__CYGWIN__) if (dosyslog) vsyslog(LOG_ERR, format, ap); else @@ -173,9 +172,9 @@ int main(int argc, char*argv[]) } /* open the device using libusb */ - status = libusb_init(NULL); + status = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (status < 0) { - logerror("libusb_init() failed: %s\n", libusb_error_name(status)); + logerror("libusb_init_context() failed: %s\n", libusb_error_name(status)); return -1; } libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, verbose); diff --git a/dependencies/libusb-1.0.27/examples/source/hotplugtest.c b/dependencies/libusb-1.0.27/examples/source/hotplugtest.c new file mode 100644 index 00000000..3e092cf4 --- /dev/null +++ b/dependencies/libusb-1.0.27/examples/source/hotplugtest.c @@ -0,0 +1,147 @@ +/* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */ +/* + * libusb example program for hotplug API + * Copyright © 2012-2013 Nathan Hjelm + * + * 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 +#include + +#include "libusb.h" + +int done = 0; +libusb_device_handle *handle = NULL; + +static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data) +{ + struct libusb_device_descriptor desc; + int rc; + + (void)ctx; + (void)dev; + (void)event; + (void)user_data; + + rc = libusb_get_device_descriptor(dev, &desc); + if (LIBUSB_SUCCESS == rc) { + printf ("Device attached: %04x:%04x\n", desc.idVendor, desc.idProduct); + } else { + printf ("Device attached\n"); + fprintf (stderr, "Error getting device descriptor: %s\n", + libusb_strerror((enum libusb_error)rc)); + } + + if (handle) { + libusb_close (handle); + handle = NULL; + } + + rc = libusb_open (dev, &handle); + if (LIBUSB_SUCCESS != rc) { + fprintf (stderr, "No access to device: %s\n", + libusb_strerror((enum libusb_error)rc)); + } + + done++; + + return 0; +} + +static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data) +{ + struct libusb_device_descriptor desc; + int rc; + + (void)ctx; + (void)dev; + (void)event; + (void)user_data; + + rc = libusb_get_device_descriptor(dev, &desc); + if (LIBUSB_SUCCESS == rc) { + printf ("Device detached: %04x:%04x\n", desc.idVendor, desc.idProduct); + } else { + printf ("Device detached\n"); + fprintf (stderr, "Error getting device descriptor: %s\n", + libusb_strerror((enum libusb_error)rc)); + } + + if (handle) { + libusb_close (handle); + handle = NULL; + } + + done++; + + return 0; +} + +int main(int argc, char *argv[]) +{ + libusb_hotplug_callback_handle hp[2]; + int product_id, vendor_id, class_id; + int rc; + + vendor_id = (argc > 1) ? (int)strtol (argv[1], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY; + product_id = (argc > 2) ? (int)strtol (argv[2], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY; + class_id = (argc > 3) ? (int)strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY; + + rc = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); + if (LIBUSB_SUCCESS != rc) + { + printf ("failed to initialise libusb: %s\n", + libusb_strerror((enum libusb_error)rc)); + return EXIT_FAILURE; + } + + if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) { + printf ("Hotplug capabilities are not supported on this platform\n"); + libusb_exit (NULL); + return EXIT_FAILURE; + } + + rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, vendor_id, + product_id, class_id, hotplug_callback, NULL, &hp[0]); + if (LIBUSB_SUCCESS != rc) { + fprintf (stderr, "Error registering callback 0\n"); + libusb_exit (NULL); + return EXIT_FAILURE; + } + + rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, vendor_id, + product_id,class_id, hotplug_callback_detach, NULL, &hp[1]); + if (LIBUSB_SUCCESS != rc) { + fprintf (stderr, "Error registering callback 1\n"); + libusb_exit (NULL); + return EXIT_FAILURE; + } + + while (done < 2) { + rc = libusb_handle_events (NULL); + if (LIBUSB_SUCCESS != rc) + printf ("libusb_handle_events() failed: %s\n", + libusb_strerror((enum libusb_error)rc)); + } + + if (handle) { + libusb_close (handle); + } + + libusb_exit (NULL); + + return EXIT_SUCCESS; +} diff --git a/dependencies/libusb-1.0.22/examples/source/listdevs.c b/dependencies/libusb-1.0.27/examples/source/listdevs.c similarity index 93% rename from dependencies/libusb-1.0.22/examples/source/listdevs.c rename to dependencies/libusb-1.0.27/examples/source/listdevs.c index 33289106..b5a9494c 100644 --- a/dependencies/libusb-1.0.22/examples/source/listdevs.c +++ b/dependencies/libusb-1.0.27/examples/source/listdevs.c @@ -55,13 +55,15 @@ int main(void) int r; ssize_t cnt; - r = libusb_init(NULL); + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (r < 0) return r; cnt = libusb_get_device_list(NULL, &devs); - if (cnt < 0) + if (cnt < 0){ + libusb_exit(NULL); return (int) cnt; + } print_devs(devs); libusb_free_device_list(devs, 1); diff --git a/dependencies/libusb-1.0.27/examples/source/sam3u_benchmark.c b/dependencies/libusb-1.0.27/examples/source/sam3u_benchmark.c new file mode 100644 index 00000000..ef7a669d --- /dev/null +++ b/dependencies/libusb-1.0.27/examples/source/sam3u_benchmark.c @@ -0,0 +1,228 @@ +/* + * libusb example program to measure Atmel SAM3U isochronous performance + * Copyright (C) 2012 Harald Welte + * + * Copied with the author's permission under LGPL-2.1 from + * http://git.gnumonks.org/cgi-bin/gitweb.cgi?p=sam3u-tests.git;a=blob;f=usb-benchmark-project/host/benchmark.c;h=74959f7ee88f1597286cd435f312a8ff52c56b7e + * + * An Atmel SAM3U test firmware is also available in the above repository. + * + * 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 + +#include +#include +#include +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#include + +#include "libusb.h" + +#define EP_DATA_IN 0x82 +#define EP_ISO_IN 0x86 + +static volatile sig_atomic_t do_exit = 0; +static struct libusb_device_handle *devh = NULL; + +static unsigned long num_bytes = 0, num_xfer = 0; +static struct timeval tv_start; + +static void get_timestamp(struct timeval *tv) +{ +#if defined(PLATFORM_WINDOWS) + static LARGE_INTEGER frequency; + LARGE_INTEGER counter; + + if (!frequency.QuadPart) + QueryPerformanceFrequency(&frequency); + + QueryPerformanceCounter(&counter); + counter.QuadPart *= 1000000; + counter.QuadPart /= frequency.QuadPart; + + tv->tv_sec = (long)(counter.QuadPart / 1000000ULL); + tv->tv_usec = (long)(counter.QuadPart % 1000000ULL); +#elif defined(HAVE_CLOCK_GETTIME) + struct timespec ts; + + (void)clock_gettime(CLOCK_MONOTONIC, &ts); + tv->tv_sec = ts.tv_sec; + tv->tv_usec = (int)(ts.tv_nsec / 1000L); +#else + gettimeofday(tv, NULL); +#endif +} + +static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr) +{ + int i; + + if (xfr->status != LIBUSB_TRANSFER_COMPLETED) { + fprintf(stderr, "transfer status %d\n", xfr->status); + libusb_free_transfer(xfr); + exit(3); + } + + if (xfr->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) { + for (i = 0; i < xfr->num_iso_packets; i++) { + struct libusb_iso_packet_descriptor *pack = &xfr->iso_packet_desc[i]; + + if (pack->status != LIBUSB_TRANSFER_COMPLETED) { + fprintf(stderr, "Error: pack %d status %d\n", i, pack->status); + exit(5); + } + + printf("pack%d length:%u, actual_length:%u\n", i, pack->length, pack->actual_length); + } + } + + printf("length:%u, actual_length:%u\n", xfr->length, xfr->actual_length); + for (i = 0; i < xfr->actual_length; i++) { + printf("%02x", xfr->buffer[i]); + if (i % 16) + printf("\n"); + else if (i % 8) + printf(" "); + else + printf(" "); + } + num_bytes += xfr->actual_length; + num_xfer++; + + if (libusb_submit_transfer(xfr) < 0) { + fprintf(stderr, "error re-submitting URB\n"); + exit(1); + } +} + +static int benchmark_in(uint8_t ep) +{ + static uint8_t buf[2048]; + static struct libusb_transfer *xfr; + int num_iso_pack = 0; + + if (ep == EP_ISO_IN) + num_iso_pack = 16; + + xfr = libusb_alloc_transfer(num_iso_pack); + if (!xfr) { + errno = ENOMEM; + return -1; + } + + if (ep == EP_ISO_IN) { + libusb_fill_iso_transfer(xfr, devh, ep, buf, + sizeof(buf), num_iso_pack, cb_xfr, NULL, 0); + libusb_set_iso_packet_lengths(xfr, sizeof(buf)/num_iso_pack); + } else + libusb_fill_bulk_transfer(xfr, devh, ep, buf, + sizeof(buf), cb_xfr, NULL, 0); + + get_timestamp(&tv_start); + + /* NOTE: To reach maximum possible performance the program must + * submit *multiple* transfers here, not just one. + * + * When only one transfer is submitted there is a gap in the bus + * schedule from when the transfer completes until a new transfer + * is submitted by the callback. This causes some jitter for + * isochronous transfers and loss of throughput for bulk transfers. + * + * This is avoided by queueing multiple transfers in advance, so + * that the host controller is always kept busy, and will schedule + * more transfers on the bus while the callback is running for + * transfers which have completed on the bus. + */ + + return libusb_submit_transfer(xfr); +} + +static void measure(void) +{ + struct timeval tv_stop; + unsigned long diff_msec; + + get_timestamp(&tv_stop); + + diff_msec = (tv_stop.tv_sec - tv_start.tv_sec) * 1000L; + diff_msec += (tv_stop.tv_usec - tv_start.tv_usec) / 1000L; + + printf("%lu transfers (total %lu bytes) in %lu milliseconds => %lu bytes/sec\n", + num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / diff_msec); +} + +static void sig_hdlr(int signum) +{ + (void)signum; + + measure(); + do_exit = 1; +} + +int main(void) +{ + int rc; + +#if defined(PLATFORM_POSIX) + struct sigaction sigact; + + sigact.sa_handler = sig_hdlr; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + (void)sigaction(SIGINT, &sigact, NULL); +#else + (void)signal(SIGINT, sig_hdlr); +#endif + + rc = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); + if (rc < 0) { + fprintf(stderr, "Error initializing libusb: %s\n", libusb_error_name(rc)); + exit(1); + } + + devh = libusb_open_device_with_vid_pid(NULL, 0x16c0, 0x0763); + if (!devh) { + fprintf(stderr, "Error finding USB device\n"); + goto out; + } + + rc = libusb_claim_interface(devh, 2); + if (rc < 0) { + fprintf(stderr, "Error claiming interface: %s\n", libusb_error_name(rc)); + goto out; + } + + benchmark_in(EP_ISO_IN); + + while (!do_exit) { + rc = libusb_handle_events(NULL); + if (rc != LIBUSB_SUCCESS) + break; + } + + /* Measurement has already been done by the signal handler. */ + + libusb_release_interface(devh, 2); +out: + if (devh) + libusb_close(devh); + libusb_exit(NULL); + return rc; +} diff --git a/dependencies/libusb-1.0.27/examples/source/testlibusb.c b/dependencies/libusb-1.0.27/examples/source/testlibusb.c new file mode 100644 index 00000000..394cec52 --- /dev/null +++ b/dependencies/libusb-1.0.27/examples/source/testlibusb.c @@ -0,0 +1,311 @@ +/* +* Test suite program based of libusb-0.1-compat testlibusb +* Copyright (c) 2013 Nathan Hjelm +* +* 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 +#include +#include "libusb.h" + +int verbose = 0; + +static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp) +{ + printf(" USB 3.0 Endpoint Companion:\n"); + printf(" bMaxBurst: %u\n", ep_comp->bMaxBurst); + printf(" bmAttributes: %02xh\n", ep_comp->bmAttributes); + printf(" wBytesPerInterval: %u\n", ep_comp->wBytesPerInterval); +} + +static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint) +{ + int i, ret; + + printf(" Endpoint:\n"); + printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress); + printf(" bmAttributes: %02xh\n", endpoint->bmAttributes); + printf(" wMaxPacketSize: %u\n", endpoint->wMaxPacketSize); + printf(" bInterval: %u\n", endpoint->bInterval); + printf(" bRefresh: %u\n", endpoint->bRefresh); + printf(" bSynchAddress: %u\n", endpoint->bSynchAddress); + + for (i = 0; i < endpoint->extra_length;) { + if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) { + struct libusb_ss_endpoint_companion_descriptor *ep_comp; + + ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp); + if (LIBUSB_SUCCESS != ret) + continue; + + print_endpoint_comp(ep_comp); + + libusb_free_ss_endpoint_companion_descriptor(ep_comp); + } + + i += endpoint->extra[i]; + } +} + +static void print_altsetting(const struct libusb_interface_descriptor *interface) +{ + uint8_t i; + + printf(" Interface:\n"); + printf(" bInterfaceNumber: %u\n", interface->bInterfaceNumber); + printf(" bAlternateSetting: %u\n", interface->bAlternateSetting); + printf(" bNumEndpoints: %u\n", interface->bNumEndpoints); + printf(" bInterfaceClass: %u\n", interface->bInterfaceClass); + printf(" bInterfaceSubClass: %u\n", interface->bInterfaceSubClass); + printf(" bInterfaceProtocol: %u\n", interface->bInterfaceProtocol); + printf(" iInterface: %u\n", interface->iInterface); + + for (i = 0; i < interface->bNumEndpoints; i++) + print_endpoint(&interface->endpoint[i]); +} + +static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap) +{ + printf(" USB 2.0 Extension Capabilities:\n"); + printf(" bDevCapabilityType: %u\n", usb_2_0_ext_cap->bDevCapabilityType); + printf(" bmAttributes: %08xh\n", usb_2_0_ext_cap->bmAttributes); +} + +static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap) +{ + printf(" USB 3.0 Capabilities:\n"); + printf(" bDevCapabilityType: %u\n", ss_usb_cap->bDevCapabilityType); + printf(" bmAttributes: %02xh\n", ss_usb_cap->bmAttributes); + printf(" wSpeedSupported: %u\n", ss_usb_cap->wSpeedSupported); + printf(" bFunctionalitySupport: %u\n", ss_usb_cap->bFunctionalitySupport); + printf(" bU1devExitLat: %u\n", ss_usb_cap->bU1DevExitLat); + printf(" bU2devExitLat: %u\n", ss_usb_cap->bU2DevExitLat); +} + +static void print_bos(libusb_device_handle *handle) +{ + struct libusb_bos_descriptor *bos; + uint8_t i; + int ret; + + ret = libusb_get_bos_descriptor(handle, &bos); + if (ret < 0) + return; + + printf(" Binary Object Store (BOS):\n"); + printf(" wTotalLength: %u\n", bos->wTotalLength); + printf(" bNumDeviceCaps: %u\n", bos->bNumDeviceCaps); + + for (i = 0; i < bos->bNumDeviceCaps; i++) { + struct libusb_bos_dev_capability_descriptor *dev_cap = bos->dev_capability[i]; + + if (dev_cap->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) { + struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension; + + ret = libusb_get_usb_2_0_extension_descriptor(NULL, dev_cap, &usb_2_0_extension); + if (ret < 0) + return; + + print_2_0_ext_cap(usb_2_0_extension); + libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension); + } else if (dev_cap->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) { + struct libusb_ss_usb_device_capability_descriptor *ss_dev_cap; + + ret = libusb_get_ss_usb_device_capability_descriptor(NULL, dev_cap, &ss_dev_cap); + if (ret < 0) + return; + + print_ss_usb_cap(ss_dev_cap); + libusb_free_ss_usb_device_capability_descriptor(ss_dev_cap); + } + } + + libusb_free_bos_descriptor(bos); +} + +static void print_interface(const struct libusb_interface *interface) +{ + int i; + + for (i = 0; i < interface->num_altsetting; i++) + print_altsetting(&interface->altsetting[i]); +} + +static void print_configuration(struct libusb_config_descriptor *config) +{ + uint8_t i; + + printf(" Configuration:\n"); + printf(" wTotalLength: %u\n", config->wTotalLength); + printf(" bNumInterfaces: %u\n", config->bNumInterfaces); + printf(" bConfigurationValue: %u\n", config->bConfigurationValue); + printf(" iConfiguration: %u\n", config->iConfiguration); + printf(" bmAttributes: %02xh\n", config->bmAttributes); + printf(" MaxPower: %u\n", config->MaxPower); + + for (i = 0; i < config->bNumInterfaces; i++) + print_interface(&config->interface[i]); +} + +static void print_device(libusb_device *dev, libusb_device_handle *handle) +{ + struct libusb_device_descriptor desc; + unsigned char string[256]; + const char *speed; + int ret; + uint8_t i; + + switch (libusb_get_device_speed(dev)) { + case LIBUSB_SPEED_LOW: speed = "1.5M"; break; + case LIBUSB_SPEED_FULL: speed = "12M"; break; + case LIBUSB_SPEED_HIGH: speed = "480M"; break; + case LIBUSB_SPEED_SUPER: speed = "5G"; break; + case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break; + default: speed = "Unknown"; + } + + ret = libusb_get_device_descriptor(dev, &desc); + if (ret < 0) { + fprintf(stderr, "failed to get device descriptor"); + return; + } + + printf("Dev (bus %u, device %u): %04X - %04X speed: %s\n", + libusb_get_bus_number(dev), libusb_get_device_address(dev), + desc.idVendor, desc.idProduct, speed); + + if (!handle) + libusb_open(dev, &handle); + + if (handle) { + if (desc.iManufacturer) { + ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string)); + if (ret > 0) + printf(" Manufacturer: %s\n", (char *)string); + } + + if (desc.iProduct) { + ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string)); + if (ret > 0) + printf(" Product: %s\n", (char *)string); + } + + if (desc.iSerialNumber && verbose) { + ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string)); + if (ret > 0) + printf(" Serial Number: %s\n", (char *)string); + } + } + + if (verbose) { + for (i = 0; i < desc.bNumConfigurations; i++) { + struct libusb_config_descriptor *config; + + ret = libusb_get_config_descriptor(dev, i, &config); + if (LIBUSB_SUCCESS != ret) { + printf(" Couldn't retrieve descriptors\n"); + continue; + } + + print_configuration(config); + + libusb_free_config_descriptor(config); + } + + if (handle && desc.bcdUSB >= 0x0201) + print_bos(handle); + } + + if (handle) + libusb_close(handle); +} + +#ifdef __linux__ +#include +#include +#include + +static int test_wrapped_device(const char *device_name) +{ + libusb_device_handle *handle; + int r, fd; + + fd = open(device_name, O_RDWR); + if (fd < 0) { + printf("Error could not open %s: %s\n", device_name, strerror(errno)); + return 1; + } + r = libusb_wrap_sys_device(NULL, fd, &handle); + if (r) { + printf("Error wrapping device: %s: %s\n", device_name, libusb_strerror(r)); + close(fd); + return 1; + } + print_device(libusb_get_device(handle), handle); + close(fd); + return 0; +} +#else +static int test_wrapped_device(const char *device_name) +{ + (void)device_name; + printf("Testing wrapped devices is not supported on your platform\n"); + return 1; +} +#endif + +int main(int argc, char *argv[]) +{ + const char *device_name = NULL; + libusb_device **devs; + ssize_t cnt; + int r, i; + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-v")) { + verbose = 1; + } else if (!strcmp(argv[i], "-d") && (i + 1) < argc) { + i++; + device_name = argv[i]; + } else { + printf("Usage %s [-v] [-d ]\n", argv[0]); + printf("Note use -d to test libusb_wrap_sys_device()\n"); + return 1; + } + } + + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); + if (r < 0) + return r; + + if (device_name) { + r = test_wrapped_device(device_name); + } else { + cnt = libusb_get_device_list(NULL, &devs); + if (cnt < 0) { + libusb_exit(NULL); + return 1; + } + + for (i = 0; devs[i]; i++) + print_device(devs[i], NULL); + + libusb_free_device_list(devs, 1); + } + + libusb_exit(NULL); + return r; +} diff --git a/dependencies/libusb-1.0.22/examples/source/xusb.c b/dependencies/libusb-1.0.27/examples/source/xusb.c similarity index 90% rename from dependencies/libusb-1.0.22/examples/source/xusb.c rename to dependencies/libusb-1.0.27/examples/source/xusb.c index 4ac11b84..239450ce 100644 --- a/dependencies/libusb-1.0.22/examples/source/xusb.c +++ b/dependencies/libusb-1.0.27/examples/source/xusb.c @@ -18,36 +18,21 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include #include #include #include #include -#include +#include #include "libusb.h" -#if defined(_WIN32) -#define msleep(msecs) Sleep(msecs) -#else -#include -#define msleep(msecs) nanosleep(&(struct timespec){msecs / 1000, (msecs * 1000000) % 1000000000UL}, NULL); -#endif - #if defined(_MSC_VER) #define snprintf _snprintf #define putenv _putenv #endif -#if !defined(bool) -#define bool int -#endif -#if !defined(true) -#define true (1 == 1) -#endif -#if !defined(false) -#define false (!true) -#endif - // Future versions of libusb will use usb_interface instead of interface // in libusb_config_descriptor => catter for that #define usb_interface interface @@ -58,6 +43,16 @@ static bool extra_info = false; static bool force_device_request = false; // For WCID descriptor queries static const char* binary_name = NULL; +static inline void msleep(int msecs) +{ +#if defined(_WIN32) + Sleep(msecs); +#else + const struct timespec ts = { msecs / 1000, (msecs % 1000) * 1000000L }; + nanosleep(&ts, NULL); +#endif +} + static void perr(char const *format, ...) { va_list args; @@ -225,7 +220,7 @@ static int display_ps3_status(libusb_device_handle *handle) printf("\tRIGHT 3 pressed\n"); break; case 0x08: - printf("\tSTART presed\n"); + printf("\tSTART pressed\n"); break; case 0x10: printf("\tUP pressed\n"); @@ -251,7 +246,7 @@ static int display_ps3_status(libusb_device_handle *handle) printf("\tLEFT 1 pressed\n"); break; case 0x08: - printf("\tRIGHT 1 presed\n"); + printf("\tRIGHT 1 pressed\n"); break; case 0x10: printf("\tTRIANGLE pressed\n"); @@ -470,20 +465,23 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, unsigned char *data; FILE *fd; - printf("Reading Max LUN:\n"); + printf("\nReading Max LUN:\n"); r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, BOMS_GET_MAX_LUN, 0, 0, &lun, 1, 1000); // Some devices send a STALL instead of the actual value. // In such cases we should set lun to 0. - if (r == 0) { + if (r == LIBUSB_ERROR_PIPE) { lun = 0; + printf(" Stalled, setting Max LUN to 0\n"); } else if (r < 0) { - perr(" Failed: %s", libusb_strerror((enum libusb_error)r)); + perr(" Failed.\n"); + return r; + } else { + printf(" Max LUN = %d\n", lun); } - printf(" Max LUN = %d\n", lun); // Send Inquiry - printf("Sending Inquiry:\n"); + printf("\nSending Inquiry:\n"); memset(buffer, 0, sizeof(buffer)); memset(cdb, 0, sizeof(cdb)); cdb[0] = 0x12; // Inquiry @@ -507,7 +505,7 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, } // Read capacity - printf("Reading Capacity:\n"); + printf("\nReading Capacity:\n"); memset(buffer, 0, sizeof(buffer)); memset(cdb, 0, sizeof(cdb)); cdb[0] = 0x25; // Read Capacity @@ -531,7 +529,7 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, } // Send Read - printf("Attempting to read %u bytes:\n", block_size); + printf("\nAttempting to read %u bytes:\n", block_size); memset(cdb, 0, sizeof(cdb)); cdb[0] = 0x28; // Read(10) @@ -627,7 +625,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in) } display_buffer_hex(hid_report_descriptor, descriptor_size); if ((binary_dump) && ((fd = fopen(binary_name, "w")) != NULL)) { - if (fwrite(hid_report_descriptor, 1, descriptor_size, fd) != descriptor_size) { + if (fwrite(hid_report_descriptor, 1, descriptor_size, fd) != (size_t)descriptor_size) { printf(" Error writing descriptor to file\n"); } fclose(fd); @@ -794,6 +792,20 @@ static void print_device_cap(struct libusb_bos_dev_capability_descriptor *dev_ca } break; } + case LIBUSB_BT_PLATFORM_DESCRIPTOR: { + struct libusb_platform_descriptor *platform_descriptor = NULL; + libusb_get_platform_descriptor(NULL, dev_cap, &platform_descriptor); + if (platform_descriptor) { + printf(" Platform descriptor:\n"); + printf(" bLength : %d\n", platform_descriptor->bLength); + printf(" PlatformCapabilityUUID : %s\n", uuid_to_string(platform_descriptor->PlatformCapabilityUUID)); + display_buffer_hex(&platform_descriptor->CapabilityData[0], platform_descriptor->bLength - 20); + printf("\n"); + libusb_free_platform_descriptor(platform_descriptor); + } + break; + + } default: printf(" Unknown BOS device capability %02x:\n", dev_cap->bDevCapabilityType); } @@ -810,8 +822,8 @@ static int test_device(uint16_t vid, uint16_t pid) int i, j, k, r; int iface, nb_ifaces, first_iface = -1; struct libusb_device_descriptor dev_desc; - const char* const speed_name[5] = { "Unknown", "1.5 Mbit/s (USB LowSpeed)", "12 Mbit/s (USB FullSpeed)", - "480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)" }; + const char* const speed_name[6] = { "Unknown", "1.5 Mbit/s (USB LowSpeed)", "12 Mbit/s (USB FullSpeed)", + "480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)", "10000 Mbit/s (USB SuperSpeedPlus)" }; char string[128]; uint8_t string_index[3]; // indexes of the string descriptors uint8_t endpoint_in = 0, endpoint_out = 0; // default IN and OUT endpoints @@ -838,7 +850,7 @@ static int test_device(uint16_t vid, uint16_t pid) printf(" (from root hub)\n"); } r = libusb_get_device_speed(dev); - if ((r<0) || (r>4)) r=0; + if ((r<0) || (r>5)) r=0; printf(" speed: %s\n", speed_name[r]); } @@ -868,6 +880,8 @@ static int test_device(uint16_t vid, uint16_t pid) printf("\nReading first configuration descriptor:\n"); CALL_CHECK_CLOSE(libusb_get_config_descriptor(dev, 0, &conf_desc), handle); + printf(" total length: %d\n", conf_desc->wTotalLength); + printf(" descriptor length: %d\n", conf_desc->bLength); nb_ifaces = conf_desc->bNumInterfaces; printf(" nb interfaces: %d\n", nb_ifaces); if (nb_ifaces > 0) @@ -919,10 +933,25 @@ static int test_device(uint16_t vid, uint16_t pid) libusb_set_auto_detach_kernel_driver(handle, 1); for (iface = 0; iface < nb_ifaces; iface++) { + int ret; + + printf("\nKernel driver attached for interface %d: ", iface); + ret = libusb_kernel_driver_active(handle, iface); + if (ret == 0) + printf("none\n"); + else if (ret == 1) + printf("yes\n"); + else if (ret == LIBUSB_ERROR_NOT_SUPPORTED) + printf("(not supported)\n"); + else + perr("\n Failed (error %d) %s\n", ret, + libusb_strerror((enum libusb_error) ret)); + printf("\nClaiming interface %d...\n", iface); r = libusb_claim_interface(handle, iface); if (r != LIBUSB_SUCCESS) { - perr(" Failed.\n"); + perr(" Failed (error %d) %s\n", ret, + libusb_strerror((enum libusb_error) ret)); } } @@ -935,12 +964,42 @@ static int test_device(uint16_t vid, uint16_t pid) printf(" String (0x%02X): \"%s\"\n", string_index[i], string); } } - // Read the OS String Descriptor + + printf("\nReading OS string descriptor:"); r = libusb_get_string_descriptor(handle, MS_OS_DESC_STRING_INDEX, 0, (unsigned char*)string, MS_OS_DESC_STRING_LENGTH); if (r == MS_OS_DESC_STRING_LENGTH && memcmp(ms_os_desc_string, string, sizeof(ms_os_desc_string)) == 0) { // If this is a Microsoft OS String Descriptor, // attempt to read the WinUSB extended Feature Descriptors + printf("\n"); read_ms_winsub_feature_descriptors(handle, string[MS_OS_DESC_VENDOR_CODE_OFFSET], first_iface); + } else { + printf(" no descriptor\n"); + } + + // Read IADs + printf("\nReading interface association descriptors (IADs) for first configuration:\n"); + struct libusb_interface_association_descriptor_array *iad_array; + r = libusb_get_interface_association_descriptors(dev, 0, &iad_array); + if (r == LIBUSB_SUCCESS) { + printf(" nb IADs: %d\n", iad_array->length); + for (i=0; ilength;i++) { + const struct libusb_interface_association_descriptor *iad = &iad_array->iad[i]; + printf(" IAD %d:\n", i); + printf(" bFirstInterface: %u\n", iad->bFirstInterface); + printf(" bInterfaceCount: %u\n", iad->bInterfaceCount); + printf(" bFunctionClass: %02X\n", iad->bFunctionClass); + printf(" bFunctionSubClass: %02X\n", iad->bFunctionSubClass); + printf(" bFunctionProtocol: %02X\n", iad->bFunctionProtocol); + if (iad->iFunction) { + if (libusb_get_string_descriptor_ascii(handle, iad->iFunction, (unsigned char*)string, sizeof(string)) > 0) + printf(" iFunction: %u (%s)\n", iad->iFunction, string); + else + printf(" iFunction: %u (libusb_get_string_descriptor_ascii failed!)\n", iad->iFunction); + } + else + printf(" iFunction: 0\n"); + } + libusb_free_interface_association_descriptors(iad_array); } switch(test_mode) { @@ -1099,17 +1158,17 @@ int main(int argc, char** argv) return 0; } - // xusb is commonly used as a debug tool, so it's convenient to have debug output during libusb_init(), - // but since we can't call on libusb_set_option() before libusb_init(), we use the env variable method - old_dbg_str = getenv("LIBUSB_DEBUG"); - if (debug_mode) { - if (putenv("LIBUSB_DEBUG=4") != 0) // LIBUSB_LOG_LEVEL_DEBUG - printf("Unable to set debug level\n"); - } - version = libusb_get_version(); printf("Using libusb v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano); - r = libusb_init(NULL); + + // xusb is commonly used as a debug tool, so it's convenient to have debug output during libusb_init_context(). + if (debug_mode) { + const struct libusb_init_option options = {.option = LIBUSB_OPTION_LOG_LEVEL, .value = {.ival = LIBUSB_LOG_LEVEL_DEBUG}}; + r = libusb_init_context(/*ctx=*/NULL, /*options=*/&options, /*num_options=*/1); + } else { + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); + } + if (r < 0) return r; diff --git a/dependencies/libusb-1.0.22/include/libusb-1.0/libusb.h b/dependencies/libusb-1.0.27/include/libusb.h similarity index 78% rename from dependencies/libusb-1.0.22/include/libusb-1.0/libusb.h rename to dependencies/libusb-1.0.27/include/libusb.h index 430136b2..f4e9203c 100644 --- a/dependencies/libusb-1.0.22/include/libusb-1.0/libusb.h +++ b/dependencies/libusb-1.0.27/include/libusb.h @@ -3,8 +3,9 @@ * Copyright © 2001 Johannes Erdfelt * Copyright © 2007-2008 Daniel Drake * Copyright © 2012 Pete Batard - * Copyright © 2012 Nathan Hjelm - * For more information, please visit: http://libusb.info + * Copyright © 2012-2023 Nathan Hjelm + * Copyright © 2014-2020 Chris Dickens + * For more information, please visit: https://libusb.info * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,55 +25,42 @@ #ifndef LIBUSB_H #define LIBUSB_H -#ifdef _MSC_VER +#if defined(_MSC_VER) +#pragma warning(push) +/* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */ +#pragma warning(disable:4200) /* on MS environments, the inline keyword is available in C++ only */ #if !defined(__cplusplus) #define inline __inline #endif -/* ssize_t is also not available (copy/paste from MinGW) */ +/* ssize_t is also not available */ #ifndef _SSIZE_T_DEFINED #define _SSIZE_T_DEFINED -#undef ssize_t -#ifdef _WIN64 - typedef __int64 ssize_t; -#else - typedef int ssize_t; -#endif /* _WIN64 */ +#include +typedef SSIZE_T ssize_t; #endif /* _SSIZE_T_DEFINED */ #endif /* _MSC_VER */ -/* stdint.h is not available on older MSVC */ -#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H)) -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -#else +#include #include -#endif - -#if !defined(_WIN32_WCE) #include -#endif - -#if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__HAIKU__) +#if !defined(_MSC_VER) #include #endif - #include -#include #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -#define ZERO_SIZED_ARRAY /* [] - valid C99 code */ +#define LIBUSB_FLEXIBLE_ARRAY /* [] - valid C99 code */ #else -#define ZERO_SIZED_ARRAY 0 /* [0] - non-standard, but usually working code */ -#endif +#define LIBUSB_FLEXIBLE_ARRAY 0 /* [0] - non-standard, but usually working code */ +#endif /* __STDC_VERSION__ */ /* 'interface' might be defined as a macro on Windows, so we need to * undefine it so as not to break the current libusb API, because * libusb_config_descriptor has an 'interface' member * As this can be problematic if you include windows.h after libusb.h * in your sources, we force windows.h to be included first. */ -#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) +#if defined(_WIN32) || defined(__CYGWIN__) #include #if defined(interface) #undef interface @@ -80,17 +68,24 @@ typedef unsigned __int32 uint32_t; #if !defined(__CYGWIN__) #include #endif -#endif +#endif /* _WIN32 || __CYGWIN__ */ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#define LIBUSB_DEPRECATED_FOR(f) \ - __attribute__((deprecated("Use " #f " instead"))) -#elif __GNUC__ >= 3 -#define LIBUSB_DEPRECATED_FOR(f) __attribute__((deprecated)) +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) +#define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated ("Use " #f " instead"))) +#elif defined(__GNUC__) && (__GNUC__ >= 3) +#define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated)) +#elif defined(_MSC_VER) +#define LIBUSB_DEPRECATED_FOR(f) __declspec(deprecated("Use " #f " instead")) #else #define LIBUSB_DEPRECATED_FOR(f) #endif /* __GNUC__ */ +#if defined(__GNUC__) +#define LIBUSB_PACKED __attribute__ ((packed)) +#else +#define LIBUSB_PACKED +#endif /* __GNUC__ */ + /** \def LIBUSB_CALL * \ingroup libusb_misc * libusb's Windows calling convention. @@ -123,22 +118,27 @@ typedef unsigned __int32 uint32_t; * return type, before the function name. See internal documentation for * API_EXPORTED. */ -#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) +#if defined(_WIN32) || defined(__CYGWIN__) #define LIBUSB_CALL WINAPI +#define LIBUSB_CALLV WINAPIV #else #define LIBUSB_CALL -#endif +#define LIBUSB_CALLV +#endif /* _WIN32 || __CYGWIN__ */ /** \def LIBUSB_API_VERSION * \ingroup libusb_misc * libusb's API version. * - * Since version 1.0.13, to help with feature detection, libusb defines + * Since version 1.0.18, to help with feature detection, libusb defines * a LIBUSB_API_VERSION macro that gets increased every time there is a * significant change to the API, such as the introduction of a new call, * the definition of a new macro/enum member, or any other element that * libusb applications may want to detect at compilation time. * + * Between versions 1.0.13 and 1.0.17 (inclusive) the older spelling of + * LIBUSBX_API_VERSION was used. + * * The macro is typically used in an application as follows: * \code * #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01001234) @@ -148,13 +148,37 @@ typedef unsigned __int32 uint32_t; * * Internally, LIBUSB_API_VERSION is defined as follows: * (libusb major << 24) | (libusb minor << 16) | (16 bit incremental) + * + * The incremental component has changed as follows: + *
    + *
  • libusbx version 1.0.13: LIBUSBX_API_VERSION = 0x01000100 + *
  • libusbx version 1.0.14: LIBUSBX_API_VERSION = 0x010000FF + *
  • libusbx version 1.0.15: LIBUSBX_API_VERSION = 0x01000101 + *
  • libusbx version 1.0.16: LIBUSBX_API_VERSION = 0x01000102 + *
  • libusbx version 1.0.17: LIBUSBX_API_VERSION = 0x01000102 + *
  • libusb version 1.0.18: LIBUSB_API_VERSION = 0x01000102 + *
  • libusb version 1.0.19: LIBUSB_API_VERSION = 0x01000103 + *
  • libusb version 1.0.20: LIBUSB_API_VERSION = 0x01000104 + *
  • libusb version 1.0.21: LIBUSB_API_VERSION = 0x01000105 + *
  • libusb version 1.0.22: LIBUSB_API_VERSION = 0x01000106 + *
  • libusb version 1.0.23: LIBUSB_API_VERSION = 0x01000107 + *
  • libusb version 1.0.24: LIBUSB_API_VERSION = 0x01000108 + *
  • libusb version 1.0.25: LIBUSB_API_VERSION = 0x01000109 + *
  • libusb version 1.0.26: LIBUSB_API_VERSION = 0x01000109 + *
  • libusb version 1.0.27: LIBUSB_API_VERSION = 0x0100010A + *
*/ -#define LIBUSB_API_VERSION 0x01000106 +#define LIBUSB_API_VERSION 0x0100010A -/* The following is kept for compatibility, but will be deprecated in the future */ +/** \def LIBUSBX_API_VERSION + * \ingroup libusb_misc + * + * This is the older spelling, kept for backwards compatibility of code + * needing to test for older library versions where the newer spelling + * did not exist. */ #define LIBUSBX_API_VERSION LIBUSB_API_VERSION -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -196,35 +220,35 @@ enum libusb_class_code { * this bDeviceClass value indicates that each interface specifies its * own class information and all interfaces operate independently. */ - LIBUSB_CLASS_PER_INTERFACE = 0, + LIBUSB_CLASS_PER_INTERFACE = 0x00, /** Audio class */ - LIBUSB_CLASS_AUDIO = 1, + LIBUSB_CLASS_AUDIO = 0x01, /** Communications class */ - LIBUSB_CLASS_COMM = 2, + LIBUSB_CLASS_COMM = 0x02, /** Human Interface Device class */ - LIBUSB_CLASS_HID = 3, + LIBUSB_CLASS_HID = 0x03, /** Physical */ - LIBUSB_CLASS_PHYSICAL = 5, - - /** Printer class */ - LIBUSB_CLASS_PRINTER = 7, + LIBUSB_CLASS_PHYSICAL = 0x05, /** Image class */ - LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */ - LIBUSB_CLASS_IMAGE = 6, + LIBUSB_CLASS_IMAGE = 0x06, + LIBUSB_CLASS_PTP = 0x06, /* legacy name from libusb-0.1 usb.h */ + + /** Printer class */ + LIBUSB_CLASS_PRINTER = 0x07, /** Mass storage class */ - LIBUSB_CLASS_MASS_STORAGE = 8, + LIBUSB_CLASS_MASS_STORAGE = 0x08, /** Hub class */ - LIBUSB_CLASS_HUB = 9, + LIBUSB_CLASS_HUB = 0x09, /** Data class */ - LIBUSB_CLASS_DATA = 10, + LIBUSB_CLASS_DATA = 0x0a, /** Smart Card */ LIBUSB_CLASS_SMART_CARD = 0x0b, @@ -244,6 +268,9 @@ enum libusb_class_code { /** Wireless class */ LIBUSB_CLASS_WIRELESS = 0xe0, + /** Miscellaneous class */ + LIBUSB_CLASS_MISCELLANEOUS = 0xef, + /** Application class */ LIBUSB_CLASS_APPLICATION = 0xfe, @@ -269,6 +296,10 @@ enum libusb_descriptor_type { /** Endpoint descriptor. See libusb_endpoint_descriptor. */ LIBUSB_DT_ENDPOINT = 0x05, + /** Interface Association Descriptor. + * See libusb_interface_association_descriptor */ + LIBUSB_DT_INTERFACE_ASSOCIATION = 0x0b, + /** BOS descriptor */ LIBUSB_DT_BOS = 0x0f, @@ -309,14 +340,16 @@ enum libusb_descriptor_type { #define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7 #define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10 #define LIBUSB_BT_CONTAINER_ID_SIZE 20 +#define LIBUSB_BT_PLATFORM_DESCRIPTOR_MIN_SIZE 20 /* We unwrap the BOS => define its max size */ -#define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\ - (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\ - (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\ - (LIBUSB_BT_CONTAINER_ID_SIZE)) +#define LIBUSB_DT_BOS_MAX_SIZE \ + (LIBUSB_DT_BOS_SIZE + \ + LIBUSB_BT_USB_2_0_EXTENSION_SIZE + \ + LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE + \ + LIBUSB_BT_CONTAINER_ID_SIZE) -#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ +#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ #define LIBUSB_ENDPOINT_DIR_MASK 0x80 /** \ingroup libusb_desc @@ -324,34 +357,31 @@ enum libusb_descriptor_type { * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme. */ enum libusb_endpoint_direction { - /** In: device-to-host */ - LIBUSB_ENDPOINT_IN = 0x80, - /** Out: host-to-device */ - LIBUSB_ENDPOINT_OUT = 0x00 + LIBUSB_ENDPOINT_OUT = 0x00, + + /** In: device-to-host */ + LIBUSB_ENDPOINT_IN = 0x80 }; -#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ +#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ /** \ingroup libusb_desc * Endpoint transfer type. Values for bits 0:1 of the * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field. */ -enum libusb_transfer_type { +enum libusb_endpoint_transfer_type { /** Control endpoint */ - LIBUSB_TRANSFER_TYPE_CONTROL = 0, + LIBUSB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0x0, /** Isochronous endpoint */ - LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, + LIBUSB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 0x1, /** Bulk endpoint */ - LIBUSB_TRANSFER_TYPE_BULK = 2, + LIBUSB_ENDPOINT_TRANSFER_TYPE_BULK = 0x2, /** Interrupt endpoint */ - LIBUSB_TRANSFER_TYPE_INTERRUPT = 3, - - /** Stream endpoint */ - LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4, + LIBUSB_ENDPOINT_TRANSFER_TYPE_INTERRUPT = 0x3 }; /** \ingroup libusb_misc @@ -386,20 +416,20 @@ enum libusb_standard_request { LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, /** Return the selected alternate setting for the specified interface */ - LIBUSB_REQUEST_GET_INTERFACE = 0x0A, + LIBUSB_REQUEST_GET_INTERFACE = 0x0a, /** Select an alternate interface for the specified interface */ - LIBUSB_REQUEST_SET_INTERFACE = 0x0B, + LIBUSB_REQUEST_SET_INTERFACE = 0x0b, /** Set then report an endpoint's synchronization frame */ - LIBUSB_REQUEST_SYNCH_FRAME = 0x0C, + LIBUSB_REQUEST_SYNCH_FRAME = 0x0c, /** Sets both the U1 and U2 Exit Latency */ LIBUSB_REQUEST_SET_SEL = 0x30, /** Delay from the time a host transmits a packet to the time it is * received by the device. */ - LIBUSB_SET_ISOCH_DELAY = 0x31, + LIBUSB_SET_ISOCH_DELAY = 0x31 }; /** \ingroup libusb_misc @@ -435,10 +465,10 @@ enum libusb_request_recipient { LIBUSB_RECIPIENT_ENDPOINT = 0x02, /** Other */ - LIBUSB_RECIPIENT_OTHER = 0x03, + LIBUSB_RECIPIENT_OTHER = 0x03 }; -#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C +#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0c /** \ingroup libusb_desc * Synchronization type for isochronous endpoints. Values for bits 2:3 of the @@ -447,19 +477,19 @@ enum libusb_request_recipient { */ enum libusb_iso_sync_type { /** No synchronization */ - LIBUSB_ISO_SYNC_TYPE_NONE = 0, + LIBUSB_ISO_SYNC_TYPE_NONE = 0x0, /** Asynchronous */ - LIBUSB_ISO_SYNC_TYPE_ASYNC = 1, + LIBUSB_ISO_SYNC_TYPE_ASYNC = 0x1, /** Adaptive */ - LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2, + LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 0x2, /** Synchronous */ - LIBUSB_ISO_SYNC_TYPE_SYNC = 3 + LIBUSB_ISO_SYNC_TYPE_SYNC = 0x3 }; -#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 +#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 /** \ingroup libusb_desc * Usage type for isochronous endpoints. Values for bits 4:5 of the @@ -468,13 +498,71 @@ enum libusb_iso_sync_type { */ enum libusb_iso_usage_type { /** Data endpoint */ - LIBUSB_ISO_USAGE_TYPE_DATA = 0, + LIBUSB_ISO_USAGE_TYPE_DATA = 0x0, /** Feedback endpoint */ - LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1, + LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 0x1, /** Implicit feedback Data endpoint */ - LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2, + LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 0x2 +}; + +/** \ingroup libusb_desc + * Supported speeds (wSpeedSupported) bitfield. Indicates what + * speeds the device supports. + */ +enum libusb_supported_speed { + /** Low speed operation supported (1.5MBit/s). */ + LIBUSB_LOW_SPEED_OPERATION = (1 << 0), + + /** Full speed operation supported (12MBit/s). */ + LIBUSB_FULL_SPEED_OPERATION = (1 << 1), + + /** High speed operation supported (480MBit/s). */ + LIBUSB_HIGH_SPEED_OPERATION = (1 << 2), + + /** Superspeed operation supported (5000MBit/s). */ + LIBUSB_SUPER_SPEED_OPERATION = (1 << 3) +}; + +/** \ingroup libusb_desc + * Masks for the bits of the + * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field + * of the USB 2.0 Extension descriptor. + */ +enum libusb_usb_2_0_extension_attributes { + /** Supports Link Power Management (LPM) */ + LIBUSB_BM_LPM_SUPPORT = (1 << 1) +}; + +/** \ingroup libusb_desc + * Masks for the bits of the + * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field + * field of the SuperSpeed USB Device Capability descriptor. + */ +enum libusb_ss_usb_device_capability_attributes { + /** Supports Latency Tolerance Messages (LTM) */ + LIBUSB_BM_LTM_SUPPORT = (1 << 1) +}; + +/** \ingroup libusb_desc + * USB capability types + */ +enum libusb_bos_type { + /** Wireless USB device capability */ + LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 0x01, + + /** USB 2.0 extensions */ + LIBUSB_BT_USB_2_0_EXTENSION = 0x02, + + /** SuperSpeed USB device capability */ + LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 0x03, + + /** Container ID type */ + LIBUSB_BT_CONTAINER_ID = 0x04, + + /** Platform descriptor */ + LIBUSB_BT_PLATFORM_DESCRIPTOR = 0x05 }; /** \ingroup libusb_desc @@ -547,17 +635,15 @@ struct libusb_endpoint_descriptor { /** The address of the endpoint described by this descriptor. Bits 0:3 are * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction, - * see \ref libusb_endpoint_direction. - */ + * see \ref libusb_endpoint_direction. */ uint8_t bEndpointAddress; /** Attributes which apply to the endpoint when it is configured using * the bConfigurationValue. Bits 0:1 determine the transfer type and - * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for - * isochronous endpoints and correspond to \ref libusb_iso_sync_type. + * correspond to \ref libusb_endpoint_transfer_type. Bits 2:3 are only used + * for isochronous endpoints and correspond to \ref libusb_iso_sync_type. * Bits 4:5 are also only used for isochronous endpoints and correspond to - * \ref libusb_iso_usage_type. Bits 6:7 are reserved. - */ + * \ref libusb_iso_usage_type. Bits 6:7 are reserved. */ uint8_t bmAttributes; /** Maximum packet size this endpoint is capable of sending/receiving. */ @@ -577,10 +663,69 @@ struct libusb_endpoint_descriptor { * it will store them here, should you wish to parse them. */ const unsigned char *extra; - /** Length of the extra descriptors, in bytes. */ + /** Length of the extra descriptors, in bytes. Must be non-negative. */ int extra_length; }; +/** \ingroup libusb_desc + * A structure representing the standard USB interface association descriptor. + * This descriptor is documented in section 9.6.4 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_interface_association_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE_ASSOCIATION + * LIBUSB_DT_INTERFACE_ASSOCIATION in this context. */ + uint8_t bDescriptorType; + + /** Interface number of the first interface that is associated + * with this function */ + uint8_t bFirstInterface; + + /** Number of contiguous interfaces that are associated with + * this function */ + uint8_t bInterfaceCount; + + /** USB-IF class code for this function. + * A value of zero is not allowed in this descriptor. + * If this field is 0xff, the function class is vendor-specific. + * All other values are reserved for assignment by the USB-IF. + */ + uint8_t bFunctionClass; + + /** USB-IF subclass code for this function. + * If this field is not set to 0xff, all values are reserved + * for assignment by the USB-IF + */ + uint8_t bFunctionSubClass; + + /** USB-IF protocol code for this function. + * These codes are qualified by the values of the bFunctionClass + * and bFunctionSubClass fields. + */ + uint8_t bFunctionProtocol; + + /** Index of string descriptor describing this function */ + uint8_t iFunction; +}; + +/** \ingroup libusb_desc + * Structure containing an array of 0 or more interface association + * descriptors + */ +struct libusb_interface_association_descriptor_array { + /** Array of interface association descriptors. The size of this array + * is determined by the length field. + */ + const struct libusb_interface_association_descriptor *iad; + + /** Number of interface association descriptors contained. Read-only. */ + int length; +}; + /** \ingroup libusb_desc * A structure representing the standard USB interface descriptor. This * descriptor is documented in section 9.6.5 of the USB 3.0 specification. @@ -627,7 +772,7 @@ struct libusb_interface_descriptor { * it will store them here, should you wish to parse them. */ const unsigned char *extra; - /** Length of the extra descriptors, in bytes. */ + /** Length of the extra descriptors, in bytes. Must be non-negative. */ int extra_length; }; @@ -639,7 +784,8 @@ struct libusb_interface { * by the num_altsetting field. */ const struct libusb_interface_descriptor *altsetting; - /** The number of alternate settings that belong to this interface */ + /** The number of alternate settings that belong to this interface. + * Must be non-negative. */ int num_altsetting; }; @@ -686,7 +832,7 @@ struct libusb_config_descriptor { * descriptors, it will store them here, should you wish to parse them. */ const unsigned char *extra; - /** Length of the extra descriptors, in bytes. */ + /** Length of the extra descriptors, in bytes. Must be non-negative. */ int extra_length; }; @@ -697,7 +843,6 @@ struct libusb_config_descriptor { * host-endian format. */ struct libusb_ss_endpoint_companion_descriptor { - /** Size of this descriptor (in bytes) */ uint8_t bLength; @@ -706,19 +851,18 @@ struct libusb_ss_endpoint_companion_descriptor { * this context. */ uint8_t bDescriptorType; - /** The maximum number of packets the endpoint can send or * receive as part of a burst. */ uint8_t bMaxBurst; - /** In bulk EP: bits 4:0 represents the maximum number of - * streams the EP supports. In isochronous EP: bits 1:0 - * represents the Mult - a zero based value that determines - * the maximum number of packets within a service interval */ + /** In bulk EP: bits 4:0 represents the maximum number of + * streams the EP supports. In isochronous EP: bits 1:0 + * represents the Mult - a zero based value that determines + * the maximum number of packets within a service interval */ uint8_t bmAttributes; - /** The total number of bytes this EP will transfer every - * service interval. valid only for periodic EPs. */ + /** The total number of bytes this EP will transfer every + * service interval. Valid only for periodic EPs. */ uint16_t wBytesPerInterval; }; @@ -729,15 +873,18 @@ struct libusb_ss_endpoint_companion_descriptor { */ struct libusb_bos_dev_capability_descriptor { /** Size of this descriptor (in bytes) */ - uint8_t bLength; + uint8_t bLength; + /** Descriptor type. Will have value * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ - uint8_t bDescriptorType; + uint8_t bDescriptorType; + /** Device Capability type */ - uint8_t bDevCapabilityType; + uint8_t bDevCapabilityType; + /** Device Capability data (bLength - 3 bytes) */ - uint8_t dev_capability_data[ZERO_SIZED_ARRAY]; + uint8_t dev_capability_data[LIBUSB_FLEXIBLE_ARRAY]; }; /** \ingroup libusb_desc @@ -762,7 +909,7 @@ struct libusb_bos_descriptor { uint8_t bNumDeviceCaps; /** bNumDeviceCap Device Capability Descriptors */ - struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY]; + struct libusb_bos_dev_capability_descriptor *dev_capability[LIBUSB_FLEXIBLE_ARRAY]; }; /** \ingroup libusb_desc @@ -788,7 +935,7 @@ struct libusb_usb_2_0_extension_descriptor { * A value of one in a bit location indicates a feature is * supported; a value of zero indicates it is not supported. * See \ref libusb_usb_2_0_extension_attributes. */ - uint32_t bmAttributes; + uint32_t bmAttributes; }; /** \ingroup libusb_desc @@ -853,14 +1000,45 @@ struct libusb_container_id_descriptor { uint8_t bDevCapabilityType; /** Reserved field */ - uint8_t bReserved; + uint8_t bReserved; /** 128 bit UUID */ uint8_t ContainerID[16]; }; +/** \ingroup libusb_desc + * A structure representing a Platform descriptor. + * This descriptor is documented in section 9.6.2.4 of the USB 3.2 specification. + */ +struct libusb_platform_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY + * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ + uint8_t bDescriptorType; + + /** Capability type. Will have value + * \ref libusb_capability_type::LIBUSB_BT_PLATFORM_DESCRIPTOR + * LIBUSB_BT_CONTAINER_ID in this context. */ + uint8_t bDevCapabilityType; + + /** Reserved field */ + uint8_t bReserved; + + /** 128 bit UUID */ + uint8_t PlatformCapabilityUUID[16]; + + /** Capability data (bLength - 20) */ + uint8_t CapabilityData[LIBUSB_FLEXIBLE_ARRAY]; +}; + /** \ingroup libusb_asyncio * Setup packet for control transfers. */ +#if defined(_MSC_VER) || defined(__WATCOMC__) +#pragma pack(push, 1) +#endif struct libusb_control_setup { /** Request type. Bits 0:4 determine recipient, see * \ref libusb_request_recipient. Bits 5:6 determine type, see @@ -885,7 +1063,10 @@ struct libusb_control_setup { /** Number of bytes to transfer */ uint16_t wLength; -}; +} LIBUSB_PACKED; +#if defined(_MSC_VER) || defined(__WATCOMC__) +#pragma pack(pop) +#endif #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup)) @@ -915,7 +1096,7 @@ struct libusb_version { const char *rc; /** For ABI compatibility only. */ - const char* describe; + const char *describe; }; /** \ingroup libusb_lib @@ -927,11 +1108,12 @@ struct libusb_version { * libusb_exit() will not destroy resources that the other user is still * using. * - * Sessions are created by libusb_init() and destroyed through libusb_exit(). + * Sessions are created by libusb_init_context() and destroyed through libusb_exit(). * If your application is guaranteed to only ever include a single libusb * user (i.e. you), you do not have to worry about contexts: pass NULL in - * every function call where a context is required. The default context - * will be used. + * every function call where a context is required, and the default context + * will be used. Note that libusb_set_option(NULL, ...) is special, and adds + * an option to a list of default options for new contexts. * * For more information, see \ref libusb_contexts. */ @@ -940,7 +1122,7 @@ typedef struct libusb_context libusb_context; /** \ingroup libusb_dev * Structure representing a USB device detected on the system. This is an * opaque type for which you are only ever provided with a pointer, usually - * originating from libusb_get_device_list(). + * originating from libusb_get_device_list() or libusb_hotplug_register_callback(). * * Certain operations can be performed on a device, but in order to do any * I/O you will have to first obtain a device handle using libusb_open(). @@ -985,62 +1167,7 @@ enum libusb_speed { LIBUSB_SPEED_SUPER = 4, /** The device is operating at super speed plus (10000MBit/s). */ - LIBUSB_SPEED_SUPER_PLUS = 5, -}; - -/** \ingroup libusb_dev - * Supported speeds (wSpeedSupported) bitfield. Indicates what - * speeds the device supports. - */ -enum libusb_supported_speed { - /** Low speed operation supported (1.5MBit/s). */ - LIBUSB_LOW_SPEED_OPERATION = 1, - - /** Full speed operation supported (12MBit/s). */ - LIBUSB_FULL_SPEED_OPERATION = 2, - - /** High speed operation supported (480MBit/s). */ - LIBUSB_HIGH_SPEED_OPERATION = 4, - - /** Superspeed operation supported (5000MBit/s). */ - LIBUSB_SUPER_SPEED_OPERATION = 8, -}; - -/** \ingroup libusb_dev - * Masks for the bits of the - * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field - * of the USB 2.0 Extension descriptor. - */ -enum libusb_usb_2_0_extension_attributes { - /** Supports Link Power Management (LPM) */ - LIBUSB_BM_LPM_SUPPORT = 2, -}; - -/** \ingroup libusb_dev - * Masks for the bits of the - * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field - * field of the SuperSpeed USB Device Capability descriptor. - */ -enum libusb_ss_usb_device_capability_attributes { - /** Supports Latency Tolerance Messages (LTM) */ - LIBUSB_BM_LTM_SUPPORT = 2, -}; - -/** \ingroup libusb_dev - * USB capability types - */ -enum libusb_bos_type { - /** Wireless USB device capability */ - LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1, - - /** USB 2.0 extensions */ - LIBUSB_BT_USB_2_0_EXTENSION = 2, - - /** SuperSpeed USB device capability */ - LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3, - - /** Container ID type */ - LIBUSB_BT_CONTAINER_ID = 4, + LIBUSB_SPEED_SUPER_PLUS = 5 }; /** \ingroup libusb_misc @@ -1094,12 +1221,31 @@ enum libusb_error { message strings in strerror.c when adding new error codes here. */ /** Other error */ - LIBUSB_ERROR_OTHER = -99, + LIBUSB_ERROR_OTHER = -99 }; /* Total number of error codes in enum libusb_error */ #define LIBUSB_ERROR_COUNT 14 +/** \ingroup libusb_asyncio + * Transfer type */ +enum libusb_transfer_type { + /** Control transfer */ + LIBUSB_TRANSFER_TYPE_CONTROL = 0U, + + /** Isochronous transfer */ + LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1U, + + /** Bulk transfer */ + LIBUSB_TRANSFER_TYPE_BULK = 2U, + + /** Interrupt transfer */ + LIBUSB_TRANSFER_TYPE_INTERRUPT = 3U, + + /** Bulk stream transfer */ + LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4U +}; + /** \ingroup libusb_asyncio * Transfer status codes */ enum libusb_transfer_status { @@ -1124,7 +1270,7 @@ enum libusb_transfer_status { LIBUSB_TRANSFER_NO_DEVICE, /** Device sent more data than requested */ - LIBUSB_TRANSFER_OVERFLOW, + LIBUSB_TRANSFER_OVERFLOW /* NB! Remember to update libusb_error_name() when adding new status codes here. */ @@ -1134,19 +1280,19 @@ enum libusb_transfer_status { * libusb_transfer.flags values */ enum libusb_transfer_flags { /** Report short frames as errors */ - LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0, + LIBUSB_TRANSFER_SHORT_NOT_OK = (1U << 0), /** Automatically free() transfer buffer during libusb_free_transfer(). * Note that buffers allocated with libusb_dev_mem_alloc() should not * be attempted freed in this way, since free() is not an appropriate * way to release such memory. */ - LIBUSB_TRANSFER_FREE_BUFFER = 1<<1, + LIBUSB_TRANSFER_FREE_BUFFER = (1U << 1), /** Automatically call libusb_free_transfer() after callback returns. * If this flag is set, it is illegal to call libusb_free_transfer() * from your transfer callback, as this will result in a double-free * when this flag is acted upon. */ - LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2, + LIBUSB_TRANSFER_FREE_TRANSFER = (1U << 2), /** Terminate transfers that are a multiple of the endpoint's * wMaxPacketSize with an extra zero length packet. This is useful @@ -1167,11 +1313,12 @@ enum libusb_transfer_flags { * * This flag is currently only supported on Linux. * On other systems, libusb_submit_transfer() will return - * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set. + * \ref LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this + * flag is set. * * Available since libusb-1.0.9. */ - LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3, + LIBUSB_TRANSFER_ADD_ZERO_PACKET = (1U << 3) }; /** \ingroup libusb_asyncio @@ -1216,7 +1363,7 @@ struct libusb_transfer { /** Address of the endpoint where this transfer will be sent. */ unsigned char endpoint; - /** Type of the endpoint from \ref libusb_transfer_type */ + /** Type of the transfer from \ref libusb_transfer_type */ unsigned char type; /** Timeout for this transfer in milliseconds. A value of 0 indicates no @@ -1232,7 +1379,7 @@ struct libusb_transfer { * to determine if errors occurred. */ enum libusb_transfer_status status; - /** Length of the data buffer */ + /** Length of the data buffer. Must be non-negative. */ int length; /** Actual length of data that was transferred. Read-only, and only for @@ -1244,18 +1391,27 @@ struct libusb_transfer { * fails, or is cancelled. */ libusb_transfer_cb_fn callback; - /** User context data to pass to the callback function. */ + /** User context data. Useful for associating specific data to a transfer + * that can be accessed from within the callback function. + * + * This field may be set manually or is taken as the `user_data` parameter + * of the following functions: + * - libusb_fill_bulk_transfer() + * - libusb_fill_bulk_stream_transfer() + * - libusb_fill_control_transfer() + * - libusb_fill_interrupt_transfer() + * - libusb_fill_iso_transfer() */ void *user_data; /** Data buffer */ unsigned char *buffer; /** Number of isochronous packets. Only used for I/O with isochronous - * endpoints. */ + * endpoints. Must be non-negative. */ int num_iso_packets; /** Isochronous packet descriptors, for isochronous transfers only. */ - struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY]; + struct libusb_iso_packet_descriptor iso_packet_desc[LIBUSB_FLEXIBLE_ARRAY]; }; /** \ingroup libusb_misc @@ -1265,44 +1421,169 @@ struct libusb_transfer { */ enum libusb_capability { /** The libusb_has_capability() API is available. */ - LIBUSB_CAP_HAS_CAPABILITY = 0x0000, + LIBUSB_CAP_HAS_CAPABILITY = 0x0000U, + /** Hotplug support is available on this platform. */ - LIBUSB_CAP_HAS_HOTPLUG = 0x0001, + LIBUSB_CAP_HAS_HOTPLUG = 0x0001U, + /** The library can access HID devices without requiring user intervention. * Note that before being able to actually access an HID device, you may * still have to call additional libusb functions such as * \ref libusb_detach_kernel_driver(). */ - LIBUSB_CAP_HAS_HID_ACCESS = 0x0100, - /** The library supports detaching of the default USB driver, using + LIBUSB_CAP_HAS_HID_ACCESS = 0x0100U, + + /** The library supports detaching of the default USB driver, using * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */ - LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101 + LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101U }; /** \ingroup libusb_lib * Log message levels. - * - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default) - * - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr - * - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr - * - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stderr - * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stderr */ enum libusb_log_level { + /** (0) : No messages ever emitted by the library (default) */ LIBUSB_LOG_LEVEL_NONE = 0, + + /** (1) : Error messages are emitted */ LIBUSB_LOG_LEVEL_ERROR = 1, + + /** (2) : Warning and error messages are emitted */ LIBUSB_LOG_LEVEL_WARNING = 2, + + /** (3) : Informational, warning and error messages are emitted */ LIBUSB_LOG_LEVEL_INFO = 3, - LIBUSB_LOG_LEVEL_DEBUG = 4, + + /** (4) : All messages are emitted */ + LIBUSB_LOG_LEVEL_DEBUG = 4 +}; + +/** \ingroup libusb_lib + * Log callback mode. + * + * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107 + * + * \see libusb_set_log_cb() + */ +enum libusb_log_cb_mode { + /** Callback function handling all log messages. */ + LIBUSB_LOG_CB_GLOBAL = (1 << 0), + + /** Callback function handling context related log messages. */ + LIBUSB_LOG_CB_CONTEXT = (1 << 1) +}; + +/** \ingroup libusb_lib + * Available option values for libusb_set_option() and libusb_init_context(). + */ +enum libusb_option { + /** Set the log message verbosity. + * + * This option must be provided an argument of type \ref libusb_log_level. + * The default level is LIBUSB_LOG_LEVEL_NONE, which means no messages are ever + * printed. If you choose to increase the message verbosity level, ensure + * that your application does not close the stderr file descriptor. + * + * You are advised to use level LIBUSB_LOG_LEVEL_WARNING. libusb is conservative + * with its message logging and most of the time, will only log messages that + * explain error conditions and other oddities. This will help you debug + * your software. + * + * If the LIBUSB_DEBUG environment variable was set when libusb was + * initialized, this option does nothing: the message verbosity is fixed + * to the value in the environment variable. + * + * If libusb was compiled without any message logging, this option does + * nothing: you'll never get any messages. + * + * If libusb was compiled with verbose debug message logging, this option + * does nothing: you'll always get messages from all levels. + */ + LIBUSB_OPTION_LOG_LEVEL = 0, + + /** Use the UsbDk backend for a specific context, if available. + * + * This option should be set at initialization with libusb_init_context() + * otherwise unspecified behavior may occur. + * + * Only valid on Windows. Ignored on all other platforms. + */ + LIBUSB_OPTION_USE_USBDK = 1, + + /** Do not scan for devices + * + * With this option set, libusb will skip scanning devices in + * libusb_init_context(). + * + * Hotplug functionality will also be deactivated. + * + * The option is useful in combination with libusb_wrap_sys_device(), + * which can access a device directly without prior device scanning. + * + * This is typically needed on Android, where access to USB devices + * is limited. + * + * This option should only be used with libusb_init_context() + * otherwise unspecified behavior may occur. + * + * Only valid on Linux. Ignored on all other platforms. + */ + LIBUSB_OPTION_NO_DEVICE_DISCOVERY = 2, + +#define LIBUSB_OPTION_WEAK_AUTHORITY LIBUSB_OPTION_NO_DEVICE_DISCOVERY + + /** Set the context log callback function. + * + * Set the log callback function either on a context or globally. This + * option must be provided an argument of type \ref libusb_log_cb. + * Using this option with a NULL context is equivalent to calling + * libusb_set_log_cb() with mode \ref LIBUSB_LOG_CB_GLOBAL. + * Using it with a non-NULL context is equivalent to calling + * libusb_set_log_cb() with mode \ref LIBUSB_LOG_CB_CONTEXT. + */ + LIBUSB_OPTION_LOG_CB = 3, + + LIBUSB_OPTION_MAX = 4 +}; + +/** \ingroup libusb_lib + * Callback function for handling log messages. + * \param ctx the context which is related to the log message, or NULL if it + * is a global log message + * \param level the log level, see \ref libusb_log_level for a description + * \param str the log message + * + * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107 + * + * \see libusb_set_log_cb() + */ +typedef void (LIBUSB_CALL *libusb_log_cb)(libusb_context *ctx, + enum libusb_log_level level, const char *str); + +/** \ingroup libusb_lib + * Structure used for setting options through \ref libusb_init_context. + * + */ +struct libusb_init_option { + /** Which option to set */ + enum libusb_option option; + /** An integer value used by the option (if applicable). */ + union { + int ival; + libusb_log_cb log_cbval; + } value; }; int LIBUSB_CALL libusb_init(libusb_context **ctx); +int LIBUSB_CALL libusb_init_context(libusb_context **ctx, const struct libusb_init_option options[], int num_options); void LIBUSB_CALL libusb_exit(libusb_context *ctx); -LIBUSB_DEPRECATED_FOR(libusb_set_option) void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level); +/* may be deprecated in the future in favor of lubusb_init_context()+libusb_set_option() */ +void LIBUSB_CALL libusb_set_log_cb(libusb_context *ctx, libusb_log_cb cb, int mode); const struct libusb_version * LIBUSB_CALL libusb_get_version(void); int LIBUSB_CALL libusb_has_capability(uint32_t capability); const char * LIBUSB_CALL libusb_error_name(int errcode); int LIBUSB_CALL libusb_setlocale(const char *locale); -const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode); +const char * LIBUSB_CALL libusb_strerror(int errcode); ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx, libusb_device ***list); @@ -1324,7 +1605,7 @@ int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev, void LIBUSB_CALL libusb_free_config_descriptor( struct libusb_config_descriptor *config); int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor( - struct libusb_context *ctx, + libusb_context *ctx, const struct libusb_endpoint_descriptor *endpoint, struct libusb_ss_endpoint_companion_descriptor **ep_comp); void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor( @@ -1333,27 +1614,32 @@ int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *dev_handle, struct libusb_bos_descriptor **bos); void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos); int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor( - struct libusb_context *ctx, + libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension); void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor( struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension); int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor( - struct libusb_context *ctx, + libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap); void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor( struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap); -int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx, +int LIBUSB_CALL libusb_get_container_id_descriptor(libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_container_id_descriptor **container_id); void LIBUSB_CALL libusb_free_container_id_descriptor( struct libusb_container_id_descriptor *container_id); +int LIBUSB_CALL libusb_get_platform_descriptor(libusb_context *ctx, + struct libusb_bos_dev_capability_descriptor *dev_cap, + struct libusb_platform_descriptor **platform_descriptor); +void LIBUSB_CALL libusb_free_platform_descriptor( + struct libusb_platform_descriptor *platform_descriptor); uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev); uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev); -int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len); +int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len); LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers) -int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length); +int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *path, uint8_t path_length); libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev); uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev); int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev); @@ -1361,7 +1647,17 @@ int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint); int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev, unsigned char endpoint); +int LIBUSB_CALL libusb_get_max_alt_packet_size(libusb_device *dev, + int interface_number, int alternate_setting, unsigned char endpoint); +int LIBUSB_CALL libusb_get_interface_association_descriptors(libusb_device *dev, + uint8_t config_index, struct libusb_interface_association_descriptor_array **iad_array); +int LIBUSB_CALL libusb_get_active_interface_association_descriptors(libusb_device *dev, + struct libusb_interface_association_descriptor_array **iad_array); +void LIBUSB_CALL libusb_free_interface_association_descriptors( + struct libusb_interface_association_descriptor_array *iad_array); + +int LIBUSB_CALL libusb_wrap_sys_device(libusb_context *ctx, intptr_t sys_dev, libusb_device_handle **dev_handle); int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **dev_handle); void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle); libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle); @@ -1436,7 +1732,7 @@ static inline unsigned char *libusb_control_transfer_get_data( static inline struct libusb_control_setup *libusb_control_transfer_get_setup( struct libusb_transfer *transfer) { - return (struct libusb_control_setup *)(void *) transfer->buffer; + return (struct libusb_control_setup *)(void *)transfer->buffer; } /** \ingroup libusb_asyncio @@ -1466,7 +1762,7 @@ static inline void libusb_fill_control_setup(unsigned char *buffer, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength) { - struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; + struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer; setup->bmRequestType = bmRequestType; setup->bRequest = bRequest; setup->wValue = libusb_cpu_to_le16(wValue); @@ -1516,7 +1812,7 @@ static inline void libusb_fill_control_transfer( unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) { - struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; + struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer; transfer->dev_handle = dev_handle; transfer->endpoint = 0; transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL; @@ -1655,6 +1951,7 @@ static inline void libusb_set_iso_packet_lengths( struct libusb_transfer *transfer, unsigned int length) { int i; + for (i = 0; i < transfer->num_iso_packets; i++) transfer->iso_packet_desc[i].length = length; } @@ -1869,7 +2166,7 @@ void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx, * Callbacks handles are generated by libusb_hotplug_register_callback() * and can be used to deregister callbacks. Callback handles are unique * per libusb_context and it is safe to call libusb_hotplug_deregister_callback() - * on an already deregisted callback. + * on an already deregistered callback. * * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * @@ -1881,29 +2178,30 @@ typedef int libusb_hotplug_callback_handle; * * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * - * Flags for hotplug events */ + * Hotplug events */ typedef enum { - /** Default value when not using any flags. */ - LIBUSB_HOTPLUG_NO_FLAGS = 0, + /** A device has been plugged in and is ready to use */ + LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = (1 << 0), - /** Arm the callback and fire it for all matching currently attached devices. */ - LIBUSB_HOTPLUG_ENUMERATE = 1<<0, -} libusb_hotplug_flag; + /** A device has left and is no longer available. + * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. + * It is safe to call libusb_get_device_descriptor on a device that has left */ + LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = (1 << 1) +} libusb_hotplug_event; /** \ingroup libusb_hotplug * * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * - * Hotplug events */ + * Hotplug flags */ typedef enum { - /** A device has been plugged in and is ready to use */ - LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01, + /** Arm the callback and fire it for all matching currently attached devices. */ + LIBUSB_HOTPLUG_ENUMERATE = (1 << 0) +} libusb_hotplug_flag; - /** A device has left and is no longer available. - * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. - * It is safe to call libusb_get_device_descriptor on a device that has left */ - LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02, -} libusb_hotplug_event; +/** \ingroup libusb_hotplug + * Convenience macro when not using any flags */ +#define LIBUSB_HOTPLUG_NO_FLAGS 0 /** \ingroup libusb_hotplug * Wildcard matching for hotplug events */ @@ -1932,9 +2230,7 @@ typedef enum { * returning 1 will cause this callback to be deregistered */ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx, - libusb_device *device, - libusb_hotplug_event event, - void *user_data); + libusb_device *device, libusb_hotplug_event event, void *user_data); /** \ingroup libusb_hotplug * Register a hotplug callback function @@ -1959,25 +2255,23 @@ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx, * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * * \param[in] ctx context to register this callback with - * \param[in] events bitwise or of events that will trigger this callback. See \ref - * libusb_hotplug_event - * \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag + * \param[in] events bitwise or of hotplug events that will trigger this callback. + * See \ref libusb_hotplug_event + * \param[in] flags bitwise or of hotplug flags that affect registration. + * See \ref libusb_hotplug_flag * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY * \param[in] cb_fn the function to be invoked on a matching event/device * \param[in] user_data user data to pass to the callback function * \param[out] callback_handle pointer to store the handle of the allocated callback (can be NULL) - * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure + * \returns \ref LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure */ int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx, - libusb_hotplug_event events, - libusb_hotplug_flag flags, - int vendor_id, int product_id, - int dev_class, - libusb_hotplug_callback_fn cb_fn, - void *user_data, - libusb_hotplug_callback_handle *callback_handle); + int events, int flags, + int vendor_id, int product_id, int dev_class, + libusb_hotplug_callback_fn cb_fn, void *user_data, + libusb_hotplug_callback_handle *callback_handle); /** \ingroup libusb_hotplug * Deregisters a hotplug callback. @@ -1991,48 +2285,26 @@ int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx, * \param[in] callback_handle the handle of the callback to deregister */ void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx, - libusb_hotplug_callback_handle callback_handle); + libusb_hotplug_callback_handle callback_handle); -/** \ingroup libusb_lib - * Available option values for libusb_set_option(). +/** \ingroup libusb_hotplug + * Gets the user_data associated with a hotplug callback. + * + * Since version v1.0.24 \ref LIBUSB_API_VERSION >= 0x01000108 + * + * \param[in] ctx context this callback is registered with + * \param[in] callback_handle the handle of the callback to get the user_data of */ -enum libusb_option { - /** Set the log message verbosity. - * - * The default level is LIBUSB_LOG_LEVEL_NONE, which means no messages are ever - * printed. If you choose to increase the message verbosity level, ensure - * that your application does not close the stderr file descriptor. - * - * You are advised to use level LIBUSB_LOG_LEVEL_WARNING. libusb is conservative - * with its message logging and most of the time, will only log messages that - * explain error conditions and other oddities. This will help you debug - * your software. - * - * If the LIBUSB_DEBUG environment variable was set when libusb was - * initialized, this function does nothing: the message verbosity is fixed - * to the value in the environment variable. - * - * If libusb was compiled without any message logging, this function does - * nothing: you'll never get any messages. - * - * If libusb was compiled with verbose debug message logging, this function - * does nothing: you'll always get messages from all levels. - */ - LIBUSB_OPTION_LOG_LEVEL, +void * LIBUSB_CALL libusb_hotplug_get_user_data(libusb_context *ctx, + libusb_hotplug_callback_handle callback_handle); - /** Use the UsbDk backend for a specific context, if available. - * - * This option should be set immediately after calling libusb_init(), otherwise - * unspecified behavior may occur. - * - * Only valid on Windows. - */ - LIBUSB_OPTION_USE_USBDK, -}; +int LIBUSB_CALLV libusb_set_option(libusb_context *ctx, enum libusb_option option, ...); -int LIBUSB_CALL libusb_set_option(libusb_context *ctx, enum libusb_option option, ...); +#ifdef _MSC_VER +#pragma warning(pop) +#endif -#ifdef __cplusplus +#if defined(__cplusplus) } #endif diff --git a/dependencies/libusb-1.0.22/libusb-1.0.def b/dependencies/libusb-1.0.27/libusb-1.0.def similarity index 87% rename from dependencies/libusb-1.0.22/libusb-1.0.def rename to dependencies/libusb-1.0.27/libusb-1.0.def index 3fd4b6bf..6d7caa7f 100644 --- a/dependencies/libusb-1.0.22/libusb-1.0.def +++ b/dependencies/libusb-1.0.27/libusb-1.0.def @@ -40,6 +40,10 @@ EXPORTS libusb_free_container_id_descriptor@4 = libusb_free_container_id_descriptor libusb_free_device_list libusb_free_device_list@8 = libusb_free_device_list + libusb_free_interface_association_descriptors + libusb_free_interface_association_descriptors@4 = libusb_free_interface_association_descriptors + libusb_free_platform_descriptor + libusb_free_platform_descriptor@4 = libusb_free_platform_descriptor libusb_free_pollfds libusb_free_pollfds@4 = libusb_free_pollfds libusb_free_ss_endpoint_companion_descriptor @@ -54,6 +58,8 @@ EXPORTS libusb_free_usb_2_0_extension_descriptor@4 = libusb_free_usb_2_0_extension_descriptor libusb_get_active_config_descriptor libusb_get_active_config_descriptor@8 = libusb_get_active_config_descriptor + libusb_get_active_interface_association_descriptors + libusb_get_active_interface_association_descriptors@8 = libusb_get_active_interface_association_descriptors libusb_get_bos_descriptor libusb_get_bos_descriptor@8 = libusb_get_bos_descriptor libusb_get_bus_number @@ -76,6 +82,10 @@ EXPORTS libusb_get_device_list@8 = libusb_get_device_list libusb_get_device_speed libusb_get_device_speed@4 = libusb_get_device_speed + libusb_get_interface_association_descriptors + libusb_get_interface_association_descriptors@12 = libusb_get_interface_association_descriptors + libusb_get_max_alt_packet_size + libusb_get_max_alt_packet_size@16 = libusb_get_max_alt_packet_size libusb_get_max_iso_packet_size libusb_get_max_iso_packet_size@8 = libusb_get_max_iso_packet_size libusb_get_max_packet_size @@ -84,6 +94,8 @@ EXPORTS libusb_get_next_timeout@8 = libusb_get_next_timeout libusb_get_parent libusb_get_parent@4 = libusb_get_parent + libusb_get_platform_descriptor + libusb_get_platform_descriptor@12 = libusb_get_platform_descriptor libusb_get_pollfds libusb_get_pollfds@4 = libusb_get_pollfds libusb_get_port_number @@ -116,10 +128,14 @@ EXPORTS libusb_has_capability@4 = libusb_has_capability libusb_hotplug_deregister_callback libusb_hotplug_deregister_callback@8 = libusb_hotplug_deregister_callback + libusb_hotplug_get_user_data + libusb_hotplug_get_user_data@8 = libusb_hotplug_get_user_data libusb_hotplug_register_callback libusb_hotplug_register_callback@36 = libusb_hotplug_register_callback libusb_init libusb_init@4 = libusb_init + libusb_init_context + libusb_init_context@12 = libusb_init_context libusb_interrupt_event_handler libusb_interrupt_event_handler@4 = libusb_interrupt_event_handler libusb_interrupt_transfer @@ -150,8 +166,9 @@ EXPORTS libusb_set_debug@8 = libusb_set_debug libusb_set_interface_alt_setting libusb_set_interface_alt_setting@12 = libusb_set_interface_alt_setting + libusb_set_log_cb + libusb_set_log_cb@12 = libusb_set_log_cb libusb_set_option - _libusb_set_option = libusb_set_option libusb_set_pollfd_notifiers libusb_set_pollfd_notifiers@16 = libusb_set_pollfd_notifiers libusb_setlocale @@ -174,3 +191,5 @@ EXPORTS libusb_unref_device@4 = libusb_unref_device libusb_wait_for_event libusb_wait_for_event@8 = libusb_wait_for_event + libusb_wrap_sys_device + libusb_wrap_sys_device@12 = libusb_wrap_sys_device