aboutsummaryrefslogtreecommitdiff
path: root/libusb
diff options
context:
space:
mode:
Diffstat (limited to 'libusb')
-rw-r--r--libusb/Makefile.am9
-rw-r--r--libusb/Makefile.in514
-rw-r--r--libusb/core.c918
-rw-r--r--libusb/usb.h339
-rw-r--r--libusb/usbi.h60
5 files changed, 1840 insertions, 0 deletions
diff --git a/libusb/Makefile.am b/libusb/Makefile.am
new file mode 100644
index 0000000..33a609a
--- /dev/null
+++ b/libusb/Makefile.am
@@ -0,0 +1,9 @@
+include_HEADERS = usb.h
+lib_LTLIBRARIES = libusb.la
+
+libusb_la_SOURCES = core.c usbi.h
+libusb_la_CFLAGS = -fvisibility=hidden $(AM_CFLAGS) $(LIBUSB_1_0_CFLAGS)
+libusb_la_LIBADD = $(LIBUSB_1_0_LIBS)
+libusb_la_LDFLAGS = -version-info $(LT_MAJOR):$(LT_REVISION):$(LT_AGE) \
+ -release 0.1
+
diff --git a/libusb/Makefile.in b/libusb/Makefile.in
new file mode 100644
index 0000000..49389c2
--- /dev/null
+++ b/libusb/Makefile.in
@@ -0,0 +1,514 @@
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = libusb
+DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
+libLTLIBRARIES_INSTALL = $(INSTALL)
+LTLIBRARIES = $(lib_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+libusb_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_libusb_la_OBJECTS = libusb_la-core.lo
+libusb_la_OBJECTS = $(am_libusb_la_OBJECTS)
+libusb_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libusb_la_CFLAGS) \
+ $(CFLAGS) $(libusb_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(libusb_la_SOURCES)
+DIST_SOURCES = $(libusb_la_SOURCES)
+includeHEADERS_INSTALL = $(INSTALL_HEADER)
+HEADERS = $(include_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_CFLAGS = @AM_CFLAGS@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBUSB01_VERSION = @LIBUSB01_VERSION@
+LIBUSB_1_0_CFLAGS = @LIBUSB_1_0_CFLAGS@
+LIBUSB_1_0_LIBS = @LIBUSB_1_0_LIBS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_MAJOR = @LT_MAJOR@
+LT_REVISION = @LT_REVISION@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+include_HEADERS = usb.h
+lib_LTLIBRARIES = libusb.la
+libusb_la_SOURCES = core.c usbi.h
+libusb_la_CFLAGS = -fvisibility=hidden $(AM_CFLAGS) $(LIBUSB_1_0_CFLAGS)
+libusb_la_LIBADD = $(LIBUSB_1_0_LIBS)
+libusb_la_LDFLAGS = -version-info $(LT_MAJOR):$(LT_REVISION):$(LT_AGE) \
+ -release 0.1
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libusb/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu libusb/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ if test -f $$p; then \
+ f=$(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
+ else :; fi; \
+ done
+
+uninstall-libLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ p=$(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
+ done
+
+clean-libLTLIBRARIES:
+ -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libusb.la: $(libusb_la_OBJECTS) $(libusb_la_DEPENDENCIES)
+ $(libusb_la_LINK) -rpath $(libdir) $(libusb_la_OBJECTS) $(libusb_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libusb_la-core.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+libusb_la-core.lo: core.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libusb_la_CFLAGS) $(CFLAGS) -MT libusb_la-core.lo -MD -MP -MF $(DEPDIR)/libusb_la-core.Tpo -c -o libusb_la-core.lo `test -f 'core.c' || echo '$(srcdir)/'`core.c
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libusb_la-core.Tpo $(DEPDIR)/libusb_la-core.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='core.c' object='libusb_la-core.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libusb_la_CFLAGS) $(CFLAGS) -c -o libusb_la-core.lo `test -f 'core.c' || echo '$(srcdir)/'`core.c
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+install-includeHEADERS: $(include_HEADERS)
+ @$(NORMAL_INSTALL)
+ test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
+ @list='$(include_HEADERS)'; for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ f=$(am__strip_dir) \
+ echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
+ $(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
+ done
+
+uninstall-includeHEADERS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(include_HEADERS)'; for p in $$list; do \
+ f=$(am__strip_dir) \
+ echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
+ rm -f "$(DESTDIR)$(includedir)/$$f"; \
+ done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs:
+ for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am: install-includeHEADERS
+
+install-dvi: install-dvi-am
+
+install-exec-am: install-libLTLIBRARIES
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libLTLIBRARIES clean-libtool ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-includeHEADERS install-info \
+ install-info-am install-libLTLIBRARIES install-man install-pdf \
+ install-pdf-am install-ps install-ps-am install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-includeHEADERS \
+ uninstall-libLTLIBRARIES
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/libusb/core.c b/libusb/core.c
new file mode 100644
index 0000000..4182584
--- /dev/null
+++ b/libusb/core.c
@@ -0,0 +1,918 @@
+/*
+ * Core functions for libusb-compat-0.1
+ * Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
+ * Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.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 <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <libusb.h>
+
+#include "usb.h"
+#include "usbi.h"
+
+static libusb_context *ctx = NULL;
+static int usb_debug = 0;
+
+enum usbi_log_level {
+ LOG_LEVEL_DEBUG,
+ LOG_LEVEL_INFO,
+ LOG_LEVEL_WARNING,
+ LOG_LEVEL_ERROR,
+};
+
+#ifdef ENABLE_LOGGING
+#define _usbi_log(level, fmt...) usbi_log(level, __FUNCTION__, fmt)
+#else
+#define _usbi_log(level, fmt...)
+#endif
+
+#ifdef ENABLE_DEBUG_LOGGING
+#define usbi_dbg(fmt...) _usbi_log(LOG_LEVEL_DEBUG, fmt)
+#else
+#define usbi_dbg(fmt...)
+#endif
+
+#define usbi_info(fmt...) _usbi_log(LOG_LEVEL_INFO, fmt)
+#define usbi_warn(fmt...) _usbi_log(LOG_LEVEL_WARNING, fmt)
+#define usbi_err(fmt...) _usbi_log(LOG_LEVEL_ERROR, fmt)
+
+API_EXPORTED struct usb_bus *usb_busses = NULL;
+
+#define compat_err(e) -(errno=libusb_to_errno(e))
+
+static int libusb_to_errno(int result)
+{
+ switch (result) {
+ case LIBUSB_SUCCESS:
+ return 0;
+ case LIBUSB_ERROR_IO:
+ return EIO;
+ case LIBUSB_ERROR_INVALID_PARAM:
+ return EINVAL;
+ case LIBUSB_ERROR_ACCESS:
+ return EACCES;
+ case LIBUSB_ERROR_NO_DEVICE:
+ return ENXIO;
+ case LIBUSB_ERROR_NOT_FOUND:
+ return ENOENT;
+ case LIBUSB_ERROR_BUSY:
+ return EBUSY;
+ case LIBUSB_ERROR_TIMEOUT:
+ return ETIMEDOUT;
+ case LIBUSB_ERROR_OVERFLOW:
+ return EOVERFLOW;
+ case LIBUSB_ERROR_PIPE:
+ return EPIPE;
+ case LIBUSB_ERROR_INTERRUPTED:
+ return EINTR;
+ case LIBUSB_ERROR_NO_MEM:
+ return ENOMEM;
+ case LIBUSB_ERROR_NOT_SUPPORTED:
+ return ENOSYS;
+ default:
+ return ERANGE;
+ }
+}
+
+static void usbi_log(enum usbi_log_level level, const char *function,
+ const char *format, ...)
+{
+ va_list args;
+ FILE *stream = stdout;
+ const char *prefix;
+
+#ifndef ENABLE_DEBUG_LOGGING
+ if (!usb_debug)
+ return;
+#endif
+
+ switch (level) {
+ case LOG_LEVEL_INFO:
+ prefix = "info";
+ break;
+ case LOG_LEVEL_WARNING:
+ stream = stderr;
+ prefix = "warning";
+ break;
+ case LOG_LEVEL_ERROR:
+ stream = stderr;
+ prefix = "error";
+ break;
+ case LOG_LEVEL_DEBUG:
+ stream = stderr;
+ prefix = "debug";
+ break;
+ default:
+ stream = stderr;
+ prefix = "unknown";
+ break;
+ }
+
+ fprintf(stream, "libusb-compat %s: %s: ", prefix, function);
+
+ va_start (args, format);
+ vfprintf(stream, format, args);
+ va_end (args);
+
+ fprintf(stream, "\n");
+}
+
+API_EXPORTED void usb_init(void)
+{
+ int r;
+ usbi_dbg("");
+
+ if (!ctx) {
+ r = libusb_init(&ctx);
+ if (r < 0) {
+ usbi_err("initialization failed!");
+ return;
+ }
+
+ /* usb_set_debug can be called before usb_init */
+ if (usb_debug)
+ libusb_set_debug(ctx, 3);
+ }
+}
+
+API_EXPORTED void usb_set_debug(int level)
+{
+ usb_debug = level;
+
+ /* usb_set_debug can be called before usb_init */
+ if (ctx)
+ libusb_set_debug(ctx, 3);
+}
+
+API_EXPORTED char *usb_strerror(void)
+{
+ return strerror(errno);
+}
+
+static int find_busses(struct usb_bus **ret)
+{
+ libusb_device **dev_list = NULL;
+ struct usb_bus *busses = NULL;
+ struct usb_bus *bus;
+ int dev_list_len = 0;
+ int i;
+ int r;
+
+ r = libusb_get_device_list(ctx, &dev_list);
+ if (r < 0) {
+ usbi_err("get_device_list failed with error %d", r);
+ return compat_err(r);
+ }
+
+ if (r == 0) {
+ libusb_free_device_list(dev_list, 1);
+ /* no buses */
+ return 0;
+ }
+
+ /* iterate over the device list, identifying the individual busses.
+ * we use the location field of the usb_bus structure to store the
+ * bus number. */
+
+ dev_list_len = r;
+ for (i = 0; i < dev_list_len; i++) {
+ libusb_device *dev = dev_list[i];
+ uint8_t bus_num = libusb_get_bus_number(dev);
+
+ /* if we already know about it, continue */
+ if (busses) {
+ bus = busses;
+ int found = 0;
+ do {
+ if (bus_num == bus->location) {
+ found = 1;
+ break;
+ }
+ } while ((bus = bus->next) != NULL);
+ if (found)
+ continue;
+ }
+
+ /* add it to the list of busses */
+ bus = malloc(sizeof(*bus));
+ if (!bus)
+ goto err;
+
+ memset(bus, 0, sizeof(*bus));
+ bus->location = bus_num;
+ sprintf(bus->dirname, "%03d", bus_num);
+ LIST_ADD(busses, bus);
+ }
+
+ libusb_free_device_list(dev_list, 1);
+ *ret = busses;
+ return 0;
+
+err:
+ bus = busses;
+ while (bus) {
+ struct usb_bus *tbus = bus->next;
+ free(bus);
+ bus = tbus;
+ }
+ return -ENOMEM;
+}
+
+API_EXPORTED int usb_find_busses(void)
+{
+ struct usb_bus *new_busses = NULL;
+ struct usb_bus *bus;
+ int changes = 0;
+ int r;
+
+ /* libusb-1.0 initialization might have failed, but we can't indicate
+ * this with libusb-0.1, so trap that situation here */
+ if (!ctx)
+ return 0;
+
+ usbi_dbg("");
+ r = find_busses(&new_busses);
+ if (r < 0) {
+ usbi_err("find_busses failed with error %d", r);
+ return r;
+ }
+
+ /* walk through all busses we already know about, removing duplicates
+ * from the new list. if we do not find it in the new list, the bus
+ * has been removed. */
+
+ bus = usb_busses;
+ while (bus) {
+ struct usb_bus *tbus = bus->next;
+ struct usb_bus *nbus = new_busses;
+ int found = 0;
+ usbi_dbg("in loop");
+
+#if 0 /* (yavor) NO caching */
+ while (nbus) {
+ struct usb_bus *tnbus = nbus->next;
+
+ if (bus->location == nbus->location) {
+ LIST_DEL(new_busses, nbus);
+ free(nbus);
+ found = 1;
+ break;
+ }
+ nbus = tnbus;
+ }
+#endif
+ if (!found) {
+ /* bus removed */
+ usbi_dbg("bus %d removed", bus->location);
+ changes++;
+ LIST_DEL(usb_busses, bus);
+ free(bus);
+ }
+
+ bus = tbus;
+ }
+
+ /* anything remaining in new_busses is a new bus */
+ bus = new_busses;
+ while (bus) {
+ struct usb_bus *tbus = bus->next;
+ usbi_dbg("bus %d added", bus->location);
+ LIST_DEL(new_busses, bus);
+ LIST_ADD(usb_busses, bus);
+ changes++;
+ bus = tbus;
+ }
+
+ return changes;
+}
+
+static int find_devices(libusb_device **dev_list, int dev_list_len,
+ struct usb_bus *bus, struct usb_device **ret)
+{
+ struct usb_device *devices = NULL;
+ struct usb_device *dev;
+ int i;
+
+ for (i = 0; i < dev_list_len; i++) {
+ libusb_device *newlib_dev = dev_list[i];
+ uint8_t bus_num = libusb_get_bus_number(newlib_dev);
+
+ if (bus_num != bus->location)
+ continue;
+
+ dev = malloc(sizeof(*dev));
+ if (!dev)
+ goto err;
+
+ /* No need to reference the device now, just take the pointer. We
+ * increase the reference count later if we keep the device. */
+ dev->dev = newlib_dev;
+
+ dev->bus = bus;
+ dev->devnum = libusb_get_device_address(newlib_dev);
+ sprintf(dev->filename, "%03d", dev->devnum);
+ LIST_ADD(devices, dev);
+ }
+
+ *ret = devices;
+ return 0;
+
+err:
+ dev = devices;
+ while (dev) {
+ struct usb_device *tdev = dev->next;
+ free(dev);
+ dev = tdev;
+ }
+ return -ENOMEM;
+}
+
+static void clear_endpoint_descriptor(struct usb_endpoint_descriptor *ep)
+{
+ if (ep->extra)
+ free(ep->extra);
+}
+
+static void clear_interface_descriptor(struct usb_interface_descriptor *iface)
+{
+ if (iface->extra)
+ free(iface->extra);
+ if (iface->endpoint) {
+ int i;
+ for (i = 0; i < iface->bNumEndpoints; i++)
+ clear_endpoint_descriptor(iface->endpoint + i);
+ free(iface->endpoint);
+ }
+}
+
+static void clear_interface(struct usb_interface *iface)
+{
+ if (iface->altsetting) {
+ int i;
+ for (i = 0; i < iface->num_altsetting; i++)
+ clear_interface_descriptor(iface->altsetting + i);
+ free(iface->altsetting);
+ }
+}
+
+static void clear_config_descriptor(struct usb_config_descriptor *config)
+{
+ if (config->extra)
+ free(config->extra);
+ if (config->interface) {
+ int i;
+ for (i = 0; i < config->bNumInterfaces; i++)
+ clear_interface(config->interface + i);
+ free(config->interface);
+ }
+}
+
+static void clear_device(struct usb_device *dev)
+{
+ int i;
+ for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
+ clear_config_descriptor(dev->config + i);
+}
+
+static int copy_endpoint_descriptor(struct usb_endpoint_descriptor *dest,
+ const struct libusb_endpoint_descriptor *src)
+{
+ memcpy(dest, src, USB_DT_ENDPOINT_AUDIO_SIZE);
+
+ dest->extralen = src->extra_length;
+ if (src->extra_length) {
+ dest->extra = malloc(src->extra_length);
+ if (!dest->extra)
+ return -ENOMEM;
+ memcpy(dest->extra, src->extra, src->extra_length);
+ }
+
+ return 0;
+}
+
+static int copy_interface_descriptor(struct usb_interface_descriptor *dest,
+ const struct libusb_interface_descriptor *src)
+{
+ int i;
+ int num_endpoints = src->bNumEndpoints;
+ size_t alloc_size = sizeof(struct usb_endpoint_descriptor) * num_endpoints;
+
+ memcpy(dest, src, USB_DT_INTERFACE_SIZE);
+ dest->endpoint = malloc(alloc_size);
+ if (!dest->endpoint)
+ return -ENOMEM;
+ memset(dest->endpoint, 0, alloc_size);
+
+ for (i = 0; i < num_endpoints; i++) {
+ int r = copy_endpoint_descriptor(dest->endpoint + i, &src->endpoint[i]);
+ if (r < 0) {
+ clear_interface_descriptor(dest);
+ return r;
+ }
+ }
+
+ dest->extralen = src->extra_length;
+ if (src->extra_length) {
+ dest->extra = malloc(src->extra_length);
+ if (!dest->extra) {
+ clear_interface_descriptor(dest);
+ return -ENOMEM;
+ }
+ memcpy(dest->extra, src->extra, src->extra_length);
+ }
+
+ return 0;
+}
+
+static int copy_interface(struct usb_interface *dest,
+ const struct libusb_interface *src)
+{
+ int i;
+ int num_altsetting = src->num_altsetting;
+ size_t alloc_size = sizeof(struct usb_interface_descriptor)
+ * num_altsetting;
+
+ dest->num_altsetting = num_altsetting;
+ dest->altsetting = malloc(alloc_size);
+ if (!dest->altsetting)
+ return -ENOMEM;
+ memset(dest->altsetting, 0, alloc_size);
+
+ for (i = 0; i < num_altsetting; i++) {
+ int r = copy_interface_descriptor(dest->altsetting + i,
+ &src->altsetting[i]);
+ if (r < 0) {
+ clear_interface(dest);
+ return r;
+ }
+ }
+
+ return 0;
+}
+
+static int copy_config_descriptor(struct usb_config_descriptor *dest,
+ const struct libusb_config_descriptor *src)
+{
+ int i;
+ int num_interfaces = src->bNumInterfaces;
+ size_t alloc_size = sizeof(struct usb_interface) * num_interfaces;
+
+ memcpy(dest, src, USB_DT_CONFIG_SIZE);
+ dest->interface = malloc(alloc_size);
+ if (!dest->interface)
+ return -ENOMEM;
+ memset(dest->interface, 0, alloc_size);
+
+ for (i = 0; i < num_interfaces; i++) {
+ int r = copy_interface(dest->interface + i, &src->interface[i]);
+ if (r < 0) {
+ clear_config_descriptor(dest);
+ return r;
+ }
+ }
+
+ dest->extralen = src->extra_length;
+ if (src->extra_length) {
+ dest->extra = malloc(src->extra_length);
+ if (!dest->extra) {
+ clear_config_descriptor(dest);
+ return -ENOMEM;
+ }
+ memcpy(dest->extra, src->extra, src->extra_length);
+ }
+
+ return 0;
+}
+
+static int initialize_device(struct usb_device *dev)
+{
+ libusb_device *newlib_dev = dev->dev;
+ int num_configurations;
+ size_t alloc_size;
+ int r;
+ int i;
+
+ /* device descriptor is identical in both libs */
+ r = libusb_get_device_descriptor(newlib_dev,
+ (struct libusb_device_descriptor *) &dev->descriptor);
+ if (r < 0) {
+ usbi_err("error %d getting device descriptor", r);
+ return compat_err(r);
+ }
+
+ num_configurations = dev->descriptor.bNumConfigurations;
+ alloc_size = sizeof(struct usb_config_descriptor) * num_configurations;
+ dev->config = malloc(alloc_size);
+ if (!dev->config)
+ return -ENOMEM;
+ memset(dev->config, 0, alloc_size);
+
+ /* even though structures are identical, we can't just use libusb-1.0's
+ * config descriptors because we have to store all configurations in
+ * a single flat memory area (libusb-1.0 provides separate allocations).
+ * we hand-copy libusb-1.0's descriptors into our own structures. */
+ for (i = 0; i < num_configurations; i++) {
+ struct libusb_config_descriptor *newlib_config;
+ r = libusb_get_config_descriptor(newlib_dev, i, &newlib_config);
+ if (r < 0) {
+ clear_device(dev);
+ free(dev->config);
+ return compat_err(r);
+ }
+ r = copy_config_descriptor(dev->config + i, newlib_config);
+ libusb_free_config_descriptor(newlib_config);
+ if (r < 0) {
+ clear_device(dev);
+ free(dev->config);
+ return r;
+ }
+ }
+
+ /* libusb doesn't implement this and it doesn't seem that important. If
+ * someone asks for it, we can implement it in v1.1 or later. */
+ dev->num_children = 0;
+ dev->children = NULL;
+
+ libusb_ref_device(newlib_dev);
+ return 0;
+}
+
+static void free_device(struct usb_device *dev)
+{
+ clear_device(dev);
+ libusb_unref_device(dev->dev);
+ free(dev);
+}
+
+API_EXPORTED int usb_find_devices(void)
+{
+ struct usb_bus *bus;
+ libusb_device **dev_list;
+ int dev_list_len;
+ int r;
+ int changes = 0;
+
+ /* libusb-1.0 initialization might have failed, but we can't indicate
+ * this with libusb-0.1, so trap that situation here */
+ if (!ctx)
+ return 0;
+
+ usbi_dbg("");
+ dev_list_len = libusb_get_device_list(ctx, &dev_list);
+ if (dev_list_len < 0)
+ return compat_err(dev_list_len);
+
+ for (bus = usb_busses; bus; bus = bus->next) {
+ struct usb_device *new_devices = NULL;
+ struct usb_device *dev;
+
+ r = find_devices(dev_list, dev_list_len, bus, &new_devices);
+ if (r < 0) {
+ libusb_free_device_list(dev_list, 1);
+ return r;
+ }
+
+ /* walk through the devices we already know about, removing duplicates
+ * from the new list. if we do not find it in the new list, the device
+ * has been removed. */
+ dev = bus->devices;
+ while (dev) {
+ int found = 0;
+ struct usb_device *tdev = dev->next;
+ struct usb_device *ndev = new_devices;
+
+ while (ndev) {
+ if (ndev->devnum == dev->devnum) {
+ LIST_DEL(new_devices, ndev);
+ free(ndev);
+ found = 1;
+ break;
+ }
+ ndev = ndev->next;
+ }
+
+ if (!found) {
+ usbi_dbg("device %d.%d removed",
+ dev->bus->location, dev->devnum);
+ LIST_DEL(bus->devices, dev);
+ free_device(dev);
+ changes++;
+ }
+
+ dev = tdev;
+ }
+
+ /* anything left in new_devices is a new device */
+ dev = new_devices;
+ while (dev) {
+ struct usb_device *tdev = dev->next;
+ r = initialize_device(dev);
+ if (r < 0) {
+ usbi_err("couldn't initialize device %d.%d (error %d)",
+ dev->bus->location, dev->devnum, r);
+ dev = tdev;
+ continue;
+ }
+ usbi_dbg("device %d.%d added", dev->bus->location, dev->devnum);
+ LIST_DEL(new_devices, dev);
+ LIST_ADD(bus->devices, dev);
+ changes++;
+ dev = tdev;
+ }
+ }
+
+ libusb_free_device_list(dev_list, 1);
+ return changes;
+}
+
+API_EXPORTED struct usb_bus *usb_get_busses(void)
+{
+ return usb_busses;
+}
+
+API_EXPORTED usb_dev_handle *usb_open(struct usb_device *dev)
+{
+ int r;
+ usbi_dbg("");
+
+ usb_dev_handle *udev = malloc(sizeof(*udev));
+ if (!udev)
+ return NULL;
+
+ r = libusb_open((libusb_device *) dev->dev, &udev->handle);
+ if (r < 0) {
+ usbi_err("could not open device, error %d", r);
+ free(udev);
+ errno = libusb_to_errno(r);
+ return NULL;
+ }
+
+ udev->last_claimed_interface = -1;
+ udev->device = dev;
+ return udev;
+}
+
+API_EXPORTED int usb_close(usb_dev_handle *dev)
+{
+ usbi_dbg("");
+ libusb_close(dev->handle);
+ free(dev);
+ return 0;
+}
+
+API_EXPORTED struct usb_device *usb_device(usb_dev_handle *dev)
+{
+ return dev->device;
+}
+
+API_EXPORTED int usb_set_configuration(usb_dev_handle *dev, int configuration)
+{
+ usbi_dbg("configuration %d", configuration);
+ return compat_err(libusb_set_configuration(dev->handle, configuration));
+}
+
+API_EXPORTED int usb_claim_interface(usb_dev_handle *dev, int interface)
+{
+ int r;
+ usbi_dbg("interface %d", interface);
+
+ r = libusb_claim_interface(dev->handle, interface);
+ if (r == 0) {
+ dev->last_claimed_interface = interface;
+ return 0;
+ }
+
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_release_interface(usb_dev_handle *dev, int interface)
+{
+ int r;
+ usbi_dbg("interface %d", interface);
+
+ r = libusb_release_interface(dev->handle, interface);
+ if (r == 0)
+ dev->last_claimed_interface = -1;
+
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_set_altinterface(usb_dev_handle *dev, int alternate)
+{
+ usbi_dbg("alternate %d", alternate);
+ if (dev->last_claimed_interface < 0)
+ return -(errno=EINVAL);
+
+ return compat_err(libusb_set_interface_alt_setting(dev->handle,
+ dev->last_claimed_interface, alternate));
+}
+
+API_EXPORTED int usb_resetep(usb_dev_handle *dev, unsigned int ep)
+{
+ return compat_err(usb_clear_halt(dev, ep));
+}
+
+API_EXPORTED int usb_clear_halt(usb_dev_handle *dev, unsigned int ep)
+{
+ usbi_dbg("endpoint %x", ep);
+ return compat_err(libusb_clear_halt(dev->handle, ep & 0xff));
+}
+
+API_EXPORTED int usb_reset(usb_dev_handle *dev)
+{
+ usbi_dbg("");
+ return compat_err(libusb_reset_device(dev->handle));
+}
+
+static int usb_bulk_io(usb_dev_handle *dev, int ep, char *bytes,
+ int size, int timeout)
+{
+ int actual_length;
+ int r;
+ usbi_dbg("endpoint %x size %d timeout %d", ep, size, timeout);
+ r = libusb_bulk_transfer(dev->handle, ep & 0xff, bytes, size,
+ &actual_length, timeout);
+
+ /* if we timed out but did transfer some data, report as successful short
+ * read. FIXME: is this how libusb-0.1 works? */
+ if (r == 0 || (r == LIBUSB_ERROR_TIMEOUT && actual_length > 0))
+ return actual_length;
+
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes,
+ int size, int timeout)
+{
+ if (!(ep & USB_ENDPOINT_IN)) {
+ /* libusb-0.1 will strangely fix up a read request from endpoint
+ * 0x01 to be from endpoint 0x81. do the same thing here, but
+ * warn about this silly behaviour. */
+ usbi_warn("endpoint %x is missing IN direction bit, fixing");
+ ep |= USB_ENDPOINT_IN;
+ }
+
+ return usb_bulk_io(dev, ep, bytes, size, timeout);
+}
+
+API_EXPORTED int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes,
+ int size, int timeout)
+{
+ if (ep & USB_ENDPOINT_IN) {
+ /* libusb-0.1 on BSD strangely fix up a write request to endpoint
+ * 0x81 to be to endpoint 0x01. do the same thing here, but
+ * warn about this silly behaviour. */
+ usbi_warn("endpoint %x has excessive IN direction bit, fixing");
+ ep &= ~USB_ENDPOINT_IN;
+ }
+
+ return usb_bulk_io(dev, ep, bytes, size, timeout);
+}
+
+static int usb_interrupt_io(usb_dev_handle *dev, int ep, char *bytes,
+ int size, int timeout)
+{
+ int actual_length;
+ int r;
+ usbi_dbg("endpoint %x size %d timeout %d", ep, size, timeout);
+ r = libusb_interrupt_transfer(dev->handle, ep & 0xff, bytes, size,
+ &actual_length, timeout);
+
+ /* if we timed out but did transfer some data, report as successful short
+ * read. FIXME: is this how libusb-0.1 works? */
+ if (r == 0 || (r == LIBUSB_ERROR_TIMEOUT && actual_length > 0))
+ return actual_length;
+
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes,
+ int size, int timeout)
+{
+ if (!(ep & USB_ENDPOINT_IN)) {
+ /* libusb-0.1 will strangely fix up a read request from endpoint
+ * 0x01 to be from endpoint 0x81. do the same thing here, but
+ * warn about this silly behaviour. */
+ usbi_warn("endpoint %x is missing IN direction bit, fixing");
+ ep |= USB_ENDPOINT_IN;
+ }
+ return usb_interrupt_io(dev, ep, bytes, size, timeout);
+}
+
+API_EXPORTED int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes,
+ int size, int timeout)
+{
+ if (ep & USB_ENDPOINT_IN) {
+ /* libusb-0.1 on BSD strangely fix up a write request to endpoint
+ * 0x81 to be to endpoint 0x01. do the same thing here, but
+ * warn about this silly behaviour. */
+ usbi_warn("endpoint %x has excessive IN direction bit, fixing");
+ ep &= ~USB_ENDPOINT_IN;
+ }
+
+ return usb_interrupt_io(dev, ep, bytes, size, timeout);
+}
+
+API_EXPORTED int usb_control_msg(usb_dev_handle *dev, int bmRequestType,
+ int bRequest, int wValue, int wIndex, char *bytes, int size, int timeout)
+{
+ int r;
+ usbi_dbg("RQT=%x RQ=%x V=%x I=%x len=%d timeout=%d", bmRequestType,
+ bRequest, wValue, wIndex, size, timeout);
+
+ r = libusb_control_transfer(dev->handle, bmRequestType & 0xff,
+ bRequest & 0xff, wValue & 0xffff, wIndex & 0xffff, bytes, size & 0xffff,
+ timeout);
+
+ if (r >= 0)
+ return r;
+
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_get_string(usb_dev_handle *dev, int desc_index, int langid,
+ char *buf, size_t buflen)
+{
+ int r;
+ r = libusb_get_string_descriptor(dev->handle, desc_index & 0xff,
+ langid & 0xffff, buf, (int) buflen);
+ if (r >= 0)
+ return r;
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_get_string_simple(usb_dev_handle *dev, int desc_index,
+ char *buf, size_t buflen)
+{
+ int r;
+ r = libusb_get_string_descriptor_ascii(dev->handle, desc_index & 0xff,
+ buf, (int) buflen);
+ if (r >= 0)
+ return r;
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_get_descriptor(usb_dev_handle *dev, unsigned char type,
+ unsigned char desc_index, void *buf, int size)
+{
+ int r;
+ r = libusb_get_descriptor(dev->handle, type, desc_index, buf, size);
+ if (r >= 0)
+ return r;
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_get_descriptor_by_endpoint(usb_dev_handle *dev, int ep,
+ unsigned char type, unsigned char desc_index, void *buf, int size)
+{
+ /* this function doesn't make much sense - the specs don't talk about
+ * getting a descriptor "by endpoint". libusb-1.0 does not provide this
+ * functionality so we just send a control message directly */
+ int r;
+ r = libusb_control_transfer(dev->handle,
+ LIBUSB_ENDPOINT_IN | (ep & 0xff), LIBUSB_REQUEST_GET_DESCRIPTOR,
+ (type << 8) | desc_index, 0, buf, size, 1000);
+ if (r >= 0)
+ return r;
+ return compat_err(r);
+}
+
+API_EXPORTED int usb_get_driver_np(usb_dev_handle *dev, int interface,
+ char *name, unsigned int namelen)
+{
+ int r = libusb_kernel_driver_active(dev->handle, interface);
+ if (r == 1) {
+ /* libusb-1.0 doesn't expose driver name, so fill in a dummy value */
+ snprintf(name, namelen, "dummy");
+ return 0;
+ } else if (r == 0) {
+ return -(errno=ENODATA);
+ } else {
+ return compat_err(r);
+ }
+}
+
+API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface)
+{
+ return compat_err(libusb_detach_kernel_driver(dev->handle, interface));
+}
+
diff --git a/libusb/usb.h b/libusb/usb.h
new file mode 100644
index 0000000..b7af749
--- /dev/null
+++ b/libusb/usb.h
@@ -0,0 +1,339 @@
+/*
+ * Prototypes, structure definitions and macros.
+ *
+ * Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.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
+ *
+ * This file (and only this file) may alternatively be licensed under the
+ * BSD license. See the LICENSE file shipped with the libusb-compat-0.1 source
+ * distribution for details.
+ */
+
+#ifndef __USB_H__
+#define __USB_H__
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <dirent.h>
+
+/*
+ * USB spec information
+ *
+ * This is all stuff grabbed from various USB specs and is pretty much
+ * not subject to change
+ */
+
+/*
+ * Device and/or Interface Class codes
+ */
+#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
+#define USB_CLASS_AUDIO 1
+#define USB_CLASS_COMM 2
+#define USB_CLASS_HID 3
+#define USB_CLASS_PRINTER 7
+#define USB_CLASS_PTP 6
+#define USB_CLASS_MASS_STORAGE 8
+#define USB_CLASS_HUB 9
+#define USB_CLASS_DATA 10
+#define USB_CLASS_VENDOR_SPEC 0xff
+
+/*
+ * Descriptor types
+ */
+#define USB_DT_DEVICE 0x01
+#define USB_DT_CONFIG 0x02
+#define USB_DT_STRING 0x03
+#define USB_DT_INTERFACE 0x04
+#define USB_DT_ENDPOINT 0x05
+
+#define USB_DT_HID 0x21
+#define USB_DT_REPORT 0x22
+#define USB_DT_PHYSICAL 0x23
+#define USB_DT_HUB 0x29
+
+/*
+ * Descriptor sizes per descriptor type
+ */
+#define USB_DT_DEVICE_SIZE 18
+#define USB_DT_CONFIG_SIZE 9
+#define USB_DT_INTERFACE_SIZE 9
+#define USB_DT_ENDPOINT_SIZE 7
+#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
+#define USB_DT_HUB_NONVAR_SIZE 7
+
+/* All standard descriptors have these 2 fields in common */
+struct usb_descriptor_header {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+};
+
+/* String descriptor */
+struct usb_string_descriptor {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+ u_int16_t wData[1];
+};
+
+/* HID descriptor */
+struct usb_hid_descriptor {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+ u_int16_t bcdHID;
+ u_int8_t bCountryCode;
+ u_int8_t bNumDescriptors;
+ /* u_int8_t bReportDescriptorType; */
+ /* u_int16_t wDescriptorLength; */
+ /* ... */
+};
+
+/* Endpoint descriptor */
+#define USB_MAXENDPOINTS 32
+struct usb_endpoint_descriptor {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+ u_int8_t bEndpointAddress;
+ u_int8_t bmAttributes;
+ u_int16_t wMaxPacketSize;
+ u_int8_t bInterval;
+ u_int8_t bRefresh;
+ u_int8_t bSynchAddress;
+
+ unsigned char *extra; /* Extra descriptors */
+ int extralen;
+};
+
+#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
+#define USB_ENDPOINT_DIR_MASK 0x80
+
+#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
+#define USB_ENDPOINT_TYPE_CONTROL 0
+#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
+#define USB_ENDPOINT_TYPE_BULK 2
+#define USB_ENDPOINT_TYPE_INTERRUPT 3
+
+/* Interface descriptor */
+#define USB_MAXINTERFACES 32
+struct usb_interface_descriptor {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+ u_int8_t bInterfaceNumber;
+ u_int8_t bAlternateSetting;
+ u_int8_t bNumEndpoints;
+ u_int8_t bInterfaceClass;
+ u_int8_t bInterfaceSubClass;
+ u_int8_t bInterfaceProtocol;
+ u_int8_t iInterface;
+
+ struct usb_endpoint_descriptor *endpoint;
+
+ unsigned char *extra; /* Extra descriptors */
+ int extralen;
+};
+
+#define USB_MAXALTSETTING 128 /* Hard limit */
+struct usb_interface {
+ struct usb_interface_descriptor *altsetting;
+
+ int num_altsetting;
+};
+
+/* Configuration descriptor information.. */
+#define USB_MAXCONFIG 8
+struct usb_config_descriptor {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+ u_int16_t wTotalLength;
+ u_int8_t bNumInterfaces;
+ u_int8_t bConfigurationValue;
+ u_int8_t iConfiguration;
+ u_int8_t bmAttributes;
+ u_int8_t MaxPower;
+
+ struct usb_interface *interface;
+
+ unsigned char *extra; /* Extra descriptors */
+ int extralen;
+};
+
+/* Device descriptor */
+struct usb_device_descriptor {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+ u_int16_t bcdUSB;
+ u_int8_t bDeviceClass;
+ u_int8_t bDeviceSubClass;
+ u_int8_t bDeviceProtocol;
+ u_int8_t bMaxPacketSize0;
+ u_int16_t idVendor;
+ u_int16_t idProduct;
+ u_int16_t bcdDevice;
+ u_int8_t iManufacturer;
+ u_int8_t iProduct;
+ u_int8_t iSerialNumber;
+ u_int8_t bNumConfigurations;
+};
+
+struct usb_ctrl_setup {
+ u_int8_t bRequestType;
+ u_int8_t bRequest;
+ u_int16_t wValue;
+ u_int16_t wIndex;
+ u_int16_t wLength;
+};
+
+/*
+ * Standard requests
+ */
+#define USB_REQ_GET_STATUS 0x00
+#define USB_REQ_CLEAR_FEATURE 0x01
+/* 0x02 is reserved */
+#define USB_REQ_SET_FEATURE 0x03
+/* 0x04 is reserved */
+#define USB_REQ_SET_ADDRESS 0x05
+#define USB_REQ_GET_DESCRIPTOR 0x06
+#define USB_REQ_SET_DESCRIPTOR 0x07
+#define USB_REQ_GET_CONFIGURATION 0x08
+#define USB_REQ_SET_CONFIGURATION 0x09
+#define USB_REQ_GET_INTERFACE 0x0A
+#define USB_REQ_SET_INTERFACE 0x0B
+#define USB_REQ_SYNCH_FRAME 0x0C
+
+#define USB_TYPE_STANDARD (0x00 << 5)
+#define USB_TYPE_CLASS (0x01 << 5)
+#define USB_TYPE_VENDOR (0x02 << 5)
+#define USB_TYPE_RESERVED (0x03 << 5)
+
+#define USB_RECIP_DEVICE 0x00
+#define USB_RECIP_INTERFACE 0x01
+#define USB_RECIP_ENDPOINT 0x02
+#define USB_RECIP_OTHER 0x03
+
+/*
+ * Various libusb API related stuff
+ */
+
+#define USB_ENDPOINT_IN 0x80
+#define USB_ENDPOINT_OUT 0x00
+
+/* Error codes */
+#define USB_ERROR_BEGIN 500000
+
+/* Data types */
+struct usb_device;
+struct usb_bus;
+
+/*
+ * To maintain compatibility with applications already built with libusb,
+ * we must only add entries to the end of this structure. NEVER delete or
+ * move members and only change types if you really know what you're doing.
+ */
+struct usb_device {
+ struct usb_device *next, *prev;
+
+ char filename[PATH_MAX + 1];
+
+ struct usb_bus *bus;
+
+ struct usb_device_descriptor descriptor;
+ struct usb_config_descriptor *config;
+
+ void *dev; /* Darwin support */
+
+ u_int8_t devnum;
+
+ unsigned char num_children;
+ struct usb_device **children;
+};
+
+struct usb_bus {
+ struct usb_bus *next, *prev;
+
+ char dirname[PATH_MAX + 1];
+
+ struct usb_device *devices;
+ u_int32_t location;
+
+ struct usb_device *root_dev;
+};
+
+struct usb_dev_handle;
+typedef struct usb_dev_handle usb_dev_handle;
+
+/* Variables */
+extern struct usb_bus *usb_busses;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function prototypes */
+
+/* usb.c */
+usb_dev_handle *usb_open(struct usb_device *dev);
+int usb_close(usb_dev_handle *dev);
+int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
+ size_t buflen);
+int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
+ size_t buflen);
+
+/* descriptors.c */
+int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
+ unsigned char type, unsigned char index, void *buf, int size);
+int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
+ unsigned char index, void *buf, int size);
+
+/* <arch>.c */
+int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
+ int timeout);
+int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
+ int timeout);
+int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
+ int timeout);
+int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
+ int timeout);
+int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
+ int value, int index, char *bytes, int size, int timeout);
+int usb_set_configuration(usb_dev_handle *dev, int configuration);
+int usb_claim_interface(usb_dev_handle *dev, int interface);
+int usb_release_interface(usb_dev_handle *dev, int interface);
+int usb_set_altinterface(usb_dev_handle *dev, int alternate);
+int usb_resetep(usb_dev_handle *dev, unsigned int ep);
+int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
+int usb_reset(usb_dev_handle *dev);
+
+#define LIBUSB_HAS_GET_DRIVER_NP 1
+int usb_get_driver_np(usb_dev_handle *dev, int interface, char *name,
+ unsigned int namelen);
+#define LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 1
+int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface);
+
+char *usb_strerror(void);
+
+void usb_init(void);
+void usb_set_debug(int level);
+int usb_find_busses(void);
+int usb_find_devices(void);
+struct usb_device *usb_device(usb_dev_handle *dev);
+struct usb_bus *usb_get_busses(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __USB_H__ */
+
diff --git a/libusb/usbi.h b/libusb/usbi.h
new file mode 100644
index 0000000..44c0344
--- /dev/null
+++ b/libusb/usbi.h
@@ -0,0 +1,60 @@
+/*
+ * Internal header for libusb-compat-0.1
+ * Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
+ * Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.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_USBI_H__
+#define __LIBUSB_USBI_H__
+
+/* Some quick and generic macros for the simple kind of lists we use */
+#define LIST_ADD(begin, ent) \
+ do { \
+ if (begin) { \
+ ent->next = begin; \
+ ent->next->prev = ent; \
+ } else \
+ ent->next = NULL; \
+ ent->prev = NULL; \
+ begin = ent; \
+ } while(0)
+
+#define LIST_DEL(begin, ent) \
+ do { \
+ if (ent->prev) \
+ ent->prev->next = ent->next; \
+ else \
+ begin = ent->next; \
+ if (ent->next) \
+ ent->next->prev = ent->prev; \
+ ent->prev = NULL; \
+ ent->next = NULL; \
+ } while (0)
+
+struct usb_dev_handle {
+ libusb_device_handle *handle;
+ struct usb_device *device;
+
+ /* libusb-0.1 is buggy w.r.t. interface claiming. it allows you to claim
+ * multiple interfaces but only tracks the most recently claimed one,
+ * which is used for usb_set_altinterface(). we clone the buggy behaviour
+ * here. */
+ int last_claimed_interface;
+};
+
+#endif
+