From 28e998d962cd69a3ef553931f90904f67a5d2d7f Mon Sep 17 00:00:00 2001
From: debrouxl <lionel_debroux@yahoo.fr>
Date: Sat, 19 Feb 2011 17:09:26 +0100
Subject: WIP libticables: add experimental libusb 1.0 backend for *nix.
 libusb 1.0 backend: Jon Sturm.
 Autotools infrastructure: Lionel, glitches reported by Jon and fixed by Lionel.
 Glue code: Lionel.
 Testing: Lionel, Jon and others.

---
 libticables/trunk/Makefile.in               |    2 +
 libticables/trunk/build/mingw/Makefile.in   |    2 +
 libticables/trunk/config.h.in               |    5 +-
 libticables/trunk/configure                 |  231 +++++++---
 libticables/trunk/configure.ac              |   55 ++-
 libticables/trunk/docs/Makefile.in          |    2 +
 libticables/trunk/src/Makefile.am           |    4 +-
 libticables/trunk/src/Makefile.in           |    6 +-
 libticables/trunk/src/bsd/detect.c          |    2 +-
 libticables/trunk/src/link_usb.c            |    2 +
 libticables/trunk/src/linux/detect.c        |    2 +-
 libticables/trunk/src/linux/link_dev.c      |    2 +-
 libticables/trunk/src/linux/link_usb.c      |    6 +-
 libticables/trunk/src/linux/link_usb1.c     |  667 +++++++++++++++++++++++++++
 libticables/trunk/src/probe.c               |    6 +-
 libticables/trunk/src/ticables.c            |   96 +++--
 libticables/trunk/src/win32/dha/Makefile.in |    2 +
 libticables/trunk/src/win64/rwp/Makefile.in |    2 +
 libticables/trunk/tests/Makefile.in         |    2 +
 19 files changed, 976 insertions(+), 120 deletions(-)
 create mode 100644 libticables/trunk/src/linux/link_usb1.c

diff --git a/libticables/trunk/Makefile.in b/libticables/trunk/Makefile.in
index 8c67326..f14ad16 100644
--- a/libticables/trunk/Makefile.in
+++ b/libticables/trunk/Makefile.in
@@ -180,6 +180,8 @@ LIBINTL = @LIBINTL@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
+LIBUSB10_CFLAGS = @LIBUSB10_CFLAGS@
+LIBUSB10_LIBS = @LIBUSB10_LIBS@
 LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
 LIBUSB_LIBS = @LIBUSB_LIBS@
 LN_S = @LN_S@
diff --git a/libticables/trunk/build/mingw/Makefile.in b/libticables/trunk/build/mingw/Makefile.in
index 289441a..28ff3f5 100644
--- a/libticables/trunk/build/mingw/Makefile.in
+++ b/libticables/trunk/build/mingw/Makefile.in
@@ -100,6 +100,8 @@ LIBINTL = @LIBINTL@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
+LIBUSB10_CFLAGS = @LIBUSB10_CFLAGS@
+LIBUSB10_LIBS = @LIBUSB10_LIBS@
 LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
 LIBUSB_LIBS = @LIBUSB_LIBS@
 LN_S = @LN_S@
diff --git a/libticables/trunk/config.h.in b/libticables/trunk/config.h.in
index 9a5bef8..10e8dec 100644
--- a/libticables/trunk/config.h.in
+++ b/libticables/trunk/config.h.in
@@ -41,9 +41,12 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
-/* Define to 1 to enable libusb support. */
+/* Define to 1 to enable libusb 0.1.x support. */
 #undef HAVE_LIBUSB
 
+/* Define to 1 to enable EXPERIMENTAL libusb 1.0.x support. */
+#undef HAVE_LIBUSB_1_0
+
 /* Define to 1 if you have the <linux/parport.h> header file. */
 #undef HAVE_LINUX_PARPORT_H
 
diff --git a/libticables/trunk/configure b/libticables/trunk/configure
index f5fd22e..ef5fcad 100755
--- a/libticables/trunk/configure
+++ b/libticables/trunk/configure
@@ -756,6 +756,8 @@ LTLIBOBJS
 OS_WIN32_FALSE
 OS_WIN32_TRUE
 LIBOBJS
+LIBUSB10_LIBS
+LIBUSB10_CFLAGS
 LIBUSB_LIBS
 LIBUSB_CFLAGS
 GLIB_LIBS
@@ -912,6 +914,7 @@ enable_rpath
 with_libiconv_prefix
 with_libintl_prefix
 enable_libusb
+enable_libusb10
 enable_logging
 '
       ac_precious_vars='build_alias
@@ -935,7 +938,9 @@ PKG_CONFIG_LIBDIR
 GLIB_CFLAGS
 GLIB_LIBS
 LIBUSB_CFLAGS
-LIBUSB_LIBS'
+LIBUSB_LIBS
+LIBUSB10_CFLAGS
+LIBUSB10_LIBS'
 
 
 # Initialize some variables set by options.
@@ -1567,7 +1572,8 @@ Optional Features:
   --disable-libtool-lock  avoid locking (might break parallel builds)
   --disable-nls           do not use Native Language Support
   --disable-rpath         do not hardcode runtime library paths
-  --disable-libusb        disable USB support
+  --disable-libusb        disable USB support through libusb 0.1.x
+  --enable-libusb10       enable EXPERIMENTAL USB support through libusb 1.0.x
   --enable-logging        enable logging
 
 Optional Packages:
@@ -1607,6 +1613,10 @@ Some influential environment variables:
   LIBUSB_CFLAGS
               C compiler flags for LIBUSB, overriding pkg-config
   LIBUSB_LIBS linker flags for LIBUSB, overriding pkg-config
+  LIBUSB10_CFLAGS
+              C compiler flags for LIBUSB10, overriding pkg-config
+  LIBUSB10_LIBS
+              linker flags for LIBUSB10, overriding pkg-config
 
 Use these variables to override the choices made by `configure' or to help
 it to find libraries and programs with nonstandard names/locations.
@@ -4946,7 +4956,7 @@ ia64-*-hpux*)
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 4949 "configure"' > conftest.$ac_ext
+  echo '#line 4959 "configure"' > conftest.$ac_ext
   if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -7641,11 +7651,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7644: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7654: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7648: \$? = $ac_status" >&5
+   echo "$as_me:7658: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -7931,11 +7941,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7934: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7944: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7938: \$? = $ac_status" >&5
+   echo "$as_me:7948: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -8035,11 +8045,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8038: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:8048: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:8042: \$? = $ac_status" >&5
+   echo "$as_me:8052: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -10073,7 +10083,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 10076 "configure"
+#line 10086 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -10173,7 +10183,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 10176 "configure"
+#line 10186 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12514,11 +12524,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:12517: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:12527: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:12521: \$? = $ac_status" >&5
+   echo "$as_me:12531: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -12618,11 +12628,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:12621: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:12631: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:12625: \$? = $ac_status" >&5
+   echo "$as_me:12635: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -14216,11 +14226,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14219: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14229: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:14223: \$? = $ac_status" >&5
+   echo "$as_me:14233: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -14320,11 +14330,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14323: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14333: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:14327: \$? = $ac_status" >&5
+   echo "$as_me:14337: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -16494,11 +16504,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16497: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:16507: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:16501: \$? = $ac_status" >&5
+   echo "$as_me:16511: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -16784,11 +16794,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16787: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:16797: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:16791: \$? = $ac_status" >&5
+   echo "$as_me:16801: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -16888,11 +16898,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16891: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:16901: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:16895: \$? = $ac_status" >&5
+   echo "$as_me:16905: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -22185,6 +22195,7 @@ $as_echo "#define HAVE_DCGETTEXT 1" >>confdefs.h
 
 
 
+# Call explicitely before using PKG_*
 
 
 
@@ -22305,6 +22316,7 @@ $as_echo "no" >&6; }
 	fi
 fi
 
+
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLIB" >&5
 $as_echo_n "checking for GLIB... " >&6; }
@@ -22404,8 +22416,8 @@ else
   cab_cv_use_libusb=yes
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to disable USB" >&5
-$as_echo_n "checking whether to disable USB... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable USB through libusb 0.1.x" >&5
+$as_echo_n "checking whether to enable USB through libusb 0.1.x... " >&6; }
 if test "${cab_cv_use_libusb+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
@@ -22413,7 +22425,33 @@ else
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cab_cv_use_libusb" >&5
 $as_echo "$cab_cv_use_libusb" >&6; }
-if test x$cab_cv_use_libusb = xyes; then
+
+# Check whether --enable-libusb10 was given.
+if test "${enable_libusb10+set}" = set; then :
+  enableval=$enable_libusb10; cab_cv_use_libusb10=$enableval
+else
+  cab_cv_use_libusb10=no
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable USB through libusb 1.0.x" >&5
+$as_echo_n "checking whether to enable USB through libusb 1.0.x... " >&6; }
+if test "${cab_cv_use_libusb10+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cab_cv_use_libusb10=no
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cab_cv_use_libusb10" >&5
+$as_echo "$cab_cv_use_libusb10" >&6; }
+
+if test "x$cab_cv_use_libusb" = xyes; then :
+  if test "x$cab_cv_use_libusb10" = xyes; then :
+  as_fn_error $? "cannot enable both libusb 0.1.x support and libusb 1.0.x support !" "$LINENO" 5
+
+fi
+
+fi
+
+if test "x$cab_cv_use_libusb" = xyes; then
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBUSB" >&5
@@ -22423,12 +22461,12 @@ if test -n "$LIBUSB_CFLAGS"; then
     pkg_cv_LIBUSB_CFLAGS="$LIBUSB_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libusb >= 0.1.10\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libusb >= 0.1.10") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \" libusb >= 0.1.12 \""; } >&5
+  ($PKG_CONFIG --exists --print-errors " libusb >= 0.1.12 ") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_LIBUSB_CFLAGS=`$PKG_CONFIG --cflags "libusb >= 0.1.10" 2>/dev/null`
+  pkg_cv_LIBUSB_CFLAGS=`$PKG_CONFIG --cflags " libusb >= 0.1.12 " 2>/dev/null`
 else
   pkg_failed=yes
 fi
@@ -22439,12 +22477,12 @@ if test -n "$LIBUSB_LIBS"; then
     pkg_cv_LIBUSB_LIBS="$LIBUSB_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libusb >= 0.1.10\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libusb >= 0.1.10") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \" libusb >= 0.1.12 \""; } >&5
+  ($PKG_CONFIG --exists --print-errors " libusb >= 0.1.12 ") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_LIBUSB_LIBS=`$PKG_CONFIG --libs "libusb >= 0.1.10" 2>/dev/null`
+  pkg_cv_LIBUSB_LIBS=`$PKG_CONFIG --libs " libusb >= 0.1.12 " 2>/dev/null`
 else
   pkg_failed=yes
 fi
@@ -22464,52 +22502,123 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-	        LIBUSB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libusb >= 0.1.10" 2>&1`
+	        LIBUSB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors " libusb >= 0.1.12 " 2>&1`
         else
-	        LIBUSB_PKG_ERRORS=`$PKG_CONFIG --print-errors "libusb >= 0.1.10" 2>&1`
+	        LIBUSB_PKG_ERRORS=`$PKG_CONFIG --print-errors " libusb >= 0.1.12 " 2>&1`
         fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$LIBUSB_PKG_ERRORS" >&5
 
-	as_fn_error $? "Package requirements (libusb >= 0.1.10) were not met:
-
-$LIBUSB_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables LIBUSB_CFLAGS
-and LIBUSB_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+	have_libusb=no
 elif test $pkg_failed = untried; then
      	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LIBUSB_CFLAGS
-and LIBUSB_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5 ; }
+	have_libusb=no
 else
 	LIBUSB_CFLAGS=$pkg_cv_LIBUSB_CFLAGS
 	LIBUSB_LIBS=$pkg_cv_LIBUSB_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
-
+	have_libusb=yes
 fi
+  if test "$have_libusb" = "yes"; then
+    CFLAGS="$CFLAGS $LIBUSB_CFLAGS"
+    USB_LIBS="$USB_LIBS $LIBUSB_LIBS"
+    HAVE_USB=yes
 
 $as_echo "#define HAVE_LIBUSB 1" >>confdefs.h
 
+  else
+    LIBUSB_CFLAGS=
+    LIBUSB_LIBS=
+  fi
+fi
+
+if test "x$cab_cv_use_libusb10" = xyes; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBUSB10" >&5
+$as_echo_n "checking for LIBUSB10... " >&6; }
+
+if test -n "$LIBUSB10_CFLAGS"; then
+    pkg_cv_LIBUSB10_CFLAGS="$LIBUSB10_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \" libusb-1.0 >= 1.0.0 \""; } >&5
+  ($PKG_CONFIG --exists --print-errors " libusb-1.0 >= 1.0.0 ") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBUSB10_CFLAGS=`$PKG_CONFIG --cflags " libusb-1.0 >= 1.0.0 " 2>/dev/null`
 else
-  LIBUSB_CFLAGS=
-  LIBUSB_LIBS=
+  pkg_failed=yes
 fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$LIBUSB10_LIBS"; then
+    pkg_cv_LIBUSB10_LIBS="$LIBUSB10_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \" libusb-1.0 >= 1.0.0 \""; } >&5
+  ($PKG_CONFIG --exists --print-errors " libusb-1.0 >= 1.0.0 ") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBUSB10_LIBS=`$PKG_CONFIG --libs " libusb-1.0 >= 1.0.0 " 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        LIBUSB10_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors " libusb-1.0 >= 1.0.0 " 2>&1`
+        else
+	        LIBUSB10_PKG_ERRORS=`$PKG_CONFIG --print-errors " libusb-1.0 >= 1.0.0 " 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$LIBUSB10_PKG_ERRORS" >&5
+
+	have_libusb10=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_libusb10=no
+else
+	LIBUSB10_CFLAGS=$pkg_cv_LIBUSB10_CFLAGS
+	LIBUSB10_LIBS=$pkg_cv_LIBUSB10_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_libusb10=yes
+fi
+  if test "$have_libusb10" = "yes"; then
+    CFLAGS="$CFLAGS $LIBUSB10_CFLAGS"
+    USB_LIBS="$USB_LIBS $LIBUSB10_LIBS"
+    HAVE_USB=yes
+
+$as_echo "#define HAVE_LIBUSB_1_0 1" >>confdefs.h
+
+  else
+    LIBUSB10_CFLAGS=
+    LIBUSB10_LIBS=
+  fi
+fi
+
+
+
 
 
 
diff --git a/libticables/trunk/configure.ac b/libticables/trunk/configure.ac
index 01f6c15..c3ba7a0 100644
--- a/libticables/trunk/configure.ac
+++ b/libticables/trunk/configure.ac
@@ -63,25 +63,64 @@ AC_CHECK_TOOL(RC, windres, windres)
 AM_GNU_GETTEXT(external)
 AM_GNU_GETTEXT_VERSION([0.16])
 
+# Call explicitely before using PKG_*
+PKG_PROG_PKG_CONFIG
+
 PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.4.0)
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 
 # USB cable support
 AC_ARG_ENABLE(libusb,
-  AC_HELP_STRING([--disable-libusb], [disable USB support]),
+  AC_HELP_STRING([--disable-libusb], [disable USB support through libusb 0.1.x]),
   [cab_cv_use_libusb=$enableval], [cab_cv_use_libusb=yes])
-AC_CACHE_CHECK([whether to disable USB],
+AC_CACHE_CHECK([whether to enable USB through libusb 0.1.x],
   [cab_cv_use_libusb], [cab_cv_use_libusb=no])
-if test x$cab_cv_use_libusb = xyes; then
-  PKG_CHECK_MODULES(LIBUSB, libusb >= 0.1.10)
-  AC_DEFINE(HAVE_LIBUSB, 1, [Define to 1 to enable libusb support.])
-else
-  LIBUSB_CFLAGS=
-  LIBUSB_LIBS=
+
+AC_ARG_ENABLE(libusb10,
+  AC_HELP_STRING([--enable-libusb10], [enable EXPERIMENTAL USB support through libusb 1.0.x]),
+  [cab_cv_use_libusb10=$enableval], [cab_cv_use_libusb10=no])
+AC_CACHE_CHECK([whether to enable USB through libusb 1.0.x],
+  [cab_cv_use_libusb10], [cab_cv_use_libusb10=no])
+
+AS_IF([test "x$cab_cv_use_libusb" = xyes],
+  AS_IF([test "x$cab_cv_use_libusb10" = xyes],
+    AC_MSG_ERROR([cannot enable both libusb 0.1.x support and libusb 1.0.x support !])
+  )
+)
+
+if test "x$cab_cv_use_libusb" = xyes; then
+  dnl Try libusb-0.1
+  PKG_CHECK_MODULES(LIBUSB, [ libusb >= 0.1.12 ], have_libusb=yes, have_libusb=no)
+  if test "$have_libusb" = "yes"; then
+    CFLAGS="$CFLAGS $LIBUSB_CFLAGS"
+    USB_LIBS="$USB_LIBS $LIBUSB_LIBS"
+    HAVE_USB=yes
+    AC_DEFINE(HAVE_LIBUSB, 1, [Define to 1 to enable libusb 0.1.x support.])
+  else
+    LIBUSB_CFLAGS=
+    LIBUSB_LIBS=
+  fi
 fi
+
+if test "x$cab_cv_use_libusb10" = xyes; then
+  dnl Try libusb-1.0
+  PKG_CHECK_MODULES(LIBUSB10, [ libusb-1.0 >= 1.0.0 ], have_libusb10=yes, have_libusb10=no)
+  if test "$have_libusb10" = "yes"; then
+    CFLAGS="$CFLAGS $LIBUSB10_CFLAGS"
+    USB_LIBS="$USB_LIBS $LIBUSB10_LIBS"
+    HAVE_USB=yes
+    AC_DEFINE(HAVE_LIBUSB_1_0, 1, [Define to 1 to enable EXPERIMENTAL libusb 1.0.x support.])
+  else
+    LIBUSB10_CFLAGS=
+    LIBUSB10_LIBS=
+  fi
+fi
+
 AC_SUBST(LIBUSB_CFLAGS)
 AC_SUBST(LIBUSB_LIBS)
+AC_SUBST(LIBUSB10_CFLAGS)
+AC_SUBST(LIBUSB10_LIBS)
 
 # Checks for header files.
 AC_HEADER_DIRENT
diff --git a/libticables/trunk/docs/Makefile.in b/libticables/trunk/docs/Makefile.in
index 9d88580..24f287e 100644
--- a/libticables/trunk/docs/Makefile.in
+++ b/libticables/trunk/docs/Makefile.in
@@ -98,6 +98,8 @@ LIBINTL = @LIBINTL@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
+LIBUSB10_CFLAGS = @LIBUSB10_CFLAGS@
+LIBUSB10_LIBS = @LIBUSB10_LIBS@
 LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
 LIBUSB_LIBS = @LIBUSB_LIBS@
 LN_S = @LN_S@
diff --git a/libticables/trunk/src/Makefile.am b/libticables/trunk/src/Makefile.am
index f76cbdd..2c827cc 100644
--- a/libticables/trunk/src/Makefile.am
+++ b/libticables/trunk/src/Makefile.am
@@ -12,8 +12,8 @@ libticablesinclude_HEADERS = ticables.h export1.h stdints1.h timeout.h
 # build instructions
 libticables2_la_CPPFLAGS = -I$(top_srcdir)/intl \
 	-DLOCALEDIR=\"$(datadir)/locale\" \
-	@GLIB_CFLAGS@ @LIBUSB_CFLAGS@ -DTICABLES_EXPORTS
-libticables2_la_LIBADD = @GLIB_LIBS@ @LTLIBINTL@ @LIBUSB_LIBS@
+	@GLIB_CFLAGS@ @LIBUSB_CFLAGS@ @LIBUSB10_CFLAGS@ -DTICABLES_EXPORTS
+libticables2_la_LIBADD = @GLIB_LIBS@ @LTLIBINTL@ @LIBUSB_LIBS@ @LIBUSB10_LIBS@
 libticables2_la_LDFLAGS = -no-undefined -version-info @LT_LIBVERSION@
 libticables2_la_SOURCES = *.h \
 	data_log.c \
diff --git a/libticables/trunk/src/Makefile.in b/libticables/trunk/src/Makefile.in
index a00bcbf..5ff0e31 100644
--- a/libticables/trunk/src/Makefile.in
+++ b/libticables/trunk/src/Makefile.in
@@ -203,6 +203,8 @@ LIBINTL = @LIBINTL@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
+LIBUSB10_CFLAGS = @LIBUSB10_CFLAGS@
+LIBUSB10_LIBS = @LIBUSB10_LIBS@
 LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
 LIBUSB_LIBS = @LIBUSB_LIBS@
 LN_S = @LN_S@
@@ -305,9 +307,9 @@ libticablesinclude_HEADERS = ticables.h export1.h stdints1.h timeout.h
 # build instructions
 libticables2_la_CPPFLAGS = -I$(top_srcdir)/intl \
 	-DLOCALEDIR=\"$(datadir)/locale\" \
-	@GLIB_CFLAGS@ @LIBUSB_CFLAGS@ -DTICABLES_EXPORTS
+	@GLIB_CFLAGS@ @LIBUSB_CFLAGS@ @LIBUSB10_CFLAGS@ -DTICABLES_EXPORTS
 
-libticables2_la_LIBADD = @GLIB_LIBS@ @LTLIBINTL@ @LIBUSB_LIBS@
+libticables2_la_LIBADD = @GLIB_LIBS@ @LTLIBINTL@ @LIBUSB_LIBS@ @LIBUSB10_LIBS@
 libticables2_la_LDFLAGS = -no-undefined -version-info @LT_LIBVERSION@ \
 	$(am__append_1)
 libticables2_la_SOURCES = *.h \
diff --git a/libticables/trunk/src/bsd/detect.c b/libticables/trunk/src/bsd/detect.c
index edd0a9b..35306b0 100644
--- a/libticables/trunk/src/bsd/detect.c
+++ b/libticables/trunk/src/bsd/detect.c
@@ -321,7 +321,7 @@ int bsd_check_parport(const char *devname)
 int bsd_check_libusb(void)
 {
 	ticables_info(_("Check for lib-usb support:"));
-#if defined(HAVE_LIBUSB)
+#if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)
 	ticables_info(_("    usb support: available."));
 #else
 	ticables_info(_("    usb support: not compiled."));
diff --git a/libticables/trunk/src/link_usb.c b/libticables/trunk/src/link_usb.c
index 351eca7..ffb6499 100644
--- a/libticables/trunk/src/link_usb.c
+++ b/libticables/trunk/src/link_usb.c
@@ -33,6 +33,8 @@
 
 #ifdef HAVE_LIBUSB
 # include "linux/link_usb.c"
+#elif defined(HAVE_LIBUSB_1_0)
+# include "linux/link_usb1.c"
 #endif
 #ifdef HAVE_LINUX_TICABLE_H
 # include "linux/link_dev.c"
diff --git a/libticables/trunk/src/linux/detect.c b/libticables/trunk/src/linux/detect.c
index 7422f81..50958c0 100644
--- a/libticables/trunk/src/linux/detect.c
+++ b/libticables/trunk/src/linux/detect.c
@@ -401,7 +401,7 @@ int linux_check_parport(const char *devname)
 int linux_check_libusb(void)
 {
 	ticables_info(_("Check for lib-usb support:"));
-#if defined(HAVE_LIBUSB)
+#if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)
 	ticables_info(_("    usb support: available."));
 #else
 	ticables_info(_("    usb support: not compiled."));
diff --git a/libticables/trunk/src/linux/link_dev.c b/libticables/trunk/src/linux/link_dev.c
index 0539d73..af98fc2 100644
--- a/libticables/trunk/src/linux/link_dev.c
+++ b/libticables/trunk/src/linux/link_dev.c
@@ -406,7 +406,7 @@ TIEXPORT1 int TICALL usb_probe_devices2(int **list)
     return 0;
 }
 
-#ifndef HAVE_LIBUSB
+#if !defined(HAVE_LIBUSB) && !defined(HAVE_LIBUSB_1_0)
 TIEXPORT1 int TICALL usb_probe_devices(int **list)
 {
   return usb_probe_devices2(list);
diff --git a/libticables/trunk/src/linux/link_usb.c b/libticables/trunk/src/linux/link_usb.c
index f292fd8..0cfd9ba 100644
--- a/libticables/trunk/src/linux/link_usb.c
+++ b/libticables/trunk/src/linux/link_usb.c
@@ -31,7 +31,7 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-/* TI-GRAPH LINK USB and direct USB cable support (lib-usb) */
+/* TI-GRAPH LINK USB and direct USB cable support (libusb 0.1.x) */
 
 /* 
    Some important remarks... (http://lpg.ticalc.org/prj_usb/index.html)
@@ -73,7 +73,7 @@
 	IOCTL_INTERNAL_USB_RESET_PORT followed by an IOCTL_INTERNAL_USB_CYCLE_PORT.
 	NSpire simply needs an RESET_PORT.
 */
-                                     
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -247,7 +247,7 @@ static const usb_infos tigl_infos[] =
 	{VID_TI, PID_TI89TM,   "TI-89 Titanium Hand-Held",    NULL},
 	{VID_TI, PID_TI84P_SE, "TI-84 Plus Silver Hand-Held", NULL},
 	{VID_TI, PID_NSPIRE,   "TI-Nspire Hand-Held",         NULL},
-	{0,           0,            NULL,                          NULL}
+	{0,      0,            NULL,                          NULL}
 };
 
 // list of devices found 
diff --git a/libticables/trunk/src/linux/link_usb1.c b/libticables/trunk/src/linux/link_usb1.c
new file mode 100644
index 0000000..1ff1841
--- /dev/null
+++ b/libticables/trunk/src/linux/link_usb1.c
@@ -0,0 +1,667 @@
+/* Hey EMACS -*- linux-c -*- */
+/* $Id$ */
+
+/*  libticables2 - link cable library, a part of the TiLP project
+ *  Copyright (c) 1999-2006 Romain Lievin
+ *  Copyright (c) 2001 Julien Blache (original author)
+ *  Copyright (c) 2007 Romain Liévin (libusb-win32 support)
+ *  Copyright (c) 2007 Kevin Kofler (libusb-win32 slv_check support)
+ *  Copyright (c) 2011 Jon Sturm (libusb-1.0 support)
+ *
+ *  Portions lifted from libusb (LGPL):
+ *  Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
+ *  Copyright (C) 2001 Johannes Erdfelt <johannes@erdfelt.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA.
+ */
+
+/* TI-GRAPH LINK USB and direct USB cable support (libusb 1.0.x) */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <libusb-1.0/libusb.h>
+
+#ifndef __WIN32__
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#endif
+
+
+#include "../ticables.h"
+#include "../logging.h"
+#include "../error.h"
+#include "../gettext.h"
+#if defined(__WIN32__)
+#include "../win32/detect.h"
+#elif defined(__BSD__)
+#include "../bsd/detect.h"
+#else
+#include "detect.h"
+#endif
+#include "../timeout.h"
+
+/* Constants */
+
+#define MAX_CABLES   4
+
+#define VID_TI       0x0451     /* Texas Instruments, Inc.            */
+
+#define to           (100 * h->timeout)        // in ms
+
+/* Types */
+
+// device infos
+typedef struct
+{
+	uint16_t    vid;
+	uint16_t    pid;
+	const char* str;
+
+	struct libusb_device *dev;
+} usb_infos;
+
+// list of known devices
+static usb_infos tigl_infos[] =
+{
+	{VID_TI, PID_TIGLUSB,  "TI-GRAPH LINK USB",           NULL},
+	{VID_TI, PID_TI84P,    "TI-84 Plus Hand-Held",        NULL},
+	{VID_TI, PID_TI89TM,   "TI-89 Titanium Hand-Held",    NULL},
+	{VID_TI, PID_TI84P_SE, "TI-84 Plus Silver Hand-Held", NULL},
+	{VID_TI, PID_NSPIRE,   "TI-Nspire Hand-Held",         NULL},
+	{0,      0,            NULL,                          NULL}
+};
+
+// list of devices found
+static usb_infos tigl_devices[MAX_CABLES+1];
+
+// internal structure for holding data
+typedef struct
+{
+	struct libusb_device *device;
+	struct libusb_device_handle *handle;
+
+	int      nBytesRead;
+	uint8_t  rBuf[64];
+	uint8_t* rBufPtr;
+	int      in_endpoint;
+	int      out_endpoint;
+	int      max_ps;
+	int      was_max_ps;
+} usb_struct;
+
+// convenient macros
+#define uDev       (((usb_struct *)(h->priv2))->device)
+#define uHdl       (((usb_struct *)(h->priv2))->handle)
+#define max_ps     (((usb_struct *)(h->priv2))->max_ps)
+#define nBytesRead (((usb_struct *)(h->priv2))->nBytesRead)
+#define rBuf       (((usb_struct *)(h->priv2))->rBuf)
+#define rBufPtr    (((usb_struct *)(h->priv2))->rBufPtr)
+#define uInEnd     (((usb_struct *)(h->priv2))->in_endpoint)
+#define uOutEnd    (((usb_struct *)(h->priv2))->out_endpoint)
+
+/*
+ * Taken from libusb git, will be included in later releases of
+ * libusb-1.0 but as most distros will not be shipping that for a while
+ * this will have to do. ~ Jon 2011/02/08
+ */
+const char* tigl_strerror(enum libusb_error errcode)
+{
+	switch (errcode)
+	{
+		case LIBUSB_SUCCESS:
+			return "Success";
+		case LIBUSB_ERROR_IO:
+			return "Input/output error";
+		case LIBUSB_ERROR_INVALID_PARAM:
+			return "Invalid parameter";
+		case LIBUSB_ERROR_ACCESS:
+			return "Access denied (insufficient permissions)";
+		case LIBUSB_ERROR_NO_DEVICE:
+			return "No such device (it may have been disconnected)";
+		case LIBUSB_ERROR_NOT_FOUND:
+			return "Entity not found";
+		case LIBUSB_ERROR_BUSY:
+			return "Resource busy";
+		case LIBUSB_ERROR_TIMEOUT:
+			return "Operation timed out";
+		case LIBUSB_ERROR_OVERFLOW:
+			return "Overflow";
+		case LIBUSB_ERROR_PIPE:
+			return "Pipe error";
+		case LIBUSB_ERROR_INTERRUPTED:
+			return "System call interrupted (perhaps due to signal)";
+		case LIBUSB_ERROR_NO_MEM:
+			return "Insufficient memory";
+		case LIBUSB_ERROR_NOT_SUPPORTED:
+			return "Operation not supported or unimplemented on this platform";
+		case LIBUSB_ERROR_OTHER:
+			return "Other error";
+	}
+	return "Unknown error";
+}
+
+static const char* tigl_get_product(struct libusb_device *dev)
+{
+	libusb_device_handle *han;
+	int ret;
+	static unsigned char string[64];
+
+	struct libusb_device_descriptor desc;
+	int r = libusb_get_device_descriptor(dev, &desc);
+	if (r < 0)
+	{
+		ticables_error("failed to get device descriptor");
+		return "";
+	}
+
+	if (desc.iProduct)
+	{
+		if (!libusb_open(dev, &han))
+		{
+			ret = libusb_get_string_descriptor_ascii(han, desc.iProduct, string, sizeof(string));
+			libusb_close(han);
+			if (ret > 0)
+			{
+				return (const char *) string;
+			}
+			else
+			{
+				ticables_warning("libusb_get_string_descriptor_ascii (%s).\n", tigl_strerror(ret));
+				return "";
+			}
+		}
+		else
+		{
+			return "";
+		}
+	}
+	return string;
+}
+
+static int tigl_find(void)
+{
+	// discover devices
+	libusb_device **list;
+	ssize_t cnt = libusb_get_device_list(NULL, &list);
+	ssize_t i = 0;
+	int j = 0;
+	int k;
+
+	if (cnt <= 0)
+	{
+		return 0;
+	}
+
+	for (i = 0; i < cnt; i++)
+	{
+		libusb_device *device = list[i];
+		struct libusb_device_descriptor desc;
+		int r = libusb_get_device_descriptor(device, &desc);
+		if (r < 0)
+		{
+			fprintf(stderr, "failed to get device descriptor");
+			return r;
+		}
+		if ((desc.idVendor == VID_TI))
+		{
+			for(k = 0; k < (int)(sizeof(tigl_infos) / sizeof(usb_infos)); k++)
+			{
+				if(desc.idProduct == tigl_infos[k].pid)
+				{
+					ticables_info(_(" found %s on #%i, version <%x.%02x>\n"),
+						      tigl_get_product(device), j+1,
+						      desc.bcdDevice >> 8,
+						      desc.bcdDevice & 0xff);
+
+					memcpy(&tigl_devices[j], &tigl_infos[k], sizeof(usb_infos));
+					tigl_devices[j++].dev = device;
+				}
+			}
+		}
+	}
+	return j;
+}
+
+static int tigl_enum(void)
+{
+	int ret = 0;
+
+	/* find all TI products on all ports */
+	ret = tigl_find();
+	if (ret == 0)
+	{
+		ticables_warning(_(" no devices found!\n"));
+		return ERR_LIBUSB_OPEN;
+	}
+
+	return 0;
+}
+
+static int tigl_open(int id, libusb_device_handle ** udh)
+{
+	int ret;
+
+	tigl_enum();
+
+	if(tigl_devices[id].dev == NULL)
+	{
+		return ERR_LIBUSB_OPEN;
+	}
+
+	if (!libusb_open(tigl_devices[id].dev, udh))
+	{
+		/* only one configuration: #1 */
+		ret = libusb_set_configuration(*udh, 1);
+		if (ret)
+		{
+			ticables_warning("libusb_set_configuration (%s).\n", tigl_strerror(ret));
+		}
+
+		/* configuration #1, interface #0 */
+		ret = libusb_claim_interface(*udh, 0);
+		if (ret)
+		{
+			ticables_warning("libusb_claim_interface (%s).\n", tigl_strerror(ret));
+			return ERR_LIBUSB_CLAIM;
+		}
+
+		return 0;
+	}
+	else
+	{
+		return ERR_LIBUSB_OPEN;
+	}
+
+	return 0;
+}
+
+static int tigl_close(libusb_device_handle **udh)
+{
+	libusb_release_interface(*udh, 0);
+	libusb_close(*udh);
+	*udh = NULL;
+
+	return 0;
+}
+
+static int tigl_reset(CableHandle *h)
+{
+	int ret;
+
+	// Reset out pipe
+	ret = libusb_clear_halt(uHdl, uOutEnd);
+	if (ret)
+	{
+		ticables_warning("libusb_clear_halt (%s).\n", tigl_strerror(ret));
+	}
+
+	// Reset in pipe
+	ret = libusb_clear_halt(uHdl, uInEnd);
+	if (ret)
+	{
+		ticables_warning("libusb_clear_halt (%s).\n", tigl_strerror(ret));
+	}
+
+	return 0;
+}
+
+/* API */
+
+static int slv_prepare(CableHandle *h)
+{
+	char str[64];
+
+#if defined(__WIN32__)
+	TRYC(win32_check_libusb());
+#elif defined(__BSD__)
+	TRYC(bsd_check_libusb());
+#else
+	TRYC(linux_check_libusb());
+#endif
+
+	if(h->port >= MAX_CABLES)
+	{
+		return ERR_ILLEGAL_ARG;
+	}
+
+	h->address = h->port-1;
+	sprintf(str, "TiglUsb #%i", h->port);
+	h->device = strdup(str);
+	h->priv2 = (usb_struct *)calloc(1, sizeof(usb_struct));
+
+	return 0;
+}
+
+static int slv_open(CableHandle *h)
+{
+	int i;
+	struct libusb_config_descriptor *config;
+	const struct libusb_interface *interface_;
+	const struct libusb_interface_descriptor *interface;
+	const struct libusb_endpoint_descriptor *endpoint;
+
+	// open device
+	TRYC(tigl_open(h->address, &uHdl));
+	uDev = tigl_devices[h->address].dev;
+	uInEnd  = 0x81;
+	uOutEnd = 0x02;
+
+	// get max packet size
+	libusb_get_active_config_descriptor(uDev, &config);
+	interface_ = &(config->interface[0]);
+	interface = &(interface_->altsetting[0]);
+	endpoint = &(interface->endpoint[0]);
+	max_ps = endpoint->wMaxPacketSize;
+
+	// Enumerate endpoints.
+	for (i = 0; i < interface->bNumEndpoints; i++)
+	{
+		endpoint = &(interface->endpoint[i]);
+		if ((endpoint->bmAttributes & LIBUSB_TRANSFER_TYPE_BULK) == LIBUSB_TRANSFER_TYPE_BULK)
+		{
+			if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN)
+			{
+				if (endpoint->bEndpointAddress != 0x83) // Some Nspire OS use that seemingly bogus endpoint.
+				{
+					uInEnd = endpoint->bEndpointAddress;
+					ticables_info("found bulk in endpoint 0x%02X\n", uInEnd);
+				}
+				else
+				{
+					ticables_info("XXX: swallowing bulk in endpoint 0x83, advertised by Nspire (CAS and non-CAS) 1.x but seemingly not working\n");
+				}
+			}
+			else
+			{
+				uOutEnd = endpoint->bEndpointAddress;
+				ticables_info("found bulk out endpoint 0x%02X\n", uOutEnd);
+			}
+		}
+	}
+	nBytesRead = 0;
+
+	return 0;
+}
+
+static int slv_close(CableHandle *h)
+{
+	if (uHdl != NULL)
+	{
+		tigl_close(&uHdl);
+	}
+
+	uDev = NULL;
+
+	free(h->priv2);
+	h->priv2 = NULL;
+
+	return 0;
+}
+
+static int slv_reset(CableHandle *h)
+{
+	int ret = 0;
+
+	/* Reset both endpoints (send an URB_FUNCTION_RESET_PIPE) */
+	TRYC(tigl_reset(h));
+
+	/* Reset USB port (send an IOCTL_INTERNAL_USB_RESET_PORT) */
+	ret = libusb_reset_device(uHdl);
+	if (ret != 0)
+	{
+		ticables_warning("libusb_device_reset (%s).\n", tigl_strerror(ret));
+		return ERR_LIBUSB_RESET;
+	}
+	else
+	{
+		// lib-usb doc: after calling usb_reset, the device will need to re-enumerate
+		// and thusly, requires you to find the new device and open a new handle. The
+		// handle used to call usb_reset will no longer work.
+#ifdef __WIN32__
+		Sleep(500);
+#else
+		usleep(500000);
+#endif
+		TRYC(slv_close(h));
+
+		h->priv2 = (usb_struct *)calloc(1, sizeof(usb_struct));
+		TRYC(slv_open(h));
+	}
+
+	return 0;
+}
+
+// convenient function which send one or more bytes
+static int send_block(CableHandle *h, uint8_t *data, int length)
+{
+	int ret, tmp, tmp2;
+
+	ret = libusb_bulk_transfer(uHdl, uOutEnd, (unsigned char*)data, length, &tmp, to);
+
+	if ((tigl_devices[h->port].pid == PID_NSPIRE) && (tmp % max_ps == 0) && !ret)
+	{
+		ticables_info("XXX triggering an extra bulk write for buggy Nspire OS versions");
+		ret = libusb_bulk_transfer(uHdl, uOutEnd, (unsigned char*)data, 0, &tmp2, to);
+	}
+
+	if (ret == LIBUSB_ERROR_TIMEOUT)
+	{
+		ticables_warning("libusb_bulk_transfer (%s).\n", tigl_strerror(ret));
+		return ERR_WRITE_TIMEOUT;
+	}
+	else if(ret != 0)
+	{
+		ticables_warning("libusb_bulk_transfer (%s).\n", tigl_strerror(ret));
+		return ERR_WRITE_ERROR;
+	}
+
+	return 0;
+}
+
+static int slv_put(CableHandle* h, uint8_t *data, uint32_t len)
+{
+	return send_block(h, data, len);
+}
+
+static int slv_get_(CableHandle *h, uint8_t *data)
+{
+	int ret = 0;
+	int len = 0;
+	int tmp;
+	tiTIME clk;
+
+	/* Read up to 32/64 bytes and store them in a buffer for subsequent accesses */
+	if (nBytesRead <= 0)
+	{
+		TO_START(clk);
+		do
+		{
+			ret = libusb_bulk_transfer(uHdl, uInEnd, (unsigned char*)rBuf, max_ps, &len, 0);
+		}
+		while(!len && !ret);
+
+		if (tigl_devices[h->port].pid == PID_NSPIRE && (len % max_ps) == 0 && !ret)
+		{
+			ticables_info("XXX triggering an extra bulk read for buggy Nspire OS versions");
+			ret = libusb_bulk_transfer(uHdl, uInEnd, (unsigned char*)data, 0, &tmp, to);
+		}
+
+		if(ret == LIBUSB_ERROR_TIMEOUT)
+		{
+			ticables_warning("libusb_bulk_transfer (%s).\n", tigl_strerror(ret));
+			nBytesRead = 0;
+			return ERR_READ_TIMEOUT;
+		}
+		else if(ret != 0)
+		{
+			ticables_warning("libusb_bulk_transfer (%s).\n", tigl_strerror(ret));
+			nBytesRead = 0;
+			return ERR_READ_ERROR;
+		}
+
+		nBytesRead = len;
+		rBufPtr = rBuf;
+	}
+
+	*data = *rBufPtr++;
+	nBytesRead--;
+
+	return 0;
+}
+
+static int slv_get(CableHandle* h, uint8_t *data, uint32_t len)
+{
+	int i=0;
+
+	/* we can't do that in any other way because slv_get_ can returns
+	 * 1, 2, ..., len bytes.
+	 *
+	 * XXX But we know how much was actually recived can't we just try
+	 * again if its less than we expected rather than this mess, whatever
+	 * the point of it was?
+	 */
+	for(i = 0; i < (int)len; i++)
+	{
+		TRYC(slv_get_(h, data+i));
+	}
+
+	return 0;
+}
+
+static int slv_probe(CableHandle *h)
+{
+	int i;
+
+	TRYC(tigl_enum());
+
+	for(i = 0; i < MAX_CABLES; i++)
+	{
+		if(tigl_devices[h->address].pid == PID_TIGLUSB)
+		{
+			return 0;
+		}
+	}
+
+	return ERR_PROBE_FAILED;
+}
+
+static int raw_probe(CableHandle *h)
+{
+	int i;
+
+	TRYC(tigl_enum());
+
+	for(i = 0; i < MAX_CABLES; i++)
+	{
+		if (tigl_devices[h->address].pid == PID_TI89TM ||
+		    tigl_devices[h->address].pid == PID_TI84P ||
+		    tigl_devices[h->address].pid == PID_TI84P_SE ||
+		    tigl_devices[h->address].pid == PID_NSPIRE)
+		{
+			return 0;
+		}
+	}
+
+	return ERR_PROBE_FAILED;
+}
+
+static int slv_check(CableHandle *h, int *status)
+{
+	// We are using the syncronous api for now so transfers finish right away.
+	return 0;
+}
+
+static int slv_set_red_wire(CableHandle *h, int b)
+{
+	return 0;
+}
+
+static int slv_set_white_wire(CableHandle *h, int b)
+{
+	return 0;
+}
+
+static int slv_get_red_wire(CableHandle *h)
+{
+	return 1;
+}
+
+static int slv_get_white_wire(CableHandle *h)
+{
+	return 1;
+}
+
+const CableFncts cable_slv =
+{
+	CABLE_SLV,
+	"SLV",
+	N_("SilverLink"),
+	N_("SilverLink (TI-GRAPH LINK USB) cable"),
+	0,
+	&slv_prepare,
+	&slv_open, &slv_close, &slv_reset, &slv_probe, NULL,
+	&slv_put, &slv_get, &slv_check,
+	&slv_set_red_wire, &slv_set_white_wire,
+	&slv_get_red_wire, &slv_get_white_wire,
+};
+
+const CableFncts cable_raw =
+{
+	CABLE_USB,
+	"USB",
+	N_("DirectLink"),
+	N_("DirectLink (DIRECT USB) cable"),
+	0,
+	&slv_prepare,
+	&slv_open, &slv_close, &slv_reset, &raw_probe, NULL,
+	&slv_put, &slv_get, &slv_check,
+	&slv_set_red_wire, &slv_set_white_wire,
+	&slv_get_red_wire, &slv_get_white_wire,
+};
+
+//=======================
+
+TIEXPORT1 int TICALL usb_probe_devices1(int **list);
+
+TIEXPORT1 int TICALL usb_probe_devices(int **list)
+{
+	return usb_probe_devices1(list);
+}
+
+// returns number of devices and list of PIDs (dynamically allocated)
+TIEXPORT1 int TICALL usb_probe_devices1(int **list)
+{
+	int i;
+
+	TRYC(tigl_enum());
+
+	*list = (int *)calloc(MAX_CABLES+1, sizeof(int));
+	for(i = 0; i < MAX_CABLES; i++)
+	{
+		(*list)[i] = tigl_devices[i].pid;
+	}
+
+	return 0;
+}
diff --git a/libticables/trunk/src/probe.c b/libticables/trunk/src/probe.c
index 7ede314..1a3cbbc 100644
--- a/libticables/trunk/src/probe.c
+++ b/libticables/trunk/src/probe.c
@@ -168,9 +168,9 @@ TIEXPORT1 int TICALL ticables_is_usb_enabled(void)
 {
 #if defined(__WIN32__)
 	return !win32_check_libusb();
-#elif defined(__LINUX__) && defined(HAVE_LIBUSB)
+#elif defined(__LINUX__) && (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0))
 	return !linux_check_libusb();
-#elif defined(HAVE_LIBUSB)
+#elif (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0))
 	return 1;
 #else
 	return 0;
@@ -194,7 +194,7 @@ extern int usb_probe_devices(int **list);
  **/
 TIEXPORT1 int TICALL ticables_get_usb_devices(int **list, int *len)
 {
-#if defined(__WIN32__) || defined(HAVE_LIBUSB)
+#if defined(__WIN32__) || (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0))
 	int i, *p;
 	int ret = 0;
 
diff --git a/libticables/trunk/src/ticables.c b/libticables/trunk/src/ticables.c
index 57de980..a4221d7 100644
--- a/libticables/trunk/src/ticables.c
+++ b/libticables/trunk/src/ticables.c
@@ -39,6 +39,8 @@
 # include "./win32/usb.h"
 #elif defined(HAVE_LIBUSB)
 # include <usb.h>
+#elif defined(HAVE_LIBUSB_1_0)
+# include <libusb-1.0/libusb.h>
 #endif
 
 #include "gettext.h"
@@ -64,10 +66,10 @@ static CableFncts const *const cables[] =
 #if !defined(NO_CABLE_PAR) && (defined(HAVE_LINUX_PARPORT_H) || defined(__WIN32__))
 	&cable_par,
 #endif
-#if !defined(NO_CABLE_SLV) && (defined(HAVE_LIBUSB) || defined(__WIN32__))
+#if !defined(NO_CABLE_SLV) && (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0) || defined(__WIN32__))
 	&cable_slv,
 #endif
-#if !defined(NO_CABLE_SLV) && (defined(HAVE_LIBUSB) || defined(__WIN32__))
+#if !defined(NO_CABLE_SLV) && (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0) || defined(__WIN32__))
 	&cable_raw,
 #endif
 #ifndef NO_CABLE_VTI
@@ -99,56 +101,67 @@ int ticables_instance = 0;	// counts # of instances
  **/
 TIEXPORT1 int TICALL ticables_library_init(void)
 {
-    char locale_dir[65536];
+	char locale_dir[65536];
+#if (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB10))
+	int ret;
+#endif
 
 #ifdef __WIN32__
-  	HANDLE hDll;
-  	int i;
+	HANDLE hDll;
+	int i;
 
 	hDll = GetModuleHandle("libticables2-4.dll");
-  	GetModuleFileName(hDll, locale_dir, 65535);
+	GetModuleFileName(hDll, locale_dir, 65535);
 
-  	for (i = strlen(locale_dir); i >= 0; i--) 
+	for (i = strlen(locale_dir); i >= 0; i--)
 	{
-    	if (locale_dir[i] == '\\')
-      		break;
-  	}
-  	locale_dir[i] = '\0';
+		if (locale_dir[i] == '\\')
+		{
+			break;
+		}
+	}
+	locale_dir[i] = '\0';
 
 #ifdef __MINGW32__
-   strcat(locale_dir, "\\..\\share\\locale");
+	strcat(locale_dir, "\\..\\share\\locale");
 #else
-   strcat(locale_dir, "\\locale");
+	strcat(locale_dir, "\\locale");
 #endif
 #else
 	strcpy(locale_dir, LOCALEDIR);
 #endif
 
 	if (ticables_instance)
+	{
 		return (++ticables_instance);
+	}
 	ticables_info(_("ticables library version %s"), libticables2_VERSION);
-  	errno = 0;
+	errno = 0;
 
 #if defined(ENABLE_NLS)
-  	ticables_info("setlocale: %s", setlocale(LC_ALL, ""));
-  	ticables_info("bindtextdomain: %s", bindtextdomain(PACKAGE, locale_dir));
-  	//bind_textdomain_codeset(PACKAGE, "UTF-8"/*"ISO-8859-15"*/);
-  	ticables_info("textdomain: %s", textdomain(PACKAGE));
+	ticables_info("setlocale: %s", setlocale(LC_ALL, ""));
+	ticables_info("bindtextdomain: %s", bindtextdomain(PACKAGE, locale_dir));
+	//bind_textdomain_codeset(PACKAGE, "UTF-8"/*"ISO-8859-15"*/);
+	ticables_info("textdomain: %s", textdomain(PACKAGE));
 #endif
 #ifdef __LINUX__
 	{
-	    struct utsname buf;
-	    
-	    uname(&buf);
-	    ticables_info("kernel: %s", buf.release);
+		struct utsname buf;
+
+		uname(&buf);
+		ticables_info("kernel: %s", buf.release);
 	}
 #endif
 #if defined(HAVE_LIBUSB)
 	/* init the libusb */
 	usb_init();
+#elif defined(HAVE_LIBUSB_1_0)
+	/* init the libusb */
+	libusb_init(NULL);
+	libusb_set_debug(NULL, 3);
 #endif
 
-  	return (++ticables_instance);
+	return (++ticables_instance);
 }
 
 
@@ -162,7 +175,12 @@ TIEXPORT1 int TICALL ticables_library_init(void)
 TIEXPORT1 int
 TICALL ticables_library_exit(void)
 {
-  	return (--ticables_instance);
+#if defined(HAVE_LIBUSB)
+	// No exit function for libusb 0.1.x.
+#elif defined(HAVE_LIBUSB_1_0)
+	libusb_exit(NULL); // XXX NULL ?
+#endif
+	return (--ticables_instance);
 }
 
 /***********/
@@ -204,14 +222,18 @@ TIEXPORT1 CableHandle* TICALL ticables_handle_new(CableModel model, CablePort po
 	handle->timeout = DFLT_TIMEOUT;
 
 	for(i = 0; cables[i]; i++)
+	{
 		if(cables[i]->model == (const int)model)
 		{
 			handle->cable = (CableFncts *)cables[i];
 			break;
 		}
+	}
 
 	if(handle->cable == NULL)
+	{
 		return NULL;
+	}
 
 	return handle;
 }
@@ -228,23 +250,17 @@ TIEXPORT1 int TICALL ticables_handle_del(CableHandle* handle)
 {
 	if(handle)
 	{
-		if(handle->priv2)
-		{
-			free(handle->priv2);
-			handle->priv2 = NULL;
-		}
+		free(handle->priv2);
+		handle->priv2 = NULL;
 
-		if(handle->device)
-		{
-			free(handle->device);
-			handle->device = NULL;
-		}
+		free(handle->device);
+		handle->device = NULL;
 
-    	free(handle);
-	    handle = NULL;
+		free(handle);
+		handle = NULL;
 	}
 
-    return 0;
+	return 0;
 }
 
 /**
@@ -266,13 +282,19 @@ TIEXPORT1 int TICALL ticables_options_set_timeout(CableHandle* handle, int timeo
 		const CableFncts *cable = handle->cable;
 
 		if(!handle->open)
+		{
 			return -1;
+		}
 		if(handle->busy)
+		{
 			return ERR_BUSY;
+		}
 
 		handle->busy = 1;
 		if(cable->timeout)
+		{
 			cable->timeout(handle);
+		}
 		handle->busy = 0;
 	}
 
diff --git a/libticables/trunk/src/win32/dha/Makefile.in b/libticables/trunk/src/win32/dha/Makefile.in
index 6a7937e..414e175 100644
--- a/libticables/trunk/src/win32/dha/Makefile.in
+++ b/libticables/trunk/src/win32/dha/Makefile.in
@@ -169,6 +169,8 @@ LIBINTL = @LIBINTL@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
+LIBUSB10_CFLAGS = @LIBUSB10_CFLAGS@
+LIBUSB10_LIBS = @LIBUSB10_LIBS@
 LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
 LIBUSB_LIBS = @LIBUSB_LIBS@
 LN_S = @LN_S@
diff --git a/libticables/trunk/src/win64/rwp/Makefile.in b/libticables/trunk/src/win64/rwp/Makefile.in
index 4a4f240..8123b75 100644
--- a/libticables/trunk/src/win64/rwp/Makefile.in
+++ b/libticables/trunk/src/win64/rwp/Makefile.in
@@ -169,6 +169,8 @@ LIBINTL = @LIBINTL@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
+LIBUSB10_CFLAGS = @LIBUSB10_CFLAGS@
+LIBUSB10_LIBS = @LIBUSB10_LIBS@
 LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
 LIBUSB_LIBS = @LIBUSB_LIBS@
 LN_S = @LN_S@
diff --git a/libticables/trunk/tests/Makefile.in b/libticables/trunk/tests/Makefile.in
index fa076bb..587e799 100644
--- a/libticables/trunk/tests/Makefile.in
+++ b/libticables/trunk/tests/Makefile.in
@@ -119,6 +119,8 @@ LIBINTL = @LIBINTL@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
+LIBUSB10_CFLAGS = @LIBUSB10_CFLAGS@
+LIBUSB10_LIBS = @LIBUSB10_LIBS@
 LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
 LIBUSB_LIBS = @LIBUSB_LIBS@
 LN_S = @LN_S@
-- 
1.7.4.15.g7811d

