early-access version 1701

This commit is contained in:
pineappleEA 2021-05-21 07:39:33 +02:00
parent f11e1d29de
commit 9256601d27
199 changed files with 15535 additions and 7268 deletions

View file

@ -1,7 +1,7 @@
yuzu emulator early access
=============
This is the source code for early-access 1700.
This is the source code for early-access 1701.
## Legal Notice

View file

@ -48,7 +48,7 @@ if(WIN32 OR CYGWIN)
libusb/libusb/os/threads_windows.c
libusb/libusb/os/windows_winusb.c
libusb/libusb/os/windows_usbdk.c
libusb/libusb/os/windows_nt_common.c
libusb/libusb/os/windows_common.c
)
set(OS_WINDOWS TRUE)
elseif(APPLE)
@ -105,7 +105,7 @@ endif()
if(UNIX)
target_sources(usb PRIVATE
libusb/libusb/os/poll_posix.c
libusb/libusb/os/events_posix.c
libusb/libusb/os/threads_posix.c
)
find_package(Threads REQUIRED)
@ -118,7 +118,7 @@ if(UNIX)
set(THREADS_POSIX TRUE)
elseif(WIN32)
target_sources(usb PRIVATE
libusb/libusb/os/poll_windows.c
libusb/libusb/os/events_windows.c
libusb/libusb/os/threads_windows.c
)
endif()

View file

@ -1,11 +1,7 @@
*.sh eol=lf
*.ac eol=lf
*.am eol=lf
*.dsw eol=crlf
*.dsp eol=crlf whitespace=space-before-tab
*.sln eol=crlf
*.vcproj eol=crlf
*.vcxproj* eol=crlf
*.bat eol=crlf
*.sh eol=lf
.gitattributes export-ignore
.gitignore export-ignore
INSTALL_WIN.txt eol=crlf

View file

@ -2,6 +2,7 @@
.libs
Makefile
Makefile.in
!doc/Makefile.in
*.la
*.lo
*.o
@ -37,14 +38,17 @@ examples/hotplugtest
examples/sam3u_benchmark
examples/testlibusb
tests/stress
android/libs
android/obj
*.exe
*.pc
doc/html
doc/api-1.0
*.plg
*.ncb
*.opt
Debug
Release
*.db
*.user
*.suo
*.sdf
@ -54,7 +58,11 @@ Release
*.orig
.dirstamp
.amend
.DS_Store
Xcode/build
xcshareddata
xcuserdata
*.xcuserdatad
*.xccheckout
*.xcscmblueprint
*.xcworkspace

View file

@ -0,0 +1,22 @@
#!/bin/bash
set -eu
buildsys="${1}-${Platform}"
if [ "${buildsys}" == "MinGW-Win32" ]; then
export PATH="/c/mingw-w64/i686-6.3.0-posix-dwarf-rt_v5-rev1/mingw32/bin:${PATH}"
elif [ "${buildsys}" == "MinGW-x64" ]; then
export PATH="/c/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin:${PATH}"
fi
builddir="build-${buildsys}"
installdir="${PWD}/libusb-${buildsys}"
cd libusb
echo "Bootstrapping ..."
./bootstrap.sh
echo ""
exec .private/ci-build.sh --build-dir "${builddir}" --install -- "--prefix=${installdir}"

67
externals/libusb/libusb/.private/ci-build.sh vendored Executable file
View file

@ -0,0 +1,67 @@
#!/bin/bash
set -e
builddir=
install=no
while [ $# -gt 0 ]; do
case "$1" in
--build-dir)
if [ $# -lt 2 ]; then
echo "ERROR: missing argument for --build-dir option" >&2
exit 1
fi
builddir=$2
shift 2
;;
--install)
install=yes
shift
;;
--)
shift
break;
;;
*)
echo "ERROR: Unexpected argument: $1" >&2
exit 1
esac
done
if [ -z "${builddir}" ]; then
echo "ERROR: --build-dir option not specified" >&2
exit 1
fi
if [ -e "${builddir}" ]; then
echo "ERROR: directory entry named '${builddir}' already exists" >&2
exit 1
fi
mkdir "${builddir}"
cd "${builddir}"
cflags="-O2"
# enable extra warnings
cflags+=" -Winline"
cflags+=" -Wmissing-include-dirs"
cflags+=" -Wnested-externs"
cflags+=" -Wpointer-arith"
cflags+=" -Wredundant-decls"
cflags+=" -Wswitch-enum"
echo ""
echo "Configuring ..."
CFLAGS="${cflags}" ../configure --enable-examples-build --enable-tests-build "$@"
echo ""
echo "Building ..."
make -j4 -k
if [ "${install}" = "yes" ]; then
echo ""
echo "Installing ..."
make install
fi

View file

@ -14,6 +14,10 @@
# derivative branch, such as one you would create for private development.
#
if [ -n "$LIBUSB_SKIP_NANO" ]; then
exit 0
fi
case "$1" in
amend)
# Check if a .amend exists. If none, create one and warn user to re-commit.

View file

@ -26,6 +26,10 @@
BRANCH_OFFSET=10000
################################################################################
if [ -n "$LIBUSB_SKIP_NANO" ]; then
exit 0
fi
if [ "$BASH_VERSION" = '' ]; then
TYPE_CMD="type git >/dev/null 2>&1"
else

View file

@ -2,7 +2,7 @@
*********************************************************************
* The latest version of this snapshot can always be downloaded at: *
* https://sourceforge.net/projects/libusb/files/ *
* https://github.com/libusb/libusb/releases *
*********************************************************************
o Visual Studio:
@ -24,24 +24,6 @@ o Visual Studio:
remember that you need to have a copy of the DLL either in the runtime
directory or in system32
o WDK/DDK:
- The following is an example of a sources files that you can use to compile
a libusb 1.0 based console application. In this sample ..\libusb\ is the
directory where you would have copied libusb.h as well as the relevant
libusb-1.0.lib
TARGETNAME=your_app
TARGETTYPE=PROGRAM
USE_MSVCRT=1
UMTYPE=console
INCLUDES=..\libusb;$(DDK_INC_PATH)
TARGETLIBS=..\libusb\libusb-1.0.lib
SOURCES=your_app.c
- Note that if you plan to use libCMT instead of MSVCRT (USE_LIBCMT=1 instead
of USE_MSVCRT=1), you will need to recompile libusb to use libCMT. This can
easily be achieved, in the DDK environment, by running 'ddk_build /MT'
o MinGW/cygwin
- Copy libusb.h, from include/libusb-1.0/ to your default include directory,
and copy the MinGW32/ or MinGW64/ .a files to your default library directory.
@ -55,6 +37,9 @@ o Additional information:
- For some libusb samples (including source), please have a look in examples/
- For additional information on the libusb 1.0 Windows backend please visit:
http://windows.libusb.info
- Using the UsbDk backend is now a run-time choice rather than a compile-time
choice. For additional information, including example usage, please visit:
http://windows.libusb.info/#Driver_Installation
- The MinGW and MS generated DLLs are fully interchangeable, provided that you
use the import libs provided or generate one from the .def also provided.
- If you find any issue, please visit http://libusb.info/ and check the

View file

@ -1,49 +1,59 @@
language: c
git:
depth: 1
matrix:
include:
- os: linux
dist: trusty
sudo: required
dist: focal
compiler: clang
- os: linux
dist: focal
compiler: gcc
- os: linux
dist: trusty
sudo: required
dist: bionic
compiler: clang
- os: osx
osx_image: xcode8
- os: linux
dist: bionic
compiler: gcc
- os: linux
dist: xenial
compiler: clang
- os: linux
dist: xenial
compiler: gcc
- os: osx
osx_image: xcode8
osx_image: xcode12.2
compiler: clang
- os: osx
osx_image: xcode7.1
compiler: gcc
- os: osx
osx_image: xcode7.1
osx_image: xcode11.3
compiler: clang
- os: osx
osx_image: beta-xcode6.2
compiler: gcc
- os: osx
osx_image: beta-xcode6.2
osx_image: xcode9.4
compiler: clang
addons:
homebrew:
update: true
brewfile: true
apt:
packages:
- autoconf
- automake
- libtool
- m4
- libudev-dev
sources:
- ubuntu-toolchain-r-test
- m4
homebrew:
packages:
- autoconf
- automake
- libtool
- m4
update: true
before_script:
- ./bootstrap.sh
script:
- ./autogen.sh && make clean && make
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./travis-autogen.sh --disable-udev && make clean && make ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cd Xcode && xcodebuild -project libusb.xcodeproj ; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then .private/ci-build.sh --build-dir build-netlink -- --disable-udev; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then .private/ci-build.sh --build-dir build-udev -- --enable-udev; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then .private/ci-build.sh --build-dir build; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then cd Xcode && xcodebuild -project libusb.xcodeproj; fi

View file

@ -11,11 +11,18 @@ Copyright © 2012-2013 Toby Gray <toby.gray@realvnc.com>
Copyright © 2013-2018 Chris Dickens <christopher.a.dickens@gmail.com>
Other contributors:
Aaron Luft
Adrian Bunk
Adrien Destugues
Akshay Jaggi
Alan Ott
Alan Stern
Aleksandr Mezin
Alexander Pyhalov
Alexander Schlarb
Alexander Stein
Alex Vatchenko
Andrew Aldridge
Andrew Fernandes
Andy Chunyu
Andy McFadden
@ -25,18 +32,25 @@ Anthony Clay
Antonio Ospite
Artem Egorkine
Aurelien Jarno
Axel Gembe
Aymeric Vincent
Baruch Siach
Bastien Nocera
Bei Zhang
Bence Csokas
Benjamin Dobell
Brent Rector
Carl Karsten
Chris Zhu
Christophe Zeitouny
Chunyu Xie
Colin Walters
Dave Camarillo
David Engraf
David Moore
Davidlohr Bueso
David Moore
Dmitry Fleytman
Dmitry Kostjuchenko
Doug Johnston
Evan Hunter
Federico Manzan
@ -44,60 +58,85 @@ Felipe Balbi
Florian Albrechtskirchinger
Francesco Montorsi
Francisco Facioni
Frank Li
Frederik Carlier
Gaurav Gupta
Graeme Gill
Greg Kroah-Hartman
Gustavo Zacarias
Hans Ulrich Niedermann
Harry Mallon
Hector Martin
Hoi-Ho Chan
Ido Yariv
Igor Anokhin
Ihor Dutchak
Ilya Konstantinov
Jakub Klama
James Hanko
Jeffrey Nichols
Jie Zhang
Johann Richard
John Keeping
John Sheu
Jonas Malaco
Jonathon Jongsma
Joost Muller
Josh Gao
Joshua Blake
Joshua Hou
Juan Cruz Viotti
Justin Bischoff
KIMURA Masaru
Karsten Koenig
Kenjiro Tsuji
KIMURA Masaru
Konrad Rzepecki
Kuangye Guo
Lars Kanis
Lars Wirzenius
Lei Chen
Léo Lam
Luca Longinotti
Marcus Meissner
Markus Heidelberg
Martin Ettl
Martin Koegler
Martin Thierer
Matthew Stapleton
Matthias Bolte
Michel Zou
Mike Frysinger
Mikhail Gusarov
Mikolaj Kucharski
Morgan Leborgne
Moritz Fischer
Ларионов Даниил
Nia Alarie
Nicholas Corgan
Omri Iluz
Orin Eman
Patrick Stewart
Paul Fertser
Paul Qureshi
Pekka Nikander
Philémon Favrod
Pino Toscano
Rob Walker
Romain Vimont
Roman Kalashnikov
Saleem Rashid
Sameeh Jubran
Sean McBride
Sebastian Pipping
Sebastian von Ohr
Sergey Serb
Simon Haggett
Simon Newton
Slash Gordon
Stefan Agner
Stefan Tauner
Steinar H. Gunderson
Stephen Groat
Theo Buehler
Thomas Röfer
Tim Hutt
Tim Roberts
@ -106,14 +145,25 @@ Toby Peterson
Tormod Volden
Trygve Laugstøl
Uri Lublin
Uwe Bonnes
Vasily Khoruzhick
Vegard Storheil Eriksen
Venkatesh Shukla
Vianney le Clément de Saint-Marcq
Victor Toso
Vinicius Tinti
Vitali Lovich
Vladimir Beloborodov
William Orr
William Skellenger
Xiaofan Chen
Zhiqiang Liu
Zoltán Kovács
Сергей Валерьевич
Ларионов Даниил
Роман Донченко
liangyunwang
parafin
RipleyTom
saur0n
winterrace

View file

@ -1,6 +1,30 @@
For detailed information about the changes below, please see the git log or
visit: http://log.libusb.info
2020-12-09: v1.0.24
* Add new platform abstraction (#252)
* Add Null POSIX backend
* Add support for eventfd
* Add support for thread IDs on Haiku, NetBSD and Solaris
* New API libusb_hotplug_get_user_data()
* Darwin (macOS): Fix race condition that results in segmentation fault (#701)
* Darwin (macOS): Fix stale descriptor information post reset (#733)
* Darwin (macOS): use IOUSBDevice as darwin_device_class explicitly (#693)
* Linux: Drop support for kernel older than 2.6.32
* Linux: Provide an event thread name (#689)
* Linux: Wait until all USBs have been reaped before freeing them (#607)
* NetBSD: Recognize device timeouts (#710)
* OpenBSD: Allow opening ugen devices multiple times (#763)
* OpenBSD: Support libusb_get_port_number() (#764)
* SunOS: Fix a memory leak (#756)
* SunOS: Various fixes (#627, #628, #629)
* Windows: Add Visual Studio 2019 support
* Windows: Drop support for WinCE and Visual Studio older than 2013
* Windows: Drop support for Windows XP
* Windows: Support building all examples using Visual Studio (#151)
* Documentation fixes and improvements
* Various other bug fixes and improvements
2019-08-28: v1.0.23
* Add German translation (#446)
* Add Hungarian translation (#493)
@ -22,7 +46,7 @@ visit: http://log.libusb.info
* Windows: Add support for isochronous transfers with WinUSB
* Various other bug fixes and improvements
2018-03-24: v1.0.22:
2018-03-24: v1.0.22
* New libusb_set_option() API
* Fix transfer timeout not being cleared upon resubmission
* Report super speed plus devices on modern Linux and macOS
@ -40,7 +64,7 @@ visit: http://log.libusb.info
* Windows: Support cancelation of individual transfers (Vista and later)
* Various other bug fixes and improvements
2016-10-01: v1.0.21:
2016-10-01: v1.0.21
* Core: Refactor code related to transfer flags and timeout handling
* Darwin: Ignore root hub simulation devices
* Darwin: Improved support for OS X El Capitan

View file

@ -1,73 +1,51 @@
Installation Instructions for Windows
*************************************
If you are compiling for MinGW or cygwin, please refer to the INSTALL file.
If you are compiling for MinGW or cygwin, please refer to the INSTALL file,
which is automatically generated by autotools (e.g. running bootstrap.sh).
If you are using Microsoft Visual Studio:
- Open the relevant solution file in /msvc:
libusb.dsw for MSVC6, libusb_2005.sln for Visual Studio 2005 or 2008,
libusb_2010.sln for Visual Studio 2010,
libusb_2012.sln for Visual Studio 2012 or later,
libusb_wince.sln for Windows CE support in Visual Studio 2005.
libusb_2013.sln for Visual Studio 2013,
libusb_2015.sln for Visual Studio 2015,
libusb_2017.sln for Visual Studio 2017,
libusb_2019.sln for Visual Studio 2019 or later.
- If you want to debug the library, uncomment the ENABLE_DEBUG_LOGGING define
in msvc\config.h
- Select your configuration and compile the project
Note that if you are using Visual Studio Express, you may have to install the
Windows SDK to be able to compile the 64 bit version of the library.
Installing and building libusb via vcpkg
****************************************
If you are using the freely available Windows DDK/WDK (Driver Development Kit)
- If you want to debug the library, uncomment the ENABLE_DEBUG_LOGGING define
in msvc\config.h
- Open one of the relevant Free Build or Checked Build prompt for your target
platform
- Navigate to the msvc\ directory where the ddk_build.cmd file is located, and
run 'ddk_build'
- To produce a DLL rather than a static library, use: 'ddk_build DLL'
- To produce a static library that uses LIBCMT[d] instead of MSVCRT[d] (/MT[d]
vs /MD[d] in Visual Studio) use: 'ddk_build /MT'
You can download and install libusb using the vcpkg dependency manager:
Note that using the Windows DDK, it is possible to compile both the 32 and 64
bit versions of the library.
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
./vcpkg integrate install
vcpkg install libusb
If you are building for Windows CE then you will need the Windows CE Standard 5.00 SDK.
The libusb port in vcpkg is kept up to date by Microsoft team members and
community contributors. If the version is out of date, please create an issue
or pull request (https://github.com/Microsoft/vcpkg) on the vcpkg repository.
Destination directories
***********************
The 32 bit binaries compiled either from Visual Studio or the DDK are placed in
a Win32\ directory at the root of the library
The 64 bit binaries are placed in an x64\ directory
Windows CE binaries are placed in one of the following directories, depending
on the target processor: ARMV4I, MIPSII, MIPSII_FP, MIPSIV, MIPSIV_FP, SH4 or x86.
The 32-bit binaries are placed in a Win32\ directory at the root of the
library.
The 64-bit binaries are placed in a x64\ directory.
Troubleshooting
***************
If the compilation process complains about missing libraries, ensure that the
default library paths for your project points to the relevant directories.
If needed, these libraries can be obtained by installing either the latest
Windows SDK or the DDK (Links provided at the end of this file).
For Windows CE it is necessary to install the CE USB Kernel Wrapper driver for
libusb to function on a device.
If needed, these libraries can be obtained by installing the latest Windows
SDK.
Links
*****
Additional information related to the Windows backend:
http://windows.libusb.info
Latest Windows Driver (Development) Kit (WDK):
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=36a2630f-5d56-43b5-b996-7633f2ec14ff
Latest Microsoft Windows SDK:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505
Windows CE Standard 5.00 SDK:
http://www.microsoft.com/en-gb/download/details.aspx?id=17310
Windows CE USB Kernel Wrapper Driver:
https://github.com/RealVNC/CEUSBKWrapper

View file

@ -1,10 +1,8 @@
AUTOMAKE_OPTIONS = dist-bzip2 no-dist-gzip
ACLOCAL_AMFLAGS = -I m4
DISTCLEANFILES = libusb-1.0.pc
EXTRA_DIST = TODO PORTING msvc libusb/libusb-1.0.def libusb/version_nano.h \
examples/getopt/getopt.c examples/getopt/getopt1.c examples/getopt/getopt.h \
android Xcode
SUBDIRS = libusb doc
EXTRA_DIST = INSTALL_WIN.txt PORTING doc/libusb.png \
android msvc Xcode
SUBDIRS = libusb
if BUILD_EXAMPLES
SUBDIRS += examples
@ -14,15 +12,39 @@ if BUILD_TESTS
SUBDIRS += tests
endif
pkgconfigdir=$(libdir)/pkgconfig
pkgconfig_DATA=libusb-1.0.pc
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libusb-1.0.pc
.PHONY: dist-up
# The package name is libusb-1.0, but we want the distribution
# to be created as libusb-x.y.z instead of libusb-1.0-x.y.z
distdir = libusb-$(VERSION)
# Ensure any generated docs are cleaned out
# We need this here because make does not recurse into doc/
clean-local:
rm -rf doc/$(DOXYGEN_HTMLDIR)
# Use dist-hook to accomplish the following things for the dist recipe:
# 1) Remove the GitHub Markdown from the README file
# 2) Remove the .gitattributes file from the msvc directory
dist-hook:
chmod u+w $(distdir)/README $(distdir)/msvc
$(SED) -i.orig -e '/Build Status/d' $(distdir)/README
$(SED) -i.orig -e '/^$$/N;/^\n$$/D' $(distdir)/README
$(SED) -i.orig -e 's/\[\([A-Z]*\)\](\1)/\1/' $(distdir)/README
rm -f $(distdir)/README.orig
rm -f $(distdir)/msvc/.gitattributes
reldir = .release/$(distdir)
dist-up: dist
sfurl = frs.sourceforge.net:/home/frs/project/libusb/libusb-1.0
.PHONY: dist-upload
dist-upload: dist
rm -rf $(reldir)
mkdir -p $(reldir)
cp $(distdir).tar.bz2 $(reldir)
rsync -rv $(reldir) frs.sourceforge.net:/home/frs/project/l/li/libusb/libusb-1.0/
if [ -z "$$SF_USER" ]; then \
rsync -rv $(reldir) $(sfurl); \
else \
rsync -rv $(reldir) $$SF_USER@$(sfurl); \
fi
rm -rf $(reldir)

View file

@ -1,11 +1,11 @@
# libusb
[![Build Status](https://travis-ci.org/libusb/libusb.svg?branch=master)](https://travis-ci.org/libusb/libusb)
[![Build status](https://ci.appveyor.com/api/projects/status/xvrfam94jii4a6lw?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/libusb)
[![Build Status](https://ci.appveyor.com/api/projects/status/xvrfam94jii4a6lw?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/libusb)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/2180/badge.svg)](https://scan.coverity.com/projects/libusb-libusb)
libusb is a library for USB device access from Linux, macOS,
Windows, OpenBSD/NetBSD and Haiku userspace.
Windows, OpenBSD/NetBSD, Haiku and Solaris userspace.
It is written in C (Haiku backend in C++) and licensed under the GNU
Lesser General Public License version 2.1 or, at your option, any later
version (see [COPYING](COPYING)).

View file

@ -1,11 +1,11 @@
# libusb
[![Build Status](https://travis-ci.org/libusb/libusb.svg?branch=master)](https://travis-ci.org/libusb/libusb)
[![Build status](https://ci.appveyor.com/api/projects/status/xvrfam94jii4a6lw?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/libusb)
[![Build Status](https://ci.appveyor.com/api/projects/status/xvrfam94jii4a6lw?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/libusb)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/2180/badge.svg)](https://scan.coverity.com/projects/libusb-libusb)
libusb is a library for USB device access from Linux, macOS,
Windows, OpenBSD/NetBSD and Haiku userspace.
Windows, OpenBSD/NetBSD, Haiku and Solaris userspace.
It is written in C (Haiku backend in C++) and licensed under the GNU
Lesser General Public License version 2.1 or, at your option, any later
version (see [COPYING](COPYING)).

View file

@ -17,45 +17,49 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// libusb does not follow C99 strict aliasing rules, so disable it.
GCC_STRICT_ALIASING = NO
// Use C99 dialect.
GCC_C_LANGUAGE_STANDARD = c99
// Use GNU11 dialect.
GCC_C_LANGUAGE_STANDARD = gnu11
// Don't search user paths with <> style #includes.
ALWAYS_SEARCH_USER_PATHS = NO
// Enable weak references for Objective-C
CLANG_ENABLE_OBJC_WEAK = YES
// Compiler errors.
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES
// Compiler warnings.
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
GCC_WARN_ABOUT_RETURN_TYPE = YES
GCC_WARN_UNINITIALIZED_AUTOS = YES
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
GCC_WARN_SHADOW = YES
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
GCC_WARN_ABOUT_RETURN_TYPE = YES
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
GCC_WARN_SHADOW = YES
GCC_WARN_UNINITIALIZED_AUTOS = YES
GCC_WARN_UNKNOWN_PRAGMAS = YES
GCC_WARN_UNUSED_FUNCTION = YES
GCC_WARN_UNUSED_LABEL = YES
GCC_WARN_UNUSED_VARIABLE = YES
GCC_WARN_UNUSED_PARAMETER = YES
CLANG_WARN_EMPTY_BODY = YES
CLANG_WARN_CONSTANT_CONVERSION = YES
CLANG_WARN_ENUM_CONVERSION = YES
CLANG_WARN_INT_CONVERSION = YES
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
CLANG_WARN_BOOL_CONVERSION = YES
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES
CLANG_WARN_FLOAT_CONVERSION = YES
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES
CLANG_WARN_INFINITE_RECURSION = YES
GCC_WARN_UNUSED_VARIABLE = YES
CLANG_WARN_ASSIGN_ENUM = YES
CLANG_WARN_STRICT_PROTOTYPES = YES
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES
CLANG_WARN_BOOL_CONVERSION = YES
CLANG_WARN_COMMA = YES
CLANG_WARN_CONSTANT_CONVERSION = YES
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
CLANG_WARN_EMPTY_BODY = YES
CLANG_WARN_ENUM_CONVERSION = YES
CLANG_WARN_FLOAT_CONVERSION = YES
CLANG_WARN_INFINITE_RECURSION = YES
CLANG_WARN_INT_CONVERSION = YES
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES
CLANG_WARN_STRICT_PROTOTYPES = YES
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES
// Static analyzer warnings.
CLANG_ANALYZER_NONNULL = YES
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES

View file

@ -1,25 +1,37 @@
/* config.h. Manually generated for Xcode. */
/* Default visibility */
#define DEFAULT_VISIBILITY /**/
#include <AvailabilityMacros.h>
/* Message logging */
/* Define to the attribute for default visibility. */
#define DEFAULT_VISIBILITY __attribute__ ((visibility ("default")))
/* Define to 1 to enable message logging. */
#define ENABLE_LOGGING 1
/* Define to 1 if you have the <poll.h> header file. */
#define HAVE_POLL_H 1
/* On 10.12 and later, use newly available clock_*() functions */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
/* Define to 1 if you have the `clock_gettime' function. */
#define HAVE_CLOCK_GETTIME 1
#endif
/* On 10.6 and later, use newly available pthread_threadid_np() function */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
/* Define to 1 if you have the 'pthread_threadid_np' function. */
#define HAVE_PTHREAD_THREADID_NP 1
#endif
/* Define to 1 if the system has the type `nfds_t'. */
#define HAVE_NFDS_T 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Darwin backend */
#define OS_DARWIN 1
/* Define to 1 if compiling for a POSIX platform. */
#define PLATFORM_POSIX 1
/* type of second poll() argument */
#define POLL_NFDS_TYPE nfds_t
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
#define PRINTF_FORMAT(a, b) __attribute__ ((__format__ (__printf__, a, b)))
/* Use POSIX Threads */
#define THREADS_POSIX 1
/* Use GNU extensions */
/* Enable GNU extensions. */
#define _GNU_SOURCE 1

File diff suppressed because it is too large Load diff

View file

@ -17,59 +17,39 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Start with debug message logging enabled */
/* Define to the attribute for default visibility. */
#define DEFAULT_VISIBILITY __attribute__ ((visibility ("default")))
/* Define to 1 to start with debug message logging enabled. */
/* #undef ENABLE_DEBUG_LOGGING */
/* Message logging */
#define ENABLE_LOGGING
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Linux backend */
#define OS_LINUX 1
/* Enable output to system log */
#define USE_SYSTEM_LOGGING_FACILITY 1
/* type of second poll() argument */
#define POLL_NFDS_TYPE nfds_t
/* Use POSIX Threads */
#define THREADS_POSIX 1
/* Default visibility */
#define DEFAULT_VISIBILITY __attribute__((visibility("default")))
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <poll.h> header file. */
#define HAVE_POLL_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the <linux/filter.h> header file. */
#define HAVE_LINUX_FILTER_H 1
/* Define to 1 if you have the <linux/netlink.h> header file. */
#define HAVE_LINUX_NETLINK_H 1
/* Define to 1 to enable message logging. */
#define ENABLE_LOGGING 1
/* Define to 1 if you have the <asm/types.h> header file. */
#define HAVE_ASM_TYPES_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the `clock_gettime' function. */
#define HAVE_CLOCK_GETTIME 1
/* Define to 1 if the system has the type `nfds_t'. */
#define HAVE_NFDS_T 1
/* Define to 1 if you have the `pipe2' function. */
#define HAVE_PIPE2 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if compiling for a POSIX platform. */
#define PLATFORM_POSIX 1
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
#define PRINTF_FORMAT(a, b) __attribute__ ((__format__ (__printf__, a, b)))
/* Define to 1 to output logging messages to the systemwide log. */
#define USE_SYSTEM_LOGGING_FACILITY 1
/* Enable GNU extensions. */
#define _GNU_SOURCE 1

View file

@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH:= $(call my-dir)
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/libusb.mk
include $(LOCAL_PATH)/examples.mk

View file

@ -18,6 +18,22 @@
APP_ABI := all
APP_CFLAGS := \
-std=gnu11 \
-Wall \
-Wextra \
-Wshadow \
-Wunused \
-Wwrite-strings \
-Werror=format-security \
-Werror=implicit-function-declaration \
-Werror=implicit-int \
-Werror=init-self \
-Werror=missing-prototypes \
-Werror=strict-prototypes \
-Werror=undef \
-Werror=uninitialized
# Workaround for MIPS toolchain linker being unable to find liblog dependency
# of shared object in NDK versions at least up to r9.
#

View file

@ -16,39 +16,61 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH:= $(call my-dir)
LIBUSB_ROOT_REL:= ../..
LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
LOCAL_PATH := $(call my-dir)
LIBUSB_ROOT_REL := ../..
LIBUSB_ROOT_ABS := $(LOCAL_PATH)/../..
# listdevs
# dpfp
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/listdevs.c
$(LIBUSB_ROOT_REL)/examples/dpfp.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE:= listdevs
LOCAL_MODULE := dpfp
include $(BUILD_EXECUTABLE)
# xusb
# dpfp_threaded
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/xusb.c
$(LIBUSB_ROOT_REL)/examples/dpfp.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_CFLAGS := -DDPFP_THREADED -pthread
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE := dpfp_threaded
include $(BUILD_EXECUTABLE)
# fxload
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/ezusb.c \
$(LIBUSB_ROOT_REL)/examples/fxload.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE:= xusb
LOCAL_MODULE := fxload
include $(BUILD_EXECUTABLE)
@ -60,32 +82,33 @@ LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/hotplugtest.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE:= hotplugtest
LOCAL_MODULE := hotplugtest
include $(BUILD_EXECUTABLE)
# fxload
# listdevs
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/fxload.c \
$(LIBUSB_ROOT_REL)/examples/ezusb.c
$(LIBUSB_ROOT_REL)/examples/listdevs.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE:= fxload
LOCAL_MODULE := listdevs
include $(BUILD_EXECUTABLE)
# sam3u_benchmake
# sam3u_benchmark
include $(CLEAR_VARS)
@ -93,42 +116,28 @@ LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/sam3u_benchmark.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE:= sam3u_benchmark
LOCAL_MODULE := sam3u_benchmark
include $(BUILD_EXECUTABLE)
# dpfp
# xusb
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/dpfp.c
$(LIBUSB_ROOT_REL)/examples/xusb.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE:= dpfp
include $(BUILD_EXECUTABLE)
# dpfp_threaded
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/dpfp_threaded.c
LOCAL_C_INCLUDES += \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_MODULE:= dpfp_threaded
LOCAL_MODULE := xusb
include $(BUILD_EXECUTABLE)

View file

@ -16,17 +16,14 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH:= $(call my-dir)
LIBUSB_ROOT_REL:= ../..
LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
LOCAL_PATH := $(call my-dir)
LIBUSB_ROOT_REL := ../..
LIBUSB_ROOT_ABS := $(LOCAL_PATH)/../..
# libusb
include $(CLEAR_VARS)
LIBUSB_ROOT_REL:= ../..
LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/libusb/core.c \
$(LIBUSB_ROOT_REL)/libusb/descriptor.c \
@ -35,7 +32,7 @@ LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/libusb/sync.c \
$(LIBUSB_ROOT_REL)/libusb/strerror.c \
$(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c \
$(LIBUSB_ROOT_REL)/libusb/os/poll_posix.c \
$(LIBUSB_ROOT_REL)/libusb/os/events_posix.c \
$(LIBUSB_ROOT_REL)/libusb/os/threads_posix.c \
$(LIBUSB_ROOT_REL)/libusb/os/linux_netlink.c
@ -47,6 +44,8 @@ LOCAL_C_INCLUDES += \
LOCAL_EXPORT_C_INCLUDES := \
$(LIBUSB_ROOT_ABS)/libusb
LOCAL_CFLAGS := -fvisibility=hidden -pthread
LOCAL_LDLIBS := -llog
LOCAL_MODULE := libusb1.0

View file

@ -16,41 +16,24 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH:= $(call my-dir)
LIBUSB_ROOT_REL:= ../..
LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
# testlib
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/tests/testlib.c
LOCAL_C_INCLUDES += \
$(LIBUSB_ROOT_ABS)/tests
LOCAL_EXPORT_C_INCLUDES := \
$(LIBUSB_ROOT_ABS)/tests
LOCAL_MODULE := testlib
include $(BUILD_STATIC_LIBRARY)
LOCAL_PATH := $(call my-dir)
LIBUSB_ROOT_REL := ../..
LIBUSB_ROOT_ABS := $(LOCAL_PATH)/../..
# stress
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/tests/stress.c
$(LIBUSB_ROOT_REL)/tests/stress.c \
$(LIBUSB_ROOT_REL)/tests/testlib.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_STATIC_LIBRARIES += testlib
LOCAL_MODULE:= stress
LOCAL_MODULE := stress
include $(BUILD_EXECUTABLE)

View file

@ -1,41 +1,72 @@
version: 1.0.{build}
configuration:
- Debug
- Release
image:
- Visual Studio 2013
- Visual Studio 2015
- Visual Studio 2017
- Visual Studio 2019
platform:
- x64
- Win32
- Win32
- x64
configuration:
- Debug
- Release
clone_depth: 1
build:
project: msvc\libusb_2013.sln
parallel: true
verbosity: detailed
environment:
for:
-
matrix:
- libusb_2015: msvc\libusb_2015.sln
libusb_2013: msvc\libusb_2013.sln
libusb_2012: msvc\libusb_2012.sln
libusb_2010: msvc\libusb_2010.sln
install:
only:
- image: Visual Studio 2013
build:
project: msvc\libusb_2013.sln
- cmd: >-
rem Copying libusb to cygwin home directory
-
matrix:
only:
- image: Visual Studio 2015
configuration: Debug
build:
project: msvc\libusb_2015.sln
xcopy /S C:\projects\libusb C:\cygwin\home\appveyor\
-
matrix:
only:
- image: Visual Studio 2015
platform: Win32
configuration: Release
install:
- cmd: xcopy /S /I "%APPVEYOR_BUILD_FOLDER%" C:\msys64\home\appveyor\libusb
- cmd: xcopy /S /I "%APPVEYOR_BUILD_FOLDER%" C:\cygwin\home\appveyor\libusb
build_script:
- cmd: msbuild "%APPVEYOR_BUILD_FOLDER%\msvc\libusb_2015.sln" /m /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- cmd: C:\msys64\usr\bin\bash -l "%APPVEYOR_BUILD_FOLDER%\.private\appveyor_build.sh" MinGW
- cmd: C:\cygwin\bin\bash -l "%APPVEYOR_BUILD_FOLDER%\.private\appveyor_build.sh" cygwin
rem Copying libusb to MinGW home directory
-
matrix:
only:
- image: Visual Studio 2015
platform: x64
configuration: Release
install:
- cmd: xcopy /S /I "%APPVEYOR_BUILD_FOLDER%" C:\msys64\home\appveyor\libusb
- cmd: xcopy /S /I "%APPVEYOR_BUILD_FOLDER%" C:\cygwin64\home\appveyor\libusb
build_script:
- cmd: msbuild "%APPVEYOR_BUILD_FOLDER%\msvc\libusb_2015.sln" /m /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- cmd: C:\msys64\usr\bin\bash -l "%APPVEYOR_BUILD_FOLDER%\.private\appveyor_build.sh" MinGW
- cmd: C:\cygwin64\bin\bash -l "%APPVEYOR_BUILD_FOLDER%\.private\appveyor_build.sh" cygwin
xcopy /S C:\projects\libusb C:\msys64\home\appveyor\
-
matrix:
only:
- image: Visual Studio 2017
build:
project: msvc\libusb_2017.sln
build_script:
- cmd: >-
msbuild %libusb_2015% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
msbuild %libusb_2013% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
msbuild %libusb_2012% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
msvc/appveyor.bat
appveyor_minGW.bat
appveyor_cygwin.bat
-
matrix:
only:
- image: Visual Studio 2019
build:
project: msvc\libusb_2019.sln

View file

@ -3,6 +3,6 @@
set -e
./bootstrap.sh
if test -z "$NOCONFIGURE"; then
if [ -z "$NOCONFIGURE" ]; then
exec ./configure --enable-examples-build --enable-tests-build "$@"
fi

View file

@ -1,6 +1,8 @@
#!/bin/sh
if ! test -d m4 ; then
set -e
if [ ! -d m4 ]; then
mkdir m4
fi
autoreconf -ivf || exit 1
exec autoreconf -ivf

View file

@ -15,312 +15,365 @@ LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])
AC_INIT([libusb],[LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC],[libusb-devel@lists.sourceforge.net],[libusb],[http://libusb.info])
# Library versioning
# These numbers should be tweaked on every release. Read carefully:
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
# http://sourceware.org/autobook/autobook/autobook_91.html
lt_current=2
lt_revision=0
lt_age=2
LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
AM_INIT_AUTOMAKE
AC_PREREQ([2.69])
AC_INIT([libusb-1.0], [LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC], [libusb-devel@lists.sourceforge.net], [libusb-1.0], [http://libusb.info])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([libusb/core.c])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
AC_PREREQ([2.69])
AC_PROG_CC
AC_PROG_CXX
AC_C_INLINE
AM_INIT_AUTOMAKE
LT_INIT
LT_LANG([Windows Resource])
AC_C_INLINE
AM_PROG_CC_C_O
AC_DEFINE([_GNU_SOURCE], 1, [Use GNU extensions])
LTLDFLAGS="${LTLDFLAGS} -no-undefined"
dnl Library versioning
dnl These numbers should be tweaked on every release. Read carefully:
dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
dnl http://sourceware.org/autobook/autobook/autobook_91.html
lt_current=3
lt_revision=0
lt_age=3
LT_LDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age} -no-undefined"
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
EXTRA_CPPFLAGS=
EXTRA_CFLAGS=
dnl check for -std=gnu11 compiler support (optional)
dnl note that we don't just check if the compiler accepts '-std=x11'
dnl but also that it supports the _Thread_local keyword because some compilers
dnl (e.g. gcc 4.8) accept the command line option but do not implement TLS
saved_CFLAGS="${CFLAGS}"
CFLAGS="-std=gnu11"
AC_MSG_CHECKING([if $CC supports -std=gnu11])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
[AC_MSG_RESULT([yes])
c_dialect=gnu],
[AC_MSG_RESULT([no])
c_dialect=])
if test "x$c_dialect" != xgnu; then
dnl fallback check for -std=c11 compiler support (required)
CFLAGS="-std=c11"
AC_MSG_CHECKING([if $CC supports -std=c11])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([compiler with C11 support is required to build libusb])])
c_dialect=c
fi
CFLAGS="${saved_CFLAGS}"
AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.])
AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.])
AC_DEFINE([PRINTF_FORMAT(a, b)], [__attribute__ ((__format__ (__printf__, a, b)))], [Define to the attribute for enabling parameter checks on printf-like functions.])
create_import_lib=
is_android_linux=
AC_MSG_CHECKING([operating system])
dnl on linux-android platform, some functions are in different places
case $host in
*-linux-android*)
AC_MSG_RESULT([This is a Linux-Android system])
is_backend_android=yes
;;
*)
is_backend_android=no
esac
case $host in
*-linux* | *-uclinux*)
AC_MSG_RESULT([Linux])
backend=linux
threads=posix
;;
*-darwin*)
AC_MSG_RESULT([Darwin/Mac OS X])
backend=darwin
threads=posix
;;
*-openbsd*)
AC_MSG_RESULT([OpenBSD])
backend=openbsd
threads=posix
;;
*-netbsd*)
AC_MSG_RESULT([NetBSD])
backend=netbsd
threads=posix
;;
*-mingw* | *msys*)
AC_MSG_RESULT([Windows])
backend=windows
threads=windows
create_import_lib=yes
AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
;;
*-cygwin*)
AC_MSG_RESULT([Cygwin (using Windows backend)])
backend=windows
threads=posix
platform=posix
;;
*-haiku*)
AC_MSG_RESULT([Haiku])
backend=haiku
threads=posix
platform=posix
;;
*-linux* | *-uclinux*)
dnl on Android Linux, some functions are in different places
case $host in
*-linux-android*)
AC_MSG_RESULT([Android Linux])
is_android_linux=yes
;;
*)
AC_MSG_RESULT([Linux])
;;
esac
backend=linux
platform=posix
;;
*-netbsd*)
AC_MSG_RESULT([NetBSD])
backend=netbsd
platform=posix
;;
*-openbsd*)
AC_MSG_RESULT([OpenBSD])
backend=openbsd
platform=posix
;;
*-solaris*)
AC_MSG_RESULT([SunOS])
backend=sunos
threads=posix
platform=posix
;;
*-cygwin*)
AC_MSG_RESULT([Windows (using Cygwin)])
backend=windows
platform=windows
EXTRA_CFLAGS="-mwin32"
;;
*-mingw* | *msys*)
AC_MSG_RESULT([Windows])
backend=windows
platform=windows
test "x$enable_shared" = xyes && create_import_lib=yes
EXTRA_CFLAGS="-mwin32 -fno-omit-frame-pointer"
;;
*)
AC_MSG_ERROR([unsupported operating system $host])
AC_MSG_RESULT([Null])
AC_MSG_WARN([The host being compiled for is not supported.])
AC_MSG_WARN([The library may compile but will not function in any useful manner.])
backend=null
platform=posix
;;
esac
if test "x$platform" = xposix; then
AC_DEFINE([PLATFORM_POSIX], [1], [Define to 1 if compiling for a POSIX platform.])
AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]])
AC_CHECK_FUNCS([pipe2])
dnl Some compilers do not support the '-pthread' option so check for it here
saved_CFLAGS="${CFLAGS}"
CFLAGS="-Wall -Werror -pthread"
AC_MSG_CHECKING([if $CC recognizes -pthread])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
[AC_MSG_RESULT([yes])
AC_SUBST(THREAD_CFLAGS, [-pthread])],
[AC_MSG_RESULT([no])])
CFLAGS="${saved_CFLAGS}"
dnl Android Linux and Darwin provide pthread functions directly in libc
dnl glibc also provides some pthread functions directly, so search for a thread-specific function
AC_SEARCH_LIBS([pthread_create], [pthread],
[test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])],
[], [])
elif test "x$platform" = xwindows; then
AC_DEFINE([PLATFORM_WINDOWS], [1], [Define to 1 if compiling for a Windows platform.])
else
AC_MSG_ERROR([Unknown platform])
fi
case $backend in
linux)
AC_DEFINE(OS_LINUX, 1, [Linux backend])
AC_SUBST(OS_LINUX)
AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [-pthread])
AC_ARG_ENABLE([udev],
[AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
[], [enable_udev=yes])
if test "x$enable_udev" = xyes ; then
# system has udev. use it or fail!
AC_CHECK_HEADERS([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
AC_DEFINE(USE_UDEV, 1, [Use udev for device enumeration/hotplug])
else
AC_CHECK_HEADERS([asm/types.h], [], [])
AC_CHECK_HEADERS([sys/socket.h linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink headers not found])], [
#ifdef HAVE_ASM_TYPES_H
#include <asm/types.h>
#endif
#include <sys/socket.h>
])
fi
AC_SUBST(USE_UDEV)
if test "x$is_backend_android" != xyes; then
THREAD_CFLAGS="-pthread"
LIBS="${LIBS} -pthread"
fi
AC_CHECK_HEADERS([poll.h])
AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
;;
darwin)
AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
AC_SUBST(OS_DARWIN)
LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
AC_CHECK_HEADERS([poll.h])
AC_CHECK_TYPE([nfds_t],
[AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
[AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
[#include <poll.h>])
;;
openbsd)
AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
AC_SUBST(OS_OPENBSD)
THREAD_CFLAGS="-pthread"
LIBS="-pthread"
AC_CHECK_HEADERS([poll.h])
AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
;;
sunos)
AC_DEFINE(OS_SUNOS, 1, [SunOS backend])
AC_SUBST(OS_SUNOS)
THREAD_CFLAGS="-pthread"
LIBS="-pthread -ldevinfo"
AC_CHECK_HEADERS([poll.h])
AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
;;
netbsd)
AC_DEFINE(OS_NETBSD, 1, [NetBSD backend])
AC_SUBST(OS_NETBSD)
THREAD_CFLAGS="-pthread"
LIBS="-pthread"
AC_CHECK_HEADERS([poll.h])
AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
;;
windows)
AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
AC_SUBST(OS_WINDOWS)
LIBS=""
LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
AC_DEFINE([WINVER], 0x0501, [Oldest Windows version supported])
AC_DEFINE([_WIN32_WINNT], 0x0501, [Oldest Windows version supported])
AC_CHECK_FUNCS([pthread_threadid_np])
LIBS="${LIBS} -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
;;
haiku)
AC_DEFINE(OS_HAIKU, 1, [Haiku backend])
AC_SUBST(OS_HAIKU)
LIBS="${LIBS} -lbe"
AC_CHECK_HEADERS([poll.h])
AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
;;
linux)
AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [])
AC_CHECK_FUNCS([pthread_setname_np])
AC_ARG_ENABLE([udev],
[AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
[use_udev=$enableval], [use_udev=yes])
if test "x$use_udev" = xyes; then
dnl system has udev. use it or fail!
AC_CHECK_HEADER([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
else
AC_CHECK_HEADERS([asm/types.h])
AC_CHECK_HEADER([linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink header not found])])
AC_CHECK_HEADER([sys/socket.h], [], [AC_MSG_ERROR([Linux socket header not found])])
fi
;;
sunos)
LIBS="${LIBS} -ldevinfo"
;;
windows)
AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Define to the oldest supported Windows version.])
LT_LDFLAGS="${LT_LDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
;;
*)
dnl no special handling required
;;
esac
AC_SUBST(LIBS)
dnl headers not available on all platforms but required on others
AC_CHECK_HEADERS([sys/time.h])
AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
AM_CONDITIONAL(OS_SUNOS, test "x$backend" = xsunos)
AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
AM_CONDITIONAL(OS_HAIKU, test "x$backend" = xhaiku)
AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = xyes)
AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
if test "x$threads" = xposix; then
AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
fi
# timerfd
AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
AC_ARG_ENABLE([timerfd],
[AS_HELP_STRING([--enable-timerfd],
[use timerfd for timing [default=auto]])],
[use_timerfd=$enableval], [use_timerfd=auto])
if test "x$use_timerfd" = xyes -a "x$timerfd_h" = x0; then
AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
fi
AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
if test "x$use_timerfd" = xyes -a "x$tfd_hdr_ok" = xno; then
AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
fi
AC_MSG_CHECKING([whether to use timerfd for timing])
if test "x$use_timerfd" = xno; then
AC_MSG_RESULT([no (disabled by user)])
else
if test "x$timerfd_h" = x1 -a "x$tfd_hdr_ok" = xyes; then
AC_MSG_RESULT([yes])
AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
else
AC_MSG_RESULT([no (header not available)])
if test "x$platform" = xposix; then
dnl the clock_gettime() function needs certain clock IDs defined
AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
if test "x$have_clock_gettime" = xyes; then
AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
dnl use the monotonic clock for condition variable timed waits if possible
AC_CHECK_FUNCS([pthread_condattr_setclock], [need_clock_realtime=], [need_clock_realtime=yes])
if test "x$need_clock_realtime" = xyes; then
AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
fi
elif test "x$backend" != xdarwin; then
AC_MSG_ERROR([clock_gettime() is required on this platform])
fi
fi
AC_CHECK_FUNCS([pipe2])
AC_CHECK_TYPES([struct timespec])
dnl eventfd support
if test "x$backend" = xlinux || test "x$backend" = xsunos; then
AC_ARG_ENABLE([eventfd],
[AS_HELP_STRING([--enable-eventfd], [use eventfd for signalling [default=auto]])],
[use_eventfd=$enableval],
[use_eventfd=auto])
if test "x$use_eventfd" != xno; then
AC_CHECK_HEADER([sys/eventfd.h], [eventfd_h=yes], [eventfd_h=])
if test "x$eventfd_h" = xyes; then
AC_CHECK_DECLS([EFD_NONBLOCK, EFD_CLOEXEC], [eventfd_h_ok=yes], [eventfd_h_ok=], [[#include <sys/eventfd.h>]])
if test "x$eventfd_h_ok" = xyes; then
AC_CHECK_FUNC([eventfd], [eventfd_ok=yes], [eventfd_ok=])
if test "x$eventfd_ok" = xyes; then
AC_DEFINE([HAVE_EVENTFD], [1], [Define to 1 if the system has eventfd functionality.])
elif test "x$use_eventfd" = xyes; then
AC_MSG_ERROR([eventfd() function not found; glibc 2.9+ required])
fi
elif test "x$use_eventfd" = xyes; then
AC_MSG_ERROR([eventfd header not usable; glibc 2.9+ required])
fi
elif test "x$use_eventfd" = xyes; then
AC_MSG_ERROR([eventfd header not available; glibc 2.9+ required])
fi
fi
AC_MSG_CHECKING([whether to use eventfd for signalling])
if test "x$use_eventfd" = xno; then
AC_MSG_RESULT([no (disabled by user)])
elif test "x$eventfd_h" != xyes; then
AC_MSG_RESULT([no (header not available)])
elif test "x$eventfd_h_ok" != xyes; then
AC_MSG_RESULT([no (header not usable)])
elif test "x$eventfd_ok" != xyes; then
AC_MSG_RESULT([no (functions not available)])
else
AC_MSG_RESULT([yes])
fi
fi
# Message logging
AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
dnl timerfd support
if test "x$backend" = xlinux || test "x$backend" = xsunos; then
AC_ARG_ENABLE([timerfd],
[AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])],
[use_timerfd=$enableval],
[use_timerfd=auto])
if test "x$use_timerfd" != xno; then
AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=])
if test "x$timerfd_h" = xyes; then
AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=], [[#include <sys/timerfd.h>]])
if test "x$timerfd_h_ok" = xyes; then
AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=])
if test "x$timerfd_ok" = xyes; then
AC_DEFINE([HAVE_TIMERFD], [1], [Define to 1 if the system has timerfd functionality.])
elif test "x$use_timerfd" = xyes; then
AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required])
fi
elif test "x$use_timerfd" = xyes; then
AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
fi
elif test "x$use_timerfd" = xyes; then
AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
fi
fi
AC_MSG_CHECKING([whether to use timerfd for timing])
if test "x$use_timerfd" = xno; then
AC_MSG_RESULT([no (disabled by user)])
elif test "x$timerfd_h" != xyes; then
AC_MSG_RESULT([no (header not available)])
elif test "x$timerfd_h_ok" != xyes; then
AC_MSG_RESULT([no (header not usable)])
elif test "x$timerfd_ok" != xyes; then
AC_MSG_RESULT([no (functions not available)])
else
AC_MSG_RESULT([yes])
fi
fi
dnl Message logging
AC_ARG_ENABLE([log],
[AS_HELP_STRING([--disable-log], [disable all logging])],
[log_enabled=$enableval],
[log_enabled=yes])
if test "x$log_enabled" != xno; then
AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
AC_DEFINE([ENABLE_LOGGING], [1], [Define to 1 to enable message logging.])
fi
AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
[start with debug message logging enabled [default=no]])],
AC_ARG_ENABLE([debug-log],
[AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])],
[debug_log_enabled=$enableval],
[debug_log_enabled=no])
if test "x$debug_log_enabled" != xno; then
AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to 1 to start with debug message logging enabled.])
fi
AC_ARG_ENABLE([system-log], [AS_HELP_STRING([--enable-system-log],
[output logging messages to system wide log, if supported by the OS [default=no]])],
AC_ARG_ENABLE([system-log],
[AS_HELP_STRING([--enable-system-log], [output logging messages to the systemwide log, if supported by the OS [default=no]])],
[system_log_enabled=$enableval],
[system_log_enabled=no])
if test "x$system_log_enabled" != xno; then
AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], 1, [Enable output to system log])
# Check if syslog is available in standard C library
AC_CHECK_HEADERS(syslog.h)
AC_CHECK_FUNC([syslog], [have_syslog=yes], [have_syslog=no])
if test "x$have_syslog" != xno; then
AC_DEFINE([HAVE_SYSLOG_FUNC], 1, [syslog() function available])
AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Define to 1 to output logging messages to the systemwide log.])
if test "x$backend" != xwindows && test "x$is_android_linux" != xyes; then
dnl Check if syslog is available in standard C library
AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=])
if test "x$syslog_h" = xyes; then
AC_CHECK_FUNCS([syslog])
fi
fi
fi
# Examples build
AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
[build example applications [default=no]])],
dnl Examples build
AC_ARG_ENABLE([examples-build],
[AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
[build_examples=$enableval],
[build_examples=no])
AM_CONDITIONAL(BUILD_EXAMPLES, test "x$build_examples" != xno)
# Tests build
AC_ARG_ENABLE([tests-build], [AS_HELP_STRING([--enable-tests-build],
[build test applications [default=no]])],
dnl Tests build
AC_ARG_ENABLE([tests-build],
[AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])],
[build_tests=$enableval],
[build_tests=no])
AM_CONDITIONAL(BUILD_TESTS, test "x$build_tests" != xno)
# headers not available on all platforms but required on others
AC_CHECK_HEADERS([sys/time.h])
AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno])
AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno])
AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes])
AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin])
AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd])
AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull])
AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd])
AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos])
AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
AM_CONDITIONAL([PLATFORM_POSIX], [test "x$platform" = xposix])
AM_CONDITIONAL([PLATFORM_WINDOWS], [test "x$platform" = xwindows])
AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
# sigaction not available on MinGW
AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
AM_CONDITIONAL(HAVE_SIGACTION, test "x$have_sigaction" = xyes)
dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
dnl Windows with GCC 8 or later because of dynamically loaded functions
if test "x$backend" = xwindows; then
saved_CFLAGS="${CFLAGS}"
CFLAGS="-Werror -Wcast-function-type"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
[EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-cast-function-type"],
[])
CFLAGS="${saved_CFLAGS}"
fi
# check for -fvisibility=hidden compiler support (GCC >= 3.4)
saved_cflags="$CFLAGS"
# -Werror required for cygwin
CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[VISIBILITY_CFLAGS="-fvisibility=hidden"
AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility])],
[VISIBILITY_CFLAGS=""
AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility])],
])
CFLAGS="$saved_cflags"
SHARED_CFLAGS="-Wall -Wextra -Wshadow -Wunused -Wwrite-strings -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=init-self -Werror=missing-prototypes -Werror=strict-prototypes -Werror=undef -Werror=uninitialized"
# check for -Wno-pointer-sign compiler support (GCC >= 4)
saved_cflags="$CFLAGS"
CFLAGS="$CFLAGS -Wno-pointer-sign"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
CFLAGS="$saved_cflags"
# check for -std=gnu99 compiler support
saved_cflags="$CFLAGS"
CFLAGS="-std=gnu99"
AC_MSG_CHECKING([whether CC supports -std=gnu99])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes])]
[AM_CFLAGS="${AM_CFLAGS} -std=gnu99"],
[AC_MSG_RESULT([no])]
)
CFLAGS="$saved_cflags"
AM_CFLAGS="${AM_CFLAGS} -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
AM_CPPFLAGS="${EXTRA_CPPFLAGS}"
AC_SUBST(AM_CPPFLAGS)
AM_CFLAGS="-std=${c_dialect}11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS}"
AC_SUBST(AM_CFLAGS)
AC_SUBST(LTLDFLAGS)
AM_CXXFLAGS="-std=${c_dialect}++11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS} -Wmissing-declarations"
AC_SUBST(AM_CXXFLAGS)
AC_SUBST(LT_LDFLAGS)
dnl set name of html output directory for doxygen
AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0])
AC_CONFIG_FILES([libusb-1.0.pc])
AC_CONFIG_FILES([Makefile])

22
externals/libusb/libusb/doc/Makefile.in vendored Executable file
View file

@ -0,0 +1,22 @@
LIBUSB_SRC_DIR = @top_srcdir@/libusb
EXCLUDED_FILES = hotplug.h libusbi.h version.h version_nano.h
LIBUSB_SRC = $(wildcard $(LIBUSB_SRC_DIR)/*.c) $(wildcard $(LIBUSB_SRC_DIR)/*.h)
LIBUSB_DOC_SRC = $(filter-out $(addprefix $(LIBUSB_SRC_DIR)/,$(EXCLUDED_FILES)),$(LIBUSB_SRC))
docs: @DOXYGEN_HTMLDIR@
@DOXYGEN_HTMLDIR@: doxygen.cfg @top_srcdir@/doc/libusb.png $(LIBUSB_DOC_SRC)
doxygen $<
sfurl = web.sourceforge.net:/home/project-web/libusb/htdocs
docs-upload: @DOXYGEN_HTMLDIR@
if [ -z "$$SF_USER" ]; then \
rsync -rv --delete $< $(sfurl); \
else \
rsync -rv --delete $< $$SF_USER@$(sfurl); \
fi
clean:
rm -rf @DOXYGEN_HTMLDIR@
.PHONY: clean docs docs-upload

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,12 @@
AM_CPPFLAGS = -I$(top_srcdir)/libusb
LDADD = ../libusb/libusb-1.0.la
LIBS =
noinst_PROGRAMS = listdevs xusb fxload hotplugtest testlibusb
noinst_PROGRAMS = dpfp dpfp_threaded fxload hotplugtest listdevs sam3u_benchmark testlibusb xusb
if HAVE_SIGACTION
noinst_PROGRAMS += dpfp
if THREADS_POSIX
dpfp_threaded_CFLAGS = $(AM_CFLAGS)
noinst_PROGRAMS += dpfp_threaded
endif
sam3u_benchmark_SOURCES = sam3u_benchmark.c
noinst_PROGRAMS += sam3u_benchmark
endif
dpfp_threaded_CPPFLAGS = $(AM_CPPFLAGS) -DDPFP_THREADED
dpfp_threaded_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
dpfp_threaded_LDADD = $(LDADD) $(THREAD_LIBS)
dpfp_threaded_SOURCES = dpfp.c
fxload_SOURCES = ezusb.c ezusb.h fxload.c
fxload_CFLAGS = $(THREAD_CFLAGS) $(AM_CFLAGS)

View file

@ -1,6 +1,8 @@
/*
* libusb example program to manipulate U.are.U 4000B fingerprint scanner.
* Copyright © 2007 Daniel Drake <dsd@gentoo.org>
* Copyright © 2016 Nathan Hjelm <hjelmn@mac.com>
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
*
* Basic image capture program only, does not consider the powerup quirks or
* the fact that image encryption may be enabled. Not expected to work
@ -21,14 +23,121 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libusb.h"
#if defined(_MSC_VER)
#define snprintf _snprintf
#endif
#if defined(DPFP_THREADED)
#if defined(PLATFORM_POSIX)
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#define THREAD_RETURN_VALUE NULL
typedef sem_t * semaphore_t;
typedef pthread_t thread_t;
static inline semaphore_t semaphore_create(void)
{
sem_t *semaphore;
char name[50];
sprintf(name, "/org.libusb.example.dpfp_threaded:%d", (int)getpid());
semaphore = sem_open(name, O_CREAT | O_EXCL, 0, 0);
if (semaphore == SEM_FAILED)
return NULL;
/* Remove semaphore so that it does not persist after process exits */
(void)sem_unlink(name);
return semaphore;
}
static inline void semaphore_give(semaphore_t semaphore)
{
(void)sem_post(semaphore);
}
static inline void semaphore_take(semaphore_t semaphore)
{
(void)sem_wait(semaphore);
}
static inline void semaphore_destroy(semaphore_t semaphore)
{
(void)sem_close(semaphore);
}
static inline int thread_create(thread_t *thread,
void *(*thread_entry)(void *arg), void *arg)
{
return pthread_create(thread, NULL, thread_entry, arg) == 0 ? 0 : -1;
}
static inline void thread_join(thread_t thread)
{
(void)pthread_join(thread, NULL);
}
#elif defined(PLATFORM_WINDOWS)
#define THREAD_RETURN_VALUE 0
typedef HANDLE semaphore_t;
typedef HANDLE thread_t;
#if defined(__CYGWIN__)
typedef DWORD thread_return_t;
#else
#include <process.h>
typedef unsigned thread_return_t;
#endif
static inline semaphore_t semaphore_create(void)
{
return CreateSemaphore(NULL, 0, 1, NULL);
}
static inline void semaphore_give(semaphore_t semaphore)
{
(void)ReleaseSemaphore(semaphore, 1, NULL);
}
static inline void semaphore_take(semaphore_t semaphore)
{
(void)WaitForSingleObject(semaphore, INFINITE);
}
static inline void semaphore_destroy(semaphore_t semaphore)
{
(void)CloseHandle(semaphore);
}
static inline int thread_create(thread_t *thread,
thread_return_t (__stdcall *thread_entry)(void *arg), void *arg)
{
#if defined(__CYGWIN__)
*thread = CreateThread(NULL, 0, thread_entry, arg, 0, NULL);
#else
*thread = (HANDLE)_beginthreadex(NULL, 0, thread_entry, arg, 0, NULL);
#endif
return *thread != NULL ? 0 : -1;
}
static inline void thread_join(thread_t thread)
{
(void)WaitForSingleObject(thread, INFINITE);
(void)CloseHandle(thread);
}
#endif
#endif
#define EP_INTR (1 | LIBUSB_ENDPOINT_IN)
#define EP_DATA (2 | LIBUSB_ENDPOINT_IN)
#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN)
@ -57,25 +166,65 @@ enum {
};
static int state = 0;
static struct libusb_device_handle *devh = NULL;
static libusb_device_handle *devh = NULL;
static unsigned char imgbuf[0x1b340];
static unsigned char irqbuf[INTR_LENGTH];
static struct libusb_transfer *img_transfer = NULL;
static struct libusb_transfer *irq_transfer = NULL;
static int img_idx = 0;
static int do_exit = 0;
static volatile sig_atomic_t do_exit = 0;
#if defined(DPFP_THREADED)
static semaphore_t exit_semaphore;
static thread_t poll_thread;
#endif
static void request_exit(sig_atomic_t code)
{
do_exit = code;
#if defined(DPFP_THREADED)
semaphore_give(exit_semaphore);
#endif
}
#if defined(DPFP_THREADED)
#if defined(PLATFORM_POSIX)
static void *poll_thread_main(void *arg)
#elif defined(PLATFORM_WINDOWS)
static thread_return_t __stdcall poll_thread_main(void *arg)
#endif
{
(void)arg;
printf("poll thread running\n");
while (!do_exit) {
struct timeval tv = { 1, 0 };
int r;
r = libusb_handle_events_timeout(NULL, &tv);
if (r < 0) {
request_exit(2);
break;
}
}
printf("poll thread shutting down\n");
return THREAD_RETURN_VALUE;
}
#endif
static int find_dpfp_device(void)
{
devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a);
return devh ? 0 : -EIO;
return devh ? 0 : -ENODEV;
}
static int print_f0_data(void)
{
unsigned char data[0x10];
size_t i;
int r;
unsigned int i;
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0xf0, 0, data,
sizeof(data), 0);
@ -83,14 +232,14 @@ static int print_f0_data(void)
fprintf(stderr, "F0 error %d\n", r);
return r;
}
if ((unsigned int) r < sizeof(data)) {
if (r < (int)sizeof(data)) {
fprintf(stderr, "short read (%d)\n", r);
return -1;
}
printf("F0 data:");
for (i = 0; i < sizeof(data); i++)
printf("%02x ", data[i]);
printf(" %02x", data[i]);
printf("\n");
return 0;
}
@ -104,7 +253,7 @@ static int get_hwstat(unsigned char *status)
fprintf(stderr, "read hwstat error %d\n", r);
return r;
}
if ((unsigned int) r < 1) {
if (r < 1) {
fprintf(stderr, "short read (%d)\n", r);
return -1;
}
@ -123,8 +272,8 @@ static int set_hwstat(unsigned char data)
fprintf(stderr, "set hwstat error %d\n", r);
return r;
}
if ((unsigned int) r < 1) {
fprintf(stderr, "short write (%d)", r);
if (r < 1) {
fprintf(stderr, "short write (%d)\n", r);
return -1;
}
@ -134,15 +283,15 @@ static int set_hwstat(unsigned char data)
static int set_mode(unsigned char data)
{
int r;
printf("set mode %02x\n", data);
printf("set mode %02x\n", data);
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x4e, 0, &data, 1, 0);
if (r < 0) {
fprintf(stderr, "set mode error %d\n", r);
return r;
}
if ((unsigned int) r < 1) {
fprintf(stderr, "short write (%d)", r);
if (r < 1) {
fprintf(stderr, "short write (%d)\n", r);
return -1;
}
@ -153,18 +302,18 @@ static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer)
{
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "mode change transfer not completed!\n");
do_exit = 2;
request_exit(2);
}
printf("async cb_mode_changed length=%d actual_length=%d\n",
transfer->length, transfer->actual_length);
if (next_state() < 0)
do_exit = 2;
request_exit(2);
}
static int set_mode_async(unsigned char data)
{
unsigned char *buf = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
unsigned char *buf = malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
struct libusb_transfer *transfer;
if (!buf)
@ -203,7 +352,7 @@ static int do_sync_intr(unsigned char *data)
return -1;
}
printf("recv interrupt %04x\n", *((uint16_t *) data));
printf("recv interrupt %04x\n", *((uint16_t *)data));
return 0;
}
@ -223,17 +372,17 @@ static int sync_intr(unsigned char type)
static int save_to_file(unsigned char *data)
{
FILE *fd;
FILE *f;
char filename[64];
snprintf(filename, sizeof(filename), "finger%d.pgm", img_idx++);
fd = fopen(filename, "w");
if (!fd)
f = fopen(filename, "w");
if (!f)
return -1;
fputs("P5 384 289 255 ", fd);
(void) fwrite(data + 64, 1, 384*289, fd);
fclose(fd);
fputs("P5 384 289 255 ", f);
(void)fwrite(data + 64, 1, 384*289, f);
fclose(f);
printf("saved image to %s\n", filename);
return 0;
}
@ -241,6 +390,7 @@ static int save_to_file(unsigned char *data)
static int next_state(void)
{
int r = 0;
printf("old state: %d\n", state);
switch (state) {
case STATE_AWAIT_IRQ_FINGER_REMOVED:
@ -282,57 +432,60 @@ static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "irq transfer status %d?\n", transfer->status);
do_exit = 2;
libusb_free_transfer(transfer);
irq_transfer = NULL;
return;
goto err_free_transfer;
}
printf("IRQ callback %02x\n", irqtype);
switch (state) {
case STATE_AWAIT_IRQ_FINGER_DETECTED:
if (irqtype == 0x01) {
if (next_state() < 0) {
do_exit = 2;
return;
}
if (next_state() < 0)
goto err_free_transfer;
} else {
printf("finger-on-sensor detected in wrong state!\n");
}
break;
case STATE_AWAIT_IRQ_FINGER_REMOVED:
if (irqtype == 0x02) {
if (next_state() < 0) {
do_exit = 2;
return;
}
if (next_state() < 0)
goto err_free_transfer;
} else {
printf("finger-on-sensor detected in wrong state!\n");
}
break;
}
if (libusb_submit_transfer(irq_transfer) < 0)
do_exit = 2;
goto err_free_transfer;
return;
err_free_transfer:
libusb_free_transfer(transfer);
irq_transfer = NULL;
request_exit(2);
}
static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer)
{
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "img transfer status %d?\n", transfer->status);
do_exit = 2;
libusb_free_transfer(transfer);
img_transfer = NULL;
return;
goto err_free_transfer;
}
printf("Image callback\n");
save_to_file(imgbuf);
if (next_state() < 0) {
do_exit = 2;
return;
}
if (next_state() < 0)
goto err_free_transfer;
if (libusb_submit_transfer(img_transfer) < 0)
do_exit = 2;
goto err_free_transfer;
return;
err_free_transfer:
libusb_free_transfer(transfer);
img_transfer = NULL;
request_exit(2);
}
static int init_capture(void)
@ -413,17 +566,33 @@ static void sighandler(int signum)
{
(void)signum;
do_exit = 1;
request_exit(1);
}
static void setup_signals(void)
{
#if defined(PLATFORM_POSIX)
struct sigaction sigact;
sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
(void)sigaction(SIGINT, &sigact, NULL);
(void)sigaction(SIGTERM, &sigact, NULL);
(void)sigaction(SIGQUIT, &sigact, NULL);
#else
(void)signal(SIGINT, sighandler);
(void)signal(SIGTERM, sighandler);
#endif
}
int main(void)
{
struct sigaction sigact;
int r;
r = libusb_init(NULL);
if (r < 0) {
fprintf(stderr, "failed to initialise libusb\n");
fprintf(stderr, "failed to initialise libusb %d - %s\n", r, libusb_strerror(r));
exit(1);
}
@ -435,7 +604,7 @@ int main(void)
r = libusb_claim_interface(devh, 0);
if (r < 0) {
fprintf(stderr, "usb_claim_interface error %d\n", r);
fprintf(stderr, "claim interface error %d - %s\n", r, libusb_strerror(r));
goto out;
}
printf("claimed interface\n");
@ -449,45 +618,66 @@ int main(void)
goto out_deinit;
/* async from here onwards */
setup_signals();
r = alloc_transfers();
if (r < 0)
goto out_deinit;
#if defined(DPFP_THREADED)
exit_semaphore = semaphore_create();
if (!exit_semaphore) {
fprintf(stderr, "failed to initialise semaphore\n");
goto out_deinit;
}
r = thread_create(&poll_thread, poll_thread_main, NULL);
if (r) {
semaphore_destroy(exit_semaphore);
goto out_deinit;
}
r = init_capture();
if (r < 0)
request_exit(2);
while (!do_exit)
semaphore_take(exit_semaphore);
#else
r = init_capture();
if (r < 0)
goto out_deinit;
sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGINT, &sigact, NULL);
sigaction(SIGTERM, &sigact, NULL);
sigaction(SIGQUIT, &sigact, NULL);
while (!do_exit) {
r = libusb_handle_events(NULL);
if (r < 0)
goto out_deinit;
request_exit(2);
}
#endif
printf("shutting down...\n");
if (irq_transfer) {
r = libusb_cancel_transfer(irq_transfer);
if (r < 0)
goto out_deinit;
}
#if defined(DPFP_THREADED)
thread_join(poll_thread);
semaphore_destroy(exit_semaphore);
#endif
if (img_transfer) {
r = libusb_cancel_transfer(img_transfer);
if (r < 0)
goto out_deinit;
fprintf(stderr, "failed to cancel transfer %d - %s\n", r, libusb_strerror(r));
}
while (irq_transfer || img_transfer)
if (irq_transfer) {
r = libusb_cancel_transfer(irq_transfer);
if (r < 0)
fprintf(stderr, "failed to cancel transfer %d - %s\n", r, libusb_strerror(r));
}
while (img_transfer || irq_transfer) {
if (libusb_handle_events(NULL) < 0)
break;
}
if (do_exit == 1)
r = 0;
@ -495,7 +685,9 @@ int main(void)
r = 1;
out_deinit:
if (img_transfer)
libusb_free_transfer(img_transfer);
if (irq_transfer)
libusb_free_transfer(irq_transfer);
set_mode(0);
set_hwstat(0x80);

View file

@ -20,6 +20,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@ -29,9 +32,6 @@
#include "libusb.h"
#include "ezusb.h"
extern void logerror(const char *format, ...)
__attribute__ ((format(printf, 1, 2)));
/*
* This file contains functions for uploading firmware into Cypress
* EZ-USB microcontrollers. These chips use control endpoint 0 and vendor

View file

@ -20,23 +20,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(_MSC_VER)
#include <config.h>
#include <stdbool.h>
#else
#define __attribute__(x)
#if !defined(bool)
#define bool int
#endif
#if !defined(true)
#define true (1 == 1)
#endif
#if !defined(false)
#define false (!true)
#endif
#if defined(_PREFAST_)
#pragma warning(disable:28193)
#endif
#endif
#define FX_TYPE_UNDEFINED -1
#define FX_TYPE_AN21 0 /* Original AnchorChips parts */
@ -113,6 +100,8 @@ extern int ezusb_load_eeprom(libusb_device_handle *device,
/* Verbosity level (default 1). Can be increased or decreased with options v/q */
extern int verbose;
extern void logerror(const char *format, ...) PRINTF_FORMAT(1, 2);
#ifdef __cplusplus
}
#endif

View file

@ -21,6 +21,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -32,7 +34,7 @@
#include "libusb.h"
#include "ezusb.h"
#if !defined(_WIN32) || defined(__CYGWIN__ )
#if !defined(_WIN32) || defined(__CYGWIN__)
#include <syslog.h>
static bool dosyslog = false;
#include <strings.h>
@ -47,15 +49,12 @@ static bool dosyslog = false;
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif
void logerror(const char *format, ...)
__attribute__ ((format (__printf__, 1, 2)));
void logerror(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#if !defined(_WIN32) || defined(__CYGWIN__ )
#if !defined(_WIN32) || defined(__CYGWIN__)
if (dosyslog)
vsyslog(LOG_ERR, format, ap);
else

View file

@ -95,7 +95,7 @@ int main(int argc, char *argv[])
}
if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
printf ("Hotplug capabilites are not supported on this platform\n");
printf ("Hotplug capabilities are not supported on this platform\n");
libusb_exit (NULL);
return EXIT_FAILURE;
}

View file

@ -22,24 +22,54 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <config.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>
#include <libusb.h>
#include "libusb.h"
#define EP_DATA_IN 0x82
#define EP_ISO_IN 0x86
static int do_exit = 0;
static volatile sig_atomic_t do_exit = 0;
static struct libusb_device_handle *devh = NULL;
static unsigned long num_bytes = 0, num_xfer = 0;
static struct timeval tv_start;
static void get_timestamp(struct timeval *tv)
{
#if defined(PLATFORM_WINDOWS)
static LARGE_INTEGER frequency;
LARGE_INTEGER counter;
if (!frequency.QuadPart)
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&counter);
counter.QuadPart *= 1000000;
counter.QuadPart /= frequency.QuadPart;
tv->tv_sec = (long)(counter.QuadPart / 1000000ULL);
tv->tv_usec = (long)(counter.QuadPart % 1000000ULL);
#elif defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
(void)clock_gettime(CLOCK_MONOTONIC, &ts);
tv->tv_sec = ts.tv_sec;
tv->tv_usec = (int)(ts.tv_nsec / 1000L);
#else
gettimeofday(tv, NULL);
#endif
}
static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr)
{
int i;
@ -103,7 +133,7 @@ static int benchmark_in(uint8_t ep)
libusb_fill_bulk_transfer(xfr, devh, ep, buf,
sizeof(buf), cb_xfr, NULL, 0);
gettimeofday(&tv_start, NULL);
get_timestamp(&tv_start);
/* NOTE: To reach maximum possible performance the program must
* submit *multiple* transfers here, not just one.
@ -125,36 +155,39 @@ static int benchmark_in(uint8_t ep)
static void measure(void)
{
struct timeval tv_stop;
unsigned int diff_msec;
unsigned long diff_msec;
gettimeofday(&tv_stop, NULL);
get_timestamp(&tv_stop);
diff_msec = (tv_stop.tv_sec - tv_start.tv_sec)*1000;
diff_msec += (tv_stop.tv_usec - tv_start.tv_usec)/1000;
diff_msec = (tv_stop.tv_sec - tv_start.tv_sec) * 1000L;
diff_msec += (tv_stop.tv_usec - tv_start.tv_usec) / 1000L;
printf("%lu transfers (total %lu bytes) in %u miliseconds => %lu bytes/sec\n",
num_xfer, num_bytes, diff_msec, (num_bytes*1000)/diff_msec);
printf("%lu transfers (total %lu bytes) in %lu milliseconds => %lu bytes/sec\n",
num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / diff_msec);
}
static void sig_hdlr(int signum)
{
switch (signum) {
case SIGINT:
(void)signum;
measure();
do_exit = 1;
break;
}
}
int main(int argc, char **argv)
int main(void)
{
int rc;
#if defined(PLATFORM_POSIX)
struct sigaction sigact;
sigact.sa_handler = sig_hdlr;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGINT, &sigact, NULL);
(void)sigaction(SIGINT, &sigact, NULL);
#else
(void)signal(SIGINT, sig_hdlr);
#endif
rc = libusb_init(NULL);
if (rc < 0) {
@ -184,7 +217,7 @@ int main(int argc, char **argv)
/* Measurement has already been done by the signal handler. */
libusb_release_interface(devh, 0);
libusb_release_interface(devh, 2);
out:
if (devh)
libusb_close(devh);

View file

@ -21,18 +21,14 @@
#include <string.h>
#include "libusb.h"
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
int verbose = 0;
static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp)
{
printf(" USB 3.0 Endpoint Companion:\n");
printf(" bMaxBurst: %d\n", ep_comp->bMaxBurst);
printf(" bmAttributes: 0x%02x\n", ep_comp->bmAttributes);
printf(" wBytesPerInterval: %d\n", ep_comp->wBytesPerInterval);
printf(" bMaxBurst: %u\n", ep_comp->bMaxBurst);
printf(" bmAttributes: %02xh\n", ep_comp->bmAttributes);
printf(" wBytesPerInterval: %u\n", ep_comp->wBytesPerInterval);
}
static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
@ -42,19 +38,18 @@ static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
printf(" Endpoint:\n");
printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize);
printf(" bInterval: %d\n", endpoint->bInterval);
printf(" bRefresh: %d\n", endpoint->bRefresh);
printf(" bSynchAddress: %d\n", endpoint->bSynchAddress);
printf(" wMaxPacketSize: %u\n", endpoint->wMaxPacketSize);
printf(" bInterval: %u\n", endpoint->bInterval);
printf(" bRefresh: %u\n", endpoint->bRefresh);
printf(" bSynchAddress: %u\n", endpoint->bSynchAddress);
for (i = 0; i < endpoint->extra_length;) {
if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) {
struct libusb_ss_endpoint_companion_descriptor *ep_comp;
ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp);
if (LIBUSB_SUCCESS != ret) {
if (LIBUSB_SUCCESS != ret)
continue;
}
print_endpoint_comp(ep_comp);
@ -70,13 +65,13 @@ static void print_altsetting(const struct libusb_interface_descriptor *interface
uint8_t i;
printf(" Interface:\n");
printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber);
printf(" bAlternateSetting: %d\n", interface->bAlternateSetting);
printf(" bNumEndpoints: %d\n", interface->bNumEndpoints);
printf(" bInterfaceClass: %d\n", interface->bInterfaceClass);
printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass);
printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol);
printf(" iInterface: %d\n", interface->iInterface);
printf(" bInterfaceNumber: %u\n", interface->bInterfaceNumber);
printf(" bAlternateSetting: %u\n", interface->bAlternateSetting);
printf(" bNumEndpoints: %u\n", interface->bNumEndpoints);
printf(" bInterfaceClass: %u\n", interface->bInterfaceClass);
printf(" bInterfaceSubClass: %u\n", interface->bInterfaceSubClass);
printf(" bInterfaceProtocol: %u\n", interface->bInterfaceProtocol);
printf(" iInterface: %u\n", interface->iInterface);
for (i = 0; i < interface->bNumEndpoints; i++)
print_endpoint(&interface->endpoint[i]);
@ -85,57 +80,57 @@ static void print_altsetting(const struct libusb_interface_descriptor *interface
static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap)
{
printf(" USB 2.0 Extension Capabilities:\n");
printf(" bDevCapabilityType: %d\n", usb_2_0_ext_cap->bDevCapabilityType);
printf(" bmAttributes: 0x%x\n", usb_2_0_ext_cap->bmAttributes);
printf(" bDevCapabilityType: %u\n", usb_2_0_ext_cap->bDevCapabilityType);
printf(" bmAttributes: %08xh\n", usb_2_0_ext_cap->bmAttributes);
}
static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap)
{
printf(" USB 3.0 Capabilities:\n");
printf(" bDevCapabilityType: %d\n", ss_usb_cap->bDevCapabilityType);
printf(" bmAttributes: 0x%x\n", ss_usb_cap->bmAttributes);
printf(" wSpeedSupported: 0x%x\n", ss_usb_cap->wSpeedSupported);
printf(" bFunctionalitySupport: %d\n", ss_usb_cap->bFunctionalitySupport);
printf(" bU1devExitLat: %d\n", ss_usb_cap->bU1DevExitLat);
printf(" bU2devExitLat: %d\n", ss_usb_cap->bU2DevExitLat);
printf(" bDevCapabilityType: %u\n", ss_usb_cap->bDevCapabilityType);
printf(" bmAttributes: %02xh\n", ss_usb_cap->bmAttributes);
printf(" wSpeedSupported: %u\n", ss_usb_cap->wSpeedSupported);
printf(" bFunctionalitySupport: %u\n", ss_usb_cap->bFunctionalitySupport);
printf(" bU1devExitLat: %u\n", ss_usb_cap->bU1DevExitLat);
printf(" bU2devExitLat: %u\n", ss_usb_cap->bU2DevExitLat);
}
static void print_bos(libusb_device_handle *handle)
{
struct libusb_bos_descriptor *bos;
uint8_t i;
int ret;
ret = libusb_get_bos_descriptor(handle, &bos);
if (0 > ret) {
if (ret < 0)
return;
}
printf(" Binary Object Store (BOS):\n");
printf(" wTotalLength: %d\n", bos->wTotalLength);
printf(" bNumDeviceCaps: %d\n", bos->bNumDeviceCaps);
printf(" wTotalLength: %u\n", bos->wTotalLength);
printf(" bNumDeviceCaps: %u\n", bos->bNumDeviceCaps);
if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
for (i = 0; i < bos->bNumDeviceCaps; i++) {
struct libusb_bos_dev_capability_descriptor *dev_cap = bos->dev_capability[i];
if (dev_cap->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;
ret = libusb_get_usb_2_0_extension_descriptor(NULL, bos->dev_capability[0],&usb_2_0_extension);
if (0 > ret) {
ret = libusb_get_usb_2_0_extension_descriptor(NULL, dev_cap, &usb_2_0_extension);
if (ret < 0)
return;
}
print_2_0_ext_cap(usb_2_0_extension);
libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);
}
} else if (dev_cap->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
struct libusb_ss_usb_device_capability_descriptor *ss_dev_cap;
if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
struct libusb_ss_usb_device_capability_descriptor *dev_cap;
ret = libusb_get_ss_usb_device_capability_descriptor(NULL, bos->dev_capability[0],&dev_cap);
if (0 > ret) {
ret = libusb_get_ss_usb_device_capability_descriptor(NULL, dev_cap, &ss_dev_cap);
if (ret < 0)
return;
}
print_ss_usb_cap(dev_cap);
libusb_free_ss_usb_device_capability_descriptor(dev_cap);
print_ss_usb_cap(ss_dev_cap);
libusb_free_ss_usb_device_capability_descriptor(ss_dev_cap);
}
}
libusb_free_bos_descriptor(bos);
@ -154,79 +149,71 @@ static void print_configuration(struct libusb_config_descriptor *config)
uint8_t i;
printf(" Configuration:\n");
printf(" wTotalLength: %d\n", config->wTotalLength);
printf(" bNumInterfaces: %d\n", config->bNumInterfaces);
printf(" bConfigurationValue: %d\n", config->bConfigurationValue);
printf(" iConfiguration: %d\n", config->iConfiguration);
printf(" wTotalLength: %u\n", config->wTotalLength);
printf(" bNumInterfaces: %u\n", config->bNumInterfaces);
printf(" bConfigurationValue: %u\n", config->bConfigurationValue);
printf(" iConfiguration: %u\n", config->iConfiguration);
printf(" bmAttributes: %02xh\n", config->bmAttributes);
printf(" MaxPower: %d\n", config->MaxPower);
printf(" MaxPower: %u\n", config->MaxPower);
for (i = 0; i < config->bNumInterfaces; i++)
print_interface(&config->interface[i]);
}
static int print_device(libusb_device *dev, int level)
static void print_device(libusb_device *dev, libusb_device_handle *handle)
{
struct libusb_device_descriptor desc;
libusb_device_handle *handle = NULL;
char description[260];
char string[256];
unsigned char string[256];
const char *speed;
int ret;
uint8_t i;
switch (libusb_get_device_speed(dev)) {
case LIBUSB_SPEED_LOW: speed = "1.5M"; break;
case LIBUSB_SPEED_FULL: speed = "12M"; break;
case LIBUSB_SPEED_HIGH: speed = "480M"; break;
case LIBUSB_SPEED_SUPER: speed = "5G"; break;
case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break;
default: speed = "Unknown";
}
ret = libusb_get_device_descriptor(dev, &desc);
if (ret < 0) {
fprintf(stderr, "failed to get device descriptor");
return -1;
return;
}
ret = libusb_open(dev, &handle);
if (LIBUSB_SUCCESS == ret) {
printf("Dev (bus %u, device %u): %04X - %04X speed: %s\n",
libusb_get_bus_number(dev), libusb_get_device_address(dev),
desc.idVendor, desc.idProduct, speed);
if (!handle)
libusb_open(dev, &handle);
if (handle) {
if (desc.iManufacturer) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
if (ret > 0)
snprintf(description, sizeof(description), "%s - ", string);
else
snprintf(description, sizeof(description), "%04X - ",
desc.idVendor);
printf(" Manufacturer: %s\n", (char *)string);
}
else
snprintf(description, sizeof(description), "%04X - ",
desc.idVendor);
if (desc.iProduct) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
if (ret > 0)
snprintf(description + strlen(description), sizeof(description) -
strlen(description), "%s", string);
else
snprintf(description + strlen(description), sizeof(description) -
strlen(description), "%04X", desc.idProduct);
}
else
snprintf(description + strlen(description), sizeof(description) -
strlen(description), "%04X", desc.idProduct);
}
else {
snprintf(description, sizeof(description), "%04X - %04X",
desc.idVendor, desc.idProduct);
printf(" Product: %s\n", (char *)string);
}
printf("%.*sDev (bus %d, device %d): %s\n", level * 2, " ",
libusb_get_bus_number(dev), libusb_get_device_address(dev), description);
if (handle && verbose) {
if (desc.iSerialNumber) {
if (desc.iSerialNumber && verbose) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
if (ret > 0)
printf("%.*s - Serial Number: %s\n", level * 2,
" ", string);
printf(" Serial Number: %s\n", (char *)string);
}
}
if (verbose) {
for (i = 0; i < desc.bNumConfigurations; i++) {
struct libusb_config_descriptor *config;
ret = libusb_get_config_descriptor(dev, i, &config);
if (LIBUSB_SUCCESS != ret) {
printf(" Couldn't retrieve descriptors\n");
@ -238,40 +225,87 @@ static int print_device(libusb_device *dev, int level)
libusb_free_config_descriptor(config);
}
if (handle && desc.bcdUSB >= 0x0201) {
if (handle && desc.bcdUSB >= 0x0201)
print_bos(handle);
}
}
if (handle)
libusb_close(handle);
}
#ifdef __linux__
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
static int test_wrapped_device(const char *device_name)
{
libusb_device_handle *handle;
int r, fd;
fd = open(device_name, O_RDWR);
if (fd < 0) {
printf("Error could not open %s: %s\n", device_name, strerror(errno));
return 1;
}
r = libusb_wrap_sys_device(NULL, fd, &handle);
if (r) {
printf("Error wrapping device: %s: %s\n", device_name, libusb_strerror(r));
close(fd);
return 1;
}
print_device(libusb_get_device(handle), handle);
close(fd);
return 0;
}
#else
static int test_wrapped_device(const char *device_name)
{
(void)device_name;
printf("Testing wrapped devices is not supported on your platform\n");
return 1;
}
#endif
int main(int argc, char *argv[])
{
const char *device_name = NULL;
libusb_device **devs;
ssize_t cnt;
int r, i;
if (argc > 1 && !strcmp(argv[1], "-v"))
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-v")) {
verbose = 1;
} else if (!strcmp(argv[i], "-d") && (i + 1) < argc) {
i++;
device_name = argv[i];
} else {
printf("Usage %s [-v] [-d </dev/bus/usb/...>]\n", argv[0]);
printf("Note use -d to test libusb_wrap_sys_device()\n");
return 1;
}
}
r = libusb_init(NULL);
if (r < 0)
return r;
if (device_name) {
r = test_wrapped_device(device_name);
} else {
cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0)
return (int)cnt;
for (i = 0; devs[i]; ++i) {
print_device(devs[i], 0);
if (cnt < 0) {
libusb_exit(NULL);
return 1;
}
for (i = 0; devs[i]; i++)
print_device(devs[i], NULL);
libusb_free_device_list(devs, 1);
}
libusb_exit(NULL);
return 0;
return r;
}

View file

@ -18,36 +18,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "libusb.h"
#if defined(_WIN32)
#define msleep(msecs) Sleep(msecs)
#else
#include <time.h>
#define msleep(msecs) nanosleep(&(struct timespec){msecs / 1000, (msecs * 1000000) % 1000000000UL}, NULL);
#endif
#if defined(_MSC_VER)
#define snprintf _snprintf
#define putenv _putenv
#endif
#if !defined(bool)
#define bool int
#endif
#if !defined(true)
#define true (1 == 1)
#endif
#if !defined(false)
#define false (!true)
#endif
// Future versions of libusb will use usb_interface instead of interface
// in libusb_config_descriptor => catter for that
#define usb_interface interface
@ -58,6 +43,16 @@ static bool extra_info = false;
static bool force_device_request = false; // For WCID descriptor queries
static const char* binary_name = NULL;
static inline void msleep(int msecs)
{
#if defined(_WIN32)
Sleep(msecs);
#else
const struct timespec ts = { msecs / 1000, (msecs % 1000) * 1000000L };
nanosleep(&ts, NULL);
#endif
}
static void perr(char const *format, ...)
{
va_list args;
@ -976,6 +971,7 @@ static int test_device(uint16_t vid, uint16_t pid)
int main(int argc, char** argv)
{
static char debug_env_str[] = "LIBUSB_DEBUG=4"; // LIBUSB_LOG_LEVEL_DEBUG
bool show_help = false;
bool debug_mode = false;
const struct libusb_version* version;
@ -1103,7 +1099,7 @@ int main(int argc, char** argv)
// but since we can't call on libusb_set_option() before libusb_init(), we use the env variable method
old_dbg_str = getenv("LIBUSB_DEBUG");
if (debug_mode) {
if (putenv("LIBUSB_DEBUG=4") != 0) // LIBUSB_LOG_LEVEL_DEBUG
if (putenv(debug_env_str) != 0)
printf("Unable to set debug level\n");
}

View file

@ -1,101 +1,88 @@
all: libusb-1.0.la libusb-1.0.dll
AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -fvisibility=hidden $(THREAD_CFLAGS)
AM_CXXFLAGS += -fvisibility=hidden $(THREAD_CFLAGS)
lib_LTLIBRARIES = libusb-1.0.la
POSIX_POLL_SRC = os/poll_posix.h os/poll_posix.c
POSIX_THREADS_SRC = os/threads_posix.h os/threads_posix.c
WINDOWS_POLL_SRC = os/poll_windows.h os/poll_windows.c
WINDOWS_THREADS_SRC = os/threads_windows.h os/threads_windows.c
LINUX_USBFS_SRC = os/linux_usbfs.h os/linux_usbfs.c
DARWIN_USB_SRC = os/darwin_usb.h os/darwin_usb.c
OPENBSD_USB_SRC = os/openbsd_usb.c
NETBSD_USB_SRC = os/netbsd_usb.c
SUNOS_USB_SRC = os/sunos_usb.c os/sunos_usb.h
WINDOWS_USB_SRC = libusb-1.0.def libusb-1.0.rc \
os/windows_common.h \
os/windows_nt_common.h os/windows_nt_common.c \
os/windows_nt_shared_types.h \
POSIX_PLATFORM_SRC = os/events_posix.h os/events_posix.c \
os/threads_posix.h os/threads_posix.c
WINDOWS_PLATFORM_SRC = os/events_windows.h os/events_windows.c \
os/threads_windows.h os/threads_windows.c
if PLATFORM_POSIX
PLATFORM_SRC = $(POSIX_PLATFORM_SRC)
else
PLATFORM_SRC = $(WINDOWS_PLATFORM_SRC)
endif
OS_DARWIN_SRC = os/darwin_usb.h os/darwin_usb.c
OS_HAIKU_SRC = os/haiku_usb.h os/haiku_usb_backend.cpp \
os/haiku_pollfs.cpp os/haiku_usb_raw.h os/haiku_usb_raw.cpp
OS_LINUX_SRC = os/linux_usbfs.h os/linux_usbfs.c
OS_NETBSD_SRC = os/netbsd_usb.c
OS_NULL_SRC = os/null_usb.c
OS_OPENBSD_SRC = os/openbsd_usb.c
OS_SUNOS_SRC = os/sunos_usb.h os/sunos_usb.c
OS_WINDOWS_SRC = libusb-1.0.def libusb-1.0.rc \
os/windows_common.h os/windows_common.c \
os/windows_usbdk.h os/windows_usbdk.c \
os/windows_winusb.h os/windows_winusb.c
WINCE_USB_SRC = os/wince_usb.h os/wince_usb.c
HAIKU_USB_SRC = os/haiku_usb.h os/haiku_usb_backend.cpp \
os/haiku_usb_raw.h os/haiku_usb_raw.cpp os/haiku_pollfs.cpp
EXTRA_DIST = $(POSIX_POLL_SRC) $(POSIX_THREADS_SRC) \
$(WINDOWS_POLL_SRC) $(WINDOWS_THREADS_SRC) \
$(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) \
$(OPENBSD_USB_SRC) $(NETBSD_USB_SRC) \
$(WINDOWS_USB_SRC) $(WINCE_USB_SRC) \
$(HAIKU_USB_SRC) \
os/linux_udev.c os/linux_netlink.c
if OS_LINUX
if USE_UDEV
OS_SRC = $(LINUX_USBFS_SRC) os/linux_udev.c
else
OS_SRC = $(LINUX_USBFS_SRC) os/linux_netlink.c
endif
endif
if OS_DARWIN
OS_SRC = $(DARWIN_USB_SRC)
AM_CFLAGS_EXT = -no-cpp-precomp
endif
if OS_OPENBSD
OS_SRC = $(OPENBSD_USB_SRC)
endif
if OS_NETBSD
OS_SRC = $(NETBSD_USB_SRC)
endif
if OS_SUNOS
OS_SRC = $(SUNOS_USB_SRC)
OS_SRC = $(OS_DARWIN_SRC)
endif
if OS_HAIKU
noinst_LTLIBRARIES = libusb_haiku.la
libusb_haiku_la_SOURCES = $(HAIKU_USB_SRC)
libusb_haiku_la_SOURCES = $(OS_HAIKU_SRC)
libusb_1_0_la_LIBADD = libusb_haiku.la
endif
if OS_WINDOWS
OS_SRC = $(WINDOWS_USB_SRC)
.rc.lo:
$(AM_V_GEN)$(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) -i $< -o $@
libusb-1.0.rc: version.h version_nano.h
if OS_LINUX
OS_SRC = $(OS_LINUX_SRC)
if USE_UDEV
OS_SRC += os/linux_udev.c
else
OS_SRC += os/linux_netlink.c
endif
endif
libusb-1.0.dll: libusb-1.0.def libusb-1.0.la
if OS_NETBSD
OS_SRC = $(OS_NETBSD_SRC)
endif
if OS_NULL
OS_SRC = $(OS_NULL_SRC)
endif
if OS_OPENBSD
OS_SRC = $(OS_OPENBSD_SRC)
endif
if OS_SUNOS
OS_SRC = $(OS_SUNOS_SRC)
endif
if OS_WINDOWS
OS_SRC = $(OS_WINDOWS_SRC)
include Makefile.am.extra
# Dependencies for compiling libusb-1.0.lo from libusb-1.0.rc
-include ./$(DEPDIR)/libusb-1.0.Plo
if CREATE_IMPORT_LIB
all-local: .libs/libusb-1.0.dll.a
# Rebuild the import lib from the .def so that MS and MinGW DLLs can be interchanged
$(AM_V_GEN)$(DLLTOOL) $(DLLTOOLFLAGS) --kill-at --input-def $(srcdir)/libusb-1.0.def --dllname $@ --output-lib .libs/$@.a
.libs/libusb-1.0.dll.a: libusb-1.0.def libusb-1.0.la
$(AM_V_DLLTOOL)$(DLLTOOL) $(DLLTOOLFLAGS) --kill-at --input-def $< --dllname libusb-1.0.dll --output-lib $@
endif
endif
if OS_WINDOWS
POLL_SRC = $(WINDOWS_POLL_SRC)
else
POLL_SRC = $(POSIX_POLL_SRC)
endif
if THREADS_POSIX
THREADS_SRC = $(POSIX_THREADS_SRC)
else
THREADS_SRC = $(WINDOWS_THREADS_SRC)
endif
libusb_1_0_la_CFLAGS = $(AM_CFLAGS)
libusb_1_0_la_LDFLAGS = $(LTLDFLAGS)
libusb_1_0_la_SOURCES = libusbi.h libusb.h version.h version_nano.h \
libusb_1_0_la_LDFLAGS = $(LT_LDFLAGS)
libusb_1_0_la_SOURCES = libusbi.h version.h version_nano.h \
core.c descriptor.c hotplug.h hotplug.c io.c strerror.c sync.c \
$(POLL_SRC) $(THREADS_SRC) $(OS_SRC)
$(PLATFORM_SRC) $(OS_SRC)
hdrdir = $(includedir)/libusb-1.0
hdr_HEADERS = libusb.h
pkginclude_HEADERS = libusb.h

View file

@ -0,0 +1,26 @@
AM_V_DLLTOOL = $(am__v_DLLTOOL_$(V))
am__v_DLLTOOL_ = $(am__v_DLLTOOL_$(AM_DEFAULT_VERBOSITY))
am__v_DLLTOOL_0 = @echo " DLLTOOL " $@;
am__v_DLLTOOL_1 =
AM_V_RC = $(am__v_RC_$(V))
am__v_RC_ = $(am__v_RC_$(AM_DEFAULT_VERBOSITY))
am__v_RC_0 = @echo " RC " $@;
am__v_RC_1 =
LTRC = $(LIBTOOL) $(AM_V_lt) --tag=RC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(RC) $(AM_RCFLAGS) \
$(RCFLAGS)
RCPPARGS = \
--preprocessor-arg -MT \
--preprocessor-arg $@ \
--preprocessor-arg -MD \
--preprocessor-arg -MP \
--preprocessor-arg -MF \
--preprocessor-arg $$depbase.Tpo
.rc.lo:
$(AM_V_RC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
$(LTRC) $(RCPPARGS) -i $< -o $@ &&\
$(am__mv) $$depbase.Tpo $$depbase.Plo

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -19,17 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <assert.h>
#include "libusbi.h"
#include "hotplug.h"
@ -61,8 +50,8 @@
* expecting additional events. Returning 0 will rearm the callback and 1 will cause
* the callback to be deregistered. Note that when callbacks are called from
* libusb_hotplug_register_callback() because of the \ref LIBUSB_HOTPLUG_ENUMERATE
* flag, the callback return value is ignored, iow you cannot cause a callback
* to be deregistered by returning 1 when it is called from
* flag, the callback return value is ignored. In other words, you cannot cause a
* callback to be deregistered by returning 1 when it is called from
* libusb_hotplug_register_callback().
*
* Callbacks for a particular context are automatically deregistered by libusb_exit().
@ -154,6 +143,13 @@ int main (void) {
\endcode
*/
#define VALID_HOTPLUG_EVENTS \
(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | \
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT)
#define VALID_HOTPLUG_FLAGS \
(LIBUSB_HOTPLUG_ENUMERATE)
static int usbi_hotplug_match_cb(struct libusb_context *ctx,
struct libusb_device *dev, libusb_hotplug_event event,
struct libusb_hotplug_callback *hotplug_cb)
@ -188,7 +184,7 @@ void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
list_for_each_entry_safe(hotplug_cb, next, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
for_each_hotplug_cb_safe(ctx, hotplug_cb, next) {
if (hotplug_cb->flags & USBI_HOTPLUG_NEEDS_FREE) {
/* process deregistration in usbi_hotplug_deregister() */
continue;
@ -210,8 +206,8 @@ void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev,
libusb_hotplug_event event)
{
int pending_events;
struct libusb_hotplug_message *message = calloc(1, sizeof(*message));
unsigned int event_flags;
if (!message) {
usbi_err(ctx, "error allocating hotplug message");
@ -224,15 +220,16 @@ void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device
/* Take the event data lock and add this message to the list.
* Only signal an event if there are no prior pending events. */
usbi_mutex_lock(&ctx->event_data_lock);
pending_events = usbi_pending_events(ctx);
event_flags = ctx->event_flags;
ctx->event_flags |= USBI_EVENT_HOTPLUG_MSG_PENDING;
list_add_tail(&message->list, &ctx->hotplug_msgs);
if (!pending_events)
usbi_signal_event(ctx);
if (!event_flags)
usbi_signal_event(&ctx->event);
usbi_mutex_unlock(&ctx->event_data_lock);
}
int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
libusb_hotplug_event events, libusb_hotplug_flag flags,
int events, int flags,
int vendor_id, int product_id, int dev_class,
libusb_hotplug_callback_fn cb_fn, void *user_data,
libusb_hotplug_callback_handle *callback_handle)
@ -240,8 +237,8 @@ int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
struct libusb_hotplug_callback *new_callback;
/* check for sane values */
if ((!events || (~(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT) & events)) ||
(flags && (~LIBUSB_HOTPLUG_ENUMERATE & flags)) ||
if ((!events || (~VALID_HOTPLUG_EVENTS & events)) ||
(~VALID_HOTPLUG_FLAGS & flags) ||
(LIBUSB_HOTPLUG_MATCH_ANY != vendor_id && (~0xffff & vendor_id)) ||
(LIBUSB_HOTPLUG_MATCH_ANY != product_id && (~0xffff & product_id)) ||
(LIBUSB_HOTPLUG_MATCH_ANY != dev_class && (~0xff & dev_class)) ||
@ -254,7 +251,7 @@ int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
return LIBUSB_ERROR_NOT_SUPPORTED;
}
USBI_GET_CONTEXT(ctx);
ctx = usbi_get_context(ctx);
new_callback = calloc(1, sizeof(*new_callback));
if (!new_callback) {
@ -319,7 +316,7 @@ int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
return LIBUSB_SUCCESS;
}
void API_EXPORTED libusb_hotplug_deregister_callback(struct libusb_context *ctx,
void API_EXPORTED libusb_hotplug_deregister_callback(libusb_context *ctx,
libusb_hotplug_callback_handle callback_handle)
{
struct libusb_hotplug_callback *hotplug_cb;
@ -330,12 +327,12 @@ void API_EXPORTED libusb_hotplug_deregister_callback(struct libusb_context *ctx,
return;
}
USBI_GET_CONTEXT(ctx);
usbi_dbg("deregister hotplug cb %d", callback_handle);
ctx = usbi_get_context(ctx);
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
list_for_each_entry(hotplug_cb, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
for_each_hotplug_cb(ctx, hotplug_cb) {
if (callback_handle == hotplug_cb->handle) {
/* Mark this callback for deregistration */
hotplug_cb->flags |= USBI_HOTPLUG_NEEDS_FREE;
@ -345,23 +342,50 @@ void API_EXPORTED libusb_hotplug_deregister_callback(struct libusb_context *ctx,
usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
if (deregistered) {
int pending_events;
unsigned int event_flags;
usbi_mutex_lock(&ctx->event_data_lock);
pending_events = usbi_pending_events(ctx);
event_flags = ctx->event_flags;
ctx->event_flags |= USBI_EVENT_HOTPLUG_CB_DEREGISTERED;
if (!pending_events)
usbi_signal_event(ctx);
if (!event_flags)
usbi_signal_event(&ctx->event);
usbi_mutex_unlock(&ctx->event_data_lock);
}
}
DEFAULT_VISIBILITY
void * LIBUSB_CALL libusb_hotplug_get_user_data(libusb_context *ctx,
libusb_hotplug_callback_handle callback_handle)
{
struct libusb_hotplug_callback *hotplug_cb;
void *user_data = NULL;
/* check for hotplug support */
if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
return NULL;
}
usbi_dbg("get hotplug user data %d", callback_handle);
ctx = usbi_get_context(ctx);
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
for_each_hotplug_cb(ctx, hotplug_cb) {
if (callback_handle == hotplug_cb->handle) {
user_data = hotplug_cb->user_data;
}
}
usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
return user_data;
}
void usbi_hotplug_deregister(struct libusb_context *ctx, int forced)
{
struct libusb_hotplug_callback *hotplug_cb, *next;
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
list_for_each_entry_safe(hotplug_cb, next, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
for_each_hotplug_cb_safe(ctx, hotplug_cb, next) {
if (forced || (hotplug_cb->flags & USBI_HOTPLUG_NEEDS_FREE)) {
usbi_dbg("freeing hotplug cb %p with handle %d", hotplug_cb,
hotplug_cb->handle);

View file

@ -90,6 +90,12 @@ struct libusb_hotplug_message {
struct list_head list;
};
#define for_each_hotplug_cb(ctx, c) \
for_each_helper(c, &(ctx)->hotplug_cbs, struct libusb_hotplug_callback)
#define for_each_hotplug_cb_safe(ctx, c, n) \
for_each_safe_helper(c, n, &(ctx)->hotplug_cbs, struct libusb_hotplug_callback)
void usbi_hotplug_deregister(struct libusb_context *ctx, int forced);
void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
libusb_hotplug_event event);

File diff suppressed because it is too large Load diff

View file

@ -116,6 +116,8 @@ EXPORTS
libusb_has_capability@4 = libusb_has_capability
libusb_hotplug_deregister_callback
libusb_hotplug_deregister_callback@8 = libusb_hotplug_deregister_callback
libusb_hotplug_get_user_data
libusb_hotplug_get_user_data@8 = libusb_hotplug_get_user_data
libusb_hotplug_register_callback
libusb_hotplug_register_callback@36 = libusb_hotplug_register_callback
libusb_init
@ -176,3 +178,5 @@ EXPORTS
libusb_unref_device@4 = libusb_unref_device
libusb_wait_for_event
libusb_wait_for_event@8 = libusb_wait_for_event
libusb_wrap_sys_device
libusb_wrap_sys_device@12 = libusb_wrap_sys_device

View file

@ -1,27 +1,19 @@
/*
* For Windows: input this file to the Resoure Compiler to produce a binary
* For Windows: input this file to the Resource Compiler to produce a binary
* .res file. This is then embedded in the resultant library (like any other
* compilation object).
* The information can then be queried using standard APIs and can also be
* viewed with utilities such as Windows Explorer.
*/
#ifndef _WIN32_WCE
#include "winresrc.h"
#endif
#include "version.h"
#ifndef LIBUSB_VERSIONSTRING
#define LU_STR(s) #s
#define LU_XSTR(s) LU_STR(s)
#if LIBUSB_NANO > 0
#define LIBUSB_VERSIONSTRING \
LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO) LIBUSB_RC "\0"
#else
#define LIBUSB_VERSIONSTRING \
LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
LU_XSTR(LIBUSB_MICRO) LIBUSB_RC "\0"
#endif
#endif
VS_VERSION_INFO VERSIONINFO

View file

@ -4,6 +4,7 @@
* Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
* Copyright © 2012 Pete Batard <pete@akeo.ie>
* Copyright © 2012-2018 Nathan Hjelm <hjelmn@cs.unm.edu>
* Copyright © 2014-2020 Chris Dickens <christopher.a.dickens@gmail.com>
* For more information, please visit: http://libusb.info
*
* This library is free software; you can redistribute it and/or
@ -24,55 +25,36 @@
#ifndef LIBUSB_H
#define LIBUSB_H
#ifdef _MSC_VER
#if defined(_MSC_VER)
/* on MS environments, the inline keyword is available in C++ only */
#if !defined(__cplusplus)
#define inline __inline
#endif
/* ssize_t is also not available (copy/paste from MinGW) */
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
#undef ssize_t
#ifdef _WIN64
typedef __int64 ssize_t;
#else
typedef int ssize_t;
#endif /* _WIN64 */
#endif /* _SSIZE_T_DEFINED */
/* ssize_t is also not available */
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#endif /* _MSC_VER */
/* stdint.h is not available on older MSVC */
#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
#else
#include <limits.h>
#include <stdint.h>
#endif
#if !defined(_WIN32_WCE)
#include <sys/types.h>
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__HAIKU__)
#if !defined(_MSC_VER)
#include <sys/time.h>
#endif
#include <time.h>
#include <limits.h>
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define ZERO_SIZED_ARRAY /* [] - valid C99 code */
#else
#define ZERO_SIZED_ARRAY 0 /* [0] - non-standard, but usually working code */
#endif
#endif /* __STDC_VERSION__ */
/* 'interface' might be defined as a macro on Windows, so we need to
* undefine it so as not to break the current libusb API, because
* libusb_config_descriptor has an 'interface' member
* As this can be problematic if you include windows.h after libusb.h
* in your sources, we force windows.h to be included first. */
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
#if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
#if defined(interface)
#undef interface
@ -80,17 +62,22 @@ typedef unsigned __int32 uint32_t;
#if !defined(__CYGWIN__)
#include <winsock.h>
#endif
#endif
#endif /* _WIN32 || __CYGWIN__ */
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define LIBUSB_DEPRECATED_FOR(f) \
__attribute__((deprecated("Use " #f " instead")))
#elif __GNUC__ >= 3
#define LIBUSB_DEPRECATED_FOR(f) __attribute__((deprecated))
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
#define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated ("Use " #f " instead")))
#elif defined(__GNUC__) && (__GNUC__ >= 3)
#define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated))
#else
#define LIBUSB_DEPRECATED_FOR(f)
#endif /* __GNUC__ */
#if defined(__GNUC__)
#define LIBUSB_PACKED __attribute__ ((packed))
#else
#define LIBUSB_PACKED
#endif /* __GNUC__ */
/** \def LIBUSB_CALL
* \ingroup libusb_misc
* libusb's Windows calling convention.
@ -123,11 +110,11 @@ typedef unsigned __int32 uint32_t;
* return type, before the function name. See internal documentation for
* API_EXPORTED.
*/
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
#if defined(_WIN32) || defined(__CYGWIN__)
#define LIBUSB_CALL WINAPI
#else
#define LIBUSB_CALL
#endif
#endif /* _WIN32 || __CYGWIN__ */
/** \def LIBUSB_API_VERSION
* \ingroup libusb_misc
@ -149,12 +136,12 @@ typedef unsigned __int32 uint32_t;
* Internally, LIBUSB_API_VERSION is defined as follows:
* (libusb major << 24) | (libusb minor << 16) | (16 bit incremental)
*/
#define LIBUSB_API_VERSION 0x01000107
#define LIBUSB_API_VERSION 0x01000108
/* The following is kept for compatibility, but will be deprecated in the future */
#define LIBUSBX_API_VERSION LIBUSB_API_VERSION
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif
@ -196,35 +183,35 @@ enum libusb_class_code {
* this bDeviceClass value indicates that each interface specifies its
* own class information and all interfaces operate independently.
*/
LIBUSB_CLASS_PER_INTERFACE = 0,
LIBUSB_CLASS_PER_INTERFACE = 0x00,
/** Audio class */
LIBUSB_CLASS_AUDIO = 1,
LIBUSB_CLASS_AUDIO = 0x01,
/** Communications class */
LIBUSB_CLASS_COMM = 2,
LIBUSB_CLASS_COMM = 0x02,
/** Human Interface Device class */
LIBUSB_CLASS_HID = 3,
LIBUSB_CLASS_HID = 0x03,
/** Physical */
LIBUSB_CLASS_PHYSICAL = 5,
/** Printer class */
LIBUSB_CLASS_PRINTER = 7,
LIBUSB_CLASS_PHYSICAL = 0x05,
/** Image class */
LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
LIBUSB_CLASS_IMAGE = 6,
LIBUSB_CLASS_IMAGE = 0x06,
LIBUSB_CLASS_PTP = 0x06, /* legacy name from libusb-0.1 usb.h */
/** Printer class */
LIBUSB_CLASS_PRINTER = 0x07,
/** Mass storage class */
LIBUSB_CLASS_MASS_STORAGE = 8,
LIBUSB_CLASS_MASS_STORAGE = 0x08,
/** Hub class */
LIBUSB_CLASS_HUB = 9,
LIBUSB_CLASS_HUB = 0x09,
/** Data class */
LIBUSB_CLASS_DATA = 10,
LIBUSB_CLASS_DATA = 0x0a,
/** Smart Card */
LIBUSB_CLASS_SMART_CARD = 0x0b,
@ -244,6 +231,9 @@ enum libusb_class_code {
/** Wireless class */
LIBUSB_CLASS_WIRELESS = 0xe0,
/** Miscellaneous class */
LIBUSB_CLASS_MISCELLANEOUS = 0xef,
/** Application class */
LIBUSB_CLASS_APPLICATION = 0xfe,
@ -311,10 +301,11 @@ enum libusb_descriptor_type {
#define LIBUSB_BT_CONTAINER_ID_SIZE 20
/* We unwrap the BOS => define its max size */
#define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\
(LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\
(LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\
(LIBUSB_BT_CONTAINER_ID_SIZE))
#define LIBUSB_DT_BOS_MAX_SIZE \
(LIBUSB_DT_BOS_SIZE + \
LIBUSB_BT_USB_2_0_EXTENSION_SIZE + \
LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE + \
LIBUSB_BT_CONTAINER_ID_SIZE)
#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
#define LIBUSB_ENDPOINT_DIR_MASK 0x80
@ -324,11 +315,11 @@ enum libusb_descriptor_type {
* \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
*/
enum libusb_endpoint_direction {
/** In: device-to-host */
LIBUSB_ENDPOINT_IN = 0x80,
/** Out: host-to-device */
LIBUSB_ENDPOINT_OUT = 0x00
LIBUSB_ENDPOINT_OUT = 0x00,
/** In: device-to-host */
LIBUSB_ENDPOINT_IN = 0x80
};
#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
@ -337,21 +328,18 @@ enum libusb_endpoint_direction {
* Endpoint transfer type. Values for bits 0:1 of the
* \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
*/
enum libusb_transfer_type {
enum libusb_endpoint_transfer_type {
/** Control endpoint */
LIBUSB_TRANSFER_TYPE_CONTROL = 0,
LIBUSB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0x0,
/** Isochronous endpoint */
LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
LIBUSB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 0x1,
/** Bulk endpoint */
LIBUSB_TRANSFER_TYPE_BULK = 2,
LIBUSB_ENDPOINT_TRANSFER_TYPE_BULK = 0x2,
/** Interrupt endpoint */
LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
/** Stream endpoint */
LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4,
LIBUSB_ENDPOINT_TRANSFER_TYPE_INTERRUPT = 0x3
};
/** \ingroup libusb_misc
@ -386,20 +374,20 @@ enum libusb_standard_request {
LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
/** Return the selected alternate setting for the specified interface */
LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
LIBUSB_REQUEST_GET_INTERFACE = 0x0a,
/** Select an alternate interface for the specified interface */
LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
LIBUSB_REQUEST_SET_INTERFACE = 0x0b,
/** Set then report an endpoint's synchronization frame */
LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
LIBUSB_REQUEST_SYNCH_FRAME = 0x0c,
/** Sets both the U1 and U2 Exit Latency */
LIBUSB_REQUEST_SET_SEL = 0x30,
/** Delay from the time a host transmits a packet to the time it is
* received by the device. */
LIBUSB_SET_ISOCH_DELAY = 0x31,
LIBUSB_SET_ISOCH_DELAY = 0x31
};
/** \ingroup libusb_misc
@ -435,10 +423,10 @@ enum libusb_request_recipient {
LIBUSB_RECIPIENT_ENDPOINT = 0x02,
/** Other */
LIBUSB_RECIPIENT_OTHER = 0x03,
LIBUSB_RECIPIENT_OTHER = 0x03
};
#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0c
/** \ingroup libusb_desc
* Synchronization type for isochronous endpoints. Values for bits 2:3 of the
@ -447,16 +435,16 @@ enum libusb_request_recipient {
*/
enum libusb_iso_sync_type {
/** No synchronization */
LIBUSB_ISO_SYNC_TYPE_NONE = 0,
LIBUSB_ISO_SYNC_TYPE_NONE = 0x0,
/** Asynchronous */
LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
LIBUSB_ISO_SYNC_TYPE_ASYNC = 0x1,
/** Adaptive */
LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 0x2,
/** Synchronous */
LIBUSB_ISO_SYNC_TYPE_SYNC = 3
LIBUSB_ISO_SYNC_TYPE_SYNC = 0x3
};
#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
@ -468,13 +456,68 @@ enum libusb_iso_sync_type {
*/
enum libusb_iso_usage_type {
/** Data endpoint */
LIBUSB_ISO_USAGE_TYPE_DATA = 0,
LIBUSB_ISO_USAGE_TYPE_DATA = 0x0,
/** Feedback endpoint */
LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 0x1,
/** Implicit feedback Data endpoint */
LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 0x2
};
/** \ingroup libusb_desc
* Supported speeds (wSpeedSupported) bitfield. Indicates what
* speeds the device supports.
*/
enum libusb_supported_speed {
/** Low speed operation supported (1.5MBit/s). */
LIBUSB_LOW_SPEED_OPERATION = (1 << 0),
/** Full speed operation supported (12MBit/s). */
LIBUSB_FULL_SPEED_OPERATION = (1 << 1),
/** High speed operation supported (480MBit/s). */
LIBUSB_HIGH_SPEED_OPERATION = (1 << 2),
/** Superspeed operation supported (5000MBit/s). */
LIBUSB_SUPER_SPEED_OPERATION = (1 << 3)
};
/** \ingroup libusb_desc
* Masks for the bits of the
* \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field
* of the USB 2.0 Extension descriptor.
*/
enum libusb_usb_2_0_extension_attributes {
/** Supports Link Power Management (LPM) */
LIBUSB_BM_LPM_SUPPORT = (1 << 1)
};
/** \ingroup libusb_desc
* Masks for the bits of the
* \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field
* field of the SuperSpeed USB Device Capability descriptor.
*/
enum libusb_ss_usb_device_capability_attributes {
/** Supports Latency Tolerance Messages (LTM) */
LIBUSB_BM_LTM_SUPPORT = (1 << 1)
};
/** \ingroup libusb_desc
* USB capability types
*/
enum libusb_bos_type {
/** Wireless USB device capability */
LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 0x01,
/** USB 2.0 extensions */
LIBUSB_BT_USB_2_0_EXTENSION = 0x02,
/** SuperSpeed USB device capability */
LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 0x03,
/** Container ID type */
LIBUSB_BT_CONTAINER_ID = 0x04
};
/** \ingroup libusb_desc
@ -547,17 +590,15 @@ struct libusb_endpoint_descriptor {
/** The address of the endpoint described by this descriptor. Bits 0:3 are
* the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
* see \ref libusb_endpoint_direction.
*/
* see \ref libusb_endpoint_direction. */
uint8_t bEndpointAddress;
/** Attributes which apply to the endpoint when it is configured using
* the bConfigurationValue. Bits 0:1 determine the transfer type and
* correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
* isochronous endpoints and correspond to \ref libusb_iso_sync_type.
* correspond to \ref libusb_endpoint_transfer_type. Bits 2:3 are only used
* for isochronous endpoints and correspond to \ref libusb_iso_sync_type.
* Bits 4:5 are also only used for isochronous endpoints and correspond to
* \ref libusb_iso_usage_type. Bits 6:7 are reserved.
*/
* \ref libusb_iso_usage_type. Bits 6:7 are reserved. */
uint8_t bmAttributes;
/** Maximum packet size this endpoint is capable of sending/receiving. */
@ -698,7 +739,6 @@ struct libusb_config_descriptor {
* host-endian format.
*/
struct libusb_ss_endpoint_companion_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
@ -707,7 +747,6 @@ struct libusb_ss_endpoint_companion_descriptor {
* this context. */
uint8_t bDescriptorType;
/** The maximum number of packets the endpoint can send or
* receive as part of a burst. */
uint8_t bMaxBurst;
@ -719,7 +758,7 @@ struct libusb_ss_endpoint_companion_descriptor {
uint8_t bmAttributes;
/** The total number of bytes this EP will transfer every
* service interval. valid only for periodic EPs. */
* service interval. Valid only for periodic EPs. */
uint16_t wBytesPerInterval;
};
@ -731,12 +770,15 @@ struct libusb_ss_endpoint_companion_descriptor {
struct libusb_bos_dev_capability_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
* LIBUSB_DT_DEVICE_CAPABILITY in this context. */
uint8_t bDescriptorType;
/** Device Capability type */
uint8_t bDevCapabilityType;
/** Device Capability data (bLength - 3 bytes) */
uint8_t dev_capability_data[ZERO_SIZED_ARRAY];
};
@ -862,6 +904,9 @@ struct libusb_container_id_descriptor {
/** \ingroup libusb_asyncio
* Setup packet for control transfers. */
#if defined(_MSC_VER)
#pragma pack(push, 1)
#endif
struct libusb_control_setup {
/** Request type. Bits 0:4 determine recipient, see
* \ref libusb_request_recipient. Bits 5:6 determine type, see
@ -886,7 +931,10 @@ struct libusb_control_setup {
/** Number of bytes to transfer */
uint16_t wLength;
};
} LIBUSB_PACKED;
#if defined(_MSC_VER)
#pragma pack(pop)
#endif
#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
@ -916,7 +964,7 @@ struct libusb_version {
const char *rc;
/** For ABI compatibility only. */
const char* describe;
const char *describe;
};
/** \ingroup libusb_lib
@ -986,62 +1034,7 @@ enum libusb_speed {
LIBUSB_SPEED_SUPER = 4,
/** The device is operating at super speed plus (10000MBit/s). */
LIBUSB_SPEED_SUPER_PLUS = 5,
};
/** \ingroup libusb_dev
* Supported speeds (wSpeedSupported) bitfield. Indicates what
* speeds the device supports.
*/
enum libusb_supported_speed {
/** Low speed operation supported (1.5MBit/s). */
LIBUSB_LOW_SPEED_OPERATION = 1,
/** Full speed operation supported (12MBit/s). */
LIBUSB_FULL_SPEED_OPERATION = 2,
/** High speed operation supported (480MBit/s). */
LIBUSB_HIGH_SPEED_OPERATION = 4,
/** Superspeed operation supported (5000MBit/s). */
LIBUSB_SUPER_SPEED_OPERATION = 8,
};
/** \ingroup libusb_dev
* Masks for the bits of the
* \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field
* of the USB 2.0 Extension descriptor.
*/
enum libusb_usb_2_0_extension_attributes {
/** Supports Link Power Management (LPM) */
LIBUSB_BM_LPM_SUPPORT = 2,
};
/** \ingroup libusb_dev
* Masks for the bits of the
* \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field
* field of the SuperSpeed USB Device Capability descriptor.
*/
enum libusb_ss_usb_device_capability_attributes {
/** Supports Latency Tolerance Messages (LTM) */
LIBUSB_BM_LTM_SUPPORT = 2,
};
/** \ingroup libusb_dev
* USB capability types
*/
enum libusb_bos_type {
/** Wireless USB device capability */
LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,
/** USB 2.0 extensions */
LIBUSB_BT_USB_2_0_EXTENSION = 2,
/** SuperSpeed USB device capability */
LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3,
/** Container ID type */
LIBUSB_BT_CONTAINER_ID = 4,
LIBUSB_SPEED_SUPER_PLUS = 5
};
/** \ingroup libusb_misc
@ -1095,12 +1088,31 @@ enum libusb_error {
message strings in strerror.c when adding new error codes here. */
/** Other error */
LIBUSB_ERROR_OTHER = -99,
LIBUSB_ERROR_OTHER = -99
};
/* Total number of error codes in enum libusb_error */
#define LIBUSB_ERROR_COUNT 14
/** \ingroup libusb_asyncio
* Transfer type */
enum libusb_transfer_type {
/** Control transfer */
LIBUSB_TRANSFER_TYPE_CONTROL = 0U,
/** Isochronous transfer */
LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1U,
/** Bulk transfer */
LIBUSB_TRANSFER_TYPE_BULK = 2U,
/** Interrupt transfer */
LIBUSB_TRANSFER_TYPE_INTERRUPT = 3U,
/** Bulk stream transfer */
LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4U
};
/** \ingroup libusb_asyncio
* Transfer status codes */
enum libusb_transfer_status {
@ -1125,7 +1137,7 @@ enum libusb_transfer_status {
LIBUSB_TRANSFER_NO_DEVICE,
/** Device sent more data than requested */
LIBUSB_TRANSFER_OVERFLOW,
LIBUSB_TRANSFER_OVERFLOW
/* NB! Remember to update libusb_error_name()
when adding new status codes here. */
@ -1135,19 +1147,19 @@ enum libusb_transfer_status {
* libusb_transfer.flags values */
enum libusb_transfer_flags {
/** Report short frames as errors */
LIBUSB_TRANSFER_SHORT_NOT_OK = 1U << 0,
LIBUSB_TRANSFER_SHORT_NOT_OK = (1U << 0),
/** Automatically free() transfer buffer during libusb_free_transfer().
* Note that buffers allocated with libusb_dev_mem_alloc() should not
* be attempted freed in this way, since free() is not an appropriate
* way to release such memory. */
LIBUSB_TRANSFER_FREE_BUFFER = 1U << 1,
LIBUSB_TRANSFER_FREE_BUFFER = (1U << 1),
/** Automatically call libusb_free_transfer() after callback returns.
* If this flag is set, it is illegal to call libusb_free_transfer()
* from your transfer callback, as this will result in a double-free
* when this flag is acted upon. */
LIBUSB_TRANSFER_FREE_TRANSFER = 1U << 2,
LIBUSB_TRANSFER_FREE_TRANSFER = (1U << 2),
/** Terminate transfers that are a multiple of the endpoint's
* wMaxPacketSize with an extra zero length packet. This is useful
@ -1172,7 +1184,7 @@ enum libusb_transfer_flags {
*
* Available since libusb-1.0.9.
*/
LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1U << 3,
LIBUSB_TRANSFER_ADD_ZERO_PACKET = (1U << 3)
};
/** \ingroup libusb_asyncio
@ -1217,7 +1229,7 @@ struct libusb_transfer {
/** Address of the endpoint where this transfer will be sent. */
unsigned char endpoint;
/** Type of the endpoint from \ref libusb_transfer_type */
/** Type of the transfer from \ref libusb_transfer_type */
unsigned char type;
/** Timeout for this transfer in milliseconds. A value of 0 indicates no
@ -1245,7 +1257,16 @@ struct libusb_transfer {
* fails, or is cancelled. */
libusb_transfer_cb_fn callback;
/** User context data to pass to the callback function. */
/** User context data. Useful for associating specific data to a transfer
* that can be accessed from within the callback function.
*
* This field may be set manually or is taken as the `user_data` parameter
* of the following functions:
* - libusb_fill_bulk_transfer()
* - libusb_fill_bulk_stream_transfer()
* - libusb_fill_control_transfer()
* - libusb_fill_interrupt_transfer()
* - libusb_fill_iso_transfer() */
void *user_data;
/** Data buffer */
@ -1266,33 +1287,40 @@ struct libusb_transfer {
*/
enum libusb_capability {
/** The libusb_has_capability() API is available. */
LIBUSB_CAP_HAS_CAPABILITY = 0x0000,
LIBUSB_CAP_HAS_CAPABILITY = 0x0000U,
/** Hotplug support is available on this platform. */
LIBUSB_CAP_HAS_HOTPLUG = 0x0001,
LIBUSB_CAP_HAS_HOTPLUG = 0x0001U,
/** The library can access HID devices without requiring user intervention.
* Note that before being able to actually access an HID device, you may
* still have to call additional libusb functions such as
* \ref libusb_detach_kernel_driver(). */
LIBUSB_CAP_HAS_HID_ACCESS = 0x0100,
LIBUSB_CAP_HAS_HID_ACCESS = 0x0100U,
/** The library supports detaching of the default USB driver, using
* \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */
LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101
LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101U
};
/** \ingroup libusb_lib
* Log message levels.
* - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default)
* - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr
* - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
* - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stderr
* - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stderr
*/
enum libusb_log_level {
/** (0) : No messages ever emitted by the library (default) */
LIBUSB_LOG_LEVEL_NONE = 0,
/** (1) : Error messages are emitted */
LIBUSB_LOG_LEVEL_ERROR = 1,
/** (2) : Warning and error messages are emitted */
LIBUSB_LOG_LEVEL_WARNING = 2,
/** (3) : Informational, warning and error messages are emitted */
LIBUSB_LOG_LEVEL_INFO = 3,
LIBUSB_LOG_LEVEL_DEBUG = 4,
/** (4) : All messages are emitted */
LIBUSB_LOG_LEVEL_DEBUG = 4
};
/** \ingroup libusb_lib
@ -1300,12 +1328,11 @@ enum libusb_log_level {
* \see libusb_set_log_cb()
*/
enum libusb_log_cb_mode {
/** Callback function handling all log messages. */
LIBUSB_LOG_CB_GLOBAL = (1 << 0),
/** Callback function handling all log mesages. */
LIBUSB_LOG_CB_GLOBAL = 1 << 0,
/** Callback function handling context related log mesages. */
LIBUSB_LOG_CB_CONTEXT = 1 << 1
/** Callback function handling context related log messages. */
LIBUSB_LOG_CB_CONTEXT = (1 << 1)
};
/** \ingroup libusb_lib
@ -1328,7 +1355,7 @@ const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
int LIBUSB_CALL libusb_has_capability(uint32_t capability);
const char * LIBUSB_CALL libusb_error_name(int errcode);
int LIBUSB_CALL libusb_setlocale(const char *locale);
const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
const char * LIBUSB_CALL libusb_strerror(int errcode);
ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
libusb_device ***list);
@ -1350,7 +1377,7 @@ int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
void LIBUSB_CALL libusb_free_config_descriptor(
struct libusb_config_descriptor *config);
int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor(
struct libusb_context *ctx,
libusb_context *ctx,
const struct libusb_endpoint_descriptor *endpoint,
struct libusb_ss_endpoint_companion_descriptor **ep_comp);
void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor(
@ -1359,27 +1386,27 @@ int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *dev_handle,
struct libusb_bos_descriptor **bos);
void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor(
struct libusb_context *ctx,
libusb_context *ctx,
struct libusb_bos_dev_capability_descriptor *dev_cap,
struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension);
void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor(
struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension);
int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor(
struct libusb_context *ctx,
libusb_context *ctx,
struct libusb_bos_dev_capability_descriptor *dev_cap,
struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap);
void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor(
struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap);
int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx,
int LIBUSB_CALL libusb_get_container_id_descriptor(libusb_context *ctx,
struct libusb_bos_dev_capability_descriptor *dev_cap,
struct libusb_container_id_descriptor **container_id);
void LIBUSB_CALL libusb_free_container_id_descriptor(
struct libusb_container_id_descriptor *container_id);
uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len);
int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len);
LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)
int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *path, uint8_t path_length);
libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
@ -1463,7 +1490,7 @@ static inline unsigned char *libusb_control_transfer_get_data(
static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
struct libusb_transfer *transfer)
{
return (struct libusb_control_setup *)(void *) transfer->buffer;
return (struct libusb_control_setup *)(void *)transfer->buffer;
}
/** \ingroup libusb_asyncio
@ -1493,7 +1520,7 @@ static inline void libusb_fill_control_setup(unsigned char *buffer,
uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
uint16_t wLength)
{
struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer;
setup->bmRequestType = bmRequestType;
setup->bRequest = bRequest;
setup->wValue = libusb_cpu_to_le16(wValue);
@ -1543,7 +1570,7 @@ static inline void libusb_fill_control_transfer(
unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
unsigned int timeout)
{
struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer;
transfer->dev_handle = dev_handle;
transfer->endpoint = 0;
transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
@ -1682,6 +1709,7 @@ static inline void libusb_set_iso_packet_lengths(
struct libusb_transfer *transfer, unsigned int length)
{
int i;
for (i = 0; i < transfer->num_iso_packets; i++)
transfer->iso_packet_desc[i].length = length;
}
@ -1896,7 +1924,7 @@ void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
* Callbacks handles are generated by libusb_hotplug_register_callback()
* and can be used to deregister callbacks. Callback handles are unique
* per libusb_context and it is safe to call libusb_hotplug_deregister_callback()
* on an already deregisted callback.
* on an already deregistered callback.
*
* Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
*
@ -1908,29 +1936,30 @@ typedef int libusb_hotplug_callback_handle;
*
* Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
*
* Flags for hotplug events */
* Hotplug events */
typedef enum {
/** Default value when not using any flags. */
LIBUSB_HOTPLUG_NO_FLAGS = 0U,
/** A device has been plugged in and is ready to use */
LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = (1 << 0),
/** Arm the callback and fire it for all matching currently attached devices. */
LIBUSB_HOTPLUG_ENUMERATE = 1U << 0,
} libusb_hotplug_flag;
/** A device has left and is no longer available.
* It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
* It is safe to call libusb_get_device_descriptor on a device that has left */
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = (1 << 1)
} libusb_hotplug_event;
/** \ingroup libusb_hotplug
*
* Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
*
* Hotplug events */
* Hotplug flags */
typedef enum {
/** A device has been plugged in and is ready to use */
LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01U,
/** Arm the callback and fire it for all matching currently attached devices. */
LIBUSB_HOTPLUG_ENUMERATE = (1 << 0)
} libusb_hotplug_flag;
/** A device has left and is no longer available.
* It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
* It is safe to call libusb_get_device_descriptor on a device that has left */
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02U,
} libusb_hotplug_event;
/** \ingroup libusb_hotplug
* Convenience macro when not using any flags */
#define LIBUSB_HOTPLUG_NO_FLAGS 0
/** \ingroup libusb_hotplug
* Wildcard matching for hotplug events */
@ -1959,9 +1988,7 @@ typedef enum {
* returning 1 will cause this callback to be deregistered
*/
typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
libusb_device *device,
libusb_hotplug_event event,
void *user_data);
libusb_device *device, libusb_hotplug_event event, void *user_data);
/** \ingroup libusb_hotplug
* Register a hotplug callback function
@ -1986,9 +2013,10 @@ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
* Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
*
* \param[in] ctx context to register this callback with
* \param[in] events bitwise or of events that will trigger this callback. See \ref
* libusb_hotplug_event
* \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag
* \param[in] events bitwise or of hotplug events that will trigger this callback.
* See \ref libusb_hotplug_event
* \param[in] flags bitwise or of hotplug flags that affect registration.
* See \ref libusb_hotplug_flag
* \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
* \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
* \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
@ -1998,12 +2026,9 @@ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
* \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure
*/
int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
libusb_hotplug_event events,
libusb_hotplug_flag flags,
int vendor_id, int product_id,
int dev_class,
libusb_hotplug_callback_fn cb_fn,
void *user_data,
int events, int flags,
int vendor_id, int product_id, int dev_class,
libusb_hotplug_callback_fn cb_fn, void *user_data,
libusb_hotplug_callback_handle *callback_handle);
/** \ingroup libusb_hotplug
@ -2020,6 +2045,17 @@ int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
libusb_hotplug_callback_handle callback_handle);
/** \ingroup libusb_hotplug
* Gets the user_data associated with a hotplug callback.
*
* Since version v1.0.24 \ref LIBUSB_API_VERSION >= 0x01000108
*
* \param[in] ctx context this callback is registered with
* \param[in] callback_handle the handle of the callback to get the user_data of
*/
void * LIBUSB_CALL libusb_hotplug_get_user_data(libusb_context *ctx,
libusb_hotplug_callback_handle callback_handle);
/** \ingroup libusb_lib
* Available option values for libusb_set_option().
*/
@ -2045,7 +2081,7 @@ enum libusb_option {
* If libusb was compiled with verbose debug message logging, this function
* does nothing: you'll always get messages from all levels.
*/
LIBUSB_OPTION_LOG_LEVEL,
LIBUSB_OPTION_LOG_LEVEL = 0,
/** Use the UsbDk backend for a specific context, if available.
*
@ -2054,12 +2090,23 @@ enum libusb_option {
*
* Only valid on Windows.
*/
LIBUSB_OPTION_USE_USBDK,
LIBUSB_OPTION_USE_USBDK = 1,
/** Set libusb has weak authority. With this option, libusb will skip
* scan devices in libusb_init.
*
* This option should be set before calling libusb_init(), otherwise
* libusb_init will failed. Normally libusb_wrap_sys_device need set
* this option.
*
* Only valid on Linux-based operating system, such as Android.
*/
LIBUSB_OPTION_WEAK_AUTHORITY = 2
};
int LIBUSB_CALL libusb_set_option(libusb_context *ctx, enum libusb_option option, ...);
#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
/* -*- Mode: C; indent-tabs-mode:nil -*- */
/*
* darwin backend for libusb 1.0
* Copyright © 2008-2019 Nathan Hjelm <hjelmn@users.sourceforge.net>
* Copyright © 2019 Google LLC. All rights reserved.
* Copyright © 2008-2020 Nathan Hjelm <hjelmn@cs.unm.edu>
* Copyright © 2019-2020 Google LLC. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -19,11 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <config.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@ -47,56 +46,37 @@
#include <objc/objc-auto.h>
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
/* Apple deprecated the darwin atomics in 10.12 in favor of C11 atomics */
#include <stdatomic.h>
#define libusb_darwin_atomic_fetch_add(x, y) atomic_fetch_add(x, y)
_Atomic int32_t initCount = ATOMIC_VAR_INIT(0);
#else
/* use darwin atomics if the target is older than 10.12 */
#include <libkern/OSAtomic.h>
/* OSAtomicAdd32Barrier returns the new value */
#define libusb_darwin_atomic_fetch_add(x, y) (OSAtomicAdd32Barrier(y, x) - y)
static volatile int32_t initCount = 0;
#endif
/* On 10.12 and later, use newly available clock_*() functions */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
#define OSX_USE_CLOCK_GETTIME 1
#else
#define OSX_USE_CLOCK_GETTIME 0
#endif
#include "darwin_usb.h"
static pthread_mutex_t libusb_darwin_init_mutex = PTHREAD_MUTEX_INITIALIZER;
static int init_count = 0;
/* async event thread */
static pthread_mutex_t libusb_darwin_at_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t libusb_darwin_at_cond = PTHREAD_COND_INITIALIZER;
#if !OSX_USE_CLOCK_GETTIME
#if !defined(HAVE_CLOCK_GETTIME)
static clock_serv_t clock_realtime;
static clock_serv_t clock_monotonic;
#endif
#define LIBUSB_DARWIN_STARTUP_FAILURE ((CFRunLoopRef) -1)
static CFRunLoopRef libusb_darwin_acfl = NULL; /* event cf loop */
static CFRunLoopSourceRef libusb_darwin_acfls = NULL; /* shutdown signal for event cf loop */
static usbi_mutex_t darwin_cached_devices_lock = PTHREAD_MUTEX_INITIALIZER;
static struct list_head darwin_cached_devices = {&darwin_cached_devices, &darwin_cached_devices};
static const char *darwin_device_class = kIOUSBDeviceClassName;
static struct list_head darwin_cached_devices;
static const char *darwin_device_class = "IOUSBDevice";
#define DARWIN_CACHED_DEVICE(a) ((struct darwin_cached_device *) (((struct darwin_device_priv *)((a)->os_priv))->dev))
#define DARWIN_CACHED_DEVICE(a) (((struct darwin_device_priv *)usbi_get_device_priv((a)))->dev)
/* async event thread */
static pthread_t libusb_darwin_at;
static int darwin_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian);
static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int iface);
static int darwin_release_interface(struct libusb_device_handle *dev_handle, int iface);
static int darwin_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, void *buffer, size_t len);
static int darwin_claim_interface(struct libusb_device_handle *dev_handle, uint8_t iface);
static int darwin_release_interface(struct libusb_device_handle *dev_handle, uint8_t iface);
static int darwin_reset_device(struct libusb_device_handle *dev_handle);
static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0);
@ -141,6 +121,8 @@ static const char *darwin_error_str (IOReturn result) {
return "out of resources";
case kIOUSBHighSpeedSplitError:
return "high speed split error";
case kIOUSBUnknownPipeErr:
return "pipe ref not recognized";
default:
snprintf(string_buffer, sizeof(string_buffer), "unknown error (0x%x)", result);
return string_buffer;
@ -168,6 +150,7 @@ static enum libusb_error darwin_to_libusb (IOReturn result) {
case kIOReturnAborted:
case kIOReturnError:
case kIOUSBNoAsyncPortErr:
case kIOUSBUnknownPipeErr:
default:
return LIBUSB_ERROR_OTHER;
}
@ -193,7 +176,7 @@ static void darwin_ref_cached_device(struct darwin_cached_device *cached_dev) {
}
static int ep_to_pipeRef(struct libusb_device_handle *dev_handle, uint8_t ep, uint8_t *pipep, uint8_t *ifcp, struct darwin_interface **interface_out) {
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
/* current interface */
struct darwin_interface *cInterface;
@ -353,7 +336,7 @@ static void darwin_devices_attached (void *ptr, io_iterator_t add_devices) {
}
/* add this device to each active context's device list */
list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
for_each_context(ctx) {
process_new_device (ctx, cached_device, old_session_id);
}
@ -397,7 +380,7 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
if (old_device->in_reenumerate) {
/* device is re-enumerating. do not dereference the device at this time. libusb_reset_device()
* will deref if needed. */
usbi_dbg ("detected device detatched due to re-enumeration");
usbi_dbg ("detected device detached due to re-enumeration");
/* the device object is no longer usable so go ahead and release it */
if (old_device->device) {
@ -419,7 +402,7 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
continue;
}
list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
for_each_context(ctx) {
usbi_dbg ("notifying context %p of device disconnect", ctx);
dev = usbi_get_device_by_session_id(ctx, (unsigned long) session);
@ -453,10 +436,20 @@ static void darwin_clear_iterator (io_iterator_t iter) {
IOObjectRelease (device);
}
static void darwin_fail_startup(void) {
pthread_mutex_lock (&libusb_darwin_at_mutex);
libusb_darwin_acfl = LIBUSB_DARWIN_STARTUP_FAILURE;
pthread_cond_signal (&libusb_darwin_at_cond);
pthread_mutex_unlock (&libusb_darwin_at_mutex);
pthread_exit (NULL);
}
static void *darwin_event_thread_main (void *arg0) {
IOReturn kresult;
struct libusb_context *ctx = (struct libusb_context *)arg0;
CFRunLoopRef runloop;
CFRunLoopSourceRef libusb_shutdown_cfsource;
CFRunLoopSourceContext libusb_shutdown_cfsourcectx;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
/* Set this thread's name, so it can be seen in the debugger
@ -475,7 +468,6 @@ static void *darwin_event_thread_main (void *arg0) {
#endif
/* hotplug (device arrival/removal) sources */
CFRunLoopSourceContext libusb_shutdown_cfsourcectx;
CFRunLoopSourceRef libusb_notification_cfsource;
io_notification_port_t libusb_notification_port;
io_iterator_t libusb_rem_device_iterator;
@ -490,8 +482,8 @@ static void *darwin_event_thread_main (void *arg0) {
memset(&libusb_shutdown_cfsourcectx, 0, sizeof(libusb_shutdown_cfsourcectx));
libusb_shutdown_cfsourcectx.info = runloop;
libusb_shutdown_cfsourcectx.perform = (void (*)(void *))CFRunLoopStop;
libusb_darwin_acfls = CFRunLoopSourceCreate(NULL, 0, &libusb_shutdown_cfsourcectx);
CFRunLoopAddSource(runloop, libusb_darwin_acfls, kCFRunLoopDefaultMode);
libusb_shutdown_cfsource = CFRunLoopSourceCreate(NULL, 0, &libusb_shutdown_cfsourcectx);
CFRunLoopAddSource(runloop, libusb_shutdown_cfsource, kCFRunLoopDefaultMode);
/* add the notification port to the run loop */
libusb_notification_port = IONotificationPortCreate (kIOMasterPortDefault);
@ -506,8 +498,9 @@ static void *darwin_event_thread_main (void *arg0) {
if (kresult != kIOReturnSuccess) {
usbi_err (ctx, "could not add hotplug event source: %s", darwin_error_str (kresult));
pthread_exit (NULL);
CFRelease (libusb_shutdown_cfsource);
CFRelease (runloop);
darwin_fail_startup ();
}
/* create notifications for attached devices */
@ -518,8 +511,9 @@ static void *darwin_event_thread_main (void *arg0) {
if (kresult != kIOReturnSuccess) {
usbi_err (ctx, "could not add hotplug event source: %s", darwin_error_str (kresult));
pthread_exit (NULL);
CFRelease (libusb_shutdown_cfsource);
CFRelease (runloop);
darwin_fail_startup ();
}
/* arm notifiers */
@ -531,6 +525,7 @@ static void *darwin_event_thread_main (void *arg0) {
/* signal the main thread that the hotplug runloop has been created. */
pthread_mutex_lock (&libusb_darwin_at_mutex);
libusb_darwin_acfl = runloop;
libusb_darwin_acfls = libusb_shutdown_cfsource;
pthread_cond_signal (&libusb_darwin_at_cond);
pthread_mutex_unlock (&libusb_darwin_at_mutex);
@ -539,11 +534,18 @@ static void *darwin_event_thread_main (void *arg0) {
usbi_dbg ("darwin event thread exiting");
/* signal the main thread that the hotplug runloop has finished. */
pthread_mutex_lock (&libusb_darwin_at_mutex);
libusb_darwin_acfls = NULL;
libusb_darwin_acfl = NULL;
pthread_cond_signal (&libusb_darwin_at_cond);
pthread_mutex_unlock (&libusb_darwin_at_mutex);
/* remove the notification cfsource */
CFRunLoopRemoveSource(runloop, libusb_notification_cfsource, kCFRunLoopDefaultMode);
/* remove the shutdown cfsource */
CFRunLoopRemoveSource(runloop, libusb_darwin_acfls, kCFRunLoopDefaultMode);
CFRunLoopRemoveSource(runloop, libusb_shutdown_cfsource, kCFRunLoopDefaultMode);
/* delete notification port */
IONotificationPortDestroy (libusb_notification_port);
@ -552,36 +554,37 @@ static void *darwin_event_thread_main (void *arg0) {
IOObjectRelease (libusb_rem_device_iterator);
IOObjectRelease (libusb_add_device_iterator);
CFRelease (libusb_darwin_acfls);
CFRelease (libusb_shutdown_cfsource);
CFRelease (runloop);
libusb_darwin_acfls = NULL;
libusb_darwin_acfl = NULL;
pthread_exit (NULL);
}
/* cleanup function to destroy cached devices */
static void __attribute__((destructor)) _darwin_finalize(void) {
static void darwin_cleanup_devices(void) {
struct darwin_cached_device *dev, *next;
usbi_mutex_lock(&darwin_cached_devices_lock);
list_for_each_entry_safe(dev, next, &darwin_cached_devices, list, struct darwin_cached_device) {
darwin_deref_cached_device(dev);
}
usbi_mutex_unlock(&darwin_cached_devices_lock);
darwin_cached_devices.prev = darwin_cached_devices.next = NULL;
}
static int darwin_init(struct libusb_context *ctx) {
bool first_init;
int rc;
rc = darwin_scan_devices (ctx);
if (LIBUSB_SUCCESS != rc) {
return rc;
}
pthread_mutex_lock (&libusb_darwin_init_mutex);
if (libusb_darwin_atomic_fetch_add (&initCount, 1) == 0) {
#if !OSX_USE_CLOCK_GETTIME
first_init = (1 == ++init_count);
do {
if (first_init) {
assert (NULL == darwin_cached_devices.next);
list_init (&darwin_cached_devices);
#if !defined(HAVE_CLOCK_GETTIME)
/* create the clocks that will be used if clock_gettime() is not available */
host_name_port_t host_self;
@ -590,45 +593,77 @@ static int darwin_init(struct libusb_context *ctx) {
host_get_clock_service(host_self, SYSTEM_CLOCK, &clock_monotonic);
mach_port_deallocate(mach_task_self(), host_self);
#endif
}
pthread_create (&libusb_darwin_at, NULL, darwin_event_thread_main, ctx);
rc = darwin_scan_devices (ctx);
if (LIBUSB_SUCCESS != rc)
break;
if (first_init) {
rc = pthread_create (&libusb_darwin_at, NULL, darwin_event_thread_main, ctx);
if (0 != rc) {
usbi_err (ctx, "could not create event thread, error %d", rc);
rc = LIBUSB_ERROR_OTHER;
break;
}
pthread_mutex_lock (&libusb_darwin_at_mutex);
while (!libusb_darwin_acfl)
pthread_cond_wait (&libusb_darwin_at_cond, &libusb_darwin_at_mutex);
pthread_mutex_unlock (&libusb_darwin_at_mutex);
if (libusb_darwin_acfl == LIBUSB_DARWIN_STARTUP_FAILURE) {
libusb_darwin_acfl = NULL;
rc = LIBUSB_ERROR_OTHER;
}
pthread_mutex_unlock (&libusb_darwin_at_mutex);
if (0 != rc)
pthread_join (libusb_darwin_at, NULL);
}
} while (0);
if (LIBUSB_SUCCESS != rc) {
if (first_init) {
darwin_cleanup_devices ();
#if !defined(HAVE_CLOCK_GETTIME)
mach_port_deallocate(mach_task_self(), clock_realtime);
mach_port_deallocate(mach_task_self(), clock_monotonic);
#endif
}
--init_count;
}
pthread_mutex_unlock (&libusb_darwin_init_mutex);
return rc;
}
static void darwin_exit (struct libusb_context *ctx) {
UNUSED(ctx);
if (libusb_darwin_atomic_fetch_add (&initCount, -1) == 1) {
#if !OSX_USE_CLOCK_GETTIME
pthread_mutex_lock (&libusb_darwin_init_mutex);
if (0 == --init_count) {
/* stop the event runloop and wait for the thread to terminate. */
pthread_mutex_lock (&libusb_darwin_at_mutex);
CFRunLoopSourceSignal (libusb_darwin_acfls);
CFRunLoopWakeUp (libusb_darwin_acfl);
while (libusb_darwin_acfl)
pthread_cond_wait (&libusb_darwin_at_cond, &libusb_darwin_at_mutex);
pthread_mutex_unlock (&libusb_darwin_at_mutex);
pthread_join (libusb_darwin_at, NULL);
darwin_cleanup_devices ();
#if !defined(HAVE_CLOCK_GETTIME)
mach_port_deallocate(mach_task_self(), clock_realtime);
mach_port_deallocate(mach_task_self(), clock_monotonic);
#endif
/* stop the event runloop and wait for the thread to terminate. */
CFRunLoopSourceSignal(libusb_darwin_acfls);
CFRunLoopWakeUp (libusb_darwin_acfl);
pthread_join (libusb_darwin_at, NULL);
}
pthread_mutex_unlock (&libusb_darwin_init_mutex);
}
static int darwin_get_device_descriptor(struct libusb_device *dev, unsigned char *buffer, int *host_endian) {
struct darwin_cached_device *priv = DARWIN_CACHED_DEVICE(dev);
/* return cached copy */
memmove (buffer, &(priv->dev_descriptor), DEVICE_DESC_LENGTH);
*host_endian = 0;
return LIBUSB_SUCCESS;
}
static int get_configuration_index (struct libusb_device *dev, int config_value) {
static int get_configuration_index (struct libusb_device *dev, UInt8 config_value) {
struct darwin_cached_device *priv = DARWIN_CACHED_DEVICE(dev);
UInt8 i, numConfig;
IOUSBConfigurationDescriptorPtr desc;
@ -650,7 +685,7 @@ static int get_configuration_index (struct libusb_device *dev, int config_value)
return LIBUSB_ERROR_NOT_FOUND;
}
static int darwin_get_active_config_descriptor(struct libusb_device *dev, unsigned char *buffer, size_t len, int *host_endian) {
static int darwin_get_active_config_descriptor(struct libusb_device *dev, void *buffer, size_t len) {
struct darwin_cached_device *priv = DARWIN_CACHED_DEVICE(dev);
int config_index;
@ -662,10 +697,10 @@ static int darwin_get_active_config_descriptor(struct libusb_device *dev, unsign
return config_index;
assert(config_index >= 0 && config_index <= UINT8_MAX);
return darwin_get_config_descriptor (dev, (UInt8)config_index, buffer, len, host_endian);
return darwin_get_config_descriptor (dev, (UInt8)config_index, buffer, len);
}
static int darwin_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian) {
static int darwin_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, void *buffer, size_t len) {
struct darwin_cached_device *priv = DARWIN_CACHED_DEVICE(dev);
IOUSBConfigurationDescriptorPtr desc;
IOReturn kresult;
@ -681,9 +716,6 @@ static int darwin_get_config_descriptor(struct libusb_device *dev, uint8_t confi
len = libusb_le16_to_cpu(desc->wTotalLength);
memmove (buffer, desc, len);
/* GetConfigurationDescriptorPtr returns the descriptor in USB bus order */
*host_endian = 0;
}
ret = darwin_to_libusb (kresult);
@ -710,7 +742,8 @@ static enum libusb_error darwin_check_configuration (struct libusb_context *ctx,
/* checking the configuration of a root hub simulation takes ~1 s in 10.11. the device is
not usable anyway */
if (0x05ac == dev->dev_descriptor.idVendor && 0x8005 == dev->dev_descriptor.idProduct) {
if (0x05ac == libusb_le16_to_cpu (dev->dev_descriptor.idVendor) &&
0x8005 == libusb_le16_to_cpu (dev->dev_descriptor.idProduct)) {
usbi_dbg ("ignoring configuration on root hub simulation");
dev->active_config = 0;
return LIBUSB_SUCCESS;
@ -891,14 +924,14 @@ static enum libusb_error darwin_cache_device_descriptor (struct darwin_cached_de
usbi_dbg ("cached device descriptor:");
usbi_dbg (" bDescriptorType: 0x%02x", dev->dev_descriptor.bDescriptorType);
usbi_dbg (" bcdUSB: 0x%04x", dev->dev_descriptor.bcdUSB);
usbi_dbg (" bcdUSB: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.bcdUSB));
usbi_dbg (" bDeviceClass: 0x%02x", dev->dev_descriptor.bDeviceClass);
usbi_dbg (" bDeviceSubClass: 0x%02x", dev->dev_descriptor.bDeviceSubClass);
usbi_dbg (" bDeviceProtocol: 0x%02x", dev->dev_descriptor.bDeviceProtocol);
usbi_dbg (" bMaxPacketSize0: 0x%02x", dev->dev_descriptor.bMaxPacketSize0);
usbi_dbg (" idVendor: 0x%04x", dev->dev_descriptor.idVendor);
usbi_dbg (" idProduct: 0x%04x", dev->dev_descriptor.idProduct);
usbi_dbg (" bcdDevice: 0x%04x", dev->dev_descriptor.bcdDevice);
usbi_dbg (" idVendor: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.idVendor));
usbi_dbg (" idProduct: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.idProduct));
usbi_dbg (" bcdDevice: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.bcdDevice));
usbi_dbg (" iManufacturer: 0x%02x", dev->dev_descriptor.iManufacturer);
usbi_dbg (" iProduct: 0x%02x", dev->dev_descriptor.iProduct);
usbi_dbg (" iSerialNumber: 0x%02x", dev->dev_descriptor.iSerialNumber);
@ -1035,7 +1068,8 @@ static enum libusb_error darwin_get_cached_device(io_service_t service, struct d
if (new_device->can_enumerate) {
snprintf(new_device->sys_path, 20, "%03i-%04x-%04x-%02x-%02x", new_device->address,
new_device->dev_descriptor.idVendor, new_device->dev_descriptor.idProduct,
libusb_le16_to_cpu (new_device->dev_descriptor.idVendor),
libusb_le16_to_cpu (new_device->dev_descriptor.idProduct),
new_device->dev_descriptor.bDeviceClass, new_device->dev_descriptor.bDeviceSubClass);
}
} while (0);
@ -1075,7 +1109,7 @@ static enum libusb_error process_new_device (struct libusb_context *ctx, struct
return LIBUSB_ERROR_NO_MEM;
}
priv = (struct darwin_device_priv *)dev->os_priv;
priv = usbi_get_device_priv(dev);
priv->dev = cached_device;
darwin_ref_cached_device (priv->dev);
@ -1084,9 +1118,15 @@ static enum libusb_error process_new_device (struct libusb_context *ctx, struct
assert(cached_device->address <= UINT8_MAX);
dev->device_address = (uint8_t)cached_device->address;
} else {
priv = (struct darwin_device_priv *)dev->os_priv;
priv = usbi_get_device_priv(dev);
}
static_assert(sizeof(dev->device_descriptor) == sizeof(cached_device->dev_descriptor),
"mismatch between libusb and IOKit device descriptor sizes");
memcpy(&dev->device_descriptor, &cached_device->dev_descriptor, LIBUSB_DT_DEVICE_SIZE);
usbi_localize_device_descriptor(&dev->device_descriptor);
dev->session_data = cached_device->session;
if (cached_device->parent_session > 0) {
dev->parent_dev = usbi_get_device_by_session_id (ctx, (unsigned long) cached_device->parent_session);
} else {
@ -1156,7 +1196,7 @@ static enum libusb_error darwin_scan_devices(struct libusb_context *ctx) {
}
static int darwin_open (struct libusb_device_handle *dev_handle) {
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
IOReturn kresult;
@ -1205,7 +1245,7 @@ static int darwin_open (struct libusb_device_handle *dev_handle) {
}
static void darwin_close (struct libusb_device_handle *dev_handle) {
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
IOReturn kresult;
int i;
@ -1244,10 +1284,10 @@ static void darwin_close (struct libusb_device_handle *dev_handle) {
}
}
static int darwin_get_configuration(struct libusb_device_handle *dev_handle, int *config) {
static int darwin_get_configuration(struct libusb_device_handle *dev_handle, uint8_t *config) {
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
*config = (int) dpriv->active_config;
*config = dpriv->active_config;
return LIBUSB_SUCCESS;
}
@ -1255,9 +1295,10 @@ static int darwin_get_configuration(struct libusb_device_handle *dev_handle, int
static enum libusb_error darwin_set_configuration(struct libusb_device_handle *dev_handle, int config) {
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
IOReturn kresult;
int i;
uint8_t i;
assert(config >= 0 && config <= UINT8_MAX);
if (config == -1)
config = 0;
/* Setting configuration will invalidate the interface, so we need
to reclaim it. First, dispose of existing interfaces, if any. */
@ -1279,7 +1320,7 @@ static enum libusb_error darwin_set_configuration(struct libusb_device_handle *d
return LIBUSB_SUCCESS;
}
static IOReturn darwin_get_interface (usb_device_t **darwin_device, int ifc, io_service_t *usbInterfacep) {
static IOReturn darwin_get_interface (usb_device_t **darwin_device, uint8_t ifc, io_service_t *usbInterfacep) {
IOUSBFindInterfaceRequest request;
IOReturn kresult;
io_iterator_t interface_iterator;
@ -1316,8 +1357,8 @@ static IOReturn darwin_get_interface (usb_device_t **darwin_device, int ifc, io_
return kIOReturnSuccess;
}
static enum libusb_error get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
static enum libusb_error get_endpoints (struct libusb_device_handle *dev_handle, uint8_t iface) {
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
/* current interface */
struct darwin_interface *cInterface = &priv->interfaces[iface];
@ -1376,21 +1417,19 @@ static enum libusb_error get_endpoints (struct libusb_device_handle *dev_handle,
return LIBUSB_SUCCESS;
}
static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int iface) {
static int darwin_claim_interface(struct libusb_device_handle *dev_handle, uint8_t iface) {
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
io_service_t usbInterface = IO_OBJECT_NULL;
IOReturn kresult;
enum libusb_error ret;
IOCFPlugInInterface **plugInInterface = NULL;
SInt32 score;
assert(iface >= 0 && iface <= UINT8_MAX);
/* current interface */
struct darwin_interface *cInterface = &priv->interfaces[iface];
kresult = darwin_get_interface (dpriv->device, (uint8_t)iface, &usbInterface);
kresult = darwin_get_interface (dpriv->device, iface, &usbInterface);
if (kresult != kIOReturnSuccess)
return darwin_to_libusb (kresult);
@ -1399,13 +1438,13 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
usbi_info (HANDLE_CTX (dev_handle), "no interface found; setting configuration: %d", dpriv->first_config);
/* set the configuration */
ret = darwin_set_configuration (dev_handle, dpriv->first_config);
ret = darwin_set_configuration (dev_handle, (int) dpriv->first_config);
if (ret != LIBUSB_SUCCESS) {
usbi_err (HANDLE_CTX (dev_handle), "could not set configuration");
return ret;
}
kresult = darwin_get_interface (dpriv->device, (uint8_t)iface, &usbInterface);
kresult = darwin_get_interface (dpriv->device, iface, &usbInterface);
if (kresult != kIOReturnSuccess) {
usbi_err (HANDLE_CTX (dev_handle), "darwin_get_interface: %s", darwin_error_str(kresult));
return darwin_to_libusb (kresult);
@ -1483,8 +1522,8 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
return LIBUSB_SUCCESS;
}
static int darwin_release_interface(struct libusb_device_handle *dev_handle, int iface) {
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
static int darwin_release_interface(struct libusb_device_handle *dev_handle, uint8_t iface) {
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
IOReturn kresult;
/* current interface */
@ -1516,8 +1555,8 @@ static int darwin_release_interface(struct libusb_device_handle *dev_handle, int
return darwin_to_libusb (kresult);
}
static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting) {
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_handle, uint8_t iface, uint8_t altsetting) {
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
IOReturn kresult;
enum libusb_error ret;
@ -1527,8 +1566,7 @@ static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_hand
if (!cInterface->interface)
return LIBUSB_ERROR_NO_DEVICE;
assert(altsetting >= 0 && altsetting <= UINT8_MAX);
kresult = (*(cInterface->interface))->SetAlternateInterface (cInterface->interface, (UInt8)altsetting);
kresult = (*(cInterface->interface))->SetAlternateInterface (cInterface->interface, altsetting);
if (kresult != kIOReturnSuccess)
darwin_reset_device (dev_handle);
@ -1568,7 +1606,7 @@ static int darwin_clear_halt(struct libusb_device_handle *dev_handle, unsigned c
static int darwin_restore_state (struct libusb_device_handle *dev_handle, int8_t active_config,
unsigned long claimed_interfaces) {
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
int open_count = dpriv->open_count;
int ret;
@ -1603,16 +1641,16 @@ static int darwin_restore_state (struct libusb_device_handle *dev_handle, int8_t
usbi_dbg ("darwin/restore_state: reclaiming interfaces");
if (claimed_interfaces) {
for (int iface = 0 ; iface < USB_MAXINTERFACES ; ++iface) {
for (uint8_t iface = 0 ; iface < USB_MAXINTERFACES ; ++iface) {
if (!(claimed_interfaces & (1U << iface))) {
continue;
}
usbi_dbg ("darwin/restore_state: re-claiming interface %d", iface);
usbi_dbg ("darwin/restore_state: re-claiming interface %u", iface);
ret = darwin_claim_interface (dev_handle, iface);
if (LIBUSB_SUCCESS != ret) {
usbi_dbg ("darwin/restore_state: could not claim interface %d", iface);
usbi_dbg ("darwin/restore_state: could not claim interface %u", iface);
return LIBUSB_ERROR_NOT_FOUND;
}
@ -1688,14 +1726,13 @@ static int darwin_reset_device(struct libusb_device_handle *dev_handle) {
return darwin_restore_state (dev_handle, active_config, claimed_interfaces);
}
static int darwin_kernel_driver_active(struct libusb_device_handle *dev_handle, int interface) {
static int darwin_kernel_driver_active(struct libusb_device_handle *dev_handle, uint8_t interface) {
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
io_service_t usbInterface;
CFTypeRef driver;
IOReturn kresult;
assert(interface >= 0 && interface <= UINT8_MAX);
kresult = darwin_get_interface (dpriv->device, (uint8_t)interface, &usbInterface);
kresult = darwin_get_interface (dpriv->device, interface, &usbInterface);
if (kresult != kIOReturnSuccess) {
usbi_err (HANDLE_CTX (dev_handle), "darwin_get_interface: %s", darwin_error_str(kresult));
@ -1715,21 +1752,8 @@ static int darwin_kernel_driver_active(struct libusb_device_handle *dev_handle,
return 0;
}
/* attaching/detaching kernel drivers is not currently supported (maybe in the future?) */
static int darwin_attach_kernel_driver (struct libusb_device_handle *dev_handle, int interface) {
UNUSED(dev_handle);
UNUSED(interface);
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int darwin_detach_kernel_driver (struct libusb_device_handle *dev_handle, int interface) {
UNUSED(dev_handle);
UNUSED(interface);
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static void darwin_destroy_device(struct libusb_device *dev) {
struct darwin_device_priv *dpriv = (struct darwin_device_priv *) dev->os_priv;
struct darwin_device_priv *dpriv = usbi_get_device_priv(dev);
if (dpriv->dev) {
/* need to hold the lock in case this is the last reference to the device */
@ -1745,11 +1769,16 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) {
IOReturn ret;
uint8_t transferType;
/* None of the values below are used in libusbx for bulk transfers */
uint8_t direction, number, interval, pipeRef;
uint8_t pipeRef;
uint16_t maxPacketSize;
struct darwin_interface *cInterface;
#if InterfaceVersion >= 550
IOUSBEndpointProperties pipeProperties = {.bVersion = kUSBEndpointPropertiesVersion3};
#else
/* None of the values below are used in libusb for bulk transfers */
uint8_t direction, number, interval;
#endif
if (ep_to_pipeRef (transfer->dev_handle, transfer->endpoint, &pipeRef, NULL, &cInterface) != 0) {
usbi_err (TRANSFER_CTX (transfer), "endpoint not found on any open interface");
@ -1757,8 +1786,15 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) {
return LIBUSB_ERROR_NOT_FOUND;
}
#if InterfaceVersion >= 550
ret = (*(cInterface->interface))->GetPipePropertiesV3 (cInterface->interface, pipeRef, &pipeProperties);
transferType = pipeProperties.bTransferType;
maxPacketSize = pipeProperties.wMaxPacketSize;
#else
ret = (*(cInterface->interface))->GetPipeProperties (cInterface->interface, pipeRef, &direction, &number,
&transferType, &maxPacketSize, &interval);
#endif
if (ret) {
usbi_err (TRANSFER_CTX (transfer), "bulk transfer failed (dir = %s): %s (code = 0x%08x)", IS_XFERIN(transfer) ? "In" : "Out",
@ -1834,7 +1870,7 @@ static int submit_stream_transfer(struct usbi_transfer *itransfer) {
static int submit_iso_transfer(struct usbi_transfer *itransfer) {
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
IOReturn kresult;
uint8_t direction, number, interval, pipeRef, transferType;
@ -1926,7 +1962,7 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) {
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_control_setup *setup = (struct libusb_control_setup *) transfer->buffer;
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(transfer->dev_handle->dev);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
IOReturn kresult;
@ -2058,20 +2094,10 @@ static int darwin_cancel_transfer(struct usbi_transfer *itransfer) {
}
}
static void darwin_clear_transfer_priv (struct usbi_transfer *itransfer) {
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
if (transfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS && tpriv->isoc_framelist) {
free (tpriv->isoc_framelist);
tpriv->isoc_framelist = NULL;
}
}
static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0) {
struct usbi_transfer *itransfer = (struct usbi_transfer *)refcon;
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
usbi_dbg ("an async io operation has completed");
@ -2120,74 +2146,63 @@ static enum libusb_transfer_status darwin_transfer_status (struct usbi_transfer
static int darwin_handle_transfer_completion (struct usbi_transfer *itransfer) {
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
bool isIsoc = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS == transfer->type;
bool isBulk = LIBUSB_TRANSFER_TYPE_BULK == transfer->type;
bool isControl = LIBUSB_TRANSFER_TYPE_CONTROL == transfer->type;
bool isInterrupt = LIBUSB_TRANSFER_TYPE_INTERRUPT == transfer->type;
int i;
struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
const unsigned char max_transfer_type = LIBUSB_TRANSFER_TYPE_BULK_STREAM;
const char *transfer_types[max_transfer_type + 1] = {"control", "isoc", "bulk", "interrupt", "bulk-stream"};
bool is_isoc = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS == transfer->type;
if (!isIsoc && !isBulk && !isControl && !isInterrupt) {
if (transfer->type > max_transfer_type) {
usbi_err (TRANSFER_CTX(transfer), "unknown endpoint type %d", transfer->type);
return LIBUSB_ERROR_INVALID_PARAM;
}
usbi_dbg ("handling %s completion with kernel status %d",
isControl ? "control" : isBulk ? "bulk" : isIsoc ? "isoc" : "interrupt", tpriv->result);
if (NULL == tpriv) {
usbi_err (TRANSFER_CTX(transfer), "malformed request is missing transfer priv");
return LIBUSB_ERROR_INVALID_PARAM;
}
usbi_dbg ("handling transfer completion type %s with kernel status %d", transfer_types[transfer->type], tpriv->result);
if (kIOReturnSuccess == tpriv->result || kIOReturnUnderrun == tpriv->result) {
if (isIsoc && tpriv->isoc_framelist) {
if (is_isoc && tpriv->isoc_framelist) {
/* copy isochronous results back */
for (i = 0; i < transfer->num_iso_packets ; i++) {
for (int i = 0; i < transfer->num_iso_packets ; i++) {
struct libusb_iso_packet_descriptor *lib_desc = &transfer->iso_packet_desc[i];
lib_desc->status = darwin_transfer_status (itransfer, tpriv->isoc_framelist[i].frStatus);
lib_desc->actual_length = tpriv->isoc_framelist[i].frActCount;
}
} else if (!isIsoc)
} else if (!is_isoc) {
itransfer->transferred += tpriv->size;
}
}
/* it is ok to handle cancelled transfers without calling usbi_handle_transfer_cancellation (we catch timeout transfers) */
return usbi_handle_transfer_completion (itransfer, darwin_transfer_status (itransfer, tpriv->result));
}
static int darwin_clock_gettime(int clk_id, struct timespec *tp) {
#if !OSX_USE_CLOCK_GETTIME
#if !defined(HAVE_CLOCK_GETTIME)
void usbi_get_monotonic_time(struct timespec *tp) {
mach_timespec_t sys_time;
clock_serv_t clock_ref;
switch (clk_id) {
case USBI_CLOCK_REALTIME:
/* CLOCK_REALTIME represents time since the epoch */
clock_ref = clock_realtime;
break;
case USBI_CLOCK_MONOTONIC:
/* use system boot time as reference for the monotonic clock */
clock_ref = clock_monotonic;
break;
default:
return LIBUSB_ERROR_INVALID_PARAM;
}
clock_get_time (clock_ref, &sys_time);
clock_get_time (clock_monotonic, &sys_time);
tp->tv_sec = sys_time.tv_sec;
tp->tv_nsec = sys_time.tv_nsec;
return LIBUSB_SUCCESS;
#else
switch (clk_id) {
case USBI_CLOCK_MONOTONIC:
return clock_gettime(CLOCK_MONOTONIC, tp);
case USBI_CLOCK_REALTIME:
return clock_gettime(CLOCK_REALTIME, tp);
default:
return LIBUSB_ERROR_INVALID_PARAM;
}
#endif
}
void usbi_get_real_time(struct timespec *tp) {
mach_timespec_t sys_time;
/* CLOCK_REALTIME represents time since the epoch */
clock_get_time (clock_realtime, &sys_time);
tp->tv_sec = sys_time.tv_sec;
tp->tv_nsec = sys_time.tv_nsec;
}
#endif
#if InterfaceVersion >= 550
static int darwin_alloc_streams (struct libusb_device_handle *dev_handle, uint32_t num_streams, unsigned char *endpoints,
int num_endpoints) {
@ -2196,7 +2211,7 @@ static int darwin_alloc_streams (struct libusb_device_handle *dev_handle, uint32
uint8_t pipeRef;
int rc, i;
/* find the mimimum number of supported streams on the endpoint list */
/* find the minimum number of supported streams on the endpoint list */
for (i = 0 ; i < num_endpoints ; ++i) {
if (0 != (rc = ep_to_pipeRef (dev_handle, endpoints[i], &pipeRef, NULL, &cInterface))) {
return rc;
@ -2252,8 +2267,6 @@ const struct usbi_os_backend usbi_backend = {
.caps = 0,
.init = darwin_init,
.exit = darwin_exit,
.get_device_list = NULL, /* not needed */
.get_device_descriptor = darwin_get_device_descriptor,
.get_active_config_descriptor = darwin_get_active_config_descriptor,
.get_config_descriptor = darwin_get_config_descriptor,
.hotplug_poll = darwin_hotplug_poll,
@ -2275,19 +2288,14 @@ const struct usbi_os_backend usbi_backend = {
#endif
.kernel_driver_active = darwin_kernel_driver_active,
.detach_kernel_driver = darwin_detach_kernel_driver,
.attach_kernel_driver = darwin_attach_kernel_driver,
.destroy_device = darwin_destroy_device,
.submit_transfer = darwin_submit_transfer,
.cancel_transfer = darwin_cancel_transfer,
.clear_transfer_priv = darwin_clear_transfer_priv,
.handle_transfer_completion = darwin_handle_transfer_completion,
.clock_gettime = darwin_clock_gettime,
.device_priv_size = sizeof(struct darwin_device_priv),
.device_handle_priv_size = sizeof(struct darwin_device_handle_priv),
.transfer_priv_size = sizeof(struct darwin_transfer_priv),

View file

@ -0,0 +1,300 @@
/*
* libusb event abstraction on POSIX platforms
*
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libusbi.h"
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_EVENTFD
#include <sys/eventfd.h>
#endif
#ifdef HAVE_TIMERFD
#include <sys/timerfd.h>
#endif
#include <unistd.h>
#ifdef HAVE_EVENTFD
#define EVENT_READ_FD(e) ((e)->eventfd)
#define EVENT_WRITE_FD(e) ((e)->eventfd)
#else
#define EVENT_READ_FD(e) ((e)->pipefd[0])
#define EVENT_WRITE_FD(e) ((e)->pipefd[1])
#endif
#ifdef HAVE_NFDS_T
typedef nfds_t usbi_nfds_t;
#else
typedef unsigned int usbi_nfds_t;
#endif
int usbi_create_event(usbi_event_t *event)
{
#ifdef HAVE_EVENTFD
event->eventfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
if (event->eventfd == -1) {
usbi_err(NULL, "failed to create eventfd, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
return 0;
#else
#if defined(HAVE_PIPE2)
int ret = pipe2(event->pipefd, O_CLOEXEC);
#else
int ret = pipe(event->pipefd);
#endif
if (ret != 0) {
usbi_err(NULL, "failed to create pipe, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
#if !defined(HAVE_PIPE2) && defined(FD_CLOEXEC)
ret = fcntl(event->pipefd[0], F_GETFD);
if (ret == -1) {
usbi_err(NULL, "failed to get pipe fd flags, errno=%d", errno);
goto err_close_pipe;
}
ret = fcntl(event->pipefd[0], F_SETFD, ret | FD_CLOEXEC);
if (ret == -1) {
usbi_err(NULL, "failed to set pipe fd flags, errno=%d", errno);
goto err_close_pipe;
}
ret = fcntl(event->pipefd[1], F_GETFD);
if (ret == -1) {
usbi_err(NULL, "failed to get pipe fd flags, errno=%d", errno);
goto err_close_pipe;
}
ret = fcntl(event->pipefd[1], F_SETFD, ret | FD_CLOEXEC);
if (ret == -1) {
usbi_err(NULL, "failed to set pipe fd flags, errno=%d", errno);
goto err_close_pipe;
}
#endif
ret = fcntl(event->pipefd[1], F_GETFL);
if (ret == -1) {
usbi_err(NULL, "failed to get pipe fd status flags, errno=%d", errno);
goto err_close_pipe;
}
ret = fcntl(event->pipefd[1], F_SETFL, ret | O_NONBLOCK);
if (ret == -1) {
usbi_err(NULL, "failed to set pipe fd status flags, errno=%d", errno);
goto err_close_pipe;
}
return 0;
err_close_pipe:
close(event->pipefd[1]);
close(event->pipefd[0]);
return LIBUSB_ERROR_OTHER;
#endif
}
void usbi_destroy_event(usbi_event_t *event)
{
#ifdef HAVE_EVENTFD
if (close(event->eventfd) == -1)
usbi_warn(NULL, "failed to close eventfd, errno=%d", errno);
#else
if (close(event->pipefd[1]) == -1)
usbi_warn(NULL, "failed to close pipe write end, errno=%d", errno);
if (close(event->pipefd[0]) == -1)
usbi_warn(NULL, "failed to close pipe read end, errno=%d", errno);
#endif
}
void usbi_signal_event(usbi_event_t *event)
{
uint64_t dummy = 1;
ssize_t r;
r = write(EVENT_WRITE_FD(event), &dummy, sizeof(dummy));
if (r != sizeof(dummy))
usbi_warn(NULL, "event write failed");
}
void usbi_clear_event(usbi_event_t *event)
{
uint64_t dummy;
ssize_t r;
r = read(EVENT_READ_FD(event), &dummy, sizeof(dummy));
if (r != sizeof(dummy))
usbi_warn(NULL, "event read failed");
}
#ifdef HAVE_TIMERFD
int usbi_create_timer(usbi_timer_t *timer)
{
timer->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
if (timer->timerfd == -1) {
usbi_warn(NULL, "failed to create timerfd, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
return 0;
}
void usbi_destroy_timer(usbi_timer_t *timer)
{
if (close(timer->timerfd) == -1)
usbi_warn(NULL, "failed to close timerfd, errno=%d", errno);
}
int usbi_arm_timer(usbi_timer_t *timer, const struct timespec *timeout)
{
const struct itimerspec it = { { 0, 0 }, { timeout->tv_sec, timeout->tv_nsec } };
if (timerfd_settime(timer->timerfd, TFD_TIMER_ABSTIME, &it, NULL) == -1) {
usbi_warn(NULL, "failed to arm timerfd, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
return 0;
}
int usbi_disarm_timer(usbi_timer_t *timer)
{
const struct itimerspec it = { { 0, 0 }, { 0, 0 } };
if (timerfd_settime(timer->timerfd, 0, &it, NULL) == -1) {
usbi_warn(NULL, "failed to disarm timerfd, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
return 0;
}
#endif
int usbi_alloc_event_data(struct libusb_context *ctx)
{
struct usbi_event_source *ievent_source;
struct pollfd *fds;
size_t i = 0;
if (ctx->event_data) {
free(ctx->event_data);
ctx->event_data = NULL;
}
ctx->event_data_cnt = 0;
for_each_event_source(ctx, ievent_source)
ctx->event_data_cnt++;
fds = calloc(ctx->event_data_cnt, sizeof(*fds));
if (!fds)
return LIBUSB_ERROR_NO_MEM;
for_each_event_source(ctx, ievent_source) {
fds[i].fd = ievent_source->data.os_handle;
fds[i].events = ievent_source->data.poll_events;
i++;
}
ctx->event_data = fds;
return 0;
}
int usbi_wait_for_events(struct libusb_context *ctx,
struct usbi_reported_events *reported_events, int timeout_ms)
{
struct pollfd *fds = ctx->event_data;
usbi_nfds_t nfds = (usbi_nfds_t)ctx->event_data_cnt;
int internal_fds, num_ready;
usbi_dbg("poll() %u fds with timeout in %dms", (unsigned int)nfds, timeout_ms);
num_ready = poll(fds, nfds, timeout_ms);
usbi_dbg("poll() returned %d", num_ready);
if (num_ready == 0) {
if (usbi_using_timer(ctx))
goto done;
return LIBUSB_ERROR_TIMEOUT;
} else if (num_ready == -1) {
if (errno == EINTR)
return LIBUSB_ERROR_INTERRUPTED;
usbi_err(ctx, "poll() failed, errno=%d", errno);
return LIBUSB_ERROR_IO;
}
/* fds[0] is always the internal signalling event */
if (fds[0].revents) {
reported_events->event_triggered = 1;
num_ready--;
} else {
reported_events->event_triggered = 0;
}
#ifdef HAVE_OS_TIMER
/* on timer configurations, fds[1] is the timer */
if (usbi_using_timer(ctx) && fds[1].revents) {
reported_events->timer_triggered = 1;
num_ready--;
} else {
reported_events->timer_triggered = 0;
}
#endif
if (!num_ready)
goto done;
/* the backend will never need to attempt to handle events on the
* library's internal file descriptors, so we determine how many are
* in use internally for this context and skip these when passing any
* remaining pollfds to the backend. */
internal_fds = usbi_using_timer(ctx) ? 2 : 1;
fds += internal_fds;
nfds -= internal_fds;
usbi_mutex_lock(&ctx->event_data_lock);
if (ctx->event_flags & USBI_EVENT_EVENT_SOURCES_MODIFIED) {
struct usbi_event_source *ievent_source;
for_each_removed_event_source(ctx, ievent_source) {
usbi_nfds_t n;
for (n = 0; n < nfds; n++) {
if (ievent_source->data.os_handle != fds[n].fd)
continue;
if (!fds[n].revents)
continue;
/* pollfd was removed between the creation of the fds array and
* here. remove triggered revent as it is no longer relevant. */
usbi_dbg("fd %d was removed, ignoring raised events", fds[n].fd);
fds[n].revents = 0;
num_ready--;
break;
}
}
}
usbi_mutex_unlock(&ctx->event_data_lock);
if (num_ready) {
assert(num_ready > 0);
reported_events->event_data = fds;
reported_events->event_data_count = (unsigned int)nfds;
}
done:
reported_events->num_ready = num_ready;
return LIBUSB_SUCCESS;
}

View file

@ -0,0 +1,59 @@
/*
* libusb event abstraction on POSIX platforms
*
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBUSB_EVENTS_POSIX_H
#define LIBUSB_EVENTS_POSIX_H
#include <poll.h>
typedef int usbi_os_handle_t;
#define USBI_OS_HANDLE_FORMAT_STRING "fd %d"
#ifdef HAVE_EVENTFD
typedef struct usbi_event {
int eventfd;
} usbi_event_t;
#define USBI_EVENT_OS_HANDLE(e) ((e)->eventfd)
#define USBI_EVENT_POLL_EVENTS POLLIN
#define USBI_INVALID_EVENT { -1 }
#else
typedef struct usbi_event {
int pipefd[2];
} usbi_event_t;
#define USBI_EVENT_OS_HANDLE(e) ((e)->pipefd[0])
#define USBI_EVENT_POLL_EVENTS POLLIN
#define USBI_INVALID_EVENT { { -1, -1 } }
#endif
#ifdef HAVE_TIMERFD
#define HAVE_OS_TIMER 1
typedef struct usbi_timer {
int timerfd;
} usbi_timer_t;
#define USBI_TIMER_OS_HANDLE(t) ((t)->timerfd)
#define USBI_TIMER_POLL_EVENTS POLLIN
static inline int usbi_timer_valid(usbi_timer_t *timer)
{
return timer->timerfd >= 0;
}
#endif
#endif

View file

@ -0,0 +1,214 @@
/*
* libusb event abstraction on Microsoft Windows
*
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include "libusbi.h"
#include "windows_common.h"
int usbi_create_event(usbi_event_t *event)
{
event->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (event->hEvent == NULL) {
usbi_err(NULL, "CreateEvent failed: %s", windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
return 0;
}
void usbi_destroy_event(usbi_event_t *event)
{
if (!CloseHandle(event->hEvent))
usbi_warn(NULL, "CloseHandle failed: %s", windows_error_str(0));
}
void usbi_signal_event(usbi_event_t *event)
{
if (!SetEvent(event->hEvent))
usbi_warn(NULL, "SetEvent failed: %s", windows_error_str(0));
}
void usbi_clear_event(usbi_event_t *event)
{
if (!ResetEvent(event->hEvent))
usbi_warn(NULL, "ResetEvent failed: %s", windows_error_str(0));
}
#ifdef HAVE_OS_TIMER
int usbi_create_timer(usbi_timer_t *timer)
{
timer->hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
if (timer->hTimer == NULL) {
usbi_warn(NULL, "CreateWaitableTimer failed: %s", windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
return 0;
}
void usbi_destroy_timer(usbi_timer_t *timer)
{
if (!CloseHandle(timer->hTimer))
usbi_warn(NULL, "CloseHandle failed: %s", windows_error_str(0));
}
int usbi_arm_timer(usbi_timer_t *timer, const struct timespec *timeout)
{
struct timespec systime, remaining;
FILETIME filetime;
LARGE_INTEGER dueTime;
/* Transfer timeouts are based on the monotonic clock and the waitable
* timers on the system clock. This requires a conversion between the
* two, so we calculate the remaining time relative to the monotonic
* clock and calculate an absolute system time for the timer expiration.
* Note that if the timeout has already passed, the remaining time will
* be negative and thus an absolute system time in the past will be set.
* This works just as intended because the timer becomes signalled
* immediately. */
usbi_get_monotonic_time(&systime);
TIMESPEC_SUB(timeout, &systime, &remaining);
GetSystemTimeAsFileTime(&filetime);
dueTime.LowPart = filetime.dwLowDateTime;
dueTime.HighPart = filetime.dwHighDateTime;
dueTime.QuadPart += (remaining.tv_sec * 10000000LL) + (remaining.tv_nsec / 100LL);
if (!SetWaitableTimer(timer->hTimer, &dueTime, 0, NULL, NULL, FALSE)) {
usbi_warn(NULL, "SetWaitableTimer failed: %s", windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
return 0;
}
int usbi_disarm_timer(usbi_timer_t *timer)
{
LARGE_INTEGER dueTime;
/* A manual-reset waitable timer will stay in the signalled state until
* another call to SetWaitableTimer() is made. It is possible that the
* timer has already expired by the time we come in to disarm it, so to
* be entirely sure the timer is disarmed and not in the signalled state,
* we will set it with an impossibly large expiration and immediately
* cancel. */
dueTime.QuadPart = LLONG_MAX;
if (!SetWaitableTimer(timer->hTimer, &dueTime, 0, NULL, NULL, FALSE)) {
usbi_warn(NULL, "SetWaitableTimer failed: %s", windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
if (!CancelWaitableTimer(timer->hTimer)) {
usbi_warn(NULL, "SetWaitableTimer failed: %s", windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
return 0;
}
#endif
int usbi_alloc_event_data(struct libusb_context *ctx)
{
struct usbi_event_source *ievent_source;
HANDLE *handles;
size_t i = 0;
/* Event sources are only added during usbi_io_init(). We should not
* be running this function again if the event data has already been
* allocated. */
if (ctx->event_data) {
usbi_warn(ctx, "program assertion failed - event data already allocated");
return LIBUSB_ERROR_OTHER;
}
ctx->event_data_cnt = 0;
for_each_event_source(ctx, ievent_source)
ctx->event_data_cnt++;
/* We only expect up to two HANDLEs to wait on, one for the internal
* signalling event and the other for the timer. */
if (ctx->event_data_cnt != 1 && ctx->event_data_cnt != 2) {
usbi_err(ctx, "program assertion failed - expected exactly 1 or 2 HANDLEs");
return LIBUSB_ERROR_OTHER;
}
handles = calloc(ctx->event_data_cnt, sizeof(HANDLE));
if (!handles)
return LIBUSB_ERROR_NO_MEM;
for_each_event_source(ctx, ievent_source) {
handles[i] = ievent_source->data.os_handle;
i++;
}
ctx->event_data = handles;
return 0;
}
int usbi_wait_for_events(struct libusb_context *ctx,
struct usbi_reported_events *reported_events, int timeout_ms)
{
HANDLE *handles = ctx->event_data;
DWORD num_handles = (DWORD)ctx->event_data_cnt;
DWORD result;
usbi_dbg("WaitForMultipleObjects() for %lu HANDLEs with timeout in %dms", ULONG_CAST(num_handles), timeout_ms);
result = WaitForMultipleObjects(num_handles, handles, FALSE, (DWORD)timeout_ms);
usbi_dbg("WaitForMultipleObjects() returned %lu", ULONG_CAST(result));
if (result == WAIT_TIMEOUT) {
if (usbi_using_timer(ctx))
goto done;
return LIBUSB_ERROR_TIMEOUT;
} else if (result == WAIT_FAILED) {
usbi_err(ctx, "WaitForMultipleObjects() failed: %s", windows_error_str(0));
return LIBUSB_ERROR_IO;
}
result -= WAIT_OBJECT_0;
/* handles[0] is always the internal signalling event */
if (result == 0)
reported_events->event_triggered = 1;
else
reported_events->event_triggered = 0;
#ifdef HAVE_OS_TIMER
/* on timer configurations, handles[1] is the timer */
if (usbi_using_timer(ctx)) {
/* The WaitForMultipleObjects() function reports the index of
* the first object that became signalled. If the internal
* signalling event was reported, we need to also check and
* report whether the timer is in the signalled state. */
if (result == 1 || WaitForSingleObject(handles[1], 0) == WAIT_OBJECT_0)
reported_events->timer_triggered = 1;
else
reported_events->timer_triggered = 0;
} else {
reported_events->timer_triggered = 0;
}
#endif
done:
/* no events are ever reported to the backend */
reported_events->num_ready = 0;
return LIBUSB_SUCCESS;
}

View file

@ -0,0 +1,46 @@
/*
* libusb event abstraction on Microsoft Windows
*
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBUSB_EVENTS_WINDOWS_H
#define LIBUSB_EVENTS_WINDOWS_H
typedef HANDLE usbi_os_handle_t;
#define USBI_OS_HANDLE_FORMAT_STRING "HANDLE %p"
typedef struct usbi_event {
HANDLE hEvent;
} usbi_event_t;
#define USBI_EVENT_OS_HANDLE(e) ((e)->hEvent)
#define USBI_EVENT_POLL_EVENTS 0
#define USBI_INVALID_EVENT { INVALID_HANDLE_VALUE }
#define HAVE_OS_TIMER 1
typedef struct usbi_timer {
HANDLE hTimer;
} usbi_timer_t;
#define USBI_TIMER_OS_HANDLE(t) ((t)->hTimer)
#define USBI_TIMER_POLL_EVENTS 0
static inline int usbi_timer_valid(usbi_timer_t *timer)
{
return timer->hTimer != NULL;
}
#endif

View file

@ -97,7 +97,7 @@ WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
unsigned long session_id = (unsigned long)&fDevice;
usbi_mutex_lock(&active_contexts_lock);
list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
for_each_context(ctx) {
struct libusb_device *dev = usbi_get_device_by_session_id(ctx, session_id);
if (dev) {
usbi_dbg("using previously allocated device with location %lu", session_id);
@ -110,7 +110,7 @@ WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
usbi_dbg("device allocation failed");
continue;
}
*((USBDevice **)dev->os_priv) = fDevice;
*((USBDevice **)usbi_get_device_priv(dev)) = fDevice;
// Calculate pseudo-device-address
int addr, tmp;
@ -125,9 +125,14 @@ WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
addr += tmp + 1;
parent_path.GetParent(&parent_path);
}
sscanf(path.Path(), "/dev/bus/usb/%d", &dev->bus_number);
sscanf(path.Path(), "/dev/bus/usb/%hhu", &dev->bus_number);
dev->device_address = addr - (dev->bus_number + 1);
static_assert(sizeof(dev->device_descriptor) == sizeof(usb_device_descriptor),
"mismatch between libusb and OS device descriptor sizes");
memcpy(&dev->device_descriptor, fDevice->Descriptor(), LIBUSB_DT_DEVICE_SIZE);
usbi_localize_device_descriptor(&dev->device_descriptor);
if (usbi_sanitize_device(dev) < 0) {
usbi_dbg("device sanitization failed");
libusb_unref_device(dev);
@ -167,7 +172,7 @@ WatchedEntry::~WatchedEntry()
unsigned long session_id = (unsigned long)&fDevice;
usbi_mutex_lock(&active_contexts_lock);
list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
for_each_context(ctx) {
dev = usbi_get_device_by_session_id(ctx, session_id);
if (dev != NULL) {
usbi_disconnect_device(dev);

View file

@ -38,22 +38,22 @@ public:
const char* Location() const;
uint8 CountConfigurations() const;
const usb_device_descriptor* Descriptor() const;
const usb_configuration_descriptor* ConfigurationDescriptor(uint32) const;
const usb_configuration_descriptor* ConfigurationDescriptor(uint8) const;
const usb_configuration_descriptor* ActiveConfiguration() const;
uint8 EndpointToIndex(uint8) const;
uint8 EndpointToInterface(uint8) const;
int ClaimInterface(int);
int ReleaseInterface(int);
int CheckInterfacesFree(int);
int SetActiveConfiguration(int);
int ActiveConfigurationIndex() const;
int ClaimInterface(uint8);
int ReleaseInterface(uint8);
int CheckInterfacesFree(uint8);
void SetActiveConfiguration(uint8);
uint8 ActiveConfigurationIndex() const;
bool InitCheck();
private:
int Initialise();
unsigned int fClaimedInterfaces; // Max Interfaces can be 32. Using a bitmask
usb_device_descriptor fDeviceDescriptor;
unsigned char** fConfigurationDescriptors;
int fActiveConfiguration;
uint8 fActiveConfiguration;
char* fPath;
map<uint8,uint8> fConfigToIndex;
map<uint8,uint8>* fEndpointToIndex;
@ -65,11 +65,11 @@ class USBDeviceHandle {
public:
USBDeviceHandle(USBDevice *dev);
virtual ~USBDeviceHandle();
int ClaimInterface(int);
int ReleaseInterface(int);
int SetConfiguration(int);
int SetAltSetting(int, int);
int ClearHalt(int);
int ClaimInterface(uint8);
int ReleaseInterface(uint8);
int SetConfiguration(uint8);
int SetAltSetting(uint8, uint8);
int ClearHalt(uint8);
status_t SubmitTransfer(struct usbi_transfer *);
status_t CancelTransfer(USBTransfer *);
bool InitCheck();

View file

@ -26,7 +26,7 @@
#include "haiku_usb.h"
int _errno_to_libusb(int status)
static int _errno_to_libusb(int status)
{
return status;
}
@ -127,7 +127,7 @@ USBTransfer::Do(int fRawFD)
int i;
usb_iso_packet_descriptor *packetDescriptors = new usb_iso_packet_descriptor[fLibusbTransfer->num_iso_packets];
for (i = 0; i < fLibusbTransfer->num_iso_packets; i++) {
if ((int16)(fLibusbTransfer->iso_packet_desc[i]).length != (fLibusbTransfer->iso_packet_desc[i]).length) {
if ((fLibusbTransfer->iso_packet_desc[i]).length > (unsigned int)INT16_MAX) {
fUsbiTransfer->transferred = -1;
usbi_err(TRANSFER_CTX(fLibusbTransfer), "failed isochronous transfer");
break;
@ -201,7 +201,7 @@ status_t
USBDeviceHandle::SubmitTransfer(struct usbi_transfer *itransfer)
{
USBTransfer *transfer = new USBTransfer(itransfer, fUSBDevice);
*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = transfer;
*((USBTransfer **)usbi_get_transfer_priv(itransfer)) = transfer;
BAutolock locker(fTransfersLock);
fTransfers.AddItem(transfer);
release_sem(fTransfersSem);
@ -215,16 +215,16 @@ USBDeviceHandle::CancelTransfer(USBTransfer *transfer)
fTransfersLock.Lock();
bool removed = fTransfers.RemoveItem(transfer);
fTransfersLock.Unlock();
if(removed)
if (removed)
usbi_signal_transfer_completion(transfer->UsbiTransfer());
return LIBUSB_SUCCESS;
}
USBDeviceHandle::USBDeviceHandle(USBDevice *dev)
:
fTransfersThread(-1),
fUSBDevice(dev),
fClaimedInterfaces(0),
fTransfersThread(-1),
fInitCheck(false)
{
fRawFD = open(dev->Location(), O_RDWR | O_CLOEXEC);
@ -242,7 +242,7 @@ USBDeviceHandle::~USBDeviceHandle()
{
if (fRawFD > 0)
close(fRawFD);
for(int i = 0; i < 32; i++) {
for (int i = 0; i < 32; i++) {
if (fClaimedInterfaces & (1U << i))
ReleaseInterface(i);
}
@ -252,7 +252,7 @@ USBDeviceHandle::~USBDeviceHandle()
}
int
USBDeviceHandle::ClaimInterface(int inumber)
USBDeviceHandle::ClaimInterface(uint8 inumber)
{
int status = fUSBDevice->ClaimInterface(inumber);
if (status == LIBUSB_SUCCESS)
@ -261,7 +261,7 @@ USBDeviceHandle::ClaimInterface(int inumber)
}
int
USBDeviceHandle::ReleaseInterface(int inumber)
USBDeviceHandle::ReleaseInterface(uint8 inumber)
{
fUSBDevice->ReleaseInterface(inumber);
fClaimedInterfaces &= ~(1U << inumber);
@ -269,10 +269,10 @@ USBDeviceHandle::ReleaseInterface(int inumber)
}
int
USBDeviceHandle::SetConfiguration(int config)
USBDeviceHandle::SetConfiguration(uint8 config)
{
int config_index = fUSBDevice->CheckInterfacesFree(config);
if(config_index == LIBUSB_ERROR_BUSY || config_index == LIBUSB_ERROR_NOT_FOUND)
if (config_index == LIBUSB_ERROR_BUSY || config_index == LIBUSB_ERROR_NOT_FOUND)
return config_index;
usb_raw_command command;
command.config.config_index = config_index;
@ -280,12 +280,12 @@ USBDeviceHandle::SetConfiguration(int config)
command.config.status != B_USB_RAW_STATUS_SUCCESS) {
return _errno_to_libusb(command.config.status);
}
fUSBDevice->SetActiveConfiguration(config_index);
fUSBDevice->SetActiveConfiguration((uint8)config_index);
return LIBUSB_SUCCESS;
}
int
USBDeviceHandle::SetAltSetting(int inumber, int alt)
USBDeviceHandle::SetAltSetting(uint8 inumber, uint8 alt)
{
usb_raw_command command;
command.alternate.config_index = fUSBDevice->ActiveConfigurationIndex();
@ -295,7 +295,7 @@ USBDeviceHandle::SetAltSetting(int inumber, int alt)
usbi_err(NULL, "Error retrieving active alternate interface");
return _errno_to_libusb(command.alternate.status);
}
if (command.alternate.alternate_info == alt) {
if (command.alternate.alternate_info == (uint32)alt) {
usbi_dbg("Setting alternate interface successful");
return LIBUSB_SUCCESS;
}
@ -309,9 +309,8 @@ USBDeviceHandle::SetAltSetting(int inumber, int alt)
return LIBUSB_SUCCESS;
}
int
USBDevice::ClearHalt(int endpoint)
USBDeviceHandle::ClearHalt(uint8 endpoint)
{
usb_raw_command command;
command.control.request_type = USB_REQTYPE_ENDPOINT_OUT;
@ -324,15 +323,16 @@ USBDevice::ClearHalt(int endpoint)
command.control.status != B_USB_RAW_STATUS_SUCCESS) {
return _errno_to_libusb(command.control.status);
}
return LIBUSB_SUCCESS;
}
USBDevice::USBDevice(const char *path)
:
fPath(NULL),
fActiveConfiguration(0), //0?
fConfigurationDescriptors(NULL),
fClaimedInterfaces(0),
fConfigurationDescriptors(NULL),
fActiveConfiguration(0), //0?
fPath(NULL),
fEndpointToIndex(NULL),
fEndpointToInterface(NULL),
fInitCheck(false)
@ -345,7 +345,7 @@ USBDevice::~USBDevice()
{
free(fPath);
if (fConfigurationDescriptors) {
for(int i = 0; i < fDeviceDescriptor.num_configurations; i++) {
for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
if (fConfigurationDescriptors[i])
delete fConfigurationDescriptors[i];
}
@ -382,7 +382,7 @@ USBDevice::Descriptor() const
}
const usb_configuration_descriptor *
USBDevice::ConfigurationDescriptor(uint32 index) const
USBDevice::ConfigurationDescriptor(uint8 index) const
{
if (index > CountConfigurations())
return NULL;
@ -395,13 +395,13 @@ USBDevice::ActiveConfiguration() const
return (usb_configuration_descriptor *) fConfigurationDescriptors[fActiveConfiguration];
}
int
uint8
USBDevice::ActiveConfigurationIndex() const
{
return fActiveConfiguration;
}
int USBDevice::ClaimInterface(int interface)
int USBDevice::ClaimInterface(uint8 interface)
{
if (interface > ActiveConfiguration()->number_interfaces)
return LIBUSB_ERROR_NOT_FOUND;
@ -411,27 +411,26 @@ int USBDevice::ClaimInterface(int interface)
return LIBUSB_SUCCESS;
}
int USBDevice::ReleaseInterface(int interface)
int USBDevice::ReleaseInterface(uint8 interface)
{
fClaimedInterfaces &= ~(1U << interface);
return LIBUSB_SUCCESS;
}
int
USBDevice::CheckInterfacesFree(int config)
USBDevice::CheckInterfacesFree(uint8 config)
{
if (fConfigToIndex.count(config) == 0)
return LIBUSB_ERROR_NOT_FOUND;
if (fClaimedInterfaces == 0)
return fConfigToIndex[(uint8)config];
return fConfigToIndex[config];
return LIBUSB_ERROR_BUSY;
}
int
USBDevice::SetActiveConfiguration(int config_index)
void
USBDevice::SetActiveConfiguration(uint8 config_index)
{
fActiveConfiguration = config_index;
return LIBUSB_SUCCESS;
}
uint8
@ -463,7 +462,7 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
fConfigurationDescriptors = new(std::nothrow) unsigned char *[fDeviceDescriptor.num_configurations];
fEndpointToIndex = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
fEndpointToInterface = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
for (int i = 0; i < fDeviceDescriptor.num_configurations; i++) {
for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
usb_configuration_descriptor tmp_config;
command.config.descriptor = &tmp_config;
command.config.config_index = i;
@ -479,14 +478,14 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
command.config_etc.descriptor = (usb_configuration_descriptor*)fConfigurationDescriptors[i];
command.config_etc.length = tmp_config.total_length;
command.config_etc.config_index = i;
if (ioctl(fRawFD, B_USB_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC, &command, sizeof(command)) ||
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC, &command, sizeof(command)) ||
command.config_etc.status != B_USB_RAW_STATUS_SUCCESS) {
usbi_err(NULL, "failed retrieving full configuration descriptor");
close(fRawFD);
return B_ERROR;
}
for (int j = 0; j < tmp_config.number_interfaces; j++) {
for (uint8 j = 0; j < tmp_config.number_interfaces; j++) {
command.alternate.config_index = i;
command.alternate.interface_index = j;
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command, sizeof(command)) ||
@ -495,8 +494,8 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
close(fRawFD);
return B_ERROR;
}
int num_alternate = command.alternate.alternate_info;
for (int k = 0; k < num_alternate; k++) {
uint8 num_alternate = (uint8)command.alternate.alternate_info;
for (uint8 k = 0; k < num_alternate; k++) {
usb_interface_descriptor tmp_interface;
command.interface_etc.config_index = i;
command.interface_etc.interface_index = j;
@ -508,7 +507,7 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
close(fRawFD);
return B_ERROR;
}
for (int l = 0; l < tmp_interface.num_endpoints; l++) {
for (uint8 l = 0; l < tmp_interface.num_endpoints; l++) {
usb_endpoint_descriptor tmp_endpoint;
command.endpoint_etc.config_index = i;
command.endpoint_etc.interface_index = j;

View file

@ -30,11 +30,12 @@ USBRoster gUsbRoster;
int32 gInitCount = 0;
static int haiku_get_config_descriptor(struct libusb_device *, uint8_t,
unsigned char *, size_t, int *);
void *, size_t);
static int
haiku_init(struct libusb_context *ctx)
{
UNUSED(ctx);
if (atomic_add(&gInitCount, 1) == 0)
return gUsbRoster.Start();
return LIBUSB_SUCCESS;
@ -51,7 +52,7 @@ haiku_exit(struct libusb_context *ctx)
static int
haiku_open(struct libusb_device_handle *dev_handle)
{
USBDevice *dev = *((USBDevice **)dev_handle->dev->os_priv);
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(dev_handle->dev));
USBDeviceHandle *handle = new(std::nothrow) USBDeviceHandle(dev);
if (handle == NULL)
return LIBUSB_ERROR_NO_MEM;
@ -59,93 +60,79 @@ haiku_open(struct libusb_device_handle *dev_handle)
delete handle;
return LIBUSB_ERROR_NO_DEVICE;
}
*((USBDeviceHandle **)dev_handle->os_priv) = handle;
*((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle)) = handle;
return LIBUSB_SUCCESS;
}
static void
haiku_close(struct libusb_device_handle *dev_handle)
{
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
USBDeviceHandle **pHandle = (USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle);
USBDeviceHandle *handle = *pHandle;
if (handle == NULL)
return;
delete handle;
*((USBDeviceHandle **)dev_handle->os_priv) = NULL;
*pHandle = NULL;
}
static int
haiku_get_device_descriptor(struct libusb_device *device, unsigned char *buffer, int *host_endian)
haiku_get_active_config_descriptor(struct libusb_device *device, void *buffer, size_t len)
{
USBDevice *dev = *((USBDevice **)device->os_priv);
memcpy(buffer, dev->Descriptor(), DEVICE_DESC_LENGTH);
*host_endian = 0;
return LIBUSB_SUCCESS;
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
return haiku_get_config_descriptor(device, dev->ActiveConfigurationIndex(), buffer, len);
}
static int
haiku_get_active_config_descriptor(struct libusb_device *device, unsigned char *buffer, size_t len, int *host_endian)
haiku_get_config_descriptor(struct libusb_device *device, uint8_t config_index, void *buffer, size_t len)
{
USBDevice *dev = *((USBDevice **)device->os_priv);
return haiku_get_config_descriptor(device, dev->ActiveConfigurationIndex(), buffer, len, host_endian);
}
static int
haiku_get_config_descriptor(struct libusb_device *device, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian)
{
USBDevice *dev = *((USBDevice **)device->os_priv);
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
const usb_configuration_descriptor *config = dev->ConfigurationDescriptor(config_index);
if (config == NULL) {
usbi_err(DEVICE_CTX(device), "failed getting configuration descriptor");
return LIBUSB_ERROR_INVALID_PARAM;
return LIBUSB_ERROR_IO;
}
if (len > config->total_length) {
len = config->total_length;
}
memcpy(buffer, config, len);
*host_endian = 0;
return len;
}
static int
haiku_set_configuration(struct libusb_device_handle *dev_handle, int config)
{
USBDeviceHandle *handle= *((USBDeviceHandle **)dev_handle->os_priv);
return handle->SetConfiguration(config);
USBDeviceHandle *handle= *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
if (config <= 0)
return LIBUSB_ERROR_NOT_SUPPORTED; // cannot unconfigure
return handle->SetConfiguration((uint8)config);
}
static int
haiku_claim_interface(struct libusb_device_handle *dev_handle, int interface_number)
haiku_claim_interface(struct libusb_device_handle *dev_handle, uint8_t interface_number)
{
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
return handle->ClaimInterface(interface_number);
}
static int
haiku_set_altsetting(struct libusb_device_handle *dev_handle, int interface_number, int altsetting)
haiku_set_altsetting(struct libusb_device_handle *dev_handle, uint8_t interface_number, uint8_t altsetting)
{
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
return handle->SetAltSetting(interface_number, altsetting);
}
static int
haiku_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
return handle->ClearHalt(endpoint);
}
static int
haiku_reset_device(struct libusb_device_handle *dev_handle)
haiku_release_interface(struct libusb_device_handle *dev_handle, uint8_t interface_number)
{
/* TODO */
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
haiku_release_interface(struct libusb_device_handle *dev_handle, int interface_number)
{
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
haiku_set_altsetting(dev_handle,interface_number, 0);
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
haiku_set_altsetting(dev_handle, interface_number, 0);
return handle->ReleaseInterface(interface_number);
}
@ -153,7 +140,7 @@ static int
haiku_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle->os_priv);
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)usbi_get_device_handle_priv(fLibusbTransfer->dev_handle));
return fDeviceHandle->SubmitTransfer(itransfer);
}
@ -161,27 +148,20 @@ static int
haiku_cancel_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle->os_priv);
return fDeviceHandle->CancelTransfer(*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)));
}
static void
haiku_clear_transfer_priv(struct usbi_transfer *itransfer)
{
USBTransfer *transfer = *((USBTransfer **)usbi_transfer_get_os_priv(itransfer));
delete transfer;
*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)usbi_get_device_handle_priv(fLibusbTransfer->dev_handle));
return fDeviceHandle->CancelTransfer(*((USBTransfer **)usbi_get_transfer_priv(itransfer)));
}
static int
haiku_handle_transfer_completion(struct usbi_transfer *itransfer)
{
USBTransfer *transfer = *((USBTransfer **)usbi_transfer_get_os_priv(itransfer));
USBTransfer **pTransfer = (USBTransfer **)usbi_get_transfer_priv(itransfer);
USBTransfer *transfer = *pTransfer;
usbi_mutex_lock(&itransfer->lock);
if (transfer->IsCancelled()) {
delete transfer;
*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
*pTransfer = NULL;
usbi_mutex_unlock(&itransfer->lock);
if (itransfer->transferred < 0)
itransfer->transferred = 0;
@ -194,74 +174,58 @@ haiku_handle_transfer_completion(struct usbi_transfer *itransfer)
itransfer->transferred = 0;
}
delete transfer;
*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
*pTransfer = NULL;
usbi_mutex_unlock(&itransfer->lock);
return usbi_handle_transfer_completion(itransfer, status);
}
static int
haiku_clock_gettime(int clkid, struct timespec *tp)
{
if (clkid == USBI_CLOCK_REALTIME)
return clock_gettime(CLOCK_REALTIME, tp);
if (clkid == USBI_CLOCK_MONOTONIC)
return clock_gettime(CLOCK_MONOTONIC, tp);
return LIBUSB_ERROR_INVALID_PARAM;
}
const struct usbi_os_backend usbi_backend = {
.name = "Haiku usbfs",
.caps = 0,
.init = haiku_init,
.exit = haiku_exit,
.set_option = NULL,
.get_device_list = NULL,
.hotplug_poll = NULL,
.wrap_sys_device = NULL,
.open = haiku_open,
.close = haiku_close,
.get_device_descriptor = haiku_get_device_descriptor,
.get_active_config_descriptor = haiku_get_active_config_descriptor,
.get_config_descriptor = haiku_get_config_descriptor,
.get_config_descriptor_by_value = NULL,
/*.name =*/ "Haiku usbfs",
/*.caps =*/ 0,
/*.init =*/ haiku_init,
/*.exit =*/ haiku_exit,
/*.set_option =*/ NULL,
/*.get_device_list =*/ NULL,
/*.hotplug_poll =*/ NULL,
/*.wrap_sys_device =*/ NULL,
/*.open =*/ haiku_open,
/*.close =*/ haiku_close,
/*.get_active_config_descriptor =*/ haiku_get_active_config_descriptor,
/*.get_config_descriptor =*/ haiku_get_config_descriptor,
/*.get_config_descriptor_by_value =*/ NULL,
.get_configuration = NULL,
.set_configuration = haiku_set_configuration,
.claim_interface = haiku_claim_interface,
.release_interface = haiku_release_interface,
/*.get_configuration =*/ NULL,
/*.set_configuration =*/ haiku_set_configuration,
.set_interface_altsetting = haiku_set_altsetting,
.clear_halt = haiku_clear_halt,
.reset_device = haiku_reset_device,
/*.claim_interface =*/ haiku_claim_interface,
/*.release_interface =*/ haiku_release_interface,
/*.set_interface_altsetting =*/ haiku_set_altsetting,
.alloc_streams = NULL,
.free_streams = NULL,
/*.clear_halt =*/ haiku_clear_halt,
/*.reset_device =*/ NULL,
.dev_mem_alloc = NULL,
.dev_mem_free = NULL,
/*.alloc_streams =*/ NULL,
/*.free_streams =*/ NULL,
.kernel_driver_active = NULL,
.detach_kernel_driver = NULL,
.attach_kernel_driver = NULL,
/*.dev_mem_alloc =*/ NULL,
/*.dev_mem_free =*/ NULL,
.destroy_device = NULL,
/*.kernel_driver_active =*/ NULL,
/*.detach_kernel_driver =*/ NULL,
/*.attach_kernel_driver =*/ NULL,
.submit_transfer = haiku_submit_transfer,
.cancel_transfer = haiku_cancel_transfer,
.clear_transfer_priv = haiku_clear_transfer_priv,
/*.destroy_device =*/ NULL,
.handle_events = NULL,
.handle_transfer_completion = haiku_handle_transfer_completion,
/*.submit_transfer =*/ haiku_submit_transfer,
/*.cancel_transfer =*/ haiku_cancel_transfer,
/*.clear_transfer_priv =*/ NULL,
.clock_gettime = haiku_clock_gettime,
/*.handle_events =*/ NULL,
/*.handle_transfer_completion =*/ haiku_handle_transfer_completion,
#ifdef USBI_TIMERFD_AVAILABLE
.get_timerfd_clockid = NULL,
#endif
.context_priv_size = 0,
.device_priv_size = sizeof(USBDevice *),
.device_handle_priv_size = sizeof(USBDeviceHandle *),
.transfer_priv_size = sizeof(USBTransfer *),
/*.context_priv_size =*/ 0,
/*.device_priv_size =*/ sizeof(USBDevice *),
/*.device_handle_priv_size =*/ sizeof(USBDeviceHandle *),
/*.transfer_priv_size =*/ sizeof(USBTransfer *),
};

View file

@ -21,27 +21,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include "libusbi.h"
#include "linux_usbfs.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#ifdef HAVE_ASM_TYPES_H
#include <asm/types.h>
#endif
#include <sys/socket.h>
#include <linux/netlink.h>
#include "libusbi.h"
#include "linux_usbfs.h"
#include <sys/socket.h>
#define NL_GROUP_KERNEL 1
@ -54,7 +48,7 @@
#endif
static int linux_netlink_socket = -1;
static int netlink_control_pipe[2] = { -1, -1 };
static usbi_event_t netlink_control_event = USBI_INVALID_EVENT;
static pthread_t libusb_linux_event_thread;
static void *linux_netlink_event_thread_main(void *arg);
@ -68,12 +62,12 @@ static int set_fd_cloexec_nb(int fd, int socktype)
if (!(socktype & SOCK_CLOEXEC)) {
flags = fcntl(fd, F_GETFD);
if (flags == -1) {
usbi_err(NULL, "failed to get netlink fd flags (%d)", errno);
usbi_err(NULL, "failed to get netlink fd flags, errno=%d", errno);
return -1;
}
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) {
usbi_err(NULL, "failed to set netlink fd flags (%d)", errno);
usbi_err(NULL, "failed to set netlink fd flags, errno=%d", errno);
return -1;
}
}
@ -83,12 +77,12 @@ static int set_fd_cloexec_nb(int fd, int socktype)
if (!(socktype & SOCK_NONBLOCK)) {
flags = fcntl(fd, F_GETFL);
if (flags == -1) {
usbi_err(NULL, "failed to get netlink fd status flags (%d)", errno);
usbi_err(NULL, "failed to get netlink fd status flags, errno=%d", errno);
return -1;
}
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
usbi_err(NULL, "failed to set netlink fd status flags (%d)", errno);
usbi_err(NULL, "failed to set netlink fd status flags, errno=%d", errno);
return -1;
}
}
@ -111,7 +105,7 @@ int linux_netlink_start_event_monitor(void)
}
if (linux_netlink_socket == -1) {
usbi_err(NULL, "failed to create netlink socket (%d)", errno);
usbi_err(NULL, "failed to create netlink socket, errno=%d", errno);
goto err;
}
@ -121,35 +115,33 @@ int linux_netlink_start_event_monitor(void)
ret = bind(linux_netlink_socket, (struct sockaddr *)&sa_nl, sizeof(sa_nl));
if (ret == -1) {
usbi_err(NULL, "failed to bind netlink socket (%d)", errno);
usbi_err(NULL, "failed to bind netlink socket, errno=%d", errno);
goto err_close_socket;
}
ret = setsockopt(linux_netlink_socket, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt));
if (ret == -1) {
usbi_err(NULL, "failed to set netlink socket SO_PASSCRED option (%d)", errno);
usbi_err(NULL, "failed to set netlink socket SO_PASSCRED option, errno=%d", errno);
goto err_close_socket;
}
ret = usbi_pipe(netlink_control_pipe);
ret = usbi_create_event(&netlink_control_event);
if (ret) {
usbi_err(NULL, "failed to create netlink control pipe");
usbi_err(NULL, "failed to create netlink control event");
goto err_close_socket;
}
ret = pthread_create(&libusb_linux_event_thread, NULL, linux_netlink_event_thread_main, NULL);
if (ret != 0) {
usbi_err(NULL, "failed to create netlink event thread (%d)", ret);
goto err_close_pipe;
goto err_destroy_event;
}
return LIBUSB_SUCCESS;
err_close_pipe:
close(netlink_control_pipe[0]);
close(netlink_control_pipe[1]);
netlink_control_pipe[0] = -1;
netlink_control_pipe[1] = -1;
err_destroy_event:
usbi_destroy_event(&netlink_control_event);
netlink_control_event = (usbi_event_t)USBI_INVALID_EVENT;
err_close_socket:
close(linux_netlink_socket);
linux_netlink_socket = -1;
@ -159,28 +151,23 @@ err:
int linux_netlink_stop_event_monitor(void)
{
char dummy = 1;
ssize_t r;
int ret;
assert(linux_netlink_socket != -1);
/* Write some dummy data to the control pipe and
* wait for the thread to exit */
r = write(netlink_control_pipe[1], &dummy, sizeof(dummy));
if (r <= 0)
usbi_warn(NULL, "netlink control pipe signal failed");
/* Signal the control event and wait for the thread to exit */
usbi_signal_event(&netlink_control_event);
pthread_join(libusb_linux_event_thread, NULL);
ret = pthread_join(libusb_linux_event_thread, NULL);
if (ret)
usbi_warn(NULL, "failed to join netlink event thread (%d)", ret);
usbi_destroy_event(&netlink_control_event);
netlink_control_event = (usbi_event_t)USBI_INVALID_EVENT;
close(linux_netlink_socket);
linux_netlink_socket = -1;
/* close and reset control pipe */
close(netlink_control_pipe[0]);
close(netlink_control_pipe[1]);
netlink_control_pipe[0] = -1;
netlink_control_pipe[1] = -1;
return LIBUSB_SUCCESS;
}
@ -314,7 +301,7 @@ static int linux_netlink_read_message(void)
len = recvmsg(linux_netlink_socket, &msg, 0);
if (len == -1) {
if (errno != EAGAIN && errno != EINTR)
usbi_err(NULL, "error receiving message from netlink (%d)", errno);
usbi_err(NULL, "error receiving message from netlink, errno=%d", errno);
return -1;
}
@ -359,33 +346,38 @@ static int linux_netlink_read_message(void)
static void *linux_netlink_event_thread_main(void *arg)
{
char dummy;
int r;
ssize_t nb;
struct pollfd fds[] = {
{ .fd = netlink_control_pipe[0],
.events = POLLIN },
{ .fd = USBI_EVENT_OS_HANDLE(&netlink_control_event),
.events = USBI_EVENT_POLL_EVENTS },
{ .fd = linux_netlink_socket,
.events = POLLIN },
};
int r;
UNUSED(arg);
#if defined(HAVE_PTHREAD_SETNAME_NP)
r = pthread_setname_np(pthread_self(), "libusb_event");
if (r)
usbi_warn(NULL, "failed to set hotplug event thread name, error=%d", r);
#endif
usbi_dbg("netlink event thread entering");
while ((r = poll(fds, 2, -1)) >= 0 || errno == EINTR) {
if (r < 0) {
/* temporary failure */
while (1) {
r = poll(fds, 2, -1);
if (r == -1) {
/* check for temporary failure */
if (errno == EINTR)
continue;
}
if (fds[0].revents & POLLIN) {
/* activity on control pipe, read the byte and exit */
nb = read(netlink_control_pipe[0], &dummy, sizeof(dummy));
if (nb <= 0)
usbi_warn(NULL, "netlink control pipe read failed");
usbi_err(NULL, "poll() failed, errno=%d", errno);
break;
}
if (fds[1].revents & POLLIN) {
if (fds[0].revents) {
/* activity on control event, exit */
break;
}
if (fds[1].revents) {
usbi_mutex_static_lock(&linux_hotplug_lock);
linux_netlink_read_message();
usbi_mutex_static_unlock(&linux_hotplug_lock);

View file

@ -20,36 +20,25 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/socket.h>
#include <unistd.h>
#include <libudev.h>
#include "libusbi.h"
#include "linux_usbfs.h"
#include <errno.h>
#include <fcntl.h>
#include <libudev.h>
#include <poll.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
/* udev context */
static struct udev *udev_ctx = NULL;
static int udev_monitor_fd = -1;
static int udev_control_pipe[2] = {-1, -1};
static usbi_event_t udev_control_event = USBI_INVALID_EVENT;
static struct udev_monitor *udev_monitor = NULL;
static pthread_t linux_event_thread;
static void udev_hotplug_event(struct udev_device* udev_dev);
static void udev_hotplug_event(struct udev_device *udev_dev);
static void *linux_udev_event_thread_main(void *arg);
int linux_udev_start_event_monitor(void)
@ -86,12 +75,12 @@ int linux_udev_start_event_monitor(void)
/* Make sure the udev file descriptor is marked as CLOEXEC */
r = fcntl(udev_monitor_fd, F_GETFD);
if (r == -1) {
usbi_err(NULL, "geting udev monitor fd flags (%d)", errno);
usbi_err(NULL, "failed to get udev monitor fd flags, errno=%d", errno);
goto err_free_monitor;
}
if (!(r & FD_CLOEXEC)) {
if (fcntl(udev_monitor_fd, F_SETFD, r | FD_CLOEXEC) == -1) {
usbi_err(NULL, "setting udev monitor fd flags (%d)", errno);
usbi_err(NULL, "failed to set udev monitor fd flags, errno=%d", errno);
goto err_free_monitor;
}
}
@ -101,33 +90,33 @@ int linux_udev_start_event_monitor(void)
* so make sure this is set */
r = fcntl(udev_monitor_fd, F_GETFL);
if (r == -1) {
usbi_err(NULL, "getting udev monitor fd status flags (%d)", errno);
usbi_err(NULL, "failed to get udev monitor fd status flags, errno=%d", errno);
goto err_free_monitor;
}
if (!(r & O_NONBLOCK)) {
if (fcntl(udev_monitor_fd, F_SETFL, r | O_NONBLOCK) == -1) {
usbi_err(NULL, "setting udev monitor fd status flags (%d)", errno);
usbi_err(NULL, "failed to set udev monitor fd status flags, errno=%d", errno);
goto err_free_monitor;
}
}
r = usbi_pipe(udev_control_pipe);
r = usbi_create_event(&udev_control_event);
if (r) {
usbi_err(NULL, "could not create udev control pipe");
usbi_err(NULL, "failed to create udev control event");
goto err_free_monitor;
}
r = pthread_create(&linux_event_thread, NULL, linux_udev_event_thread_main, NULL);
if (r) {
usbi_err(NULL, "creating hotplug event thread (%d)", r);
goto err_close_pipe;
usbi_err(NULL, "failed to create hotplug event thread (%d)", r);
goto err_destroy_event;
}
return LIBUSB_SUCCESS;
err_close_pipe:
close(udev_control_pipe[0]);
close(udev_control_pipe[1]);
err_destroy_event:
usbi_destroy_event(&udev_control_event);
udev_control_event = (usbi_event_t)USBI_INVALID_EVENT;
err_free_monitor:
udev_monitor_unref(udev_monitor);
udev_monitor = NULL;
@ -141,20 +130,21 @@ err:
int linux_udev_stop_event_monitor(void)
{
char dummy = 1;
int r;
assert(udev_ctx != NULL);
assert(udev_monitor != NULL);
assert(udev_monitor_fd != -1);
/* Write some dummy data to the control pipe and
* wait for the thread to exit */
r = write(udev_control_pipe[1], &dummy, sizeof(dummy));
if (r <= 0) {
usbi_warn(NULL, "udev control pipe signal failed");
}
pthread_join(linux_event_thread, NULL);
/* Signal the control event and wait for the thread to exit */
usbi_signal_event(&udev_control_event);
r = pthread_join(linux_event_thread, NULL);
if (r)
usbi_warn(NULL, "failed to join hotplug event thread (%d)", r);
usbi_destroy_event(&udev_control_event);
udev_control_event = (usbi_event_t)USBI_INVALID_EVENT;
/* Release the udev monitor */
udev_monitor_unref(udev_monitor);
@ -165,44 +155,44 @@ int linux_udev_stop_event_monitor(void)
udev_unref(udev_ctx);
udev_ctx = NULL;
/* close and reset control pipe */
close(udev_control_pipe[0]);
close(udev_control_pipe[1]);
udev_control_pipe[0] = -1;
udev_control_pipe[1] = -1;
return LIBUSB_SUCCESS;
}
static void *linux_udev_event_thread_main(void *arg)
{
char dummy;
int r;
ssize_t nb;
struct udev_device* udev_dev;
struct pollfd fds[] = {
{.fd = udev_control_pipe[0],
.events = POLLIN},
{.fd = udev_monitor_fd,
.events = POLLIN},
{ .fd = USBI_EVENT_OS_HANDLE(&udev_control_event),
.events = USBI_EVENT_POLL_EVENTS },
{ .fd = udev_monitor_fd,
.events = POLLIN },
};
struct udev_device *udev_dev;
int r;
usbi_dbg("udev event thread entering.");
UNUSED(arg);
while ((r = poll(fds, 2, -1)) >= 0 || errno == EINTR) {
if (r < 0) {
/* temporary failure */
#if defined(HAVE_PTHREAD_SETNAME_NP)
r = pthread_setname_np(pthread_self(), "libusb_event");
if (r)
usbi_warn(NULL, "failed to set hotplug event thread name, error=%d", r);
#endif
usbi_dbg("udev event thread entering");
while (1) {
r = poll(fds, 2, -1);
if (r == -1) {
/* check for temporary failure */
if (errno == EINTR)
continue;
}
if (fds[0].revents & POLLIN) {
/* activity on control pipe, read the byte and exit */
nb = read(udev_control_pipe[0], &dummy, sizeof(dummy));
if (nb <= 0) {
usbi_warn(NULL, "udev control pipe read failed");
}
usbi_err(NULL, "poll() failed, errno=%d", errno);
break;
}
if (fds[1].revents & POLLIN) {
if (fds[0].revents) {
/* activity on control event, exit */
break;
}
if (fds[1].revents) {
usbi_mutex_static_lock(&linux_hotplug_lock);
udev_dev = udev_monitor_receive_device(udev_monitor);
if (udev_dev)
@ -235,10 +225,10 @@ static int udev_device_info(struct libusb_context *ctx, int detached,
dev_node, *sys_name, -1);
}
static void udev_hotplug_event(struct udev_device* udev_dev)
static void udev_hotplug_event(struct udev_device *udev_dev)
{
const char* udev_action;
const char* sys_name = NULL;
const char *udev_action;
const char *sys_name = NULL;
uint8_t busnum = 0, devaddr = 0;
int detached;
int r;
@ -262,6 +252,8 @@ static void udev_hotplug_event(struct udev_device* udev_dev)
linux_hotplug_enumerate(busnum, devaddr, sys_name);
} else if (detached) {
linux_device_disconnected(busnum, devaddr);
} else if (strncmp(udev_action, "bind", 4) == 0) {
/* silently ignore "known unhandled" action */
} else {
usbi_err(NULL, "ignoring udev action %s", udev_action);
}
@ -315,7 +307,7 @@ int linux_udev_scan_devices(struct libusb_context *ctx)
void linux_udev_hotplug_poll(void)
{
struct udev_device* udev_dev;
struct udev_device *udev_dev;
usbi_mutex_static_lock(&linux_hotplug_lock);
do {

File diff suppressed because it is too large Load diff

View file

@ -21,29 +21,20 @@
#ifndef LIBUSB_USBFS_H
#define LIBUSB_USBFS_H
#include <linux/magic.h>
#include <linux/types.h>
#define SYSFS_DEVICE_PATH "/sys/bus/usb/devices"
#define SYSFS_MOUNT_PATH "/sys"
#define SYSFS_DEVICE_PATH SYSFS_MOUNT_PATH "/bus/usb/devices"
struct usbfs_ctrltransfer {
/* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
uint32_t timeout; /* in milliseconds */
/* pointer to data */
void *data;
};
struct usbfs_bulktransfer {
/* keep in sync with usbdevice_fs.h:usbdevfs_bulktransfer */
unsigned int ep;
unsigned int len;
unsigned int timeout; /* in milliseconds */
__u8 bmRequestType;
__u8 bRequest;
__u16 wValue;
__u16 wIndex;
__u16 wLength;
__u32 timeout; /* in milliseconds */
/* pointer to data */
void *data;
@ -68,12 +59,10 @@ struct usbfs_getdriver {
#define USBFS_URB_QUEUE_BULK 0x10
#define USBFS_URB_ZERO_PACKET 0x40
enum usbfs_urb_type {
USBFS_URB_TYPE_ISO = 0,
USBFS_URB_TYPE_INTERRUPT = 1,
USBFS_URB_TYPE_CONTROL = 2,
USBFS_URB_TYPE_BULK = 3,
};
#define USBFS_URB_TYPE_ISO 0
#define USBFS_URB_TYPE_INTERRUPT 1
#define USBFS_URB_TYPE_CONTROL 2
#define USBFS_URB_TYPE_BULK 3
struct usbfs_iso_packet_desc {
unsigned int length;
@ -117,11 +106,6 @@ struct usbfs_ioctl {
void *data; /* param buffer (in, or out) */
};
struct usbfs_hub_portinfo {
unsigned char numports;
unsigned char port[127]; /* port to device num mapping */
};
#define USBFS_CAP_ZERO_PACKET 0x01
#define USBFS_CAP_BULK_CONTINUATION 0x02
#define USBFS_CAP_NO_PACKET_SIZE_LIM 0x04
@ -143,35 +127,39 @@ struct usbfs_streams {
unsigned char eps[0];
};
#define USBFS_SPEED_UNKNOWN 0
#define USBFS_SPEED_LOW 1
#define USBFS_SPEED_FULL 2
#define USBFS_SPEED_HIGH 3
#define USBFS_SPEED_WIRELESS 4
#define USBFS_SPEED_SUPER 5
#define USBFS_SPEED_SUPER_PLUS 6
#define IOCTL_USBFS_CONTROL _IOWR('U', 0, struct usbfs_ctrltransfer)
#define IOCTL_USBFS_BULK _IOWR('U', 2, struct usbfs_bulktransfer)
#define IOCTL_USBFS_RESETEP _IOR('U', 3, unsigned int)
#define IOCTL_USBFS_SETINTF _IOR('U', 4, struct usbfs_setinterface)
#define IOCTL_USBFS_SETCONFIG _IOR('U', 5, unsigned int)
#define IOCTL_USBFS_SETINTERFACE _IOR('U', 4, struct usbfs_setinterface)
#define IOCTL_USBFS_SETCONFIGURATION _IOR('U', 5, unsigned int)
#define IOCTL_USBFS_GETDRIVER _IOW('U', 8, struct usbfs_getdriver)
#define IOCTL_USBFS_SUBMITURB _IOR('U', 10, struct usbfs_urb)
#define IOCTL_USBFS_DISCARDURB _IO('U', 11)
#define IOCTL_USBFS_REAPURB _IOW('U', 12, void *)
#define IOCTL_USBFS_REAPURBNDELAY _IOW('U', 13, void *)
#define IOCTL_USBFS_CLAIMINTF _IOR('U', 15, unsigned int)
#define IOCTL_USBFS_RELEASEINTF _IOR('U', 16, unsigned int)
#define IOCTL_USBFS_CLAIMINTERFACE _IOR('U', 15, unsigned int)
#define IOCTL_USBFS_RELEASEINTERFACE _IOR('U', 16, unsigned int)
#define IOCTL_USBFS_CONNECTINFO _IOW('U', 17, struct usbfs_connectinfo)
#define IOCTL_USBFS_IOCTL _IOWR('U', 18, struct usbfs_ioctl)
#define IOCTL_USBFS_HUB_PORTINFO _IOR('U', 19, struct usbfs_hub_portinfo)
#define IOCTL_USBFS_RESET _IO('U', 20)
#define IOCTL_USBFS_CLEAR_HALT _IOR('U', 21, unsigned int)
#define IOCTL_USBFS_DISCONNECT _IO('U', 22)
#define IOCTL_USBFS_CONNECT _IO('U', 23)
#define IOCTL_USBFS_CLAIM_PORT _IOR('U', 24, unsigned int)
#define IOCTL_USBFS_RELEASE_PORT _IOR('U', 25, unsigned int)
#define IOCTL_USBFS_GET_CAPABILITIES _IOR('U', 26, __u32)
#define IOCTL_USBFS_DISCONNECT_CLAIM _IOR('U', 27, struct usbfs_disconnect_claim)
#define IOCTL_USBFS_ALLOC_STREAMS _IOR('U', 28, struct usbfs_streams)
#define IOCTL_USBFS_FREE_STREAMS _IOR('U', 29, struct usbfs_streams)
#define IOCTL_USBFS_DROP_PRIVILEGES _IOW('U', 30, __u32)
#define IOCTL_USBFS_GET_SPEED _IO('U', 31)
extern usbi_mutex_static_t linux_hotplug_lock;
#if defined(HAVE_LIBUDEV)
#ifdef HAVE_LIBUDEV
int linux_udev_start_event_monitor(void);
int linux_udev_stop_event_monitor(void);
int linux_udev_scan_devices(struct libusb_context *ctx);
@ -182,10 +170,39 @@ int linux_netlink_stop_event_monitor(void);
void linux_netlink_hotplug_poll(void);
#endif
static inline int linux_start_event_monitor(void)
{
#if defined(HAVE_LIBUDEV)
return linux_udev_start_event_monitor();
#elif !defined(__ANDROID__)
return linux_netlink_start_event_monitor();
#else
return LIBUSB_SUCCESS;
#endif
}
static inline void linux_stop_event_monitor(void)
{
#if defined(HAVE_LIBUDEV)
linux_udev_stop_event_monitor();
#elif !defined(__ANDROID__)
linux_netlink_stop_event_monitor();
#endif
}
static inline void linux_hotplug_poll(void)
{
#if defined(HAVE_LIBUDEV)
linux_udev_hotplug_poll();
#elif !defined(__ANDROID__)
linux_netlink_hotplug_poll();
#endif
}
void linux_hotplug_enumerate(uint8_t busnum, uint8_t devaddr, const char *sys_name);
void linux_device_disconnected(uint8_t busnum, uint8_t devaddr);
int linux_get_device_address (struct libusb_context *ctx, int detached,
int linux_get_device_address(struct libusb_context *ctx, int detached,
uint8_t *busnum, uint8_t *devaddr, const char *dev_node,
const char *sys_name, int fd);
int linux_enumerate_device(struct libusb_context *ctx,

View file

@ -36,8 +36,7 @@ struct device_priv {
char devnode[16];
int fd;
unsigned char *cdesc; /* active config descriptor */
usb_device_descriptor_t ddesc; /* usb device descriptor */
usb_config_descriptor_t *cdesc; /* active config descriptor */
};
struct handle_priv {
@ -52,30 +51,25 @@ static int netbsd_get_device_list(struct libusb_context *,
static int netbsd_open(struct libusb_device_handle *);
static void netbsd_close(struct libusb_device_handle *);
static int netbsd_get_device_descriptor(struct libusb_device *, unsigned char *,
int *);
static int netbsd_get_active_config_descriptor(struct libusb_device *,
unsigned char *, size_t, int *);
void *, size_t);
static int netbsd_get_config_descriptor(struct libusb_device *, uint8_t,
unsigned char *, size_t, int *);
void *, size_t);
static int netbsd_get_configuration(struct libusb_device_handle *, int *);
static int netbsd_get_configuration(struct libusb_device_handle *, uint8_t *);
static int netbsd_set_configuration(struct libusb_device_handle *, int);
static int netbsd_claim_interface(struct libusb_device_handle *, int);
static int netbsd_release_interface(struct libusb_device_handle *, int);
static int netbsd_claim_interface(struct libusb_device_handle *, uint8_t);
static int netbsd_release_interface(struct libusb_device_handle *, uint8_t);
static int netbsd_set_interface_altsetting(struct libusb_device_handle *, int,
int);
static int netbsd_set_interface_altsetting(struct libusb_device_handle *,
uint8_t, uint8_t);
static int netbsd_clear_halt(struct libusb_device_handle *, unsigned char);
static int netbsd_reset_device(struct libusb_device_handle *);
static void netbsd_destroy_device(struct libusb_device *);
static int netbsd_submit_transfer(struct usbi_transfer *);
static int netbsd_cancel_transfer(struct usbi_transfer *);
static void netbsd_clear_transfer_priv(struct usbi_transfer *);
static int netbsd_handle_transfer_completion(struct usbi_transfer *);
static int netbsd_clock_gettime(int, struct timespec *);
/*
* Private functions
@ -87,55 +81,33 @@ static int _sync_gen_transfer(struct usbi_transfer *);
static int _access_endpoint(struct libusb_transfer *);
const struct usbi_os_backend usbi_backend = {
"Synchronous NetBSD backend",
0,
NULL, /* init() */
NULL, /* exit() */
NULL, /* set_option() */
netbsd_get_device_list,
NULL, /* hotplug_poll */
netbsd_open,
netbsd_close,
.name = "Synchronous NetBSD backend",
.caps = 0,
.get_device_list = netbsd_get_device_list,
.open = netbsd_open,
.close = netbsd_close,
netbsd_get_device_descriptor,
netbsd_get_active_config_descriptor,
netbsd_get_config_descriptor,
NULL, /* get_config_descriptor_by_value() */
.get_active_config_descriptor = netbsd_get_active_config_descriptor,
.get_config_descriptor = netbsd_get_config_descriptor,
netbsd_get_configuration,
netbsd_set_configuration,
.get_configuration = netbsd_get_configuration,
.set_configuration = netbsd_set_configuration,
netbsd_claim_interface,
netbsd_release_interface,
.claim_interface = netbsd_claim_interface,
.release_interface = netbsd_release_interface,
netbsd_set_interface_altsetting,
netbsd_clear_halt,
netbsd_reset_device,
.set_interface_altsetting = netbsd_set_interface_altsetting,
.clear_halt = netbsd_clear_halt,
NULL, /* alloc_streams */
NULL, /* free_streams */
.destroy_device = netbsd_destroy_device,
NULL, /* dev_mem_alloc() */
NULL, /* dev_mem_free() */
.submit_transfer = netbsd_submit_transfer,
.cancel_transfer = netbsd_cancel_transfer,
NULL, /* kernel_driver_active() */
NULL, /* detach_kernel_driver() */
NULL, /* attach_kernel_driver() */
.handle_transfer_completion = netbsd_handle_transfer_completion,
netbsd_destroy_device,
netbsd_submit_transfer,
netbsd_cancel_transfer,
netbsd_clear_transfer_priv,
NULL, /* handle_events() */
netbsd_handle_transfer_completion,
netbsd_clock_gettime,
0, /* context_priv_size */
sizeof(struct device_priv),
sizeof(struct handle_priv),
0, /* transfer_priv_size */
.device_priv_size = sizeof(struct device_priv),
.device_handle_priv_size = sizeof(struct handle_priv),
};
int
@ -145,11 +117,12 @@ netbsd_get_device_list(struct libusb_context * ctx,
struct libusb_device *dev;
struct device_priv *dpriv;
struct usb_device_info di;
usb_device_descriptor_t ddesc;
unsigned long session_id;
char devnode[16];
int fd, err, i;
usbi_dbg("");
usbi_dbg(" ");
/* Only ugen(4) is supported */
for (i = 0; i < USB_MAX_DEVICES; i++) {
@ -177,16 +150,20 @@ netbsd_get_device_list(struct libusb_context * ctx,
dev->device_address = di.udi_addr;
dev->speed = di.udi_speed;
dpriv = (struct device_priv *)dev->os_priv;
dpriv = usbi_get_device_priv(dev);
strlcpy(dpriv->devnode, devnode, sizeof(devnode));
dpriv->fd = -1;
if (ioctl(fd, USB_GET_DEVICE_DESC, &dpriv->ddesc) < 0) {
if (ioctl(fd, USB_GET_DEVICE_DESC, &ddesc) < 0) {
err = errno;
goto error;
}
dpriv->cdesc = NULL;
static_assert(sizeof(dev->device_descriptor) == sizeof(ddesc),
"mismatch between libusb and OS device descriptor sizes");
memcpy(&dev->device_descriptor, &ddesc, LIBUSB_DT_DEVICE_SIZE);
usbi_localize_device_descriptor(&dev->device_descriptor);
if (_cache_active_config_descriptor(dev, fd)) {
err = errno;
goto error;
@ -214,8 +191,8 @@ error:
int
netbsd_open(struct libusb_device_handle *handle)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
dpriv->fd = open(dpriv->devnode, O_RDWR);
@ -236,7 +213,7 @@ netbsd_open(struct libusb_device_handle *handle)
void
netbsd_close(struct libusb_device_handle *handle)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
usbi_dbg("close: fd %d", dpriv->fd);
@ -244,49 +221,30 @@ netbsd_close(struct libusb_device_handle *handle)
dpriv->fd = -1;
}
int
netbsd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
int *host_endian)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
usbi_dbg("");
memcpy(buf, &dpriv->ddesc, DEVICE_DESC_LENGTH);
*host_endian = 0;
return (LIBUSB_SUCCESS);
}
int
netbsd_get_active_config_descriptor(struct libusb_device *dev,
unsigned char *buf, size_t len, int *host_endian)
void *buf, size_t len)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
usb_config_descriptor_t *ucd;
struct device_priv *dpriv = usbi_get_device_priv(dev);
ucd = (usb_config_descriptor_t *) dpriv->cdesc;
len = MIN(len, UGETW(ucd->wTotalLength));
len = MIN(len, (size_t)UGETW(dpriv->cdesc->wTotalLength));
usbi_dbg("len %d", len);
usbi_dbg("len %zu", len);
memcpy(buf, dpriv->cdesc, len);
*host_endian = 0;
return len;
return (int)len;
}
int
netbsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
unsigned char *buf, size_t len, int *host_endian)
void *buf, size_t len)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(dev);
struct usb_full_desc ufd;
int fd, err;
usbi_dbg("index %d, len %d", idx, len);
usbi_dbg("index %u, len %zu", idx, len);
/* A config descriptor may be requested before opening the device */
if (dpriv->fd >= 0) {
@ -311,22 +269,22 @@ netbsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
if (dpriv->fd < 0)
close(fd);
*host_endian = 0;
return len;
return (int)len;
}
int
netbsd_get_configuration(struct libusb_device_handle *handle, int *config)
netbsd_get_configuration(struct libusb_device_handle *handle, uint8_t *config)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
int tmp;
usbi_dbg("");
usbi_dbg(" ");
if (ioctl(dpriv->fd, USB_GET_CONFIG, config) < 0)
if (ioctl(dpriv->fd, USB_GET_CONFIG, &tmp) < 0)
return _errno_to_libusb(errno);
usbi_dbg("configuration %d", *config);
usbi_dbg("configuration %d", tmp);
*config = (uint8_t)tmp;
return (LIBUSB_SUCCESS);
}
@ -334,7 +292,7 @@ netbsd_get_configuration(struct libusb_device_handle *handle, int *config)
int
netbsd_set_configuration(struct libusb_device_handle *handle, int config)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
usbi_dbg("configuration %d", config);
@ -345,11 +303,13 @@ netbsd_set_configuration(struct libusb_device_handle *handle, int config)
}
int
netbsd_claim_interface(struct libusb_device_handle *handle, int iface)
netbsd_claim_interface(struct libusb_device_handle *handle, uint8_t iface)
{
struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
UNUSED(iface);
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
hpriv->endpoints[i] = -1;
@ -357,11 +317,13 @@ netbsd_claim_interface(struct libusb_device_handle *handle, int iface)
}
int
netbsd_release_interface(struct libusb_device_handle *handle, int iface)
netbsd_release_interface(struct libusb_device_handle *handle, uint8_t iface)
{
struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
UNUSED(iface);
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
if (hpriv->endpoints[i] >= 0)
close(hpriv->endpoints[i]);
@ -370,13 +332,13 @@ netbsd_release_interface(struct libusb_device_handle *handle, int iface)
}
int
netbsd_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
int altsetting)
netbsd_set_interface_altsetting(struct libusb_device_handle *handle, uint8_t iface,
uint8_t altsetting)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
struct usb_alt_interface intf;
usbi_dbg("iface %d, setting %d", iface, altsetting);
usbi_dbg("iface %u, setting %u", iface, altsetting);
memset(&intf, 0, sizeof(intf));
@ -392,10 +354,10 @@ netbsd_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
int
netbsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
struct usb_ctl_request req;
usbi_dbg("");
usbi_dbg(" ");
req.ucr_request.bmRequestType = UT_WRITE_ENDPOINT;
req.ucr_request.bRequest = UR_CLEAR_FEATURE;
@ -409,20 +371,12 @@ netbsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
return (LIBUSB_SUCCESS);
}
int
netbsd_reset_device(struct libusb_device_handle *handle)
{
usbi_dbg("");
return (LIBUSB_ERROR_NOT_SUPPORTED);
}
void
netbsd_destroy_device(struct libusb_device *dev)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(dev);
usbi_dbg("");
usbi_dbg(" ");
free(dpriv->cdesc);
}
@ -431,13 +385,11 @@ int
netbsd_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer;
struct handle_priv *hpriv;
int err = 0;
usbi_dbg("");
usbi_dbg(" ");
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
@ -476,39 +428,19 @@ netbsd_submit_transfer(struct usbi_transfer *itransfer)
int
netbsd_cancel_transfer(struct usbi_transfer *itransfer)
{
usbi_dbg("");
UNUSED(itransfer);
usbi_dbg(" ");
return (LIBUSB_ERROR_NOT_SUPPORTED);
}
void
netbsd_clear_transfer_priv(struct usbi_transfer *itransfer)
{
usbi_dbg("");
/* Nothing to do */
}
int
netbsd_handle_transfer_completion(struct usbi_transfer *itransfer)
{
return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
}
int
netbsd_clock_gettime(int clkid, struct timespec *tp)
{
usbi_dbg("clock %d", clkid);
if (clkid == USBI_CLOCK_REALTIME)
return clock_gettime(CLOCK_REALTIME, tp);
if (clkid == USBI_CLOCK_MONOTONIC)
return clock_gettime(CLOCK_MONOTONIC, tp);
return (LIBUSB_ERROR_INVALID_PARAM);
}
int
_errno_to_libusb(int err)
{
@ -521,6 +453,9 @@ _errno_to_libusb(int err)
return (LIBUSB_ERROR_NO_DEVICE);
case ENOMEM:
return (LIBUSB_ERROR_NO_MEM);
case EWOULDBLOCK:
case ETIMEDOUT:
return (LIBUSB_ERROR_TIMEOUT);
}
usbi_dbg("error: %s", strerror(err));
@ -531,10 +466,10 @@ _errno_to_libusb(int err)
int
_cache_active_config_descriptor(struct libusb_device *dev, int fd)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(dev);
struct usb_config_desc ucd;
struct usb_full_desc ufd;
unsigned char* buf;
void *buf;
int len;
usbi_dbg("fd %d", fd);
@ -547,7 +482,7 @@ _cache_active_config_descriptor(struct libusb_device *dev, int fd)
usbi_dbg("active bLength %d", ucd.ucd_desc.bLength);
len = UGETW(ucd.ucd_desc.wTotalLength);
buf = malloc(len);
buf = malloc((size_t)len);
if (buf == NULL)
return (LIBUSB_ERROR_NO_MEM);
@ -578,7 +513,7 @@ _sync_control_transfer(struct usbi_transfer *itransfer)
struct usb_ctl_request req;
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
setup = (struct libusb_control_setup *)transfer->buffer;
usbi_dbg("type %d request %d value %d index %d length %d timeout %d",
@ -620,8 +555,8 @@ _access_endpoint(struct libusb_transfer *transfer)
int fd, endpt;
mode_t mode;
hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
endpt = UE_GET_ADDR(transfer->endpoint);
mode = IS_XFERIN(transfer) ? O_RDONLY : O_WRONLY;

111
externals/libusb/libusb/libusb/os/null_usb.c vendored Executable file
View file

@ -0,0 +1,111 @@
/*
* Copyright © 2019 Pino Toscano <toscano.pino@tiscali.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libusbi.h"
static int
null_get_device_list(struct libusb_context * ctx,
struct discovered_devs **discdevs)
{
return LIBUSB_SUCCESS;
}
static int
null_open(struct libusb_device_handle *handle)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static void
null_close(struct libusb_device_handle *handle)
{
}
static int
null_get_active_config_descriptor(struct libusb_device *dev,
void *buf, size_t len)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
void *buf, size_t len)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_set_configuration(struct libusb_device_handle *handle, int config)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_claim_interface(struct libusb_device_handle *handle, uint8_t iface)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_release_interface(struct libusb_device_handle *handle, uint8_t iface)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_set_interface_altsetting(struct libusb_device_handle *handle, uint8_t iface,
uint8_t altsetting)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_submit_transfer(struct usbi_transfer *itransfer)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int
null_cancel_transfer(struct usbi_transfer *itransfer)
{
return LIBUSB_ERROR_NOT_SUPPORTED;
}
const struct usbi_os_backend usbi_backend = {
.name = "Null backend",
.caps = 0,
.get_device_list = null_get_device_list,
.open = null_open,
.close = null_close,
.get_active_config_descriptor = null_get_active_config_descriptor,
.get_config_descriptor = null_get_config_descriptor,
.set_configuration = null_set_configuration,
.claim_interface = null_claim_interface,
.release_interface = null_release_interface,
.set_interface_altsetting = null_set_interface_altsetting,
.clear_halt = null_clear_halt,
.submit_transfer = null_submit_transfer,
.cancel_transfer = null_cancel_transfer,
};

View file

@ -36,8 +36,7 @@ struct device_priv {
char *devname; /* name of the ugen(4) node */
int fd; /* device file descriptor */
unsigned char *cdesc; /* active config descriptor */
usb_device_descriptor_t ddesc; /* usb device descriptor */
usb_config_descriptor_t *cdesc; /* active config descriptor */
};
struct handle_priv {
@ -52,30 +51,25 @@ static int obsd_get_device_list(struct libusb_context *,
static int obsd_open(struct libusb_device_handle *);
static void obsd_close(struct libusb_device_handle *);
static int obsd_get_device_descriptor(struct libusb_device *, unsigned char *,
int *);
static int obsd_get_active_config_descriptor(struct libusb_device *,
unsigned char *, size_t, int *);
void *, size_t);
static int obsd_get_config_descriptor(struct libusb_device *, uint8_t,
unsigned char *, size_t, int *);
void *, size_t);
static int obsd_get_configuration(struct libusb_device_handle *, int *);
static int obsd_get_configuration(struct libusb_device_handle *, uint8_t *);
static int obsd_set_configuration(struct libusb_device_handle *, int);
static int obsd_claim_interface(struct libusb_device_handle *, int);
static int obsd_release_interface(struct libusb_device_handle *, int);
static int obsd_claim_interface(struct libusb_device_handle *, uint8_t);
static int obsd_release_interface(struct libusb_device_handle *, uint8_t);
static int obsd_set_interface_altsetting(struct libusb_device_handle *, int,
int);
static int obsd_set_interface_altsetting(struct libusb_device_handle *, uint8_t,
uint8_t);
static int obsd_clear_halt(struct libusb_device_handle *, unsigned char);
static int obsd_reset_device(struct libusb_device_handle *);
static void obsd_destroy_device(struct libusb_device *);
static int obsd_submit_transfer(struct usbi_transfer *);
static int obsd_cancel_transfer(struct usbi_transfer *);
static void obsd_clear_transfer_priv(struct usbi_transfer *);
static int obsd_handle_transfer_completion(struct usbi_transfer *);
static int obsd_clock_gettime(int, struct timespec *);
/*
* Private functions
@ -95,7 +89,6 @@ const struct usbi_os_backend usbi_backend = {
.open = obsd_open,
.close = obsd_close,
.get_device_descriptor = obsd_get_device_descriptor,
.get_active_config_descriptor = obsd_get_active_config_descriptor,
.get_config_descriptor = obsd_get_config_descriptor,
@ -107,16 +100,13 @@ const struct usbi_os_backend usbi_backend = {
.set_interface_altsetting = obsd_set_interface_altsetting,
.clear_halt = obsd_clear_halt,
.reset_device = obsd_reset_device,
.destroy_device = obsd_destroy_device,
.submit_transfer = obsd_submit_transfer,
.cancel_transfer = obsd_cancel_transfer,
.clear_transfer_priv = obsd_clear_transfer_priv,
.handle_transfer_completion = obsd_handle_transfer_completion,
.clock_gettime = obsd_clock_gettime,
.device_priv_size = sizeof(struct device_priv),
.device_handle_priv_size = sizeof(struct handle_priv),
};
@ -139,7 +129,7 @@ obsd_get_device_list(struct libusb_context * ctx,
char *udevname;
int fd, addr, i, j;
usbi_dbg("");
usbi_dbg(" ");
for (i = 0; i < 8; i++) {
snprintf(busnode, sizeof(busnode), USBDEV "%d", i);
@ -183,10 +173,10 @@ obsd_get_device_list(struct libusb_context * ctx,
dev->bus_number = di.udi_bus;
dev->device_address = di.udi_addr;
dev->speed = di.udi_speed;
dev->port_number = di.udi_port;
dpriv = (struct device_priv *)dev->os_priv;
dpriv = usbi_get_device_priv(dev);
dpriv->fd = -1;
dpriv->cdesc = NULL;
dpriv->devname = udevname;
dd.udd_bus = di.udi_bus;
@ -195,7 +185,11 @@ obsd_get_device_list(struct libusb_context * ctx,
libusb_unref_device(dev);
continue;
}
dpriv->ddesc = dd.udd_desc;
static_assert(sizeof(dev->device_descriptor) == sizeof(dd.udd_desc),
"mismatch between libusb and OS device descriptor sizes");
memcpy(&dev->device_descriptor, &dd.udd_desc, LIBUSB_DT_DEVICE_SIZE);
usbi_localize_device_descriptor(&dev->device_descriptor);
if (_cache_active_config_descriptor(dev)) {
libusb_unref_device(dev);
@ -228,19 +222,21 @@ obsd_get_device_list(struct libusb_context * ctx,
int
obsd_open(struct libusb_device_handle *handle)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
char devnode[16];
if (dpriv->devname) {
int fd;
/*
* Only open ugen(4) attached devices read-write, all
* read-only operations are done through the bus node.
*/
snprintf(devnode, sizeof(devnode), DEVPATH "%s.00",
dpriv->devname);
dpriv->fd = open(devnode, O_RDWR);
if (dpriv->fd < 0)
fd = open(devnode, O_RDWR);
if (fd < 0)
return _errno_to_libusb(errno);
dpriv->fd = fd;
usbi_dbg("open %s: fd %d", devnode, dpriv->fd);
}
@ -251,7 +247,7 @@ obsd_open(struct libusb_device_handle *handle)
void
obsd_close(struct libusb_device_handle *handle)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
if (dpriv->devname) {
usbi_dbg("close: fd %d", dpriv->fd);
@ -261,42 +257,24 @@ obsd_close(struct libusb_device_handle *handle)
}
}
int
obsd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
int *host_endian)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
usbi_dbg("");
memcpy(buf, &dpriv->ddesc, DEVICE_DESC_LENGTH);
*host_endian = 0;
return (LIBUSB_SUCCESS);
}
int
obsd_get_active_config_descriptor(struct libusb_device *dev,
unsigned char *buf, size_t len, int *host_endian)
void *buf, size_t len)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
usb_config_descriptor_t *ucd = (usb_config_descriptor_t *)dpriv->cdesc;
struct device_priv *dpriv = usbi_get_device_priv(dev);
len = MIN(len, UGETW(ucd->wTotalLength));
len = MIN(len, (size_t)UGETW(dpriv->cdesc->wTotalLength));
usbi_dbg("len %zu", len);
memcpy(buf, dpriv->cdesc, len);
*host_endian = 0;
return (len);
return ((int)len);
}
int
obsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
unsigned char *buf, size_t len, int *host_endian)
void *buf, size_t len)
{
struct usb_device_fdesc udf;
int fd, err;
@ -319,20 +297,17 @@ obsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
}
close(fd);
*host_endian = 0;
return (len);
return ((int)len);
}
int
obsd_get_configuration(struct libusb_device_handle *handle, int *config)
obsd_get_configuration(struct libusb_device_handle *handle, uint8_t *config)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
usb_config_descriptor_t *ucd = (usb_config_descriptor_t *)dpriv->cdesc;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
*config = ucd->bConfigurationValue;
*config = dpriv->cdesc->bConfigurationValue;
usbi_dbg("bConfigurationValue %d", *config);
usbi_dbg("bConfigurationValue %u", *config);
return (LIBUSB_SUCCESS);
}
@ -340,7 +315,7 @@ obsd_get_configuration(struct libusb_device_handle *handle, int *config)
int
obsd_set_configuration(struct libusb_device_handle *handle, int config)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
if (dpriv->devname == NULL)
return (LIBUSB_ERROR_NOT_SUPPORTED);
@ -354,11 +329,13 @@ obsd_set_configuration(struct libusb_device_handle *handle, int config)
}
int
obsd_claim_interface(struct libusb_device_handle *handle, int iface)
obsd_claim_interface(struct libusb_device_handle *handle, uint8_t iface)
{
struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
UNUSED(iface);
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
hpriv->endpoints[i] = -1;
@ -366,11 +343,13 @@ obsd_claim_interface(struct libusb_device_handle *handle, int iface)
}
int
obsd_release_interface(struct libusb_device_handle *handle, int iface)
obsd_release_interface(struct libusb_device_handle *handle, uint8_t iface)
{
struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
UNUSED(iface);
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
if (hpriv->endpoints[i] >= 0)
close(hpriv->endpoints[i]);
@ -379,16 +358,16 @@ obsd_release_interface(struct libusb_device_handle *handle, int iface)
}
int
obsd_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
int altsetting)
obsd_set_interface_altsetting(struct libusb_device_handle *handle, uint8_t iface,
uint8_t altsetting)
{
struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
struct usb_alt_interface intf;
if (dpriv->devname == NULL)
return (LIBUSB_ERROR_NOT_SUPPORTED);
usbi_dbg("iface %d, setting %d", iface, altsetting);
usbi_dbg("iface %u, setting %u", iface, altsetting);
memset(&intf, 0, sizeof(intf));
@ -410,7 +389,7 @@ obsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
if ((fd = _bus_open(handle->dev->bus_number)) < 0)
return _errno_to_libusb(errno);
usbi_dbg("");
usbi_dbg(" ");
req.ucr_addr = handle->dev->device_address;
req.ucr_request.bmRequestType = UT_WRITE_ENDPOINT;
@ -429,20 +408,12 @@ obsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
return (LIBUSB_SUCCESS);
}
int
obsd_reset_device(struct libusb_device_handle *handle)
{
usbi_dbg("");
return (LIBUSB_ERROR_NOT_SUPPORTED);
}
void
obsd_destroy_device(struct libusb_device *dev)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(dev);
usbi_dbg("");
usbi_dbg(" ");
free(dpriv->cdesc);
free(dpriv->devname);
@ -452,13 +423,11 @@ int
obsd_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer;
struct handle_priv *hpriv;
int err = 0;
usbi_dbg("");
usbi_dbg(" ");
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
@ -497,37 +466,19 @@ obsd_submit_transfer(struct usbi_transfer *itransfer)
int
obsd_cancel_transfer(struct usbi_transfer *itransfer)
{
usbi_dbg("");
UNUSED(itransfer);
usbi_dbg(" ");
return (LIBUSB_ERROR_NOT_SUPPORTED);
}
void
obsd_clear_transfer_priv(struct usbi_transfer *itransfer)
{
usbi_dbg("");
/* Nothing to do */
}
int
obsd_handle_transfer_completion(struct usbi_transfer *itransfer)
{
return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
}
int
obsd_clock_gettime(int clkid, struct timespec *tp)
{
if (clkid == USBI_CLOCK_REALTIME)
return clock_gettime(CLOCK_REALTIME, tp);
if (clkid == USBI_CLOCK_MONOTONIC)
return clock_gettime(CLOCK_MONOTONIC, tp);
return (LIBUSB_ERROR_INVALID_PARAM);
}
int
_errno_to_libusb(int err)
{
@ -552,10 +503,10 @@ _errno_to_libusb(int err)
int
_cache_active_config_descriptor(struct libusb_device *dev)
{
struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
struct device_priv *dpriv = usbi_get_device_priv(dev);
struct usb_device_cdesc udc;
struct usb_device_fdesc udf;
unsigned char* buf;
void *buf;
int fd, len, err;
if ((fd = _bus_open(dev->bus_number)) < 0)
@ -575,7 +526,7 @@ _cache_active_config_descriptor(struct libusb_device *dev)
usbi_dbg("active bLength %d", udc.udc_desc.bLength);
len = UGETW(udc.udc_desc.wTotalLength);
buf = malloc(len);
buf = malloc((size_t)len);
if (buf == NULL)
return (LIBUSB_ERROR_NO_MEM);
@ -611,7 +562,7 @@ _sync_control_transfer(struct usbi_transfer *itransfer)
struct usb_ctl_request req;
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
setup = (struct libusb_control_setup *)transfer->buffer;
usbi_dbg("type %x request %x value %x index %d length %d timeout %d",
@ -673,8 +624,8 @@ _access_endpoint(struct libusb_transfer *transfer)
int fd, endpt;
mode_t mode;
hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
endpt = UE_GET_ADDR(transfer->endpoint);
mode = IS_XFERIN(transfer) ? O_RDONLY : O_WRONLY;
@ -705,7 +656,7 @@ _sync_gen_transfer(struct usbi_transfer *itransfer)
int fd, nr = 1;
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
if (dpriv->devname == NULL)
return (LIBUSB_ERROR_NOT_SUPPORTED);

File diff suppressed because it is too large Load diff

View file

@ -30,7 +30,6 @@
typedef struct sunos_device_priv {
uint8_t cfgvalue; /* active config value */
uint8_t *raw_cfgdescr; /* active config descriptor */
struct libusb_device_descriptor dev_descr; /* usb device descriptor */
char *ugenpath; /* name of the ugen(4) node */
char *phypath; /* physical path */
} sunos_dev_priv_t;

View file

@ -19,23 +19,39 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include "libusbi.h"
#include <time.h>
#if defined(__linux__) || defined(__OpenBSD__)
# if defined(__OpenBSD__)
# define _BSD_SOURCE
# endif
#include <errno.h>
#if defined(__ANDROID__)
# include <unistd.h>
#elif defined(__HAIKU__)
# include <os/kernel/OS.h>
#elif defined(__linux__)
# include <sys/syscall.h>
#elif defined(__APPLE__)
# include <pthread.h>
#elif defined(__CYGWIN__)
# include <windows.h>
# include <unistd.h>
#elif defined(__NetBSD__)
# include <lwp.h>
#elif defined(__OpenBSD__)
# define _BSD_SOURCE
# include <sys/syscall.h>
# include <unistd.h>
#elif defined(__sun__)
# include <sys/lwp.h>
#endif
#include "threads_posix.h"
#include "libusbi.h"
void usbi_cond_init(pthread_cond_t *cond)
{
#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
pthread_condattr_t condattr;
PTHREAD_CHECK(pthread_condattr_init(&condattr));
PTHREAD_CHECK(pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC));
PTHREAD_CHECK(pthread_cond_init(cond, &condattr));
PTHREAD_CHECK(pthread_condattr_destroy(&condattr));
#else
PTHREAD_CHECK(pthread_cond_init(cond, NULL));
#endif
}
int usbi_cond_timedwait(pthread_cond_t *cond,
pthread_mutex_t *mutex, const struct timeval *tv)
@ -43,38 +59,71 @@ int usbi_cond_timedwait(pthread_cond_t *cond,
struct timespec timeout;
int r;
r = usbi_backend.clock_gettime(USBI_CLOCK_REALTIME, &timeout);
if (r < 0)
return r;
#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
usbi_get_monotonic_time(&timeout);
#else
usbi_get_real_time(&timeout);
#endif
timeout.tv_sec += tv->tv_sec;
timeout.tv_nsec += tv->tv_usec * 1000;
while (timeout.tv_nsec >= 1000000000L) {
timeout.tv_nsec -= 1000000000L;
timeout.tv_nsec += tv->tv_usec * 1000L;
if (timeout.tv_nsec >= NSEC_PER_SEC) {
timeout.tv_nsec -= NSEC_PER_SEC;
timeout.tv_sec++;
}
return pthread_cond_timedwait(cond, mutex, &timeout);
r = pthread_cond_timedwait(cond, mutex, &timeout);
if (r == 0)
return 0;
else if (r == ETIMEDOUT)
return LIBUSB_ERROR_TIMEOUT;
else
return LIBUSB_ERROR_OTHER;
}
int usbi_get_tid(void)
unsigned int usbi_get_tid(void)
{
int ret;
static _Thread_local unsigned int tl_tid;
int tid;
if (tl_tid)
return tl_tid;
#if defined(__ANDROID__)
ret = gettid();
tid = gettid();
#elif defined(__APPLE__)
#ifdef HAVE_PTHREAD_THREADID_NP
uint64_t thread_id;
if (pthread_threadid_np(NULL, &thread_id) == 0)
tid = (int)thread_id;
else
tid = -1;
#else
tid = (int)pthread_mach_thread_np(pthread_self());
#endif
#elif defined(__HAIKU__)
tid = get_pthread_thread_id(pthread_self());
#elif defined(__linux__)
ret = syscall(SYS_gettid);
tid = (int)syscall(SYS_gettid);
#elif defined(__NetBSD__)
tid = _lwp_self();
#elif defined(__OpenBSD__)
/* The following only works with OpenBSD > 5.1 as it requires
real thread support. For 5.1 and earlier, -1 is returned. */
ret = syscall(SYS_getthrid);
#elif defined(__APPLE__)
ret = (int)pthread_mach_thread_np(pthread_self());
#elif defined(__CYGWIN__)
ret = GetCurrentThreadId();
* real thread support. For 5.1 and earlier, -1 is returned. */
tid = syscall(SYS_getthrid);
#elif defined(__sun__)
tid = _lwp_self();
#else
ret = -1;
tid = -1;
#endif
/* TODO: NetBSD thread ID support */
return ret;
if (tid == -1) {
/* If we don't have a thread ID, at least return a unique
* value that can be used to distinguish individual
* threads. */
tid = (int)(intptr_t)pthread_self();
}
return tl_tid = (unsigned int)tid;
}

View file

@ -22,67 +22,63 @@
#define LIBUSB_THREADS_POSIX_H
#include <pthread.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#define PTHREAD_CHECK(expression) ASSERT_EQ(expression, 0)
#define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
typedef pthread_mutex_t usbi_mutex_static_t;
static inline void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
{
(void)pthread_mutex_lock(mutex);
PTHREAD_CHECK(pthread_mutex_lock(mutex));
}
static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex)
{
(void)pthread_mutex_unlock(mutex);
PTHREAD_CHECK(pthread_mutex_unlock(mutex));
}
typedef pthread_mutex_t usbi_mutex_t;
static inline int usbi_mutex_init(usbi_mutex_t *mutex)
static inline void usbi_mutex_init(usbi_mutex_t *mutex)
{
return pthread_mutex_init(mutex, NULL);
PTHREAD_CHECK(pthread_mutex_init(mutex, NULL));
}
static inline void usbi_mutex_lock(usbi_mutex_t *mutex)
{
(void)pthread_mutex_lock(mutex);
PTHREAD_CHECK(pthread_mutex_lock(mutex));
}
static inline void usbi_mutex_unlock(usbi_mutex_t *mutex)
{
(void)pthread_mutex_unlock(mutex);
PTHREAD_CHECK(pthread_mutex_unlock(mutex));
}
static inline int usbi_mutex_trylock(usbi_mutex_t *mutex)
{
return pthread_mutex_trylock(mutex);
return pthread_mutex_trylock(mutex) == 0;
}
static inline void usbi_mutex_destroy(usbi_mutex_t *mutex)
{
(void)pthread_mutex_destroy(mutex);
PTHREAD_CHECK(pthread_mutex_destroy(mutex));
}
typedef pthread_cond_t usbi_cond_t;
static inline void usbi_cond_init(pthread_cond_t *cond)
void usbi_cond_init(pthread_cond_t *cond);
static inline void usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
{
(void)pthread_cond_init(cond, NULL);
}
static inline int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
{
return pthread_cond_wait(cond, mutex);
PTHREAD_CHECK(pthread_cond_wait(cond, mutex));
}
int usbi_cond_timedwait(usbi_cond_t *cond,
usbi_mutex_t *mutex, const struct timeval *tv);
static inline void usbi_cond_broadcast(usbi_cond_t *cond)
{
(void)pthread_cond_broadcast(cond);
PTHREAD_CHECK(pthread_cond_broadcast(cond));
}
static inline void usbi_cond_destroy(usbi_cond_t *cond)
{
(void)pthread_cond_destroy(cond);
PTHREAD_CHECK(pthread_cond_destroy(cond));
}
typedef pthread_key_t usbi_tls_key_t;
static inline void usbi_tls_key_create(usbi_tls_key_t *key)
{
(void)pthread_key_create(key, NULL);
PTHREAD_CHECK(pthread_key_create(key, NULL));
}
static inline void *usbi_tls_key_get(usbi_tls_key_t key)
{
@ -90,13 +86,13 @@ static inline void *usbi_tls_key_get(usbi_tls_key_t key)
}
static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr)
{
(void)pthread_setspecific(key, ptr);
PTHREAD_CHECK(pthread_setspecific(key, ptr));
}
static inline void usbi_tls_key_delete(usbi_tls_key_t key)
{
(void)pthread_key_delete(key);
PTHREAD_CHECK(pthread_key_delete(key));
}
int usbi_get_tid(void);
unsigned int usbi_get_tid(void);
#endif /* LIBUSB_THREADS_POSIX_H */

View file

@ -2,6 +2,7 @@
* libusb synchronization on Microsoft Windows
*
* Copyright © 2010 Michael Plante <michael.plante@gmail.com>
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,109 +19,22 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <errno.h>
#include "libusbi.h"
struct usbi_cond_perthread {
struct list_head list;
HANDLE event;
};
void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
{
while (InterlockedExchange(mutex, 1L) == 1L)
SleepEx(0, TRUE);
}
void usbi_cond_init(usbi_cond_t *cond)
{
list_init(&cond->waiters);
list_init(&cond->not_waiting);
}
static int usbi_cond_intwait(usbi_cond_t *cond,
usbi_mutex_t *mutex, DWORD timeout_ms)
{
struct usbi_cond_perthread *pos;
DWORD r;
// Same assumption as usbi_cond_broadcast() holds
if (list_empty(&cond->not_waiting)) {
pos = malloc(sizeof(*pos));
if (pos == NULL)
return ENOMEM; // This errno is not POSIX-allowed.
pos->event = CreateEvent(NULL, FALSE, FALSE, NULL); // auto-reset.
if (pos->event == NULL) {
free(pos);
return ENOMEM;
}
} else {
pos = list_first_entry(&cond->not_waiting, struct usbi_cond_perthread, list);
list_del(&pos->list); // remove from not_waiting list.
// Ensure the event is clear before waiting
WaitForSingleObject(pos->event, 0);
}
list_add(&pos->list, &cond->waiters);
LeaveCriticalSection(mutex);
r = WaitForSingleObject(pos->event, timeout_ms);
EnterCriticalSection(mutex);
list_del(&pos->list);
list_add(&pos->list, &cond->not_waiting);
if (r == WAIT_OBJECT_0)
return 0;
else if (r == WAIT_TIMEOUT)
return ETIMEDOUT;
else
return EINVAL;
}
// N.B.: usbi_cond_*wait() can also return ENOMEM, even though pthread_cond_*wait cannot!
int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
{
return usbi_cond_intwait(cond, mutex, INFINITE);
}
int usbi_cond_timedwait(usbi_cond_t *cond,
usbi_mutex_t *mutex, const struct timeval *tv)
{
DWORD millis;
millis = (DWORD)(tv->tv_sec * 1000) + (tv->tv_usec / 1000);
millis = (DWORD)(tv->tv_sec * 1000L) + (tv->tv_usec / 1000L);
/* round up to next millisecond */
if (tv->tv_usec % 1000)
if (tv->tv_usec % 1000L)
millis++;
return usbi_cond_intwait(cond, mutex, millis);
}
void usbi_cond_broadcast(usbi_cond_t *cond)
{
// Assumes mutex is locked; this is not in keeping with POSIX spec, but
// libusb does this anyway, so we simplify by not adding more sync
// primitives to the CV definition!
struct usbi_cond_perthread *pos;
list_for_each_entry(pos, &cond->waiters, list, struct usbi_cond_perthread)
SetEvent(pos->event);
// The wait function will remove its respective item from the list.
}
void usbi_cond_destroy(usbi_cond_t *cond)
{
// This assumes no one is using this anymore. The check MAY NOT BE safe.
struct usbi_cond_perthread *pos, *next;
if (!list_empty(&cond->waiters))
return; // (!see above!)
list_for_each_entry_safe(pos, next, &cond->not_waiting, list, struct usbi_cond_perthread) {
CloseHandle(pos->event);
list_del(&pos->list);
free(pos);
}
if (SleepConditionVariableCS(cond, mutex, millis))
return 0;
else if (GetLastError() == ERROR_TIMEOUT)
return LIBUSB_ERROR_TIMEOUT;
else
return LIBUSB_ERROR_OTHER;
}

View file

@ -21,23 +21,24 @@
#ifndef LIBUSB_THREADS_WINDOWS_H
#define LIBUSB_THREADS_WINDOWS_H
#define WINAPI_CHECK(expression) ASSERT_NE(expression, 0)
#define USBI_MUTEX_INITIALIZER 0L
#ifdef _WIN32_WCE
typedef LONG usbi_mutex_static_t;
#else
typedef volatile LONG usbi_mutex_static_t;
#endif
void usbi_mutex_static_lock(usbi_mutex_static_t *mutex);
static inline void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
{
while (InterlockedExchange(mutex, 1L) == 1L)
SleepEx(0, TRUE);
}
static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex)
{
InterlockedExchange(mutex, 0L);
}
typedef CRITICAL_SECTION usbi_mutex_t;
static inline int usbi_mutex_init(usbi_mutex_t *mutex)
static inline void usbi_mutex_init(usbi_mutex_t *mutex)
{
InitializeCriticalSection(mutex);
return 0;
}
static inline void usbi_mutex_lock(usbi_mutex_t *mutex)
{
@ -49,46 +50,47 @@ static inline void usbi_mutex_unlock(usbi_mutex_t *mutex)
}
static inline int usbi_mutex_trylock(usbi_mutex_t *mutex)
{
return !TryEnterCriticalSection(mutex);
return TryEnterCriticalSection(mutex) != 0;
}
static inline void usbi_mutex_destroy(usbi_mutex_t *mutex)
{
DeleteCriticalSection(mutex);
}
// We *were* getting timespec from pthread.h:
#if (!defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED))
#if !defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED)
#define HAVE_STRUCT_TIMESPEC 1
#define _TIMESPEC_DEFINED 1
struct timespec {
long tv_sec;
long tv_nsec;
};
#endif /* HAVE_STRUCT_TIMESPEC | _TIMESPEC_DEFINED */
#endif /* HAVE_STRUCT_TIMESPEC || _TIMESPEC_DEFINED */
// We *were* getting ETIMEDOUT from pthread.h:
#ifndef ETIMEDOUT
#define ETIMEDOUT 10060 /* This is the value in winsock.h. */
#endif
typedef struct usbi_cond {
// Every time a thread touches the CV, it winds up in one of these lists.
// It stays there until the CV is destroyed, even if the thread terminates.
struct list_head waiters;
struct list_head not_waiting;
} usbi_cond_t;
void usbi_cond_init(usbi_cond_t *cond);
int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex);
typedef CONDITION_VARIABLE usbi_cond_t;
static inline void usbi_cond_init(usbi_cond_t *cond)
{
InitializeConditionVariable(cond);
}
static inline void usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
{
WINAPI_CHECK(SleepConditionVariableCS(cond, mutex, INFINITE));
}
int usbi_cond_timedwait(usbi_cond_t *cond,
usbi_mutex_t *mutex, const struct timeval *tv);
void usbi_cond_broadcast(usbi_cond_t *cond);
void usbi_cond_destroy(usbi_cond_t *cond);
static inline void usbi_cond_broadcast(usbi_cond_t *cond)
{
WakeAllConditionVariable(cond);
}
static inline void usbi_cond_destroy(usbi_cond_t *cond)
{
UNUSED(cond);
}
typedef DWORD usbi_tls_key_t;
static inline void usbi_tls_key_create(usbi_tls_key_t *key)
{
*key = TlsAlloc();
assert(*key != TLS_OUT_OF_INDEXES);
}
static inline void *usbi_tls_key_get(usbi_tls_key_t key)
{
@ -96,16 +98,16 @@ static inline void *usbi_tls_key_get(usbi_tls_key_t key)
}
static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr)
{
(void)TlsSetValue(key, ptr);
WINAPI_CHECK(TlsSetValue(key, ptr));
}
static inline void usbi_tls_key_delete(usbi_tls_key_t key)
{
(void)TlsFree(key);
WINAPI_CHECK(TlsFree(key));
}
static inline int usbi_get_tid(void)
static inline unsigned int usbi_get_tid(void)
{
return (int)GetCurrentThreadId();
return (unsigned int)GetCurrentThreadId();
}
#endif /* LIBUSB_THREADS_WINDOWS_H */

View file

@ -0,0 +1,886 @@
/*
* windows backend for libusb 1.0
* Copyright © 2009-2012 Pete Batard <pete@akeo.ie>
* With contributions from Michael Plante, Orin Eman et al.
* Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
* HID Reports IOCTLs inspired from HIDAPI by Alan Ott, Signal 11 Software
* Hash table functions adapted from glibc, by Ulrich Drepper et al.
* Major code testing contribution by Xiaofan Chen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <process.h>
#include <stdio.h>
#include "libusbi.h"
#include "windows_common.h"
#define EPOCH_TIME UINT64_C(116444736000000000) // 1970.01.01 00:00:000 in MS Filetime
#define STATUS_SUCCESS ((ULONG_PTR)0UL)
// Public
enum windows_version windows_version = WINDOWS_UNDEFINED;
// Global variables for init/exit
static unsigned int init_count;
static bool usbdk_available;
/*
* Converts a windows error to human readable string
* uses retval as errorcode, or, if 0, use GetLastError()
*/
#if defined(ENABLE_LOGGING)
const char *windows_error_str(DWORD error_code)
{
static char err_string[256];
DWORD size;
int len;
if (error_code == 0)
error_code = GetLastError();
len = sprintf(err_string, "[%lu] ", ULONG_CAST(error_code));
// Translate codes returned by SetupAPI. The ones we are dealing with are either
// in 0x0000xxxx or 0xE000xxxx and can be distinguished from standard error codes.
// See http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011.aspx
switch (error_code & 0xE0000000) {
case 0:
error_code = HRESULT_FROM_WIN32(error_code); // Still leaves ERROR_SUCCESS unmodified
break;
case 0xE0000000:
error_code = 0x80000000 | (FACILITY_SETUPAPI << 16) | (error_code & 0x0000FFFF);
break;
default:
break;
}
size = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&err_string[len], sizeof(err_string) - len, NULL);
if (size == 0) {
DWORD format_error = GetLastError();
if (format_error)
snprintf(err_string, sizeof(err_string),
"Windows error code %lu (FormatMessage error code %lu)",
ULONG_CAST(error_code), ULONG_CAST(format_error));
else
snprintf(err_string, sizeof(err_string), "Unknown error code %lu",
ULONG_CAST(error_code));
} else {
// Remove CRLF from end of message, if present
size_t pos = len + size - 2;
if (err_string[pos] == '\r')
err_string[pos] = '\0';
}
return err_string;
}
#endif
/*
* Dynamically loads a DLL from the Windows system directory. Unlike the
* LoadLibraryA() function, this function will not search through any
* directories to try and find the library.
*/
HMODULE load_system_library(struct libusb_context *ctx, const char *name)
{
char library_path[MAX_PATH];
char *filename_start;
UINT length;
length = GetSystemDirectoryA(library_path, sizeof(library_path));
if ((length == 0) || (length >= (UINT)sizeof(library_path))) {
usbi_err(ctx, "program assertion failed - could not get system directory");
return NULL;
}
filename_start = library_path + length;
// Append '\' + name + ".dll" + NUL
length += 1 + (UINT)strlen(name) + 4 + 1;
if (length >= (UINT)sizeof(library_path)) {
usbi_err(ctx, "program assertion failed - library path buffer overflow");
return NULL;
}
sprintf(filename_start, "\\%s.dll", name);
return LoadLibraryA(library_path);
}
/* Hash table functions - modified From glibc 2.3.2:
[Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
[Knuth] The Art of Computer Programming, part 3 (6.4) */
#define HTAB_SIZE 1021UL // *MUST* be a prime number!!
typedef struct htab_entry {
unsigned long used;
char *str;
} htab_entry;
static htab_entry *htab_table;
static usbi_mutex_t htab_mutex;
static unsigned long htab_filled;
/* Before using the hash table we must allocate memory for it.
We allocate one element more as the found prime number says.
This is done for more effective indexing as explained in the
comment for the hash function. */
static bool htab_create(struct libusb_context *ctx)
{
if (htab_table != NULL) {
usbi_err(ctx, "program assertion failed - hash table already allocated");
return true;
}
// Create a mutex
usbi_mutex_init(&htab_mutex);
usbi_dbg("using %lu entries hash table", HTAB_SIZE);
htab_filled = 0;
// allocate memory and zero out.
htab_table = calloc(HTAB_SIZE + 1, sizeof(htab_entry));
if (htab_table == NULL) {
usbi_err(ctx, "could not allocate space for hash table");
return false;
}
return true;
}
/* After using the hash table it has to be destroyed. */
static void htab_destroy(void)
{
unsigned long i;
if (htab_table == NULL)
return;
for (i = 0; i < HTAB_SIZE; i++)
free(htab_table[i].str);
safe_free(htab_table);
usbi_mutex_destroy(&htab_mutex);
}
/* This is the search function. It uses double hashing with open addressing.
We use a trick to speed up the lookup. The table is created with one
more element available. This enables us to use the index zero special.
This index will never be used because we store the first hash index in
the field used where zero means not used. Every other value means used.
The used field can be used as a first fast comparison for equality of
the stored and the parameter value. This helps to prevent unnecessary
expensive calls of strcmp. */
unsigned long htab_hash(const char *str)
{
unsigned long hval, hval2;
unsigned long idx;
unsigned long r = 5381UL;
int c;
const char *sz = str;
if (str == NULL)
return 0;
// Compute main hash value (algorithm suggested by Nokia)
while ((c = *sz++) != 0)
r = ((r << 5) + r) + c;
if (r == 0)
++r;
// compute table hash: simply take the modulus
hval = r % HTAB_SIZE;
if (hval == 0)
++hval;
// Try the first index
idx = hval;
// Mutually exclusive access (R/W lock would be better)
usbi_mutex_lock(&htab_mutex);
if (htab_table[idx].used) {
if ((htab_table[idx].used == hval) && (strcmp(str, htab_table[idx].str) == 0))
goto out_unlock; // existing hash
usbi_dbg("hash collision ('%s' vs '%s')", str, htab_table[idx].str);
// Second hash function, as suggested in [Knuth]
hval2 = 1UL + hval % (HTAB_SIZE - 2);
do {
// Because size is prime this guarantees to step through all available indexes
if (idx <= hval2)
idx = HTAB_SIZE + idx - hval2;
else
idx -= hval2;
// If we visited all entries leave the loop unsuccessfully
if (idx == hval)
break;
// If entry is found use it.
if ((htab_table[idx].used == hval) && (strcmp(str, htab_table[idx].str) == 0))
goto out_unlock;
} while (htab_table[idx].used);
}
// Not found => New entry
// If the table is full return an error
if (htab_filled >= HTAB_SIZE) {
usbi_err(NULL, "hash table is full (%lu entries)", HTAB_SIZE);
idx = 0UL;
goto out_unlock;
}
htab_table[idx].str = _strdup(str);
if (htab_table[idx].str == NULL) {
usbi_err(NULL, "could not duplicate string for hash table");
idx = 0UL;
goto out_unlock;
}
htab_table[idx].used = hval;
++htab_filled;
out_unlock:
usbi_mutex_unlock(&htab_mutex);
return idx;
}
enum libusb_transfer_status usbd_status_to_libusb_transfer_status(USBD_STATUS status)
{
if (USBD_SUCCESS(status))
return LIBUSB_TRANSFER_COMPLETED;
switch (status) {
case USBD_STATUS_TIMEOUT:
return LIBUSB_TRANSFER_TIMED_OUT;
case USBD_STATUS_CANCELED:
return LIBUSB_TRANSFER_CANCELLED;
case USBD_STATUS_ENDPOINT_HALTED:
return LIBUSB_TRANSFER_STALL;
case USBD_STATUS_DEVICE_GONE:
return LIBUSB_TRANSFER_NO_DEVICE;
default:
usbi_dbg("USBD_STATUS 0x%08lx translated to LIBUSB_TRANSFER_ERROR", ULONG_CAST(status));
return LIBUSB_TRANSFER_ERROR;
}
}
/*
* Make a transfer complete synchronously
*/
void windows_force_sync_completion(struct usbi_transfer *itransfer, ULONG size)
{
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
OVERLAPPED *overlapped = &transfer_priv->overlapped;
usbi_dbg("transfer %p, length %lu", USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer), ULONG_CAST(size));
overlapped->Internal = (ULONG_PTR)STATUS_SUCCESS;
overlapped->InternalHigh = (ULONG_PTR)size;
usbi_signal_transfer_completion(itransfer);
}
/* Windows version detection */
static BOOL is_x64(void)
{
BOOL ret = FALSE;
// Detect if we're running a 32 or 64 bit system
if (sizeof(uintptr_t) < 8) {
IsWow64Process(GetCurrentProcess(), &ret);
} else {
ret = TRUE;
}
return ret;
}
static enum windows_version get_windows_version(void)
{
enum windows_version winver;
OSVERSIONINFOEXA vi, vi2;
unsigned major, minor, version;
ULONGLONG major_equal, minor_equal;
const char *w, *arch;
bool ws;
memset(&vi, 0, sizeof(vi));
vi.dwOSVersionInfoSize = sizeof(vi);
if (!GetVersionExA((OSVERSIONINFOA *)&vi)) {
memset(&vi, 0, sizeof(vi));
vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
if (!GetVersionExA((OSVERSIONINFOA *)&vi))
return WINDOWS_UNDEFINED;
}
if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT)
return WINDOWS_UNDEFINED;
if ((vi.dwMajorVersion > 6) || ((vi.dwMajorVersion == 6) && (vi.dwMinorVersion >= 2))) {
// Starting with Windows 8.1 Preview, GetVersionEx() does no longer report the actual OS version
// See: http://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
major_equal = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
for (major = vi.dwMajorVersion; major <= 9; major++) {
memset(&vi2, 0, sizeof(vi2));
vi2.dwOSVersionInfoSize = sizeof(vi2);
vi2.dwMajorVersion = major;
if (!VerifyVersionInfoA(&vi2, VER_MAJORVERSION, major_equal))
continue;
if (vi.dwMajorVersion < major) {
vi.dwMajorVersion = major;
vi.dwMinorVersion = 0;
}
minor_equal = VerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL);
for (minor = vi.dwMinorVersion; minor <= 9; minor++) {
memset(&vi2, 0, sizeof(vi2));
vi2.dwOSVersionInfoSize = sizeof(vi2);
vi2.dwMinorVersion = minor;
if (!VerifyVersionInfoA(&vi2, VER_MINORVERSION, minor_equal))
continue;
vi.dwMinorVersion = minor;
break;
}
break;
}
}
if ((vi.dwMajorVersion > 0xf) || (vi.dwMinorVersion > 0xf))
return WINDOWS_UNDEFINED;
ws = (vi.wProductType <= VER_NT_WORKSTATION);
version = vi.dwMajorVersion << 4 | vi.dwMinorVersion;
switch (version) {
case 0x50: winver = WINDOWS_2000; w = "2000"; break;
case 0x51: winver = WINDOWS_XP; w = "XP"; break;
case 0x52: winver = WINDOWS_2003; w = "2003"; break;
case 0x60: winver = WINDOWS_VISTA; w = (ws ? "Vista" : "2008"); break;
case 0x61: winver = WINDOWS_7; w = (ws ? "7" : "2008_R2"); break;
case 0x62: winver = WINDOWS_8; w = (ws ? "8" : "2012"); break;
case 0x63: winver = WINDOWS_8_1; w = (ws ? "8.1" : "2012_R2"); break;
case 0x64: // Early Windows 10 Insider Previews and Windows Server 2017 Technical Preview 1 used version 6.4
case 0xA0: winver = WINDOWS_10; w = (ws ? "10" : "2016"); break;
default:
if (version < 0x50)
return WINDOWS_UNDEFINED;
winver = WINDOWS_11_OR_LATER;
w = "11 or later";
}
arch = is_x64() ? "64-bit" : "32-bit";
if (vi.wServicePackMinor)
usbi_dbg("Windows %s SP%u.%u %s", w, vi.wServicePackMajor, vi.wServicePackMinor, arch);
else if (vi.wServicePackMajor)
usbi_dbg("Windows %s SP%u %s", w, vi.wServicePackMajor, arch);
else
usbi_dbg("Windows %s %s", w, arch);
return winver;
}
static unsigned __stdcall windows_iocp_thread(void *arg)
{
struct libusb_context *ctx = arg;
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
HANDLE iocp = priv->completion_port;
DWORD num_bytes;
ULONG_PTR completion_key;
OVERLAPPED *overlapped;
struct windows_transfer_priv *transfer_priv;
struct usbi_transfer *itransfer;
usbi_dbg("I/O completion thread started");
while (true) {
overlapped = NULL;
if (!GetQueuedCompletionStatus(iocp, &num_bytes, &completion_key, &overlapped, INFINITE) && (overlapped == NULL)) {
usbi_err(ctx, "GetQueuedCompletionStatus failed: %s", windows_error_str(0));
break;
}
if (overlapped == NULL) {
// Signal to quit
if (completion_key != (ULONG_PTR)ctx)
usbi_err(ctx, "program assertion failed - overlapped is NULL");
break;
}
transfer_priv = container_of(overlapped, struct windows_transfer_priv, overlapped);
itransfer = (struct usbi_transfer *)((unsigned char *)transfer_priv + PTR_ALIGN(sizeof(*transfer_priv)));
usbi_dbg("transfer %p completed, length %lu",
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer), ULONG_CAST(num_bytes));
usbi_signal_transfer_completion(itransfer);
}
usbi_dbg("I/O completion thread exiting");
return 0;
}
static int windows_init(struct libusb_context *ctx)
{
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
char mutex_name[11 + 8 + 1]; // strlen("libusb_init") + (32-bit hex PID) + '\0'
HANDLE mutex;
bool winusb_backend_init = false;
int r;
sprintf(mutex_name, "libusb_init%08lX", ULONG_CAST(GetCurrentProcessId() & 0xFFFFFFFFU));
mutex = CreateMutexA(NULL, FALSE, mutex_name);
if (mutex == NULL) {
usbi_err(ctx, "could not create mutex: %s", windows_error_str(0));
return LIBUSB_ERROR_NO_MEM;
}
// A successful wait gives this thread ownership of the mutex
// => any concurrent wait stalls until the mutex is released
if (WaitForSingleObject(mutex, INFINITE) != WAIT_OBJECT_0) {
usbi_err(ctx, "failure to access mutex: %s", windows_error_str(0));
CloseHandle(mutex);
return LIBUSB_ERROR_NO_MEM;
}
// NB: concurrent usage supposes that init calls are equally balanced with
// exit calls. If init is called more than exit, we will not exit properly
if (++init_count == 1) { // First init?
windows_version = get_windows_version();
if (windows_version == WINDOWS_UNDEFINED) {
usbi_err(ctx, "failed to detect Windows version");
r = LIBUSB_ERROR_NOT_SUPPORTED;
goto init_exit;
} else if (windows_version < WINDOWS_VISTA) {
usbi_err(ctx, "Windows version is too old");
r = LIBUSB_ERROR_NOT_SUPPORTED;
goto init_exit;
}
if (!htab_create(ctx)) {
r = LIBUSB_ERROR_NO_MEM;
goto init_exit;
}
r = winusb_backend.init(ctx);
if (r != LIBUSB_SUCCESS)
goto init_exit;
winusb_backend_init = true;
r = usbdk_backend.init(ctx);
if (r == LIBUSB_SUCCESS) {
usbi_dbg("UsbDk backend is available");
usbdk_available = true;
} else {
usbi_info(ctx, "UsbDk backend is not available");
// Do not report this as an error
}
}
// By default, new contexts will use the WinUSB backend
priv->backend = &winusb_backend;
r = LIBUSB_ERROR_NO_MEM;
// Use an I/O completion port to manage all transfers for this context
priv->completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
if (priv->completion_port == NULL) {
usbi_err(ctx, "failed to create I/O completion port: %s", windows_error_str(0));
goto init_exit;
}
// And a dedicated thread to wait for I/O completions
priv->completion_port_thread = (HANDLE)_beginthreadex(NULL, 0, windows_iocp_thread, ctx, 0, NULL);
if (priv->completion_port_thread == NULL) {
usbi_err(ctx, "failed to create I/O completion port thread");
CloseHandle(priv->completion_port);
goto init_exit;
}
r = LIBUSB_SUCCESS;
init_exit: // Holds semaphore here
if ((init_count == 1) && (r != LIBUSB_SUCCESS)) { // First init failed?
if (usbdk_available) {
usbdk_backend.exit(ctx);
usbdk_available = false;
}
if (winusb_backend_init)
winusb_backend.exit(ctx);
htab_destroy();
--init_count;
}
ReleaseMutex(mutex);
CloseHandle(mutex);
return r;
}
static void windows_exit(struct libusb_context *ctx)
{
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
char mutex_name[11 + 8 + 1]; // strlen("libusb_init") + (32-bit hex PID) + '\0'
HANDLE mutex;
sprintf(mutex_name, "libusb_init%08lX", ULONG_CAST(GetCurrentProcessId() & 0xFFFFFFFFU));
mutex = CreateMutexA(NULL, FALSE, mutex_name);
if (mutex == NULL)
return;
// A successful wait gives this thread ownership of the mutex
// => any concurrent wait stalls until the mutex is released
if (WaitForSingleObject(mutex, INFINITE) != WAIT_OBJECT_0) {
usbi_err(ctx, "failed to access mutex: %s", windows_error_str(0));
CloseHandle(mutex);
return;
}
// A NULL completion status will indicate to the thread that it is time to exit
if (!PostQueuedCompletionStatus(priv->completion_port, 0, (ULONG_PTR)ctx, NULL))
usbi_err(ctx, "failed to post I/O completion: %s", windows_error_str(0));
if (WaitForSingleObject(priv->completion_port_thread, INFINITE) == WAIT_FAILED)
usbi_err(ctx, "failed to wait for I/O completion port thread: %s", windows_error_str(0));
CloseHandle(priv->completion_port_thread);
CloseHandle(priv->completion_port);
// Only works if exits and inits are balanced exactly
if (--init_count == 0) { // Last exit
if (usbdk_available) {
usbdk_backend.exit(ctx);
usbdk_available = false;
}
winusb_backend.exit(ctx);
htab_destroy();
}
ReleaseMutex(mutex);
CloseHandle(mutex);
}
static int windows_set_option(struct libusb_context *ctx, enum libusb_option option, va_list ap)
{
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
UNUSED(ap);
if (option == LIBUSB_OPTION_USE_USBDK) {
if (!usbdk_available) {
usbi_err(ctx, "UsbDk backend not available");
return LIBUSB_ERROR_NOT_FOUND;
}
usbi_dbg("switching context %p to use UsbDk backend", ctx);
priv->backend = &usbdk_backend;
return LIBUSB_SUCCESS;
}
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int windows_get_device_list(struct libusb_context *ctx, struct discovered_devs **discdevs)
{
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
return priv->backend->get_device_list(ctx, discdevs);
}
static int windows_open(struct libusb_device_handle *dev_handle)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->open(dev_handle);
}
static void windows_close(struct libusb_device_handle *dev_handle)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
priv->backend->close(dev_handle);
}
static int windows_get_active_config_descriptor(struct libusb_device *dev,
void *buffer, size_t len)
{
struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
return priv->backend->get_active_config_descriptor(dev, buffer, len);
}
static int windows_get_config_descriptor(struct libusb_device *dev,
uint8_t config_index, void *buffer, size_t len)
{
struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
return priv->backend->get_config_descriptor(dev, config_index, buffer, len);
}
static int windows_get_config_descriptor_by_value(struct libusb_device *dev,
uint8_t bConfigurationValue, void **buffer)
{
struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
return priv->backend->get_config_descriptor_by_value(dev, bConfigurationValue, buffer);
}
static int windows_get_configuration(struct libusb_device_handle *dev_handle, uint8_t *config)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->get_configuration(dev_handle, config);
}
static int windows_set_configuration(struct libusb_device_handle *dev_handle, int config)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
if (config == -1)
config = 0;
return priv->backend->set_configuration(dev_handle, (uint8_t)config);
}
static int windows_claim_interface(struct libusb_device_handle *dev_handle, uint8_t interface_number)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->claim_interface(dev_handle, interface_number);
}
static int windows_release_interface(struct libusb_device_handle *dev_handle, uint8_t interface_number)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->release_interface(dev_handle, interface_number);
}
static int windows_set_interface_altsetting(struct libusb_device_handle *dev_handle,
uint8_t interface_number, uint8_t altsetting)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->set_interface_altsetting(dev_handle, interface_number, altsetting);
}
static int windows_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->clear_halt(dev_handle, endpoint);
}
static int windows_reset_device(struct libusb_device_handle *dev_handle)
{
struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->reset_device(dev_handle);
}
static void windows_destroy_device(struct libusb_device *dev)
{
struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
priv->backend->destroy_device(dev);
}
static int windows_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
int r;
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
case LIBUSB_TRANSFER_TYPE_BULK:
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
break;
case LIBUSB_TRANSFER_TYPE_BULK_STREAM:
usbi_warn(ctx, "bulk stream transfers are not yet supported on this platform");
return LIBUSB_ERROR_NOT_SUPPORTED;
default:
usbi_err(ctx, "unknown endpoint type %d", transfer->type);
return LIBUSB_ERROR_INVALID_PARAM;
}
if (transfer_priv->handle != NULL) {
usbi_err(ctx, "program assertion failed - transfer HANDLE is not NULL");
transfer_priv->handle = NULL;
}
r = priv->backend->submit_transfer(itransfer);
if (r != LIBUSB_SUCCESS) {
// Always call the backend's clear_transfer_priv() function on failure
priv->backend->clear_transfer_priv(itransfer);
transfer_priv->handle = NULL;
return r;
}
// The backend should set the HANDLE used for each submitted transfer
// by calling set_transfer_priv_handle()
if (transfer_priv->handle == NULL)
usbi_err(ctx, "program assertion failed - transfer HANDLE is NULL after transfer was submitted");
return r;
}
static int windows_cancel_transfer(struct usbi_transfer *itransfer)
{
struct windows_context_priv *priv = usbi_get_context_priv(ITRANSFER_CTX(itransfer));
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
// Try CancelIoEx() on the transfer
// If that fails, fall back to the backend's cancel_transfer()
// function if it is available
if (CancelIoEx(transfer_priv->handle, &transfer_priv->overlapped))
return LIBUSB_SUCCESS;
else if (GetLastError() == ERROR_NOT_FOUND)
return LIBUSB_ERROR_NOT_FOUND;
if (priv->backend->cancel_transfer)
return priv->backend->cancel_transfer(itransfer);
usbi_warn(ITRANSFER_CTX(itransfer), "cancellation not supported for this transfer's driver");
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int windows_handle_transfer_completion(struct usbi_transfer *itransfer)
{
struct libusb_context *ctx = ITRANSFER_CTX(itransfer);
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
const struct windows_backend *backend = priv->backend;
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
enum libusb_transfer_status status, istatus;
DWORD result, bytes_transferred;
if (GetOverlappedResult(transfer_priv->handle, &transfer_priv->overlapped, &bytes_transferred, FALSE))
result = NO_ERROR;
else
result = GetLastError();
usbi_dbg("handling transfer %p completion with errcode %lu, length %lu",
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer), ULONG_CAST(result), ULONG_CAST(bytes_transferred));
switch (result) {
case NO_ERROR:
status = backend->copy_transfer_data(itransfer, bytes_transferred);
break;
case ERROR_GEN_FAILURE:
usbi_dbg("detected endpoint stall");
status = LIBUSB_TRANSFER_STALL;
break;
case ERROR_SEM_TIMEOUT:
usbi_dbg("detected semaphore timeout");
status = LIBUSB_TRANSFER_TIMED_OUT;
break;
case ERROR_OPERATION_ABORTED:
istatus = backend->copy_transfer_data(itransfer, bytes_transferred);
if (istatus != LIBUSB_TRANSFER_COMPLETED)
usbi_dbg("failed to copy partial data in aborted operation: %d", (int)istatus);
usbi_dbg("detected operation aborted");
status = LIBUSB_TRANSFER_CANCELLED;
break;
case ERROR_FILE_NOT_FOUND:
case ERROR_DEVICE_NOT_CONNECTED:
case ERROR_NO_SUCH_DEVICE:
usbi_dbg("detected device removed");
status = LIBUSB_TRANSFER_NO_DEVICE;
break;
default:
usbi_err(ctx, "detected I/O error %lu: %s",
ULONG_CAST(result), windows_error_str(result));
status = LIBUSB_TRANSFER_ERROR;
break;
}
transfer_priv->handle = NULL;
// Backend-specific cleanup
backend->clear_transfer_priv(itransfer);
if (status == LIBUSB_TRANSFER_CANCELLED)
return usbi_handle_transfer_cancellation(itransfer);
else
return usbi_handle_transfer_completion(itransfer, status);
}
void usbi_get_monotonic_time(struct timespec *tp)
{
static LONG hires_counter_init;
static uint64_t hires_ticks_to_ps;
static uint64_t hires_frequency;
LARGE_INTEGER hires_counter;
if (InterlockedExchange(&hires_counter_init, 1L) == 0L) {
LARGE_INTEGER li_frequency;
// Microsoft says that the QueryPerformanceFrequency() and
// QueryPerformanceCounter() functions always succeed on XP and later
QueryPerformanceFrequency(&li_frequency);
// The hires frequency can go as high as 4 GHz, so we'll use a conversion
// to picoseconds to compute the tv_nsecs part
hires_frequency = li_frequency.QuadPart;
hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency;
}
QueryPerformanceCounter(&hires_counter);
tp->tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
tp->tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency) * hires_ticks_to_ps) / UINT64_C(1000));
}
// NB: MSVC6 does not support named initializers.
const struct usbi_os_backend usbi_backend = {
"Windows",
USBI_CAP_HAS_HID_ACCESS,
windows_init,
windows_exit,
windows_set_option,
windows_get_device_list,
NULL, /* hotplug_poll */
NULL, /* wrap_sys_device */
windows_open,
windows_close,
windows_get_active_config_descriptor,
windows_get_config_descriptor,
windows_get_config_descriptor_by_value,
windows_get_configuration,
windows_set_configuration,
windows_claim_interface,
windows_release_interface,
windows_set_interface_altsetting,
windows_clear_halt,
windows_reset_device,
NULL, /* alloc_streams */
NULL, /* free_streams */
NULL, /* dev_mem_alloc */
NULL, /* dev_mem_free */
NULL, /* kernel_driver_active */
NULL, /* detach_kernel_driver */
NULL, /* attach_kernel_driver */
windows_destroy_device,
windows_submit_transfer,
windows_cancel_transfer,
NULL, /* clear_transfer_priv */
NULL, /* handle_events */
windows_handle_transfer_completion,
sizeof(struct windows_context_priv),
sizeof(union windows_device_priv),
sizeof(union windows_device_handle_priv),
sizeof(struct windows_transfer_priv),
};

View file

@ -2,9 +2,10 @@
* Windows backend common header for libusb 1.0
*
* This file brings together header code common between
* the desktop Windows and Windows CE backends.
* the desktop Windows backends.
* Copyright © 2012-2013 RealVNC Ltd.
* Copyright © 2009-2012 Pete Batard <pete@akeo.ie>
* Copyright © 2014-2020 Chris Dickens <christopher.a.dickens@gmail.com>
* With contributions from Michael Plante, Orin Eman et al.
* Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
* Major code testing contribution by Xiaofan Chen
@ -24,22 +25,29 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#ifndef LIBUSB_WINDOWS_COMMON_H
#define LIBUSB_WINDOWS_COMMON_H
// Windows API default is uppercase - ugh!
#if !defined(bool)
#define bool BOOL
#endif
#if !defined(true)
#define true TRUE
#endif
#if !defined(false)
#define false FALSE
#include <stdbool.h>
/*
* Workaround for the mess that exists with the DWORD and ULONG types.
* Visual Studio unconditionally defines these types as 'unsigned long'
* and a long is always 32-bits, even on 64-bit builds. GCC on the other
* hand varies the width of a long, matching it to the build. To make
* matters worse, the platform headers for these GCC builds define a
* DWORD/ULONG to be 'unsigned long' on 32-bit builds and 'unsigned int'
* on 64-bit builds. This creates a great deal of warnings for compilers
* that support printf format checking since it will never actually be
* an unsigned long.
*/
#if defined(_MSC_VER)
#define ULONG_CAST(x) (x)
#else
#define ULONG_CAST(x) ((unsigned long)(x))
#endif
#define EPOCH_TIME UINT64_C(116444736000000000) // 1970.01.01 00:00:000 in MS Filetime
#if defined(__CYGWIN__ )
#if defined(__CYGWIN__)
#define _stricmp strcasecmp
#define _strdup strdup
// _beginthreadex is MSVCRT => unavailable for cygwin. Fallback to using CreateThread
@ -48,22 +56,10 @@
#define safe_free(p) do {if (p != NULL) {free((void *)p); p = NULL;}} while (0)
#ifndef ARRAYSIZE
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif
#define ERR_BUFFER_SIZE 256
/*
* API macros - leveraged from libusb-win32 1.x
*/
#ifndef _WIN32_WCE
#define DLL_STRINGIFY(s) #s
#define DLL_LOAD_LIBRARY(name) LoadLibraryA(DLL_STRINGIFY(name))
#else
#define DLL_STRINGIFY(s) L#s
#define DLL_LOAD_LIBRARY(name) LoadLibrary(DLL_STRINGIFY(name))
#endif
/*
* Macros for handling DLL themselves
@ -71,13 +67,14 @@
#define DLL_HANDLE_NAME(name) __dll_##name##_handle
#define DLL_DECLARE_HANDLE(name) \
static HMODULE DLL_HANDLE_NAME(name) = NULL
static HMODULE DLL_HANDLE_NAME(name)
#define DLL_GET_HANDLE(name) \
#define DLL_GET_HANDLE(ctx, name) \
do { \
DLL_HANDLE_NAME(name) = DLL_LOAD_LIBRARY(name); \
DLL_HANDLE_NAME(name) = load_system_library(ctx, \
DLL_STRINGIFY(name)); \
if (!DLL_HANDLE_NAME(name)) \
return FALSE; \
return false; \
} while (0)
#define DLL_FREE_HANDLE(name) \
@ -88,7 +85,6 @@
} \
} while (0)
/*
* Macros for handling functions within a DLL
*/
@ -96,7 +92,7 @@
#define DLL_DECLARE_FUNC_PREFIXNAME(api, ret, prefixname, name, args) \
typedef ret (api * DLL_FUNC_NAME(name))args; \
static DLL_FUNC_NAME(name) prefixname = NULL
static DLL_FUNC_NAME(name) prefixname
#define DLL_DECLARE_FUNC(api, ret, name, args) \
DLL_DECLARE_FUNC_PREFIXNAME(api, ret, name, name, args)
@ -119,10 +115,275 @@
if (prefixname) \
break; \
if (ret_on_failure) \
return FALSE; \
return false; \
} while (0)
#define DLL_LOAD_FUNC(dll, name, ret_on_failure) \
DLL_LOAD_FUNC_PREFIXNAME(dll, name, name, ret_on_failure)
#define DLL_LOAD_FUNC_PREFIXED(dll, prefix, name, ret_on_failure) \
DLL_LOAD_FUNC_PREFIXNAME(dll, prefix##name, name, ret_on_failure)
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff539136(v=vs.85).aspx
#if !defined(USBD_SUCCESS)
typedef LONG USBD_STATUS;
#define USBD_SUCCESS(Status) ((USBD_STATUS)(Status) >= 0)
#define USBD_STATUS_ENDPOINT_HALTED ((USBD_STATUS)0xC0000030L)
#define USBD_STATUS_TIMEOUT ((USBD_STATUS)0xC0006000L)
#define USBD_STATUS_DEVICE_GONE ((USBD_STATUS)0xC0007000L)
#define USBD_STATUS_CANCELED ((USBD_STATUS)0xC0010000L)
#endif
// error code added with Windows SDK 10.0.18362
#ifndef ERROR_NO_SUCH_DEVICE
#define ERROR_NO_SUCH_DEVICE 433L
#endif
/* Windows versions */
enum windows_version {
WINDOWS_UNDEFINED,
WINDOWS_2000,
WINDOWS_XP,
WINDOWS_2003, // Also XP x64
WINDOWS_VISTA,
WINDOWS_7,
WINDOWS_8,
WINDOWS_8_1,
WINDOWS_10,
WINDOWS_11_OR_LATER
};
extern enum windows_version windows_version;
#include <pshpack1.h>
typedef struct USB_DEVICE_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
USHORT bcdUSB;
UCHAR bDeviceClass;
UCHAR bDeviceSubClass;
UCHAR bDeviceProtocol;
UCHAR bMaxPacketSize0;
USHORT idVendor;
USHORT idProduct;
USHORT bcdDevice;
UCHAR iManufacturer;
UCHAR iProduct;
UCHAR iSerialNumber;
UCHAR bNumConfigurations;
} USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
typedef struct USB_CONFIGURATION_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
USHORT wTotalLength;
UCHAR bNumInterfaces;
UCHAR bConfigurationValue;
UCHAR iConfiguration;
UCHAR bmAttributes;
UCHAR MaxPower;
} USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
#include <poppack.h>
#define MAX_DEVICE_ID_LEN 200
typedef struct USB_DK_DEVICE_ID {
WCHAR DeviceID[MAX_DEVICE_ID_LEN];
WCHAR InstanceID[MAX_DEVICE_ID_LEN];
} USB_DK_DEVICE_ID, *PUSB_DK_DEVICE_ID;
typedef struct USB_DK_DEVICE_INFO {
USB_DK_DEVICE_ID ID;
ULONG64 FilterID;
ULONG64 Port;
ULONG64 Speed;
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
} USB_DK_DEVICE_INFO, *PUSB_DK_DEVICE_INFO;
typedef struct USB_DK_ISO_TRANSFER_RESULT {
ULONG64 ActualLength;
ULONG64 TransferResult;
} USB_DK_ISO_TRANSFER_RESULT, *PUSB_DK_ISO_TRANSFER_RESULT;
typedef struct USB_DK_GEN_TRANSFER_RESULT {
ULONG64 BytesTransferred;
ULONG64 UsbdStatus; // USBD_STATUS code
} USB_DK_GEN_TRANSFER_RESULT, *PUSB_DK_GEN_TRANSFER_RESULT;
typedef struct USB_DK_TRANSFER_RESULT {
USB_DK_GEN_TRANSFER_RESULT GenResult;
PVOID64 IsochronousResultsArray; // array of USB_DK_ISO_TRANSFER_RESULT
} USB_DK_TRANSFER_RESULT, *PUSB_DK_TRANSFER_RESULT;
typedef struct USB_DK_TRANSFER_REQUEST {
ULONG64 EndpointAddress;
PVOID64 Buffer;
ULONG64 BufferLength;
ULONG64 TransferType;
ULONG64 IsochronousPacketsArraySize;
PVOID64 IsochronousPacketsArray;
USB_DK_TRANSFER_RESULT Result;
} USB_DK_TRANSFER_REQUEST, *PUSB_DK_TRANSFER_REQUEST;
struct usbdk_device_priv {
USB_DK_DEVICE_ID ID;
PUSB_CONFIGURATION_DESCRIPTOR *config_descriptors;
HANDLE redirector_handle;
HANDLE system_handle;
uint8_t active_configuration;
};
struct winusb_device_priv {
bool initialized;
bool root_hub;
uint8_t active_config;
uint8_t depth; // distance to HCD
const struct windows_usb_api_backend *apib;
char *dev_id;
char *path; // device interface path
int sub_api; // for WinUSB-like APIs
struct {
char *path; // each interface needs a device interface path,
const struct windows_usb_api_backend *apib; // an API backend (multiple drivers support),
int sub_api;
int8_t nb_endpoints; // and a set of endpoint addresses (USB_MAXENDPOINTS)
uint8_t *endpoint;
int current_altsetting;
bool restricted_functionality; // indicates if the interface functionality is restricted
// by Windows (eg. HID keyboards or mice cannot do R/W)
} usb_interface[USB_MAXINTERFACES];
struct hid_device_priv *hid;
PUSB_CONFIGURATION_DESCRIPTOR *config_descriptor; // list of pointers to the cached config descriptors
};
struct usbdk_device_handle_priv {
// Not currently used
char dummy;
};
struct winusb_device_handle_priv {
int active_interface;
struct {
HANDLE dev_handle; // WinUSB needs an extra handle for the file
HANDLE api_handle; // used by the API to communicate with the device
} interface_handle[USB_MAXINTERFACES];
int autoclaim_count[USB_MAXINTERFACES]; // For auto-release
};
struct usbdk_transfer_priv {
USB_DK_TRANSFER_REQUEST request;
PULONG64 IsochronousPacketsArray;
PUSB_DK_ISO_TRANSFER_RESULT IsochronousResultsArray;
};
struct winusb_transfer_priv {
uint8_t interface_number;
uint8_t *hid_buffer; // 1 byte extended data buffer, required for HID
uint8_t *hid_dest; // transfer buffer destination, required for HID
size_t hid_expected_size;
// For isochronous transfers with LibUSBk driver:
void *iso_context;
// For isochronous transfers with Microsoft WinUSB driver:
void *isoch_buffer_handle; // The isoch_buffer_handle to free at the end of the transfer
BOOL iso_break_stream; // Whether the isoch. stream was to be continued in the last call of libusb_submit_transfer.
// As we this structure is zeroed out upon initialization, we need to use inverse logic here.
libusb_transfer_cb_fn iso_user_callback; // Original transfer callback of the user. Might be used for isochronous transfers.
};
struct windows_backend {
int (*init)(struct libusb_context *ctx);
void (*exit)(struct libusb_context *ctx);
int (*get_device_list)(struct libusb_context *ctx,
struct discovered_devs **discdevs);
int (*open)(struct libusb_device_handle *dev_handle);
void (*close)(struct libusb_device_handle *dev_handle);
int (*get_active_config_descriptor)(struct libusb_device *device,
void *buffer, size_t len);
int (*get_config_descriptor)(struct libusb_device *device,
uint8_t config_index, void *buffer, size_t len);
int (*get_config_descriptor_by_value)(struct libusb_device *device,
uint8_t bConfigurationValue, void **buffer);
int (*get_configuration)(struct libusb_device_handle *dev_handle, uint8_t *config);
int (*set_configuration)(struct libusb_device_handle *dev_handle, uint8_t config);
int (*claim_interface)(struct libusb_device_handle *dev_handle, uint8_t interface_number);
int (*release_interface)(struct libusb_device_handle *dev_handle, uint8_t interface_number);
int (*set_interface_altsetting)(struct libusb_device_handle *dev_handle,
uint8_t interface_number, uint8_t altsetting);
int (*clear_halt)(struct libusb_device_handle *dev_handle,
unsigned char endpoint);
int (*reset_device)(struct libusb_device_handle *dev_handle);
void (*destroy_device)(struct libusb_device *dev);
int (*submit_transfer)(struct usbi_transfer *itransfer);
int (*cancel_transfer)(struct usbi_transfer *itransfer);
void (*clear_transfer_priv)(struct usbi_transfer *itransfer);
enum libusb_transfer_status (*copy_transfer_data)(struct usbi_transfer *itransfer, DWORD length);
};
struct windows_context_priv {
const struct windows_backend *backend;
HANDLE completion_port;
HANDLE completion_port_thread;
};
union windows_device_priv {
struct usbdk_device_priv usbdk_priv;
struct winusb_device_priv winusb_priv;
};
union windows_device_handle_priv {
struct usbdk_device_handle_priv usbdk_priv;
struct winusb_device_handle_priv winusb_priv;
};
struct windows_transfer_priv {
OVERLAPPED overlapped;
HANDLE handle;
union {
struct usbdk_transfer_priv usbdk_priv;
struct winusb_transfer_priv winusb_priv;
};
};
static inline OVERLAPPED *get_transfer_priv_overlapped(struct usbi_transfer *itransfer)
{
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
return &transfer_priv->overlapped;
}
static inline void set_transfer_priv_handle(struct usbi_transfer *itransfer, HANDLE handle)
{
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
transfer_priv->handle = handle;
}
static inline struct usbdk_transfer_priv *get_usbdk_transfer_priv(struct usbi_transfer *itransfer)
{
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
return &transfer_priv->usbdk_priv;
}
static inline struct winusb_transfer_priv *get_winusb_transfer_priv(struct usbi_transfer *itransfer)
{
struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
return &transfer_priv->winusb_priv;
}
extern const struct windows_backend usbdk_backend;
extern const struct windows_backend winusb_backend;
HMODULE load_system_library(struct libusb_context *ctx, const char *name);
unsigned long htab_hash(const char *str);
enum libusb_transfer_status usbd_status_to_libusb_transfer_status(USBD_STATUS status);
void windows_force_sync_completion(struct usbi_transfer *itransfer, ULONG size);
#if defined(ENABLE_LOGGING)
const char *windows_error_str(DWORD error_code);
#endif
#endif

View file

@ -28,7 +28,6 @@
#include "libusbi.h"
#include "windows_common.h"
#include "windows_nt_common.h"
#include "windows_usbdk.h"
#if !defined(STATUS_SUCCESS)
@ -44,28 +43,6 @@ typedef LONG NTSTATUS;
#define STATUS_REQUEST_CANCELED ((NTSTATUS)0xC0000703L)
#endif
#if !defined(USBD_SUCCESS)
typedef LONG USBD_STATUS;
#define USBD_SUCCESS(Status) ((USBD_STATUS) (Status) >= 0)
#define USBD_PENDING(Status) ((ULONG) (Status) >> 30 == 1)
#define USBD_ERROR(Status) ((USBD_STATUS) (Status) < 0)
#define USBD_STATUS_STALL_PID ((USBD_STATUS) 0xc0000004)
#define USBD_STATUS_ENDPOINT_HALTED ((USBD_STATUS) 0xc0000030)
#define USBD_STATUS_BAD_START_FRAME ((USBD_STATUS) 0xc0000a00)
#define USBD_STATUS_TIMEOUT ((USBD_STATUS) 0xc0006000)
#define USBD_STATUS_CANCELED ((USBD_STATUS) 0xc0010000)
#endif
static inline struct usbdk_device_priv *_usbdk_device_priv(struct libusb_device *dev)
{
return (struct usbdk_device_priv *)dev->os_priv;
}
static inline struct usbdk_transfer_priv *_usbdk_transfer_priv(struct usbi_transfer *itransfer)
{
return (struct usbdk_transfer_priv *)usbi_transfer_get_os_priv(itransfer);
}
static struct {
HMODULE module;
@ -104,7 +81,7 @@ static void unload_usbdk_helper_dll(void)
static int load_usbdk_helper_dll(struct libusb_context *ctx)
{
usbdk_helper.module = LoadLibraryA("UsbDkHelper");
usbdk_helper.module = load_system_library(ctx, "UsbDkHelper");
if (usbdk_helper.module == NULL) {
usbi_err(ctx, "Failed to load UsbDkHelper.dll: %s", windows_error_str(0));
return LIBUSB_ERROR_NOT_FOUND;
@ -170,29 +147,65 @@ error_unload:
return LIBUSB_ERROR_NOT_FOUND;
}
typedef SC_HANDLE (WINAPI *POPENSCMANAGERA)(LPCSTR, LPCSTR, DWORD);
typedef SC_HANDLE (WINAPI *POPENSERVICEA)(SC_HANDLE, LPCSTR, DWORD);
typedef BOOL (WINAPI *PCLOSESERVICEHANDLE)(SC_HANDLE);
static int usbdk_init(struct libusb_context *ctx)
{
POPENSCMANAGERA pOpenSCManagerA;
POPENSERVICEA pOpenServiceA;
PCLOSESERVICEHANDLE pCloseServiceHandle;
SC_HANDLE managerHandle;
SC_HANDLE serviceHandle;
HMODULE h;
managerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if (managerHandle == NULL) {
usbi_warn(ctx, "failed to open service control manager: %s", windows_error_str(0));
h = load_system_library(ctx, "Advapi32");
if (h == NULL) {
usbi_warn(ctx, "failed to open Advapi32\n");
return LIBUSB_ERROR_OTHER;
}
serviceHandle = OpenServiceA(managerHandle, "UsbDk", GENERIC_READ);
CloseServiceHandle(managerHandle);
pOpenSCManagerA = (POPENSCMANAGERA)GetProcAddress(h, "OpenSCManagerA");
if (pOpenSCManagerA == NULL) {
usbi_warn(ctx, "failed to find %s in Advapi32\n", "OpenSCManagerA");
goto error_free_library;
}
pOpenServiceA = (POPENSERVICEA)GetProcAddress(h, "OpenServiceA");
if (pOpenServiceA == NULL) {
usbi_warn(ctx, "failed to find %s in Advapi32\n", "OpenServiceA");
goto error_free_library;
}
pCloseServiceHandle = (PCLOSESERVICEHANDLE)GetProcAddress(h, "CloseServiceHandle");
if (pCloseServiceHandle == NULL) {
usbi_warn(ctx, "failed to find %s in Advapi32\n", "CloseServiceHandle");
goto error_free_library;
}
managerHandle = pOpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
if (managerHandle == NULL) {
usbi_warn(ctx, "failed to open service control manager: %s", windows_error_str(0));
goto error_free_library;
}
serviceHandle = pOpenServiceA(managerHandle, "UsbDk", GENERIC_READ);
pCloseServiceHandle(managerHandle);
if (serviceHandle == NULL) {
if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
usbi_warn(ctx, "failed to open UsbDk service: %s", windows_error_str(0));
FreeLibrary(h);
return LIBUSB_ERROR_NOT_FOUND;
}
CloseServiceHandle(serviceHandle);
pCloseServiceHandle(serviceHandle);
FreeLibrary(h);
return load_usbdk_helper_dll(ctx);
error_free_library:
FreeLibrary(h);
return LIBUSB_ERROR_OTHER;
}
static void usbdk_exit(struct libusb_context *ctx)
@ -216,26 +229,26 @@ static int usbdk_get_session_id_for_device(struct libusb_context *ctx,
return LIBUSB_SUCCESS;
}
static void usbdk_release_config_descriptors(struct usbdk_device_priv *p, uint8_t count)
static void usbdk_release_config_descriptors(struct usbdk_device_priv *priv, uint8_t count)
{
uint8_t i;
for (i = 0; i < count; i++)
usbdk_helper.ReleaseConfigurationDescriptor(p->config_descriptors[i]);
usbdk_helper.ReleaseConfigurationDescriptor(priv->config_descriptors[i]);
free(p->config_descriptors);
p->config_descriptors = NULL;
free(priv->config_descriptors);
priv->config_descriptors = NULL;
}
static int usbdk_cache_config_descriptors(struct libusb_context *ctx,
struct usbdk_device_priv *p, PUSB_DK_DEVICE_INFO info)
struct usbdk_device_priv *priv, PUSB_DK_DEVICE_INFO info)
{
uint8_t i;
USB_DK_CONFIG_DESCRIPTOR_REQUEST Request;
Request.ID = info->ID;
p->config_descriptors = calloc(info->DeviceDescriptor.bNumConfigurations, sizeof(PUSB_CONFIGURATION_DESCRIPTOR));
if (p->config_descriptors == NULL) {
priv->config_descriptors = calloc(info->DeviceDescriptor.bNumConfigurations, sizeof(PUSB_CONFIGURATION_DESCRIPTOR));
if (priv->config_descriptors == NULL) {
usbi_err(ctx, "failed to allocate configuration descriptors holder");
return LIBUSB_ERROR_NO_MEM;
}
@ -244,9 +257,9 @@ static int usbdk_cache_config_descriptors(struct libusb_context *ctx,
ULONG Length;
Request.Index = i;
if (!usbdk_helper.GetConfigurationDescriptor(&Request, &p->config_descriptors[i], &Length)) {
if (!usbdk_helper.GetConfigurationDescriptor(&Request, &priv->config_descriptors[i], &Length)) {
usbi_err(ctx, "failed to retrieve configuration descriptors");
usbdk_release_config_descriptors(p, i);
usbdk_release_config_descriptors(priv, i);
return LIBUSB_ERROR_OTHER;
}
}
@ -256,15 +269,15 @@ static int usbdk_cache_config_descriptors(struct libusb_context *ctx,
static inline int usbdk_device_priv_init(struct libusb_context *ctx, struct libusb_device *dev, PUSB_DK_DEVICE_INFO info)
{
struct usbdk_device_priv *p = _usbdk_device_priv(dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
p->info = *info;
p->active_configuration = 0;
priv->ID = info->ID;
priv->active_configuration = 0;
return usbdk_cache_config_descriptors(ctx, p, info);
return usbdk_cache_config_descriptors(ctx, priv, info);
}
static void usbdk_device_init(libusb_device *dev, PUSB_DK_DEVICE_INFO info)
static void usbdk_device_init(struct libusb_device *dev, PUSB_DK_DEVICE_INFO info)
{
dev->bus_number = (uint8_t)info->FilterID;
dev->port_number = (uint8_t)info->Port;
@ -273,8 +286,10 @@ static void usbdk_device_init(libusb_device *dev, PUSB_DK_DEVICE_INFO info)
// Addresses in libusb are 1-based
dev->device_address = (uint8_t)(info->Port + 1);
dev->num_configurations = info->DeviceDescriptor.bNumConfigurations;
static_assert(sizeof(dev->device_descriptor) == sizeof(info->DeviceDescriptor),
"mismatch between libusb and OS device descriptor sizes");
memcpy(&dev->device_descriptor, &info->DeviceDescriptor, LIBUSB_DT_DEVICE_SIZE);
usbi_localize_device_descriptor(&dev->device_descriptor);
switch (info->Speed) {
case LowSpeed:
@ -345,24 +360,12 @@ func_exit:
return r;
}
static int usbdk_get_device_descriptor(struct libusb_device *dev, unsigned char *buffer)
static int usbdk_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, void *buffer, size_t len)
{
struct usbdk_device_priv *priv = _usbdk_device_priv(dev);
memcpy(buffer, &priv->info.DeviceDescriptor, DEVICE_DESC_LENGTH);
return LIBUSB_SUCCESS;
}
static int usbdk_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, unsigned char *buffer, size_t len)
{
struct usbdk_device_priv *priv = _usbdk_device_priv(dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
PUSB_CONFIGURATION_DESCRIPTOR config_header;
size_t size;
if (config_index >= dev->num_configurations)
return LIBUSB_ERROR_INVALID_PARAM;
config_header = (PUSB_CONFIGURATION_DESCRIPTOR)priv->config_descriptors[config_index];
size = min(config_header->wTotalLength, len);
@ -371,16 +374,16 @@ static int usbdk_get_config_descriptor(struct libusb_device *dev, uint8_t config
}
static int usbdk_get_config_descriptor_by_value(struct libusb_device *dev, uint8_t bConfigurationValue,
unsigned char **buffer)
void **buffer)
{
struct usbdk_device_priv *priv = _usbdk_device_priv(dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
PUSB_CONFIGURATION_DESCRIPTOR config_header;
uint8_t index;
for (index = 0; index < dev->num_configurations; index++) {
for (index = 0; index < dev->device_descriptor.bNumConfigurations; index++) {
config_header = priv->config_descriptors[index];
if (config_header->bConfigurationValue == bConfigurationValue) {
*buffer = (unsigned char *)priv->config_descriptors[index];
*buffer = priv->config_descriptors[index];
return (int)config_header->wTotalLength;
}
}
@ -388,70 +391,87 @@ static int usbdk_get_config_descriptor_by_value(struct libusb_device *dev, uint8
return LIBUSB_ERROR_NOT_FOUND;
}
static int usbdk_get_active_config_descriptor(struct libusb_device *dev, unsigned char *buffer, size_t len)
static int usbdk_get_active_config_descriptor(struct libusb_device *dev, void *buffer, size_t len)
{
return usbdk_get_config_descriptor(dev, _usbdk_device_priv(dev)->active_configuration,
buffer, len);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
return usbdk_get_config_descriptor(dev, priv->active_configuration, buffer, len);
}
static int usbdk_open(struct libusb_device_handle *dev_handle)
{
struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
struct libusb_device *dev = dev_handle->dev;
struct libusb_context *ctx = DEVICE_CTX(dev);
struct windows_context_priv *priv = usbi_get_context_priv(ctx);
struct usbdk_device_priv *device_priv = usbi_get_device_priv(dev);
priv->redirector_handle = usbdk_helper.StartRedirect(&priv->info.ID);
if (priv->redirector_handle == INVALID_HANDLE_VALUE) {
usbi_err(DEVICE_CTX(dev_handle->dev), "Redirector startup failed");
device_priv->redirector_handle = usbdk_helper.StartRedirect(&device_priv->ID);
if (device_priv->redirector_handle == INVALID_HANDLE_VALUE) {
usbi_err(ctx, "Redirector startup failed");
device_priv->redirector_handle = NULL;
return LIBUSB_ERROR_OTHER;
}
priv->system_handle = usbdk_helper.GetRedirectorSystemHandle(priv->redirector_handle);
device_priv->system_handle = usbdk_helper.GetRedirectorSystemHandle(device_priv->redirector_handle);
if (CreateIoCompletionPort(device_priv->system_handle, priv->completion_port, 0, 0) == NULL) {
usbi_err(ctx, "failed to associate handle to I/O completion port: %s", windows_error_str(0));
usbdk_helper.StopRedirect(device_priv->redirector_handle);
device_priv->system_handle = NULL;
device_priv->redirector_handle = NULL;
return LIBUSB_ERROR_OTHER;
}
return LIBUSB_SUCCESS;
}
static void usbdk_close(struct libusb_device_handle *dev_handle)
{
struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.StopRedirect(priv->redirector_handle))
usbi_err(HANDLE_CTX(dev_handle), "Redirector shutdown failed");
priv->system_handle = NULL;
priv->redirector_handle = NULL;
}
static int usbdk_get_configuration(struct libusb_device_handle *dev_handle, int *config)
static int usbdk_get_configuration(struct libusb_device_handle *dev_handle, uint8_t *config)
{
*config = _usbdk_device_priv(dev_handle->dev)->active_configuration;
struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
*config = priv->active_configuration;
return LIBUSB_SUCCESS;
}
static int usbdk_set_configuration(struct libusb_device_handle *dev_handle, int config)
static int usbdk_set_configuration(struct libusb_device_handle *dev_handle, uint8_t config)
{
UNUSED(dev_handle);
UNUSED(config);
return LIBUSB_SUCCESS;
}
static int usbdk_claim_interface(struct libusb_device_handle *dev_handle, int iface)
static int usbdk_claim_interface(struct libusb_device_handle *dev_handle, uint8_t iface)
{
UNUSED(dev_handle);
UNUSED(iface);
return LIBUSB_SUCCESS;
}
static int usbdk_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting)
static int usbdk_set_interface_altsetting(struct libusb_device_handle *dev_handle, uint8_t iface, uint8_t altsetting)
{
struct libusb_context *ctx = HANDLE_CTX(dev_handle);
struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.SetAltsetting(priv->redirector_handle, iface, altsetting)) {
usbi_err(ctx, "SetAltsetting failed: %s", windows_error_str(0));
usbi_err(HANDLE_CTX(dev_handle), "SetAltsetting failed: %s", windows_error_str(0));
return LIBUSB_ERROR_NO_DEVICE;
}
return LIBUSB_SUCCESS;
}
static int usbdk_release_interface(struct libusb_device_handle *dev_handle, int iface)
static int usbdk_release_interface(struct libusb_device_handle *dev_handle, uint8_t iface)
{
UNUSED(dev_handle);
UNUSED(iface);
@ -460,11 +480,10 @@ static int usbdk_release_interface(struct libusb_device_handle *dev_handle, int
static int usbdk_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
struct libusb_context *ctx = HANDLE_CTX(dev_handle);
struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.ResetPipe(priv->redirector_handle, endpoint)) {
usbi_err(ctx, "ResetPipe failed: %s", windows_error_str(0));
usbi_err(HANDLE_CTX(dev_handle), "ResetPipe failed: %s", windows_error_str(0));
return LIBUSB_ERROR_NO_DEVICE;
}
@ -473,11 +492,10 @@ static int usbdk_clear_halt(struct libusb_device_handle *dev_handle, unsigned ch
static int usbdk_reset_device(struct libusb_device_handle *dev_handle)
{
struct libusb_context *ctx = HANDLE_CTX(dev_handle);
struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.ResetDevice(priv->redirector_handle)) {
usbi_err(ctx, "ResetDevice failed: %s", windows_error_str(0));
usbi_err(HANDLE_CTX(dev_handle), "ResetDevice failed: %s", windows_error_str(0));
return LIBUSB_ERROR_NO_DEVICE;
}
@ -486,21 +504,17 @@ static int usbdk_reset_device(struct libusb_device_handle *dev_handle)
static void usbdk_destroy_device(struct libusb_device *dev)
{
struct usbdk_device_priv* p = _usbdk_device_priv(dev);
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
if (p->config_descriptors != NULL)
usbdk_release_config_descriptors(p, p->info.DeviceDescriptor.bNumConfigurations);
if (priv->config_descriptors != NULL)
usbdk_release_config_descriptors(priv, dev->device_descriptor.bNumConfigurations);
}
static void usbdk_clear_transfer_priv(struct usbi_transfer *itransfer)
{
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
usbi_close(transfer_priv->pollable_fd.fd);
transfer_priv->pollable_fd = INVALID_WINFD;
transfer_priv->system_handle = NULL;
if (transfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
safe_free(transfer_priv->IsochronousPacketsArray);
safe_free(transfer_priv->IsochronousResultsArray);
@ -510,16 +524,17 @@ static void usbdk_clear_transfer_priv(struct usbi_transfer *itransfer)
static int usbdk_do_control_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
OVERLAPPED *overlapped = transfer_priv->pollable_fd.overlapped;
struct usbdk_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
OVERLAPPED *overlapped = get_transfer_priv_overlapped(itransfer);
TransferResult transResult;
transfer_priv->request.Buffer = (PVOID64)transfer->buffer;
transfer_priv->request.BufferLength = transfer->length;
transfer_priv->request.TransferType = ControlTransferType;
set_transfer_priv_handle(itransfer, priv->system_handle);
if (transfer->buffer[0] & LIBUSB_ENDPOINT_IN)
transResult = usbdk_helper.ReadPipe(priv->redirector_handle, &transfer_priv->request, overlapped);
else
@ -527,12 +542,12 @@ static int usbdk_do_control_transfer(struct usbi_transfer *itransfer)
switch (transResult) {
case TransferSuccess:
windows_force_sync_completion(overlapped, (ULONG)transfer_priv->request.Result.GenResult.BytesTransferred);
windows_force_sync_completion(itransfer, (ULONG)transfer_priv->request.Result.GenResult.BytesTransferred);
break;
case TransferSuccessAsync:
break;
case TransferFailure:
usbi_err(ctx, "ControlTransfer failed: %s", windows_error_str(0));
usbi_err(TRANSFER_CTX(transfer), "ControlTransfer failed: %s", windows_error_str(0));
return LIBUSB_ERROR_IO;
}
@ -542,10 +557,9 @@ static int usbdk_do_control_transfer(struct usbi_transfer *itransfer)
static int usbdk_do_bulk_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
OVERLAPPED *overlapped = transfer_priv->pollable_fd.overlapped;
struct usbdk_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
OVERLAPPED *overlapped = get_transfer_priv_overlapped(itransfer);
TransferResult transferRes;
transfer_priv->request.Buffer = (PVOID64)transfer->buffer;
@ -559,11 +573,10 @@ static int usbdk_do_bulk_transfer(struct usbi_transfer *itransfer)
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
transfer_priv->request.TransferType = InterruptTransferType;
break;
default:
usbi_err(ctx, "Wrong transfer type (%d) in usbdk_do_bulk_transfer", transfer->type);
return LIBUSB_ERROR_INVALID_PARAM;
}
set_transfer_priv_handle(itransfer, priv->system_handle);
if (IS_XFERIN(transfer))
transferRes = usbdk_helper.ReadPipe(priv->redirector_handle, &transfer_priv->request, overlapped);
else
@ -571,12 +584,12 @@ static int usbdk_do_bulk_transfer(struct usbi_transfer *itransfer)
switch (transferRes) {
case TransferSuccess:
windows_force_sync_completion(overlapped, (ULONG)transfer_priv->request.Result.GenResult.BytesTransferred);
windows_force_sync_completion(itransfer, (ULONG)transfer_priv->request.Result.GenResult.BytesTransferred);
break;
case TransferSuccessAsync:
break;
case TransferFailure:
usbi_err(ctx, "ReadPipe/WritePipe failed: %s", windows_error_str(0));
usbi_err(TRANSFER_CTX(transfer), "ReadPipe/WritePipe failed: %s", windows_error_str(0));
return LIBUSB_ERROR_IO;
}
@ -586,10 +599,9 @@ static int usbdk_do_bulk_transfer(struct usbi_transfer *itransfer)
static int usbdk_do_iso_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
OVERLAPPED *overlapped = transfer_priv->pollable_fd.overlapped;
struct usbdk_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
OVERLAPPED *overlapped = get_transfer_priv_overlapped(itransfer);
TransferResult transferRes;
int i;
@ -601,20 +613,22 @@ static int usbdk_do_iso_transfer(struct usbi_transfer *itransfer)
transfer_priv->IsochronousPacketsArray = malloc(transfer->num_iso_packets * sizeof(ULONG64));
transfer_priv->request.IsochronousPacketsArray = (PVOID64)transfer_priv->IsochronousPacketsArray;
if (!transfer_priv->IsochronousPacketsArray) {
usbi_err(ctx, "Allocation of IsochronousPacketsArray failed");
usbi_err(TRANSFER_CTX(transfer), "Allocation of IsochronousPacketsArray failed");
return LIBUSB_ERROR_NO_MEM;
}
transfer_priv->IsochronousResultsArray = malloc(transfer->num_iso_packets * sizeof(USB_DK_ISO_TRANSFER_RESULT));
transfer_priv->request.Result.IsochronousResultsArray = (PVOID64)transfer_priv->IsochronousResultsArray;
if (!transfer_priv->IsochronousResultsArray) {
usbi_err(ctx, "Allocation of isochronousResultsArray failed");
usbi_err(TRANSFER_CTX(transfer), "Allocation of isochronousResultsArray failed");
return LIBUSB_ERROR_NO_MEM;
}
for (i = 0; i < transfer->num_iso_packets; i++)
transfer_priv->IsochronousPacketsArray[i] = transfer->iso_packet_desc[i].length;
set_transfer_priv_handle(itransfer, priv->system_handle);
if (IS_XFERIN(transfer))
transferRes = usbdk_helper.ReadPipe(priv->redirector_handle, &transfer_priv->request, overlapped);
else
@ -622,7 +636,7 @@ static int usbdk_do_iso_transfer(struct usbi_transfer *itransfer)
switch (transferRes) {
case TransferSuccess:
windows_force_sync_completion(overlapped, (ULONG)transfer_priv->request.Result.GenResult.BytesTransferred);
windows_force_sync_completion(itransfer, (ULONG)transfer_priv->request.Result.GenResult.BytesTransferred);
break;
case TransferSuccessAsync:
break;
@ -633,151 +647,38 @@ static int usbdk_do_iso_transfer(struct usbi_transfer *itransfer)
return LIBUSB_SUCCESS;
}
static int usbdk_do_submit_transfer(struct usbi_transfer *itransfer,
short events, int (*transfer_fn)(struct usbi_transfer *))
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
struct winfd wfd;
int r;
wfd = usbi_create_fd();
if (wfd.fd < 0)
return LIBUSB_ERROR_NO_MEM;
r = usbi_add_pollfd(ctx, wfd.fd, events);
if (r) {
usbi_close(wfd.fd);
return r;
}
// Use transfer_priv to store data needed for async polling
transfer_priv->pollable_fd = wfd;
transfer_priv->system_handle = priv->system_handle;
r = transfer_fn(itransfer);
if (r != LIBUSB_SUCCESS) {
usbi_remove_pollfd(ctx, wfd.fd);
usbdk_clear_transfer_priv(itransfer);
return r;
}
return LIBUSB_SUCCESS;
}
static int usbdk_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
int (*transfer_fn)(struct usbi_transfer *);
short events;
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
events = (transfer->buffer[0] & LIBUSB_ENDPOINT_IN) ? POLLIN : POLLOUT;
transfer_fn = usbdk_do_control_transfer;
break;
return usbdk_do_control_transfer(itransfer);
case LIBUSB_TRANSFER_TYPE_BULK:
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
if (IS_XFEROUT(transfer) && (transfer->flags & LIBUSB_TRANSFER_ADD_ZERO_PACKET))
return LIBUSB_ERROR_NOT_SUPPORTED; //TODO: Check whether we can support this in UsbDk
events = IS_XFERIN(transfer) ? POLLIN : POLLOUT;
transfer_fn = usbdk_do_bulk_transfer;
break;
return usbdk_do_bulk_transfer(itransfer);
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
events = IS_XFERIN(transfer) ? POLLIN : POLLOUT;
transfer_fn = usbdk_do_iso_transfer;
break;
return usbdk_do_iso_transfer(itransfer);
default:
usbi_err(TRANSFER_CTX(transfer), "unknown endpoint type %d", transfer->type);
return LIBUSB_ERROR_INVALID_PARAM;
// Should not get here since windows_submit_transfer() validates
// the transfer->type field
usbi_err(TRANSFER_CTX(transfer), "unsupported endpoint type %d", transfer->type);
return LIBUSB_ERROR_NOT_SUPPORTED;
}
return usbdk_do_submit_transfer(itransfer, events, transfer_fn);
}
static int usbdk_abort_transfers(struct usbi_transfer *itransfer)
static enum libusb_transfer_status usbdk_copy_transfer_data(struct usbi_transfer *itransfer, DWORD length)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
struct winfd *pollable_fd = &transfer_priv->pollable_fd;
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
if (pCancelIoEx != NULL) {
// Use CancelIoEx if available to cancel just a single transfer
if (!pCancelIoEx(priv->system_handle, pollable_fd->overlapped)) {
usbi_err(ctx, "CancelIoEx failed: %s", windows_error_str(0));
return LIBUSB_ERROR_NO_DEVICE;
}
} else {
if (!usbdk_helper.AbortPipe(priv->redirector_handle, transfer->endpoint)) {
usbi_err(ctx, "AbortPipe failed: %s", windows_error_str(0));
return LIBUSB_ERROR_NO_DEVICE;
}
}
return LIBUSB_SUCCESS;
}
static int usbdk_cancel_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
// Control transfers cancelled by IoCancelXXX() API
// No special treatment needed
return LIBUSB_SUCCESS;
case LIBUSB_TRANSFER_TYPE_BULK:
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
return usbdk_abort_transfers(itransfer);
default:
usbi_err(ITRANSFER_CTX(itransfer), "unknown endpoint type %d", transfer->type);
return LIBUSB_ERROR_INVALID_PARAM;
}
}
static int usbdk_copy_transfer_data(struct usbi_transfer *itransfer, uint32_t io_size)
{
itransfer->transferred += io_size;
return LIBUSB_TRANSFER_COMPLETED;
}
static int usbdk_get_transfer_fd(struct usbi_transfer *itransfer)
{
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
return transfer_priv->pollable_fd.fd;
}
static DWORD usbdk_translate_usbd_status(USBD_STATUS UsbdStatus)
{
if (USBD_SUCCESS(UsbdStatus))
return NO_ERROR;
switch (UsbdStatus) {
case USBD_STATUS_TIMEOUT:
return ERROR_SEM_TIMEOUT;
case USBD_STATUS_CANCELED:
return ERROR_OPERATION_ABORTED;
default:
return ERROR_GEN_FAILURE;
}
}
static void usbdk_get_overlapped_result(struct usbi_transfer *itransfer, DWORD *io_result, DWORD *io_size)
{
struct usbdk_transfer_priv *transfer_priv = _usbdk_transfer_priv(itransfer);
struct winfd *pollable_fd = &transfer_priv->pollable_fd;
if (HasOverlappedIoCompletedSync(pollable_fd->overlapped) // Handle async requests that completed synchronously first
|| GetOverlappedResult(transfer_priv->system_handle, pollable_fd->overlapped, io_size, FALSE)) { // Regular async overlapped
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
UNUSED(length);
if (transfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
ULONG64 i;
for (i = 0; i < transfer_priv->request.IsochronousPacketsArraySize; i++) {
struct libusb_iso_packet_descriptor *lib_desc = &transfer->iso_packet_desc[i];
@ -796,11 +697,8 @@ static void usbdk_get_overlapped_result(struct usbi_transfer *itransfer, DWORD *
}
}
*io_size = (DWORD)transfer_priv->request.Result.GenResult.BytesTransferred;
*io_result = usbdk_translate_usbd_status((USBD_STATUS)transfer_priv->request.Result.GenResult.UsbdStatus);
} else {
*io_result = GetLastError();
}
itransfer->transferred += (int)transfer_priv->request.Result.GenResult.BytesTransferred;
return usbd_status_to_libusb_transfer_status((USBD_STATUS)transfer_priv->request.Result.GenResult.UsbdStatus);
}
const struct windows_backend usbdk_backend = {
@ -809,7 +707,6 @@ const struct windows_backend usbdk_backend = {
usbdk_get_device_list,
usbdk_open,
usbdk_close,
usbdk_get_device_descriptor,
usbdk_get_active_config_descriptor,
usbdk_get_config_descriptor,
usbdk_get_config_descriptor_by_value,
@ -822,9 +719,7 @@ const struct windows_backend usbdk_backend = {
usbdk_reset_device,
usbdk_destroy_device,
usbdk_submit_transfer,
usbdk_cancel_transfer,
NULL, /* cancel_transfer */
usbdk_clear_transfer_priv,
usbdk_copy_transfer_data,
usbdk_get_transfer_fd,
usbdk_get_overlapped_result,
};

View file

@ -21,9 +21,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#ifndef LIBUSB_WINDOWS_USBDK_H
#define LIBUSB_WINDOWS_USBDK_H
#include "windows_nt_common.h"
#include "windows_common.h"
typedef struct USB_DK_CONFIG_DESCRIPTOR_REQUEST {
USB_DK_DEVICE_ID ID;
@ -101,3 +102,5 @@ typedef BOOL (__cdecl *USBDK_RESET_DEVICE)(
typedef HANDLE (__cdecl *USBDK_GET_REDIRECTOR_SYSTEM_HANDLE)(
HANDLE DeviceHandle
);
#endif

File diff suppressed because it is too large Load diff

View file

@ -20,19 +20,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#ifndef LIBUSB_WINDOWS_WINUSB_H
#define LIBUSB_WINDOWS_WINUSB_H
#include "windows_common.h"
#include "windows_nt_common.h"
#if defined(_MSC_VER)
// disable /W4 MSVC warnings that are benign
#pragma warning(disable:4100) // unreferenced formal parameter
#pragma warning(disable:4127) // conditional expression is constant
#pragma warning(disable:4201) // nameless struct/union
#pragma warning(disable:4214) // bit field types other than int
#pragma warning(disable:4996) // deprecated API calls
#pragma warning(disable:28159) // more deprecated API calls
#endif
// Missing from MSVC6 setupapi.h
@ -48,7 +43,7 @@
#define MAX_HID_REPORT_SIZE 1024
#define MAX_HID_DESCRIPTOR_SIZE 256
#define MAX_GUID_STRING_LENGTH 40
#define MAX_PATH_LENGTH 128
#define MAX_PATH_LENGTH 256
#define MAX_KEY_LENGTH 256
#define LIST_SEPARATOR ';'
@ -73,6 +68,8 @@ const GUID GUID_DEVINTERFACE_USB_HUB = {0xF18A0E88, 0xC30C, 0x11D0, {0x88, 0x15,
const GUID GUID_DEVINTERFACE_LIBUSB0_FILTER = {0xF9F3FF14, 0xAE21, 0x48A0, {0x8A, 0x25, 0x80, 0x11, 0xA7, 0xA9, 0x31, 0xD9}};
#endif
// The following define MUST be == sizeof(USB_DESCRIPTOR_REQUEST)
#define USB_DESCRIPTOR_REQUEST_SIZE 12U
/*
* Multiple USB API backend support
@ -97,22 +94,21 @@ struct windows_usb_api_backend {
const char * const designation;
const char * const * const driver_name_list; // Driver name, without .sys, e.g. "usbccgp"
const uint8_t nb_driver_names;
int (*init)(struct libusb_context *ctx);
bool (*init)(struct libusb_context *ctx);
void (*exit)(void);
int (*open)(int sub_api, struct libusb_device_handle *dev_handle);
void (*close)(int sub_api, struct libusb_device_handle *dev_handle);
int (*configure_endpoints)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
int (*claim_interface)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
int (*set_interface_altsetting)(int sub_api, struct libusb_device_handle *dev_handle, int iface, int altsetting);
int (*release_interface)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
int (*configure_endpoints)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
int (*claim_interface)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
int (*set_interface_altsetting)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface, uint8_t altsetting);
int (*release_interface)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
int (*clear_halt)(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint);
int (*reset_device)(int sub_api, struct libusb_device_handle *dev_handle);
int (*submit_bulk_transfer)(int sub_api, struct usbi_transfer *itransfer);
int (*submit_iso_transfer)(int sub_api, struct usbi_transfer *itransfer);
int (*submit_control_transfer)(int sub_api, struct usbi_transfer *itransfer);
int (*abort_control)(int sub_api, struct usbi_transfer *itransfer);
int (*abort_transfers)(int sub_api, struct usbi_transfer *itransfer);
int (*copy_transfer_data)(int sub_api, struct usbi_transfer *itransfer, uint32_t io_size);
int (*cancel_transfer)(int sub_api, struct usbi_transfer *itransfer);
enum libusb_transfer_status (*copy_transfer_data)(int sub_api, struct usbi_transfer *itransfer, DWORD length);
};
extern const struct windows_usb_api_backend usb_api_backend[USB_API_MAX];
@ -202,56 +198,48 @@ struct hid_device_priv {
uint8_t string_index[3]; // man, prod, ser
};
static inline struct winusb_device_priv *_device_priv(struct libusb_device *dev)
{
return (struct winusb_device_priv *)dev->os_priv;
}
static inline struct winusb_device_priv *winusb_device_priv_init(struct libusb_device *dev)
{
struct winusb_device_priv *p = _device_priv(dev);
struct winusb_device_priv *priv = usbi_get_device_priv(dev);
int i;
p->apib = &usb_api_backend[USB_API_UNSUPPORTED];
p->sub_api = SUB_API_NOTSET;
priv->apib = &usb_api_backend[USB_API_UNSUPPORTED];
priv->sub_api = SUB_API_NOTSET;
for (i = 0; i < USB_MAXINTERFACES; i++) {
p->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
p->usb_interface[i].sub_api = SUB_API_NOTSET;
priv->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
priv->usb_interface[i].sub_api = SUB_API_NOTSET;
}
return p;
return priv;
}
static inline void winusb_device_priv_release(struct libusb_device *dev)
{
struct winusb_device_priv *p = _device_priv(dev);
struct winusb_device_priv *priv = usbi_get_device_priv(dev);
int i;
free(p->dev_id);
free(p->path);
if ((dev->num_configurations > 0) && (p->config_descriptor != NULL)) {
for (i = 0; i < dev->num_configurations; i++)
free(p->config_descriptor[i]);
free(priv->dev_id);
free(priv->path);
if ((dev->device_descriptor.bNumConfigurations > 0) && (priv->config_descriptor != NULL)) {
for (i = 0; i < dev->device_descriptor.bNumConfigurations; i++) {
if (priv->config_descriptor[i] == NULL)
continue;
free((UCHAR *)priv->config_descriptor[i] - USB_DESCRIPTOR_REQUEST_SIZE);
}
free(p->config_descriptor);
free(p->hid);
}
free(priv->config_descriptor);
free(priv->hid);
for (i = 0; i < USB_MAXINTERFACES; i++) {
free(p->usb_interface[i].path);
free(p->usb_interface[i].endpoint);
free(priv->usb_interface[i].path);
free(priv->usb_interface[i].endpoint);
}
}
static inline struct winusb_device_handle_priv *_device_handle_priv(
struct libusb_device_handle *handle)
{
return (struct winusb_device_handle_priv *)handle->os_priv;
}
// used to match a device driver (including filter drivers) against a supported API
struct driver_lookup {
char list[MAX_KEY_LENGTH + 1]; // REG_MULTI_SZ list of services (driver) names
const DWORD reg_prop; // SPDRP registry key to use to retrieve list
const char* designation; // internal designation (for debug output)
const char *designation; // internal designation (for debug output)
};
/*
@ -295,6 +283,9 @@ DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDevRegKey, (HDEVINFO, PSP_
DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HDEVINFO, PSP_DEVICE_INTERFACE_DATA, DWORD, DWORD));
#ifndef USB_GET_NODE_INFORMATION
#define USB_GET_NODE_INFORMATION 258
#endif
#ifndef USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
#define USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION 260
#endif
@ -312,6 +303,9 @@ DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HD
#define USB_CTL_CODE(id) \
CTL_CODE(FILE_DEVICE_USB, (id), METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_USB_GET_NODE_INFORMATION \
USB_CTL_CODE(USB_GET_NODE_INFORMATION)
#define IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION \
USB_CTL_CODE(USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION)
@ -321,7 +315,7 @@ DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HD
#define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX_V2 \
USB_CTL_CODE(USB_GET_NODE_CONNECTION_INFORMATION_EX_V2)
typedef enum USB_CONNECTION_STATUS {
typedef enum _USB_CONNECTION_STATUS {
NoDeviceConnected,
DeviceConnected,
DeviceFailedEnumeration,
@ -330,10 +324,20 @@ typedef enum USB_CONNECTION_STATUS {
DeviceNotEnoughPower,
DeviceNotEnoughBandwidth,
DeviceHubNestedTooDeeply,
DeviceInLegacyHub
} USB_CONNECTION_STATUS, *PUSB_CONNECTION_STATUS;
DeviceInLegacyHub,
DeviceEnumerating,
DeviceReset
} USB_CONNECTION_STATUS;
typedef enum USB_HUB_NODE {
typedef enum _USB_DEVICE_SPEED {
UsbLowSpeed = 0,
UsbFullSpeed,
UsbHighSpeed,
UsbSuperSpeed,
UsbSuperSpeedPlus // Not in Microsoft headers
} USB_DEVICE_SPEED;
typedef enum _USB_HUB_NODE {
UsbHub,
UsbMIParent
} USB_HUB_NODE;
@ -341,6 +345,29 @@ typedef enum USB_HUB_NODE {
// Most of the structures below need to be packed
#include <pshpack1.h>
typedef struct _USB_HUB_DESCRIPTOR {
UCHAR bDescriptorLength;
UCHAR bDescriptorType;
UCHAR bNumberOfPorts;
USHORT wHubCharacteristics;
UCHAR bPowerOnToPowerGood;
UCHAR bHubControlCurrent;
UCHAR bRemoveAndPowerMask[64];
} USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
typedef struct _USB_HUB_INFORMATION {
USB_HUB_DESCRIPTOR HubDescriptor;
BOOLEAN HubIsBusPowered;
} USB_HUB_INFORMATION, *PUSB_HUB_INFORMATION;
typedef struct _USB_NODE_INFORMATION {
USB_HUB_NODE NodeType;
union {
USB_HUB_INFORMATION HubInformation;
// USB_MI_PARENT_INFORMATION MiParentInformation;
} u;
} USB_NODE_INFORMATION, *PUSB_NODE_INFORMATION;
typedef struct _USB_DESCRIPTOR_REQUEST {
ULONG ConnectionIndex;
struct {
@ -426,6 +453,12 @@ typedef struct _USB_NODE_CONNECTION_INFORMATION_EX_V2 {
/* libusbK */
#define ISO_ALWAYS_START_ASAP 0x21
typedef struct _USBD_ISO_PACKET_DESCRIPTOR {
ULONG Offset;
ULONG Length;
USBD_STATUS Status;
} USBD_ISO_PACKET_DESCRIPTOR, *PUSBD_ISO_PACKET_DESCRIPTOR;
typedef enum _USBD_PIPE_TYPE {
UsbdPipeTypeControl,
UsbdPipeTypeIsochronous,
@ -433,6 +466,14 @@ typedef enum _USBD_PIPE_TYPE {
UsbdPipeTypeInterrupt
} USBD_PIPE_TYPE;
typedef struct {
USBD_PIPE_TYPE PipeType;
UCHAR PipeId;
USHORT MaximumPacketSize;
UCHAR Interval;
ULONG MaximumBytesPerInterval;
} WINUSB_PIPE_INFORMATION_EX, *PWINUSB_PIPE_INFORMATION_EX;
#include <pshpack1.h>
typedef struct _WINUSB_SETUP_PACKET {
@ -445,7 +486,8 @@ typedef struct _WINUSB_SETUP_PACKET {
#include <poppack.h>
typedef void *WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
typedef PVOID WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
typedef PVOID WINUSB_ISOCH_BUFFER_HANDLE, *PWINUSB_ISOCH_BUFFER_HANDLE;
typedef BOOL (WINAPI *WinUsb_AbortPipe_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
@ -475,6 +517,21 @@ typedef BOOL (WINAPI *WinUsb_Initialize_t)(
HANDLE DeviceHandle,
PWINUSB_INTERFACE_HANDLE InterfaceHandle
);
typedef BOOL (WINAPI *WinUsb_QueryPipeEx_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR AlternateInterfaceHandle,
UCHAR PipeIndex,
PWINUSB_PIPE_INFORMATION_EX PipeInformationEx
);
typedef BOOL (WINAPI *WinUsb_ReadIsochPipeAsap_t)(
PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle,
ULONG Offset,
ULONG Length,
BOOL ContinueStream,
ULONG NumberOfPackets,
PUSBD_ISO_PACKET_DESCRIPTOR IsoPacketDescriptors,
LPOVERLAPPED Overlapped
);
typedef BOOL (WINAPI *WinUsb_ReadPipe_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR PipeID,
@ -483,8 +540,12 @@ typedef BOOL (WINAPI *WinUsb_ReadPipe_t)(
PULONG LengthTransferred,
LPOVERLAPPED Overlapped
);
typedef BOOL (WINAPI *WinUsb_ResetDevice_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle
typedef BOOL (WINAPI *WinUsb_RegisterIsochBuffer_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR PipeID,
PVOID Buffer,
ULONG BufferLength,
PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle
);
typedef BOOL (WINAPI *WinUsb_ResetPipe_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
@ -501,29 +562,9 @@ typedef BOOL (WINAPI *WinUsb_SetPipePolicy_t)(
ULONG ValueLength,
PVOID Value
);
typedef BOOL (WINAPI *WinUsb_WritePipe_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR PipeID,
PUCHAR Buffer,
ULONG BufferLength,
PULONG LengthTransferred,
LPOVERLAPPED Overlapped
);
typedef PVOID WINUSB_ISOCH_BUFFER_HANDLE, *PWINUSB_ISOCH_BUFFER_HANDLE;
typedef BOOL (WINAPI *WinUsb_RegisterIsochBuffer_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR PipeID,
PVOID Buffer,
ULONG BufferLength,
PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle
);
typedef BOOL (WINAPI *WinUsb_UnregisterIsochBuffer_t)(
WINUSB_ISOCH_BUFFER_HANDLE BufferHandle
);
typedef BOOL (WINAPI *WinUsb_WriteIsochPipeAsap_t)(
WINUSB_ISOCH_BUFFER_HANDLE BufferHandle,
ULONG Offset,
@ -531,37 +572,13 @@ typedef BOOL (WINAPI *WinUsb_WriteIsochPipeAsap_t)(
BOOL ContinueStream,
LPOVERLAPPED Overlapped
);
typedef LONG USBD_STATUS;
typedef struct {
ULONG Offset;
ULONG Length;
USBD_STATUS Status;
} USBD_ISO_PACKET_DESCRIPTOR, *PUSBD_ISO_PACKET_DESCRIPTOR;
typedef BOOL (WINAPI *WinUsb_ReadIsochPipeAsap_t)(
PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle,
ULONG Offset,
ULONG Length,
BOOL ContinueStream,
ULONG NumberOfPackets,
PUSBD_ISO_PACKET_DESCRIPTOR IsoPacketDescriptors,
LPOVERLAPPED Overlapped
);
typedef struct {
USBD_PIPE_TYPE PipeType;
UCHAR PipeId;
USHORT MaximumPacketSize;
UCHAR Interval;
ULONG MaximumBytesPerInterval;
} WINUSB_PIPE_INFORMATION_EX, *PWINUSB_PIPE_INFORMATION_EX;
typedef BOOL (WINAPI *WinUsb_QueryPipeEx_t)(
typedef BOOL (WINAPI *WinUsb_WritePipe_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR AlternateInterfaceHandle,
UCHAR PipeIndex,
PWINUSB_PIPE_INFORMATION_EX PipeInformationEx
UCHAR PipeID,
PUCHAR Buffer,
ULONG BufferLength,
PULONG LengthTransferred,
LPOVERLAPPED Overlapped
);
/* /!\ These must match the ones from the official libusbk.h */
@ -611,15 +628,19 @@ typedef struct _KLIB_VERSION {
} KLIB_VERSION, *PKLIB_VERSION;
typedef BOOL (WINAPI *LibK_GetProcAddress_t)(
PVOID *ProcAddress,
ULONG DriverID,
ULONG FunctionID
PVOID ProcAddress,
INT DriverID,
INT FunctionID
);
typedef VOID (WINAPI *LibK_GetVersion_t)(
PKLIB_VERSION Version
);
typedef BOOL (WINAPI *LibK_ResetDevice_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle
);
//KISO_PACKET is equivalent of libusb_iso_packet_descriptor except uses absolute "offset" field instead of sequential Lengths
typedef struct _KISO_PACKET {
UINT offset;
@ -642,7 +663,7 @@ typedef struct _KISO_CONTEXT {
KISO_PACKET IsoPackets[0];
} KISO_CONTEXT, *PKISO_CONTEXT;
typedef BOOL(WINAPI *WinUsb_IsoReadPipe_t)(
typedef BOOL(WINAPI *LibK_IsoReadPipe_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR PipeID,
PUCHAR Buffer,
@ -651,7 +672,7 @@ typedef BOOL(WINAPI *WinUsb_IsoReadPipe_t)(
PKISO_CONTEXT IsoContext
);
typedef BOOL(WINAPI *WinUsb_IsoWritePipe_t)(
typedef BOOL(WINAPI *LibK_IsoWritePipe_t)(
WINUSB_INTERFACE_HANDLE InterfaceHandle,
UCHAR PipeID,
PUCHAR Buffer,
@ -661,8 +682,7 @@ typedef BOOL(WINAPI *WinUsb_IsoWritePipe_t)(
);
struct winusb_interface {
bool initialized;
bool CancelIoEx_supported;
HMODULE hDll;
WinUsb_AbortPipe_t AbortPipe;
WinUsb_ControlTransfer_t ControlTransfer;
WinUsb_FlushPipe_t FlushPipe;
@ -670,22 +690,27 @@ struct winusb_interface {
WinUsb_GetAssociatedInterface_t GetAssociatedInterface;
WinUsb_Initialize_t Initialize;
WinUsb_ReadPipe_t ReadPipe;
WinUsb_ResetDevice_t ResetDevice;
WinUsb_ResetPipe_t ResetPipe;
WinUsb_SetCurrentAlternateSetting_t SetCurrentAlternateSetting;
WinUsb_SetPipePolicy_t SetPipePolicy;
WinUsb_WritePipe_t WritePipe;
// Isochoronous functions for LibUSBk sub api:
WinUsb_IsoReadPipe_t IsoReadPipe;
WinUsb_IsoWritePipe_t IsoWritePipe;
// Isochronous functions for Microsoft WinUSB sub api (native WinUSB):
union {
struct {
// Isochoronous functions for libusbK sub api:
LibK_IsoReadPipe_t IsoReadPipe;
LibK_IsoWritePipe_t IsoWritePipe;
// Reset device function for libusbK sub api:
LibK_ResetDevice_t ResetDevice;
};
struct {
// Isochronous functions for WinUSB sub api:
WinUsb_QueryPipeEx_t QueryPipeEx;
WinUsb_ReadIsochPipeAsap_t ReadIsochPipeAsap;
WinUsb_RegisterIsochBuffer_t RegisterIsochBuffer;
WinUsb_UnregisterIsochBuffer_t UnregisterIsochBuffer;
WinUsb_WriteIsochPipeAsap_t WriteIsochPipeAsap;
WinUsb_ReadIsochPipeAsap_t ReadIsochPipeAsap;
WinUsb_QueryPipeEx_t QueryPipeEx;
};
};
};
/* hid.dll interface */
@ -781,3 +806,5 @@ DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_SetNumInputBuffers, (HANDLE, ULONG));
DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetPhysicalDescriptor, (HANDLE, PVOID, ULONG));
DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_FlushQueue, (HANDLE));
DLL_DECLARE_FUNC(WINAPI, BOOL, HidP_GetValueCaps, (HIDP_REPORT_TYPE, PHIDP_VALUE_CAPS, PULONG, PHIDP_PREPARSED_DATA));
#endif

View file

@ -17,22 +17,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#if defined(HAVE_STRINGS_H)
#include <strings.h>
#endif
#include "libusbi.h"
#if defined(_MSC_VER)
#define strncasecmp _strnicmp
#endif
static size_t usbi_locale = 0;
#include <ctype.h>
#include <string.h>
/** \ingroup libusb_misc
* How to add a new \ref libusb_strerror() translation:
@ -53,15 +41,15 @@ static size_t usbi_locale = 0;
* "Success",
* ...
* "Other error",
* }
* },
* };\endcode </li>
* <li> Translate each of the English messages from the section you copied into your language </li>
* <li> Save the file (in UTF-8 format) and send it to \c libusb-devel\@lists.sourceforge.net </li>
* </ol>
*/
static const char* usbi_locale_supported[] = { "en", "nl", "fr", "ru", "de", "hu" };
static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUSB_ERROR_COUNT] = {
static const char * const usbi_locale_supported[] = { "en", "nl", "fr", "ru", "de", "hu" };
static const char * const usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUSB_ERROR_COUNT] = {
{ /* English (en) */
"Success",
"Input/Output Error",
@ -122,7 +110,6 @@ static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUS
"Память исчерпана",
"Операция не поддерживается данной платформой",
"Неизвестная ошибка"
}, { /* German (de) */
"Erfolgreich",
"Eingabe-/Ausgabefehler",
@ -153,9 +140,11 @@ static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUS
"Nincs elég memória",
"A művelet nem támogatott ezen a rendszeren",
"Általános hiba",
}
},
};
static const char * const (*usbi_error_strings)[LIBUSB_ERROR_COUNT] = &usbi_localized_errors[0];
/** \ingroup libusb_misc
* Set the language, and only the language, not the encoding! used for
* translatable libusb messages.
@ -190,19 +179,20 @@ int API_EXPORTED libusb_setlocale(const char *locale)
{
size_t i;
if ( (locale == NULL) || (strlen(locale) < 2)
|| ((strlen(locale) > 2) && (locale[2] != '-') && (locale[2] != '_') && (locale[2] != '.')) )
if (!locale || strlen(locale) < 2
|| (locale[2] != '\0' && locale[2] != '-' && locale[2] != '_' && locale[2] != '.'))
return LIBUSB_ERROR_INVALID_PARAM;
for (i=0; i<ARRAYSIZE(usbi_locale_supported); i++) {
if (strncasecmp(usbi_locale_supported[i], locale, 2) == 0)
for (i = 0; i < ARRAYSIZE(usbi_locale_supported); i++) {
if (usbi_locale_supported[i][0] == tolower((unsigned char)locale[0])
&& usbi_locale_supported[i][1] == tolower((unsigned char)locale[1]))
break;
}
if (i >= ARRAYSIZE(usbi_locale_supported)) {
return LIBUSB_ERROR_NOT_FOUND;
}
usbi_locale = i;
if (i == ARRAYSIZE(usbi_locale_supported))
return LIBUSB_ERROR_NOT_FOUND;
usbi_error_strings = &usbi_localized_errors[i];
return LIBUSB_SUCCESS;
}
@ -220,14 +210,14 @@ int API_EXPORTED libusb_setlocale(const char *locale)
* \param errcode the error code whose description is desired
* \returns a short description of the error code in UTF-8 encoding
*/
DEFAULT_VISIBILITY const char* LIBUSB_CALL libusb_strerror(enum libusb_error errcode)
DEFAULT_VISIBILITY const char * LIBUSB_CALL libusb_strerror(int errcode)
{
int errcode_index = -errcode;
if ((errcode_index < 0) || (errcode_index >= LIBUSB_ERROR_COUNT)) {
if (errcode_index < 0 || errcode_index >= LIBUSB_ERROR_COUNT) {
/* "Other Error", which should always be our last message, is returned */
errcode_index = LIBUSB_ERROR_COUNT - 1;
}
return usbi_localized_errors[usbi_locale][errcode_index];
return (*usbi_error_strings)[errcode_index];
}

View file

@ -20,15 +20,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "libusbi.h"
#include <string.h>
/**
* @defgroup libusb_syncio Synchronous device I/O
*
@ -62,7 +57,7 @@ static void sync_transfer_wait_for_completion(struct libusb_transfer *transfer)
}
if (NULL == transfer->dev_handle) {
/* transfer completion after libusb_close() */
transfer->status = LIBUSB_ERROR_NO_DEVICE;
transfer->status = LIBUSB_TRANSFER_NO_DEVICE;
*completed = 1;
}
}
@ -86,7 +81,7 @@ static void sync_transfer_wait_for_completion(struct libusb_transfer *transfer)
* (depending on direction bits within bmRequestType)
* \param wLength the length field for the setup packet. The data buffer should
* be at least this size.
* \param timeout timeout (in millseconds) that this function should wait
* \param timeout timeout (in milliseconds) that this function should wait
* before giving up due to no response being received. For an unlimited
* timeout, use value 0.
* \returns on success, the number of bytes actually transferred
@ -96,7 +91,7 @@ static void sync_transfer_wait_for_completion(struct libusb_transfer *transfer)
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns LIBUSB_ERROR_BUSY if called from event handling context
* \returns LIBUSB_ERROR_INVALID_PARAM if the transfer size is larger than
* the operating system and/or hardware can support
* the operating system and/or hardware can support (see \ref asynclimits)
* \returns another LIBUSB_ERROR code on other failures
*/
int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
@ -115,7 +110,7 @@ int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
if (!transfer)
return LIBUSB_ERROR_NO_MEM;
buffer = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + wLength);
buffer = malloc(LIBUSB_CONTROL_SETUP_SIZE + wLength);
if (!buffer) {
libusb_free_transfer(transfer);
return LIBUSB_ERROR_NO_MEM;
@ -248,7 +243,7 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
* underlying O/S requirements, meaning that the timeout may expire after
* the first few chunks have completed. libusb is careful not to lose any data
* that may have been transferred; do not assume that timeout conditions
* indicate a complete lack of I/O.
* indicate a complete lack of I/O. See \ref asynctimeout for more details.
*
* \param dev_handle a handle for the device to communicate with
* \param endpoint the address of a valid endpoint to communicate with
@ -260,7 +255,7 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
* transferred. Since version 1.0.21 (\ref LIBUSB_API_VERSION >= 0x01000105),
* it is legal to pass a NULL pointer if you do not wish to receive this
* information.
* \param timeout timeout (in millseconds) that this function should wait
* \param timeout timeout (in milliseconds) that this function should wait
* before giving up due to no response being received. For an unlimited
* timeout, use value 0.
*
@ -272,11 +267,13 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
* \ref libusb_packetoverflow
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns LIBUSB_ERROR_BUSY if called from event handling context
* \returns LIBUSB_ERROR_INVALID_PARAM if the transfer size is larger than
* the operating system and/or hardware can support (see \ref asynclimits)
* \returns another LIBUSB_ERROR code on other failures
*/
int API_EXPORTED libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *data, int length, int *transferred,
unsigned int timeout)
int API_EXPORTED libusb_bulk_transfer(libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *data, int length,
int *transferred, unsigned int timeout)
{
return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
transferred, timeout, LIBUSB_TRANSFER_TYPE_BULK);
@ -299,7 +296,7 @@ int API_EXPORTED libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
* underlying O/S requirements, meaning that the timeout may expire after
* the first few chunks have completed. libusb is careful not to lose any data
* that may have been transferred; do not assume that timeout conditions
* indicate a complete lack of I/O.
* indicate a complete lack of I/O. See \ref asynctimeout for more details.
*
* The default endpoint bInterval value is used as the polling interval.
*
@ -313,7 +310,7 @@ int API_EXPORTED libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
* transferred. Since version 1.0.21 (\ref LIBUSB_API_VERSION >= 0x01000105),
* it is legal to pass a NULL pointer if you do not wish to receive this
* information.
* \param timeout timeout (in millseconds) that this function should wait
* \param timeout timeout (in milliseconds) that this function should wait
* before giving up due to no response being received. For an unlimited
* timeout, use value 0.
*
@ -324,11 +321,13 @@ int API_EXPORTED libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
* \ref libusb_packetoverflow
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns LIBUSB_ERROR_BUSY if called from event handling context
* \returns LIBUSB_ERROR_INVALID_PARAM if the transfer size is larger than
* the operating system and/or hardware can support (see \ref asynclimits)
* \returns another LIBUSB_ERROR code on other error
*/
int API_EXPORTED libusb_interrupt_transfer(
struct libusb_device_handle *dev_handle, unsigned char endpoint,
unsigned char *data, int length, int *transferred, unsigned int timeout)
int API_EXPORTED libusb_interrupt_transfer(libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *data, int length,
int *transferred, unsigned int timeout)
{
return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
transferred, timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);

View file

@ -7,7 +7,7 @@
#define LIBUSB_MINOR 0
#endif
#ifndef LIBUSB_MICRO
#define LIBUSB_MICRO 23
#define LIBUSB_MICRO 24
#endif
#ifndef LIBUSB_NANO
#define LIBUSB_NANO 0

View file

@ -1 +1 @@
#define LIBUSB_NANO 11397
#define LIBUSB_NANO 11584

3
externals/libusb/libusb/msvc/.gitattributes vendored Executable file
View file

@ -0,0 +1,3 @@
*.sln eol=crlf
*.vcxproj eol=crlf
*.vcxproj.filters eol=crlf

View file

@ -5,18 +5,30 @@
#error "Please make sure the msvc/ directory is removed from your build path."
#endif
/* Visual Studio 2013 or later is required */
#if (_MSC_VER < 1800)
#error "Visual Studio 2013 or later is required."
#endif
/* Visual Studio 2013 does not support __func__ */
#if (_MSC_VER < 1900)
#define __func__ __FUNCTION__
#endif
/* Visual Studio 2015 and later defines timespec */
#if (_MSC_VER >= 1900)
#define _TIMESPEC_DEFINED 1
#endif
/* Disable: warning C4127: conditional expression is constant */
#pragma warning(disable:4127)
/* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */
#pragma warning(disable:4200)
/* Disable: warning C4201: nonstandard extension used : nameless struct/union */
#pragma warning(disable:4201)
/* Disable: warning C4324: structure was padded due to __declspec(align()) */
#pragma warning(disable:4324)
/* Disable: warning C6258: Using TerminateThread does not allow proper thread clean up */
#pragma warning(disable:6258)
/* Disable: warning C4996: 'GetVersionA': was declared deprecated */
/* Disable: warning C4996: 'GetVersionExA': was declared deprecated */
#pragma warning(disable:4996)
#if defined(_PREFAST_)
@ -26,26 +38,21 @@
#pragma warning(disable:28125)
#endif
/* Default visibility */
/* Define to the attribute for default visibility. */
#define DEFAULT_VISIBILITY /**/
/* Enable global message logging */
/* Define to 1 to start with debug message logging enabled. */
/* #undef ENABLE_DEBUG_LOGGING */
/* Define to 1 to enable message logging. */
#define ENABLE_LOGGING 1
/* Uncomment to start with debug message logging enabled */
// #define ENABLE_DEBUG_LOGGING 1
/* Define to 1 if compiling for a Windows platform. */
#define PLATFORM_WINDOWS 1
/* Uncomment to enabling logging to system log */
// #define USE_SYSTEM_LOGGING_FACILITY
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
#define PRINTF_FORMAT(a, b) /**/
/* type of second poll() argument */
#define POLL_NFDS_TYPE unsigned int
/* Windows/WinCE backend */
#if defined(_WIN32_WCE)
#define OS_WINCE 1
#define HAVE_MISSING_H
#else
#define OS_WINDOWS 1
#define HAVE_SYS_TYPES_H 1
#endif
/* Define to 1 to output logging messages to the systemwide log. */
/* #undef USE_SYSTEM_LOGGING_FACILITY */

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp</ProjectName>
<ProjectGuid>{8c7814a1-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MinimalRebuild>true</MinimalRebuild>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2013.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4fc737f1-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
<Extensions>c</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89bd-4b04-88eb-625fbe52ebfb}</UniqueIdentifier>
<Extensions>h</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libusb\libusb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp</ProjectName>
<ProjectGuid>{8c7814a1-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2015.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4fc737f1-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
<Extensions>c</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89bd-4b04-88eb-625fbe52ebfb}</UniqueIdentifier>
<Extensions>h</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libusb\libusb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

106
externals/libusb/libusb/msvc/dpfp_2017.vcxproj vendored Executable file
View file

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp</ProjectName>
<ProjectGuid>{8c7814a1-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
<WindowsTargetPlatformVersion Condition="'$(Platform)'=='ARM' Or '$(Platform)'=='ARM64'">10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2017.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4fc737f1-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
<Extensions>c</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89bd-4b04-88eb-625fbe52ebfb}</UniqueIdentifier>
<Extensions>h</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libusb\libusb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

106
externals/libusb/libusb/msvc/dpfp_2019.vcxproj vendored Executable file
View file

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp</ProjectName>
<ProjectGuid>{8c7814a1-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2019.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4fc737f1-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
<Extensions>c</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89bd-4b04-88eb-625fbe52ebfb}</UniqueIdentifier>
<Extensions>h</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libusb\libusb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp_threaded</ProjectName>
<ProjectGuid>{8c7814a2-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>DPFP_THREADED;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MinimalRebuild>true</MinimalRebuild>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2013.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4fc737f2-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
<Extensions>c</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995381-89bd-4b04-88eb-625fbe52ebfb}</UniqueIdentifier>
<Extensions>h</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libusb\libusb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp_threaded</ProjectName>
<ProjectGuid>{8c7814a2-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>DPFP_THREADED;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2015.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4fc737f2-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
<Extensions>c</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995381-89bd-4b04-88eb-625fbe52ebfb}</UniqueIdentifier>
<Extensions>h</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libusb\libusb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp_threaded</ProjectName>
<ProjectGuid>{8c7814a2-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
<WindowsTargetPlatformVersion Condition="'$(Platform)'=='ARM' Or '$(Platform)'=='ARM64'">10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>DPFP_THREADED;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2017.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4fc737f2-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
<Extensions>c</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995381-89bd-4b04-88eb-625fbe52ebfb}</UniqueIdentifier>
<Extensions>h</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libusb\libusb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dpfp_threaded</ProjectName>
<ProjectGuid>{8c7814a2-fd6e-4185-9ea0-8208119756d4}</ProjectGuid>
<RootNamespace>examples</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\$(ProjectName)\</IntDir>
<OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\examples\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>DPFP_THREADED;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Debug'">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<ClCompile Condition="'$(Configuration)'=='Release'">
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<ProgramDatabaseFile>$(TargetDir)$(ProjectName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Debug'">
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\examples\dpfp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\libusb\libusb.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static_2019.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

Some files were not shown because too many files have changed in this diff Show more