diff -uNr libusb-1.0.19/Makefile.in libusb-1.0.19p/Makefile.in
--- libusb-1.0.19/Makefile.in	2016-06-05 04:23:20 -0500
+++ libusb-1.0.19p/Makefile.in	2016-06-05 05:40:35 -0500
@@ -282,6 +282,7 @@
 OS_NETBSD = @OS_NETBSD@
 OS_OPENBSD = @OS_OPENBSD@
 OS_WINDOWS = @OS_WINDOWS@
+OS_AIX = @OS_AIX@
 OTOOL = @OTOOL@
 OTOOL64 = @OTOOL64@
 PACKAGE = @PACKAGE@
diff -uNr libusb-1.0.19/config.h.in libusb-1.0.19p/config.h.in
--- libusb-1.0.19/config.h.in	2016-06-05 04:23:25 -0500
+++ libusb-1.0.19p/config.h.in	2016-06-05 05:40:35 -0500
@@ -97,6 +97,9 @@
 /* Windows backend */
 #undef OS_WINDOWS
 
+/* AIX backend */
+#undef OS_AIX
+
 /* Name of package */
 #undef PACKAGE
 
diff -uNr libusb-1.0.19/configure libusb-1.0.19p/configure
--- libusb-1.0.19/configure	2016-06-05 04:24:57 -0500
+++ libusb-1.0.19p/configure	2016-06-05 05:40:35 -0500
@@ -650,6 +650,8 @@
 CREATE_IMPORT_LIB_TRUE
 THREADS_POSIX_FALSE
 THREADS_POSIX_TRUE
+OS_AIX_FALSE
+OS_AIX_TRUE
 OS_WINDOWS_FALSE
 OS_WINDOWS_TRUE
 OS_NETBSD_FALSE
@@ -660,6 +662,7 @@
 OS_DARWIN_TRUE
 OS_LINUX_FALSE
 OS_LINUX_TRUE
+OS_AIX
 OS_WINDOWS
 OS_NETBSD
 OS_OPENBSD
@@ -11953,6 +11956,13 @@
 	backend="windows"
 	threads="posix"
 	;;
+*-ibm-aix*)
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: Cygwin (using AIX backend)" >&5
+$as_echo "Cygwin (using AIX backend)" >&6; }
+       backend="aix"
+       threads="posix"
+       have_syslog="yes"
+       ;;
 *)
 	as_fn_error $? "unsupported operating system" "$LINENO" 5
 esac
@@ -12250,6 +12260,34 @@
 $as_echo "#define POLL_NFDS_TYPE unsigned int" >>confdefs.h
 
 	;;
+
+aix)
+
+$as_echo "#define OS_AIX 1" >>confdefs.h
+
+
+       THREAD_CFLAGS="-pthread"
+       #LIBS="-pthread -lodm -lcfg"
+       LTLDFLAGS="${LTLDFLAGS} -lpthread -lodm -lcfg  "
+       for ac_header in poll.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "poll.h" "ac_cv_header_poll_h" "$ac_includes_default"
+if test "x$ac_cv_header_poll_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_POLL_H 1
+_ACEOF
+
+fi
+
+done
+
+
+$as_echo "#define USE_SYSTEM_LOGGING_FACILITY 1" >>confdefs.h
+
+
+$as_echo "#define POLL_NFDS_TYPE unsigned int" >>confdefs.h
+
+       ;;
 esac
 
 
@@ -12294,6 +12332,14 @@
   OS_WINDOWS_FALSE=
 fi
 
+ if test "x$backend" = xaix; then
+  OS_AIX_TRUE=
+  OS_AIX_FALSE='#'
+else
+  OS_AIX_TRUE='#'
+  OS_AIX_FALSE=
+fi
+
  if test "x$threads" = xposix; then
   THREADS_POSIX_TRUE=
   THREADS_POSIX_FALSE='#'
@@ -12591,7 +12637,7 @@
 done
 
 
-AM_CFLAGS="${AM_CFLAGS} -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
+#AM_CFLAGS="${AM_CFLAGS} -std=gnu99 ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
 
 
 
@@ -12767,6 +12813,10 @@
   as_fn_error $? "conditional \"OS_WINDOWS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${OS_AIX_TRUE}" && test -z "${OS_AIX_FALSE}"; then
+  as_fn_error $? "conditional \"OS_AIX\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${THREADS_POSIX_TRUE}" && test -z "${THREADS_POSIX_FALSE}"; then
   as_fn_error $? "conditional \"THREADS_POSIX\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff -uNr libusb-1.0.19/configure.ac libusb-1.0.19p/configure.ac
--- libusb-1.0.19/configure.ac	2016-06-05 04:24:50 -0500
+++ libusb-1.0.19p/configure.ac	2016-06-05 05:40:35 -0500
@@ -89,6 +89,12 @@
 	backend="windows"
 	threads="posix"
 	;;
+*-ibm-aix*)
+       AC_MSG_RESULT([Cygwin (using AIX backend)])
+       backend="aix"
+       threads="posix"
+       have_syslog="yes"
+       ;;
 *)
 	AC_MSG_ERROR([unsupported operating system])
 esac
@@ -169,6 +175,17 @@
 	LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
 	AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
 	;;
+
+aix)
+       AC_DEFINE(OS_AIX, 1, [AIX backend])
+       AC_SUBST(OS_AIX)
+       THREAD_CFLAGS="-pthread"
+       #LIBS="-pthread -lodm -lcfg"
+       LTLDFLAGS="${LTLDFLAGS} -lpthread -lodm -lcfg  "
+       AC_CHECK_HEADERS([poll.h])
+       AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [AIX Sys Log])
+       AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
+       ;;
 esac
 
 AC_SUBST(LIBS)
@@ -178,6 +195,7 @@
 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
 AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
+AM_CONDITIONAL(OS_AIX, test "x$backend" = xaix)
 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
 AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
 AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
@@ -276,7 +294,7 @@
 saved_cflags="$CFLAGS"
 CFLAGS="$CFLAGS -Wno-pointer-sign"
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
-	nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
+   nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
 CFLAGS="$saved_cflags"
 
 # sigaction not available on MinGW
@@ -288,7 +306,7 @@
 AC_CHECK_FUNCS(gettimeofday)
 AC_CHECK_HEADERS([signal.h])
 
-AM_CFLAGS="${AM_CFLAGS} -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
+#AM_CFLAGS="${AM_CFLAGS} -std=gnu99 ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
 
 AC_SUBST(AM_CFLAGS)
 AC_SUBST(LTLDFLAGS)
diff -uNr libusb-1.0.19/examples/xusb.c libusb-1.0.19p/examples/xusb.c
--- libusb-1.0.19/examples/xusb.c	2016-06-05 04:25:32 -0500
+++ libusb-1.0.19p/examples/xusb.c	2016-06-05 05:40:35 -0500
@@ -57,6 +57,17 @@
 static bool extra_info = false;
 static bool force_device_request = false;	// For WCID descriptor queries
 static const char* binary_name = NULL;
+#if defined (_AIX)
+
+#define USBREV32(w)    ((uint32_t) (                         \
+                           (((uint32_t)(w)>>24) & 0x000000ff)  | \
+                           (((uint32_t)(w)>> 8) & 0x0000ff00)  | \
+                           (((uint32_t)(w)<< 8) & 0x00ff0000)  | \
+                           (((uint32_t)(w)<<24) & 0xff000000)    \
+                           ))
+#endif
+
+
 
 static int perr(char const *format, ...)
 {
@@ -77,7 +88,7 @@
 
 #define RETRY_MAX                     5
 #define REQUEST_SENSE_LENGTH          0x12
-#define INQUIRY_LENGTH                0x24
+#define INQUIRY_LENGTH                0xFF
 #define READ_CAPACITY_LENGTH          0x08
 
 // HID Class-Specific Requests values. See section 7.2 of the HID specifications
@@ -344,6 +355,9 @@
 	*ret_tag = tag;
 	cbw.dCBWTag = tag++;
 	cbw.dCBWDataTransferLength = data_length;
+        #if defined(_AIX)
+	cbw.dCBWDataTransferLength = USBREV32(data_length);
+        #endif
 	cbw.bmCBWFlags = direction;
 	cbw.bCBWLUN = lun;
 	// Subclass is 1 or 6 => cdb_len
@@ -364,7 +378,6 @@
 		return -1;
 	}
 
-	printf("   sent %d CDB bytes\n", cdb_len);
 	return 0;
 }
 
@@ -397,9 +410,10 @@
 		return -1;
 	}
 	// For this test, we ignore the dCSWSignature check for validity...
-	printf("   Mass Storage Status: %02X (%s)\n", csw.bCSWStatus, csw.bCSWStatus?"FAILED":"Success");
 	if (csw.dCSWTag != expected_tag)
 		return -1;
+
+
 	if (csw.bCSWStatus) {
 		// REQUEST SENSE is appropriate only if bCSWStatus is 1, meaning that the
 		// command failed somehow.  Larger values (2 in particular) mean that
@@ -532,7 +546,10 @@
 	cdb[8] = 0x01;	// 1 block
 
 	send_mass_storage_command(handle, endpoint_out, lun, cdb, LIBUSB_ENDPOINT_IN, block_size, &expected_tag);
-	libusb_bulk_transfer(handle, endpoint_in, data, block_size, &size, 5000);
+	r = libusb_bulk_transfer(handle, endpoint_in, data, block_size, &size, 5000);
+        if (r == LIBUSB_ERROR_PIPE) {
+                        libusb_clear_halt(handle, endpoint_in);
+         }
 	printf("   READ: received %d bytes\n", size);
 	if (get_mass_storage_status(handle, endpoint_in, expected_tag) == -2) {
 		get_sense(handle, endpoint_in, endpoint_out);
@@ -931,6 +948,7 @@
 	}
 	// Read the OS String Descriptor
 	if (libusb_get_string_descriptor_ascii(handle, 0xEE, (unsigned char*)string, 128) >= 0) {
+
 		printf("   String (0x%02X): \"%s\"\n", 0xEE, string);
 		// If this is a Microsoft OS String Descriptor,
 		// attempt to read the WinUSB extended Feature Descriptors
@@ -988,7 +1006,7 @@
 	if (((uint8_t*)&endian_test)[0] == 0xBE) {
 		printf("Despite their natural superiority for end users, big endian\n"
 			"CPUs are not supported with this program, sorry.\n");
-		return 0;
+		/*return 0;*/
 	}
 
 	if (argc >= 2) {
diff -uNr libusb-1.0.19/libusb/Makefile.am libusb-1.0.19p/libusb/Makefile.am
--- libusb-1.0.19/libusb/Makefile.am	2016-03-04 08:10:42 -0600
+++ libusb-1.0.19p/libusb/Makefile.am	2016-06-05 05:40:35 -0500
@@ -11,9 +11,10 @@
 NETBSD_USB_SRC = os/netbsd_usb.c
 WINDOWS_USB_SRC = os/poll_windows.c os/windows_usb.c libusb-1.0.rc libusb-1.0.def
 WINCE_USB_SRC = os/wince_usb.c os/wince_usb.h
+AIX_USB_SRC = os/aix_usb.c os/aix_usb.h
 
 EXTRA_DIST = $(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) $(OPENBSD_USB_SRC) \
-	$(NETBSD_USB_SRC) $(WINDOWS_USB_SRC) $(WINCE_USB_SRC) \
+	$(NETBSD_USB_SRC) $(WINDOWS_USB_SRC) $(WINCE_USB_SRC) $(AIX_USB_SRC)\
 	$(POSIX_POLL_SRC) \
 	os/threads_posix.c os/threads_windows.c \
 	os/linux_udev.c os/linux_netlink.c
@@ -39,6 +40,10 @@
 OS_SRC = $(OPENBSD_USB_SRC) $(POSIX_POLL_SRC)
 endif
 
+if OS_AIX
+OS_SRC = $(AIX_USB_SRC) $(POSIX_POLL_SRC)
+endif
+
 if OS_NETBSD
 OS_SRC = $(NETBSD_USB_SRC) $(POSIX_POLL_SRC)
 endif
diff -uNr libusb-1.0.19/libusb/Makefile.in libusb-1.0.19p/libusb/Makefile.in
--- libusb-1.0.19/libusb/Makefile.in	2016-03-04 08:10:48 -0600
+++ libusb-1.0.19p/libusb/Makefile.in	2016-06-05 05:40:35 -0500
@@ -125,10 +125,10 @@
 libusb_1_0_la_LIBADD =
 am__libusb_1_0_la_SOURCES_DIST = libusbi.h core.c descriptor.c io.c \
 	strerror.c sync.c os/linux_usbfs.h os/darwin_usb.h \
-	os/windows_usb.h os/windows_common.h hotplug.h hotplug.c \
+	os/windows_usb.h os/windows_common.h os/aix_usb.h hotplug.h hotplug.c \
 	os/threads_windows.h os/threads_windows.c os/threads_posix.h \
 	os/threads_posix.c os/darwin_usb.c os/poll_posix.c \
-	os/linux_usbfs.c os/linux_netlink.c os/linux_udev.c \
+	os/linux_usbfs.c os/linux_netlink.c os/linux_udev.c os/aix_usb.c \
 	os/netbsd_usb.c os/openbsd_usb.c os/poll_windows.c \
 	os/windows_usb.c libusb-1.0.rc libusb-1.0.def os/poll_posix.h \
 	os/poll_windows.h
@@ -141,6 +141,7 @@
 am__objects_4 = os/libusb_1_0_la-linux_usbfs.lo
 am__objects_5 = os/libusb_1_0_la-netbsd_usb.lo
 am__objects_6 = os/libusb_1_0_la-openbsd_usb.lo
+am__objects_9 = os/libusb_1_0_la-aix_usb.lo
 am__objects_7 = os/libusb_1_0_la-poll_windows.lo \
 	os/libusb_1_0_la-windows_usb.lo libusb-1.0.lo
 @OS_DARWIN_FALSE@@OS_LINUX_FALSE@@OS_NETBSD_FALSE@@OS_OPENBSD_FALSE@@OS_WINDOWS_TRUE@am__objects_8 = $(am__objects_7)
@@ -148,6 +149,8 @@
 @OS_DARWIN_FALSE@@OS_LINUX_FALSE@@OS_NETBSD_FALSE@@OS_OPENBSD_TRUE@	$(am__objects_3)
 @OS_DARWIN_FALSE@@OS_LINUX_FALSE@@OS_NETBSD_TRUE@am__objects_8 = $(am__objects_5) \
 @OS_DARWIN_FALSE@@OS_LINUX_FALSE@@OS_NETBSD_TRUE@	$(am__objects_3)
+@OS_DARWIN_FALSE@@OS_LINUX_FALSE@@OS_AIX_TRUE@am__objects_8 = $(am__objects_9) \
+@OS_DARWIN_FALSE@@OS_LINUX_FALSE@@OS_AIX_TRUE@	$(am__objects_3)
 @OS_DARWIN_FALSE@@OS_LINUX_TRUE@@USE_UDEV_FALSE@am__objects_8 = $(am__objects_4) \
 @OS_DARWIN_FALSE@@OS_LINUX_TRUE@@USE_UDEV_FALSE@	$(am__objects_3) \
 @OS_DARWIN_FALSE@@OS_LINUX_TRUE@@USE_UDEV_FALSE@	os/libusb_1_0_la-linux_netlink.lo
@@ -283,6 +286,7 @@
 OS_NETBSD = @OS_NETBSD@
 OS_OPENBSD = @OS_OPENBSD@
 OS_WINDOWS = @OS_WINDOWS@
+OS_AIX = @OS_AIX@
 OTOOL = @OTOOL@
 OTOOL64 = @OTOOL64@
 PACKAGE = @PACKAGE@
@@ -360,10 +364,11 @@
 DARWIN_USB_SRC = os/darwin_usb.c
 OPENBSD_USB_SRC = os/openbsd_usb.c
 NETBSD_USB_SRC = os/netbsd_usb.c
+AIX_USB_SRC = os/aix_usb.c
 WINDOWS_USB_SRC = os/poll_windows.c os/windows_usb.c libusb-1.0.rc libusb-1.0.def
 WINCE_USB_SRC = os/wince_usb.c os/wince_usb.h
 EXTRA_DIST = $(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) $(OPENBSD_USB_SRC) \
-	$(NETBSD_USB_SRC) $(WINDOWS_USB_SRC) $(WINCE_USB_SRC) \
+	$(NETBSD_USB_SRC) $(WINDOWS_USB_SRC) $(WINCE_USB_SRC) $(AIX_USB_SRC)\
 	$(POSIX_POLL_SRC) \
 	os/threads_posix.c os/threads_windows.c \
 	os/linux_udev.c os/linux_netlink.c
@@ -376,6 +381,7 @@
 @OS_LINUX_TRUE@@USE_UDEV_TRUE@	os/linux_udev.c
 
 @OS_NETBSD_TRUE@OS_SRC = $(NETBSD_USB_SRC) $(POSIX_POLL_SRC)
+@OS_AIX_TRUE@OS_SRC = $(AIX_USB_SRC) $(POSIX_POLL_SRC)
 @OS_OPENBSD_TRUE@OS_SRC = $(OPENBSD_USB_SRC) $(POSIX_POLL_SRC)
 @OS_WINDOWS_TRUE@OS_SRC = $(WINDOWS_USB_SRC)
 @OS_DARWIN_TRUE@AM_CFLAGS_EXT = -no-cpp-precomp
@@ -481,6 +487,8 @@
 	os/$(DEPDIR)/$(am__dirstamp)
 os/libusb_1_0_la-netbsd_usb.lo: os/$(am__dirstamp) \
 	os/$(DEPDIR)/$(am__dirstamp)
+os/libusb_1_0_la-aix_usb.lo: os/$(am__dirstamp) \
+	os/$(DEPDIR)/$(am__dirstamp)
 os/libusb_1_0_la-openbsd_usb.lo: os/$(am__dirstamp) \
 	os/$(DEPDIR)/$(am__dirstamp)
 os/libusb_1_0_la-poll_windows.lo: os/$(am__dirstamp) \
@@ -511,6 +519,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@os/$(DEPDIR)/libusb_1_0_la-linux_usbfs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@os/$(DEPDIR)/libusb_1_0_la-netbsd_usb.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@os/$(DEPDIR)/libusb_1_0_la-openbsd_usb.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@os/$(DEPDIR)/libusb_1_0_la-aix_usb.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@os/$(DEPDIR)/libusb_1_0_la-poll_posix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@os/$(DEPDIR)/libusb_1_0_la-poll_windows.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@os/$(DEPDIR)/libusb_1_0_la-threads_posix.Plo@am__quote@
@@ -639,6 +648,13 @@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libusb_1_0_la_CFLAGS) $(CFLAGS) -c -o os/libusb_1_0_la-netbsd_usb.lo `test -f 'os/netbsd_usb.c' || echo '$(srcdir)/'`os/netbsd_usb.c
 
+os/libusb_1_0_la-aix_usb.lo: os/aix_usb.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libusb_1_0_la_CFLAGS) $(CFLAGS) -MT os/libusb_1_0_la-aix_usb.lo -MD -MP -MF os/$(DEPDIR)/libusb_1_0_la-aix_usb.Tpo -c -o os/libusb_1_0_la-aix_usb.lo `test -f 'os/aix_usb.c' || echo '$(srcdir)/'`os/aix_usb.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) os/$(DEPDIR)/libusb_1_0_la-aix_usb.Tpo os/$(DEPDIR)/libusb_1_0_la-aix_usb.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='os/aix_usb.c' object='os/libusb_1_0_la-aix_usb.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libusb_1_0_la_CFLAGS) $(CFLAGS) -c -o os/libusb_1_0_la-aix_usb.lo `test -f 'os/aix_usb.c' || echo '$(srcdir)/'`os/aix_usb.c
+
 os/libusb_1_0_la-openbsd_usb.lo: os/openbsd_usb.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libusb_1_0_la_CFLAGS) $(CFLAGS) -MT os/libusb_1_0_la-openbsd_usb.lo -MD -MP -MF os/$(DEPDIR)/libusb_1_0_la-openbsd_usb.Tpo -c -o os/libusb_1_0_la-openbsd_usb.lo `test -f 'os/openbsd_usb.c' || echo '$(srcdir)/'`os/openbsd_usb.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) os/$(DEPDIR)/libusb_1_0_la-openbsd_usb.Tpo os/$(DEPDIR)/libusb_1_0_la-openbsd_usb.Plo
diff -uNr libusb-1.0.19/libusb/core.c libusb-1.0.19p/libusb/core.c
--- libusb-1.0.19/libusb/core.c	2016-03-04 08:10:55 -0600
+++ libusb-1.0.19p/libusb/core.c	2016-06-05 05:40:35 -0500
@@ -56,6 +56,8 @@
 const struct usbi_os_backend * const usbi_backend = &windows_backend;
 #elif defined(OS_WINCE)
 const struct usbi_os_backend * const usbi_backend = &wince_backend;
+#elif defined(OS_AIX)
+const struct usbi_os_backend * const usbi_backend = &aix_backend;
 #else
 #error "Unsupported OS"
 #endif
@@ -780,7 +782,7 @@
 	if (port_numbers_len <= 0)
 		return LIBUSB_ERROR_INVALID_PARAM;
 
-	// HCDs can be listed as devices with port #0
+	/* HCDs can be listed as devices with port*/
 	while((dev) && (dev->port_number != 0)) {
 		if (--i < 0) {
 			usbi_warn(ctx, "port numbers array is too small");
diff -uNr libusb-1.0.19/libusb/libusb.h libusb-1.0.19p/libusb/libusb.h
--- libusb-1.0.19/libusb/libusb.h	2016-03-04 08:11:02 -0600
+++ libusb-1.0.19p/libusb/libusb.h	2016-06-05 05:40:35 -0500
@@ -54,7 +54,7 @@
 #include <sys/types.h>
 #endif
 
-#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
+#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(_AIX)
 #include <sys/time.h>
 #endif
 
@@ -1527,7 +1527,7 @@
 	transfer->buffer = buffer;
 	if (setup)
 		transfer->length = (int) (LIBUSB_CONTROL_SETUP_SIZE
-			+ libusb_le16_to_cpu(setup->wLength));
+			+ libusb_cpu_to_le16(setup->wLength));
 	transfer->user_data = user_data;
 	transfer->callback = callback;
 }
diff -uNr libusb-1.0.19/libusb/libusbi.h libusb-1.0.19p/libusb/libusbi.h
--- libusb-1.0.19/libusb/libusbi.h	2016-03-04 08:11:09 -0600
+++ libusb-1.0.19p/libusb/libusbi.h	2016-06-05 05:40:35 -0500
@@ -48,6 +48,18 @@
  */
 #define API_EXPORTED LIBUSB_CALL DEFAULT_VISIBILITY
 
+#ifdef OS_AIX
+
+/*#define LIBUSB_PRINT 1*/
+
+#ifdef LIBUSB_PRINT
+#define libusb_printf printf
+#else
+#define libusb_printf(...)
+#endif
+
+#endif
+
 #define DEVICE_DESC_LENGTH		18
 
 #define USB_MAXENDPOINTS	32
@@ -157,6 +169,22 @@
                 (tv)->tv_usec = (ts)->tv_nsec / 1000;                   \
         } while (0)
 #endif
+#ifdef OS_AIX
+#ifndef timersub
+# define timersub(tvp, uvp, vvp)                                        \
+        do                                                              \
+        {                                                               \
+                (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
+                (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
+                if ((vvp)->tv_usec < 0)                                 \
+                {                                                       \
+                        (vvp)->tv_sec--;                                \
+                        (vvp)->tv_usec += 1000000;                      \
+                }                                                       \
+        } while (0)
+#endif /* !timersub */
+#endif /* !OS_AIX */
+
 
 void usbi_log(struct libusb_context *ctx, enum libusb_log_level level,
 	const char *function, const char *format, ...);
@@ -445,7 +473,7 @@
 void usbi_disconnect_device (struct libusb_device *dev);
 
 /* Internal abstraction for poll (needs struct usbi_transfer on Windows) */
-#if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD)
+#if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD) || defined(OS_AIX)
 #include <unistd.h>
 #include "os/poll_posix.h"
 #elif defined(OS_WINDOWS) || defined(OS_WINCE)
@@ -1018,6 +1046,7 @@
 extern const struct usbi_os_backend netbsd_backend;
 extern const struct usbi_os_backend windows_backend;
 extern const struct usbi_os_backend wince_backend;
+extern const struct usbi_os_backend aix_backend;
 
 extern struct list_head active_contexts_list;
 extern usbi_mutex_static_t active_contexts_lock;
diff -uNr libusb-1.0.19/libusb/sync.c libusb-1.0.19p/libusb/sync.c
--- libusb-1.0.19/libusb/sync.c	2016-03-04 08:11:15 -0600
+++ libusb-1.0.19p/libusb/sync.c	2016-06-05 05:40:35 -0500
@@ -171,6 +171,7 @@
 	transfer->type = type;
 
 	r = libusb_submit_transfer(transfer);
+
 	if (r < 0) {
 		libusb_free_transfer(transfer);
 		return r;
@@ -179,6 +180,7 @@
 	sync_transfer_wait_for_completion(transfer);
 
 	*transferred = transfer->actual_length;
+
 	switch (transfer->status) {
 	case LIBUSB_TRANSFER_COMPLETED:
 		r = 0;
diff -uNr libusb-1.0.19/libusb/os/aix_usb.c libusb-1.0.19p/libusb/os/aix_usb.c
--- libusb-1.0.19/libusb/os/aix_usb.c   1969-12-31 18:00:00 -0600
+++ libusb-1.0.19p/libusb/os/aix_usb.c  2016-06-05 05:40:35 -0500
@@ -0,0 +1,1393 @@
+#include "aix_usb.h"
+
+static struct aix_device_priv *_device_priv(struct libusb_device *dev)
+{
+        return (struct aix_device_priv *) dev->os_priv;
+}
+
+
+static struct aix_device_handle_priv *_device_handle_priv(
+        struct libusb_device_handle *handle)
+{
+        return (struct aix_device_handle_priv *) handle->os_priv;
+}
+
+int
+aix_init(struct libusb_context *ctx)
+{
+
+  openlog("LIBUSB", LOG_PID, LOG_USER);
+  syslog(LOG_DEBUG, "LIBUSB AIX Logging Starts");
+  return 0;
+
+}
+
+void
+aix_exit(void)
+{
+ syslog(LOG_DEBUG, "LIBUSB AIX Logging Ends");
+ closelog();
+
+}
+
+
+int
+aix_get_device_list(struct libusb_context * ctx,
+	struct discovered_devs **discdevs)
+{
+
+  int fd,rc;
+  int bus_number = 0;
+  DIR *dp;
+  struct dirent *dep;
+  char *n;
+
+  /* open the usb driver */
+   fd = open (USBD_SPECIAL_FILE, 0);
+
+  if (fd < 0)
+  {
+    usbi_err(ctx, "aix_get_device_list: libusb couldn't open USB device %s: %s", 
+              USBD_SPECIAL_FILE, strerror(errno));
+    if (errno == EACCES)
+       return LIBUSB_ERROR_ACCESS;
+
+    if (errno == ENOENT)
+       return LIBUSB_ERROR_NO_DEVICE;
+
+
+    return LIBUSB_ERROR_OTHER;
+  }
+
+  dp = opendir("/dev/.");
+
+  if ( ! dp )
+  {
+     usbi_err(ctx, "opendir /dev/ failed, errno=%d", errno);
+     return LIBUSB_ERROR_IO;
+  }
+
+  while((dep=readdir(dp)))
+  {
+
+    if ( strncmp(dep->d_name,"usbhc",5) == 0 )
+    {
+
+       printf("found /dev/%s\n",dep->d_name);
+       bus_number = get_busnumber(dep->d_name);
+       if (bus_number == -1)
+           bus_number = 0;
+       usbi_dbg("\n calling add_hc_device errno:%d\n",errno);
+       rc = add_hc_device(fd ,dep->d_name, bus_number, discdevs, ctx);
+       usbi_dbg("\n done add_hc_device errno:%d\n",errno);
+       if (rc != 0) {
+          usbi_err(ctx, "add_hc_device failed errno = (%d), rc = %d", errno, rc);
+          close(fd);
+          return rc;
+       }
+     }
+  }
+
+  closedir(dp);
+
+  close(fd);
+  
+  return (LIBUSB_SUCCESS);
+}
+
+int get_busnumber(char *hc_name)
+{
+ int busnumber;
+
+ if (sscanf(hc_name, "usbhc%d", &busnumber) != 1)
+     return 0;
+
+ usbi_dbg("get_busnumber: busnumber returned: %d for usbhc: %s",busnumber, hc_name);
+
+
+ return busnumber;
+
+}
+
+
+int add_hc_device(int usbd_fd, char *hc_name, int bus_number, struct discovered_devs **discdevs, struct libusb_context *ctx)
+{
+    struct stat ss;
+    int irv;
+    dev32_t devno32;
+    USBENUM ue1;
+    USBENUM *uep;
+    size_t s;
+    usb_device_t *udp;
+    int n, rc = 0;
+    struct libusb_device *dev;
+    struct discovered_devs *ddd;
+    unsigned long session_id;
+    USBDGD_32 dgd;
+    struct aix_device_priv *priv;
+    char *hcdevpath;
+    char conn[10];
+    PDESCIDX_32 pdescidx;
+
+    /* Get the host controller devno. */
+    errno=0;
+    hcdevpath = aix_usb_concatenate("/dev/",hc_name);
+    if( ! hcdevpath )
+    {
+       printf(" strcat failed\n");
+       usbi_err(ctx, "add_hc_device: aix_usb_concatenate failed");
+       return LIBUSB_ERROR_OTHER;
+    }
+
+    irv=stat(hcdevpath,&ss);
+    if( irv != 0 )
+    {
+        printf("stat() failed, irv=%d errno=%d\n",irv,errno);
+        usbi_err(ctx, "add_hc_device: stat() failed, irv=%d errno=%d",irv,errno);
+        return LIBUSB_ERROR_NOT_FOUND;
+    }
+
+    /* Get the 32 bit version. */
+    devno32=DEVTODEV32(ss.st_rdev);
+
+    /* First find the number of devices. */
+    memset(&ue1,0,sizeof(ue1));
+    uep=&ue1;
+    uep->devno=devno32;
+    uep->buffSize=0;
+
+    errno=0;
+    irv=ioctl(usbd_fd,USBD_ENUMERATE_ALL,uep);
+    if( irv != 0 )
+    {
+        printf("ioctl(,USBD_ENUMERATE_ALL,) failed, irv=%d errno=%d\n",irv,errno);
+        usbi_err(ctx, "ioctl(,USBD_ENUMERATE_ALL,) failed, irv=%d errno=%d\n",irv,errno);
+        if (errno == ENODEV)
+            return LIBUSB_ERROR_NO_DEVICE;
+        return LIBUSB_ERROR_IO;
+    }
+
+    printf("found %d devices\n",ue1.numDevDisc);
+    usbi_dbg("add_hc_device: found %d devices",ue1.numDevDisc);
+
+    if( ue1.numDevDisc < 1 )
+    {
+        usbi_err(ctx, "add_hc_device: Number of Devices Discovered: %d",ue1.numDevDisc);
+        /* if there are no devices connected to hostcontroller,
+         * the count will be zero. hence return zero instead of negative valie
+         */
+        return 0;
+    }
+
+    /* Now fetch all the information. */
+    s=sizeof(USBENUM)+(ue1.numDevDisc-1)*sizeof(usb_device_t);
+    errno=0;
+    uep=(USBENUM *)malloc(s);
+    if( ! uep )
+    {
+        printf("malloc() failed, errno=%d\n",errno);
+        usbi_err(ctx, "add_hc_device: malloc() failed, errno=%d",errno);
+        return LIBUSB_ERROR_NO_MEM;
+    }
+
+    memset(uep,0,s);
+    uep->devno=devno32;
+    uep->buffSize=ue1.numDevDisc*sizeof(usb_device_t);
+
+    irv=ioctl(usbd_fd,USBD_ENUMERATE_ALL,uep);
+    if( irv != 0 )
+    {
+        printf("ioctl(,USBD_ENUMERATE_ALL,) failed, irv=%d errno=%d\n",irv,errno);
+        usbi_err(ctx, "ioctl(,USBD_ENUMERATE_ALL,) failed, irv=%d errno=%d\n",irv,errno);
+        free(uep);
+        return LIBUSB_ERROR_IO;
+    }
+
+    if( uep->numDevDisc != ue1.numDevDisc )
+    {
+        printf("the number of devices changed to %d\n",uep->numDevDisc);
+        usbi_dbg("the number of devices changed to %d",uep->numDevDisc);
+    }
+    if( uep->numDevEnum != ue1.numDevDisc )
+    {
+        printf("the number of devices enumerated is %d\n",uep->numDevEnum);
+        usbi_dbg("the number of devices changed to %d", uep->numDevEnum);
+    }
+
+    usbi_dbg("add_hc_device: enumerated number of devices: %d",uep->numDevEnum);
+
+    for(n = 0;n < uep->numDevEnum; n++)
+    {
+        udp=&(uep->devinfo[n]);
+
+        /*
+         * changing the logic to include config and interface
+         * some device will just by differ in intfc. For example, IBM keyboard
+         * gets enumerated as hub and keyboard which will have samevalue except for interface
+         */
+        sprintf(conn, "%d%d%d%d", bus_number,udp->addr, udp->cfg,udp->intfc);
+
+        session_id = atoi(conn);
+
+        usbi_dbg("add_hc_device: session_id : %ld bus_number: %d device address: %d device config: %d device interface: %d", session_id, bus_number, udp->addr, udp->cfg, udp->intfc);
+
+        dev = usbi_get_device_by_session_id(ctx, session_id);
+
+        if (dev) {
+            usbi_dbg("session_id %ld already exists", session_id);
+            libusb_unref_device(dev);
+            return LIBUSB_SUCCESS;
+        }
+
+        if (dev == NULL)
+        {
+
+           dev = usbi_alloc_device(ctx, session_id);
+
+           if (dev == NULL) 
+           {
+                usbi_err(ctx, "add_hc_device: usbi_alloc_device failed \
+                            for session_id: %ld", session_id);
+                return (LIBUSB_ERROR_NO_MEM);
+           }
+
+           dev->bus_number = bus_number;
+           dev->device_address = udp->addr;
+           if (udp->speed >= 0) {
+               switch (udp->speed) {
+                   case     0x1 : dev->speed = LIBUSB_SPEED_LOW; break;
+                   case     0x2 : dev->speed = LIBUSB_SPEED_FULL; break;
+                   case     0x4 : dev->speed = LIBUSB_SPEED_HIGH; break;
+                   case     0x10: dev->speed = LIBUSB_SPEED_SUPER; break;
+                   default:
+                            usbi_warn(DEVICE_CTX(dev), "Unknown device speed: ", udp->speed);
+                            dev->speed = udp->speed;
+               }
+           }
+           dev->port_number = udp->port[0];
+           priv = _device_priv(dev);
+            
+           strncpy(priv->hc_name, hc_name, 8);
+           /*priv->devno = devno32;*/
+
+           /* Populate Devselector fields */
+
+           priv->devsel.hcdevno = devno32;
+           priv->devsel.addr = udp->addr;
+           priv->devsel.cfg = udp->cfg;
+           priv->devsel.intfc = udp->intfc;
+           priv->devsel.usb_class = udp->usb_class;
+           priv->devsel.usb_subclass = udp->usb_subclass;
+           priv->devsel.usb_protocol =  udp->usb_protocol;
+           priv->devsel.device_type = udp->device_type;
+           priv->devsel.speed = udp->speed;
+          
+           usbi_dbg("add_hc_device addr: %d cfg: %d intfc: %d",udp->addr, udp->cfg, udp->intfc);
+           usbi_dbg("add_hc_device class: %d subclass: %d protocol: %d",udp->usb_class, udp->usb_subclass, udp->usb_protocol);
+           usbi_dbg("add_hc_device device_type: %d speed: %d",udp->device_type,udp->speed);
+           usbi_dbg("add_hc_device: devno:%lx",devno32);
+
+         /* Get Descriptors */
+
+           dgd.hcdevno = devno32;
+           dgd.addr = udp->addr;
+           dgd.cfg = udp->cfg;
+           dgd.intfc = udp->intfc;
+           dgd.bufferLength = 0;
+
+           /* no IOCTL fail check because we fail this IOCTL
+            * with ENOSPC as this is just to get the length of
+            * of the descriptors so that we can allocated buffer
+            */
+
+           irv = ioctl(usbd_fd, USBD_GET_DESCRIPTORS, &dgd);
+
+           usbi_dbg("\n errno after USBD_GET_DESCRIPTORS 1 is %d\n",errno);
+
+           dgd.bufferLength = dgd.minBuffLength;
+
+           dgd.buffer = (void *)malloc(dgd.minBuffLength);
+
+           usbi_dbg("add_hc_device length for descriptors: %d",dgd.minBuffLength);
+
+           if ( ! dgd.buffer )
+           {
+              printf("malloc() failed, errno=%d\n",errno);
+              usbi_err(ctx, "malloc() failed for dgd.buffer, length=%d errno=%d",dgd.minBuffLength,errno);
+              return LIBUSB_ERROR_NO_MEM;
+           }
+           
+           irv=ioctl(usbd_fd, USBD_GET_DESCRIPTORS, &dgd);
+           usbi_dbg("\n errno after USBD_GET_DESCRIPTORS 2 is %d\n",errno);
+
+           if ( irv != 0 )
+           {
+              printf("ioctl(USBD_GET_DESCRIPTORS 2) failed, irv=%d errno=%d\n",irv,errno);
+              usbi_err(ctx, "ioctl(USBD_GET_DESCRIPTORS 2) failed, irv=%d errno=%d\n",irv,errno);
+              free(uep);
+              return LIBUSB_ERROR_IO;
+           }
+
+           priv->descriptors = malloc(dgd.minBuffLength);
+
+           if ( ! (priv->descriptors) )
+           {
+              printf("malloc() failed, errno=%d\n",errno);
+              return LIBUSB_ERROR_NO_MEM;
+           }
+
+           memcpy((char *)priv->descriptors, (char *)(dgd.buffer), dgd.bufferLength);
+
+           priv->desc_size = dgd.bufferLength;
+
+           priv->current_config = dgd.cfg;
+
+           pdescidx = priv->descriptors;
+
+           priv->configdesc = pdescidx->pConfigDesc;
+
+
+           if (usbi_sanitize_device(dev)) {
+                usbi_warn(ctx, "usbi_sanitize_device failed");
+                libusb_unref_device(dev);
+                continue;
+           }
+
+           usbi_device_cache_descriptor(dev);
+           rc = get_all_config_descriptors(priv);
+           if (rc == LIBUSB_ERROR_NO_DEVICE) {
+               printf("\n get_all_config_descriptors failed unref\n");
+               libusb_unref_device(dev);
+               continue;
+           }
+
+         }
+
+         ddd = discovered_devs_append(*discdevs, dev);
+         if (ddd == NULL)
+         {
+            usbi_err(ctx, "discovered_devs_append failed");
+            return (LIBUSB_ERROR_NO_MEM);
+          }
+         libusb_unref_device(dev);
+         *discdevs = ddd;
+     }
+
+    free(uep);
+
+    usbi_dbg("add_hc_device: Function return success");
+
+    return (LIBUSB_SUCCESS);
+}
+
+
+
+int
+aix_open(struct libusb_device_handle *handle)
+{
+  int fd, rc;
+  struct libusb_device *dev = handle->dev;
+  struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+  struct aix_device_priv *priv = _device_priv(dev);
+  DEVSELECTOR devselarg;
+
+  devselarg = priv->devsel;
+
+  hpriv->devsel_handle = devselarg;
+
+  usbi_dbg("aix_open: Entering Function");
+  usbi_dbg("Printing Devselector");
+
+  fd = open_aix_libusb_device(priv);
+
+  if (fd < 0)
+  {
+    printf("aix_open: could not open the device\n");
+
+
+    usbi_err(NULL, "libusb couldn't open USB device errno: %s",
+               strerror(errno));
+
+    if (errno == EACCES)
+       return LIBUSB_ERROR_ACCESS;
+
+    if (errno == ENOENT)
+       return LIBUSB_ERROR_NO_DEVICE;
+
+
+    return LIBUSB_ERROR_OTHER;
+
+  } else {
+
+       hpriv->fd = fd;
+       strncpy(hpriv->devicename, priv->devicename, 16);
+
+       rc = usbi_add_pollfd(HANDLE_CTX(handle), fd, POLLIN);
+
+       usbi_dbg("aix_open: open on %s succesful", priv->devicename);
+
+       return rc;
+  }
+        
+}
+
+
+void
+aix_close(struct libusb_device_handle *handle)
+{
+    int fd;
+    struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+
+    fd = hpriv->fd;
+
+    usbi_dbg("aix_close: close on %s", hpriv->devicename);
+    usbi_remove_pollfd(HANDLE_CTX(handle), fd);
+    /* the close ioctl to usbd is taken care by the driver */
+    close(fd);
+    hpriv->fd = -1;
+
+}
+
+
+int
+aix_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
+    int *host_endian)
+{
+
+        struct aix_device_priv *priv = _device_priv(dev);
+        PDESCIDX_32 pdescidx;
+        pdescidx = priv->descriptors;
+        memcpy(buf, (char *)(pdescidx->pDevDesc), DEVICE_DESC_LENGTH);
+        usbi_dbg("aix_get_device_descriptor: host_endian: %d", *host_endian);
+	return (LIBUSB_SUCCESS);
+}
+
+int
+aix_get_active_config_descriptor(struct libusb_device *dev,
+    unsigned char *buf, size_t len, int *host_endian)
+{
+        struct aix_device_priv *priv = _device_priv(dev);
+        unsigned char *configdesc;
+        int size = 0;
+
+        usbi_dbg("aix_get_active_config_descriptor: devicename: %s len: %d host_endian: %d",
+                    priv->devicename, len, *host_endian);
+        
+        size = aix_get_config_desc_byvalue(dev, priv->current_config, 
+                         &configdesc, host_endian);
+
+        if (size < 0) {
+           usbi_dbg("aix_get_active_config_descriptor: size less than zero: %d", size);
+           return size;
+        }
+
+        /* Make sure we dont copy more than what is actually present */
+        size = (size < len) ? size : len;
+
+        memcpy(buf, configdesc, size);
+
+        usbi_dbg("aix_get_active_config_descriptor: Returned Size: %d", size);
+
+	return size;
+}
+
+int
+aix_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
+    unsigned char *buf, size_t len, int *host_endian)
+{
+        struct aix_device_priv *priv = _device_priv(dev);
+        PDESCIDX_32 pdescidx;
+        PUSBConfigDesc desc, desc_next;
+        int size = 0,i;
+        caddr_t ptr;
+
+        usbi_dbg("aix_get_config_descriptor: Device: %s len: %d host_endian: %d idx:%d\n", 
+                   priv->devicename, len, *host_endian,idx);
+
+
+        desc = (PUSBConfigDesc)priv->configdesc;
+        size = LOAD16(desc->wTotalLength);
+        usbi_dbg("aix_get_config_descriptor: length in aix_get_config_descriptor is %d and cdesc_len is %d",size, priv->cdesc_len); 
+        ptr = (caddr_t)desc;
+        for (i = 0; i < idx; i++){
+            desc_next = (PUSBConfigDesc)(ptr + size);
+            size = LOAD16(desc_next->wTotalLength);
+            ptr = (caddr_t)desc_next;
+        }
+        /* Make sure we dont copy more than what is actually present */
+        size = (size < len) ? size : len;
+        memcpy(buf, (char *)ptr, size);
+	return (size);
+}
+
+int
+aix_get_configuration(struct libusb_device_handle *handle, int *config)
+{
+        struct aix_device_priv *priv = _device_priv(handle->dev);
+        /* TODO: handle cases when device is disconnected */
+        usbi_dbg("aix_get_configuration: device: %s current configuration: %d", 
+                  priv->devicename, priv->current_config);
+        *config = priv->current_config; 
+	return (LIBUSB_SUCCESS);
+}
+int
+aix_get_config_desc_byvalue(struct libusb_device *dev,
+        uint8_t value, unsigned char **buffer, int *host_endian)
+{
+
+        struct aix_device_priv *priv = _device_priv(dev);
+        PDESCIDX_32 pdescidx;
+        PUSBConfigDesc desc, desc_next;
+        int size = 0, numconfig = 0, i;
+        PUSBDevDesc devdesc;
+        caddr_t ptr;
+
+        pdescidx = priv->descriptors;
+
+        usbi_dbg("aix_get_config_desc_byvalue: Device: %s Config Value: %d host_endian: %d",
+                    priv->devicename, value, *host_endian);
+
+        devdesc = (PUSBDevDesc)pdescidx->pDevDesc;
+
+        numconfig = devdesc->bNumConfigurations;
+
+        desc = (PUSBConfigDesc)priv->configdesc;
+        size = LOAD16(desc->wTotalLength);
+        ptr = (caddr_t)desc;
+        for (i = 0; i < numconfig; i++){
+            desc_next = (PUSBConfigDesc)(ptr + size);
+            size = LOAD16(desc_next->wTotalLength);
+            
+            if (desc_next->bConfigurationValue == value)
+               break;
+
+            ptr = (caddr_t)desc_next;
+            
+        }
+
+        *buffer = (char *)desc_next;
+        usbi_dbg("aix_get_config_desc_byvalue: returning withe size: %d ", size);
+	return size;
+}
+
+/*
+ * USB protocol driver does not allow sending set configuration
+ * request on a device as it sends it when device is being
+ * configured. Hence this function returns success by default
+ */
+
+int
+aix_set_configuration(struct libusb_device_handle *handle, int config)
+{
+      struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+      struct aix_device_priv *priv = _device_priv(handle->dev);
+      int rc = 0;
+
+      usbi_dbg("aix_set_configuration: on Device: %s config: %d", hpriv->devicename, config);
+
+      /*rc = ioctl(hpriv->fd, USBLIB_SET_CONFIGURATION, &config);
+
+      if (rc) {
+          usbi_err(HANDLE_CTX(handle), "aix_set_configuration: rc: %d errno: %d", rc, errno);
+          if (errno == EINVAL)
+              return LIBUSB_ERROR_NOT_FOUND;
+          else if (errno == EBUSY)
+              return LIBUSB_ERROR_BUSY;
+          else if (errno == ENODEV)
+              return LIBUSB_ERROR_NO_DEVICE;
+                usbi_err(HANDLE_CTX(handle), "failed, error %d errno %d", rc, errno);
+                return LIBUSB_ERROR_OTHER;
+       }*/
+       priv->current_config = config;
+       usbi_dbg("aix_set_configuration: returning with config: %d", priv->current_config);
+       return (LIBUSB_SUCCESS);
+}
+
+ /*
+  * This function should not generate any bus I/O and should not block.
+  * Interface claiming is a logical operation that simply ensures that
+  * no other drivers/applications are using the interface, and after
+  * claiming, no other drivers/applicatiosn can use the interface because
+  * we now "own" it.
+  */
+
+int
+aix_claim_interface(struct libusb_device_handle *handle, int iface)
+{
+        struct aix_device_priv *priv = _device_priv(handle->dev); 
+        printf("\n in aix_claim_interface\n");
+        usbi_dbg("aix_claim_interface: Device: %s Interface: %d", priv->devicename, iface);
+	return (LIBUSB_SUCCESS);
+}
+
+int
+aix_release_interface(struct libusb_device_handle *handle, int iface)
+{
+
+      struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+      struct aix_device_priv *priv = _device_priv(handle->dev);
+      int rc = 0;
+
+      rc = ioctl(hpriv->fd, USBLIB_RELEASE_INTERFACE, &iface);
+      usbi_dbg("aix_release_interface: Device: %s Interface: %d", priv->devicename, iface);
+
+      if (rc) {
+          usbi_err(HANDLE_CTX(handle), "aix_release_interface: rc: %d errno: %d", rc, errno);
+          if (errno == EINVAL)
+              return LIBUSB_ERROR_NOT_FOUND;
+          else if (errno == EBUSY)
+              return LIBUSB_ERROR_BUSY;
+          else if (errno == ENODEV)
+              return LIBUSB_ERROR_NO_DEVICE;
+      }
+
+      usbi_dbg("aix_release_interface returning with success");
+      return (LIBUSB_SUCCESS);
+}
+
+int
+aix_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
+    int altsetting)
+{
+      struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+      struct aix_device_priv *priv = _device_priv(handle->dev);
+      int rc = 0;
+      struct aix_interface_alt intf;
+
+      intf.interface = iface;
+      intf.alt_setting = altsetting;
+
+      usbi_dbg("aix_set_interface_altsetting: Device: %s Interface: %d altsetting: %d", 
+                  priv->devicename, iface, altsetting);
+
+      rc = ioctl(hpriv->fd, USBLIB_SET_ALT_INTFC, &intf);
+
+      if (rc) {
+          usbi_err(HANDLE_CTX(handle), "aix_set_interface_altsetting: rc: %d errno: %d", rc, errno);
+          if (errno == EINVAL)
+              return LIBUSB_ERROR_NOT_FOUND;
+          else if (errno == EBUSY)
+              return LIBUSB_ERROR_BUSY;
+          else if (errno == ENODEV)
+              return LIBUSB_ERROR_NO_DEVICE;
+      }
+
+      usbi_dbg("aix_set_interface_altsetting: return with success");
+
+      return (LIBUSB_SUCCESS);
+}
+
+int
+aix_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
+{
+     struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+     int rc = 0;
+     struct aix_pipeio pipeioargs;
+
+     memset(&pipeioargs, 0, sizeof(struct aix_pipeio));
+
+     usbi_dbg("aix_clear_halt: Device: %s Endpoint: %d", hpriv->devicename, endpoint);
+     pipeioargs.devsel = hpriv->devsel_handle;
+     pipeioargs.endpoint = endpoint;
+     pipeioargs.pBuffer = NULL;
+     pipeioargs.clientPriv = NULL;
+     pipeioargs.transSize = 0;
+     pipeioargs.status = 0;
+
+
+     rc = ioctl(hpriv->fd, USBLIB_HALT_CLEAR, &pipeioargs);
+     if (rc) {
+          usbi_err(HANDLE_CTX(handle), "aix_clear_halt: rc: %d errno: %d", rc, errno);
+          if (errno == EINVAL)
+              return LIBUSB_ERROR_NOT_FOUND;
+          else if (errno == ENODEV)
+              return LIBUSB_ERROR_NO_DEVICE;
+          else
+              return LIBUSB_ERROR_OTHER;
+      }
+
+     usbi_dbg("aix_clear_halt: Returning with %d", rc);
+
+     return (LIBUSB_SUCCESS);
+}
+
+int
+aix_reset_device(struct libusb_device_handle *handle)
+{
+      struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+      struct aix_device_priv *priv = _device_priv(handle->dev);
+      int rc = 0;
+
+      rc = ioctl(hpriv->fd, USBLIB_RESET_DEVICE, NULL);
+      usbi_dbg("aix_reset_device: Device: %s ", hpriv->devicename);
+
+      if (rc) {
+          usbi_err(HANDLE_CTX(handle), "aix_reset_device: rc: %d errno: %d", rc, errno);
+          if (errno == EINVAL)
+              return LIBUSB_ERROR_NOT_FOUND;
+          else if (errno == EBUSY)
+              return LIBUSB_ERROR_BUSY;
+          else if (errno == ENODEV)
+              return LIBUSB_ERROR_NO_DEVICE;
+      }
+      usbi_dbg("aix_reset_device: Returning with %d", rc);
+
+
+}
+
+void
+aix_destroy_device(struct libusb_device *dev)
+{
+
+    struct aix_device_priv *priv = _device_priv(dev);
+
+    usbi_dbg("aix_destroy_device: Device: %s",priv->devicename);
+    if (priv->descriptors)
+        free(priv->descriptors);
+    if (priv->configdesc)
+        free(priv->configdesc);
+
+}
+
+int
+aix_cancel_transfer(struct usbi_transfer *itransfer)
+{
+    int rc = 0;
+    struct aix_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+    struct libusb_transfer *transfer =
+                USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+    struct aix_device_handle_priv *dpriv =
+                _device_handle_priv(transfer->dev_handle);
+    struct aix_pipeio pipeioargs;
+
+    memset(&pipeioargs, 0, sizeof(struct aix_pipeio));
+
+    usbi_dbg("aix_cancel_transfer: Device: %s Transfer Type: %d", dpriv->devicename, transfer->type);
+
+    switch (transfer->type) {
+        case LIBUSB_TRANSFER_TYPE_BULK:
+        case LIBUSB_TRANSFER_TYPE_CONTROL:
+        case LIBUSB_TRANSFER_TYPE_INTERRUPT:
+        case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
+                /*TODO: check the status before issuing abort, 
+                 * if abort is already under process, dont issue again
+                 * check the flag CANCELLED and issue if it is not there
+                 */
+                if (tpriv->status == SUBMITTED) {
+                    tpriv->status = CANCELLED;
+                } else {
+                    printf("\n Invalid status in aix_cancel_transfer:%d\n",tpriv->status);
+                    usbi_err(TRANSFER_CTX(transfer), "Invalid status: %d", tpriv->status);
+                    return EBUSY;
+                }
+                break;
+        default:
+                usbi_err(TRANSFER_CTX(transfer),
+                        "unknown endpoint type %d", transfer->type);
+                return LIBUSB_ERROR_INVALID_PARAM;
+    }
+
+    pipeioargs.devsel = dpriv->devsel_handle;
+    pipeioargs.endpoint = transfer->endpoint;
+    pipeioargs.pBuffer = transfer->buffer;
+    pipeioargs.clientPriv = (char *)itransfer;
+    pipeioargs.transSize = transfer->length;
+    pipeioargs.status = 0;
+
+    rc = ioctl(dpriv->fd, USBLIB_ABORT_IO, &pipeioargs);
+
+    usbi_dbg("aix_cancel_transfer: Return with %d and errno: %d", rc, errno);
+
+    return rc;
+
+
+}
+
+int
+aix_submit_transfer(struct usbi_transfer *itransfer)
+{
+
+        struct libusb_transfer *transfer =
+                USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+
+        usbi_dbg("aix_submit_transfer: Transfer Type: %d", transfer->type);
+
+        switch (transfer->type) {
+        case LIBUSB_TRANSFER_TYPE_CONTROL:
+                return aix_submit_control_transfer(itransfer);
+        case LIBUSB_TRANSFER_TYPE_BULK:
+        case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
+        case LIBUSB_TRANSFER_TYPE_INTERRUPT:
+             /*
+              * same function is used irrespective
+              * of type of the transfer. the driver
+              * takes care of submitting IRP based on the
+              * endpoint type
+              */
+                return aix_submit_bulk_transfer(itransfer);
+        default:
+                usbi_err(TRANSFER_CTX(transfer),
+                        "unknown endpoint type %d", transfer->type);
+                return LIBUSB_ERROR_INVALID_PARAM;
+        }
+
+
+	return (LIBUSB_SUCCESS);
+}
+
+
+int
+aix_submit_control_transfer(struct usbi_transfer *itransfer)
+{
+
+    struct aix_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+    struct libusb_transfer *transfer =
+                USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+    struct aix_device_handle_priv *dpriv =
+                _device_handle_priv(transfer->dev_handle);
+    PIRP pirp;
+    int fd = 0;
+    struct aix_pipeio pipeioargs;
+    struct libusb_control_setup *setup;
+
+    memset(&pipeioargs, 0, sizeof(struct aix_pipeio));
+
+    pipeioargs.devsel = dpriv->devsel_handle;
+    pipeioargs.endpoint = 0;
+    pipeioargs.pBuffer = transfer->buffer;
+    pipeioargs.clientPriv = (char *)itransfer;
+    pipeioargs.transSize = transfer->length;
+    pipeioargs.status = 0;
+
+
+    setup = (struct libusb_control_setup *)(void *) transfer->buffer;
+
+    usbi_dbg("aix_submit_control_transfer: Device: %s Length: %d", dpriv->devicename,transfer->length); 
+
+    usbi_dbg(" Request type:%d\n",setup->bmRequestType);
+    usbi_dbg(" bRequesr:%d\n",setup->bRequest);
+    usbi_dbg(" wValue:0x%x\n",setup->wValue);
+    usbi_dbg(" wLength:0x%x\n",setup->wLength);
+    usbi_dbg(" wINdex:0x%x\n",setup->wIndex);
+    usbi_dbg(" transfer length is %d\n", transfer->length);
+
+    tpriv->pipeioargs = pipeioargs;
+
+    dpriv->transfer_size = transfer->length;
+
+    tpriv->status = SUBMITTED;
+
+
+    usbi_dbg("\n aix_submit_control_transfer errno 6: %d", errno);
+    ioctl(dpriv->fd, USBLIB_PIPE_IO, &pipeioargs);
+    usbi_dbg("\n aix_submit_control_transfer errno 5: %d", errno);
+
+    return 0;
+
+
+}
+
+int
+aix_submit_bulk_transfer(struct usbi_transfer *itransfer)
+{
+
+    struct aix_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+    struct libusb_transfer *transfer =
+                USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+    struct aix_device_handle_priv *dpriv =
+                _device_handle_priv(transfer->dev_handle);
+    PIRP pirp;
+    int rc = 0;
+    struct aix_pipeio pipeioargs;
+
+    memset(&pipeioargs, 0, sizeof(struct aix_pipeio));
+
+    pipeioargs.devsel = dpriv->devsel_handle;
+    pipeioargs.endpoint = transfer->endpoint;
+    pipeioargs.pBuffer = transfer->buffer;
+    pipeioargs.clientPriv = (char *)itransfer;
+    pipeioargs.transSize = transfer->length;
+    pipeioargs.status = 0;
+
+
+    tpriv->pipeioargs = pipeioargs;
+
+    dpriv->transfer_size = transfer->length;
+
+    tpriv->status = SUBMITTED;
+
+    usbi_dbg("aix_submit_bulk_transfer: Device: %s Length: %d Endpoint: %d", 
+                dpriv->devicename, transfer->length, transfer->endpoint); 
+
+    rc = ioctl(dpriv->fd, USBLIB_PIPE_IO, &pipeioargs);
+
+    if (rc) {
+        usbi_err(TRANSFER_CTX(transfer), "USBLIB_PIPE_IO failed with rc: %d errno: %d", rc, errno);
+        if (errno == ENODEV) {
+            rc = LIBUSB_ERROR_NO_DEVICE;
+        } else {
+            usbi_err(TRANSFER_CTX(transfer),
+                        "submit bulk failed error %d errno=%d", rc, errno);
+            rc = LIBUSB_ERROR_IO;
+        }
+        tpriv->status = COMPLETED;
+    }
+
+
+    return rc;
+
+
+}
+
+void
+aix_clear_transfer_priv(struct usbi_transfer *itransfer)
+{
+    struct libusb_transfer *transfer =
+           USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+    struct aix_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+
+    /*TODO: clear if anything needs to be cleared in tpriv */
+    usbi_dbg("aix_clear_transfer_priv");
+
+}
+
+
+
+char *aix_usb_concatenate(char *a, char *b)
+{
+    size_t al, bl, rvl;
+    char *rv;
+
+    if( ! a )
+    {
+        return NULL;
+    }
+    if( ! b )
+    {
+        return NULL;
+    }
+
+    al=strlen(a);
+    bl=strlen(b);
+    rvl=al+bl;
+
+    rv=(char *)malloc((rvl+1)*sizeof(char));
+    if( ! rv )
+    {
+        return rv;
+    }
+
+    memcpy(&(rv[0]),a,al);
+    memcpy(&(rv[al]),b,bl);
+    rv[rvl]='\0';
+
+    return rv;
+}
+
+static int aix_handle_events(struct libusb_context *ctx,
+        struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready)
+{
+        int r;
+        unsigned int i = 0;
+
+        usbi_dbg("in aix_handle_events nfds:%d num_ready:%d\n",nfds,num_ready);
+        usbi_dbg("aix_handle_events: printing errno 3:%d",errno);
+
+        usbi_mutex_lock(&ctx->open_devs_lock);
+        for (i = 0; i < nfds && num_ready > 0; i++) {
+                struct pollfd *pollfd = &fds[i];
+                struct libusb_device_handle *handle;
+                struct aix_device_handle_priv *hpriv = NULL;
+
+
+                if (!pollfd->revents)
+                        continue;
+
+                num_ready--;
+                list_for_each_entry(handle, &ctx->open_devs, list, struct libusb_device_handle) {
+                        hpriv = _device_handle_priv(handle);
+                        usbi_dbg(" fd in list for each entry is %d %d", hpriv->fd, pollfd->fd);
+                        if (hpriv->fd == pollfd->fd)
+                           break;
+
+                }
+
+
+                if (!hpriv || hpriv->fd != pollfd->fd) {
+                      continue;
+                }
+
+                if (pollfd->revents & POLLERR) {
+                        usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->fd);
+                        usbi_handle_disconnect(handle);
+                        usbi_dbg(" POLLERR : %d", pollfd->fd);
+                        /* device will still be marked as attached if hotplug monitor thread
+                         * hasn't processed remove event yet */
+                        if (handle->dev->attached)
+                                /*linux_device_disconnected(handle->dev->bus_number,
+                                                handle->dev->device_address, NULL);*/
+                        continue;
+                }
+
+                do {
+                        r = aix_get_irp_data(handle);
+                } while (0);
+                if (r == 1 || r == LIBUSB_ERROR_NO_DEVICE)
+                        continue;
+                else if (r < 0)
+                        goto out;
+        }
+
+        r = 0;
+out:
+        usbi_mutex_unlock(&ctx->open_devs_lock);
+        usbi_dbg("exiting handle_events");
+        usbi_dbg("aix_handle_events: printing errno 4:%d",errno);
+        return r;
+}
+
+
+int aix_get_irp_data(struct libusb_device_handle *handle)
+{
+        struct aix_device_handle_priv *hpriv = _device_handle_priv(handle);
+        int r;
+        PIRP irp;
+        struct usbi_transfer *itransfer;
+        struct libusb_transfer *transfer;
+        struct aix_pipeio pipeioargs;
+        DEVSELECTOR devsel;
+
+        devsel = hpriv->devsel_handle;
+
+        usbi_dbg("aix_get_irp_data: printing errno 1:%d",errno);
+        memset(&pipeioargs, 0, sizeof(struct aix_pipeio));
+        usbi_dbg("aix_get_irp_data: printing errno 2:%d",errno);
+
+        pipeioargs.devsel = hpriv->devsel_handle;
+        pipeioargs.endpoint = 0;
+        pipeioargs.pBuffer = (caddr_t)malloc(hpriv->transfer_size);
+        pipeioargs.clientPriv = (void *)itransfer;
+        pipeioargs.transSize = transfer->length;
+        pipeioargs.status = 0;
+
+        errno = 0;
+
+        r = ioctl(hpriv->fd, USBLIB_GETIRP_STATUS, &pipeioargs);
+
+        usbi_dbg("aix_get_irp_data: get irp status ioctl returned %d and errno:%d",r,errno);
+
+        if (r == -1 && errno == EAGAIN)
+                return 1;
+        if (r < 0) {
+                usbi_err(HANDLE_CTX(handle), "aix_get_irp_data: failed error %d errno=%d",
+                        r, errno);
+                free(pipeioargs.pBuffer);
+                if (errno == ENODEV)
+                        return LIBUSB_ERROR_NO_DEVICE;
+
+                return LIBUSB_ERROR_IO;
+        }
+
+        itransfer = (void *)pipeioargs.clientPriv;
+        transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+        if (transfer->endpoint == 0 && hpriv->transfer_size > 0 && 
+              pipeioargs.transSize > 0) {
+            memcpy(transfer->buffer, pipeioargs.pBuffer, hpriv->transfer_size);
+        }
+
+        usbi_dbg("aix_get_irp_data: status=%d transferred=%d", irp->status, irp->transSize);
+
+        switch (transfer->type) {
+        case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
+        case LIBUSB_TRANSFER_TYPE_BULK:
+        case LIBUSB_TRANSFER_TYPE_INTERRUPT:
+        case LIBUSB_TRANSFER_TYPE_CONTROL:
+                r = handle_control_bulk_completion(itransfer, &pipeioargs);
+                free(pipeioargs.pBuffer); 
+                return r;
+        default:
+                usbi_err(HANDLE_CTX(handle), "unrecognised endpoint type %x",
+                        transfer->type);
+                free(pipeioargs.pBuffer);
+                return LIBUSB_ERROR_OTHER;
+        }
+}
+
+
+
+
+int handle_control_bulk_completion(struct usbi_transfer *itransfer,
+        struct aix_pipeio *pipeioargs)
+{
+        struct aix_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+        int status;
+
+        usbi_mutex_lock(&itransfer->lock);
+        usbi_dbg("handle_control_bulk_completion: status %d length transferred = %d", \
+                       pipeioargs->status,pipeioargs->transSize);
+
+        itransfer->transferred += pipeioargs->transSize;
+
+        switch (pipeioargs->status) {
+        case USBD_SUCCESS:
+                status = LIBUSB_TRANSFER_COMPLETED;
+                break;
+        case USBD_ABORTED: /* cancelled */
+                status = LIBUSB_TRANSFER_CANCELLED;
+                break;
+        case USBD_DISCONNECT:
+                usbi_dbg("device removed");
+                status = LIBUSB_TRANSFER_NO_DEVICE;
+                break;
+        case USBD_STALL:
+                usbi_dbg("unsupported control request");
+                status = LIBUSB_TRANSFER_STALL;
+                break;
+        case USBD_BANDWIDTH:
+                usbi_dbg("control overflow error");
+                status = LIBUSB_TRANSFER_OVERFLOW;
+                break;
+        case USBD_HALTED:
+                usbi_dbg("low-level bus error occurred");
+                status = LIBUSB_TRANSFER_ERROR;
+                break;
+        default:
+               usbi_warn(ITRANSFER_CTX(itransfer),
+                        "handle_control_bulk_completion: unrecognised irp status %d", pipeioargs->status);
+                status = LIBUSB_TRANSFER_ERROR;
+                break;
+        }
+
+        usbi_mutex_unlock(&itransfer->lock);
+        return usbi_handle_transfer_completion(itransfer, status);
+}
+
+int
+aix_clock_gettime(int clkid, struct timespec *tp)
+{
+        int rc = 0;
+        usbi_dbg("clock %d", clkid);
+
+        if (clkid == USBI_CLOCK_REALTIME) {
+                rc =  clock_gettime(CLOCK_REALTIME, tp);
+                return rc;
+        }
+
+        if (clkid == USBI_CLOCK_MONOTONIC) {
+                rc =  clock_gettime(CLOCK_MONOTONIC, tp);
+                return rc;
+         
+        }
+
+        usbi_dbg("aix_clock_gettime: Invalid clock id value is %d",clkid);
+        return (LIBUSB_ERROR_INVALID_PARAM);
+}
+
+
+int aix_kernel_driver_active(
+             struct libusb_device_handle *handle,
+             int interface)
+{
+     usbi_dbg("aix_kernel_driver_active:");
+     return 0;
+
+}
+
+int aix_detach_kernel_driver(
+             struct libusb_device_handle *handle,
+             int interface)
+{
+    usbi_dbg("aix_detach_kernel_driver:");
+    return 0;
+
+}
+
+int aix_attach_kernel_driver(
+             struct libusb_device_handle *handle,
+             int interface)
+{
+    usbi_dbg("aix_attach_kernel_driver:");
+    return 0;
+
+}
+
+int
+get_all_config_descriptors(struct aix_device_priv *priv)
+{
+    int fd = 0, rc, irv;
+    PDESCIDX_32 pdescidx;
+    struct confdesc arg;
+    int num_config = 0;
+    PUSBDevDesc devdesc;
+
+    pdescidx = priv->descriptors;
+    devdesc = pdescidx->pDevDesc;
+
+    memset(&arg, 0, sizeof(struct confdesc));
+
+    num_config = devdesc->bNumConfigurations;
+
+    usbi_dbg("get_all_config_descriptors: configurations no:%d", num_config);
+
+    if (num_config <= 1) {
+       return 0;
+    } 
+   
+    /*if (num_config <= 1) {
+        priv->configdesc = malloc();
+        memcpy(buf, (char *)(pdescidx->pConfigDesc), len);
+        
+        return 0;
+    }*/
+   
+    fd = open_aix_libusb_device(priv);
+
+    if (fd < 0) {
+        usbi_dbg("get_all_config_descriptors: Open Failed");
+        return LIBUSB_ERROR_NO_DEVICE;
+    }
+
+    arg.len = 0;
+
+    arg.numconfig = num_config;
+
+    rc = ioctl(fd, USBLIB_GET_CONFIG_DESC, &arg);
+
+    if( rc != 0 )
+    {
+        usbi_err(NULL, "get_all_config_descriptors: ioctl(,USBLIB_GET_CONFIG_DESC,) failed, rc=%d errno=%d",rc,errno);
+        if (errno == ENODEV)
+            return LIBUSB_ERROR_NO_DEVICE;
+        return LIBUSB_ERROR_IO;
+    }
+
+    arg.buf  = (void *)malloc(arg.len);
+
+    if ( ! arg.buf ) {
+       printf("malloc() failed, errno=%d\n",errno);
+       usbi_err(NULL, "get_all_config_descriptors: malloc() failed, errno=%d",errno);
+       return LIBUSB_ERROR_NO_MEM;
+    }
+
+    rc = ioctl(fd, USBLIB_GET_CONFIG_DESC, &arg);
+
+
+    if ( rc != 0 ) {
+       usbi_err(NULL, "get_all_config_descriptors: ioctl(USBLIB_GET_CONFIG_DESC 2) failed, rc=%d errno=%d",rc,errno);
+       free(arg.buf);
+       return -1;
+    }
+
+    priv->configdesc = (void *)malloc(arg.len);
+
+    if ( ! (priv->configdesc) ) {
+       usbi_err(NULL, "get_all_config_descriptors: malloc() failed, errno=%d",errno);
+       free(arg.buf);
+       return LIBUSB_ERROR_NO_MEM;
+    }
+
+    memset(priv->configdesc,0,arg.len);
+
+    memcpy((char *)priv->configdesc, (char *)(arg.buf), arg.len);
+
+    usbi_dbg("get_all_config_descriptors: priv->configdesc:%x config descriptors len:%d",priv->configdesc,arg.len);
+
+    priv->cdesc_len = arg.len;
+
+    free(arg.buf);
+
+    close(fd);
+
+    return 0;
+}
+
+int
+open_aix_libusb_device(struct aix_device_priv *priv)
+{
+
+    DEVSELECTOR devselarg;
+    char connwhere[16];
+    int instance;
+    struct CuDv *cudv_ptr, cudv, *cudv_ptr1;
+    struct CuAt *cuat_ptr, cuat;
+    char   crit[64];
+    char   path[64];
+    char   devname[16];
+    int fd = 0;
+
+    devselarg = priv->devsel;
+
+    /*
+     * obtain the device name from the ODM
+     */
+
+    if (sscanf(priv->hc_name, "usbhc%d", &instance) != 1)
+        return 0;
+
+    sprintf(connwhere, "%d.%d.%d.%d",instance, devselarg.addr,
+                              devselarg.cfg, devselarg.intfc);
+
+    usbi_dbg("open_aix_libusb_device: connwhere: %s",connwhere);
+
+    sprintf(crit, "PdDvLn = 'generic/usbif/usblibke' and connwhere = '%s'",connwhere);
+
+    cudv_ptr = (struct CuDv *)odm_get_first(CuDv_CLASS,crit,&cudv);
+
+    if(cudv_ptr == (struct CuDv *) -1) {
+
+        usbi_err(NULL, "open_aix_libusb_device: Error getting CuDv structure 1");
+        return -1;
+
+    } else if ( cudv_ptr == NULL) {
+
+        sprintf(crit, "parent = 'usb0' and connwhere = '%s'",connwhere);
+
+        cudv_ptr1 = (struct CuDv *)odm_get_first(CuDv_CLASS,crit,&cudv);
+
+        if (cudv_ptr1 == (struct CuDv *) -1) {
+            usbi_err(NULL,"open_aix_libusb_device: Error getting CuDv structure 2");
+            return -1;
+        } else if (cudv_ptr1) {
+            sprintf(crit, "attribute = 'usbdevice' and value = '%s'",cudv.name);
+
+            usbi_dbg("open_aix_libusb_device: crit: %s", crit); 
+
+            cuat_ptr = (struct CuAt *)odm_get_first(CuAt_CLASS, crit, &cuat);
+
+            if((cuat_ptr == (struct CuAt *) -1)) {
+   
+                usbi_err(NULL,"open_aix_libusb_device: Error getting CuAt structure");
+                return LIBUSB_ERROR_IO;
+            } else if (cuat_ptr) {
+                strncpy(devname, cuat.name, 16);
+            } else {
+                return LIBUSB_ERROR_IO;
+            }
+        } else {
+            usbi_err(NULL, "open_aix_libusb_device: No device in CuDv");
+            return LIBUSB_ERROR_IO;
+        }
+     } else {
+         strncpy(devname, cudv.name, 16); 
+     }
+
+
+    /* Open the device now */
+
+    usbi_dbg("open_aix_libusb_device: Device Name: %s errno:%d",devname,errno);
+
+    sprintf(path, "%s/%s",USB_LIB_PATH, devname);
+
+    /* TODO: check if mode is correct */
+    fd = open (path, O_RDWR);
+
+    if (fd < 0) {
+        usbi_err(NULL, "open_aix_libusb_device: Open on %s failed", path);
+        return fd;
+    }
+
+    strncpy(priv->devicename, devname, 16);
+
+    return fd;
+}
+   
diff -uNr libusb-1.0.19/libusb/os/aix_usb.h libusb-1.0.19p/libusb/os/aix_usb.h
--- libusb-1.0.19/libusb/os/aix_usb.h   1969-12-31 18:00:00 -0600
+++ libusb-1.0.19p/libusb/os/aix_usb.h  2016-06-05 05:40:35 -0500
@@ -0,0 +1,179 @@
+#define __64BIT_KERNEL
+
+#include <sys/time.h>
+#include <sys/types.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/systemcfg.h>  /* __KERNEL_32() */
+#include <sys/sysconfig.h>
+#include <sys/ldr.h>
+#include <cf.h>
+
+#include <sys/usb.h>
+#include <sys/types.h>
+#include <sys/syslog.h>
+#include "sys/usbdi.h"
+#include <sys/cfgodm.h>
+#include <sys/cfgdb.h>
+
+#include "libusb.h"
+#include "libusbi.h"
+
+extern struct Class CuDv_CLASS[];
+
+/* There are some handy macros in sys/sysmacros.h, but they
+   are only defined for the kernel. */
+#ifndef DEVTODEV32
+#ifdef __64BIT__
+#include <sys/aixdefs.h>
+#define _KERNEL
+#define _POWER_MP
+#define __64BIT_KERNEL
+#ifndef DEV64TO32
+#define DEV64TO32(_devno)       \
+        ((dev32_t)((((_devno) & 0x0000FFFF00000000LL) >> 16) | \
+                ((_devno) & 0xFFFFLL)))
+#endif /* DEV64TO32 */
+#define DEVTODEV32(_devno)      DEV64TO32(_devno)
+#else /* __64BIT__ */
+#define DEVTODEV32(_devno)      (_devno)
+#endif /* __64BIT__ */
+#endif /* DEVTODEV32 */
+
+
+#define USB_LIB_PATH "/dev"
+
+struct aix_device_priv{
+       char hc_name[8]; /* host controller name */
+       /*dev32_t devno;*/
+       PDESCIDX_32 descriptors;
+       int desc_size;             /* Length of combined all descriptors of a device */
+       unsigned char *configdesc; /* buffer holds entire config descriptor */
+       int cdesc_len;             /* Length of entire config entire descriptors including multiple configurations */
+       int current_config;
+       DEVSELECTOR devsel;
+       char devicename[16];
+};
+
+
+struct aix_transfer_priv {
+        struct aix_pipeio pipeioargs;
+        USBstatus status;
+         #define SUBMITTED 1
+         #define CANCELLED 2 
+         #define COMPLETED 3
+};
+
+
+struct aix_device_handle_priv {
+
+       DEVSELECTOR devsel_handle;
+       int fd;
+       char devicename[16];
+       int transfer_size;
+   
+
+};
+
+/*
+ * Backend functions
+ */
+static int aix_get_device_list(struct libusb_context *,
+    struct discovered_devs **);
+static int aix_open(struct libusb_device_handle *);
+static void aix_close(struct libusb_device_handle *);
+
+static int aix_get_device_descriptor(struct libusb_device *, unsigned char *,
+    int *);
+static int aix_get_active_config_descriptor(struct libusb_device *,
+    unsigned char *, size_t, int *);
+static int aix_get_config_descriptor(struct libusb_device *, uint8_t,
+    unsigned char *, size_t, int *);
+
+static int aix_get_configuration(struct libusb_device_handle *, int *);
+static int aix_set_configuration(struct libusb_device_handle *, int);
+
+static int aix_claim_interface(struct libusb_device_handle *, int);
+static int aix_release_interface(struct libusb_device_handle *, int);
+
+static int aix_set_interface_altsetting(struct libusb_device_handle *, int,
+    int);
+static int aix_clear_halt(struct libusb_device_handle *, unsigned char);
+static int aix_reset_device(struct libusb_device_handle *);
+static void aix_destroy_device(struct libusb_device *);
+
+static int aix_submit_transfer(struct usbi_transfer *);
+static int aix_cancel_transfer(struct usbi_transfer *);
+static int aix_submit_control_transfer(struct usbi_transfer *);
+static void aix_clear_transfer_priv(struct usbi_transfer *);
+static int aix_handle_events(struct libusb_context *ctx, struct pollfd *,
+    nfds_t, int);
+static int add_hc_device(int , char *, int, struct discovered_devs **, struct libusb_context *);
+int aix_get_config_desc_byvalue(struct libusb_device *, uint8_t , unsigned char **, int *);
+static struct aix_device_priv *_device_priv(struct libusb_device *);
+static struct aix_device_handle_priv *_device_handle_priv( struct libusb_device_handle *);
+int get_busnumber(char *);
+int aix_get_irp_data(struct libusb_device_handle *);
+int aix_clock_gettime(int , struct timespec *);
+char * aix_usb_concatenate(char *, char *);
+int aix_pipe_connect(int, struct aix_pipe *);
+int aix_kernel_driver_active(struct libusb_device_handle *, int);
+int aix_detach_kernel_driver(struct libusb_device_handle *, int);
+int aix_attach_kernel_driver(struct libusb_device_handle *, int);
+int get_all_config_descriptors(struct aix_device_priv *);
+int open_aix_libusb_device(struct aix_device_priv *priv);
+static int aix_init(struct libusb_context *ctx);
+void aix_exit(void);
+
+const struct usbi_os_backend aix_backend = {
+	"Synchronous AIX backend",
+	0,
+	aix_init,				/* init() */
+	aix_exit,				/* exit() */
+	aix_get_device_list,
+	NULL,				/* hotplug_poll */
+	aix_open,
+	aix_close,
+
+	aix_get_device_descriptor,
+	aix_get_active_config_descriptor,
+	aix_get_config_descriptor,
+	aix_get_config_desc_byvalue,				/* get_config_descriptor_by_value() */
+
+	aix_get_configuration,
+	aix_set_configuration,
+
+	aix_claim_interface,
+	aix_release_interface,
+
+	aix_set_interface_altsetting,
+	aix_clear_halt,
+	aix_reset_device,
+
+	NULL,				/* alloc_streams */
+	NULL,				/* free_streams */
+
+	aix_kernel_driver_active,       /* kernel_driver_active() */
+	aix_detach_kernel_driver,	/* detach_kernel_driver() */
+	aix_attach_kernel_driver,       /* attach_kernel_driver() */
+
+	aix_destroy_device,
+
+	aix_submit_transfer,
+	aix_cancel_transfer,
+	aix_clear_transfer_priv,
+
+	aix_handle_events,
+
+	aix_clock_gettime,
+	sizeof(struct aix_device_priv),
+	sizeof(struct aix_device_handle_priv),
+	sizeof(struct aix_transfer_priv),	/* transfer_priv_size */
+	0,				/* add_iso_packet_size */
+};
+
