├── README ├── libusb ├── version_nano.h ├── os │ ├── poll_posix.h │ ├── threads_posix.c │ ├── poll_posix.c │ ├── sunos_usb.h │ ├── windows_usbdk.h │ ├── threads_posix.h │ ├── threads_windows.h │ ├── haiku_usb.h │ ├── poll_windows.h │ ├── threads_windows.c │ ├── windows_nt_common.h │ └── windows_common.h ├── version.h ├── libusb-1.0.rc ├── Makefile.am └── hotplug.h ├── NEWS ├── bootstrap.sh ├── TODO ├── autogen.sh ├── tests ├── Makefile.am └── libusb_testlib.h ├── doc └── Makefile.am ├── libusb-1.0.pc.in ├── msvc ├── xusb_sources ├── listdevs_sources ├── testlibusb_sources ├── hotplugtest_sources ├── stress_sources ├── getopt_sources ├── fxload_sources ├── missing.h ├── appveyor.bat ├── libusb_sources ├── libusb.dsw ├── config.h ├── missing.c ├── getopt_2010.vcxproj ├── getopt_2012.vcxproj ├── getopt_2013.vcxproj ├── getopt_2015.vcxproj ├── errno.h ├── xusb_2010.vcxproj ├── listdevs_2010.vcxproj ├── hotplugtest_2010.vcxproj ├── testlibusb_2010.vcxproj ├── xusb_2012.vcxproj ├── xusb_2013.vcxproj ├── xusb_2015.vcxproj ├── listdevs_2012.vcxproj ├── listdevs_2013.vcxproj ├── listdevs_2015.vcxproj ├── hotplugtest_2012.vcxproj ├── hotplugtest_2013.vcxproj ├── hotplugtest_2015.vcxproj ├── testlibusb_2012.vcxproj ├── testlibusb_2013.vcxproj ├── testlibusb_2015.vcxproj ├── stress_2010.vcxproj ├── stress_2012.vcxproj ├── stress_2013.vcxproj ├── stress_2015.vcxproj ├── fxload_2010.vcxproj ├── fxload_2012.vcxproj ├── fxload_2013.vcxproj └── fxload_2015.vcxproj ├── examples ├── Makefile.am ├── listdevs.c └── hotplugtest.c ├── Xcode ├── config.h ├── libusb_debug.xcconfig ├── libusb_release.xcconfig ├── libusb.xcconfig ├── debug.xcconfig ├── release.xcconfig └── common.xcconfig ├── Makefile.am ├── android ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── tests.mk │ ├── libusb.mk │ └── examples.mk └── config.h ├── README.md ├── README.git ├── AUTHORS └── PORTING /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /libusb/version_nano.h: -------------------------------------------------------------------------------- 1 | #define LIBUSB_NANO 11397 2 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | For the latest libusb news, please refer to the ChangeLog file, or visit: 2 | http://libusb.info 3 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if ! test -d m4 ; then 4 | mkdir m4 5 | fi 6 | autoreconf -ivf || exit 1 7 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Please see the libusb roadmap by visiting: 2 | https://github.com/libusb/libusb/milestones?direction=asc&sort=due_date&state=open 3 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | ./bootstrap.sh 6 | if test -z "$NOCONFIGURE"; then 7 | exec ./configure --enable-examples-build --enable-tests-build "$@" 8 | fi 9 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/libusb 2 | LDADD = ../libusb/libusb-1.0.la 3 | 4 | noinst_PROGRAMS = stress 5 | 6 | stress_SOURCES = stress.c libusb_testlib.h testlib.c 7 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = doxygen.cfg.in 2 | 3 | docs: doxygen.cfg 4 | doxygen $^ 5 | 6 | docs-upload: docs 7 | ln -s html api-1.0 8 | scp -r api-1.0 pbatard@web.sourceforge.net:/home/project-web/libusb/htdocs 9 | rm -f api-1.0 10 | -------------------------------------------------------------------------------- /libusb/os/poll_posix.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBUSB_POLL_POSIX_H 2 | #define LIBUSB_POLL_POSIX_H 3 | 4 | #define usbi_write write 5 | #define usbi_read read 6 | #define usbi_close close 7 | #define usbi_poll poll 8 | 9 | int usbi_pipe(int pipefd[2]); 10 | 11 | #define usbi_inc_fds_ref(x, y) 12 | #define usbi_dec_fds_ref(x, y) 13 | 14 | #endif /* LIBUSB_POLL_POSIX_H */ 15 | -------------------------------------------------------------------------------- /libusb-1.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libusb-1.0 7 | Description: C API for USB device access from Linux, Mac OS X, Windows, OpenBSD/NetBSD and Solaris userspace 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lusb-1.0 10 | Libs.private: @LIBS@ 11 | Cflags: -I${includedir}/libusb-1.0 12 | -------------------------------------------------------------------------------- /msvc/xusb_sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=xusb 2 | TARGETTYPE=PROGRAM 3 | 386_STDCALL=0 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | UMTYPE=console 18 | INCLUDES=..\..\msvc;..\..\libusb;$(DDK_INC_PATH) 19 | UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib 20 | SOURCES=..\xusb.c 21 | -------------------------------------------------------------------------------- /msvc/listdevs_sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=listdevs 2 | TARGETTYPE=PROGRAM 3 | 386_STDCALL=0 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | UMTYPE=console 18 | INCLUDES=..\..\libusb;$(DDK_INC_PATH) 19 | UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib 20 | SOURCES=..\listdevs.c 21 | -------------------------------------------------------------------------------- /msvc/testlibusb_sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=testlibusb 2 | TARGETTYPE=PROGRAM 3 | 386_STDCALL=0 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | UMTYPE=console 18 | INCLUDES=..\..\msvc;..\..\libusb;$(DDK_INC_PATH) 19 | UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib 20 | SOURCES=..\testlibusb.c 21 | -------------------------------------------------------------------------------- /msvc/hotplugtest_sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=hotplugtest 2 | TARGETTYPE=PROGRAM 3 | 386_STDCALL=0 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | UMTYPE=console 18 | INCLUDES=..\..\msvc;..\..\libusb;$(DDK_INC_PATH) 19 | UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib 20 | SOURCES=..\hotplugtest.c 21 | -------------------------------------------------------------------------------- /msvc/stress_sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=stress 2 | TARGETTYPE=PROGRAM 3 | 386_STDCALL=0 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | UMTYPE=console 18 | INCLUDES=..\..\msvc;..\..\libusb;$(DDK_INC_PATH) 19 | UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib 20 | SOURCES=..\stress.c \ 21 | ..\testlib.c 22 | -------------------------------------------------------------------------------- /libusb/version.h: -------------------------------------------------------------------------------- 1 | /* This file is parsed by m4 and windres and RC.EXE so please keep it simple. */ 2 | #include "version_nano.h" 3 | #ifndef LIBUSB_MAJOR 4 | #define LIBUSB_MAJOR 1 5 | #endif 6 | #ifndef LIBUSB_MINOR 7 | #define LIBUSB_MINOR 0 8 | #endif 9 | #ifndef LIBUSB_MICRO 10 | #define LIBUSB_MICRO 23 11 | #endif 12 | #ifndef LIBUSB_NANO 13 | #define LIBUSB_NANO 0 14 | #endif 15 | /* LIBUSB_RC is the release candidate suffix. Should normally be empty. */ 16 | #ifndef LIBUSB_RC 17 | #define LIBUSB_RC "" 18 | #endif 19 | -------------------------------------------------------------------------------- /msvc/getopt_sources: -------------------------------------------------------------------------------- 1 | TARGETTYPE=LIBRARY 2 | TARGETNAME=getopt 3 | 386_STDCALL=0 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | INCLUDES=$(DDK_INC_PATH) 18 | C_DEFINES=$(C_DEFINES) /DDDKBUILD /DHAVE_STRING_H 19 | 20 | TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \ 21 | $(SDK_LIB_PATH)\user32.lib 22 | 23 | SOURCES=..\getopt1.c \ 24 | ..\getopt.c 25 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/libusb 2 | LDADD = ../libusb/libusb-1.0.la 3 | 4 | noinst_PROGRAMS = listdevs xusb fxload hotplugtest testlibusb 5 | 6 | if HAVE_SIGACTION 7 | noinst_PROGRAMS += dpfp 8 | 9 | if THREADS_POSIX 10 | dpfp_threaded_CFLAGS = $(AM_CFLAGS) 11 | noinst_PROGRAMS += dpfp_threaded 12 | endif 13 | 14 | sam3u_benchmark_SOURCES = sam3u_benchmark.c 15 | noinst_PROGRAMS += sam3u_benchmark 16 | endif 17 | 18 | fxload_SOURCES = ezusb.c ezusb.h fxload.c 19 | fxload_CFLAGS = $(THREAD_CFLAGS) $(AM_CFLAGS) 20 | -------------------------------------------------------------------------------- /msvc/fxload_sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=fxload 2 | TARGETTYPE=PROGRAM 3 | 386_STDCALL=0 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | UMTYPE=console 18 | INCLUDES=..\..\msvc;..\..\libusb;..\getopt;$(DDK_INC_PATH) 19 | C_DEFINES=$(C_DEFINES) /D__GNU_LIBRARY__ 20 | UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib \ 21 | ..\getopt\getopt_ddkbuild\obj$(BUILD_ALT_DIR)\*\getopt.lib 22 | SOURCES=..\ezusb.c \ 23 | ..\fxload.c 24 | -------------------------------------------------------------------------------- /Xcode/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Manually generated for Xcode. */ 2 | 3 | /* Default visibility */ 4 | #define DEFAULT_VISIBILITY /**/ 5 | 6 | /* Message logging */ 7 | #define ENABLE_LOGGING 1 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #define HAVE_POLL_H 1 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #define HAVE_SYS_TIME_H 1 14 | 15 | /* Darwin backend */ 16 | #define OS_DARWIN 1 17 | 18 | /* type of second poll() argument */ 19 | #define POLL_NFDS_TYPE nfds_t 20 | 21 | /* Use POSIX Threads */ 22 | #define THREADS_POSIX 1 23 | 24 | /* Use GNU extensions */ 25 | #define _GNU_SOURCE 1 26 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = dist-bzip2 no-dist-gzip 2 | ACLOCAL_AMFLAGS = -I m4 3 | DISTCLEANFILES = libusb-1.0.pc 4 | EXTRA_DIST = TODO PORTING msvc libusb/libusb-1.0.def libusb/version_nano.h \ 5 | examples/getopt/getopt.c examples/getopt/getopt1.c examples/getopt/getopt.h \ 6 | android Xcode 7 | SUBDIRS = libusb doc 8 | 9 | if BUILD_EXAMPLES 10 | SUBDIRS += examples 11 | endif 12 | 13 | if BUILD_TESTS 14 | SUBDIRS += tests 15 | endif 16 | 17 | pkgconfigdir=$(libdir)/pkgconfig 18 | pkgconfig_DATA=libusb-1.0.pc 19 | 20 | .PHONY: dist-up 21 | 22 | reldir = .release/$(distdir) 23 | dist-up: dist 24 | rm -rf $(reldir) 25 | mkdir -p $(reldir) 26 | cp $(distdir).tar.bz2 $(reldir) 27 | rsync -rv $(reldir) frs.sourceforge.net:/home/frs/project/l/li/libusb/libusb-1.0/ 28 | rm -rf $(reldir) 29 | -------------------------------------------------------------------------------- /Xcode/libusb_debug.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // libusb Xcode configuration file 3 | // Copyright © 2012 Pete Batard 4 | // For more information, please visit: 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | // Lesser General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this library; if not, write to the Free Software 18 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | #include "debug.xcconfig" 21 | #include "libusb.xcconfig" 22 | -------------------------------------------------------------------------------- /Xcode/libusb_release.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // libusb Xcode configuration file 3 | // Copyright © 2012 Pete Batard 4 | // For more information, please visit: 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | // Lesser General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this library; if not, write to the Free Software 18 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | #include "release.xcconfig" 21 | #include "libusb.xcconfig" 22 | -------------------------------------------------------------------------------- /Xcode/libusb.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // libusb Xcode configuration file 3 | // Copyright © 2012 Pete Batard 4 | // For more information, please visit: 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | // Lesser General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this library; if not, write to the Free Software 18 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | PRODUCT_NAME = libusb-1.0.0 21 | LD_DYLIB_INSTALL_NAME = @rpath/libusb-1.0.0.dylib 22 | -------------------------------------------------------------------------------- /android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Android build config for libusb, examples and tests 2 | # Copyright © 2012-2013 RealVNC Ltd. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | 19 | LOCAL_PATH:= $(call my-dir) 20 | 21 | include $(LOCAL_PATH)/libusb.mk 22 | include $(LOCAL_PATH)/examples.mk 23 | include $(LOCAL_PATH)/tests.mk 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Non-rooted Android [LibUsb Manager](https://github.com/green-green-avk/LibUsbManager) support variant 2 | 3 | ***Deprecated*** 4 | 5 | Superseded by 6 | 7 | --- 8 | 9 | `--enable-android-helper=` option has been added into the `configure` script in order to provide USB access through Android API with help of **Another Term [Lite]** built-in service (so, no device rooting is required). 10 | 11 | See also: 12 | * [The server side source code (Another Term)](https://github.com/green-green-avk/LibUsbManager). 13 | * [The server side source code (Another Term Lite) *deprecated*](https://github.com/green-green-avk/AnotherTermLite/tree/master/libusbmanager). 14 | * [How to use (Another Term)](https://green-green-avk.github.io/AnotherTerm-docs/installing-libusb-for-nonrooted-android.html#main_content). 15 | * [How to use (Another Term Lite) *deprecated*](https://github.com/green-green-avk/AnotherTermLite/wiki/Installing-libusb-for-nonrooted-Android). 16 | 17 | Derived from: . 18 | -------------------------------------------------------------------------------- /android/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Android application build config for libusb 2 | # Copyright © 2012-2013 RealVNC Ltd. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | 19 | APP_ABI := all 20 | 21 | # Workaround for MIPS toolchain linker being unable to find liblog dependency 22 | # of shared object in NDK versions at least up to r9. 23 | # 24 | APP_LDFLAGS := -llog 25 | 26 | APP_BUILD_SCRIPT := ./Android.mk 27 | -------------------------------------------------------------------------------- /Xcode/debug.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // libusb Xcode configuration file 3 | // Copyright © 2012 Pete Batard 4 | // For more information, please visit: 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | // Lesser General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this library; if not, write to the Free Software 18 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | #include "common.xcconfig" 21 | 22 | // Embed debug symbols in binary itself. 23 | DEBUG_INFORMATION_FORMAT = dwarf 24 | 25 | // No optimizations in debug. 26 | GCC_OPTIMIZATION_LEVEL = 0 27 | 28 | // 29 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DEBUG=1 30 | -------------------------------------------------------------------------------- /msvc/missing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Header file for missing WinCE functionality 3 | * Copyright © 2012-2013 RealVNC Ltd. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef MISSING_H 21 | #define MISSING_H 22 | 23 | /* Windows CE doesn't have SleepEx() - Fallback to Sleep() */ 24 | #define SleepEx(m, a) Sleep(m) 25 | 26 | /* Windows CE doesn't have any APIs to query environment variables. 27 | * 28 | * This contains a registry based implementation of getenv. 29 | */ 30 | char *getenv(const char *name); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Xcode/release.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // libusb Xcode configuration file 3 | // Copyright © 2012 Pete Batard 4 | // For more information, please visit: 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | // Lesser General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this library; if not, write to the Free Software 18 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | #include "common.xcconfig" 21 | 22 | // Put debug symbols in separate .dym file. 23 | DEBUG_INFORMATION_FORMAT = dwarf-with-dsym 24 | 25 | // Optimizations in release. 26 | GCC_OPTIMIZATION_LEVEL = s 27 | LLVM_LTO = YES 28 | 29 | // Define NDEBUG so asserts go away in release. 30 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) NDEBUG=1 31 | -------------------------------------------------------------------------------- /msvc/appveyor.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | SetLocal EnableDelayedExpansion 3 | 4 | if [%Configuration%] NEQ [Debug] goto releasex64 5 | if [%Configuration%] NEQ [Release] goto debugx64 6 | 7 | :debugx64 8 | if [%Platform%] NEQ [x64] goto debugWin32 9 | if [%Configuration%] NEQ [Debug] exit 0 10 | call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Debug /x64 || exit /B 11 | msbuild %libusb_2010% /p:Configuration=Debug,Platform=x64 /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || exit /B 12 | 13 | :releasex64 14 | if [%Platform%] NEQ [x64] goto releaseWin32 15 | if [%Configuration%] NEQ [Release] exit 0 16 | call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x64 || exit /B 17 | msbuild %libusb_2010% /p:Configuration=Release,Platform=x64 /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || exit /B 18 | 19 | :debugWin32 20 | if [%Platform%] NEQ [Win32] exit 0 21 | if [%Configuration%] NEQ [Debug] exit 0 22 | msbuild %libusb_2010% /p:Configuration=Debug,Platform=Win32 /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || exit /B 23 | 24 | :releaseWin32 25 | if [%Platform%] NEQ [Win32] exit 0 26 | if [%Configuration%] NEQ [Release] exit 0 27 | msbuild %libusb_2010% /p:Configuration=Release,Platform=Win32 /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || exit /B 28 | -------------------------------------------------------------------------------- /msvc/libusb_sources: -------------------------------------------------------------------------------- 1 | #TARGETTYPE is not defined, to allow selection between static lib or DLL with ddk_build 2 | TARGETNAME=libusb-1.0 3 | DLLDEF=..\libusb-1.0.def 4 | 5 | _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) 6 | 7 | !IFNDEF MSC_WARNING_LEVEL 8 | MSC_WARNING_LEVEL=/W3 9 | !ENDIF 10 | 11 | !IFDEF STATIC_LIBC 12 | USE_LIBCMT=1 13 | !ELSE 14 | USE_MSVCRT=1 15 | !ENDIF 16 | 17 | INCLUDES=..;..\..\msvc;$(DDK_INC_PATH) 18 | C_DEFINES=$(C_DEFINES) $(LIBUSB_DEFINES) /DDDKBUILD 19 | 20 | # http://jpassing.com/2009/10/21/ltcg-issues-with-the-win7amd64-environment-of-wdk-7600/ 21 | # prevents the following error when using the 64 bit static lib with Visual Studio 2010: 22 | # "fatal error C1001: An internal error has occurred in the compiler. 23 | # (compiler file 'f:\dd\vctools\compiler\utc\src\p2\p2symtab.c', line 1823)" 24 | # and the following with Visual Studio 2010: 25 | # "fatal error C1047: The object or library file 'libusb-1.0.lib' was created with 26 | # an older compiler than other objects; rebuild old objects and libraries" 27 | USER_C_FLAGS=/GL- 28 | 29 | TARGETLIBS=$(SDK_LIB_PATH)\advapi32.lib \ 30 | $(SDK_LIB_PATH)\kernel32.lib 31 | 32 | SOURCES=..\core.c \ 33 | ..\descriptor.c \ 34 | ..\hotplug.c \ 35 | ..\io.c \ 36 | poll_windows.c \ 37 | ..\strerror.c \ 38 | ..\sync.c \ 39 | threads_windows.c \ 40 | windows_nt_common.c \ 41 | windows_usbdk.c \ 42 | windows_winusb.c \ 43 | ..\libusb-1.0.rc 44 | -------------------------------------------------------------------------------- /msvc/libusb.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "libusb_dll"=".\libusb_dll.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Project: "libusb_static"=".\libusb_static.dsp" - Package Owner=<4> 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<4> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | Project: "listdevs"=".\listdevs.dsp" - Package Owner=<4> 31 | 32 | Package=<5> 33 | {{{ 34 | }}} 35 | 36 | Package=<4> 37 | {{{ 38 | Begin Project Dependency 39 | Project_Dep_Name libusb_static 40 | End Project Dependency 41 | }}} 42 | 43 | ############################################################################### 44 | 45 | Project: "xusb"=".\xusb.dsp" - Package Owner=<4> 46 | 47 | Package=<5> 48 | {{{ 49 | }}} 50 | 51 | Package=<4> 52 | {{{ 53 | Begin Project Dependency 54 | Project_Dep_Name libusb_static 55 | End Project Dependency 56 | }}} 57 | 58 | ############################################################################### 59 | 60 | Global: 61 | 62 | Package=<5> 63 | {{{ 64 | }}} 65 | 66 | Package=<3> 67 | {{{ 68 | }}} 69 | 70 | ############################################################################### 71 | 72 | -------------------------------------------------------------------------------- /android/jni/tests.mk: -------------------------------------------------------------------------------- 1 | # Android build config for libusb tests 2 | # Copyright © 2012-2013 RealVNC Ltd. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | 19 | LOCAL_PATH:= $(call my-dir) 20 | LIBUSB_ROOT_REL:= ../.. 21 | LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../.. 22 | 23 | # testlib 24 | 25 | include $(CLEAR_VARS) 26 | 27 | LOCAL_SRC_FILES := \ 28 | $(LIBUSB_ROOT_REL)/tests/testlib.c 29 | 30 | LOCAL_C_INCLUDES += \ 31 | $(LIBUSB_ROOT_ABS)/tests 32 | 33 | LOCAL_EXPORT_C_INCLUDES := \ 34 | $(LIBUSB_ROOT_ABS)/tests 35 | 36 | LOCAL_MODULE := testlib 37 | 38 | include $(BUILD_STATIC_LIBRARY) 39 | 40 | 41 | # stress 42 | 43 | include $(CLEAR_VARS) 44 | 45 | LOCAL_SRC_FILES := \ 46 | $(LIBUSB_ROOT_REL)/tests/stress.c 47 | 48 | LOCAL_C_INCLUDES += \ 49 | $(LIBUSB_ROOT_ABS) 50 | 51 | LOCAL_SHARED_LIBRARIES += libusb1.0 52 | LOCAL_STATIC_LIBRARIES += testlib 53 | 54 | LOCAL_MODULE:= stress 55 | 56 | include $(BUILD_EXECUTABLE) 57 | -------------------------------------------------------------------------------- /msvc/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Manual config for MSVC. */ 2 | 3 | #ifndef _MSC_VER 4 | #warn "msvc/config.h shouldn't be included for your development environment." 5 | #error "Please make sure the msvc/ directory is removed from your build path." 6 | #endif 7 | 8 | /* Visual Studio 2015 and later defines timespec */ 9 | #if (_MSC_VER >= 1900) 10 | #define _TIMESPEC_DEFINED 1 11 | #endif 12 | 13 | /* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */ 14 | #pragma warning(disable:4200) 15 | /* Disable: warning C4324: structure was padded due to __declspec(align()) */ 16 | #pragma warning(disable:4324) 17 | /* Disable: warning C6258: Using TerminateThread does not allow proper thread clean up */ 18 | #pragma warning(disable:6258) 19 | /* Disable: warning C4996: 'GetVersionA': was declared deprecated */ 20 | #pragma warning(disable:4996) 21 | 22 | #if defined(_PREFAST_) 23 | /* Disable "Banned API" errors when using the MS's WDK OACR/Prefast */ 24 | #pragma warning(disable:28719) 25 | /* Disable "The function 'InitializeCriticalSection' must be called from within a try/except block" */ 26 | #pragma warning(disable:28125) 27 | #endif 28 | 29 | /* Default visibility */ 30 | #define DEFAULT_VISIBILITY /**/ 31 | 32 | /* Enable global message logging */ 33 | #define ENABLE_LOGGING 1 34 | 35 | /* Uncomment to start with debug message logging enabled */ 36 | // #define ENABLE_DEBUG_LOGGING 1 37 | 38 | /* Uncomment to enabling logging to system log */ 39 | // #define USE_SYSTEM_LOGGING_FACILITY 40 | 41 | /* type of second poll() argument */ 42 | #define POLL_NFDS_TYPE unsigned int 43 | 44 | /* Windows/WinCE backend */ 45 | #if defined(_WIN32_WCE) 46 | #define OS_WINCE 1 47 | #define HAVE_MISSING_H 48 | #else 49 | #define OS_WINDOWS 1 50 | #define HAVE_SYS_TYPES_H 1 51 | #endif 52 | -------------------------------------------------------------------------------- /android/jni/libusb.mk: -------------------------------------------------------------------------------- 1 | # Android build config for libusb 2 | # Copyright © 2012-2013 RealVNC Ltd. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | 19 | LOCAL_PATH:= $(call my-dir) 20 | LIBUSB_ROOT_REL:= ../.. 21 | LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../.. 22 | 23 | # libusb 24 | 25 | include $(CLEAR_VARS) 26 | 27 | LIBUSB_ROOT_REL:= ../.. 28 | LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../.. 29 | 30 | LOCAL_SRC_FILES := \ 31 | $(LIBUSB_ROOT_REL)/libusb/core.c \ 32 | $(LIBUSB_ROOT_REL)/libusb/descriptor.c \ 33 | $(LIBUSB_ROOT_REL)/libusb/hotplug.c \ 34 | $(LIBUSB_ROOT_REL)/libusb/io.c \ 35 | $(LIBUSB_ROOT_REL)/libusb/sync.c \ 36 | $(LIBUSB_ROOT_REL)/libusb/strerror.c \ 37 | $(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c \ 38 | $(LIBUSB_ROOT_REL)/libusb/os/poll_posix.c \ 39 | $(LIBUSB_ROOT_REL)/libusb/os/threads_posix.c \ 40 | $(LIBUSB_ROOT_REL)/libusb/os/linux_netlink.c 41 | 42 | LOCAL_C_INCLUDES += \ 43 | $(LOCAL_PATH)/.. \ 44 | $(LIBUSB_ROOT_ABS)/libusb \ 45 | $(LIBUSB_ROOT_ABS)/libusb/os 46 | 47 | LOCAL_EXPORT_C_INCLUDES := \ 48 | $(LIBUSB_ROOT_ABS)/libusb 49 | 50 | LOCAL_LDLIBS := -llog 51 | 52 | LOCAL_MODULE := libusb1.0 53 | 54 | include $(BUILD_SHARED_LIBRARY) 55 | -------------------------------------------------------------------------------- /README.git: -------------------------------------------------------------------------------- 1 | Notes related to git compilation: 2 | -------------------------------- 3 | 4 | If you retrieved the libusb repository from git and are using a gcc based 5 | toolchain, be mindful that you should have the autotools installed (autoconf, 6 | automake) and will need to run either ./autogen.sh or ./bootstrap.sh to produce 7 | the configure file. 8 | 9 | The difference between autogen.sh and bootstrap.sh is that the former invokes 10 | configure with a default set of options, and will therefore generate a Makefile, 11 | whereas the latter does not invoke configure at all. If using autogen.sh, note 12 | that you can also append options, that will be passed as is to configure. 13 | 14 | OS X-specific notes: 15 | ------------------- 16 | 17 | Starting with Xcode 4.3, neither Xcode.app nor the Xcode 'command line tools' 18 | includes autotools and so running either autogen.sh or bootstrap.sh will result 19 | in the message: 20 | 21 | libtoolize or glibtoolize was not found! Please install libtool. 22 | 23 | To proceed, you must find and install it from somewhere. 24 | 25 | Alternatively, you can use the Xcode project at Xcode/libusb.xcodeproj. 26 | 27 | Notes related to submitting new developments: 28 | -------------------------------------------- 29 | 30 | If you submit a new development to libusb (eg: new backend), that is unlikely 31 | to fit in a couple of small patches, we would kindly suggest that you create a 32 | public account on github, if you don't have one already, and then fork a new 33 | libusb repository under this account from https://github.com/libusb/libusb. 34 | 35 | Then you can create a git branch for your work, that we will be able to better 36 | reference and test. 37 | 38 | We also suggest that, if you are planning to bring in a large development, you 39 | try to involve the libusb community early by letting the mailing list know, as 40 | you may find that other people might be eager to help you out. 41 | See http://mailing-list.libusb.info for details on how to join the mailing list. -------------------------------------------------------------------------------- /libusb/libusb-1.0.rc: -------------------------------------------------------------------------------- 1 | /* 2 | * For Windows: input this file to the Resoure Compiler to produce a binary 3 | * .res file. This is then embedded in the resultant library (like any other 4 | * compilation object). 5 | * The information can then be queried using standard APIs and can also be 6 | * viewed with utilities such as Windows Explorer. 7 | */ 8 | #ifndef _WIN32_WCE 9 | #include "winresrc.h" 10 | #endif 11 | 12 | #include "version.h" 13 | #ifndef LIBUSB_VERSIONSTRING 14 | #define LU_STR(s) #s 15 | #define LU_XSTR(s) LU_STR(s) 16 | #if LIBUSB_NANO > 0 17 | #define LIBUSB_VERSIONSTRING \ 18 | LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \ 19 | LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO) LIBUSB_RC "\0" 20 | #else 21 | #define LIBUSB_VERSIONSTRING \ 22 | LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \ 23 | LU_XSTR(LIBUSB_MICRO) LIBUSB_RC "\0" 24 | #endif 25 | #endif 26 | 27 | VS_VERSION_INFO VERSIONINFO 28 | FILEVERSION LIBUSB_MAJOR,LIBUSB_MINOR,LIBUSB_MICRO,LIBUSB_NANO 29 | PRODUCTVERSION LIBUSB_MAJOR,LIBUSB_MINOR,LIBUSB_MICRO,LIBUSB_NANO 30 | FILEFLAGSMASK 0x3fL 31 | #ifdef _DEBUG 32 | FILEFLAGS 0x1L 33 | #else 34 | FILEFLAGS 0x0L 35 | #endif 36 | FILEOS 0x40004L 37 | FILETYPE 0x2L 38 | FILESUBTYPE 0x0L 39 | BEGIN 40 | BLOCK "StringFileInfo" 41 | BEGIN 42 | BLOCK "040904b0" 43 | BEGIN 44 | VALUE "CompanyName", "libusb.info\0" 45 | VALUE "FileDescription", "C library for writing portable USB drivers in userspace\0" 46 | VALUE "FileVersion", LIBUSB_VERSIONSTRING 47 | VALUE "InternalName", "libusb\0" 48 | VALUE "LegalCopyright", "See individual source files, GNU LGPL v2.1 or later.\0" 49 | VALUE "LegalTrademarks", "http://www.gnu.org/licenses/lgpl-2.1.html\0" 50 | VALUE "OriginalFilename", "libusb-1.0.dll\0" 51 | VALUE "PrivateBuild", "\0" 52 | VALUE "ProductName", "libusb-1.0\0" 53 | VALUE "ProductVersion", LIBUSB_VERSIONSTRING 54 | VALUE "SpecialBuild", "\0" 55 | END 56 | END 57 | BLOCK "VarFileInfo" 58 | BEGIN 59 | VALUE "Translation", 0x409, 1200 60 | END 61 | END 62 | -------------------------------------------------------------------------------- /examples/listdevs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb example program to list devices on the bus 3 | * Copyright © 2007 Daniel Drake 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include "libusb.h" 23 | 24 | static void print_devs(libusb_device **devs) 25 | { 26 | libusb_device *dev; 27 | int i = 0, j = 0; 28 | uint8_t path[8]; 29 | 30 | while ((dev = devs[i++]) != NULL) { 31 | struct libusb_device_descriptor desc; 32 | int r = libusb_get_device_descriptor(dev, &desc); 33 | if (r < 0) { 34 | fprintf(stderr, "failed to get device descriptor"); 35 | return; 36 | } 37 | 38 | printf("%04x:%04x (bus %d, device %d)", 39 | desc.idVendor, desc.idProduct, 40 | libusb_get_bus_number(dev), libusb_get_device_address(dev)); 41 | 42 | r = libusb_get_port_numbers(dev, path, sizeof(path)); 43 | if (r > 0) { 44 | printf(" path: %d", path[0]); 45 | for (j = 1; j < r; j++) 46 | printf(".%d", path[j]); 47 | } 48 | printf("\n"); 49 | } 50 | } 51 | 52 | int main(void) 53 | { 54 | libusb_device **devs; 55 | int r; 56 | ssize_t cnt; 57 | 58 | r = libusb_init(NULL); 59 | if (r < 0) 60 | return r; 61 | 62 | cnt = libusb_get_device_list(NULL, &devs); 63 | if (cnt < 0){ 64 | libusb_exit(NULL); 65 | return (int) cnt; 66 | } 67 | 68 | print_devs(devs); 69 | libusb_free_device_list(devs, 1); 70 | 71 | libusb_exit(NULL); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /Xcode/common.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // libusb Xcode configuration file 3 | // Copyright © 2012 Pete Batard 4 | // For more information, please visit: 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | // Lesser General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this library; if not, write to the Free Software 18 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | // libusb does not follow C99 strict aliasing rules, so disable it. 21 | GCC_STRICT_ALIASING = NO 22 | 23 | // Use C99 dialect. 24 | GCC_C_LANGUAGE_STANDARD = c99 25 | 26 | // Don't search user paths with <> style #includes. 27 | ALWAYS_SEARCH_USER_PATHS = NO 28 | 29 | // Compiler warnings. 30 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES 31 | GCC_WARN_ABOUT_RETURN_TYPE = YES 32 | GCC_WARN_UNINITIALIZED_AUTOS = YES 33 | GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES 34 | GCC_WARN_SHADOW = YES 35 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES 36 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES 37 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES 38 | GCC_WARN_ABOUT_MISSING_NEWLINE = YES 39 | GCC_WARN_UNKNOWN_PRAGMAS = YES 40 | GCC_WARN_UNUSED_FUNCTION = YES 41 | GCC_WARN_UNUSED_LABEL = YES 42 | GCC_WARN_UNUSED_VARIABLE = YES 43 | GCC_WARN_UNUSED_PARAMETER = YES 44 | CLANG_WARN_EMPTY_BODY = YES 45 | CLANG_WARN_CONSTANT_CONVERSION = YES 46 | CLANG_WARN_ENUM_CONVERSION = YES 47 | CLANG_WARN_INT_CONVERSION = YES 48 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES 49 | CLANG_WARN_BOOL_CONVERSION = YES 50 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES 51 | CLANG_WARN_FLOAT_CONVERSION = YES 52 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES 53 | CLANG_WARN_INFINITE_RECURSION = YES 54 | CLANG_WARN_ASSIGN_ENUM = YES 55 | CLANG_WARN_STRICT_PROTOTYPES = YES 56 | CLANG_WARN_COMMA = YES 57 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES 58 | 59 | // Static analyzer warnings. 60 | CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES 61 | CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES 62 | -------------------------------------------------------------------------------- /libusb/os/threads_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb synchronization using POSIX Threads 3 | * 4 | * Copyright © 2011 Vitali Lovich 5 | * Copyright © 2011 Peter Stuge 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | #if defined(__linux__) || defined(__OpenBSD__) 26 | # if defined(__OpenBSD__) 27 | # define _BSD_SOURCE 28 | # endif 29 | # include 30 | # include 31 | #elif defined(__APPLE__) 32 | # include 33 | #elif defined(__CYGWIN__) 34 | # include 35 | #endif 36 | 37 | #include "threads_posix.h" 38 | #include "libusbi.h" 39 | 40 | int usbi_cond_timedwait(pthread_cond_t *cond, 41 | pthread_mutex_t *mutex, const struct timeval *tv) 42 | { 43 | struct timespec timeout; 44 | int r; 45 | 46 | r = usbi_backend.clock_gettime(USBI_CLOCK_REALTIME, &timeout); 47 | if (r < 0) 48 | return r; 49 | 50 | timeout.tv_sec += tv->tv_sec; 51 | timeout.tv_nsec += tv->tv_usec * 1000; 52 | while (timeout.tv_nsec >= 1000000000L) { 53 | timeout.tv_nsec -= 1000000000L; 54 | timeout.tv_sec++; 55 | } 56 | 57 | return pthread_cond_timedwait(cond, mutex, &timeout); 58 | } 59 | 60 | int usbi_get_tid(void) 61 | { 62 | int ret; 63 | #if defined(__ANDROID__) 64 | ret = gettid(); 65 | #elif defined(__linux__) 66 | ret = syscall(SYS_gettid); 67 | #elif defined(__OpenBSD__) 68 | /* The following only works with OpenBSD > 5.1 as it requires 69 | real thread support. For 5.1 and earlier, -1 is returned. */ 70 | ret = syscall(SYS_getthrid); 71 | #elif defined(__APPLE__) 72 | ret = (int)pthread_mach_thread_np(pthread_self()); 73 | #elif defined(__CYGWIN__) 74 | ret = GetCurrentThreadId(); 75 | #else 76 | ret = -1; 77 | #endif 78 | /* TODO: NetBSD thread ID support */ 79 | return ret; 80 | } 81 | -------------------------------------------------------------------------------- /libusb/os/poll_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * poll_posix: poll compatibility wrapper for POSIX systems 3 | * Copyright © 2013 RealVNC Ltd. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "libusbi.h" 29 | 30 | int usbi_pipe(int pipefd[2]) 31 | { 32 | #if defined(HAVE_PIPE2) 33 | int ret = pipe2(pipefd, O_CLOEXEC); 34 | #else 35 | int ret = pipe(pipefd); 36 | #endif 37 | 38 | if (ret != 0) { 39 | usbi_err(NULL, "failed to create pipe (%d)", errno); 40 | return ret; 41 | } 42 | 43 | #if !defined(HAVE_PIPE2) && defined(FD_CLOEXEC) 44 | ret = fcntl(pipefd[0], F_GETFD); 45 | if (ret == -1) { 46 | usbi_err(NULL, "failed to get pipe fd flags (%d)", errno); 47 | goto err_close_pipe; 48 | } 49 | ret = fcntl(pipefd[0], F_SETFD, ret | FD_CLOEXEC); 50 | if (ret == -1) { 51 | usbi_err(NULL, "failed to set pipe fd flags (%d)", errno); 52 | goto err_close_pipe; 53 | } 54 | 55 | ret = fcntl(pipefd[1], F_GETFD); 56 | if (ret == -1) { 57 | usbi_err(NULL, "failed to get pipe fd flags (%d)", errno); 58 | goto err_close_pipe; 59 | } 60 | ret = fcntl(pipefd[1], F_SETFD, ret | FD_CLOEXEC); 61 | if (ret == -1) { 62 | usbi_err(NULL, "failed to set pipe fd flags (%d)", errno); 63 | goto err_close_pipe; 64 | } 65 | #endif 66 | 67 | ret = fcntl(pipefd[1], F_GETFL); 68 | if (ret == -1) { 69 | usbi_err(NULL, "failed to get pipe fd status flags (%d)", errno); 70 | goto err_close_pipe; 71 | } 72 | ret = fcntl(pipefd[1], F_SETFL, ret | O_NONBLOCK); 73 | if (ret == -1) { 74 | usbi_err(NULL, "failed to set pipe fd status flags (%d)", errno); 75 | goto err_close_pipe; 76 | } 77 | 78 | return 0; 79 | 80 | err_close_pipe: 81 | close(pipefd[0]); 82 | close(pipefd[1]); 83 | return ret; 84 | } 85 | -------------------------------------------------------------------------------- /libusb/os/sunos_usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016, Oracle and/or its affiliates. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef LIBUSB_SUNOS_H 21 | #define LIBUSB_SUNOS_H 22 | 23 | #include 24 | #include 25 | #include "libusbi.h" 26 | 27 | #define READ 0 28 | #define WRITE 1 29 | 30 | typedef struct sunos_device_priv { 31 | uint8_t cfgvalue; /* active config value */ 32 | uint8_t *raw_cfgdescr; /* active config descriptor */ 33 | struct libusb_device_descriptor dev_descr; /* usb device descriptor */ 34 | char *ugenpath; /* name of the ugen(4) node */ 35 | char *phypath; /* physical path */ 36 | } sunos_dev_priv_t; 37 | 38 | typedef struct endpoint { 39 | int datafd; /* data file */ 40 | int statfd; /* state file */ 41 | } sunos_ep_priv_t; 42 | 43 | typedef struct sunos_device_handle_priv { 44 | uint8_t altsetting[USB_MAXINTERFACES]; /* a interface's alt */ 45 | uint8_t config_index; 46 | sunos_ep_priv_t eps[USB_MAXENDPOINTS]; 47 | sunos_dev_priv_t *dpriv; /* device private */ 48 | } sunos_dev_handle_priv_t; 49 | 50 | typedef struct sunos_transfer_priv { 51 | struct aiocb aiocb; 52 | struct libusb_transfer *transfer; 53 | } sunos_xfer_priv_t; 54 | 55 | struct node_args { 56 | struct libusb_context *ctx; 57 | struct discovered_devs **discdevs; 58 | const char *last_ugenpath; 59 | di_devlink_handle_t dlink_hdl; 60 | }; 61 | 62 | struct devlink_cbarg { 63 | struct node_args *nargs; /* di node walk arguments */ 64 | di_node_t myself; /* the di node */ 65 | di_minor_t minor; 66 | }; 67 | 68 | typedef struct walk_link { 69 | char *path; 70 | int len; 71 | char **linkpp; 72 | } walk_link_t; 73 | 74 | /* AIO callback args */ 75 | struct aio_callback_args{ 76 | struct libusb_transfer *transfer; 77 | struct aiocb aiocb; 78 | }; 79 | 80 | #endif /* LIBUSB_SUNOS_H */ 81 | -------------------------------------------------------------------------------- /android/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Android build config for libusb 3 | * Copyright © 2012-2013 RealVNC Ltd. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /* Start with debug message logging enabled */ 21 | /* #undef ENABLE_DEBUG_LOGGING */ 22 | 23 | /* Message logging */ 24 | #define ENABLE_LOGGING 25 | 26 | /* Define to 1 if you have the header file. */ 27 | #define HAVE_DLFCN_H 1 28 | 29 | /* Define to 1 if you have the header file. */ 30 | #define HAVE_INTTYPES_H 1 31 | 32 | /* Linux backend */ 33 | #define OS_LINUX 1 34 | 35 | /* Enable output to system log */ 36 | #define USE_SYSTEM_LOGGING_FACILITY 1 37 | 38 | /* type of second poll() argument */ 39 | #define POLL_NFDS_TYPE nfds_t 40 | 41 | /* Use POSIX Threads */ 42 | #define THREADS_POSIX 1 43 | 44 | /* Default visibility */ 45 | #define DEFAULT_VISIBILITY __attribute__((visibility("default"))) 46 | 47 | /* Define to 1 if you have the header file. */ 48 | #define HAVE_MEMORY_H 1 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #define HAVE_POLL_H 1 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #define HAVE_SYS_STAT_H 1 55 | 56 | /* Define to 1 if you have the header file. */ 57 | #define HAVE_SYS_TIME_H 1 58 | 59 | /* Define to 1 if you have the header file. */ 60 | #define HAVE_SYS_TYPES_H 1 61 | 62 | /* Define to 1 if you have the header file. */ 63 | #define HAVE_UNISTD_H 1 64 | 65 | /* Define to 1 if you have the header file. */ 66 | #define HAVE_LINUX_FILTER_H 1 67 | 68 | /* Define to 1 if you have the header file. */ 69 | #define HAVE_LINUX_NETLINK_H 1 70 | 71 | /* Define to 1 if you have the header file. */ 72 | #define HAVE_ASM_TYPES_H 1 73 | 74 | /* Define to 1 if you have the header file. */ 75 | #define HAVE_SYS_SOCKET_H 1 76 | -------------------------------------------------------------------------------- /msvc/missing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Source file for missing WinCE functionality 3 | * Copyright © 2012 RealVNC Ltd. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "missing.h" 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | // The registry path to store environment variables 28 | #define ENVIRONMENT_REG_PATH _T("Software\\libusb\\environment") 29 | 30 | /* Workaround getenv not being available on WinCE. 31 | * Instead look in HKLM\Software\libusb\environment */ 32 | char *getenv(const char *name) 33 | { 34 | static char value[MAX_PATH]; 35 | TCHAR wValue[MAX_PATH]; 36 | WCHAR wName[MAX_PATH]; 37 | DWORD dwType, dwData; 38 | HKEY hkey; 39 | LONG rc; 40 | 41 | if (!name) 42 | return NULL; 43 | 44 | if (MultiByteToWideChar(CP_UTF8, 0, name, -1, wName, MAX_PATH) <= 0) { 45 | usbi_dbg("Failed to convert environment variable name to wide string"); 46 | return NULL; 47 | } 48 | wName[MAX_PATH - 1] = 0; // Be sure it's NUL terminated 49 | 50 | rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ENVIRONMENT_REG_PATH, 0, KEY_QUERY_VALUE, &hkey); 51 | if (rc != ERROR_SUCCESS) { 52 | usbi_dbg("Failed to open registry key for getenv with error %d", rc); 53 | return NULL; 54 | } 55 | 56 | // Attempt to read the key 57 | dwData = sizeof(wValue); 58 | rc = RegQueryValueEx(hkey, wName, NULL, &dwType, 59 | (LPBYTE)&wValue, &dwData); 60 | RegCloseKey(hkey); 61 | if (rc != ERROR_SUCCESS) { 62 | usbi_dbg("Failed to read registry key value for getenv with error %d", rc); 63 | return NULL; 64 | } 65 | if (dwType != REG_SZ) { 66 | usbi_dbg("Registry value was of type %d instead of REG_SZ", dwType); 67 | return NULL; 68 | } 69 | 70 | // Success in reading the key, convert from WCHAR to char 71 | if (WideCharToMultiByte(CP_UTF8, 0, 72 | wValue, dwData / sizeof(*wValue), 73 | value, MAX_PATH, 74 | NULL, NULL) <= 0) { 75 | usbi_dbg("Failed to convert environment variable value to narrow string"); 76 | return NULL; 77 | } 78 | value[MAX_PATH - 1] = 0; // Be sure it's NUL terminated 79 | return value; 80 | } 81 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Copyright © 2001 Johannes Erdfelt 2 | Copyright © 2007-2009 Daniel Drake 3 | Copyright © 2010-2012 Peter Stuge 4 | Copyright © 2008-2016 Nathan Hjelm 5 | Copyright © 2009-2013 Pete Batard 6 | Copyright © 2009-2013 Ludovic Rousseau 7 | Copyright © 2010-2012 Michael Plante 8 | Copyright © 2011-2013 Hans de Goede 9 | Copyright © 2012-2013 Martin Pieuchot 10 | Copyright © 2012-2013 Toby Gray 11 | Copyright © 2013-2018 Chris Dickens 12 | 13 | Other contributors: 14 | Adrian Bunk 15 | Akshay Jaggi 16 | Alan Ott 17 | Alan Stern 18 | Alex Vatchenko 19 | Andrew Fernandes 20 | Andy Chunyu 21 | Andy McFadden 22 | Angus Gratton 23 | Anil Nair 24 | Anthony Clay 25 | Antonio Ospite 26 | Artem Egorkine 27 | Aurelien Jarno 28 | Bastien Nocera 29 | Bei Zhang 30 | Benjamin Dobell 31 | Brent Rector 32 | Carl Karsten 33 | Christophe Zeitouny 34 | Colin Walters 35 | Dave Camarillo 36 | David Engraf 37 | David Moore 38 | Davidlohr Bueso 39 | Dmitry Fleytman 40 | Doug Johnston 41 | Evan Hunter 42 | Federico Manzan 43 | Felipe Balbi 44 | Florian Albrechtskirchinger 45 | Francesco Montorsi 46 | Francisco Facioni 47 | Gaurav Gupta 48 | Graeme Gill 49 | Gustavo Zacarias 50 | Hans Ulrich Niedermann 51 | Hector Martin 52 | Hoi-Ho Chan 53 | Ilya Konstantinov 54 | Jakub Klama 55 | James Hanko 56 | Jeffrey Nichols 57 | Johann Richard 58 | John Sheu 59 | Jonathon Jongsma 60 | Joost Muller 61 | Josh Gao 62 | Joshua Blake 63 | Justin Bischoff 64 | KIMURA Masaru 65 | Karsten Koenig 66 | Konrad Rzepecki 67 | Kuangye Guo 68 | Lars Kanis 69 | Lars Wirzenius 70 | Lei Chen 71 | Luca Longinotti 72 | Marcus Meissner 73 | Markus Heidelberg 74 | Martin Ettl 75 | Martin Koegler 76 | Matthew Stapleton 77 | Matthias Bolte 78 | Michel Zou 79 | Mike Frysinger 80 | Mikhail Gusarov 81 | Morgan Leborgne 82 | Moritz Fischer 83 | Ларионов Даниил 84 | Nicholas Corgan 85 | Omri Iluz 86 | Orin Eman 87 | Paul Fertser 88 | Pekka Nikander 89 | Rob Walker 90 | Romain Vimont 91 | Roman Kalashnikov 92 | Sameeh Jubran 93 | Sean McBride 94 | Sebastian Pipping 95 | Sergey Serb 96 | Simon Haggett 97 | Simon Newton 98 | Stefan Agner 99 | Stefan Tauner 100 | Steinar H. Gunderson 101 | Thomas Röfer 102 | Tim Hutt 103 | Tim Roberts 104 | Tobias Klauser 105 | Toby Peterson 106 | Tormod Volden 107 | Trygve Laugstøl 108 | Uri Lublin 109 | Vasily Khoruzhick 110 | Vegard Storheil Eriksen 111 | Venkatesh Shukla 112 | Vianney le Clément de Saint-Marcq 113 | Victor Toso 114 | Vitali Lovich 115 | William Skellenger 116 | Xiaofan Chen 117 | Zoltán Kovács 118 | Роман Донченко 119 | parafin 120 | -------------------------------------------------------------------------------- /libusb/os/windows_usbdk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * windows UsbDk backend for libusb 1.0 3 | * Copyright © 2014 Red Hat, Inc. 4 | 5 | * Authors: 6 | * Dmitry Fleytman 7 | * Pavel Gurvich 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "windows_nt_common.h" 27 | 28 | typedef struct USB_DK_CONFIG_DESCRIPTOR_REQUEST { 29 | USB_DK_DEVICE_ID ID; 30 | ULONG64 Index; 31 | } USB_DK_CONFIG_DESCRIPTOR_REQUEST, *PUSB_DK_CONFIG_DESCRIPTOR_REQUEST; 32 | 33 | typedef enum { 34 | TransferFailure = 0, 35 | TransferSuccess, 36 | TransferSuccessAsync 37 | } TransferResult; 38 | 39 | typedef enum { 40 | NoSpeed = 0, 41 | LowSpeed, 42 | FullSpeed, 43 | HighSpeed, 44 | SuperSpeed 45 | } USB_DK_DEVICE_SPEED; 46 | 47 | typedef enum { 48 | ControlTransferType, 49 | BulkTransferType, 50 | InterruptTransferType, 51 | IsochronousTransferType 52 | } USB_DK_TRANSFER_TYPE; 53 | 54 | typedef BOOL (__cdecl *USBDK_GET_DEVICES_LIST)( 55 | PUSB_DK_DEVICE_INFO *DeviceInfo, 56 | PULONG DeviceNumber 57 | ); 58 | typedef void (__cdecl *USBDK_RELEASE_DEVICES_LIST)( 59 | PUSB_DK_DEVICE_INFO DeviceInfo 60 | ); 61 | typedef HANDLE (__cdecl *USBDK_START_REDIRECT)( 62 | PUSB_DK_DEVICE_ID DeviceId 63 | ); 64 | typedef BOOL (__cdecl *USBDK_STOP_REDIRECT)( 65 | HANDLE DeviceHandle 66 | ); 67 | typedef BOOL (__cdecl *USBDK_GET_CONFIGURATION_DESCRIPTOR)( 68 | PUSB_DK_CONFIG_DESCRIPTOR_REQUEST Request, 69 | PUSB_CONFIGURATION_DESCRIPTOR *Descriptor, 70 | PULONG Length 71 | ); 72 | typedef void (__cdecl *USBDK_RELEASE_CONFIGURATION_DESCRIPTOR)( 73 | PUSB_CONFIGURATION_DESCRIPTOR Descriptor 74 | ); 75 | typedef TransferResult (__cdecl *USBDK_WRITE_PIPE)( 76 | HANDLE DeviceHandle, 77 | PUSB_DK_TRANSFER_REQUEST Request, 78 | LPOVERLAPPED lpOverlapped 79 | ); 80 | typedef TransferResult (__cdecl *USBDK_READ_PIPE)( 81 | HANDLE DeviceHandle, 82 | PUSB_DK_TRANSFER_REQUEST Request, 83 | LPOVERLAPPED lpOverlapped 84 | ); 85 | typedef BOOL (__cdecl *USBDK_ABORT_PIPE)( 86 | HANDLE DeviceHandle, 87 | ULONG64 PipeAddress 88 | ); 89 | typedef BOOL (__cdecl *USBDK_RESET_PIPE)( 90 | HANDLE DeviceHandle, 91 | ULONG64 PipeAddress 92 | ); 93 | typedef BOOL (__cdecl *USBDK_SET_ALTSETTING)( 94 | HANDLE DeviceHandle, 95 | ULONG64 InterfaceIdx, 96 | ULONG64 AltSettingIdx 97 | ); 98 | typedef BOOL (__cdecl *USBDK_RESET_DEVICE)( 99 | HANDLE DeviceHandle 100 | ); 101 | typedef HANDLE (__cdecl *USBDK_GET_REDIRECTOR_SYSTEM_HANDLE)( 102 | HANDLE DeviceHandle 103 | ); 104 | -------------------------------------------------------------------------------- /android/jni/examples.mk: -------------------------------------------------------------------------------- 1 | # Android build config for libusb examples 2 | # Copyright © 2012-2013 RealVNC Ltd. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | 19 | LOCAL_PATH:= $(call my-dir) 20 | LIBUSB_ROOT_REL:= ../.. 21 | LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../.. 22 | 23 | # listdevs 24 | 25 | include $(CLEAR_VARS) 26 | 27 | LOCAL_SRC_FILES := \ 28 | $(LIBUSB_ROOT_REL)/examples/listdevs.c 29 | 30 | LOCAL_C_INCLUDES += \ 31 | $(LIBUSB_ROOT_ABS) 32 | 33 | LOCAL_SHARED_LIBRARIES += libusb1.0 34 | 35 | LOCAL_MODULE:= listdevs 36 | 37 | include $(BUILD_EXECUTABLE) 38 | 39 | # xusb 40 | 41 | include $(CLEAR_VARS) 42 | 43 | LOCAL_SRC_FILES := \ 44 | $(LIBUSB_ROOT_REL)/examples/xusb.c 45 | 46 | LOCAL_C_INCLUDES += \ 47 | $(LIBUSB_ROOT_ABS) 48 | 49 | LOCAL_SHARED_LIBRARIES += libusb1.0 50 | 51 | LOCAL_MODULE:= xusb 52 | 53 | include $(BUILD_EXECUTABLE) 54 | 55 | # hotplugtest 56 | 57 | include $(CLEAR_VARS) 58 | 59 | LOCAL_SRC_FILES := \ 60 | $(LIBUSB_ROOT_REL)/examples/hotplugtest.c 61 | 62 | LOCAL_C_INCLUDES += \ 63 | $(LIBUSB_ROOT_ABS) 64 | 65 | LOCAL_SHARED_LIBRARIES += libusb1.0 66 | 67 | LOCAL_MODULE:= hotplugtest 68 | 69 | include $(BUILD_EXECUTABLE) 70 | 71 | # fxload 72 | 73 | include $(CLEAR_VARS) 74 | 75 | LOCAL_SRC_FILES := \ 76 | $(LIBUSB_ROOT_REL)/examples/fxload.c \ 77 | $(LIBUSB_ROOT_REL)/examples/ezusb.c 78 | 79 | LOCAL_C_INCLUDES += \ 80 | $(LIBUSB_ROOT_ABS) 81 | 82 | LOCAL_SHARED_LIBRARIES += libusb1.0 83 | 84 | LOCAL_MODULE:= fxload 85 | 86 | include $(BUILD_EXECUTABLE) 87 | 88 | # sam3u_benchmake 89 | 90 | include $(CLEAR_VARS) 91 | 92 | LOCAL_SRC_FILES := \ 93 | $(LIBUSB_ROOT_REL)/examples/sam3u_benchmark.c 94 | 95 | LOCAL_C_INCLUDES += \ 96 | $(LIBUSB_ROOT_ABS) 97 | 98 | LOCAL_SHARED_LIBRARIES += libusb1.0 99 | 100 | LOCAL_MODULE:= sam3u_benchmark 101 | 102 | include $(BUILD_EXECUTABLE) 103 | 104 | # dpfp 105 | 106 | include $(CLEAR_VARS) 107 | 108 | LOCAL_SRC_FILES := \ 109 | $(LIBUSB_ROOT_REL)/examples/dpfp.c 110 | 111 | LOCAL_C_INCLUDES += \ 112 | $(LIBUSB_ROOT_ABS) 113 | 114 | LOCAL_SHARED_LIBRARIES += libusb1.0 115 | 116 | LOCAL_MODULE:= dpfp 117 | 118 | include $(BUILD_EXECUTABLE) 119 | 120 | # dpfp_threaded 121 | 122 | include $(CLEAR_VARS) 123 | 124 | LOCAL_SRC_FILES := \ 125 | $(LIBUSB_ROOT_REL)/examples/dpfp_threaded.c 126 | 127 | LOCAL_C_INCLUDES += \ 128 | $(LIBUSB_ROOT_ABS) 129 | 130 | LOCAL_SHARED_LIBRARIES += libusb1.0 131 | 132 | LOCAL_MODULE:= dpfp_threaded 133 | 134 | include $(BUILD_EXECUTABLE) 135 | -------------------------------------------------------------------------------- /libusb/Makefile.am: -------------------------------------------------------------------------------- 1 | all: libusb-1.0.la libusb-1.0.dll 2 | 3 | AUTOMAKE_OPTIONS = subdir-objects 4 | 5 | lib_LTLIBRARIES = libusb-1.0.la 6 | 7 | POSIX_POLL_SRC = os/poll_posix.h os/poll_posix.c 8 | POSIX_THREADS_SRC = os/threads_posix.h os/threads_posix.c 9 | WINDOWS_POLL_SRC = os/poll_windows.h os/poll_windows.c 10 | WINDOWS_THREADS_SRC = os/threads_windows.h os/threads_windows.c 11 | LINUX_USBFS_SRC = os/linux_usbfs.h os/linux_usbfs.c 12 | DARWIN_USB_SRC = os/darwin_usb.h os/darwin_usb.c 13 | OPENBSD_USB_SRC = os/openbsd_usb.c 14 | NETBSD_USB_SRC = os/netbsd_usb.c 15 | SUNOS_USB_SRC = os/sunos_usb.c os/sunos_usb.h 16 | WINDOWS_USB_SRC = libusb-1.0.def libusb-1.0.rc \ 17 | os/windows_common.h \ 18 | os/windows_nt_common.h os/windows_nt_common.c \ 19 | os/windows_nt_shared_types.h \ 20 | os/windows_usbdk.h os/windows_usbdk.c \ 21 | os/windows_winusb.h os/windows_winusb.c 22 | WINCE_USB_SRC = os/wince_usb.h os/wince_usb.c 23 | HAIKU_USB_SRC = os/haiku_usb.h os/haiku_usb_backend.cpp \ 24 | os/haiku_usb_raw.h os/haiku_usb_raw.cpp os/haiku_pollfs.cpp 25 | 26 | EXTRA_DIST = $(POSIX_POLL_SRC) $(POSIX_THREADS_SRC) \ 27 | $(WINDOWS_POLL_SRC) $(WINDOWS_THREADS_SRC) \ 28 | $(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) \ 29 | $(OPENBSD_USB_SRC) $(NETBSD_USB_SRC) \ 30 | $(WINDOWS_USB_SRC) $(WINCE_USB_SRC) \ 31 | $(HAIKU_USB_SRC) \ 32 | os/linux_udev.c os/linux_netlink.c 33 | 34 | if OS_LINUX 35 | 36 | if USE_ANDROID_LIBUSB_HELPER 37 | OS_SRC = $(LINUX_USBFS_SRC) os/linux_android_helper.c 38 | else 39 | if USE_UDEV 40 | OS_SRC = $(LINUX_USBFS_SRC) os/linux_udev.c 41 | else 42 | OS_SRC = $(LINUX_USBFS_SRC) os/linux_netlink.c 43 | endif 44 | endif 45 | 46 | endif 47 | 48 | if OS_DARWIN 49 | OS_SRC = $(DARWIN_USB_SRC) 50 | AM_CFLAGS_EXT = -no-cpp-precomp 51 | endif 52 | 53 | if OS_OPENBSD 54 | OS_SRC = $(OPENBSD_USB_SRC) 55 | endif 56 | 57 | if OS_NETBSD 58 | OS_SRC = $(NETBSD_USB_SRC) 59 | endif 60 | 61 | if OS_SUNOS 62 | OS_SRC = $(SUNOS_USB_SRC) 63 | endif 64 | 65 | if OS_HAIKU 66 | noinst_LTLIBRARIES = libusb_haiku.la 67 | libusb_haiku_la_SOURCES = $(HAIKU_USB_SRC) 68 | libusb_1_0_la_LIBADD = libusb_haiku.la 69 | endif 70 | 71 | if OS_WINDOWS 72 | OS_SRC = $(WINDOWS_USB_SRC) 73 | 74 | .rc.lo: 75 | $(AM_V_GEN)$(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) -i $< -o $@ 76 | 77 | libusb-1.0.rc: version.h version_nano.h 78 | endif 79 | 80 | libusb-1.0.dll: libusb-1.0.def libusb-1.0.la 81 | if CREATE_IMPORT_LIB 82 | # Rebuild the import lib from the .def so that MS and MinGW DLLs can be interchanged 83 | $(AM_V_GEN)$(DLLTOOL) $(DLLTOOLFLAGS) --kill-at --input-def $(srcdir)/libusb-1.0.def --dllname $@ --output-lib .libs/$@.a 84 | endif 85 | 86 | if OS_WINDOWS 87 | POLL_SRC = $(WINDOWS_POLL_SRC) 88 | else 89 | POLL_SRC = $(POSIX_POLL_SRC) 90 | endif 91 | 92 | if THREADS_POSIX 93 | THREADS_SRC = $(POSIX_THREADS_SRC) 94 | else 95 | THREADS_SRC = $(WINDOWS_THREADS_SRC) 96 | endif 97 | 98 | libusb_1_0_la_CFLAGS = $(AM_CFLAGS) 99 | libusb_1_0_la_LDFLAGS = $(LTLDFLAGS) 100 | libusb_1_0_la_SOURCES = libusbi.h libusb.h version.h version_nano.h \ 101 | core.c descriptor.c hotplug.h hotplug.c io.c strerror.c sync.c \ 102 | $(POLL_SRC) $(THREADS_SRC) $(OS_SRC) 103 | 104 | hdrdir = $(includedir)/libusb-1.0 105 | hdr_HEADERS = libusb.h 106 | -------------------------------------------------------------------------------- /libusb/os/threads_posix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb synchronization using POSIX Threads 3 | * 4 | * Copyright © 2010 Peter Stuge 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef LIBUSB_THREADS_POSIX_H 22 | #define LIBUSB_THREADS_POSIX_H 23 | 24 | #include 25 | #ifdef HAVE_SYS_TIME_H 26 | #include 27 | #endif 28 | 29 | #define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER 30 | typedef pthread_mutex_t usbi_mutex_static_t; 31 | static inline void usbi_mutex_static_lock(usbi_mutex_static_t *mutex) 32 | { 33 | (void)pthread_mutex_lock(mutex); 34 | } 35 | static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex) 36 | { 37 | (void)pthread_mutex_unlock(mutex); 38 | } 39 | 40 | typedef pthread_mutex_t usbi_mutex_t; 41 | static inline int usbi_mutex_init(usbi_mutex_t *mutex) 42 | { 43 | return pthread_mutex_init(mutex, NULL); 44 | } 45 | static inline void usbi_mutex_lock(usbi_mutex_t *mutex) 46 | { 47 | (void)pthread_mutex_lock(mutex); 48 | } 49 | static inline void usbi_mutex_unlock(usbi_mutex_t *mutex) 50 | { 51 | (void)pthread_mutex_unlock(mutex); 52 | } 53 | static inline int usbi_mutex_trylock(usbi_mutex_t *mutex) 54 | { 55 | return pthread_mutex_trylock(mutex); 56 | } 57 | static inline void usbi_mutex_destroy(usbi_mutex_t *mutex) 58 | { 59 | (void)pthread_mutex_destroy(mutex); 60 | } 61 | 62 | typedef pthread_cond_t usbi_cond_t; 63 | static inline void usbi_cond_init(pthread_cond_t *cond) 64 | { 65 | (void)pthread_cond_init(cond, NULL); 66 | } 67 | static inline int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex) 68 | { 69 | return pthread_cond_wait(cond, mutex); 70 | } 71 | int usbi_cond_timedwait(usbi_cond_t *cond, 72 | usbi_mutex_t *mutex, const struct timeval *tv); 73 | static inline void usbi_cond_broadcast(usbi_cond_t *cond) 74 | { 75 | (void)pthread_cond_broadcast(cond); 76 | } 77 | static inline void usbi_cond_destroy(usbi_cond_t *cond) 78 | { 79 | (void)pthread_cond_destroy(cond); 80 | } 81 | 82 | typedef pthread_key_t usbi_tls_key_t; 83 | static inline void usbi_tls_key_create(usbi_tls_key_t *key) 84 | { 85 | (void)pthread_key_create(key, NULL); 86 | } 87 | static inline void *usbi_tls_key_get(usbi_tls_key_t key) 88 | { 89 | return pthread_getspecific(key); 90 | } 91 | static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr) 92 | { 93 | (void)pthread_setspecific(key, ptr); 94 | } 95 | static inline void usbi_tls_key_delete(usbi_tls_key_t key) 96 | { 97 | (void)pthread_key_delete(key); 98 | } 99 | 100 | int usbi_get_tid(void); 101 | 102 | #endif /* LIBUSB_THREADS_POSIX_H */ 103 | -------------------------------------------------------------------------------- /tests/libusb_testlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb test library helper functions 3 | * Copyright © 2012 Toby Gray 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef LIBUSB_TESTLIB_H 21 | #define LIBUSB_TESTLIB_H 22 | 23 | #include 24 | 25 | #if !defined(bool) 26 | #define bool int 27 | #endif 28 | #if !defined(true) 29 | #define true (1 == 1) 30 | #endif 31 | #if !defined(false) 32 | #define false (!true) 33 | #endif 34 | 35 | /** Values returned from a test function to indicate test result */ 36 | typedef enum { 37 | /** Indicates that the test ran successfully. */ 38 | TEST_STATUS_SUCCESS, 39 | /** Indicates that the test failed one or more test. */ 40 | TEST_STATUS_FAILURE, 41 | /** Indicates that an unexpected error occurred. */ 42 | TEST_STATUS_ERROR, 43 | /** Indicates that the test can't be run. For example this may be 44 | * due to no suitable device being connected to perform the tests.*/ 45 | TEST_STATUS_SKIP 46 | } libusb_testlib_result; 47 | 48 | /** 49 | * Context for test library functions 50 | */ 51 | typedef struct { 52 | char ** test_names; 53 | int test_count; 54 | bool list_tests; 55 | bool verbose; 56 | int old_stdout; 57 | int old_stderr; 58 | FILE* output_file; 59 | int null_fd; 60 | } libusb_testlib_ctx; 61 | 62 | /** 63 | * Logs some test information or state 64 | */ 65 | void libusb_testlib_logf(libusb_testlib_ctx * ctx, 66 | const char* fmt, ...); 67 | 68 | /** 69 | * Function pointer for a libusb test function. 70 | * 71 | * Should return TEST_STATUS_SUCCESS on success or another TEST_STATUS value. 72 | */ 73 | typedef libusb_testlib_result 74 | (*libusb_testlib_test_function)(libusb_testlib_ctx * ctx); 75 | 76 | /** 77 | * Structure holding a test description. 78 | */ 79 | typedef struct { 80 | /** Human readable name of the test. */ 81 | const char * name; 82 | /** The test library will call this function to run the test. */ 83 | libusb_testlib_test_function function; 84 | } libusb_testlib_test; 85 | 86 | /** 87 | * Value to use at the end of a test array to indicate the last 88 | * element. 89 | */ 90 | #define LIBUSB_NULL_TEST {NULL, NULL} 91 | 92 | /** 93 | * Runs the tests provided. 94 | * 95 | * Before running any tests argc and argv will be processed 96 | * to determine the mode of operation. 97 | * 98 | * \param argc The argc from main 99 | * \param argv The argv from main 100 | * \param tests A NULL_TEST terminated array of tests 101 | * \return 0 on success, non-zero on failure 102 | */ 103 | int libusb_testlib_run_tests(int argc, 104 | char ** argv, 105 | const libusb_testlib_test * tests); 106 | 107 | #endif //LIBUSB_TESTLIB_H 108 | -------------------------------------------------------------------------------- /msvc/getopt_2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | getopt 23 | {AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E} 24 | getopt 25 | 26 | 27 | 28 | StaticLibrary 29 | Unicode 30 | true 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | <_ProjectFileVersion>10.0.30319.1 41 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\$(ProjectName)\ 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\ 43 | 44 | 45 | 46 | /utf-8 %(AdditionalOptions) 47 | .;%(AdditionalIncludeDirectories) 48 | HAVE_STRING_H;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 49 | Level3 50 | 51 | 52 | ProgramDatabase 53 | Disabled 54 | MultiThreadedDebug 55 | 56 | 57 | MaxSpeed 58 | NDEBUG;%(PreprocessorDefinitions) 59 | MultiThreaded 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /msvc/getopt_2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | getopt 23 | {AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E} 24 | getopt 25 | 26 | 27 | 28 | StaticLibrary 29 | Unicode 30 | v110 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | .;%(AdditionalIncludeDirectories) 49 | HAVE_STRING_H;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | Disabled 55 | MultiThreadedDebug 56 | 57 | 58 | MaxSpeed 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /msvc/getopt_2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | getopt 23 | {AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E} 24 | getopt 25 | 26 | 27 | 28 | StaticLibrary 29 | Unicode 30 | v120 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | .;%(AdditionalIncludeDirectories) 49 | HAVE_STRING_H;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | Disabled 55 | MultiThreadedDebug 56 | 57 | 58 | MaxSpeed 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /msvc/getopt_2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | getopt 23 | {AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E} 24 | getopt 25 | 26 | 27 | 28 | StaticLibrary 29 | Unicode 30 | v140 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\lib\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | .;%(AdditionalIncludeDirectories) 49 | HAVE_STRING_H;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | Disabled 55 | MultiThreadedDebug 56 | 57 | 58 | MaxSpeed 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /libusb/os/threads_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb synchronization on Microsoft Windows 3 | * 4 | * Copyright © 2010 Michael Plante 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef LIBUSB_THREADS_WINDOWS_H 22 | #define LIBUSB_THREADS_WINDOWS_H 23 | 24 | #define USBI_MUTEX_INITIALIZER 0L 25 | #ifdef _WIN32_WCE 26 | typedef LONG usbi_mutex_static_t; 27 | #else 28 | typedef volatile LONG usbi_mutex_static_t; 29 | #endif 30 | void usbi_mutex_static_lock(usbi_mutex_static_t *mutex); 31 | static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex) 32 | { 33 | InterlockedExchange(mutex, 0L); 34 | } 35 | 36 | typedef CRITICAL_SECTION usbi_mutex_t; 37 | static inline int usbi_mutex_init(usbi_mutex_t *mutex) 38 | { 39 | InitializeCriticalSection(mutex); 40 | return 0; 41 | } 42 | static inline void usbi_mutex_lock(usbi_mutex_t *mutex) 43 | { 44 | EnterCriticalSection(mutex); 45 | } 46 | static inline void usbi_mutex_unlock(usbi_mutex_t *mutex) 47 | { 48 | LeaveCriticalSection(mutex); 49 | } 50 | static inline int usbi_mutex_trylock(usbi_mutex_t *mutex) 51 | { 52 | return !TryEnterCriticalSection(mutex); 53 | } 54 | static inline void usbi_mutex_destroy(usbi_mutex_t *mutex) 55 | { 56 | DeleteCriticalSection(mutex); 57 | } 58 | 59 | // We *were* getting timespec from pthread.h: 60 | #if (!defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED)) 61 | #define HAVE_STRUCT_TIMESPEC 1 62 | #define _TIMESPEC_DEFINED 1 63 | struct timespec { 64 | long tv_sec; 65 | long tv_nsec; 66 | }; 67 | #endif /* HAVE_STRUCT_TIMESPEC | _TIMESPEC_DEFINED */ 68 | 69 | // We *were* getting ETIMEDOUT from pthread.h: 70 | #ifndef ETIMEDOUT 71 | #define ETIMEDOUT 10060 /* This is the value in winsock.h. */ 72 | #endif 73 | 74 | typedef struct usbi_cond { 75 | // Every time a thread touches the CV, it winds up in one of these lists. 76 | // It stays there until the CV is destroyed, even if the thread terminates. 77 | struct list_head waiters; 78 | struct list_head not_waiting; 79 | } usbi_cond_t; 80 | 81 | void usbi_cond_init(usbi_cond_t *cond); 82 | int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex); 83 | int usbi_cond_timedwait(usbi_cond_t *cond, 84 | usbi_mutex_t *mutex, const struct timeval *tv); 85 | void usbi_cond_broadcast(usbi_cond_t *cond); 86 | void usbi_cond_destroy(usbi_cond_t *cond); 87 | 88 | typedef DWORD usbi_tls_key_t; 89 | static inline void usbi_tls_key_create(usbi_tls_key_t *key) 90 | { 91 | *key = TlsAlloc(); 92 | } 93 | static inline void *usbi_tls_key_get(usbi_tls_key_t key) 94 | { 95 | return TlsGetValue(key); 96 | } 97 | static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr) 98 | { 99 | (void)TlsSetValue(key, ptr); 100 | } 101 | static inline void usbi_tls_key_delete(usbi_tls_key_t key) 102 | { 103 | (void)TlsFree(key); 104 | } 105 | 106 | static inline int usbi_get_tid(void) 107 | { 108 | return (int)GetCurrentThreadId(); 109 | } 110 | 111 | #endif /* LIBUSB_THREADS_WINDOWS_H */ 112 | -------------------------------------------------------------------------------- /msvc/errno.h: -------------------------------------------------------------------------------- 1 | /* 2 | * errno.h 3 | * This file has no copyright assigned and is placed in the Public Domain. 4 | * This file is a part of the mingw-runtime package. 5 | * No warranty is given; refer to the file DISCLAIMER within the package. 6 | * 7 | * Error numbers and access to error reporting. 8 | * 9 | */ 10 | 11 | #ifndef _ERRNO_H_ 12 | #define _ERRNO_H_ 13 | 14 | #include 15 | 16 | /* 17 | * Error numbers. 18 | * TODO: Can't be sure of some of these assignments, I guessed from the 19 | * names given by strerror and the defines in the Cygnus errno.h. A lot 20 | * of the names from the Cygnus errno.h are not represented, and a few 21 | * of the descriptions returned by strerror do not obviously match 22 | * their error naming. 23 | */ 24 | #define EPERM 1 /* Operation not permitted */ 25 | #define ENOFILE 2 /* No such file or directory */ 26 | #define ENOENT 2 27 | #define ESRCH 3 /* No such process */ 28 | #define EINTR 4 /* Interrupted function call */ 29 | #define EIO 5 /* Input/output error */ 30 | #define ENXIO 6 /* No such device or address */ 31 | #define E2BIG 7 /* Arg list too long */ 32 | #define ENOEXEC 8 /* Exec format error */ 33 | #define EBADF 9 /* Bad file descriptor */ 34 | #define ECHILD 10 /* No child processes */ 35 | #define EAGAIN 11 /* Resource temporarily unavailable */ 36 | #define ENOMEM 12 /* Not enough space */ 37 | #define EACCES 13 /* Permission denied */ 38 | #define EFAULT 14 /* Bad address */ 39 | /* 15 - Unknown Error */ 40 | #define EBUSY 16 /* strerror reports "Resource device" */ 41 | #define EEXIST 17 /* File exists */ 42 | #define EXDEV 18 /* Improper link (cross-device link?) */ 43 | #define ENODEV 19 /* No such device */ 44 | #define ENOTDIR 20 /* Not a directory */ 45 | #define EISDIR 21 /* Is a directory */ 46 | #define EINVAL 22 /* Invalid argument */ 47 | #define ENFILE 23 /* Too many open files in system */ 48 | #define EMFILE 24 /* Too many open files */ 49 | #define ENOTTY 25 /* Inappropriate I/O control operation */ 50 | /* 26 - Unknown Error */ 51 | #define EFBIG 27 /* File too large */ 52 | #define ENOSPC 28 /* No space left on device */ 53 | #define ESPIPE 29 /* Invalid seek (seek on a pipe?) */ 54 | #define EROFS 30 /* Read-only file system */ 55 | #define EMLINK 31 /* Too many links */ 56 | #define EPIPE 32 /* Broken pipe */ 57 | #define EDOM 33 /* Domain error (math functions) */ 58 | #define ERANGE 34 /* Result too large (possibly too small) */ 59 | /* 35 - Unknown Error */ 60 | #define EDEADLOCK 36 /* Resource deadlock avoided (non-Cyg) */ 61 | #define EDEADLK 36 62 | #if 0 63 | /* 37 - Unknown Error */ 64 | #define ENAMETOOLONG 38 /* Filename too long (91 in Cyg?) */ 65 | #define ENOLCK 39 /* No locks available (46 in Cyg?) */ 66 | #define ENOSYS 40 /* Function not implemented (88 in Cyg?) */ 67 | #define ENOTEMPTY 41 /* Directory not empty (90 in Cyg?) */ 68 | #define EILSEQ 42 /* Illegal byte sequence */ 69 | #endif 70 | 71 | /* 72 | * NOTE: ENAMETOOLONG and ENOTEMPTY conflict with definitions in the 73 | * sockets.h header provided with windows32api-0.1.2. 74 | * You should go and put an #if 0 ... #endif around the whole block 75 | * of errors (look at the comment above them). 76 | */ 77 | 78 | #ifndef RC_INVOKED 79 | 80 | #ifdef __cplusplus 81 | extern "C" { 82 | #endif 83 | 84 | /* 85 | * Definitions of errno. For _doserrno, sys_nerr and * sys_errlist, see 86 | * stdlib.h. 87 | */ 88 | #if defined(_UWIN) || defined(_WIN32_WCE) 89 | #undef errno 90 | extern int errno; 91 | #else 92 | _CRTIMP int* __cdecl _errno(void); 93 | #define errno (*_errno()) 94 | #endif 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif /* Not RC_INVOKED */ 101 | 102 | #endif /* Not _ERRNO_H_ */ -------------------------------------------------------------------------------- /libusb/hotplug.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */ 2 | /* 3 | * Hotplug support for libusb 4 | * Copyright © 2012-2013 Nathan Hjelm 5 | * Copyright © 2012-2013 Peter Stuge 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef USBI_HOTPLUG_H 23 | #define USBI_HOTPLUG_H 24 | 25 | #include "libusbi.h" 26 | 27 | enum usbi_hotplug_flags { 28 | /* This callback is interested in device arrivals */ 29 | USBI_HOTPLUG_DEVICE_ARRIVED = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 30 | 31 | /* This callback is interested in device removals */ 32 | USBI_HOTPLUG_DEVICE_LEFT = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 33 | 34 | /* IMPORTANT: The values for the below entries must start *after* 35 | * the highest value of the above entries!!! 36 | */ 37 | 38 | /* The vendor_id field is valid for matching */ 39 | USBI_HOTPLUG_VENDOR_ID_VALID = (1U << 3), 40 | 41 | /* The product_id field is valid for matching */ 42 | USBI_HOTPLUG_PRODUCT_ID_VALID = (1U << 4), 43 | 44 | /* The dev_class field is valid for matching */ 45 | USBI_HOTPLUG_DEV_CLASS_VALID = (1U << 5), 46 | 47 | /* This callback has been unregistered and needs to be freed */ 48 | USBI_HOTPLUG_NEEDS_FREE = (1U << 6), 49 | }; 50 | 51 | /** \ingroup hotplug 52 | * The hotplug callback structure. The user populates this structure with 53 | * libusb_hotplug_prepare_callback() and then calls libusb_hotplug_register_callback() 54 | * to receive notification of hotplug events. 55 | */ 56 | struct libusb_hotplug_callback { 57 | /** Flags that control how this callback behaves */ 58 | uint8_t flags; 59 | 60 | /** Vendor ID to match (if flags says this is valid) */ 61 | uint16_t vendor_id; 62 | 63 | /** Product ID to match (if flags says this is valid) */ 64 | uint16_t product_id; 65 | 66 | /** Device class to match (if flags says this is valid) */ 67 | uint8_t dev_class; 68 | 69 | /** Callback function to invoke for matching event/device */ 70 | libusb_hotplug_callback_fn cb; 71 | 72 | /** Handle for this callback (used to match on deregister) */ 73 | libusb_hotplug_callback_handle handle; 74 | 75 | /** User data that will be passed to the callback function */ 76 | void *user_data; 77 | 78 | /** List this callback is registered in (ctx->hotplug_cbs) */ 79 | struct list_head list; 80 | }; 81 | 82 | struct libusb_hotplug_message { 83 | /** The hotplug event that occurred */ 84 | libusb_hotplug_event event; 85 | 86 | /** The device for which this hotplug event occurred */ 87 | struct libusb_device *device; 88 | 89 | /** List this message is contained in (ctx->hotplug_msgs) */ 90 | struct list_head list; 91 | }; 92 | 93 | void usbi_hotplug_deregister(struct libusb_context *ctx, int forced); 94 | void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev, 95 | libusb_hotplug_event event); 96 | void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev, 97 | libusb_hotplug_event event); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /libusb/os/haiku_usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Haiku Backend for libusb 3 | * Copyright © 2014 Akshay Jaggi 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "libusbi.h" 26 | #include "haiku_usb_raw.h" 27 | 28 | using namespace std; 29 | 30 | class USBDevice; 31 | class USBDeviceHandle; 32 | class USBTransfer; 33 | 34 | class USBDevice { 35 | public: 36 | USBDevice(const char *); 37 | virtual ~USBDevice(); 38 | const char* Location() const; 39 | uint8 CountConfigurations() const; 40 | const usb_device_descriptor* Descriptor() const; 41 | const usb_configuration_descriptor* ConfigurationDescriptor(uint32) const; 42 | const usb_configuration_descriptor* ActiveConfiguration() const; 43 | uint8 EndpointToIndex(uint8) const; 44 | uint8 EndpointToInterface(uint8) const; 45 | int ClaimInterface(int); 46 | int ReleaseInterface(int); 47 | int CheckInterfacesFree(int); 48 | int SetActiveConfiguration(int); 49 | int ActiveConfigurationIndex() const; 50 | bool InitCheck(); 51 | private: 52 | int Initialise(); 53 | unsigned int fClaimedInterfaces; // Max Interfaces can be 32. Using a bitmask 54 | usb_device_descriptor fDeviceDescriptor; 55 | unsigned char** fConfigurationDescriptors; 56 | int fActiveConfiguration; 57 | char* fPath; 58 | map fConfigToIndex; 59 | map* fEndpointToIndex; 60 | map* fEndpointToInterface; 61 | bool fInitCheck; 62 | }; 63 | 64 | class USBDeviceHandle { 65 | public: 66 | USBDeviceHandle(USBDevice *dev); 67 | virtual ~USBDeviceHandle(); 68 | int ClaimInterface(int); 69 | int ReleaseInterface(int); 70 | int SetConfiguration(int); 71 | int SetAltSetting(int, int); 72 | int ClearHalt(int); 73 | status_t SubmitTransfer(struct usbi_transfer *); 74 | status_t CancelTransfer(USBTransfer *); 75 | bool InitCheck(); 76 | private: 77 | int fRawFD; 78 | static status_t TransfersThread(void *); 79 | void TransfersWorker(); 80 | USBDevice* fUSBDevice; 81 | unsigned int fClaimedInterfaces; 82 | BList fTransfers; 83 | BLocker fTransfersLock; 84 | sem_id fTransfersSem; 85 | thread_id fTransfersThread; 86 | bool fInitCheck; 87 | }; 88 | 89 | class USBTransfer { 90 | public: 91 | USBTransfer(struct usbi_transfer *, USBDevice *); 92 | virtual ~USBTransfer(); 93 | void Do(int); 94 | struct usbi_transfer* UsbiTransfer(); 95 | void SetCancelled(); 96 | bool IsCancelled(); 97 | private: 98 | struct usbi_transfer* fUsbiTransfer; 99 | struct libusb_transfer* fLibusbTransfer; 100 | USBDevice* fUSBDevice; 101 | BLocker fStatusLock; 102 | bool fCancelled; 103 | }; 104 | 105 | class USBRoster { 106 | public: 107 | USBRoster(); 108 | virtual ~USBRoster(); 109 | int Start(); 110 | void Stop(); 111 | private: 112 | void* fLooper; 113 | }; 114 | -------------------------------------------------------------------------------- /msvc/xusb_2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | xusb 23 | {3F3138D0-7AB7-4268-9BF3-1A3EA5503A11} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | ..\libusb;%(AdditionalIncludeDirectories) 49 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | Disabled 55 | true 56 | MultiThreadedDebug 57 | 58 | 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | $(TargetDir)$(ProjectName).pdb 64 | Console 65 | 66 | 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 76 | false 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /msvc/listdevs_2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | listdevs 23 | {F4938DB0-3DE7-4737-9C5A-EAD1BE819F87} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | ..\libusb;%(AdditionalIncludeDirectories) 49 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | true 55 | Disabled 56 | MultiThreadedDebug 57 | 58 | 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | $(TargetDir)$(ProjectName).pdb 64 | Console 65 | 66 | 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 76 | false 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /msvc/hotplugtest_2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | hotplugtest 23 | {99D2AC64-DC66-4422-91CE-6715C403C9E5} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | ..\libusb;%(AdditionalIncludeDirectories) 49 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | true 55 | Disabled 56 | MultiThreadedDebug 57 | 58 | 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | $(TargetDir)$(ProjectName).pdb 64 | Console 65 | 66 | 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 76 | false 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /msvc/testlibusb_2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | testlibusb 23 | {70828935-325B-4749-B381-0E55EF31AEE8} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | ..\libusb;%(AdditionalIncludeDirectories) 49 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | true 55 | Disabled 56 | MultiThreadedDebug 57 | 58 | 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | $(TargetDir)$(ProjectName).pdb 64 | Console 65 | 66 | 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 76 | false 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /libusb/os/poll_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Windows compat: POSIX compatibility wrapper 3 | * Copyright © 2012-2013 RealVNC Ltd. 4 | * Copyright © 2009-2010 Pete Batard 5 | * Copyright © 2016-2018 Chris Dickens 6 | * With contributions from Michael Plante, Orin Eman et al. 7 | * Parts of poll implementation from libusb-win32, by Stephan Meyer et al. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | #pragma once 25 | 26 | #if defined(_MSC_VER) 27 | // disable /W4 MSVC warnings that are benign 28 | #pragma warning(disable:4127) // conditional expression is constant 29 | #endif 30 | 31 | // Handle synchronous completion through the overlapped structure 32 | #if !defined(STATUS_REPARSE) // reuse the REPARSE status code 33 | #define STATUS_REPARSE ((LONG)0x00000104L) 34 | #endif 35 | #define STATUS_COMPLETED_SYNCHRONOUSLY STATUS_REPARSE 36 | #if defined(_WIN32_WCE) 37 | // WinCE doesn't have a HasOverlappedIoCompleted() macro, so attempt to emulate it 38 | #define HasOverlappedIoCompleted(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) != STATUS_PENDING) 39 | #endif 40 | #define HasOverlappedIoCompletedSync(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) == STATUS_COMPLETED_SYNCHRONOUSLY) 41 | 42 | #define DUMMY_HANDLE ((HANDLE)(LONG_PTR)-2) 43 | 44 | #define POLLIN 0x0001 /* There is data to read */ 45 | #define POLLPRI 0x0002 /* There is urgent data to read */ 46 | #define POLLOUT 0x0004 /* Writing now will not block */ 47 | #define POLLERR 0x0008 /* Error condition */ 48 | #define POLLHUP 0x0010 /* Hung up */ 49 | #define POLLNVAL 0x0020 /* Invalid request: fd not open */ 50 | 51 | struct pollfd { 52 | int fd; /* file descriptor */ 53 | short events; /* requested events */ 54 | short revents; /* returned events */ 55 | }; 56 | 57 | struct winfd { 58 | int fd; // what's exposed to libusb core 59 | OVERLAPPED *overlapped; // what will report our I/O status 60 | }; 61 | 62 | extern const struct winfd INVALID_WINFD; 63 | 64 | struct winfd usbi_create_fd(void); 65 | 66 | int usbi_pipe(int pipefd[2]); 67 | int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout); 68 | ssize_t usbi_write(int fd, const void *buf, size_t count); 69 | ssize_t usbi_read(int fd, void *buf, size_t count); 70 | int usbi_close(int fd); 71 | 72 | void usbi_inc_fds_ref(struct pollfd *fds, unsigned int nfds); 73 | void usbi_dec_fds_ref(struct pollfd *fds, unsigned int nfds); 74 | 75 | /* 76 | * Timeval operations 77 | */ 78 | #if defined(DDKBUILD) 79 | #include // defines timeval functions on DDK 80 | #endif 81 | 82 | #if !defined(TIMESPEC_TO_TIMEVAL) 83 | #define TIMESPEC_TO_TIMEVAL(tv, ts) { \ 84 | (tv)->tv_sec = (long)(ts)->tv_sec; \ 85 | (tv)->tv_usec = (long)(ts)->tv_nsec / 1000; \ 86 | } 87 | #endif 88 | #if !defined(timersub) 89 | #define timersub(a, b, result) \ 90 | do { \ 91 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 92 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 93 | if ((result)->tv_usec < 0) { \ 94 | --(result)->tv_sec; \ 95 | (result)->tv_usec += 1000000; \ 96 | } \ 97 | } while (0) 98 | #endif 99 | -------------------------------------------------------------------------------- /msvc/xusb_2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | xusb 23 | {3F3138D0-7AB7-4268-9BF3-1A3EA5503A11} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v110 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | Disabled 56 | true 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/xusb_2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | xusb 23 | {3F3138D0-7AB7-4268-9BF3-1A3EA5503A11} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v120 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | Disabled 56 | true 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/xusb_2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | xusb 23 | {3F3138D0-7AB7-4268-9BF3-1A3EA5503A11} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v140 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | Disabled 56 | true 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /examples/hotplugtest.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */ 2 | /* 3 | * libusb example program for hotplug API 4 | * Copyright © 2012-2013 Nathan Hjelm 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "libusb.h" 25 | 26 | int done = 0; 27 | libusb_device_handle *handle = NULL; 28 | 29 | static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data) 30 | { 31 | struct libusb_device_descriptor desc; 32 | int rc; 33 | 34 | (void)ctx; 35 | (void)dev; 36 | (void)event; 37 | (void)user_data; 38 | 39 | rc = libusb_get_device_descriptor(dev, &desc); 40 | if (LIBUSB_SUCCESS != rc) { 41 | fprintf (stderr, "Error getting device descriptor\n"); 42 | } 43 | 44 | printf ("Device attached: %04x:%04x\n", desc.idVendor, desc.idProduct); 45 | 46 | if (handle) { 47 | libusb_close (handle); 48 | handle = NULL; 49 | } 50 | 51 | rc = libusb_open (dev, &handle); 52 | if (LIBUSB_SUCCESS != rc) { 53 | fprintf (stderr, "Error opening device\n"); 54 | } 55 | 56 | done++; 57 | 58 | return 0; 59 | } 60 | 61 | static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data) 62 | { 63 | (void)ctx; 64 | (void)dev; 65 | (void)event; 66 | (void)user_data; 67 | 68 | printf ("Device detached\n"); 69 | 70 | if (handle) { 71 | libusb_close (handle); 72 | handle = NULL; 73 | } 74 | 75 | done++; 76 | 77 | return 0; 78 | } 79 | 80 | int main(int argc, char *argv[]) 81 | { 82 | libusb_hotplug_callback_handle hp[2]; 83 | int product_id, vendor_id, class_id; 84 | int rc; 85 | 86 | vendor_id = (argc > 1) ? (int)strtol (argv[1], NULL, 0) : 0x045a; 87 | product_id = (argc > 2) ? (int)strtol (argv[2], NULL, 0) : 0x5005; 88 | class_id = (argc > 3) ? (int)strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY; 89 | 90 | rc = libusb_init (NULL); 91 | if (rc < 0) 92 | { 93 | printf("failed to initialise libusb: %s\n", libusb_error_name(rc)); 94 | return EXIT_FAILURE; 95 | } 96 | 97 | if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) { 98 | printf ("Hotplug capabilites are not supported on this platform\n"); 99 | libusb_exit (NULL); 100 | return EXIT_FAILURE; 101 | } 102 | 103 | rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, vendor_id, 104 | product_id, class_id, hotplug_callback, NULL, &hp[0]); 105 | if (LIBUSB_SUCCESS != rc) { 106 | fprintf (stderr, "Error registering callback 0\n"); 107 | libusb_exit (NULL); 108 | return EXIT_FAILURE; 109 | } 110 | 111 | rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, vendor_id, 112 | product_id,class_id, hotplug_callback_detach, NULL, &hp[1]); 113 | if (LIBUSB_SUCCESS != rc) { 114 | fprintf (stderr, "Error registering callback 1\n"); 115 | libusb_exit (NULL); 116 | return EXIT_FAILURE; 117 | } 118 | 119 | while (done < 2) { 120 | rc = libusb_handle_events (NULL); 121 | if (rc < 0) 122 | printf("libusb_handle_events() failed: %s\n", libusb_error_name(rc)); 123 | } 124 | 125 | if (handle) { 126 | libusb_close (handle); 127 | } 128 | 129 | libusb_exit (NULL); 130 | 131 | return EXIT_SUCCESS; 132 | } 133 | -------------------------------------------------------------------------------- /msvc/listdevs_2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | listdevs 23 | {F4938DB0-3DE7-4737-9C5A-EAD1BE819F87} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v110 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/listdevs_2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | listdevs 23 | {F4938DB0-3DE7-4737-9C5A-EAD1BE819F87} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v120 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/listdevs_2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | listdevs 23 | {F4938DB0-3DE7-4737-9C5A-EAD1BE819F87} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v140 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/hotplugtest_2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | hotplugtest 23 | {99D2AC64-DC66-4422-91CE-6715C403C9E5} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v110 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/hotplugtest_2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | hotplugtest 23 | {99D2AC64-DC66-4422-91CE-6715C403C9E5} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v120 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/hotplugtest_2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | hotplugtest 23 | {99D2AC64-DC66-4422-91CE-6715C403C9E5} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v140 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/testlibusb_2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | testlibusb 23 | {70828935-325B-4749-B381-0E55EF31AEE8} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v110 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/testlibusb_2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | testlibusb 23 | {70828935-325B-4749-B381-0E55EF31AEE8} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v120 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /msvc/testlibusb_2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | testlibusb 23 | {70828935-325B-4749-B381-0E55EF31AEE8} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v140 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | ..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /PORTING: -------------------------------------------------------------------------------- 1 | PORTING LIBUSB TO OTHER PLATFORMS 2 | 3 | Introduction 4 | ============ 5 | 6 | This document is aimed at developers wishing to port libusb to unsupported 7 | platforms. I believe the libusb API is OS-independent, so by supporting 8 | multiple operating systems we pave the way for cross-platform USB device 9 | drivers. 10 | 11 | Implementation-wise, the basic idea is that you provide an interface to 12 | libusb's internal "backend" API, which performs the appropriate operations on 13 | your target platform. 14 | 15 | In terms of USB I/O, your backend provides functionality to submit 16 | asynchronous transfers (synchronous transfers are implemented in the higher 17 | layers, based on the async interface). Your backend must also provide 18 | functionality to cancel those transfers. 19 | 20 | Your backend must also provide an event handling function to "reap" ongoing 21 | transfers and process their results. 22 | 23 | The backend must also provide standard functions for other USB operations, 24 | e.g. setting configuration, obtaining descriptors, etc. 25 | 26 | 27 | File descriptors for I/O polling 28 | ================================ 29 | 30 | For libusb to work, your event handling function obviously needs to be called 31 | at various points in time. Your backend must provide a set of file descriptors 32 | which libusb and its users can pass to poll() or select() to determine when 33 | it is time to call the event handling function. 34 | 35 | On Linux, this is easy: the usbfs kernel interface exposes a file descriptor 36 | which can be passed to poll(). If something similar is not true for your 37 | platform, you can emulate this using an internal library thread to reap I/O as 38 | necessary, and a pipe() with the main library to raise events. The file 39 | descriptor of the pipe can then be provided to libusb as an event source. 40 | 41 | 42 | Interface semantics and documentation 43 | ===================================== 44 | 45 | Documentation of the backend interface can be found in libusbi.h inside the 46 | usbi_os_backend structure definition. 47 | 48 | Your implementations of these functions will need to call various internal 49 | libusb functions, prefixed with "usbi_". Documentation for these functions 50 | can be found in the .c files where they are implemented. 51 | 52 | You probably want to skim over *all* the documentation before starting your 53 | implementation. For example, you probably need to allocate and store private 54 | OS-specific data for device handles, but the documentation for the mechanism 55 | for doing so is probably not the first thing you will see. 56 | 57 | The Linux backend acts as a good example - view it as a reference 58 | implementation which you should try to match the behaviour of. 59 | 60 | 61 | Getting started 62 | =============== 63 | 64 | 1. Modify configure.ac to detect your platform appropriately (see the OS_LINUX 65 | stuff for an example). 66 | 67 | 2. Implement your backend in the libusb/os/ directory, modifying 68 | libusb/os/Makefile.am appropriately. 69 | 70 | 3. Add preprocessor logic to the top of libusb/core.c to statically assign the 71 | right usbi_backend for your platform. 72 | 73 | 4. Produce and test your implementation. 74 | 75 | 5. Send your implementation to libusb-devel mailing list. 76 | 77 | 78 | Implementation difficulties? Questions? 79 | ======================================= 80 | 81 | If you encounter difficulties porting libusb to your platform, please raise 82 | these issues on the libusb-devel mailing list. Where possible and sensible, I 83 | am interested in solving problems preventing libusb from operating on other 84 | platforms. 85 | 86 | The libusb-devel mailing list is also a good place to ask questions and 87 | make suggestions about the internal API. Hopefully we can produce some 88 | better documentation based on your questions and other input. 89 | 90 | You are encouraged to get involved in the process; if the library needs 91 | some infrastructure additions/modifications to better support your platform, 92 | you are encouraged to make such changes (in cleanly distinct patch 93 | submissions). Even if you do not make such changes yourself, please do raise 94 | the issues on the mailing list at the very minimum. 95 | -------------------------------------------------------------------------------- /libusb/os/threads_windows.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb synchronization on Microsoft Windows 3 | * 4 | * Copyright © 2010 Michael Plante 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "libusbi.h" 26 | 27 | struct usbi_cond_perthread { 28 | struct list_head list; 29 | HANDLE event; 30 | }; 31 | 32 | void usbi_mutex_static_lock(usbi_mutex_static_t *mutex) 33 | { 34 | while (InterlockedExchange(mutex, 1L) == 1L) 35 | SleepEx(0, TRUE); 36 | } 37 | 38 | void usbi_cond_init(usbi_cond_t *cond) 39 | { 40 | list_init(&cond->waiters); 41 | list_init(&cond->not_waiting); 42 | } 43 | 44 | static int usbi_cond_intwait(usbi_cond_t *cond, 45 | usbi_mutex_t *mutex, DWORD timeout_ms) 46 | { 47 | struct usbi_cond_perthread *pos; 48 | DWORD r; 49 | 50 | // Same assumption as usbi_cond_broadcast() holds 51 | if (list_empty(&cond->not_waiting)) { 52 | pos = malloc(sizeof(*pos)); 53 | if (pos == NULL) 54 | return ENOMEM; // This errno is not POSIX-allowed. 55 | pos->event = CreateEvent(NULL, FALSE, FALSE, NULL); // auto-reset. 56 | if (pos->event == NULL) { 57 | free(pos); 58 | return ENOMEM; 59 | } 60 | } else { 61 | pos = list_first_entry(&cond->not_waiting, struct usbi_cond_perthread, list); 62 | list_del(&pos->list); // remove from not_waiting list. 63 | // Ensure the event is clear before waiting 64 | WaitForSingleObject(pos->event, 0); 65 | } 66 | 67 | list_add(&pos->list, &cond->waiters); 68 | 69 | LeaveCriticalSection(mutex); 70 | r = WaitForSingleObject(pos->event, timeout_ms); 71 | EnterCriticalSection(mutex); 72 | 73 | list_del(&pos->list); 74 | list_add(&pos->list, &cond->not_waiting); 75 | 76 | if (r == WAIT_OBJECT_0) 77 | return 0; 78 | else if (r == WAIT_TIMEOUT) 79 | return ETIMEDOUT; 80 | else 81 | return EINVAL; 82 | } 83 | 84 | // N.B.: usbi_cond_*wait() can also return ENOMEM, even though pthread_cond_*wait cannot! 85 | int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex) 86 | { 87 | return usbi_cond_intwait(cond, mutex, INFINITE); 88 | } 89 | 90 | int usbi_cond_timedwait(usbi_cond_t *cond, 91 | usbi_mutex_t *mutex, const struct timeval *tv) 92 | { 93 | DWORD millis; 94 | 95 | millis = (DWORD)(tv->tv_sec * 1000) + (tv->tv_usec / 1000); 96 | /* round up to next millisecond */ 97 | if (tv->tv_usec % 1000) 98 | millis++; 99 | return usbi_cond_intwait(cond, mutex, millis); 100 | } 101 | 102 | void usbi_cond_broadcast(usbi_cond_t *cond) 103 | { 104 | // Assumes mutex is locked; this is not in keeping with POSIX spec, but 105 | // libusb does this anyway, so we simplify by not adding more sync 106 | // primitives to the CV definition! 107 | struct usbi_cond_perthread *pos; 108 | 109 | list_for_each_entry(pos, &cond->waiters, list, struct usbi_cond_perthread) 110 | SetEvent(pos->event); 111 | // The wait function will remove its respective item from the list. 112 | } 113 | 114 | void usbi_cond_destroy(usbi_cond_t *cond) 115 | { 116 | // This assumes no one is using this anymore. The check MAY NOT BE safe. 117 | struct usbi_cond_perthread *pos, *next; 118 | 119 | if (!list_empty(&cond->waiters)) 120 | return; // (!see above!) 121 | list_for_each_entry_safe(pos, next, &cond->not_waiting, list, struct usbi_cond_perthread) { 122 | CloseHandle(pos->event); 123 | list_del(&pos->list); 124 | free(pos); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /msvc/stress_2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | stress 23 | {53942EFF-C810-458D-B3CB-EE5CE9F1E781} 24 | tests 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | .;..\libusb;%(AdditionalIncludeDirectories) 49 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | true 55 | Disabled 56 | MultiThreadedDebug 57 | 58 | 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | $(TargetDir)$(ProjectName).pdb 64 | Console 65 | 66 | 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 80 | false 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /msvc/stress_2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | stress 23 | {53942EFF-C810-458D-B3CB-EE5CE9F1E781} 24 | tests 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v110 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | .;..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 81 | false 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /msvc/stress_2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | stress 23 | {53942EFF-C810-458D-B3CB-EE5CE9F1E781} 24 | tests 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v120 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | .;..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 81 | false 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /msvc/stress_2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | stress 23 | {53942EFF-C810-458D-B3CB-EE5CE9F1E781} 24 | tests 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v140 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\tests\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | .;..\libusb;%(AdditionalIncludeDirectories) 50 | _CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 81 | false 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /msvc/fxload_2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | fxload 23 | {9E166F7A-A793-9FB6-0A67-F0AED8AE8C88} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 44 | 45 | 46 | 47 | /utf-8 %(AdditionalOptions) 48 | .;..\examples\getopt;..\libusb;%(AdditionalIncludeDirectories) 49 | __GNU_LIBRARY__;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 50 | Level3 51 | 52 | 53 | ProgramDatabase 54 | true 55 | Disabled 56 | MultiThreadedDebug 57 | 58 | 59 | NDEBUG;%(PreprocessorDefinitions) 60 | MultiThreaded 61 | 62 | 63 | $(TargetDir)$(ProjectName).pdb 64 | Console 65 | 66 | 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | {ae83e1b4-ce06-47ee-b7a3-c3a1d7c2d71e} 80 | false 81 | 82 | 83 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 84 | false 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /msvc/fxload_2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | fxload 23 | {9E166F7A-A793-9FB6-0A67-F0AED8AE8C88} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v110 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | .;..\examples\getopt;..\libusb;%(AdditionalIncludeDirectories) 50 | __GNU_LIBRARY__;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {ae83e1b4-ce06-47ee-b7a3-c3a1d7c2d71e} 81 | false 82 | 83 | 84 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 85 | false 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /msvc/fxload_2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | fxload 23 | {9E166F7A-A793-9FB6-0A67-F0AED8AE8C88} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v120 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | .;..\examples\getopt;..\libusb;%(AdditionalIncludeDirectories) 50 | __GNU_LIBRARY__;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {ae83e1b4-ce06-47ee-b7a3-c3a1d7c2d71e} 81 | false 82 | 83 | 84 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 85 | false 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /msvc/fxload_2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | fxload 23 | {9E166F7A-A793-9FB6-0A67-F0AED8AE8C88} 24 | examples 25 | Win32Proj 26 | 27 | 28 | 29 | Application 30 | Unicode 31 | v140 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\ 44 | $(ProjectDir)..\$(Platform)\$(Configuration)\examples\ 45 | 46 | 47 | 48 | /utf-8 %(AdditionalOptions) 49 | .;..\examples\getopt;..\libusb;%(AdditionalIncludeDirectories) 50 | __GNU_LIBRARY__;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | Level3 52 | 53 | 54 | ProgramDatabase 55 | true 56 | Disabled 57 | MultiThreadedDebug 58 | 59 | 60 | NDEBUG;%(PreprocessorDefinitions) 61 | MultiThreaded 62 | 63 | 64 | $(TargetDir)$(ProjectName).pdb 65 | Console 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {ae83e1b4-ce06-47ee-b7a3-c3a1d7c2d71e} 81 | false 82 | 83 | 84 | {349ee8f9-7d25-4909-aaf5-ff3fade72187} 85 | false 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /libusb/os/windows_nt_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Windows backend common header for libusb 1.0 3 | * 4 | * This file brings together header code common between 5 | * the desktop Windows backends. 6 | * Copyright © 2012-2013 RealVNC Ltd. 7 | * Copyright © 2009-2012 Pete Batard 8 | * With contributions from Michael Plante, Orin Eman et al. 9 | * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer 10 | * Major code testing contribution by Xiaofan Chen 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "windows_nt_shared_types.h" 30 | 31 | /* Windows versions */ 32 | enum windows_version { 33 | WINDOWS_UNDEFINED, 34 | WINDOWS_2000, 35 | WINDOWS_XP, 36 | WINDOWS_2003, // Also XP x64 37 | WINDOWS_VISTA, 38 | WINDOWS_7, 39 | WINDOWS_8, 40 | WINDOWS_8_1, 41 | WINDOWS_10, 42 | WINDOWS_11_OR_LATER 43 | }; 44 | 45 | extern enum windows_version windows_version; 46 | 47 | /* This call is only available from Vista */ 48 | extern BOOL (WINAPI *pCancelIoEx)(HANDLE, LPOVERLAPPED); 49 | 50 | struct windows_backend { 51 | int (*init)(struct libusb_context *ctx); 52 | void (*exit)(struct libusb_context *ctx); 53 | int (*get_device_list)(struct libusb_context *ctx, 54 | struct discovered_devs **discdevs); 55 | int (*open)(struct libusb_device_handle *dev_handle); 56 | void (*close)(struct libusb_device_handle *dev_handle); 57 | int (*get_device_descriptor)(struct libusb_device *device, unsigned char *buffer); 58 | int (*get_active_config_descriptor)(struct libusb_device *device, 59 | unsigned char *buffer, size_t len); 60 | int (*get_config_descriptor)(struct libusb_device *device, 61 | uint8_t config_index, unsigned char *buffer, size_t len); 62 | int (*get_config_descriptor_by_value)(struct libusb_device *device, 63 | uint8_t bConfigurationValue, unsigned char **buffer); 64 | int (*get_configuration)(struct libusb_device_handle *dev_handle, int *config); 65 | int (*set_configuration)(struct libusb_device_handle *dev_handle, int config); 66 | int (*claim_interface)(struct libusb_device_handle *dev_handle, int interface_number); 67 | int (*release_interface)(struct libusb_device_handle *dev_handle, int interface_number); 68 | int (*set_interface_altsetting)(struct libusb_device_handle *dev_handle, 69 | int interface_number, int altsetting); 70 | int (*clear_halt)(struct libusb_device_handle *dev_handle, 71 | unsigned char endpoint); 72 | int (*reset_device)(struct libusb_device_handle *dev_handle); 73 | void (*destroy_device)(struct libusb_device *dev); 74 | int (*submit_transfer)(struct usbi_transfer *itransfer); 75 | int (*cancel_transfer)(struct usbi_transfer *itransfer); 76 | void (*clear_transfer_priv)(struct usbi_transfer *itransfer); 77 | int (*copy_transfer_data)(struct usbi_transfer *itransfer, uint32_t io_size); 78 | int (*get_transfer_fd)(struct usbi_transfer *itransfer); 79 | void (*get_overlapped_result)(struct usbi_transfer *itransfer, 80 | DWORD *io_result, DWORD *io_size); 81 | }; 82 | 83 | struct windows_context_priv { 84 | const struct windows_backend *backend; 85 | }; 86 | 87 | union windows_device_priv { 88 | struct usbdk_device_priv usbdk_priv; 89 | struct winusb_device_priv winusb_priv; 90 | }; 91 | 92 | union windows_device_handle_priv { 93 | struct usbdk_device_handle_priv usbdk_priv; 94 | struct winusb_device_handle_priv winusb_priv; 95 | }; 96 | 97 | union windows_transfer_priv { 98 | struct usbdk_transfer_priv usbdk_priv; 99 | struct winusb_transfer_priv winusb_priv; 100 | }; 101 | 102 | extern const struct windows_backend usbdk_backend; 103 | extern const struct windows_backend winusb_backend; 104 | 105 | unsigned long htab_hash(const char *str); 106 | void windows_force_sync_completion(OVERLAPPED *overlapped, ULONG size); 107 | 108 | #if defined(ENABLE_LOGGING) 109 | const char *windows_error_str(DWORD error_code); 110 | #endif 111 | -------------------------------------------------------------------------------- /libusb/os/windows_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Windows backend common header for libusb 1.0 3 | * 4 | * This file brings together header code common between 5 | * the desktop Windows and Windows CE backends. 6 | * Copyright © 2012-2013 RealVNC Ltd. 7 | * Copyright © 2009-2012 Pete Batard 8 | * With contributions from Michael Plante, Orin Eman et al. 9 | * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer 10 | * Major code testing contribution by Xiaofan Chen 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #pragma once 28 | 29 | // Windows API default is uppercase - ugh! 30 | #if !defined(bool) 31 | #define bool BOOL 32 | #endif 33 | #if !defined(true) 34 | #define true TRUE 35 | #endif 36 | #if !defined(false) 37 | #define false FALSE 38 | #endif 39 | 40 | #define EPOCH_TIME UINT64_C(116444736000000000) // 1970.01.01 00:00:000 in MS Filetime 41 | 42 | #if defined(__CYGWIN__ ) 43 | #define _stricmp strcasecmp 44 | #define _strdup strdup 45 | // _beginthreadex is MSVCRT => unavailable for cygwin. Fallback to using CreateThread 46 | #define _beginthreadex(a, b, c, d, e, f) CreateThread(a, b, (LPTHREAD_START_ROUTINE)c, d, e, (LPDWORD)f) 47 | #endif 48 | 49 | #define safe_free(p) do {if (p != NULL) {free((void *)p); p = NULL;}} while (0) 50 | 51 | #ifndef ARRAYSIZE 52 | #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) 53 | #endif 54 | 55 | #define ERR_BUFFER_SIZE 256 56 | 57 | /* 58 | * API macros - leveraged from libusb-win32 1.x 59 | */ 60 | #ifndef _WIN32_WCE 61 | #define DLL_STRINGIFY(s) #s 62 | #define DLL_LOAD_LIBRARY(name) LoadLibraryA(DLL_STRINGIFY(name)) 63 | #else 64 | #define DLL_STRINGIFY(s) L#s 65 | #define DLL_LOAD_LIBRARY(name) LoadLibrary(DLL_STRINGIFY(name)) 66 | #endif 67 | 68 | /* 69 | * Macros for handling DLL themselves 70 | */ 71 | #define DLL_HANDLE_NAME(name) __dll_##name##_handle 72 | 73 | #define DLL_DECLARE_HANDLE(name) \ 74 | static HMODULE DLL_HANDLE_NAME(name) = NULL 75 | 76 | #define DLL_GET_HANDLE(name) \ 77 | do { \ 78 | DLL_HANDLE_NAME(name) = DLL_LOAD_LIBRARY(name); \ 79 | if (!DLL_HANDLE_NAME(name)) \ 80 | return FALSE; \ 81 | } while (0) 82 | 83 | #define DLL_FREE_HANDLE(name) \ 84 | do { \ 85 | if (DLL_HANDLE_NAME(name)) { \ 86 | FreeLibrary(DLL_HANDLE_NAME(name)); \ 87 | DLL_HANDLE_NAME(name) = NULL; \ 88 | } \ 89 | } while (0) 90 | 91 | 92 | /* 93 | * Macros for handling functions within a DLL 94 | */ 95 | #define DLL_FUNC_NAME(name) __dll_##name##_func_t 96 | 97 | #define DLL_DECLARE_FUNC_PREFIXNAME(api, ret, prefixname, name, args) \ 98 | typedef ret (api * DLL_FUNC_NAME(name))args; \ 99 | static DLL_FUNC_NAME(name) prefixname = NULL 100 | 101 | #define DLL_DECLARE_FUNC(api, ret, name, args) \ 102 | DLL_DECLARE_FUNC_PREFIXNAME(api, ret, name, name, args) 103 | #define DLL_DECLARE_FUNC_PREFIXED(api, ret, prefix, name, args) \ 104 | DLL_DECLARE_FUNC_PREFIXNAME(api, ret, prefix##name, name, args) 105 | 106 | #define DLL_LOAD_FUNC_PREFIXNAME(dll, prefixname, name, ret_on_failure) \ 107 | do { \ 108 | HMODULE h = DLL_HANDLE_NAME(dll); \ 109 | prefixname = (DLL_FUNC_NAME(name))GetProcAddress(h, \ 110 | DLL_STRINGIFY(name)); \ 111 | if (prefixname) \ 112 | break; \ 113 | prefixname = (DLL_FUNC_NAME(name))GetProcAddress(h, \ 114 | DLL_STRINGIFY(name) DLL_STRINGIFY(A)); \ 115 | if (prefixname) \ 116 | break; \ 117 | prefixname = (DLL_FUNC_NAME(name))GetProcAddress(h, \ 118 | DLL_STRINGIFY(name) DLL_STRINGIFY(W)); \ 119 | if (prefixname) \ 120 | break; \ 121 | if (ret_on_failure) \ 122 | return FALSE; \ 123 | } while (0) 124 | 125 | #define DLL_LOAD_FUNC(dll, name, ret_on_failure) \ 126 | DLL_LOAD_FUNC_PREFIXNAME(dll, name, name, ret_on_failure) 127 | #define DLL_LOAD_FUNC_PREFIXED(dll, prefix, name, ret_on_failure) \ 128 | DLL_LOAD_FUNC_PREFIXNAME(dll, prefix##name, name, ret_on_failure) 129 | --------------------------------------------------------------------------------