summaryrefslogtreecommitdiff
path: root/usb
diff options
context:
space:
mode:
Diffstat (limited to 'usb')
-rw-r--r--usb/45-Argyll.rules62
-rw-r--r--usb/55-Argyll.rules90
-rw-r--r--usb/Argyll9
-rw-r--r--usb/Argyll.kext/Info.plist30
-rw-r--r--usb/Argyll.usermap53
-rw-r--r--usb/ArgyllCMS.cat3
-rw-r--r--usb/ArgyllCMS.inf213
-rw-r--r--usb/ArgyllCMS.inf.d34
-rw-r--r--usb/ArgyllCMS.inf.t111
-rw-r--r--usb/ArgyllCMS_x64.cat3
-rw-r--r--usb/Jamfile52
-rw-r--r--usb/Readme.txt8
-rw-r--r--usb/afiles60
-rw-r--r--usb/bin/amd64/libusb0.sysbin0 -> 52832 bytes
-rw-r--r--usb/bin/ia64/libusb0.sysbin0 -> 110176 bytes
-rw-r--r--usb/bin/libusb-win32-bin-README.txt27
-rw-r--r--usb/bin/x86/libusb0.sysbin0 -> 42592 bytes
-rw-r--r--usb/binfiles.lx4
-rw-r--r--usb/binfiles.msw6
-rw-r--r--usb/binfiles.osx2
-rw-r--r--usb/driver/AUTHORS.txt16
-rw-r--r--usb/driver/COPYING_GPL.txt674
-rw-r--r--usb/driver/LICENSE.txt9
-rw-r--r--usb/driver/Makefile261
-rw-r--r--usb/driver/README.txt12
-rw-r--r--usb/driver/abort_endpoint.c56
-rw-r--r--usb/driver/claim_interface.c89
-rw-r--r--usb/driver/clear_feature.c64
-rw-r--r--usb/driver/dispatch.c99
-rw-r--r--usb/driver/driver_api.h400
-rw-r--r--usb/driver/driver_debug.c75
-rw-r--r--usb/driver/driver_debug.h30
-rw-r--r--usb/driver/driver_registry.c376
-rw-r--r--usb/driver/get_configuration.c56
-rw-r--r--usb/driver/get_descriptor.c289
-rw-r--r--usb/driver/get_interface.c109
-rw-r--r--usb/driver/get_status.c74
-rw-r--r--usb/driver/ioctl.c795
-rw-r--r--usb/driver/libusb-win32-README-1.2.6.0.txt239
-rw-r--r--usb/driver/libusb_driver.c971
-rw-r--r--usb/driver/libusb_driver.h429
-rw-r--r--usb/driver/libusb_driver_rc.rc25
-rw-r--r--usb/driver/lusb_defdi_guids.h45
-rw-r--r--usb/driver/pnp.c302
-rw-r--r--usb/driver/power.c269
-rw-r--r--usb/driver/release_interface.c105
-rw-r--r--usb/driver/reset_device.c56
-rw-r--r--usb/driver/reset_endpoint.c56
-rw-r--r--usb/driver/set_configuration.c205
-rw-r--r--usb/driver/set_descriptor.c71
-rw-r--r--usb/driver/set_feature.c67
-rw-r--r--usb/driver/set_interface.c124
-rw-r--r--usb/driver/transfer.c1493
-rw-r--r--usb/driver/usbd.def35
-rw-r--r--usb/driver/usbdlib_gcc.h310
-rw-r--r--usb/driver/vendor_request.c143
-rw-r--r--usb/install_kext.sh6
57 files changed, 9202 insertions, 0 deletions
diff --git a/usb/45-Argyll.rules b/usb/45-Argyll.rules
new file mode 100644
index 0000000..3f89f69
--- /dev/null
+++ b/usb/45-Argyll.rules
@@ -0,0 +1,62 @@
+# udev rule to change permissions so that the USB instruments can be accessed by Argyll
+# where the udev is old and doesn't understand the more modern syntax in 55-Argyll.rules.
+# Copy to /etc/udev/rules.d/45-Argyll.rules
+
+# Colorimtre HCFR
+SYSFS{idVendor}=="04db", SYSFS{idProduct}=="005b", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# MonacoOPTIX (Same as i1 Display 1)
+SYSFS{idVendor}=="0670", SYSFS{idProduct}=="0001", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+
+# Huey (Lenovo W70DS Laptop ?)
+SYSFS{idVendor}=="0765", SYSFS{idProduct}=="5001", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# Huey (Lenovo W530 Laptop ?)
+SYSFS{idVendor}=="0765", SYSFS{idProduct}=="5010", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# i1Display 3
+SYSFS{idVendor}=="0765", SYSFS{idProduct}=="5020", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# ColorMunki Smile
+SYSFS{idVendor}=="0765", SYSFS{idProduct}=="6003", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# DTP20
+SYSFS{idVendor}=="0765", SYSFS{idProduct}=="d020", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# DTP92Q - not tested
+SYSFS{idVendor}=="0765", SYSFS{idProduct}=="d092", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# DTP94
+SYSFS{idVendor}=="0765", SYSFS{idProduct}=="d094", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# Spyder 1
+SYSFS{idVendor}=="085c", SYSFS{idProduct}=="0100", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# Spyder 2
+SYSFS{idVendor}=="085c", SYSFS{idProduct}=="0200", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# Spyder 3
+SYSFS{idVendor}=="085c", SYSFS{idProduct}=="0300", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# Spyder 4
+SYSFS{idVendor}=="085c", SYSFS{idProduct}=="0400", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# i1Pro
+SYSFS{idVendor}=="0971", SYSFS{idProduct}=="2000", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# i1Monitor
+SYSFS{idVendor}=="0971", SYSFS{idProduct}=="2001", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# i1Display
+SYSFS{idVendor}=="0971", SYSFS{idProduct}=="2003", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# Huey
+SYSFS{idVendor}=="0971", SYSFS{idProduct}=="2005", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# ColorMunki
+SYSFS{idVendor}=="0971", SYSFS{idProduct}=="2007", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+
+# ColorHug
+SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="f8da", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
+SYSFS{idVendor}=="273f", SYSFS{idProduct}=="1001", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", MODE="660", GROUP="plugdev"
diff --git a/usb/55-Argyll.rules b/usb/55-Argyll.rules
new file mode 100644
index 0000000..9e083dc
--- /dev/null
+++ b/usb/55-Argyll.rules
@@ -0,0 +1,90 @@
+# udev rule to recognize instruments and make them accessible to user applications.
+# Copy this to /etc/udev/rules.d/55-Argyll.rules
+
+# Skip all this to speed things up if it'a not a usb add.
+ACTION!="add", GOTO="argyll_rules_end"
+SUBSYSTEM!="usb", GOTO="argyll_rules_end"
+
+# Recognize the color measurement devices
+
+# Colorimtre HCFR
+ATTRS{idVendor}=="04db", ATTRS{idProduct}=="005b", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+
+# MonacoOPTIX (Same as i1 Display 1)
+ATTRS{idVendor}=="0670", ATTRS{idProduct}=="0001", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+
+# HueyL (not tested)
+ATTRS{idVendor}=="0765", ATTRS{idProduct}=="5001", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# HueyL (not tested)
+ATTRS{idVendor}=="0765", ATTRS{idProduct}=="5010", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# i1Display 3
+ATTRS{idVendor}=="0765", ATTRS{idProduct}=="5020", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# ColorMunki Smile
+ATTRS{idVendor}=="0765", ATTRS{idProduct}=="6003", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# DTP20
+ATTRS{idVendor}=="0765", ATTRS{idProduct}=="d020", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# DTP92Q (not tested)
+ATTRS{idVendor}=="0765", ATTRS{idProduct}=="d092", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# DTP94
+ATTRS{idVendor}=="0765", ATTRS{idProduct}=="d094", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+
+# i1Pro
+ATTRS{idVendor}=="0971", ATTRS{idProduct}=="2000", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# i1Monitor
+ATTRS{idVendor}=="0971", ATTRS{idProduct}=="2001", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# i1Display
+ATTRS{idVendor}=="0971", ATTRS{idProduct}=="2003", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# i1 io table (not tested)
+ATTRS{idVendor}=="0971", ATTRS{idProduct}=="2004", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# Huey
+ATTRS{idVendor}=="0971", ATTRS{idProduct}=="2005", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# i1 iSis (not tested)
+ATTRS{idVendor}=="0971", ATTRS{idProduct}=="2006", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# ColorMunki
+ATTRS{idVendor}=="0971", ATTRS{idProduct}=="2007", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+
+# Spyder 1
+ATTRS{idVendor}=="085c", ATTRS{idProduct}=="0100", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# Spyder 2
+ATTRS{idVendor}=="085c", ATTRS{idProduct}=="0200", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# Spyder 3
+ATTRS{idVendor}=="085c", ATTRS{idProduct}=="0300", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+# Spyder 4
+ATTRS{idVendor}=="085c", ATTRS{idProduct}=="0400", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+
+# ColorHug, old and new
+ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="f8da", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+ATTRS{idVendor}=="273f", ATTRS{idProduct}=="1001", ENV{COLOR_MEASUREMENT_DEVICE}="1"
+
+
+# Let users access these devices
+ENV{COLOR_MEASUREMENT_DEVICE}=="*?", TAG+="uaccess"
+
+# Otherwise, restrict access to members of the plugdev group,
+# which the user may have to add to the system.
+ENV{COLOR_MEASUREMENT_DEVICE}=="*?", MODE="660", GROUP="plugdev"
+
+# Set ID_VENDOR and ID_MODEL acording to VID and PID
+IMPORT{builtin}="hwdb --subsystem=usb"
+
+LABEL="argyll_rules_end"
diff --git a/usb/Argyll b/usb/Argyll
new file mode 100644
index 0000000..b16d929
--- /dev/null
+++ b/usb/Argyll
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Copy to /etc/hotplug/usb/Argyll
+#
+# Argyll hotplug script. Adds the USB devices to the plugdev group.
+if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
+then
+ chgrp plugdev "${DEVICE}"
+ chmod 660 "${DEVICE}"
+fi
diff --git a/usb/Argyll.kext/Info.plist b/usb/Argyll.kext/Info.plist
new file mode 100644
index 0000000..754e6d5
--- /dev/null
+++ b/usb/Argyll.kext/Info.plist
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key> <string>English</string>
+ <key>CFBundleGetInfoString</key> <string>Libusb USB device Shield</string>
+ <key>CFBundleIdentifier</key> <string>com.libusb.USB_Shield</string>
+ <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string>
+ <key>CFBundleName</key> <string>Libusb USB device Shield</string>
+ <key>CFBundlePackageType</key> <string>KEXT</string>
+ <key>CFBundleSignature</key> <string>????</string>
+ <key>CFBundleVersion</key> <string>6.0</string>
+ <key>IOKitPersonalities</key>
+ <dict>
+ <key>HCFR</key>
+ <dict>
+ <key>CFBundleIdentifier</key> <string>com.apple.driver.AppleUSBComposite</string>
+ <key>IOClass</key> <string>AppleUSBComposite</string>
+ <key>IOProviderClass</key> <string>IOUSBDevice</string>
+ <key>idVendor</key> <integer>1243</integer>
+ <key>idProduct</key> <integer>91</integer>
+ </dict>
+ </dict>
+ <key>OSBundleCompatibleVersion</key> <string>1.8</string>
+ <key>OSBundleLibraries</key>
+ <dict>
+ <key>com.apple.kernel.iokit</key> <string>6.0</string>
+ </dict>
+</dict>
+</plist>
diff --git a/usb/Argyll.usermap b/usb/Argyll.usermap
new file mode 100644
index 0000000..00a350c
--- /dev/null
+++ b/usb/Argyll.usermap
@@ -0,0 +1,53 @@
+# hotplug device mapping to handling script.
+# Copy this to /etc/hotplug/usb/Argyll.usermap
+#
+# Detect instruments by their USB VID and PID
+#
+# DTP20
+Argyll 0x0003 0x0765 0xd020 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# DTP92Q - not tested
+Argyll 0x0003 0x0765 0xd092 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# DTP94
+Argyll 0x0003 0x0765 0xd094 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# MonacoOPTIX (Same as i1 Display 1)
+Argyll 0x0003 0x0670 0x0001 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# i1 Display
+Argyll 0x0003 0x0971 0x2003 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# i1 Display 3
+Argyll 0x0003 0x0765 0x5020 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# i1 Monitor
+Argyll 0x0003 0x0971 0x2001 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# i1 Pro
+Argyll 0x0003 0x0971 0x2000 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# ColorMunki
+Argyll 0x0003 0x0971 0x2007 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# ColorMunki Smile
+Argyll 0x0003 0x0765 0x6003 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# Colorimtre HCFR
+Argyll 0x0003 0x04DB 0x005B 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# Spyder 2
+Argyll 0x0003 0x085C 0x0200 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# Spyder 3
+Argyll 0x0003 0x085C 0x0300 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# Spyder 4
+Argyll 0x0003 0x085C 0x0400 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# Huey
+Argyll 0x0003 0x0971 0x2005 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+#
+# ColorHug
+Argyll 0x0003 0x04D8 0xF8DA 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
+Argyll 0x0003 0x273F 0x1001 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
diff --git a/usb/ArgyllCMS.cat b/usb/ArgyllCMS.cat
new file mode 100644
index 0000000..d401490
--- /dev/null
+++ b/usb/ArgyllCMS.cat
@@ -0,0 +1,3 @@
+This file will contain the digital signature of the files to be installed
+on the system.
+This file will be provided by Microsoft upon certification of your drivers.
diff --git a/usb/ArgyllCMS.inf b/usb/ArgyllCMS.inf
new file mode 100644
index 0000000..64f5eca
--- /dev/null
+++ b/usb/ArgyllCMS.inf
@@ -0,0 +1,213 @@
+;--------------------------------------------------------------------------
+; Copyright 2012 Graeme W. Gill.
+;
+; Permission is hereby granted, free of charge, to any person obtaining a copy
+; of this file, to deal
+; in this file without restriction, including without limitation the rights
+; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of this file, and to permit persons to whom this file is
+; furnished to do so, subject to the following conditions:
+;
+; The above copyright notice and this permission notice shall be included in
+; all copies or substantial portions of this file.
+;
+; THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+; OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS IN
+; THIS FILE.
+;--------------------------------------------------------------------------
+
+; ==== Strings ====
+
+[Strings]
+
+DeviceGUID = {247e32a0-32f9-11df-aacc-0002a5d5c51b}
+
+Date = "01/17/2012" ; MM/DD/YYYY
+libusb0ver = "1.2.6.0"
+
+Libusb_ClassName = "Argyll LibUSB-win32 devices"
+Libusb_DiskName = "LibUSB-win32 Device Install Disk"
+
+libusb0_SvcDesc = "LibUSB-win32 libusb0 - Kernel Driver 2012/1/17, 1.2.6.0"
+
+; ==== Version ====
+
+[Version]
+Signature = "$Windows NT$"
+DriverVer = %Date%,%libusb0ver%
+Provider = "ArgyllCMS"
+
+; (Note the ClassGuid must not be quoted or a string substitution to work on Win2K)
+Class = %Libusb_ClassName%
+ClassGuid = {817cffe0-328b-11df-9b9f-0002a5d5c51b} ; LibUSB-win32 ClassGUID
+CatalogFile = "ArgyllCMS.cat"
+CatalogFile.NTAMD64 = "ArgyllCMS_x64.cat"
+
+[ClassInstall32]
+AddReg=class_install_add_reg
+
+[class_install_add_reg]
+HKR,,,,%Libusb_ClassName%
+HKR,,Icon,,"-20" ; -20 is for the USB icon
+
+; ==== Files Sources and Destinations ====
+
+[SourceDisksNames]
+1 = %Libusb_DiskName%
+
+[SourceDisksFiles]
+libusb0.sys = 1,\bin\x86,
+
+[SourceDisksFiles.amd64]
+libusb0.sys = 1,\bin\amd64,
+
+[DestinationDirs]
+libusb0_files_sys = 10,system32\drivers
+
+; ==== libusb0 Device driver ====
+
+[libusb0_files_sys]
+libusb0.sys,libusb0.sys
+
+; For each one of these, there must be one for Services !!!
+[LIBUSB0_DEV]
+CopyFiles = Libusb0_files_sys
+
+[LIBUSB0_DEV.HW]
+AddReg = libusb0_add_reg_hw
+
+[libusb0_add_reg]
+HKR,,DevLoader,,*ntkern
+HKR,,NTMPDriver,,libusb0.sys
+
+[libusb0_add_reg_hw]
+HKR,,DeviceInterfaceGUIDs,0x10000,%DeviceGUID%
+HKR,,SurpriseRemovalOK,0x00010001,1 ; Device properties
+
+[LIBUSB0_DEV.Services]
+AddService = libusb0, 0x00000002, libusb0_add_service
+
+[libusb0_add_service]
+DisplayName = %libusb0_SvcDesc%
+ServiceType = 1
+StartType = 3
+ErrorControl = 0
+ServiceBinary = %12%\libusb0.sys
+
+; ==== Manufacturers ====
+
+[Manufacturer]
+"HCFR Association"=HCFR_Devices,NTx86,NTamd64
+"Sequel Imaging"=Sequel_Devices,NTx86,NTamd64
+"X-Rite"=X_Rite_Devices,NTx86,NTamd64
+"ColorVision"=ColorVision_Devices,NTx86,NTamd64
+"Gretag Macbeth/X-Rite"=GM_X_Rite_Devices,NTx86,NTamd64
+"Hughski Ltd"=Hughski_Devices,NTx86,NTamd64
+
+; ==== Devices ====
+
+[HCFR_Devices]
+"Colorimtre HCFR V3.1 (Argyll)" = LIBUSB0_DEV, USB\VID_04DB&PID_005B
+"Colorimtre HCFR V4.0 (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_FE17
+
+[Sequel_Devices]
+"Eye-One Display 1 (Argyll)" = LIBUSB0_DEV, USB\VID_0670&PID_0001
+
+[X_Rite_Devices]
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5001
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5010
+"Eye-One Display 3 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5020
+"ColorMunki Smile (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_6003
+"DTP20 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D020
+"DTP92Q (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D092
+"DTP94 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D094
+
+[ColorVision_Devices]
+"Spyder1 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0100
+"Spyder2 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0200
+"Spyder3 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0300
+"Spyder4 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0400
+
+[GM_X_Rite_Devices]
+"Eye-One Pro (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2000
+"Eye-One Monitor (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2001
+"Eye-One Display 2 (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2003
+"Huey (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2005
+"ColorMunki (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2007
+
+[Hughski_Devices]
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_273F&PID_1001
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_F8DA
+
+
+[HCFR_Devices.NTx86]
+"Colorimtre HCFR V3.1 (Argyll)" = LIBUSB0_DEV, USB\VID_04DB&PID_005B
+"Colorimtre HCFR V4.0 (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_FE17
+
+[Sequel_Devices.NTx86]
+"Eye-One Display 1 (Argyll)" = LIBUSB0_DEV, USB\VID_0670&PID_0001
+
+[X_Rite_Devices.NTx86]
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5001
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5010
+"Eye-One Display 3 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5020
+"ColorMunki Smile (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_6003
+"DTP20 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D020
+"DTP92Q (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D092
+"DTP94 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D094
+
+[ColorVision_Devices.NTx86]
+"Spyder1 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0100
+"Spyder2 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0200
+"Spyder3 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0300
+"Spyder4 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0400
+
+[GM_X_Rite_Devices.NTx86]
+"Eye-One Pro (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2000
+"Eye-One Monitor (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2001
+"Eye-One Display 2 (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2003
+"Huey (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2005
+"ColorMunki (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2007
+
+[Hughski_Devices.NTx86]
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_273F&PID_1001
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_F8DA
+
+
+[HCFR_Devices.NTamd64]
+"Colorimtre HCFR V3.1 (Argyll)" = LIBUSB0_DEV, USB\VID_04DB&PID_005B
+"Colorimtre HCFR V4.0 (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_FE17
+
+[Sequel_Devices.NTamd64]
+"Eye-One Display 1 (Argyll)" = LIBUSB0_DEV, USB\VID_0670&PID_0001
+
+[X_Rite_Devices.NTamd64]
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5001
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5010
+"Eye-One Display 3 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5020
+"ColorMunki Smile (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_6003
+"DTP20 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D020
+"DTP92Q (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D092
+"DTP94 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D094
+
+[ColorVision_Devices.NTamd64]
+"Spyder1 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0100
+"Spyder2 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0200
+"Spyder3 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0300
+"Spyder4 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0400
+
+[GM_X_Rite_Devices.NTamd64]
+"Eye-One Pro (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2000
+"Eye-One Monitor (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2001
+"Eye-One Display 2 (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2003
+"Huey (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2005
+"ColorMunki (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2007
+
+[Hughski_Devices.NTamd64]
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_273F&PID_1001
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_F8DA
+
diff --git a/usb/ArgyllCMS.inf.d b/usb/ArgyllCMS.inf.d
new file mode 100644
index 0000000..cb7eb5d
--- /dev/null
+++ b/usb/ArgyllCMS.inf.d
@@ -0,0 +1,34 @@
+
+[HCFR_Devices#PLAT#]
+"Colorimtre HCFR V3.1 (Argyll)" = LIBUSB0_DEV, USB\VID_04DB&PID_005B
+"Colorimtre HCFR V4.0 (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_FE17
+
+[Sequel_Devices#PLAT#]
+"Eye-One Display 1 (Argyll)" = LIBUSB0_DEV, USB\VID_0670&PID_0001
+
+[X_Rite_Devices#PLAT#]
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5001
+"HueyL (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5010
+"Eye-One Display 3 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_5020
+"ColorMunki Smile (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_6003
+"DTP20 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D020
+"DTP92Q (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D092
+"DTP94 (Argyll)" = LIBUSB0_DEV, USB\VID_0765&PID_D094
+
+[ColorVision_Devices#PLAT#]
+"Spyder1 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0100
+"Spyder2 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0200
+"Spyder3 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0300
+"Spyder4 (Argyll)" = LIBUSB0_DEV, USB\VID_085C&PID_0400
+
+[GM_X_Rite_Devices#PLAT#]
+"Eye-One Pro (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2000
+"Eye-One Monitor (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2001
+"Eye-One Display 2 (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2003
+"Huey (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2005
+"ColorMunki (Argyll)" = LIBUSB0_DEV, USB\VID_0971&PID_2007
+
+[Hughski_Devices#PLAT#]
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_273F&PID_1001
+"ColorHug (Argyll)" = LIBUSB0_DEV, USB\VID_04D8&PID_F8DA
+
diff --git a/usb/ArgyllCMS.inf.t b/usb/ArgyllCMS.inf.t
new file mode 100644
index 0000000..d810d4f
--- /dev/null
+++ b/usb/ArgyllCMS.inf.t
@@ -0,0 +1,111 @@
+;--------------------------------------------------------------------------
+; Copyright 2012 Graeme W. Gill.
+;
+; Permission is hereby granted, free of charge, to any person obtaining a copy
+; of this file, to deal
+; in this file without restriction, including without limitation the rights
+; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of this file, and to permit persons to whom this file is
+; furnished to do so, subject to the following conditions:
+;
+; The above copyright notice and this permission notice shall be included in
+; all copies or substantial portions of this file.
+;
+; THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+; OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS IN
+; THIS FILE.
+;--------------------------------------------------------------------------
+
+; ==== Strings ====
+
+[Strings]
+
+DeviceGUID = {247e32a0-32f9-11df-aacc-0002a5d5c51b}
+
+Date = "01/17/2012" ; MM/DD/YYYY
+libusb0ver = "1.2.6.0"
+
+Libusb_ClassName = "Argyll LibUSB-win32 devices"
+Libusb_DiskName = "LibUSB-win32 Device Install Disk"
+
+libusb0_SvcDesc = "LibUSB-win32 libusb0 - Kernel Driver 2012/1/17, 1.2.6.0"
+
+; ==== Version ====
+
+[Version]
+Signature = "$Windows NT$"
+DriverVer = %Date%,%libusb0ver%
+Provider = "ArgyllCMS"
+
+; (Note the ClassGuid must not be quoted or a string substitution to work on Win2K)
+Class = %Libusb_ClassName%
+ClassGuid = {817cffe0-328b-11df-9b9f-0002a5d5c51b} ; LibUSB-win32 ClassGUID
+CatalogFile = "ArgyllCMS.cat"
+CatalogFile.NTAMD64 = "ArgyllCMS_x64.cat"
+
+[ClassInstall32]
+AddReg=class_install_add_reg
+
+[class_install_add_reg]
+HKR,,,,%Libusb_ClassName%
+HKR,,Icon,,"-20" ; -20 is for the USB icon
+
+; ==== Files Sources and Destinations ====
+
+[SourceDisksNames]
+1 = %Libusb_DiskName%
+
+[SourceDisksFiles]
+libusb0.sys = 1,\bin\x86,
+
+[SourceDisksFiles.amd64]
+libusb0.sys = 1,\bin\amd64,
+
+[DestinationDirs]
+libusb0_files_sys = 10,system32\drivers
+
+; ==== libusb0 Device driver ====
+
+[libusb0_files_sys]
+libusb0.sys,libusb0.sys
+
+; For each one of these, there must be one for Services !!!
+[LIBUSB0_DEV]
+CopyFiles = Libusb0_files_sys
+
+[LIBUSB0_DEV.HW]
+AddReg = libusb0_add_reg_hw
+
+[libusb0_add_reg]
+HKR,,DevLoader,,*ntkern
+HKR,,NTMPDriver,,libusb0.sys
+
+[libusb0_add_reg_hw]
+HKR,,DeviceInterfaceGUIDs,0x10000,%DeviceGUID%
+HKR,,SurpriseRemovalOK,0x00010001,1 ; Device properties
+
+[LIBUSB0_DEV.Services]
+AddService = libusb0, 0x00000002, libusb0_add_service
+
+[libusb0_add_service]
+DisplayName = %libusb0_SvcDesc%
+ServiceType = 1
+StartType = 3
+ErrorControl = 0
+ServiceBinary = %12%\libusb0.sys
+
+; ==== Manufacturers ====
+
+[Manufacturer]
+"HCFR Association"=HCFR_Devices,NTx86,NTamd64
+"Sequel Imaging"=Sequel_Devices,NTx86,NTamd64
+"X-Rite"=X_Rite_Devices,NTx86,NTamd64
+"ColorVision"=ColorVision_Devices,NTx86,NTamd64
+"Gretag Macbeth/X-Rite"=GM_X_Rite_Devices,NTx86,NTamd64
+"Hughski Ltd"=Hughski_Devices,NTx86,NTamd64
+
+; ==== Devices ====
diff --git a/usb/ArgyllCMS_x64.cat b/usb/ArgyllCMS_x64.cat
new file mode 100644
index 0000000..d401490
--- /dev/null
+++ b/usb/ArgyllCMS_x64.cat
@@ -0,0 +1,3 @@
+This file will contain the digital signature of the files to be installed
+on the system.
+This file will be provided by Microsoft upon certification of your drivers.
diff --git a/usb/Jamfile b/usb/Jamfile
new file mode 100644
index 0000000..403e3f2
--- /dev/null
+++ b/usb/Jamfile
@@ -0,0 +1,52 @@
+
+# JAM style makefile for libusb-win32, to create .inf files.
+
+# This doesn't make the drivers themselves.
+# (you need the Server 2003 DDK 64 & 32 bit build enironmantes,
+# and then run ddk_build.cmd. This will then run
+# build in libusb/os. )
+
+#PREF_CCFLAGS = $(CCOPTFLAG) ; # Turn optimisation on
+PREF_CCFLAGS = $(CCDEBUGFLAG) ; # Debugging flags
+#PREF_CCFLAGS = $(CCHEAPDEBUG) ; # Heap Debugging flags
+PREF_LINKFLAGS = $(LINKDEBUGFLAG) ; # Link debugging flags
+
+#Products
+#Libraries = ;
+#Executables = ;
+#Headers = ;
+
+#Install
+#InstallBin $(DESTDIR)$(PREFIX)/bin : $(Executables) ;
+#InstallFile $(DESTDIR)$(PREFIX)/h : $(Headers) ;
+#InstallLib $(DESTDIR)$(PREFIX)/lib : $(Libraries) ;
+
+if [ GLOB $(PATH) : sed sed.exe ] {
+ Echo "sed seems to be available" ;
+ CREATE_INFS = true ;
+} else {
+ CREATE_INFS = false ;
+}
+
+# Create ArgyllCMS.inf from the template and device list
+if $(CREATE_INFS) = true {
+ local _i _t _d ;
+ NDepends files : ArgyllCMS.inf ;
+ NDepends install : ArgyllCMS.inf ArgyllCMS.cat ArgyllCMS_x64.cat ;
+
+ _i = [ NormPaths ArgyllCMS.inf ] ;
+ _t = [ NormPaths ArgyllCMS.inf.t ] ;
+ _d = [ NormPaths ArgyllCMS.inf.d ] ;
+
+ File ArgyllCMS.inf : ArgyllCMS.inf.t ;
+ GenFileNND ArgyllCMS.inf : "sed s/#PLAT#// $(_d) >> $(_i)" : ArgyllCMS.inf.t ArgyllCMS.inf.d ;
+ GenFileNND ArgyllCMS.inf : "sed s/#PLAT#/.NTx86/ $(_d) >> $(_i)" : ArgyllCMS.inf.t ArgyllCMS.inf.d ;
+ GenFileNND ArgyllCMS.inf : "sed s/#PLAT#/.NTamd64/ $(_d) >> $(_i)" : ArgyllCMS.inf.t ArgyllCMS.inf.d ;
+}
+
+
+
+
+
+
+
diff --git a/usb/Readme.txt b/usb/Readme.txt
new file mode 100644
index 0000000..999db32
--- /dev/null
+++ b/usb/Readme.txt
@@ -0,0 +1,8 @@
+
+Here are the necessary files to install the MSWin
+instrument device drivers, and build the spectro/usbio_nt
+library that uses the device drivers.
+
+The source to the kernel driver is here, but not built with
+Argyll. The pre-built, signed drivers are used.
+
diff --git a/usb/afiles b/usb/afiles
new file mode 100644
index 0000000..fe1116b
--- /dev/null
+++ b/usb/afiles
@@ -0,0 +1,60 @@
+afiles
+binfiles.msw
+binfiles.osx
+binfiles.lx
+Readme.txt
+Jamfile
+45-Argyll.rules
+55-Argyll.rules
+Argyll
+Argyll.usermap
+Argyll.kext/Info.plist
+install_kext.sh
+ArgyllCMS.inf
+ArgyllCMS.cat
+ArgyllCMS_x64.cat
+ArgyllCMS.inf.t
+ArgyllCMS.inf.d
+bin/libusb-win32-bin-README.txt
+bin/amd64/libusb0.sys
+bin/ia64/libusb0.sys
+bin/x86/libusb0.sys
+driver/libusb-win32-README-1.2.6.0.txt
+driver/LICENSE.txt
+driver/README.txt
+driver/AUTHORS.txt
+driver/COPYING_GPL.txt
+driver/Makefile
+driver/abort_endpoint.c
+driver/claim_interface.c
+driver/clear_feature.c
+driver/dispatch.c
+driver/driver_api.h
+driver/driver_debug.c
+driver/driver_debug.h
+driver/driver_registry.c
+driver/get_configuration.c
+driver/get_descriptor.c
+driver/get_interface.c
+driver/get_status.c
+driver/ioctl.c
+driver/libusb_driver.c
+driver/libusb_driver.h
+driver/libusb_driver_rc.rc
+driver/lusb_defdi_guids.h
+driver/pnp.c
+driver/power.c
+driver/release_interface.c
+driver/reset_device.c
+driver/reset_endpoint.c
+driver/set_configuration.c
+driver/set_descriptor.c
+driver/set_feature.c
+driver/set_interface.c
+driver/transfer.c
+driver/usbd.def
+driver/usbdlib_gcc.h
+driver/vendor_request.c
+
+
+
diff --git a/usb/bin/amd64/libusb0.sys b/usb/bin/amd64/libusb0.sys
new file mode 100644
index 0000000..0718dfb
--- /dev/null
+++ b/usb/bin/amd64/libusb0.sys
Binary files differ
diff --git a/usb/bin/ia64/libusb0.sys b/usb/bin/ia64/libusb0.sys
new file mode 100644
index 0000000..f17914b
--- /dev/null
+++ b/usb/bin/ia64/libusb0.sys
Binary files differ
diff --git a/usb/bin/libusb-win32-bin-README.txt b/usb/bin/libusb-win32-bin-README.txt
new file mode 100644
index 0000000..455eb6b
--- /dev/null
+++ b/usb/bin/libusb-win32-bin-README.txt
@@ -0,0 +1,27 @@
+libusb-win32-bin v1.2.6.0 (01/17/2012) - [Package Information]
+
+ALL ARCHITECTURES:
+ x86\libusb0_x86.dll: x86 32-bit library. Must be renamed to libusb0.dll
+ On 64 bit, Installs to Windows\syswow64\libusb0.dll.
+ On 32 bit, Installs to Windows\system32\libusb0.dll.
+
+ x86\inf-wizard.exe: inf-wizard application with embedded libusb-win32
+ v1.2.6.0 binaries.
+
+X86 ONLY ARCHITECTURES:
+ x86\libusb0.sys: x86 32-bit driver.
+ Installs to Windows\system32\drivers\libusb0.sys
+
+AMD64-INTEL64 ONLY ARCHITECTURES:
+ amd64\libusb0.sys: x64 64-bit driver.
+ Installs to Windows\system32\drivers\libusb0.sys
+
+ amd64\libusb0.dll: x64 64-bit library.
+ Installs to Windows\system32\libusb0.dll
+
+IA64 ONLY ARCHITECTURES:
+ ia64\libusb0.sys: IA64 64-bit driver.
+ Installs to Windows\system32\drivers\libusb0.sys
+
+ ia64\libusb0.dll: IA64 64-bit library.
+ Installs to Windows\system32\libusb0.dll
diff --git a/usb/bin/x86/libusb0.sys b/usb/bin/x86/libusb0.sys
new file mode 100644
index 0000000..5322e5b
--- /dev/null
+++ b/usb/bin/x86/libusb0.sys
Binary files differ
diff --git a/usb/binfiles.lx b/usb/binfiles.lx
new file mode 100644
index 0000000..7dd8767
--- /dev/null
+++ b/usb/binfiles.lx
@@ -0,0 +1,4 @@
+45-Argyll.rules
+55-Argyll.rules
+Argyll
+Argyll.usermap
diff --git a/usb/binfiles.msw b/usb/binfiles.msw
new file mode 100644
index 0000000..f498d92
--- /dev/null
+++ b/usb/binfiles.msw
@@ -0,0 +1,6 @@
+bin/libusb-win32-bin-README.txt
+bin/x86/libusb0.sys
+bin/amd64/libusb0.sys
+ArgyllCMS.cat
+ArgyllCMS.inf
+ArgyllCMS_x64.cat
diff --git a/usb/binfiles.osx b/usb/binfiles.osx
new file mode 100644
index 0000000..60ed4ec
--- /dev/null
+++ b/usb/binfiles.osx
@@ -0,0 +1,2 @@
+Argyll.kext/Info.plist
+install_kext.sh
diff --git a/usb/driver/AUTHORS.txt b/usb/driver/AUTHORS.txt
new file mode 100644
index 0000000..375ec6c
--- /dev/null
+++ b/usb/driver/AUTHORS.txt
@@ -0,0 +1,16 @@
+
+Library, Test Programs:
+
+Stephan Meyer, <ste_meyer@web.de>
+Johannes Erdfelt, <johannes@erdfelt.com>
+Thomas Sailer, <sailer@ife.ee.ethz.ch>
+
+Drivers, Installer:
+
+Stephan Meyer, <ste_meyer@web.de>
+Travis Robinson, <libusbdotnet@gmail.com>
+
+Testing, Technical support:
+
+Xiaofan Chen, <xiaofanc@gmail.com>
+
diff --git a/usb/driver/COPYING_GPL.txt b/usb/driver/COPYING_GPL.txt
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/usb/driver/COPYING_GPL.txt
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/usb/driver/LICENSE.txt b/usb/driver/LICENSE.txt
new file mode 100644
index 0000000..d8dd99d
--- /dev/null
+++ b/usb/driver/LICENSE.txt
@@ -0,0 +1,9 @@
+
+The library (DLL) is distributed under the terms of the GNU Lesser General Public License (LGPL).
+
+All other components (drivers, services, installer) are distributed under the terms of the GNU General Public License (GPL).
+
+This license combination explicitly allows the use of this library in commercial, non Open Source applications. Read the licenses carefully and apply all of their requirements before including this library in a commercial application!
+
+[ Taken from the libsub-win32 web page <http://libusb-win32.sourceforge.net./#license>
+ on the 14th of December 2007 - GWG ]
diff --git a/usb/driver/Makefile b/usb/driver/Makefile
new file mode 100644
index 0000000..18937ab
--- /dev/null
+++ b/usb/driver/Makefile
@@ -0,0 +1,261 @@
+# LIBUSB-WIN32, Generic Windows USB Library
+# Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+# Copyright (c) 2010 Travis Robinson <libusbdotnet@gmail.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+# Supported arugments: all, dll, filter, infwizard, test, testwin, driver
+#
+#
+
+# If you're cross-compiling and your mingw32 tools are called
+# i586-mingw32msvc-gcc and so on, then you can compile libusb-win32
+# by running
+# make host_prefix=i586-mingw32msvc all
+
+ifdef host_prefix
+ override host_prefix := $(host_prefix)-
+endif
+ifdef host_prefix_x86
+ override host_prefix_x86 := $(host_prefix_x86)-
+endif
+ifdef cflags
+ DBG_DEFINE = $(cflags)
+endif
+
+CC = $(host_prefix)gcc
+LD = $(host_prefix)ld
+WINDRES = $(host_prefix)windres
+DLLTOOL = $(host_prefix)dlltool
+
+CC86 = $(host_prefix_x86)gcc
+LD86 = $(host_prefix_x86)ld
+WINDRES86 = windres
+DLLTOOL86 = dlltool
+
+MAKE = make
+CP = cp
+CD = cd
+MV = mv
+RM = -rm -fr
+TAR = tar
+ISCC = iscc
+INSTALL = install
+LIB = lib
+IMPLIB = implib
+UNIX2DOS = unix2dos
+
+TARGET = libusb
+DLL_TARGET = $(TARGET)0
+LIB_TARGET = $(TARGET)
+DRIVER_TARGET = $(TARGET)0.sys
+INSTALL_DIR = /usr
+VPATH = .:./src:./src/driver:./tests
+
+LIBWDI_DIR = ./projects/additional/libwdi/libwdi
+SRC_DIR = ./src
+DRIVER_SRC_DIR = $(SRC_DIR)/driver
+
+LIBWDI_CONFIG_H = -DWDF_VER=\"01009\" -DUSER_DIR=\"\" -DOPT_M32 -DWINVER=0x500
+
+DRIVER_OBJECTS = abort_endpoint.o claim_interface.o clear_feature.o \
+ dispatch.o get_configuration.o \
+ get_descriptor.o get_interface.o get_status.o \
+ ioctl.o libusb_driver.o pnp.o release_interface.o reset_device.o \
+ reset_endpoint.o set_configuration.o set_descriptor.o \
+ set_feature.o set_interface.o transfer.o vendor_request.o \
+ power.o driver_registry.o error.o libusb_driver_rc.o
+
+LIBWDI_OBJECTS = $(LIBWDI_DIR)/logging.5.o \
+ $(LIBWDI_DIR)/tokenizer.5.o \
+ $(LIBWDI_DIR)/vid_data.5.o \
+ $(LIBWDI_DIR)/libwdi_dlg.5.o \
+ $(LIBWDI_DIR)/libwdi.5.o
+
+
+INCLUDES = -I./src -I./src/driver -I.
+
+CFLAGS = -O2 -Wall -DWINVER=0x500 $(DBG_DEFINE)
+WIN_CFLAGS = $(CFLAGS) -mwindows
+
+WINDRES_FLAGS = -I$(SRC_DIR)
+
+STDC_LD_LIBS=-lkernel32 \
+ -luser32 \
+ -lgdi32 \
+ -lwinspool \
+ -lcomdlg32 \
+ -ladvapi32 \
+ -lshell32 \
+ -lole32 \
+ -loleaut32 \
+ -luuid \
+ -lodbc32 \
+ -lodbccp32
+
+LDFLAGS = -s -L. -lusb -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lcomctl32
+TEST_WIN_LDFLAGS = -s -L. -lusb -lkernel32 -lgdi32 -luser32 -lnewdev -lsetupapi -lcomctl32 -lole32 -mwindows
+WIN_LDFLAGS = -s -L. -lkernel32 -lgdi32 -luser32 -lnewdev -lsetupapi -lcomctl32 -lole32 -mwindows
+DLL_LDFLAGS = -s -mdll \
+ -Wl,--kill-at \
+ -Wl,--out-implib,$(LIB_TARGET).a \
+ -Wl,--enable-stdcall-fixup \
+ -L. -lcfgmgr32 -lsetupapi -lgdi32
+
+LIBWDI_DLL_LDFLAGS = -s -shared \
+ -Wl,--kill-at \
+ -Wl,--out-implib,libwdi.a \
+ -Wl,--enable-stdcall-fixup \
+ -L. -lnewdev -lsetupapi -lole32
+
+DRIVER_LDFLAGS = -s -shared -Wl,--entry,_DriverEntry@8 \
+ -nostartfiles -nostdlib -L. -lusbd -lntoskrnl -lhal
+
+
+.PHONY: all
+all: dll filter test testwin
+
+.PHONY: dll
+dll: DLL_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"$(DLL_TARGET)-dll\" -DTARGETTYPE=DYNLINK
+dll: $(DLL_TARGET).dll
+
+$(DLL_TARGET).dll: usb.2.o error.2.o descriptors.2.o windows.2.o install.2.o registry.2.o resource.2.o
+ $(CC) $(DLL_CFLAGS) -o $@ -I./src $^ $(DLL_TARGET).def $(DLL_LDFLAGS)
+
+%.2.o: %.c libusb_driver.h driver_api.h error.h
+ $(CC) $(DLL_CFLAGS) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
+
+%.2.o: %.rc
+ $(WINDRES) $(CPPFLAGS) $(WINDRES_FLAGS) $< -o $@
+
+.PHONY: filter
+filter: FILTER_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"install-filter\" -DTARGETTYPE=PROGRAMconsole -DLOG_STYLE_SHORT
+filter: FILTER_LDFLAGS = -s -L. -lgdi32 -luser32 -lcfgmgr32 -lsetupapi
+filter: install-filter.exe
+
+
+install-filter.exe: install_filter.1.o error.1.o install.1.o registry.1.o install_filter_rc.1.o
+ $(CC) $(FILTER_CFLAGS) -o $@ -I./src $^ $(FILTER_LDFLAGS)
+
+%.1.o: %.c libusb_driver.h driver_api.h error.h
+ $(CC) $(FILTER_CFLAGS) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
+
+%.1.o: %.rc
+ $(WINDRES) $(CPPFLAGS) $(WINDRES_FLAGS) $< -o $@
+
+.PHONY: test
+test: dll
+test: TEST_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"testlibusb\" -DTARGETTYPE=PROGRAMconsole
+test: testlibusb.exe
+
+testlibusb.exe: testlibusb.3.o
+ $(CC) $(TEST_CFLAGS) -o $@ -I./src $^ $(LDFLAGS)
+
+%.3.o: %.c libusb_driver.h driver_api.h error.h
+ $(CC) -c $< -o $@ $(TEST_CFLAGS) $(CPPFLAGS) $(INCLUDES)
+
+.PHONY: testwin
+testwin: dll
+testwin: TESTWIN_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"testlibusb-win\" -DTARGETTYPE=PROGRAMwindows
+testwin: testlibusb-win.exe
+
+testlibusb-win.exe: testlibusb_win.4.o testlibusb_win_rc.4.o
+ $(CC) $(TESTWIN_CFLAGS) -o $@ -I./src $^ $(TEST_WIN_LDFLAGS)
+
+%.4.o: %.c libusb_driver.h driver_api.h error.h
+ $(CC) -c $< -o $@ $(TESTWIN_CFLAGS) $(CPPFLAGS) $(INCLUDES)
+
+%.4.o: %.rc
+ $(WINDRES) $(CPPFLAGS) $(WINDRES_FLAGS) $< -o $@
+
+#
+# LIBWDI installer_x86
+#
+.PHONY: installer_x86
+installer_x86: INSTALLER_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"installer_x86\" -DTARGETTYPE=PROGRAMconsole $(LIBWDI_CONFIG_H)
+installer_x86: INSTALLER_LDFLAGS = -s -L. -ladvapi32 -lnewdev -lsetupapi
+installer_x86: installer_x86.exe
+
+installer_x86.exe: $(LIBWDI_DIR)/installer.6.o
+ $(CC86) $(INSTALLER_CFLAGS) -o $@ -I$(LIBWDI_DIR) $^ $(INSTALLER_LDFLAGS)
+ $(CP) $(LIBWDI_DIR)/../msvc/config.h $(LIBWDI_DIR)
+
+%.6.o: %.c $(LIBWDI_DIR)/installer.h
+ $(CC86) -c $< -o $@ $(INSTALLER_CFLAGS) $(CPPFLAGS) -DWINVER=0x500 -I$(LIBWDI_DIR)
+
+#
+# LIBWDI embedder
+#
+.PHONY: embedder
+embedder: installer_x86
+embedder: EMBEDDER_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"embedder\" -DTARGETTYPE=PROGRAMconsole $(LIBWDI_CONFIG_H)
+embedder: EMBEDDER_LDFLAGS = -s -L. -luser32 -lversion
+embedder: embedder.exe
+
+embedder.exe: $(LIBWDI_DIR)/embedder.7.o
+ $(CC86) $(EMBEDDER_CFLAGS) -o $@ -I$(LIBWDI_DIR) $^ $(EMBEDDER_LDFLAGS)
+ $(CP) -u $(LIBWDI_DIR)/winusb.inf.in ./
+ $(CP) -u $(LIBWDI_DIR)/libusb-win32.inf.in ./
+ ./embedder.exe embedded.h
+
+%.7.o: %.c $(LIBWDI_DIR)/embedder.h
+ $(CC86) -c $< -o $@ $(EMBEDDER_CFLAGS) $(CPPFLAGS) -DWINVER=0x500 -I$(LIBWDI_DIR)
+
+.PHONY: infwizard
+infwizard: embedder
+infwizard: INFWIZARD_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"infwizard\" -DTARGETTYPE=PROGRAMwindows
+infwizard: inf-wizard.exe
+
+inf-wizard.exe: inf_wizard.5.o inf_wizard_rc.5.o $(LIBWDI_OBJECTS)
+ $(CC86) $(WIN_CFLAGS) -o $@ -I./src -I$(LIBWDI_DIR) $^ $(WIN_LDFLAGS)
+
+%.5.o: %.c libusb-win32_version.h $(LIBWDI_DIR)/libwdi.h
+ $(CC86) -c $< -o $@ -I$(LIBWDI_DIR) $(INFWIZARD_CFLAGS) $(CPPFLAGS) $(INCLUDES)
+
+%.5.o: %.rc
+ $(WINDRES86) $(CPPFLAGS) $(WINDRES_FLAGS) $< -o $@
+
+.PHONY: driver
+driver: DRIVER_CFLAGS = $(CFLAGS) -DLOG_APPNAME=\"$(DLL_TARGET)-sys\" -DTARGETTYPE=DRIVER
+driver: $(DRIVER_TARGET)
+
+$(DRIVER_TARGET): libusbd.a $(DRIVER_OBJECTS)
+ $(CC) -o $@ $(DRIVER_OBJECTS) $(DLL_TARGET)_drv.def $(DRIVER_LDFLAGS)
+
+libusbd.a:
+ $(DLLTOOL) --dllname usbd.sys --add-underscore --def ./src/driver/usbd.def --output-lib libusbd.a
+
+%.o: %.c libusb_driver.h driver_api.h error.h
+ $(CC) -c $< -o $@ $(DRIVER_CFLAGS) $(CPPFLAGS) $(INCLUDES)
+
+%.o: %.rc
+ $(WINDRES) $(CPPFLAGS) $(WINDRES_FLAGS) $< -o $@
+
+.PHONY: cleantemp
+cleantemp:
+ $(RM) *.o *.a *.exp *.tar.gz *~ *.iss *.rc *.h
+ $(RM) $(LIBWDI_DIR)/*.o
+ $(RM) $(LIBWDI_DIR)/config.h
+ $(RM) ./src/*~ *.log
+ $(RM) $(DRIVER_SRC_DIR)/*~
+ $(RM) README.txt
+ $(RM) winusb.inf.in
+ $(RM) libusb-win32.inf.in
+ $(RM) inf_wizard.ico
+
+.PHONY: clean
+clean: cleantemp
+ $(RM) *.dll *.lib *.exe *.sys
diff --git a/usb/driver/README.txt b/usb/driver/README.txt
new file mode 100644
index 0000000..0dc3ac0
--- /dev/null
+++ b/usb/driver/README.txt
@@ -0,0 +1,12 @@
+
+This is libusb-win32 (http://libusb-win32.sourceforge.net) version 1.2.6.0.
+Libusb-win32 is a library that allows userspace application to access USB
+devices on Windows operation systems (Win2k, WinXP, Vista, Win7).
+It is derived from and fully API compatible to libusb available at
+http://libusb.sourceforge.net.
+
+For more information visit the project's web site at:
+
+http://libusb-win32.sourceforge.net
+http://sourceforge.net/projects/libusb-win32
+
diff --git a/usb/driver/abort_endpoint.c b/usb/driver/abort_endpoint.c
new file mode 100644
index 0000000..3ec46e9
--- /dev/null
+++ b/usb/driver/abort_endpoint.c
@@ -0,0 +1,56 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS abort_endpoint(libusb_device_t *dev, int endpoint, int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("endpoint: 0x%02x timeout: %d\n", endpoint, timeout);
+
+ memset(&urb, 0, sizeof(struct _URB_PIPE_REQUEST));
+
+ if (!dev->config.value)
+ {
+ USBERR0("invalid configuration 0\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ if (!get_pipe_handle(dev, endpoint, &urb.UrbPipeRequest.PipeHandle))
+ {
+ USBERR0("getting endpoint pipe failed\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ urb.UrbHeader.Length = (USHORT) sizeof(struct _URB_PIPE_REQUEST);
+ urb.UrbHeader.Function = URB_FUNCTION_ABORT_PIPE;
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("request failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ }
+
+ return status;
+}
diff --git a/usb/driver/claim_interface.c b/usb/driver/claim_interface.c
new file mode 100644
index 0000000..9ec0fe5
--- /dev/null
+++ b/usb/driver/claim_interface.c
@@ -0,0 +1,89 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS claim_interface(libusb_device_t *dev, FILE_OBJECT *file_object,
+ int interface)
+{
+ USBMSG("interface %d\n", interface);
+
+ if (!dev->config.value)
+ {
+ USBERR0("device is not configured\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ if (interface >= LIBUSB_MAX_NUMBER_OF_INTERFACES)
+ {
+ USBERR("interface number %d too high\n",
+ interface);
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (!dev->config.interfaces[interface].valid)
+ {
+ USBERR("interface %d does not exist\n", interface);
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (dev->config.interfaces[interface].file_object == file_object)
+ {
+ return STATUS_SUCCESS;
+ }
+
+ if (dev->config.interfaces[interface].file_object)
+ {
+ USBERR("could not claim interface %d, interface is already claimed\n", interface);
+ return STATUS_DEVICE_BUSY;
+ }
+
+ dev->config.interfaces[interface].file_object = file_object;
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS claim_interface_ex(libusb_device_t *dev,
+ FILE_OBJECT *file_object,
+ interface_request_t* interface_request)
+{
+ PUSB_INTERFACE_DESCRIPTOR interface_descriptor;
+
+ USBMSG("interface-%s=%d\n",
+ interface_request->intf_use_index ? "index" : "number",
+ interface_request->intf_use_index ? interface_request->interface_index : interface_request->interface_number);
+
+ if (!dev->config.value || !dev->config.descriptor)
+ {
+ USBERR0("device is not configured\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ interface_request->altsetting_index=FIND_INTERFACE_INDEX_ANY;
+ interface_descriptor = find_interface_desc_ex(dev->config.descriptor,dev->config.total_size,interface_request,NULL);
+ if (!interface_descriptor)
+ {
+ return STATUS_NO_MORE_ENTRIES;
+ }
+
+ return claim_interface(dev, file_object, interface_descriptor->bInterfaceNumber);
+}
diff --git a/usb/driver/clear_feature.c b/usb/driver/clear_feature.c
new file mode 100644
index 0000000..c3b5c24
--- /dev/null
+++ b/usb/driver/clear_feature.c
@@ -0,0 +1,64 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+NTSTATUS clear_feature(libusb_device_t *dev,
+ int recipient, int index, int feature, int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("recipient: %02d index: %04d feature: %04d timeout: %d\n",
+ recipient,index,feature,timeout);
+
+ memset(&urb, 0, sizeof(struct _URB_CONTROL_FEATURE_REQUEST));
+
+ switch (recipient)
+ {
+ case USB_RECIP_DEVICE:
+ urb.UrbHeader.Function = URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE;
+ break;
+ case USB_RECIP_INTERFACE:
+ urb.UrbHeader.Function = URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE;
+ break;
+ case USB_RECIP_ENDPOINT:
+ urb.UrbHeader.Function = URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT;
+ break;
+ case USB_RECIP_OTHER:
+ urb.UrbHeader.Function = URB_FUNCTION_CLEAR_FEATURE_TO_OTHER;
+ break;
+ default:
+ USBERR0("invalid recipient\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_FEATURE_REQUEST);
+ urb.UrbControlFeatureRequest.FeatureSelector = (USHORT)feature;
+ urb.UrbControlFeatureRequest.Index = (USHORT)index;
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("clearing feature failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ }
+
+ return status;
+}
diff --git a/usb/driver/dispatch.c b/usb/driver/dispatch.c
new file mode 100644
index 0000000..8eccb21
--- /dev/null
+++ b/usb/driver/dispatch.c
@@ -0,0 +1,99 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+NTSTATUS DDKAPI dispatch(DEVICE_OBJECT *device_object, IRP *irp)
+{
+ libusb_device_t *dev = device_object->DeviceExtension;
+ IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
+
+ switch (stack_location->MajorFunction)
+ {
+ case IRP_MJ_PNP:
+ return dispatch_pnp(dev, irp);
+
+ case IRP_MJ_POWER:
+ // ID: 2960644 (farthen)
+ // You can't set the power state if the device is not handled at all
+ if(!dev->next_stack_device)
+ {
+ return complete_irp(irp, STATUS_INVALID_DEVICE_STATE, 0);
+ }
+ return dispatch_power(dev, irp);
+ }
+
+ /* since this driver may run as an upper filter we have to check whether */
+ /* the IRP is sent to this device object or to the lower one */
+ if (accept_irp(dev, irp))
+ {
+ switch (stack_location->MajorFunction)
+ {
+ case IRP_MJ_DEVICE_CONTROL:
+
+ if (dev->is_started)
+ {
+ return dispatch_ioctl(dev, irp);
+ }
+ else /* not started yet */
+ {
+ return complete_irp(irp, STATUS_INVALID_DEVICE_STATE, 0);
+ }
+
+ case IRP_MJ_CREATE:
+
+ if (dev->is_started)
+ {
+ // only one driver can act as power policy owner and
+ // power_set_device_state() can only be issued by the PPO.
+ // disallow_power_control is set to true for drivers which
+ // we know cause a BSOD on any attempt to request power irps.
+ if (dev->power_state.DeviceState != PowerDeviceD0 && !dev->disallow_power_control)
+ {
+ /* power up the device, block until the call */
+ /* completes */
+ power_set_device_state(dev, PowerDeviceD0, TRUE);
+ }
+ return complete_irp(irp, STATUS_SUCCESS, 0);
+ }
+ else /* not started yet */
+ {
+ return complete_irp(irp, STATUS_INVALID_DEVICE_STATE, 0);
+ }
+
+ case IRP_MJ_CLOSE:
+
+ /* release all interfaces bound to this file object */
+ release_all_interfaces(dev, stack_location->FileObject);
+ return complete_irp(irp, STATUS_SUCCESS, 0);
+
+ case IRP_MJ_CLEANUP:
+
+ return complete_irp(irp, STATUS_SUCCESS, 0);
+
+ default:
+ return complete_irp(irp, STATUS_NOT_SUPPORTED, 0);
+ }
+ }
+ else /* the IRP is for the lower device object */
+ {
+ return pass_irp_down(dev, irp, NULL, NULL);
+ }
+}
+
diff --git a/usb/driver/driver_api.h b/usb/driver/driver_api.h
new file mode 100644
index 0000000..5339a81
--- /dev/null
+++ b/usb/driver/driver_api.h
@@ -0,0 +1,400 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef __DRIVER_API_H__
+#define __DRIVER_API_H__
+
+enum
+{
+ LIBUSB_DEBUG_OFF,
+ LIBUSB_DEBUG_ERR,
+ LIBUSB_DEBUG_WRN,
+ LIBUSB_DEBUG_MSG,
+
+ LIBUSB_DEBUG_MAX = 0xff,
+};
+
+
+/* 64k */
+#define LIBUSB_MAX_READ_WRITE 0x10000
+
+#define LIBUSB_MAX_NUMBER_OF_DEVICES 256
+#define LIBUSB_MAX_NUMBER_OF_CHILDREN 32
+
+#define LIBUSB_IOCTL_SET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_SET_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_CLEAR_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x806, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_STATUS CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x807, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_SET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x808, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x809, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x80A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x80B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_VENDOR_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x80C, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_VENDOR_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x80D, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_RESET_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x80E, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_ABORT_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x80F, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_RESET_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x810, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_SET_DEBUG_LEVEL CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x811, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x812, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_ISOCHRONOUS_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x813, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_ISOCHRONOUS_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x814, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x815, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x816, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+/////////////////////////////////////////////////////////////////////////////
+// supported after 0.1.12.2
+/////////////////////////////////////////////////////////////////////////////
+
+// [trobinso] adds support for querying device properties
+#define LIBUSB_IOCTL_GET_DEVICE_PROPERTY CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x900, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_CUSTOM_REG_PROPERTY CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x901, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+// supported after 1.2.0.0
+/////////////////////////////////////////////////////////////////////////////
+#define LIBUSB_IOCTL_GET_CACHED_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x902, METHOD_BUFFERED, FILE_ANY_ACCESS)
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+// supported after 1.2.2.0
+/////////////////////////////////////////////////////////////////////////////
+#define LIBUSB_IOCTL_GET_OBJECT_NAME CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x8FF, METHOD_BUFFERED, FILE_ANY_ACCESS)
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+// supported after 1.2.3.0
+/////////////////////////////////////////////////////////////////////////////
+#define LIBUSB_IOCTL_QUERY_DEVICE_INFORMATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x904, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_SET_PIPE_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x906, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_PIPE_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x907, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_SET_POWER_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x908, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_GET_POWER_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x909, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_CONTROL_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x90A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_CONTROL_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x90B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
+
+#define LIBUSB_IOCTL_FLUSH_PIPE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x90C, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSBK_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x90D, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSBK_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x90E, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSBK_IOCTL_RELEASE_ALL_INTERFACES CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x90F, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSBK_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x910, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define LIBUSBK_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
+ 0x911, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+/////////////////////////////////////////////////////////////////////////////
+// supported after 1.2.4.8 (libusb0.sys only)
+/////////////////////////////////////////////////////////////////////////////
+#define LIBUSB_IOCTL_RESET_DEVICE_EX CTL_CODE(FILE_DEVICE_UNKNOWN,\
+0x817, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#include <pshpack1.h>
+
+enum LIBUSB0_TRANSFER_FLAGS
+{
+ TRANSFER_FLAGS_SHORT_NOT_OK = 1 << 0,
+ TRANSFER_FLAGS_ISO_SET_START_FRAME = 1 << 30,
+ TRANSFER_FLAGS_ISO_ADD_LATENCY = 1 << 31,
+};
+
+/*
+typedef struct
+{
+ unsigned int timeout;
+ union
+ {
+ struct
+ {
+ unsigned int configuration;
+ } configuration;
+ struct
+ {
+ unsigned int interface;
+ unsigned int altsetting;
+ } interface;
+ struct
+ {
+ unsigned int endpoint;
+ unsigned int packet_size;
+
+ // TODO: max_transfer_size, short transfer not ok, use iso_start_frame
+ unsigned int max_transfer_size;
+ unsigned int transfer_flags;
+ unsigned int iso_start_frame_latency;
+ } endpoint;
+ struct
+ {
+ unsigned int type;
+ unsigned int recipient;
+ unsigned int request;
+ unsigned int value;
+ unsigned int index;
+ } vendor;
+ struct
+ {
+ unsigned int recipient;
+ unsigned int feature;
+ unsigned int index;
+ } feature;
+ struct
+ {
+ unsigned int recipient;
+ unsigned int index;
+ unsigned int status;
+ } status;
+ struct
+ {
+ unsigned int type;
+ unsigned int index;
+ unsigned int language_id;
+ unsigned int recipient;
+ } descriptor;
+ struct
+ {
+ unsigned int level;
+ } debug;
+ struct
+ {
+ unsigned int major;
+ unsigned int minor;
+ unsigned int micro;
+ unsigned int nano;
+ unsigned int mod_value;
+ } version;
+ struct
+ {
+ unsigned int property;
+ } device_property;
+ struct
+ {
+ unsigned int key_type;
+ unsigned int name_offset;
+ unsigned int value_offset;
+ unsigned int value_length;
+ } device_registry_key;
+ struct
+ {
+ // 0 - device plug and play registry key pathname
+ unsigned int objname_index;
+ } objname;
+ };
+} libusb_request;
+*/
+
+#pragma warning(disable:4201)
+
+typedef struct
+{
+ unsigned int interface_number;
+ unsigned int altsetting_number;
+
+ unsigned char intf_use_index:1; // libusbK Only
+ unsigned char altf_use_index:1; // libusbK Only
+ unsigned char:6;
+
+ short interface_index; // libusbK Only
+ short altsetting_index; // libusbK Only
+}interface_request_t;
+
+typedef struct
+{
+ unsigned int timeout;
+ union
+ {
+ struct
+ {
+ unsigned int configuration;
+ } configuration;
+
+ interface_request_t intf;
+
+ struct
+ {
+ unsigned int endpoint;
+ unsigned int packet_size;
+
+ // TODO: max_transfer_size, short transfer not ok, use iso_start_frame
+ unsigned int max_transfer_size;
+ unsigned int transfer_flags;
+ unsigned int iso_start_frame_latency;
+ } endpoint;
+ struct
+ {
+ unsigned int type;
+ unsigned int recipient;
+ unsigned int request;
+ unsigned int value;
+ unsigned int index;
+ } vendor;
+ struct
+ {
+ unsigned int recipient;
+ unsigned int feature;
+ unsigned int index;
+ } feature;
+ struct
+ {
+ unsigned int recipient;
+ unsigned int index;
+ unsigned int status;
+ } status;
+ struct
+ {
+ unsigned int type;
+ unsigned int index;
+ unsigned int language_id;
+ unsigned int recipient;
+ } descriptor;
+ struct
+ {
+ unsigned int level;
+ } debug;
+ struct
+ {
+ unsigned int major;
+ unsigned int minor;
+ unsigned int micro;
+ unsigned int nano;
+ unsigned int mod_value;
+ } version;
+ struct
+ {
+ unsigned int property;
+ } device_property;
+ struct
+ {
+ unsigned int key_type;
+ unsigned int name_offset;
+ unsigned int value_offset;
+ unsigned int value_length;
+ } device_registry_key;
+ struct
+ {
+ // 0 - device plug and play registry key pathname
+ unsigned int objname_index;
+ } objname;
+ struct
+ {
+ ULONG information_type;
+ } query_device;
+ struct
+ {
+ unsigned int interface_index;
+ unsigned int pipe_id;
+ unsigned int policy_type;
+ } pipe_policy;
+ struct
+ {
+ unsigned int policy_type;
+ } power_policy;
+ struct
+ {
+ unsigned int reset_type;
+ } reset_ex;
+
+ // WDF_USB_CONTROL_SETUP_PACKET control;
+ struct
+ {
+ UCHAR RequestType;
+ UCHAR Request;
+ USHORT Value;
+ USHORT Index;
+ USHORT Length;
+ } control;
+ };
+} libusb_request;
+#pragma warning(default:4201)
+
+#include <poppack.h>
+
+#endif
diff --git a/usb/driver/driver_debug.c b/usb/driver/driver_debug.c
new file mode 100644
index 0000000..49f1878
--- /dev/null
+++ b/usb/driver/driver_debug.c
@@ -0,0 +1,75 @@
+/* LIBUSB-WIN32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+#include <stdio.h>
+#include <stdarg.h>
+
+int debug_level = LIBUSB_DEBUG_MSG;
+
+void DEBUG_PRINT_NL()
+{
+#ifdef DBG
+ if (debug_level >= LIBUSB_DEBUG_MSG)
+ DbgPrint(("\n"));
+#endif
+}
+
+void DEBUG_SET_LEVEL(int level)
+{
+#ifdef DBG
+ debug_level = level;
+#endif
+}
+
+void DEBUG_MESSAGE(const char *format, ...)
+{
+#ifdef DBG
+
+ char tmp[256];
+
+ if (debug_level >= LIBUSB_DEBUG_MSG)
+ {
+ va_list args;
+ va_start(args, format);
+ _vsnprintf(tmp, sizeof(tmp) - 1, format, args);
+ va_end(args);
+
+ DbgPrint("LIBUSB-DRIVER - %s", tmp);
+ }
+#endif
+}
+
+void DEBUG_ERROR(const char *format, ...)
+{
+#ifdef DBG
+
+ char tmp[256];
+
+ if (debug_level >= LIBUSB_DEBUG_ERR)
+ {
+ va_list args;
+ va_start(args, format);
+ _vsnprintf(tmp, sizeof(tmp) - 1, format, args);
+ va_end(args);
+
+ DbgPrint("LIBUSB-DRIVER - %s", tmp);
+ }
+#endif
+}
diff --git a/usb/driver/driver_debug.h b/usb/driver/driver_debug.h
new file mode 100644
index 0000000..a4f396f
--- /dev/null
+++ b/usb/driver/driver_debug.h
@@ -0,0 +1,30 @@
+/* LIBUSB-WIN32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef __LIBUSB_DEBUG_H__
+#define __LIBUSB_DEBUG_H__
+
+
+void DEBUG_PRINT_NL();
+void DEBUG_SET_LEVEL(int level);
+void DEBUG_MESSAGE(const char *format, ...);
+void DEBUG_ERROR(const char *format, ...);
+
+
+#endif
diff --git a/usb/driver/driver_registry.c b/usb/driver/driver_registry.c
new file mode 100644
index 0000000..3b0c67d
--- /dev/null
+++ b/usb/driver/driver_registry.c
@@ -0,0 +1,376 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+#include "lusb_defdi_guids.h"
+
+/* missing in mingw's ddk headers */
+#ifndef PLUGPLAY_REGKEY_DEVICE
+#define PLUGPLAY_REGKEY_DEVICE 1
+#endif
+
+#define LIBUSB_REG_SURPRISE_REMOVAL_OK L"SurpriseRemovalOK"
+#define LIBUSB_REG_INITIAL_CONFIG_VALUE L"InitialConfigValue"
+#define LIBUSB_REG_DEVICE_INTERFACE_GUIDS L"DeviceInterfaceGUIDs"
+
+static bool_t reg_get_property(DEVICE_OBJECT *physical_device_object,
+ int property, char *data, int size);
+
+static bool_t reg_get_property(DEVICE_OBJECT *physical_device_object,
+ int property, char *data, int size)
+{
+ WCHAR tmp[512];
+ ULONG ret;
+ ULONG i;
+
+ if (!physical_device_object || !data || !size)
+ {
+ return FALSE;
+ }
+
+ memset(data, 0, size);
+ memset(tmp, 0, sizeof(tmp));
+
+ if (NT_SUCCESS(IoGetDeviceProperty(physical_device_object,
+ property,
+ sizeof(tmp) - 2,
+ tmp,
+ &ret)) && ret)
+ {
+ /* convert unicode string to normal character string */
+ for (i = 0; (i < ret/2) && (i < ((ULONG)size - 1)); i++)
+ {
+ data[i] = (char)tmp[i];
+ }
+
+ _strlwr(data);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+bool_t reg_get_properties(libusb_device_t *dev)
+{
+ HANDLE key = NULL;
+ PVOID keyObject = NULL;
+ NTSTATUS status;
+ UNICODE_STRING surprise_removal_ok_name;
+ UNICODE_STRING initial_config_value_name;
+ UNICODE_STRING device_interface_guids;
+ UNICODE_STRING device_interface_guid_value;
+ KEY_VALUE_FULL_INFORMATION *info;
+ ULONG pool_length;
+ ULONG length;
+ ULONG val;
+ LPWSTR valW;
+
+ if (!dev->physical_device_object)
+ {
+ return FALSE;
+ }
+
+ /* default settings */
+ dev->surprise_removal_ok = FALSE;
+ dev->is_filter = TRUE;
+ dev->initial_config_value = SET_CONFIG_ACTIVE_CONFIG;
+
+ status = IoOpenDeviceRegistryKey(dev->physical_device_object,
+ PLUGPLAY_REGKEY_DEVICE,
+ STANDARD_RIGHTS_ALL,
+ &key);
+ if (NT_SUCCESS(status))
+ {
+ RtlInitUnicodeString(&surprise_removal_ok_name,
+ LIBUSB_REG_SURPRISE_REMOVAL_OK);
+
+ RtlInitUnicodeString(&initial_config_value_name,
+ LIBUSB_REG_INITIAL_CONFIG_VALUE);
+
+ RtlInitUnicodeString(&device_interface_guids,
+ LIBUSB_REG_DEVICE_INTERFACE_GUIDS);
+
+ pool_length = sizeof(KEY_VALUE_FULL_INFORMATION) + 512;
+
+ info = ExAllocatePool(NonPagedPool, pool_length);
+ if (!info)
+ {
+ ZwClose(key);
+ USBERR("ExAllocatePool failed allocating %d bytes\n", pool_length);
+ return FALSE;
+ }
+
+
+ // get surprise_removal_ok
+ // get is_filter
+ length = pool_length;
+ memset(info, 0, length);
+
+ status = ZwQueryValueKey(key, &surprise_removal_ok_name,
+ KeyValueFullInformation, info, length, &length);
+
+ if (NT_SUCCESS(status) && (info->Type == REG_DWORD))
+ {
+ val = *((ULONG *)(((char *)info) + info->DataOffset));
+
+ dev->surprise_removal_ok = val ? TRUE : FALSE;
+ dev->is_filter = FALSE;
+ }
+
+ if (!dev->is_filter)
+ {
+ // get device interface guid
+ length = pool_length;
+ memset(info, 0, length);
+
+ status = ZwQueryValueKey(key, &device_interface_guids,
+ KeyValueFullInformation, info, length, &length);
+
+ if (NT_SUCCESS(status) && (info->Type == REG_MULTI_SZ))
+ {
+ valW = ((LPWSTR)(((char *)info) + info->DataOffset));
+ RtlInitUnicodeString(&device_interface_guid_value,valW);
+ status = RtlGUIDFromString(&device_interface_guid_value, &dev->device_interface_guid);
+ if (NT_SUCCESS(status))
+ {
+ if (IsEqualGUID(&dev->device_interface_guid, &LibusbKDeviceGuid))
+ {
+ USBWRN0("libusbK default device DeviceInterfaceGUID found. skippng..\n");
+ RtlInitUnicodeString(&device_interface_guid_value,Libusb0DeviceGuidW);
+ }
+ else if (IsEqualGUID(&dev->device_interface_guid, &Libusb0FilterGuid))
+ {
+ USBWRN0("libusb0 filter DeviceInterfaceGUID found. skippng..\n");
+ RtlInitUnicodeString(&device_interface_guid_value,Libusb0DeviceGuidW);
+ }
+ else if (IsEqualGUID(&dev->device_interface_guid, &Libusb0DeviceGuid))
+ {
+ USBWRN0("libusb0 device DeviceInterfaceGUID found. skippng..\n");
+ RtlInitUnicodeString(&device_interface_guid_value,Libusb0DeviceGuidW);
+ }
+ else
+ {
+ USBMSG0("found user specified device interface guid.\n");
+ dev->device_interface_in_use = TRUE;
+ }
+ }
+ else
+ {
+ USBERR0("invalid user specified device interface guid.");
+ }
+ }
+ if (!dev->device_interface_in_use)
+ {
+ RtlInitUnicodeString(&device_interface_guid_value,Libusb0DeviceGuidW);
+ }
+ }
+ else
+ {
+ RtlInitUnicodeString(&device_interface_guid_value,Libusb0FilterGuidW);
+ }
+
+ if (!dev->device_interface_in_use)
+ {
+ status = RtlGUIDFromString(&device_interface_guid_value, &dev->device_interface_guid);
+ if (NT_SUCCESS(status))
+ {
+ USBMSG0("using default device interface guid.\n");
+ dev->device_interface_in_use = TRUE;
+ }
+ else
+ {
+ USBERR0("failed using default device interface guid.\n");
+ }
+ }
+
+ // get initial_config_value
+ length = pool_length;
+ memset(info, 0, length);
+
+ status = ZwQueryValueKey(key, &initial_config_value_name,
+ KeyValueFullInformation, info, length, &length);
+
+ if (NT_SUCCESS(status) && (info->Type == REG_DWORD))
+ {
+ val = *((ULONG *)(((char *)info) + info->DataOffset));
+ dev->initial_config_value = (int)val;
+ }
+
+ status = ObReferenceObjectByHandle(key, KEY_READ, NULL, KernelMode, &keyObject, NULL);
+ if (NT_SUCCESS(status))
+ {
+ length = pool_length;
+ memset(info, 0, length);
+ status = ObQueryNameString(keyObject, (POBJECT_NAME_INFORMATION)info, length, &length);
+ if (NT_SUCCESS(status))
+ {
+ PWSTR nameW =((POBJECT_NAME_INFORMATION)info)->Name.Buffer;
+ PSTR nameA = dev->objname_plugplay_registry_key;
+
+ val=0;
+ while (nameW[val] && val < (length/2))
+ {
+ *nameA=(char)nameW[val];
+ nameA++;
+ val++;
+ }
+ *nameA='\0';
+
+ USBDBG("reg-key-name=%s\n",dev->objname_plugplay_registry_key);
+ }
+ else
+ {
+ USBERR("ObQueryNameString failed. status=%Xh\n",status);
+ }
+
+ ObDereferenceObject(keyObject);
+ }
+ else
+ {
+ USBERR("ObReferenceObjectByHandle failed. status=%Xh\n",status);
+ }
+
+ ZwClose(key);
+ ExFreePool(info);
+ }
+
+ return TRUE;
+}
+
+bool_t reg_get_hardware_id(DEVICE_OBJECT *physical_device_object,
+ char *data, int size)
+{
+ if (!physical_device_object || !data || !size)
+ {
+ return FALSE;
+ }
+
+ return reg_get_property(physical_device_object, DevicePropertyHardwareID,
+ data, size);
+}
+
+bool_t reg_get_compatible_id(DEVICE_OBJECT *physical_device_object,
+ char *data, int size)
+{
+ if (!physical_device_object || !data || !size)
+ {
+ return FALSE;
+ }
+
+ return reg_get_property(physical_device_object, DevicePropertyCompatibleIDs,
+ data, size);
+}
+/*
+Gets a device property for the device_object.
+
+Returns: NTSTATUS code from IoGetDeviceProperty
+ STATUS_INVALID_PARAMETER
+*/
+NTSTATUS reg_get_device_property(PDEVICE_OBJECT device_object,
+ int property,
+ char* data_buffer,
+ int data_length,
+ int* actual_length)
+{
+ NTSTATUS status = STATUS_INVALID_PARAMETER;
+
+ if (!device_object || !data_buffer || !data_length || !actual_length)
+ return status;
+
+ // clear data
+ memset(data_buffer, 0, data_length);
+ *actual_length=0;
+
+ // get device property
+ status = IoGetDeviceProperty(
+ device_object, property, data_length, data_buffer, (PULONG)actual_length);
+
+ return status;
+}
+
+/*
+Gets a property from the device registry key of the device_object.
+
+Returns: NTSTATUS from ZwQueryValueKey
+ NTSTATUS from IoOpenDeviceRegistryKey if the device registry
+ key could not be opened.
+*/
+NTSTATUS reg_get_custom_property(PDEVICE_OBJECT device_object,
+ char *data_buffer,
+ unsigned int data_length,
+ unsigned int name_offset,
+ int* actual_length)
+{
+ HANDLE key = NULL;
+ NTSTATUS status;
+ UNICODE_STRING name;
+ KEY_VALUE_FULL_INFORMATION *info;
+ ULONG length;
+
+ status = IoOpenDeviceRegistryKey(device_object, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &key);
+ if (NT_SUCCESS(status))
+ {
+ RtlInitUnicodeString(&name, (WCHAR*)(&data_buffer[name_offset]));
+ length = sizeof(KEY_VALUE_FULL_INFORMATION) + name.MaximumLength + data_length;
+ info = ExAllocatePool(NonPagedPool, length);
+ if (info)
+ {
+ memset(info, 0, length);
+ status = ZwQueryValueKey(key, &name, KeyValueFullInformation, info, length, &length);
+ if (NT_SUCCESS(status))
+ {
+ data_length = (info->DataLength > data_length) ? data_length : info->DataLength;
+ memcpy(data_buffer, (((char *)info) + info->DataOffset),data_length);
+ *actual_length=data_length;
+ }
+ ExFreePool(info);
+ }
+ ZwClose(key);
+ }
+ return status;
+}
+
+VOID set_filter_interface_key(libusb_device_t *dev, ULONG id)
+{
+ if (dev->device_interface_in_use)
+ {
+ HANDLE hKey=NULL;
+ if (NT_SUCCESS(IoOpenDeviceInterfaceRegistryKey(&dev->device_interface_name,KEY_ALL_ACCESS,&hKey)))
+ {
+ UNICODE_STRING valueName;
+ RtlInitUnicodeString(&valueName, L"LUsb0");
+
+ if (NT_SUCCESS(ZwSetValueKey(hKey,&valueName, 0, REG_DWORD, &id,sizeof(ULONG))))
+ {
+ USBMSG("updated interface registry with LUsb0 direct-access symbolic link. id=%d\n",id);
+ }
+ else
+ {
+ USBERR0("IoOpenDeviceInterfaceRegistryKey:ZwSetValueKey failed\n");
+ }
+ ZwClose(hKey);
+ }
+ else
+ {
+ USBERR0("IoOpenDeviceInterfaceRegistryKey failed\n");
+ }
+ }
+} \ No newline at end of file
diff --git a/usb/driver/get_configuration.c b/usb/driver/get_configuration.c
new file mode 100644
index 0000000..fa9b522
--- /dev/null
+++ b/usb/driver/get_configuration.c
@@ -0,0 +1,56 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+NTSTATUS get_configuration(libusb_device_t *dev,
+ unsigned char *configuration, int *ret,
+ int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("timeout: %d\n", timeout);
+
+ memset(&urb, 0, sizeof(URB));
+
+ urb.UrbHeader.Function = URB_FUNCTION_GET_CONFIGURATION;
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_CONFIGURATION_REQUEST);
+ urb.UrbControlGetConfigurationRequest.TransferBufferLength = 1;
+ urb.UrbControlGetConfigurationRequest.TransferBuffer = configuration;
+
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("getting configuration failed: status: 0x%x, urb-status: 0x%x\n",
+ status, urb.UrbHeader.Status);
+ *ret = 0;
+ }
+ else
+ {
+ USBMSG("current configuration is: %d\n",
+ *configuration);
+ *ret = urb.UrbControlGetConfigurationRequest.TransferBufferLength;
+ }
+
+ return status;
+}
diff --git a/usb/driver/get_descriptor.c b/usb/driver/get_descriptor.c
new file mode 100644
index 0000000..2b5172e
--- /dev/null
+++ b/usb/driver/get_descriptor.c
@@ -0,0 +1,289 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS get_descriptor(libusb_device_t *dev,
+ void *buffer, int size, int type, int recipient,
+ int index, int language_id, int *received, int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("buffer size: %d type: %04d recipient: %04d index: %04d language id: %04d timeout: %d\n",
+ size, type, recipient, index, language_id, timeout);
+
+ memset(&urb, 0, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
+
+ switch (recipient)
+ {
+ case USB_RECIP_DEVICE:
+ urb.UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE;
+ break;
+ case USB_RECIP_INTERFACE:
+ urb.UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE;
+ break;
+ case USB_RECIP_ENDPOINT:
+ urb.UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT;
+ break;
+ default:
+ USBERR0("invalid recipient\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
+ urb.UrbControlDescriptorRequest.TransferBufferLength = size;
+ urb.UrbControlDescriptorRequest.TransferBuffer = buffer;
+ urb.UrbControlDescriptorRequest.DescriptorType = (UCHAR)type;
+ urb.UrbControlDescriptorRequest.Index = (UCHAR)index;
+ urb.UrbControlDescriptorRequest.LanguageId = (USHORT)language_id;
+
+ // the device and active config descriptors are cached. If the request
+ // is for one of these and we have already retrieved it, then this is
+ // a non-blocking non-i/o call.
+
+ if (type == USB_DEVICE_DESCRIPTOR_TYPE &&
+ recipient == USB_RECIP_DEVICE &&
+ index == 0 &&
+ language_id == 0 &&
+ size >= sizeof(USB_DEVICE_DESCRIPTOR))
+ {
+ // this is a device descriptor request.
+ if (dev->device_descriptor.bLength == 0)
+ {
+ // this is the first request made for the device descriptor.
+ // Cache it now and forever
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+ if (NT_SUCCESS(status) && urb.UrbControlDescriptorRequest.TransferBufferLength < sizeof(USB_DEVICE_DESCRIPTOR))
+ {
+ USBERR("Invalid device decriptor length %d\n", urb.UrbControlDescriptorRequest.TransferBufferLength);
+ status = STATUS_BAD_DEVICE_TYPE;
+ *received = 0;
+ goto Done;
+ }
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("getting descriptor failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ *received = 0;
+ goto Done;
+ }
+
+ // valid device descriptor
+ size = sizeof(USB_DEVICE_DESCRIPTOR);
+ RtlCopyMemory(&dev->device_descriptor, buffer, size);
+ *received = size;
+
+ }
+ else
+ {
+ // device descriptor is already cached.
+ size = sizeof(USB_DEVICE_DESCRIPTOR);
+ RtlCopyMemory(buffer, &dev->device_descriptor, size);
+ *received = size;
+ }
+
+ goto Done;
+ }
+
+ if (type == USB_CONFIGURATION_DESCRIPTOR_TYPE &&
+ recipient == USB_RECIP_DEVICE &&
+ language_id == 0 &&
+ size >= sizeof(USB_CONFIGURATION_DESCRIPTOR))
+ {
+ if (dev->device_descriptor.bLength != 0 && index >=dev->device_descriptor.bNumConfigurations)
+ {
+ USBWRN("config descriptor index %d out of range.\n", index);
+ status = STATUS_NO_MORE_ENTRIES;
+ *received = 0;
+ goto Done;
+ }
+
+ // this is a config descriptor request.
+ if (!dev->config.descriptor || dev->config.index != index)
+ {
+ // this is either:
+ // * The first request made for a config descriptor.
+ // * A request for a config descriptor other than the cached index.
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("getting descriptor failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ *received = 0;
+ goto Done;
+ }
+
+ if (!dev->config.descriptor &&
+ urb.UrbControlDescriptorRequest.TransferBufferLength >= ((PUSB_CONFIGURATION_DESCRIPTOR)buffer)->wTotalLength)
+ {
+ //
+ // This is a special case scenario where we cache the first
+ // config deescriptor requested when dev->config.descriptor == NULL
+ // and this was a request for the *entire* descriptor.
+ //
+ // Nearly all windows USB devices will only have one configuration.
+ // In the case a the filter driver, it does *not* auto configure the
+ // device which is where the *active* config descriptor caching occurs.
+ //
+ // This code ensures the first config descriptor requested is always cached
+ // even if the device is not configured yet.
+ //
+
+ PUSB_CONFIGURATION_DESCRIPTOR config_desc;
+ size = ((PUSB_CONFIGURATION_DESCRIPTOR)buffer)->wTotalLength;
+
+ if (!( config_desc = ExAllocatePool(NonPagedPool, size)))
+ {
+ USBERR0("memory allocation error\n");
+ status = STATUS_NO_MEMORY;
+ goto Done;
+ }
+
+ dev->config.descriptor=config_desc;
+
+ RtlCopyMemory(dev->config.descriptor,buffer,size);
+ dev->config.value=0;
+ dev->config.total_size=size;
+ dev->config.index=index;
+
+ *received = size;
+ }
+ else
+ {
+ *received = urb.UrbControlDescriptorRequest.TransferBufferLength;
+ }
+ goto Done;
+ }
+ else
+ {
+ // This is a request for the active configuration descriptor.
+ // This is only updated upon a successful set_configuration().
+ size = (size > dev->config.descriptor->wTotalLength) ? dev->config.descriptor->wTotalLength : size;
+ RtlCopyMemory(buffer, dev->config.descriptor, size);
+
+ *received = size;
+ goto Done;
+ }
+ }
+
+ // this is not a device or config descriptor reequest
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("getting descriptor failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ *received = 0;
+ }
+ else
+ {
+ *received = urb.UrbControlDescriptorRequest.TransferBufferLength;
+ }
+
+Done:
+ return status;
+}
+
+PUSB_CONFIGURATION_DESCRIPTOR get_config_descriptor(
+ libusb_device_t *dev,
+ int value,
+ int *size,
+ int* index)
+{
+ NTSTATUS status;
+ USB_CONFIGURATION_DESCRIPTOR *desc = NULL;
+ USB_DEVICE_DESCRIPTOR device_descriptor;
+ int i;
+ volatile int desc_size;
+
+ *index = 0;
+
+ status = get_descriptor(dev, &device_descriptor,
+ sizeof(USB_DEVICE_DESCRIPTOR),
+ USB_DEVICE_DESCRIPTOR_TYPE,
+ USB_RECIP_DEVICE,
+ 0, 0, size, LIBUSB_DEFAULT_TIMEOUT);
+
+ if (!NT_SUCCESS(status) || *size != sizeof(USB_DEVICE_DESCRIPTOR))
+ {
+ USBERR0("getting device descriptor failed\n");
+ return NULL;
+ }
+
+ if (!(desc = ExAllocatePool(NonPagedPool,
+ sizeof(USB_CONFIGURATION_DESCRIPTOR))))
+ {
+ USBERR0("memory allocation error\n");
+ return NULL;
+ }
+
+ for (i = 0; i < device_descriptor.bNumConfigurations; i++)
+ {
+
+ if (!NT_SUCCESS(get_descriptor(dev, desc,
+ sizeof(USB_CONFIGURATION_DESCRIPTOR),
+ USB_CONFIGURATION_DESCRIPTOR_TYPE,
+ USB_RECIP_DEVICE,
+ i, 0, size, LIBUSB_DEFAULT_TIMEOUT)))
+ {
+ USBERR0("getting configuration descriptor failed\n");
+ break;
+ }
+
+ // if value is negative, get the descriptor by index
+ // if positive, get it by value.
+ if ((value > 0 && desc->bConfigurationValue == value) ||
+ (value < 0 && -(i+1) == (value)))
+ {
+ desc_size = desc->wTotalLength;
+ ExFreePool(desc);
+
+ if (!(desc = ExAllocatePool(NonPagedPool, desc_size)))
+ {
+ USBERR0("memory allocation error\n");
+ break;
+ }
+
+ if (!NT_SUCCESS(get_descriptor(dev, desc, desc_size,
+ USB_CONFIGURATION_DESCRIPTOR_TYPE,
+ USB_RECIP_DEVICE,
+ i, 0, size, LIBUSB_DEFAULT_TIMEOUT)))
+ {
+ USBERR0("getting configuration descriptor failed\n");
+ break;
+ }
+ else
+ {
+ *index = i;
+ }
+
+ return desc;
+ }
+ }
+
+ if (desc)
+ {
+ ExFreePool(desc);
+ }
+
+ return NULL;
+}
diff --git a/usb/driver/get_interface.c b/usb/driver/get_interface.c
new file mode 100644
index 0000000..b218281
--- /dev/null
+++ b/usb/driver/get_interface.c
@@ -0,0 +1,109 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS get_interface(libusb_device_t *dev,
+ int interface_number,
+ unsigned char *altsetting,
+ int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+ PUSB_INTERFACE_DESCRIPTOR interface_descriptor;
+
+ USBMSG("interface: %d timeout: %d\n", interface_number, timeout);
+
+ if (!dev->config.value)
+ {
+ USBERR0("invalid configuration 0\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ memset(&urb, 0, sizeof(URB));
+
+ urb.UrbHeader.Function = URB_FUNCTION_GET_INTERFACE;
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_INTERFACE_REQUEST);
+ urb.UrbControlGetInterfaceRequest.TransferBufferLength = 1;
+ urb.UrbControlGetInterfaceRequest.TransferBuffer = altsetting;
+ urb.UrbControlGetInterfaceRequest.Interface = (USHORT)interface_number;
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("getting interface failed: status: 0x%x, urb-status: 0x%x\n",
+ status, urb.UrbHeader.Status);
+ }
+ else
+ {
+ USBMSG("current altsetting is %d\n", *altsetting);
+ }
+
+ return status;
+}
+
+NTSTATUS get_interface_ex(libusb_device_t *dev,
+ interface_request_t* interface_request,
+ int timeout)
+{
+ unsigned char alt_number;
+ NTSTATUS status = STATUS_SUCCESS;
+
+ USB_INTERFACE_DESCRIPTOR *interface_descriptor = NULL;
+
+ USBMSG("interface-%s=%d timeout=%d\n",
+ interface_request->intf_use_index ? "index" : "number",
+ interface_request->intf_use_index ? interface_request->interface_index : interface_request->interface_number,
+ timeout);
+
+ if (!dev->config.value || !dev->config.descriptor)
+ {
+ USBERR0("device is not configured\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ interface_request->altsetting_index=FIND_INTERFACE_INDEX_ANY;
+ interface_descriptor = find_interface_desc_ex(dev->config.descriptor,dev->config.total_size,interface_request,NULL);
+ if (!interface_descriptor)
+ {
+ return STATUS_NO_MORE_ENTRIES;
+ }
+
+ status = get_interface(dev,interface_descriptor->bInterfaceNumber, &alt_number, timeout);
+ if (!NT_SUCCESS(status))
+ {
+ return STATUS_NO_MORE_ENTRIES;
+ }
+
+ interface_request->interface_number=interface_descriptor->bInterfaceNumber;
+ interface_request->altsetting_number=alt_number;
+ interface_request->altf_use_index=0;
+ interface_request->intf_use_index=0;
+
+ interface_descriptor = find_interface_desc_ex(dev->config.descriptor,dev->config.total_size,interface_request,NULL);
+ if (!interface_descriptor)
+ {
+ return STATUS_NO_MORE_ENTRIES;
+ }
+
+ return status;
+}
diff --git a/usb/driver/get_status.c b/usb/driver/get_status.c
new file mode 100644
index 0000000..2e77f91
--- /dev/null
+++ b/usb/driver/get_status.c
@@ -0,0 +1,74 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS get_status(libusb_device_t *dev, int recipient,
+ int index, char *status, int *ret, int timeout)
+{
+ NTSTATUS _status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("recipient: %02d index: %04d timeout: %d\n",
+ recipient, index, timeout);
+
+ memset(&urb, 0, sizeof(URB));
+
+ switch (recipient)
+ {
+ case USB_RECIP_DEVICE:
+ urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_DEVICE;
+ break;
+ case USB_RECIP_INTERFACE:
+ urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_INTERFACE;
+ break;
+ case USB_RECIP_ENDPOINT:
+ urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_ENDPOINT;
+ break;
+ case USB_RECIP_OTHER:
+ urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_OTHER;
+ break;
+ default:
+ USBERR0("invalid recipient\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST);
+ urb.UrbControlGetStatusRequest.TransferBufferLength = 2;
+ urb.UrbControlGetStatusRequest.TransferBuffer = status;
+ urb.UrbControlGetStatusRequest.Index = (USHORT)index;
+
+ _status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(_status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("getting status failed: status: 0x%x, urb-status: 0x%x\n",
+ _status, urb.UrbHeader.Status);
+ *ret = 0;
+ }
+ else
+ {
+ *ret = urb.UrbControlGetStatusRequest.TransferBufferLength;
+ }
+
+ return _status;
+}
+
diff --git a/usb/driver/ioctl.c b/usb/driver/ioctl.c
new file mode 100644
index 0000000..f059175
--- /dev/null
+++ b/usb/driver/ioctl.c
@@ -0,0 +1,795 @@
+/* libusb-win32, Generic Windows USB Library
+* Copyright (c) 2010 Travis Robinson <libusbdotnet@gmail.com>
+* Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+*
+* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+
+#include "libusb_driver.h"
+#include "libusb-win32_version.h"
+
+// used but all transfer functions to get a valid libusb_endpoint_t *
+// for the request.
+//
+#define TRANSFER_IOCTL_GET_PIPEINFO() \
+ /* check if the pipe exists and get the pipe information */ \
+ if (!get_pipe_info(dev, request->endpoint.endpoint,&pipe_info)) \
+ { \
+ USBERR("%s: failed getting pipe info for endpoint: %02Xh\n", \
+ dispCtlCode, request->endpoint.endpoint); \
+ status = STATUS_INVALID_PARAMETER; \
+ goto IOCTL_Done; \
+ }
+
+// warns if receive buffer is not an interval of the maximum packet size.
+#define TRANSFER_IOCTL_CHECK_READ_BUFFER() \
+ /* read buffer lengthd must be equal to or an interval of the max */ \
+ /* packet size */ \
+ if (!pipe_info->maximum_packet_size) \
+ { \
+ USBWRN("%s: wMaxPacketSize=0 for endpoint %02Xh.\n", \
+ dispCtlCode, request->endpoint.endpoint); \
+ status = STATUS_INVALID_PARAMETER; \
+ goto IOCTL_Done; \
+ } \
+ else if (transfer_buffer_length % pipe_info->maximum_packet_size) \
+ { \
+ USBWRN("%s: buffer length %d is not an interval wMaxPacketSize " \
+ "for endpoint %02Xh.\n", \
+ dispCtlCode, transfer_buffer_length, request->endpoint.endpoint); \
+ }
+
+// validates the urb function and direction against libusb_endpoint_t
+#define TRANSFER_IOCTL_CHECK_FUNCTION_AND_DIRECTION() \
+ if (urbFunction != UrbFunctionFromEndpoint(pipe_info) || \
+ usbdDirection != UsbdDirectionFromEndpoint(pipe_info)) \
+ { \
+ USBERR("%s: not compatible with endpoint %02Xh.\n" \
+ "\turbFunction =%Xh usbdDirection =%Xh\n" \
+ "\tpipeFunction =%Xh pipeDirection =%Xh\n", \
+ dispCtlCode, \
+ pipe_info->address, \
+ urbFunction,usbdDirection, \
+ UrbFunctionFromEndpoint(pipe_info), \
+ UsbdDirectionFromEndpoint(pipe_info)); \
+ status = STATUS_INVALID_PARAMETER; \
+ goto IOCTL_Done; \
+ }
+
+// calls the transfer function and returns NTSTATUS
+#define TRANSFER_IOCTL_EXECUTE() \
+ if (transfer_buffer_length > (ULONG)(maxTransferSize)) \
+ /* split large transfers */ \
+ return large_transfer(dev, irp, \
+ usbdDirection, \
+ urbFunction, \
+ pipe_info, \
+ request->endpoint.packet_size, \
+ maxTransferSize, \
+ request->endpoint.transfer_flags, \
+ request->endpoint.iso_start_frame_latency, \
+ transfer_buffer_mdl, \
+ transfer_buffer_length); \
+ else \
+ /* normal transfer */ \
+ return transfer(dev, irp, \
+ usbdDirection, \
+ urbFunction, \
+ pipe_info, \
+ request->endpoint.packet_size, \
+ request->endpoint.transfer_flags, \
+ request->endpoint.iso_start_frame_latency, \
+ transfer_buffer_mdl, \
+ transfer_buffer_length);
+
+NTSTATUS dispatch_ioctl(libusb_device_t *dev, IRP *irp)
+{
+ int maxTransferSize;
+ int ret = 0;
+ NTSTATUS status = STATUS_SUCCESS;
+
+ IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
+
+ ULONG control_code = stack_location->Parameters.DeviceIoControl.IoControlCode;
+
+ ULONG input_buffer_length = stack_location->Parameters.DeviceIoControl.InputBufferLength;
+ ULONG output_buffer_length = stack_location->Parameters.DeviceIoControl.OutputBufferLength;
+ ULONG transfer_buffer_length = stack_location->Parameters.DeviceIoControl.OutputBufferLength;
+
+ libusb_request *request = (libusb_request *)irp->AssociatedIrp.SystemBuffer;
+ char *output_buffer = (char *)irp->AssociatedIrp.SystemBuffer;
+ char *input_buffer = (char *)irp->AssociatedIrp.SystemBuffer;
+ MDL *transfer_buffer_mdl = irp->MdlAddress;
+ libusb_endpoint_t* pipe_info = NULL;
+ const char* dispCtlCode = NULL;
+ int urbFunction = -1;
+ int usbdDirection = -1;
+
+ status = remove_lock_acquire(dev);
+
+ if (!NT_SUCCESS(status))
+ {
+ status = complete_irp(irp, status, 0);
+ remove_lock_release(dev);
+ return status;
+ }
+
+ ///////////////////////////////////
+ // DIRECT control codes //
+ ///////////////////////////////////
+ switch(control_code)
+ {
+ case LIBUSB_IOCTL_INTERRUPT_OR_BULK_READ:
+
+ dispCtlCode = "INTERRUPT_OR_BULK_READ";
+
+ // check if the request and buffer is valid
+ if (!request || !transfer_buffer_mdl || input_buffer_length < sizeof(libusb_request))
+ {
+ USBERR("%s: invalid transfer request\n",
+ dispCtlCode);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ // check if the pipe exists and get the pipe information
+ TRANSFER_IOCTL_GET_PIPEINFO();
+
+ // must be a bulk or interrupt pipe
+ if (!IS_BULK_PIPE(pipe_info) && !IS_INTR_PIPE(pipe_info))
+ {
+ goto IoctlIsochronousRead;
+ /*
+ USBERR("%s: incorrect pipe type: %02Xh\n",
+ dispCtlCode, pipe_info->pipe_type);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ */
+ }
+
+ // read buffer length must be equal to or an interval of the max packet size
+ TRANSFER_IOCTL_CHECK_READ_BUFFER();
+
+ urbFunction = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER;
+ usbdDirection = USBD_TRANSFER_DIRECTION_IN;
+ maxTransferSize = GetMaxTransferSize(pipe_info, request->endpoint.max_transfer_size);
+
+ // ensure that the urb function and direction we set matches the
+ // pipe information
+ //
+ TRANSFER_IOCTL_CHECK_FUNCTION_AND_DIRECTION();
+
+ // calls the transfer function and returns NTSTATUS
+ TRANSFER_IOCTL_EXECUTE();
+
+ case LIBUSB_IOCTL_INTERRUPT_OR_BULK_WRITE:
+
+ dispCtlCode = "INTERRUPT_OR_BULK_WRITE";
+
+ /* we don't check 'transfer_buffer_mdl' here because it might be NULL */
+ /* if the DLL requests to send a zero-length packet */
+ if (!request || input_buffer_length < sizeof(libusb_request))
+ {
+ USBERR("%s: invalid transfer request\n", dispCtlCode);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ // check if the pipe exists and get the pipe information
+ TRANSFER_IOCTL_GET_PIPEINFO();
+
+ // must be a bulk or interrupt pipe
+ if (!IS_BULK_PIPE(pipe_info) && !IS_INTR_PIPE(pipe_info))
+ {
+ goto IoctlIsochronousWrite;
+ /*
+ USBERR("%s: incorrect pipe type: %02Xh\n",
+ dispCtlCode, pipe_info->pipe_type);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ */
+ }
+
+ urbFunction = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER;
+ usbdDirection = USBD_TRANSFER_DIRECTION_OUT;
+ maxTransferSize = GetMaxTransferSize(pipe_info, request->endpoint.max_transfer_size);
+
+ // ensure that the urb function and direction we set matches the
+ // pipe information
+ //
+ //TRANSFER_IOCTL_CHECK_FUNCTION_AND_DIRECTION();
+
+ // calls the transfer function and returns NTSTATUS
+ TRANSFER_IOCTL_EXECUTE();
+
+ case LIBUSB_IOCTL_ISOCHRONOUS_READ:
+
+ dispCtlCode = "ISOCHRONOUS_READ";
+
+ // check if the request and buffer is valid
+ if (!request || !transfer_buffer_mdl || input_buffer_length < sizeof(libusb_request))
+ {
+ USBERR("%s: invalid transfer request\n", dispCtlCode);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ // check if the pipe exists and get the pipe information
+ TRANSFER_IOCTL_GET_PIPEINFO();
+
+IoctlIsochronousRead:
+ dispCtlCode = "ISOCHRONOUS_READ";
+ // must be an isochronous endpoint
+ if (!IS_ISOC_PIPE(pipe_info))
+ {
+ USBERR("%s: incorrect pipe type: %02Xh\n",
+ dispCtlCode, pipe_info->pipe_type);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ // read buffer length must be equal to or an interval of the max packet size
+ TRANSFER_IOCTL_CHECK_READ_BUFFER();
+
+ urbFunction = URB_FUNCTION_ISOCH_TRANSFER;
+ usbdDirection = USBD_TRANSFER_DIRECTION_IN;
+
+ // Do not use large transfers/splitting for ISO.
+ maxTransferSize = 0x7fffffff;
+
+ // ensure that the urb function and direction we set matches the
+ // pipe information
+ //
+ TRANSFER_IOCTL_CHECK_FUNCTION_AND_DIRECTION();
+
+ // calls the transfer function and returns NTSTATUS
+ TRANSFER_IOCTL_EXECUTE();
+
+ case LIBUSB_IOCTL_ISOCHRONOUS_WRITE:
+
+ dispCtlCode = "ISOCHRONOUS_WRITE";
+
+ // check if the request and buffer is valid
+ if (!transfer_buffer_mdl || !request || input_buffer_length < sizeof(libusb_request))
+ {
+ USBERR("%s: invalid transfer request\n", dispCtlCode);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ // check if the pipe exists and get the pipe information
+ TRANSFER_IOCTL_GET_PIPEINFO();
+
+IoctlIsochronousWrite:
+ dispCtlCode = "ISOCHRONOUS_WRITE";
+ // must be an isochronous endpoint
+ if (!IS_ISOC_PIPE(pipe_info))
+ {
+ USBERR("%s: incorrect pipe type: %02Xh\n",
+ dispCtlCode, pipe_info->pipe_type);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ urbFunction = URB_FUNCTION_ISOCH_TRANSFER;
+ usbdDirection = USBD_TRANSFER_DIRECTION_OUT;
+ TRANSFER_IOCTL_CHECK_FUNCTION_AND_DIRECTION();
+
+ // Do not use large transfers/splitting for ISO.
+ maxTransferSize = 0x7fffffff;
+
+ // ensure that the urb function and direction we set matches the
+ // pipe information
+ //
+ TRANSFER_IOCTL_CHECK_FUNCTION_AND_DIRECTION();
+
+ TRANSFER_IOCTL_EXECUTE();
+ }
+
+ ///////////////////////////////////
+ // METHOD_BUFFERED control codes //
+ ///////////////////////////////////
+ if (!request || input_buffer_length < sizeof(libusb_request)
+ || input_buffer_length > LIBUSB_MAX_READ_WRITE
+ || output_buffer_length > LIBUSB_MAX_READ_WRITE
+ || transfer_buffer_length > LIBUSB_MAX_READ_WRITE)
+ {
+ USBERR0("invalid input or output buffer\n");
+
+ status = complete_irp(irp, STATUS_INVALID_PARAMETER, 0);
+ remove_lock_release(dev);
+ return status;
+ }
+
+ switch(control_code)
+ {
+ case LIBUSB_IOCTL_SET_CONFIGURATION:
+
+ status = set_configuration(dev,
+ request->configuration.configuration,
+ request->timeout);
+ break;
+
+ case LIBUSB_IOCTL_GET_CACHED_CONFIGURATION:
+ case LIBUSB_IOCTL_GET_CONFIGURATION:
+
+ if (!output_buffer || output_buffer_length < 1)
+ {
+ USBERR0("get_configuration: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+ if (control_code == LIBUSB_IOCTL_GET_CACHED_CONFIGURATION)
+ {
+ ret = 0;
+ if (dev->config.value >= 0)
+ {
+ *output_buffer = (char)dev->config.value;
+ ret = 1;
+ }
+ status = STATUS_SUCCESS;
+ }
+ else
+ {
+ status = get_configuration(dev, output_buffer, &ret, request->timeout);
+ }
+ break;
+
+ case LIBUSB_IOCTL_SET_INTERFACE:
+
+ status = set_interface(
+ dev,
+ request->intf.interface_number,
+ request->intf.altsetting_number,
+ request->timeout);
+
+ break;
+
+ case LIBUSB_IOCTL_GET_INTERFACE:
+
+ if (!output_buffer || output_buffer_length < 1)
+ {
+ USBERR0("get_interface: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+
+ status = get_interface(
+ dev,
+ request->intf.interface_number,
+ output_buffer,
+ request->timeout);
+
+ if (NT_SUCCESS(status))
+ ret = 1;
+
+ break;
+
+ case LIBUSB_IOCTL_SET_FEATURE:
+
+ status = set_feature(dev, request->feature.recipient,
+ request->feature.index, request->feature.feature,
+ request->timeout);
+
+ break;
+
+ case LIBUSB_IOCTL_CLEAR_FEATURE:
+
+ status = clear_feature(dev, request->feature.recipient,
+ request->feature.index, request->feature.feature,
+ request->timeout);
+
+ break;
+
+ case LIBUSB_IOCTL_GET_STATUS:
+
+ if (!output_buffer || output_buffer_length < 2)
+ {
+ USBERR0("get_status: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+
+ status = get_status(dev, request->status.recipient,
+ request->status.index, output_buffer,
+ &ret, request->timeout);
+
+ break;
+
+ case LIBUSB_IOCTL_SET_DESCRIPTOR:
+
+ if (input_buffer_length <= sizeof(libusb_request))
+ {
+ USBERR0("set_descriptor: invalid input buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+
+ status = set_descriptor(dev,
+ input_buffer + sizeof(libusb_request),
+ input_buffer_length - sizeof(libusb_request),
+ request->descriptor.type,
+ request->descriptor.recipient,
+ request->descriptor.index,
+ request->descriptor.language_id,
+ &ret, request->timeout);
+
+ break;
+
+ case LIBUSB_IOCTL_GET_DESCRIPTOR:
+
+ if (!output_buffer || !output_buffer_length)
+ {
+ USBERR0("get_descriptor: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+
+ status = get_descriptor(dev, output_buffer,
+ output_buffer_length,
+ request->descriptor.type,
+ request->descriptor.recipient,
+ request->descriptor.index,
+ request->descriptor.language_id,
+ &ret, request->timeout);
+
+ break;
+
+ case LIBUSB_IOCTL_VENDOR_READ:
+
+ if (output_buffer_length && !output_buffer)
+ {
+ USBERR0("vendor_read: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+
+ status = vendor_class_request(dev,
+ request->vendor.type,
+ request->vendor.recipient,
+ request->vendor.request,
+ request->vendor.value,
+ request->vendor.index,
+ output_buffer,
+ output_buffer_length,
+ USBD_TRANSFER_DIRECTION_IN,
+ &ret, request->timeout);
+ break;
+
+ case LIBUSB_IOCTL_VENDOR_WRITE:
+
+ status =
+ vendor_class_request(dev,
+ request->vendor.type,
+ request->vendor.recipient,
+ request->vendor.request,
+ request->vendor.value,
+ request->vendor.index,
+ input_buffer_length == sizeof(libusb_request) ?
+NULL : input_buffer + sizeof(libusb_request),
+ input_buffer_length - sizeof(libusb_request),
+ USBD_TRANSFER_DIRECTION_OUT,
+ &ret, request->timeout);
+ break;
+
+ case LIBUSB_IOCTL_RESET_ENDPOINT:
+
+ status = reset_endpoint(dev, request->endpoint.endpoint,
+ request->timeout);
+ break;
+
+ case LIBUSB_IOCTL_ABORT_ENDPOINT:
+
+ status = abort_endpoint(dev, request->endpoint.endpoint,
+ request->timeout);
+ break;
+
+ case LIBUSB_IOCTL_RESET_DEVICE:
+
+ status = reset_device(dev, request->timeout);
+ break;
+
+ case LIBUSB_IOCTL_RESET_DEVICE_EX:
+
+ status = reset_device_ex(dev, request->timeout, request->reset_ex.reset_type);
+ break;
+
+ case LIBUSB_IOCTL_SET_DEBUG_LEVEL:
+ usb_log_set_level(request->debug.level);
+ break;
+
+ case LIBUSB_IOCTL_GET_VERSION:
+
+ if (!request || output_buffer_length < sizeof(libusb_request))
+ {
+ USBERR0("get_version: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+
+ request->version.major = VERSION_MAJOR;
+ request->version.minor = VERSION_MINOR;
+ request->version.micro = VERSION_MICRO;
+ request->version.nano = VERSION_NANO;
+ request->version.mod_value = 1;
+
+ ret = sizeof(libusb_request);
+ break;
+
+ case LIBUSB_IOCTL_CLAIM_INTERFACE:
+ status = claim_interface(dev, stack_location->FileObject,
+ request->intf.interface_number);
+ break;
+
+ case LIBUSB_IOCTL_RELEASE_INTERFACE:
+ status = release_interface(dev, stack_location->FileObject,
+ request->intf.interface_number);
+ break;
+
+ case LIBUSB_IOCTL_GET_DEVICE_PROPERTY:
+ if (!request || output_buffer_length < sizeof(libusb_request))
+ {
+ USBERR0("get_device_property: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+ status = reg_get_device_property(
+ dev->physical_device_object,
+ request->device_property.property,
+ output_buffer,
+ output_buffer_length, &ret);
+ break;
+
+ case LIBUSB_IOCTL_GET_CUSTOM_REG_PROPERTY:
+ if (!input_buffer || (input_buffer_length < sizeof(libusb_request)))
+ {
+ USBERR0("get_custom_reg_property: invalid buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+ status=reg_get_custom_property(
+ dev->physical_device_object,
+ input_buffer,
+ output_buffer_length,
+ request->device_registry_key.name_offset,
+ &ret);
+ break;
+
+ case LIBUSB_IOCTL_GET_OBJECT_NAME:
+ if (!request || output_buffer_length < 2)
+ {
+ USBERR0("get_object_name: invalid output buffer\n");
+ status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+ switch (request->objname.objname_index)
+ {
+ case 0:
+ ret = (int)strlen(dev->objname_plugplay_registry_key)+1;
+ ret = ret > (int)output_buffer_length ? (int)output_buffer_length : ret;
+ RtlCopyMemory(output_buffer, dev->objname_plugplay_registry_key,(SIZE_T) (ret-1));
+ output_buffer[ret-1]='\0';
+ break;
+ default:
+ status = STATUS_INVALID_PARAMETER;
+ }
+ break;
+
+ case LIBUSB_IOCTL_QUERY_DEVICE_INFORMATION: // METHOD_BUFFERED (QUERY_DEVICE_INFORMATION)
+ status = STATUS_NOT_IMPLEMENTED;
+ break;
+
+ case LIBUSB_IOCTL_SET_PIPE_POLICY: // METHOD_BUFFERED (SET_PIPE_POLICY)
+ if (!request || !input_buffer || (input_buffer_length <= sizeof(libusb_request)))
+ {
+ USBERR0("set_pipe_policy: invalid output buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+ input_buffer+=sizeof(libusb_request);
+ input_buffer_length-=sizeof(libusb_request);
+ if (request->pipe_policy.policy_type==PIPE_TRANSFER_TIMEOUT)
+ {
+ if (input_buffer_length < sizeof(ULONG))
+ {
+ USBERR0("set_pipe_policy:pipe_transfer_timeout: invalid input buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+ if (request->pipe_policy.pipe_id & USB_ENDPOINT_ADDRESS_MASK)
+ {
+ status = STATUS_NOT_IMPLEMENTED;
+ break;
+ }
+
+ if (request->pipe_policy.pipe_id & USB_ENDPOINT_DIR_MASK)
+ dev->control_read_timeout=*((PULONG)input_buffer);
+ else
+ dev->control_write_timeout=*((PULONG)input_buffer);
+
+ status = STATUS_SUCCESS;
+ break;
+ }
+
+ break;
+
+ case LIBUSB_IOCTL_GET_PIPE_POLICY: // METHOD_BUFFERED (GET_PIPE_POLICY)
+ if (!request || input_buffer_length < sizeof(libusb_request) || !output_buffer || (output_buffer_length < 1))
+ {
+ USBERR0("get_pipe_policy: invalid output buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+ if (request->pipe_policy.policy_type==PIPE_TRANSFER_TIMEOUT)
+ {
+ if (output_buffer_length < sizeof(ULONG))
+ {
+ USBERR0("get_pipe_policy:pipe_transfer_timeout: invalid output buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+ if (request->pipe_policy.pipe_id & USB_ENDPOINT_ADDRESS_MASK)
+ {
+ status = STATUS_NOT_IMPLEMENTED;
+ break;
+ }
+ if (request->pipe_policy.pipe_id & USB_ENDPOINT_DIR_MASK)
+ *((PULONG)output_buffer) = dev->control_read_timeout;
+ else
+ *((PULONG)output_buffer) = dev->control_write_timeout;
+
+ status = STATUS_SUCCESS;
+ break;
+ }
+ break;
+
+ case LIBUSB_IOCTL_SET_POWER_POLICY: // METHOD_BUFFERED (SET_POWER_POLICY)
+ status = STATUS_NOT_IMPLEMENTED;
+ break;
+
+ case LIBUSB_IOCTL_GET_POWER_POLICY: // METHOD_BUFFERED (GET_POWER_POLICY)
+ status = STATUS_NOT_IMPLEMENTED;
+ break;
+
+ case LIBUSB_IOCTL_CONTROL_WRITE: // METHOD_IN_DIRECT (CONTROL_WRITE)
+ // check if the request and buffer is valid
+ if (!request || !transfer_buffer_mdl || input_buffer_length < sizeof(libusb_request))
+ {
+ USBERR("%s: invalid transfer request\n", dispCtlCode);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ status = control_transfer(
+ dev,
+ irp,
+ transfer_buffer_mdl,
+ transfer_buffer_length,
+ USBD_TRANSFER_DIRECTION_OUT,
+ &ret,
+ dev->control_write_timeout,
+ request->control.RequestType,
+ request->control.Request,
+ request->control.Value,
+ request->control.Index,
+ request->control.Length);
+
+ break;
+
+ case LIBUSB_IOCTL_CONTROL_READ: // METHOD_OUT_DIRECT (CONTROL_READ)
+ // check if the request and buffer is valid
+ if (!request || !transfer_buffer_mdl || input_buffer_length < sizeof(libusb_request))
+ {
+ USBERR("%s: invalid transfer request\n", dispCtlCode);
+ status = STATUS_INVALID_PARAMETER;
+ goto IOCTL_Done;
+ }
+
+ status = control_transfer(
+ dev,
+ irp,
+ transfer_buffer_mdl,
+ transfer_buffer_length,
+ USBD_TRANSFER_DIRECTION_IN,
+ &ret,
+ dev->control_read_timeout,
+ request->control.RequestType,
+ request->control.Request,
+ request->control.Value,
+ request->control.Index,
+ request->control.Length);
+
+ break;
+
+ case LIBUSB_IOCTL_FLUSH_PIPE: // METHOD_BUFFERED (FLUSH_PIPE)
+
+ status = STATUS_SUCCESS;
+ break;
+
+
+ case LIBUSBK_IOCTL_CLAIM_INTERFACE: // METHOD_BUFFERED (CLAIM_INTERFACE)
+ if (!request || output_buffer_length < sizeof(libusb_request))
+ {
+ USBERR0("claim_interfaceK: invalid output buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+
+ status = claim_interface_ex(dev, stack_location->FileObject, &request->intf);
+ if (NT_SUCCESS(status))
+ {
+ ret = sizeof(libusb_request);
+ }
+ break;
+
+ case LIBUSBK_IOCTL_RELEASE_INTERFACE: // METHOD_BUFFERED (RELEASE_INTERFACE)
+
+ if (!request || output_buffer_length < sizeof(libusb_request))
+ {
+ USBERR0("release_interfaceK: invalid output buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+
+ status = release_interface_ex(dev, stack_location->FileObject, &request->intf);
+ if (NT_SUCCESS(status))
+ {
+ ret = sizeof(libusb_request);
+ }
+ break;
+
+ case LIBUSBK_IOCTL_SET_INTERFACE: // METHOD_BUFFERED (SET_INTERFACE)
+
+ if (!request || output_buffer_length < sizeof(libusb_request))
+ {
+ USBERR0("set_interfaceK: invalid output buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+
+ status = set_interface_ex(dev, &request->intf, request->timeout);
+ if (NT_SUCCESS(status))
+ {
+ ret = sizeof(libusb_request);
+ }
+ break;
+
+ case LIBUSBK_IOCTL_GET_INTERFACE: // METHOD_BUFFERED (GET_INTERFACE)
+
+ if (!request || output_buffer_length < sizeof(libusb_request))
+ {
+ USBERR0("get_interfaceK: invalid output buffer\n");
+ status = STATUS_BUFFER_TOO_SMALL;
+ break;
+ }
+
+ status = get_interface_ex(dev, &request->intf, request->timeout);
+ if (NT_SUCCESS(status))
+ {
+ ret = sizeof(libusb_request);
+ }
+ break;
+
+ default:
+ status = STATUS_INVALID_PARAMETER;
+ }
+
+IOCTL_Done:
+ status = complete_irp(irp, status, ret);
+ remove_lock_release(dev);
+
+ return status;
+}
diff --git a/usb/driver/libusb-win32-README-1.2.6.0.txt b/usb/driver/libusb-win32-README-1.2.6.0.txt
new file mode 100644
index 0000000..99445f7
--- /dev/null
+++ b/usb/driver/libusb-win32-README-1.2.6.0.txt
@@ -0,0 +1,239 @@
+LibUsb-Win32 Change Log
+V1.2.6.0 (01/17/2012)
+==============================================
+* Official release.
+
+* Removed ISO maximum transfer size restrictions/transfer spltting.
+
+* Fixed inf-wizard device notification issue.
+
+V1.2.5.0 (07/23/2011)
+==============================================
+* Official release.
+
+V1.2.4.9 (07/13/2011) - SNAPSHOT RELEASE
+==============================================
+* Updated GCC lib file 'libusb.a'
+
+V1.2.4.8 (07/12/2011) - SNAPSHOT RELEASE
+==============================================
+* Added new public api function 'usb_reset_ex'. This is an extended
+ device reset function which allows developers to specify a port reset, a
+ port cycle, or both.
+
+* Added new public defines 'USB_RESET_TYPE_XXX' for 'usb_reset_ex'
+ function.
+
+V1.2.4.7 (07/02/2011) - SNAPSHOT RELEASE
+==============================================
+* Sync transfers which specify a zero (0) timeout are now considered to be
+ INFINITE.
+
+V1.2.4.6 (05/12/2011) - SNAPSHOT RELEASE
+==============================================
+* Added device interface registration. This provides identical
+ functionality to the "DeviceInterfaceGUIDs" supported by WinUSB and
+ libusbK. A device interface guid can be specified in the .inf file. They
+ can be used to quickly locate a usb device or set of USB devices using
+ the setup api as well as device notification registration.
+
+* New IOCTL codes added to for native libusbK/WinUSB compatibility.
+ NOTE: These IOCTLs are currently used only by libusbK.dll.
+ o LIBUSB_IOCTL_QUERY_DEVICE_INFORMATION
+ o LIBUSB_IOCTL_SET_PIPE_POLICY
+ o LIBUSB_IOCTL_GET_PIPE_POLICY
+ o LIBUSB_IOCTL_SET_POWER_POLICY
+ o LIBUSB_IOCTL_GET_POWER_POLICY
+ o LIBUSB_IOCTL_CONTROL_WRITE
+ o LIBUSB_IOCTL_CONTROL_READ
+ o LIBUSB_IOCTL_FLUSH_PIPE
+ o LIBUSBK_IOCTL_CLAIM_INTERFACE
+ o LIBUSBK_IOCTL_RELEASE_INTERFACE
+ o LIBUSBK_IOCTL_RELEASE_ALL_INTERFACES
+ o LIBUSBK_IOCTL_SET_INTERFACE
+ o LIBUSBK_IOCTL_GET_INTERFACE
+
+* Renamed main header file (usb.h) to lusb0_usb.h. This eliminates
+ conflicts with the main WDK usb include as well as making the
+ libusb-win32 header more distinguishable from other usb library header
+ files.
+
+* Added device descriptor caching and active/first config descriptor
+ caching. Descriptor caching prevents unnecessary control requests from
+ interrupting devices that could potentially be in-use. It also makes
+ libusb0.sys more compliant with usb libraries targeting platform where
+ descriptor caching is done automatically. (linux/mac)
+
+* Upgraded to libwdi v1.1.1
+ o Zadig UI improvements
+ o wdi-simple now handles certificate related operations
+ o New NSIS (Nullsoft Scriptable Install System) script sample
+ o improved INNO Setup script sample
+ o libusbK support
+ o autogeneration and self-signing of a .cat file, to prevent further security
+ prompts during driver installation on Vista and later.
+ for more information, see http://libwdi-cps.akeo.ie
+ o disable restore point creation during installation
+ o Visual Studio 2010 support and overall MS file cleanup
+ o use of the Kerberos/e2fsprogs parser in Zadig instead of libconfig
+
+V1.2.4.0 (04/11/2011)
+=======================
+* Removed get configuration request from the core driver
+ set_configuration function. This caused problems with
+ some non-compliant usb devices.
+
+* Added device descriptor dump to test applications.
+
+V1.2.3.0 (03/16/2011)
+=======================
+* Fixed bug-id 3117686 reported by Tim Schuerewegen.
+
+* Added LIBUSB_IOCTL_GET_OBJECT_NAME. This new IOCTL code retrieves object
+ from the driver. The only valid object name index is 0. Index 0 is
+ returns the devices plug and play registry key pathname.
+
+* Removed maximum timeout restriction for vendor class requests.
+
+V1.2.2.0 (10/02/2010)
+=======================
+* Added install-filter-win.exe. A gui installer for device filters.
+
+* Added new libusb0.dll function usb_install_np_rundll(). This function
+ is designed for rundll32.exe and takes the same parameters as
+ install-filter.exe.
+
+* Updated install-filter.exe. This application has several new features.
+ Type "install-filter --help" for more details.
+
+* Updated libusb-win32-devel-filter package. This package is once again
+ available for download as a setup.exe.
+
+* Updated libusb-win32 "bin" package format. inf-wizard.exe has been moved
+ up one directory.
+
+* Updated driver_installer_template.iss example. This is an Inno Setup
+ Script showing how to create your own setup.exe for installing your
+ application and driver.
+
+* Fixed missing byte order marker in inf-wizard.exe .inf files. (libwdi)
+
+* Fixed auto-configuration issue when there is more than one driver in the
+ stack.
+
+* Fixed BSOD when using the filter driver with devices that are auto
+ suspended by other drivers in the stack.
+
+* Fixed BSOD for devices with endpoints that have '0' for wMaxPacketSize.
+
+* Fixed BSOD when cancelling large transfers on high speed devices.
+
+
+V1.2.1.0 (07/28/2010)
+=======================
+* Updated bulk.c to include async i/o example code.
+
+* Fixed usb_install_driver_np() issue with inf-wizard generated infs.
+
+* Fixed inf2cat.exe issue with inf-wizard generated infs.
+
+* Added 'Install Now' feature to inf-wizard. (libwdi)
+
+* Added embedded libusb-win32 binaries to inf-wizard. (libwdi)
+
+* Added libwdi (http://www.libusb.org/wiki/libwdi) to inf-wizard.
+
+* Added get cached configuration request to usb_open(). This is a new
+ control code that involves no device i/o and allows
+ usb_set_configuration() to be omitted if the driver has already
+ configured it.
+
+* Fixed set_configuration() failure for devices that do not properly
+ support get_configuration().
+
+V1.2.0.0 (07/07/2010)
+=======================
+* First signed driver release! The libusb-win32 kernel driver (libusb0.sys)
+ can now be used on x64 Windows machines that require signed drivers.
+
+* Fixed 2128187 reported by Tim Green. usb_get_descriptor() can fail
+ because the given buffer of 8 bytes is too small.
+
+* Fixed 2928293 reported by Tim Green. Sometimes the call to
+ usb_fetch_and_parse_descriptors() in usb_find_devices() can fail. This
+ patch moves the LIST_ADD to after a successful read of the device's
+ configuration descriptors.
+
+* Fixed issue causing libusb-win32 to not act as power policy owner
+ when it should.
+
+* Fixed issue in which on rare occasion, a libusb-win32 filter device could
+ run as a "normal" device.
+
+* Fixed filter driver issue for device using wudfr.sys.
+
+* Added large transfer splitting to driver (bulk, int, iso). NOTE:
+ The dll continues to break transfers in the same manner it always has.
+
+
+V1.1.14.3 (06/12/2010)
+=======================
+* Remove get_configuration() request from usb_open(). This caused claim
+ interface to fail when used as a filter driver.
+
+V1.1.14.0 (06/01/2010)
+=======================
+* Updated logging functions and standardized log message display format.
+
+* Updated inf-wizard to use the new directory format for the libusb-win32
+ binaries.
+
+* Updated package directories to reflect the winddk BUILDARCH env variable.
+ (i64 := ia64, x64 := amd64)
+
+* Added request to get the current configuration in usb_open().
+
+* Fixed 2960644 (reported by farthen) crash on shutdown with x64 based
+ systems while using inf files for each libusb device.
+
+* Added additional log message only included in debug/chk builds.
+
+* Updated default log levels to highest verbose level for debug builds.
+
+* Added test signing support to the libusb-win32 make.cmd. This allows
+ libusb0.sys and libusb0.dll to be signed with a digital signature.
+ (see make.cmd for mmore details)
+
+* Added MSVC 2008 project files
+
+* Moved version defines to an include file (libusb_version.h)
+ This file is generated from libusb_version_h.in with "make.cmd makever"
+
+* Removed all "dist" commands from cyg/mingw makefile. Instead use "make.cmd"
+ in the "ddk_make" directory.
+
+* Fixed filter setup not running in 64bit mode
+
+* Fixed 64bit inf-wizard, testlibusb-win builds
+
+* Added set initial config value #1 when the driver is not a filter.
+ optionally, the initial configuration value can be specified in the inf
+ file: HKR,,"InitialConfigValue",0x00010001,<your config value>
+
+* Added support for querying device registry keys
+ (LIBUSB_IOCTL_GET_CUSTOM_REG_PROPERTY)
+
+* Added support for querying device properties
+ (LIBUSB_IOCTL_GET_DEVICE_PROPERTY)
+
+* Fixed possible race condition in kernel add_device()
+
+* Updated default ddk build version number to 1.1.14.0 to facilitate
+ Microsoft WHQL submission.
+
+* Added DDK build distribution system. Official libusb-win32 releases
+ (after 0.1.12.2) are built using Microsoft's WinDDK. (see make.cmd)
+
+* Fixed 2658937 (reported by Tim Roberts) The libusb-win32 driver always
+ acts as a power policy owner.
+
diff --git a/usb/driver/libusb_driver.c b/usb/driver/libusb_driver.c
new file mode 100644
index 0000000..61ebf77
--- /dev/null
+++ b/usb/driver/libusb_driver.c
@@ -0,0 +1,971 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#define __LIBUSB_DRIVER_C__
+
+#include "libusb_driver.h"
+#include "libusb-win32_version.h"
+
+// Device objects with an attached device using the
+// driver names listed here skipped in the add_device() routine.
+//
+const char* attached_driver_skip_list[] =
+{
+ "\\driver\\picopp",
+ "\\driver\\libusb0",
+ NULL
+};
+
+// Device objects with an attached device using the
+// driver names listed here have wdf below them. Special
+// restrictions apply to these devices.
+//
+const char* attached_driver_wdf_list[] =
+{
+ "\\driver\\winusb",
+ "\\driver\\wudfrd",
+ NULL
+};
+
+static bool_t match_driver(PDEVICE_OBJECT deviceObject, const char* driverString);
+
+
+#ifdef DBG
+
+static void debug_show_devices(PDEVICE_OBJECT deviceObject, int index, bool_t showNextDevice)
+{
+ ANSI_STRING driverName;
+
+ if (index > 16) return;
+
+ if (deviceObject)
+ {
+ if (deviceObject->DriverObject)
+ {
+ if (NT_SUCCESS(RtlUnicodeStringToAnsiString(&driverName, &deviceObject->DriverObject->DriverName, TRUE)))
+ {
+ USBDBG("[%s #%d] %s\n",
+ (showNextDevice ? "NextDevice" : "AttachedDevice"),
+ index, driverName.Buffer);
+ RtlFreeAnsiString(&driverName);
+ }
+ }
+ if (deviceObject->AttachedDevice && !showNextDevice)
+ debug_show_devices(deviceObject->AttachedDevice, index+1, showNextDevice);
+ if (deviceObject->NextDevice && showNextDevice)
+ debug_show_devices(deviceObject->NextDevice, index+1, showNextDevice);
+ }
+}
+#endif
+
+static bool_t match_driver(PDEVICE_OBJECT deviceObject, const char* driverString)
+{
+ ANSI_STRING driverName;
+ bool_t ret = FALSE;
+
+ if (deviceObject)
+ {
+ if (deviceObject->DriverObject)
+ {
+ if (NT_SUCCESS(RtlUnicodeStringToAnsiString(&driverName, &deviceObject->DriverObject->DriverName, TRUE)))
+ {
+ _strlwr(driverName.Buffer);
+
+ if (strstr(driverName.Buffer,driverString))
+ {
+ ret = TRUE;
+ }
+ RtlFreeAnsiString(&driverName);
+ }
+ }
+ }
+
+ return ret;
+}
+
+static void DDKAPI unload(DRIVER_OBJECT *driver_object);
+static NTSTATUS DDKAPI on_usbd_complete(DEVICE_OBJECT *device_object,
+ IRP *irp,
+ void *context);
+
+NTSTATUS DDKAPI DriverEntry(DRIVER_OBJECT *driver_object,
+ UNICODE_STRING *registry_path)
+{
+ int i;
+
+ USBMSG("[loading-driver] v%d.%d.%d.%d\n",
+ VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO, VERSION_NANO);
+
+ /* initialize the driver object's dispatch table */
+ for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
+ {
+ driver_object->MajorFunction[i] = dispatch;
+ }
+
+ driver_object->DriverExtension->AddDevice = add_device;
+ driver_object->DriverUnload = unload;
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS DDKAPI add_device(DRIVER_OBJECT *driver_object,
+ DEVICE_OBJECT *physical_device_object)
+{
+ NTSTATUS status;
+ DEVICE_OBJECT *device_object = NULL;
+ libusb_device_t *dev;
+ ULONG device_type;
+ UNICODE_STRING nt_device_name;
+ UNICODE_STRING symbolic_link_name;
+ WCHAR tmp_name_0[128];
+ WCHAR tmp_name_1[128];
+ char id[256];
+ char compat_id[256];
+ int i;
+ DEVICE_OBJECT* attached_device;
+ bool_t has_wdf = FALSE;
+
+ /* get the hardware ID from the registry */
+ if (!reg_get_hardware_id(physical_device_object, id, sizeof(id)))
+ {
+ USBERR0("unable to read registry\n");
+ return STATUS_SUCCESS;
+ }
+
+ /* only attach the (filter) driver to USB devices, skip hubs */
+ if (!strstr(id, "usb\\") ||
+ strstr(id, "hub") ||
+ !strstr(id, "vid_") ||
+ !strstr(id, "pid_"))
+ {
+ USBDBG("skipping non-usb device or hub %s\n",id);
+ return STATUS_SUCCESS;
+ }
+
+ if (!reg_get_compatible_id(physical_device_object, compat_id, sizeof(compat_id)))
+ {
+ USBERR0("unable to read registry\n");
+ return STATUS_SUCCESS;
+ }
+ // Don't attach to usb device hubs
+ if (strstr(compat_id, "class_09"))
+ {
+ USBDBG("skipping usb device hub (%s) %s\n",compat_id, id);
+ return STATUS_SUCCESS;
+ }
+
+#ifdef DBG
+ debug_show_devices(physical_device_object->AttachedDevice, 0, FALSE);
+#endif
+
+ attached_device = physical_device_object->AttachedDevice;
+ while (attached_device)
+ {
+ // make sure this device isn't already using a driver that is
+ // incompatible with libusb-win32.
+ for (i=0; attached_driver_skip_list[i] != NULL; i++)
+ {
+ if (match_driver(attached_device, attached_driver_skip_list[i]))
+ {
+ USBDBG("skipping device %s\n", id);
+ return STATUS_SUCCESS;
+ }
+ }
+
+ // look for wdf
+ for (i=0; attached_driver_wdf_list[i] != NULL; i++)
+ {
+ if (match_driver(attached_device, attached_driver_wdf_list[i]))
+ {
+ has_wdf = TRUE;
+ }
+ }
+
+ attached_device=attached_device->AttachedDevice;
+ }
+
+ device_object = IoGetAttachedDeviceReference(physical_device_object);
+ if (device_object)
+ {
+ device_type = device_object->DeviceType;
+ ObDereferenceObject(device_object);
+ }
+ else
+ {
+ device_type = FILE_DEVICE_UNKNOWN;
+ }
+
+ /* try to create a new device object */
+ for (i = 1; i < LIBUSB_MAX_NUMBER_OF_DEVICES; i++)
+ {
+ /* initialize some unicode strings */
+ _snwprintf(tmp_name_0, sizeof(tmp_name_0)/sizeof(WCHAR), L"%s%04d",
+ LIBUSB_NT_DEVICE_NAME, i);
+ _snwprintf(tmp_name_1, sizeof(tmp_name_1)/sizeof(WCHAR), L"%s%04d",
+ LIBUSB_SYMBOLIC_LINK_NAME, i);
+
+ RtlInitUnicodeString(&nt_device_name, tmp_name_0);
+ RtlInitUnicodeString(&symbolic_link_name, tmp_name_1);
+
+ /* create the object */
+ status = IoCreateDevice(driver_object,
+ sizeof(libusb_device_t),
+ &nt_device_name, device_type, 0, FALSE,
+ &device_object);
+
+ if (NT_SUCCESS(status))
+ {
+ USBMSG("device #%d created for %s\n", i, id);
+ break;
+ }
+
+ device_object = NULL;
+
+ /* continue until an unused device name is found */
+ }
+
+ if (!device_object)
+ {
+ USBERR0("creating device failed\n");
+ return status;
+ }
+
+ status = IoCreateSymbolicLink(&symbolic_link_name, &nt_device_name);
+
+ if (!NT_SUCCESS(status))
+ {
+ USBERR0("creating symbolic link failed\n");
+ IoDeleteDevice(device_object);
+ return status;
+ }
+
+ /* setup the "device object" */
+ dev = device_object->DeviceExtension;
+
+ memset(dev, 0, sizeof(libusb_device_t));
+
+ // [trobinso] See patch: 2873573 (Tim Green)
+ dev->self = device_object;
+ dev->physical_device_object = physical_device_object;
+ dev->id = i;
+
+ // store the device id in the device extentions
+ RtlCopyMemory(dev->device_id, id, sizeof(dev->device_id));
+
+ /* set initial power states */
+ dev->power_state.DeviceState = PowerDeviceD0;
+ dev->power_state.SystemState = PowerSystemWorking;
+
+ dev->disallow_power_control = has_wdf;
+
+ /* get device properties from the registry */
+ if (!reg_get_properties(dev))
+ {
+ USBERR0("getting device properties failed\n");
+ IoDeleteSymbolicLink(&symbolic_link_name);
+ IoDeleteDevice(device_object);
+ return STATUS_SUCCESS;
+ }
+
+ if (dev->is_filter && !physical_device_object->AttachedDevice)
+ {
+ USBWRN("[FILTER-MODE-MISMATCH] device is reporting itself as filter when there are no attached device(s).\n%s\n", id);
+ }
+ else if (!dev->is_filter && physical_device_object->AttachedDevice)
+ {
+ USBWRN("[FILTER-MODE-MISMATCH] device is reporting itself as normal when there are already attached device(s).\n%s\n", id);
+ //dev->is_filter = TRUE;
+ }
+
+ clear_pipe_info(dev);
+
+ remove_lock_initialize(dev);
+
+ if (dev->device_interface_in_use)
+ {
+ status = IoRegisterDeviceInterface(physical_device_object,
+ (LPGUID)&dev->device_interface_guid,
+ NULL,
+ &dev->device_interface_name);
+ if (!NT_SUCCESS (status))
+ {
+ dev->device_interface_name.Buffer = NULL;
+
+ USBERR0("creating device interface failed\n");
+ IoDeleteSymbolicLink(&symbolic_link_name);
+ IoDeleteDevice(device_object);
+ return status;
+ }
+ else
+ {
+ set_filter_interface_key(dev,dev->id);
+ if (dev->device_interface_in_use)
+ {
+ HANDLE hKey=NULL;
+ if (NT_SUCCESS(IoOpenDeviceInterfaceRegistryKey(&dev->device_interface_name,KEY_ALL_ACCESS,&hKey)))
+ {
+ UNICODE_STRING valueName;
+ RtlInitUnicodeString(&valueName, L"LUsb0");
+
+ if (NT_SUCCESS(ZwSetValueKey(hKey,&valueName, 0, REG_DWORD, &dev->id,sizeof(ULONG))))
+ {
+ USBMSG("updated interface registry with LUsb0 direct-access symbolic link. id=%04d\n",dev->id);
+ }
+ else
+ {
+ USBERR0("IoOpenDeviceInterfaceRegistryKey:ZwSetValueKey failed\n");
+ }
+ ZwClose(hKey);
+ }
+ else
+ {
+ USBERR0("IoOpenDeviceInterfaceRegistryKey failed\n");
+ }
+ }
+ }
+ }
+ // make sure the the devices can't be removed
+ // before we are done adding it.
+ if (!NT_SUCCESS(remove_lock_acquire(dev)))
+ {
+ USBERR0("remove_lock_acquire failed\n");
+ IoDeleteSymbolicLink(&symbolic_link_name);
+ IoDeleteDevice(device_object);
+ return STATUS_SUCCESS;
+ }
+
+ /* attach the newly created device object to the stack */
+ dev->next_stack_device = IoAttachDeviceToDeviceStack(device_object, physical_device_object);
+
+ if (!dev->next_stack_device)
+ {
+ USBERR("attaching %s to device stack failed\n", id);
+ IoDeleteSymbolicLink(&symbolic_link_name);
+ IoDeleteDevice(device_object);
+ remove_lock_release(dev); // always release acquired locks
+ return STATUS_NO_SUCH_DEVICE;
+ }
+
+ if (dev->is_filter)
+ {
+ USBDBG("[filter-mode] id=#%d %s\n",dev->id, dev->device_id);
+
+ /* send all USB requests to the PDO in filter driver mode */
+ dev->target_device = dev->physical_device_object;
+
+ /* use the same flags as the underlying object */
+ device_object->Flags |= dev->next_stack_device->Flags
+ & (DO_BUFFERED_IO | DO_DIRECT_IO | DO_POWER_PAGABLE);
+
+ // use the same DeviceType as the underlying object
+ device_object->DeviceType = dev->next_stack_device->DeviceType;
+
+ // use the same Characteristics as the underlying object
+ device_object->Characteristics = dev->next_stack_device->Characteristics;
+ }
+ else
+ {
+ USBDBG("[normal-mode] id=#%d %s\n",dev->id, dev->device_id);
+
+ /* send all USB requests to the lower object in device driver mode */
+ dev->target_device = dev->next_stack_device;
+ device_object->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE;
+ }
+
+ UpdateContextConfigDescriptor(dev,NULL,0,0,-1);
+
+ device_object->Flags &= ~DO_DEVICE_INITIALIZING;
+ remove_lock_release(dev);
+
+ USBMSG("complete status=%08X\n",status);
+ return status;
+}
+
+
+VOID DDKAPI unload(DRIVER_OBJECT *driver_object)
+{
+ USBMSG("[unloading-driver] v%d.%d.%d.%d\n",
+ VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO, VERSION_NANO);
+}
+
+NTSTATUS complete_irp(IRP *irp, NTSTATUS status, ULONG info)
+{
+ irp->IoStatus.Status = status;
+ irp->IoStatus.Information = info;
+ IoCompleteRequest(irp, IO_NO_INCREMENT);
+
+ return status;
+}
+
+NTSTATUS call_usbd_ex(libusb_device_t *dev, void *urb, ULONG control_code,
+ int timeout, int max_timeout)
+{
+ KEVENT event;
+ NTSTATUS status;
+ IRP *irp;
+ IO_STACK_LOCATION *next_irp_stack;
+ LARGE_INTEGER _timeout;
+ IO_STATUS_BLOCK io_status;
+
+ if (max_timeout > 0 && timeout > max_timeout)
+ {
+ timeout = max_timeout;
+ }
+ if (timeout <= 0)
+ timeout = LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT;
+
+ KeInitializeEvent(&event, NotificationEvent, FALSE);
+
+ irp = IoBuildDeviceIoControlRequest(control_code, dev->target_device,
+ NULL, 0, NULL, 0, TRUE,
+ NULL, &io_status);
+
+ if (!irp)
+ {
+ return STATUS_NO_MEMORY;
+ }
+
+ next_irp_stack = IoGetNextIrpStackLocation(irp);
+ next_irp_stack->Parameters.Others.Argument1 = urb;
+ next_irp_stack->Parameters.Others.Argument2 = NULL;
+
+ IoSetCompletionRoutine(irp, on_usbd_complete, &event, TRUE, TRUE, TRUE);
+
+ status = IoCallDriver(dev->target_device, irp);
+ if(status == STATUS_PENDING)
+ {
+ _timeout.QuadPart = -(timeout * 10000);
+
+ if(KeWaitForSingleObject(&event, Executive, KernelMode,
+ FALSE, &_timeout) == STATUS_TIMEOUT)
+ {
+ USBERR0("request timed out\n");
+ IoCancelIrp(irp);
+ }
+ }
+
+ /* wait until completion routine is called */
+ KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+
+ status = irp->IoStatus.Status;
+
+ /* complete the request */
+ IoCompleteRequest(irp, IO_NO_INCREMENT);
+
+ USBDBG("status = %08Xh\n",status);
+ return status;
+}
+
+static NTSTATUS DDKAPI on_usbd_complete(DEVICE_OBJECT *device_object,
+ IRP *irp, void *context)
+{
+ KeSetEvent((KEVENT *) context, IO_NO_INCREMENT, FALSE);
+
+ return STATUS_MORE_PROCESSING_REQUIRED;
+}
+
+
+NTSTATUS pass_irp_down(libusb_device_t *dev, IRP *irp,
+ PIO_COMPLETION_ROUTINE completion_routine,
+ void *context)
+{
+ if (completion_routine)
+ {
+ IoCopyCurrentIrpStackLocationToNext(irp);
+ IoSetCompletionRoutine(irp, completion_routine, context,
+ TRUE, TRUE, TRUE);
+ }
+ else
+ {
+ IoSkipCurrentIrpStackLocation(irp);
+ }
+
+ return IoCallDriver(dev->next_stack_device, irp);
+}
+/*
+bool_t accept_irp(libusb_device_t *dev, IRP *irp)
+{
+ if (irp->Tail.Overlay.OriginalFileObject)
+ {
+ return irp->Tail.Overlay.OriginalFileObject->DeviceObject
+ == dev->self ? TRUE : FALSE;
+ }
+
+ return FALSE;
+}
+*/
+bool_t accept_irp(libusb_device_t *dev, IRP *irp)
+{
+ /* check if the IRP is sent to libusb's device object or to */
+ /* the lower one. This check is necessary since the device object */
+ /* might be a filter */
+ if(!irp->Tail.Overlay.OriginalFileObject)
+ return FALSE;
+ if (irp->Tail.Overlay.OriginalFileObject->DeviceObject == dev->self)
+ return TRUE;
+
+ /* cover the cases when access is made by using device interfaces */
+ if (!dev->is_filter &&
+ dev->device_interface_in_use &&
+ (irp->Tail.Overlay.OriginalFileObject->DeviceObject == dev->physical_device_object))
+ return TRUE;
+
+ return FALSE;
+}
+
+bool_t get_pipe_handle(libusb_device_t *dev, int endpoint_address,
+ USBD_PIPE_HANDLE *pipe_handle)
+{
+ int i, j;
+
+ *pipe_handle = NULL;
+
+ for (i = 0; i < LIBUSB_MAX_NUMBER_OF_INTERFACES; i++)
+ {
+ if (dev->config.interfaces[i].valid)
+ {
+ for (j = 0; j < LIBUSB_MAX_NUMBER_OF_ENDPOINTS; j++)
+ {
+ if (dev->config.interfaces[i].endpoints[j].address
+ == endpoint_address)
+ {
+ *pipe_handle = dev->config.interfaces[i].endpoints[j].handle;
+
+ return !*pipe_handle ? FALSE : TRUE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+bool_t get_pipe_info(libusb_device_t *dev, int endpoint_address,
+ libusb_endpoint_t** pipe_info)
+{
+ int i, j;
+
+ *pipe_info = NULL;
+
+ for (i = 0; i < LIBUSB_MAX_NUMBER_OF_INTERFACES; i++)
+ {
+ if (dev->config.interfaces[i].valid)
+ {
+ for (j = 0; j < LIBUSB_MAX_NUMBER_OF_ENDPOINTS; j++)
+ {
+ if (dev->config.interfaces[i].endpoints[j].address
+ == endpoint_address)
+ {
+ *pipe_info = &dev->config.interfaces[i].endpoints[j];
+
+ return !*pipe_info ? FALSE : TRUE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+void clear_pipe_info(libusb_device_t *dev)
+{
+ memset(dev->config.interfaces, 0 , sizeof(dev->config.interfaces));
+}
+
+bool_t update_pipe_info(libusb_device_t *dev,
+ USBD_INTERFACE_INFORMATION *interface_info)
+{
+ int i;
+ int number;
+ int maxTransferSize;
+ int maxPacketSize;
+
+ if (!interface_info)
+ {
+ return FALSE;
+ }
+
+ number = interface_info->InterfaceNumber;
+
+ if (interface_info->InterfaceNumber >= LIBUSB_MAX_NUMBER_OF_INTERFACES)
+ {
+ return FALSE;
+ }
+
+ USBMSG("interface %d\n", number);
+
+ dev->config.interfaces[number].valid = TRUE;
+
+ for (i = 0; i < LIBUSB_MAX_NUMBER_OF_ENDPOINTS; i++)
+ {
+ dev->config.interfaces[number].endpoints[i].address = 0;
+ dev->config.interfaces[number].endpoints[i].handle = NULL;
+ }
+
+ if (interface_info)
+ {
+ for (i = 0; i < (int)interface_info->NumberOfPipes
+ && i < LIBUSB_MAX_NUMBER_OF_ENDPOINTS; i++)
+ {
+ maxPacketSize = interface_info->Pipes[i].MaximumPacketSize;
+ maxTransferSize = interface_info->Pipes[i].MaximumTransferSize;
+
+ USBMSG("EP%02Xh maximum-packet-size=%d maximum-transfer-size=%d\n",
+ interface_info->Pipes[i].EndpointAddress,
+ maxPacketSize,
+ maxTransferSize);
+
+ dev->config.interfaces[number].endpoints[i].handle = interface_info->Pipes[i].PipeHandle;
+ dev->config.interfaces[number].endpoints[i].address = interface_info->Pipes[i].EndpointAddress;
+ dev->config.interfaces[number].endpoints[i].maximum_packet_size = maxPacketSize;
+ dev->config.interfaces[number].endpoints[i].interval = interface_info->Pipes[i].Interval;
+ dev->config.interfaces[number].endpoints[i].pipe_type = interface_info->Pipes[i].PipeType;
+ dev->config.interfaces[number].endpoints[i].pipe_flags = interface_info->Pipes[i].PipeFlags;
+
+ if (maxPacketSize)
+ {
+ // set max the maximum transfer size default to an interval of max packet size.
+ maxTransferSize = maxTransferSize - (maxTransferSize % maxPacketSize);
+ if (maxTransferSize < maxPacketSize)
+ {
+ maxTransferSize = LIBUSB_MAX_READ_WRITE;
+ }
+ else if (maxTransferSize > LIBUSB_MAX_READ_WRITE)
+ {
+ maxTransferSize = LIBUSB_MAX_READ_WRITE - (LIBUSB_MAX_READ_WRITE % maxPacketSize);
+ }
+
+ if (maxTransferSize != interface_info->Pipes[i].MaximumTransferSize)
+ {
+ USBWRN("overriding EP%02Xh maximum-transfer-size=%d\n",
+ dev->config.interfaces[number].endpoints[i].address,
+ maxTransferSize);
+ }
+ }
+ else
+ {
+ if (!maxTransferSize)
+ {
+ // use the libusb-win32 default
+ maxTransferSize = LIBUSB_MAX_READ_WRITE;
+ }
+ }
+ dev->config.interfaces[number].endpoints[i].maximum_transfer_size = maxTransferSize;
+ }
+ }
+ return TRUE;
+}
+
+
+void remove_lock_initialize(libusb_device_t *dev)
+{
+ KeInitializeEvent(&dev->remove_lock.event, NotificationEvent, FALSE);
+ dev->remove_lock.usage_count = 1;
+ dev->remove_lock.remove_pending = FALSE;
+}
+
+
+NTSTATUS remove_lock_acquire(libusb_device_t *dev)
+{
+ InterlockedIncrement(&dev->remove_lock.usage_count);
+
+ if (dev->remove_lock.remove_pending)
+ {
+ if (InterlockedDecrement(&dev->remove_lock.usage_count) == 0)
+ {
+ KeSetEvent(&dev->remove_lock.event, 0, FALSE);
+ }
+ return STATUS_DELETE_PENDING;
+ }
+ return STATUS_SUCCESS;
+}
+
+
+void remove_lock_release(libusb_device_t *dev)
+{
+ if (InterlockedDecrement(&dev->remove_lock.usage_count) == 0)
+ {
+ KeSetEvent(&dev->remove_lock.event, 0, FALSE);
+ }
+}
+
+
+void remove_lock_release_and_wait(libusb_device_t *dev)
+{
+ dev->remove_lock.remove_pending = TRUE;
+ remove_lock_release(dev);
+ remove_lock_release(dev);
+ KeWaitForSingleObject(&dev->remove_lock.event, Executive, KernelMode,
+ FALSE, NULL);
+}
+
+
+USB_INTERFACE_DESCRIPTOR *
+find_interface_desc(USB_CONFIGURATION_DESCRIPTOR *config_desc,
+ unsigned int size, int interface_number, int altsetting)
+{
+ usb_descriptor_header_t *desc = (usb_descriptor_header_t *)config_desc;
+ char *p = (char *)desc;
+ USB_INTERFACE_DESCRIPTOR *if_desc = NULL;
+
+ if (!config_desc || (size < config_desc->wTotalLength))
+ return NULL;
+
+ while (size && desc->length <= size)
+ {
+ if (desc->type == USB_INTERFACE_DESCRIPTOR_TYPE)
+ {
+ if_desc = (USB_INTERFACE_DESCRIPTOR *)desc;
+
+ if ((if_desc->bInterfaceNumber == (UCHAR)interface_number)
+ && (if_desc->bAlternateSetting == (UCHAR)altsetting))
+ {
+ return if_desc;
+ }
+ }
+
+ size -= desc->length;
+ p += desc->length;
+ desc = (usb_descriptor_header_t *)p;
+ }
+
+ return NULL;
+}
+
+USB_INTERFACE_DESCRIPTOR* find_interface_desc_ex(USB_CONFIGURATION_DESCRIPTOR *config_desc,
+ unsigned int size,
+ interface_request_t* intf,
+ unsigned int* size_left)
+{
+#define INTF_FIELD 0
+#define ALTF_FIELD 1
+
+ usb_descriptor_header_t *desc = (usb_descriptor_header_t *)config_desc;
+ char *p = (char *)desc;
+ int lastInfNumber, lastAltNumber;
+ int currentInfIndex;
+ short InterfacesByIndex[LIBUSB_MAX_NUMBER_OF_INTERFACES][2];
+
+ USB_INTERFACE_DESCRIPTOR *if_desc = NULL;
+
+ memset(InterfacesByIndex,0xFF,sizeof(InterfacesByIndex));
+
+ if (!config_desc)
+ return NULL;
+
+ size = size > config_desc->wTotalLength ? config_desc->wTotalLength : size;
+
+ while (size && desc->length <= size)
+ {
+ if (desc->type == USB_INTERFACE_DESCRIPTOR_TYPE)
+ {
+ // this is a new interface or alternate interface
+ if_desc = (USB_INTERFACE_DESCRIPTOR *)desc;
+ for (currentInfIndex=0; currentInfIndex<LIBUSB_MAX_NUMBER_OF_INTERFACES;currentInfIndex++)
+ {
+ if (InterfacesByIndex[currentInfIndex][INTF_FIELD]==-1)
+ {
+ // this is a new interface
+ InterfacesByIndex[currentInfIndex][INTF_FIELD]=if_desc->bInterfaceNumber;
+ InterfacesByIndex[currentInfIndex][ALTF_FIELD]=0;
+ break;
+ }
+ else if (InterfacesByIndex[currentInfIndex][INTF_FIELD]==if_desc->bInterfaceNumber)
+ {
+ // this is a new alternate interface
+ InterfacesByIndex[currentInfIndex][ALTF_FIELD]++;
+ break;
+ }
+ }
+
+ // if the interface index is -1, then we don't care;
+ // i.e. any interface number or index
+ if (intf->interface_index!=FIND_INTERFACE_INDEX_ANY)
+ {
+ if (intf->intf_use_index)
+ {
+ // looking for a particular interface index; if this is not it then continue on.
+ if (intf->interface_index != currentInfIndex)
+ goto NextInterface;
+ }
+ else
+ {
+ // looking for a particular interface number; if this is not it then continue on.
+ if (intf->interface_number != if_desc->bInterfaceNumber)
+ goto NextInterface;
+ }
+ }
+
+ if (intf->altsetting_index!=FIND_INTERFACE_INDEX_ANY)
+ {
+ if (intf->altf_use_index)
+ {
+ // looking for a particular alternate interface index; if this is not it then continue on.
+ if (intf->altsetting_index != InterfacesByIndex[currentInfIndex][ALTF_FIELD])
+ goto NextInterface;
+ }
+ else
+ {
+ // looking for a particular alternate interface number; if this is not it then continue on.
+ if (intf->altsetting_number != if_desc->bAlternateSetting)
+ goto NextInterface;
+ }
+ }
+
+ // found a match
+ intf->interface_index = (unsigned char)currentInfIndex;
+ intf->altsetting_index = (unsigned char)InterfacesByIndex[currentInfIndex][ALTF_FIELD];
+ intf->interface_number = if_desc->bInterfaceNumber;
+ intf->altsetting_number = if_desc->bAlternateSetting;
+
+ if (size_left)
+ {
+ *size_left=size;
+ }
+ return if_desc;
+
+ }
+
+NextInterface:
+ size -= desc->length;
+ p += desc->length;
+ desc = (usb_descriptor_header_t *)p;
+ }
+
+ return NULL;
+}
+
+USB_ENDPOINT_DESCRIPTOR *
+find_endpoint_desc_by_index(USB_INTERFACE_DESCRIPTOR *interface_desc,
+ unsigned int size, int pipe_index)
+{
+ usb_descriptor_header_t *desc = (usb_descriptor_header_t *)interface_desc;
+ char *p = (char *)desc;
+ int currentPipeIndex;
+ short PipesByIndex[LIBUSB_MAX_NUMBER_OF_ENDPOINTS];
+
+ USB_ENDPOINT_DESCRIPTOR *ep_desc = NULL;
+ memset(PipesByIndex,0xFF,sizeof(PipesByIndex));
+
+ if (size && desc->length <= size)
+ {
+ size -= desc->length;
+ p += desc->length;
+ desc = (usb_descriptor_header_t *)p;
+ }
+
+ while (size && desc->length <= size)
+ {
+ if (desc->type == USB_ENDPOINT_DESCRIPTOR_TYPE)
+ {
+ ep_desc = (USB_ENDPOINT_DESCRIPTOR *)desc;
+ for (currentPipeIndex=0; currentPipeIndex<LIBUSB_MAX_NUMBER_OF_ENDPOINTS;currentPipeIndex++)
+ {
+ if (PipesByIndex[currentPipeIndex]==-1)
+ {
+ PipesByIndex[currentPipeIndex]=ep_desc->bEndpointAddress;
+ break;
+ }
+ else if (PipesByIndex[currentPipeIndex]==ep_desc->bEndpointAddress)
+ {
+ // the pipe is defined twice in the same interface
+ USBWRN("invalid endpoint descriptor at pipe index=%d\n",currentPipeIndex);
+ break;
+ }
+ }
+
+ if (pipe_index == currentPipeIndex)
+ {
+ return ep_desc;
+ }
+ }
+ else
+ {
+ break;
+ }
+
+ size -= desc->length;
+ p += desc->length;
+ desc = (usb_descriptor_header_t *)p;
+ }
+
+ return NULL;
+}
+
+
+ULONG get_current_frame(IN PDEVICE_EXTENSION deviceExtension, IN PIRP Irp)
+/*++
+
+Routine Description:
+
+ This routine send an irp/urb pair with
+ function code URB_FUNCTION_GET_CURRENT_FRAME_NUMBER
+ to fetch the current frame
+
+Arguments:
+
+ DeviceObject - pointer to device object
+ PIRP - I/O request packet
+
+Return Value:
+
+ Current frame
+
+--*/
+{
+ KEVENT event;
+ PIO_STACK_LOCATION nextStack;
+ struct _URB_GET_CURRENT_FRAME_NUMBER urb;
+
+ //
+ // initialize the urb
+ //
+
+ urb.Hdr.Function = URB_FUNCTION_GET_CURRENT_FRAME_NUMBER;
+ urb.Hdr.Length = sizeof(urb);
+ urb.FrameNumber = (ULONG) -1;
+
+ nextStack = IoGetNextIrpStackLocation(Irp);
+ nextStack->Parameters.Others.Argument1 = (PVOID) &urb;
+ nextStack->Parameters.DeviceIoControl.IoControlCode =
+ IOCTL_INTERNAL_USB_SUBMIT_URB;
+ nextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
+
+ KeInitializeEvent(&event,
+ NotificationEvent,
+ FALSE);
+
+ IoSetCompletionRoutine(Irp,
+ on_usbd_complete,
+ &event,
+ TRUE,
+ TRUE,
+ TRUE);
+
+
+ IoCallDriver(deviceExtension->target_device, Irp);
+
+ KeWaitForSingleObject((PVOID) &event,
+ Executive,
+ KernelMode,
+ FALSE,
+ NULL);
+
+ return urb.FrameNumber;
+}
diff --git a/usb/driver/libusb_driver.h b/usb/driver/libusb_driver.h
new file mode 100644
index 0000000..e0a5d3c
--- /dev/null
+++ b/usb/driver/libusb_driver.h
@@ -0,0 +1,429 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef __LIBUSB_DRIVER_H__
+#define __LIBUSB_DRIVER_H__
+
+//#define SKIP_CONFIGURE_NORMAL_DEVICES
+//#define SKIP_DEVICES_WINUSB
+//#define SKIP_DEVICES_PICOPP
+
+#ifdef __GNUC__
+#include <ddk/usb100.h>
+#include <ddk/usbdi.h>
+#include <ddk/winddk.h>
+#include "usbdlib_gcc.h"
+#else
+#include <ntifs.h>
+#include <wdm.h>
+#include "usbdi.h"
+#include "usbdlib.h"
+#endif
+
+#include <wchar.h>
+#include <initguid.h>
+
+#undef interface
+
+#include "driver_debug.h"
+#include "error.h"
+#include "driver_api.h"
+
+/* some missing defines */
+#ifdef __GNUC__
+
+#define USBD_TRANSFER_DIRECTION_OUT 0
+#define USBD_TRANSFER_DIRECTION_BIT 0
+#define USBD_TRANSFER_DIRECTION_IN (1 << USBD_TRANSFER_DIRECTION_BIT)
+#define USBD_SHORT_TRANSFER_OK_BIT 1
+#define USBD_SHORT_TRANSFER_OK (1 << USBD_SHORT_TRANSFER_OK_BIT)
+#define USBD_START_ISO_TRANSFER_ASAP_BIT 2
+#define USBD_START_ISO_TRANSFER_ASAP (1 << USBD_START_ISO_TRANSFER_ASAP_BIT)
+
+#endif
+
+#define SET_CONFIG_ACTIVE_CONFIG -258
+
+#define USB_RECIP_DEVICE 0x00
+#define USB_RECIP_INTERFACE 0x01
+#define USB_RECIP_ENDPOINT 0x02
+#define USB_RECIP_OTHER 0x03
+
+#define USB_TYPE_STANDARD 0x00
+#define USB_TYPE_CLASS 0x01
+#define USB_TYPE_VENDOR 0x02
+
+
+#define LIBUSB_NT_DEVICE_NAME L"\\Device\\libusb0"
+#define LIBUSB_SYMBOLIC_LINK_NAME L"\\DosDevices\\libusb0-"
+
+#define LIBUSB_MAX_NUMBER_OF_ENDPOINTS 32
+#define LIBUSB_MAX_NUMBER_OF_INTERFACES 32
+
+
+#define LIBUSB_DEFAULT_TIMEOUT 5000
+#define LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT 5000
+
+
+#ifndef __GNUC__
+#define DDKAPI
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE (!(FALSE))
+#endif
+
+typedef int bool_t;
+
+#define POOL_TAG (ULONG) '0BSU'
+#undef ExAllocatePool
+#define ExAllocatePool(type, size) ExAllocatePoolWithTag(type, size, POOL_TAG)
+
+#define IS_PIPE_TYPE(pipeInfo, pipeType) ((((pipeInfo->pipe_type & 3)==pipeType))?TRUE:FALSE)
+
+#define IS_CTRL_PIPE(pipeInfo) IS_PIPE_TYPE(pipeInfo,UsbdPipeTypeControl)
+#define IS_ISOC_PIPE(pipeInfo) IS_PIPE_TYPE(pipeInfo,UsbdPipeTypeIsochronous)
+#define IS_BULK_PIPE(pipeInfo) IS_PIPE_TYPE(pipeInfo,UsbdPipeTypeBulk)
+#define IS_INTR_PIPE(pipeInfo) IS_PIPE_TYPE(pipeInfo,UsbdPipeTypeInterrupt)
+
+#define GetMaxTransferSize(pipeInfo, reqMaxTransferSize) ((reqMaxTransferSize) ? reqMaxTransferSize : pipeInfo->maximum_transfer_size)
+
+#define UrbFunctionFromEndpoint(PipeInfo) ((IS_ISOC_PIPE(PipeInfo)) ? URB_FUNCTION_ISOCH_TRANSFER : URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER)
+#define UsbdDirectionFromEndpoint(PipeInfo) ((PipeInfo->address & 0x80) ? USBD_TRANSFER_DIRECTION_IN : USBD_TRANSFER_DIRECTION_OUT)
+
+#define UpdateContextConfigDescriptor(DeviceContext, Descriptor, Size, Value, Index) \
+{ \
+ if (DeviceContext->config.descriptor && DeviceContext->config.descriptor!=(Descriptor)) \
+ ExFreePool(DeviceContext->config.descriptor); \
+ DeviceContext->config.descriptor=(Descriptor); \
+ DeviceContext->config.total_size=(Size); \
+ DeviceContext->config.value=(Value); \
+ DeviceContext->config.index=(Index); \
+}
+
+#ifndef __WUSBIO_H__
+
+// Pipe policy types
+
+// The default value is zero. To set a time-out value, in Value pass the address of a caller-allocated ULONG variable that contains the time-out interval.
+// The PIPE_TRANSFER_TIMEOUT value specifies the time-out interval, in milliseconds. The host controller cancels transfers that do not complete within the specified time-out interval.
+// A value of zero (default) indicates that transfers do not time out because the host controller never cancels the transfer.
+#define PIPE_TRANSFER_TIMEOUT 0x03
+
+// Device Information types
+#define DEVICE_SPEED 0x01
+
+// Device Speeds
+#define LowSpeed 0x01
+#define FullSpeed 0x02
+#define HighSpeed 0x03
+
+#endif
+
+#define USB_ENDPOINT_ADDRESS_MASK 0x0F
+#define USB_ENDPOINT_DIR_MASK 0x80
+#define LBYTE(w) (w & 0xFF)
+#define HBYTE(w) ((w>>8) & 0xFF)
+
+
+#include <pshpack1.h>
+
+typedef struct
+{
+ unsigned char length;
+ unsigned char type;
+} usb_descriptor_header_t;
+
+#include <poppack.h>
+
+
+typedef struct
+{
+ long usage_count;
+ int remove_pending;
+ KEVENT event;
+} libusb_remove_lock_t;
+
+typedef struct
+{
+ int address;
+ USBD_PIPE_HANDLE handle;
+ int maximum_packet_size; // Maximum packet size for this pipe
+ int interval; // Polling interval in ms if interrupt pipe
+ USBD_PIPE_TYPE pipe_type; // PipeType identifies type of transfer valid for this pipe
+
+ //
+ // INPUT
+ // These fields are filled in by the client driver
+ //
+ int maximum_transfer_size; // Maximum size for a single request
+ // in bytes.
+ int pipe_flags;
+} libusb_endpoint_t;
+
+typedef struct
+{
+ bool_t valid;
+ FILE_OBJECT *file_object; /* file object this interface is bound to */
+ libusb_endpoint_t endpoints[LIBUSB_MAX_NUMBER_OF_ENDPOINTS];
+
+} libusb_interface_t;
+
+typedef struct
+{
+ DEVICE_OBJECT *self;
+ DEVICE_OBJECT *physical_device_object;
+ DEVICE_OBJECT *next_stack_device;
+ DEVICE_OBJECT *target_device;
+ libusb_remove_lock_t remove_lock;
+ bool_t is_filter;
+ bool_t is_started;
+ bool_t surprise_removal_ok;
+ int id;
+ USB_DEVICE_DESCRIPTOR device_descriptor;
+ struct
+ {
+ USBD_CONFIGURATION_HANDLE handle;
+ int value;
+ int index;
+ libusb_interface_t interfaces[LIBUSB_MAX_NUMBER_OF_INTERFACES];
+ PUSB_CONFIGURATION_DESCRIPTOR descriptor;
+ int total_size;
+ } config;
+ POWER_STATE power_state;
+ DEVICE_POWER_STATE device_power_states[PowerSystemMaximum];
+ int initial_config_value;
+ char device_id[256];
+ bool_t disallow_power_control;
+ char objname_plugplay_registry_key[512];
+ GUID device_interface_guid;
+ bool_t device_interface_in_use;
+ UNICODE_STRING device_interface_name;
+ int control_read_timeout;
+ int control_write_timeout;
+} libusb_device_t, DEVICE_EXTENSION, *PDEVICE_EXTENSION;
+
+
+NTSTATUS DDKAPI add_device(DRIVER_OBJECT *driver_object,
+ DEVICE_OBJECT *physical_device_object);
+
+NTSTATUS DDKAPI dispatch(DEVICE_OBJECT *device_object, IRP *irp);
+NTSTATUS dispatch_pnp(libusb_device_t *dev, IRP *irp);
+NTSTATUS dispatch_power(libusb_device_t *dev, IRP *irp);
+NTSTATUS dispatch_ioctl(libusb_device_t *dev, IRP *irp);
+
+NTSTATUS complete_irp(IRP *irp, NTSTATUS status, ULONG info);
+
+#define call_usbd(dev, urb, control_code, timeout) \
+ call_usbd_ex(dev, urb, control_code, timeout, LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT)
+
+NTSTATUS call_usbd_ex(libusb_device_t *dev,
+ void *urb,
+ ULONG control_code,
+ int timeout,
+ int max_timeout);
+
+NTSTATUS pass_irp_down(libusb_device_t *dev, IRP *irp,
+ PIO_COMPLETION_ROUTINE completion_routine,
+ void *context);
+
+bool_t accept_irp(libusb_device_t *dev, IRP *irp);
+
+bool_t get_pipe_handle(libusb_device_t *dev, int endpoint_address,
+ USBD_PIPE_HANDLE *pipe_handle);
+
+bool_t get_pipe_info(libusb_device_t *dev, int endpoint_address,
+ libusb_endpoint_t** pipe_info);
+
+void clear_pipe_info(libusb_device_t *dev);
+bool_t update_pipe_info(libusb_device_t *dev,
+ USBD_INTERFACE_INFORMATION *interface_info);
+
+void remove_lock_initialize(libusb_device_t *dev);
+NTSTATUS remove_lock_acquire(libusb_device_t *dev);
+void remove_lock_release(libusb_device_t *dev);
+void remove_lock_release_and_wait(libusb_device_t *dev);
+
+NTSTATUS set_configuration(libusb_device_t *dev,
+ int configuration, int timeout);
+NTSTATUS auto_configure(libusb_device_t *dev);
+
+NTSTATUS get_configuration(libusb_device_t *dev,
+ unsigned char *configuration, int *ret,
+ int timeout);
+
+NTSTATUS set_feature(libusb_device_t *dev,
+ int recipient, int index, int feature, int timeout);
+NTSTATUS clear_feature(libusb_device_t *dev,
+ int recipient, int index, int feature, int timeout);
+NTSTATUS get_status(libusb_device_t *dev, int recipient,
+ int index, char *status, int *ret, int timeout);
+NTSTATUS set_descriptor(libusb_device_t *dev,
+ void *buffer, int size,
+ int type, int recipient, int index, int language_id,
+ int *sent, int timeout);
+NTSTATUS get_descriptor(libusb_device_t *dev, void *buffer, int size,
+ int type, int recipient, int index, int language_id,
+ int *received, int timeout);
+
+PUSB_CONFIGURATION_DESCRIPTOR get_config_descriptor(
+ libusb_device_t *dev,
+ int value,
+ int *size,
+ int* index);
+
+NTSTATUS vendor_class_request(libusb_device_t *dev,
+ int type, int recipient,
+ int request, int value, int index,
+ void *buffer, int size, int direction,
+ int *ret, int timeout);
+
+NTSTATUS abort_endpoint(libusb_device_t *dev, int endpoint, int timeout);
+NTSTATUS reset_endpoint(libusb_device_t *dev, int endpoint, int timeout);
+NTSTATUS reset_device(libusb_device_t *dev, int timeout);
+
+#define USB_RESET_TYPE_RESET_PORT (1 << 0)
+#define USB_RESET_TYPE_CYCLE_PORT (1 << 1)
+#define USB_RESET_TYPE_FULL_RESET (USB_RESET_TYPE_CYCLE_PORT | USB_RESET_TYPE_RESET_PORT)
+NTSTATUS reset_device_ex(libusb_device_t *dev, int timeout, unsigned int reset_type);
+
+bool_t reg_get_hardware_id(DEVICE_OBJECT *physical_device_object,
+ char *data, int size);
+bool_t reg_get_compatible_id(DEVICE_OBJECT *physical_device_object,
+ char *data, int size);
+
+bool_t reg_get_properties(libusb_device_t *dev);
+
+
+void power_set_device_state(libusb_device_t *dev,
+ DEVICE_POWER_STATE device_state, bool_t block);
+
+USB_INTERFACE_DESCRIPTOR *
+find_interface_desc(USB_CONFIGURATION_DESCRIPTOR *config_desc,
+ unsigned int size, int interface_number, int altsetting);
+
+#define FIND_INTERFACE_INDEX_ANY (-1)
+USB_INTERFACE_DESCRIPTOR* find_interface_desc_ex(USB_CONFIGURATION_DESCRIPTOR *config_desc,
+ unsigned int size,
+ interface_request_t* intf,
+ unsigned int* size_left);
+
+USB_ENDPOINT_DESCRIPTOR *
+find_endpoint_desc_by_index(USB_INTERFACE_DESCRIPTOR *interface_desc,
+ unsigned int size, int pipe_index);
+
+/*
+Gets a device property for the device_object.
+
+Returns: NTSTATUS code from IoGetDeviceProperty
+ STATUS_INVALID_PARAMETER
+*/
+NTSTATUS reg_get_device_property(PDEVICE_OBJECT device_object,
+ int property,
+ char* data_buffer,
+ int data_length,
+ int* actual_length);
+
+NTSTATUS reg_get_custom_property(PDEVICE_OBJECT device_object,
+ char *data_buffer,
+ unsigned int data_length,
+ unsigned int name_offset,
+ int* actual_length);
+
+
+NTSTATUS transfer(libusb_device_t* dev,
+ IN PIRP irp,
+ IN int direction,
+ IN int urbFunction,
+ IN libusb_endpoint_t* endpoint,
+ IN int packetSize,
+ IN int transferFlags,
+ IN int isoLatency,
+ IN PMDL mdlAddress,
+ IN int totalLength);
+
+NTSTATUS large_transfer(IN libusb_device_t* dev,
+ IN PIRP irp,
+ IN int direction,
+ IN int urbFunction,
+ IN libusb_endpoint_t* endpoint,
+ IN int packetSize,
+ IN int maxTransferSize,
+ IN int transferFlags,
+ IN int isoLatency,
+ IN PMDL mdlAddress,
+ IN int totalLength);
+
+ULONG get_current_frame(IN PDEVICE_EXTENSION dev, IN PIRP Irp);
+
+
+NTSTATUS control_transfer(libusb_device_t* dev,
+ PIRP irp,
+ PMDL mdl,
+ int size,
+ int usbd_direction,
+ int *ret,
+ int timeout,
+ UCHAR request_type,
+ UCHAR request,
+ USHORT value,
+ USHORT index,
+ USHORT length);
+
+NTSTATUS claim_interface(libusb_device_t *dev, FILE_OBJECT *file_object,
+ int interface);
+
+NTSTATUS claim_interface_ex(libusb_device_t *dev,
+ FILE_OBJECT *file_object,
+ interface_request_t* interface_request);
+
+NTSTATUS release_all_interfaces(libusb_device_t *dev,
+ FILE_OBJECT *file_object);
+
+NTSTATUS release_interface(libusb_device_t *dev, FILE_OBJECT *file_object,
+ int interface);
+
+NTSTATUS release_interface_ex(libusb_device_t *dev,
+ FILE_OBJECT *file_object,
+ interface_request_t* interface_request);
+
+NTSTATUS set_interface(libusb_device_t *dev,
+ int interface_number,
+ int alt_interface_number,
+ int timeout);
+
+NTSTATUS set_interface_ex(libusb_device_t *dev,
+ interface_request_t* interface_request,
+ int timeout);
+
+NTSTATUS get_interface(libusb_device_t *dev,
+ int interface_number,
+ unsigned char *altsetting,
+ int timeout);
+
+NTSTATUS get_interface_ex(libusb_device_t *dev,
+ interface_request_t* interface_request,
+ int timeout);
+
+VOID set_filter_interface_key(libusb_device_t *dev, ULONG id);
+#endif
diff --git a/usb/driver/libusb_driver_rc.rc b/usb/driver/libusb_driver_rc.rc
new file mode 100644
index 0000000..b0affc8
--- /dev/null
+++ b/usb/driver/libusb_driver_rc.rc
@@ -0,0 +1,25 @@
+/* LIBUSB-WIN32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#define RC_FILE_TYPE VFT_DRV
+#define RC_FILE_SUB_TYPE VFT2_DRV_SYSTEM
+#define RC_PRODUCT_STR "LibUSB-Win32 - Kernel Driver"
+#define RC_FILE_NAME_STR "libusb0.sys"
+
+#include "libusb-win32_version.rc"
+
diff --git a/usb/driver/lusb_defdi_guids.h b/usb/driver/lusb_defdi_guids.h
new file mode 100644
index 0000000..99833b0
--- /dev/null
+++ b/usb/driver/lusb_defdi_guids.h
@@ -0,0 +1,45 @@
+#ifndef __LUSB_DEFDI_GUIDS_
+#define __LUSB_DEFDI_GUIDS_
+
+#ifndef DEFINE_TO_STR
+#define _DEFINE_TO_STR(x) #x
+#define DEFINE_TO_STR(x) _DEFINE_TO_STR(x)
+#endif
+
+#ifndef DEFINE_TO_STRW
+#define _DEFINE_TO_STRW(x) L#x
+#define DEFINE_TO_STRW(x) _DEFINE_TO_STRW(x)
+#endif
+
+#define DEFINE_DEVICE_INTERFACE_GUID(BaseFieldName,BaseGuidName,L1,W1,W2,B1,B2,B3,B4,B5,B6,B7,B8) \
+ const GUID BaseFieldName##Guid = { L1, W1, W2, { B1, B2, B3, B4, B5, B6, B7, B8 } }; \
+ const CHAR* BaseFieldName##GuidA = DEFINE_TO_STR(BaseGuidName); \
+ const WCHAR* BaseFieldName##GuidW = DEFINE_TO_STRW(BaseGuidName)
+
+#define _DefRawDeviceGuid {A5DCBF10-6530-11D2-901F-00C04FB951ED}
+#define _DefLibusb0FilterGuid {F9F3FF14-AE21-48A0-8A25-8011A7A931D9}
+#define _DefLibusb0DeviceGuid {20343A29-6DA1-4DB8-8A3C-16E774057BF5}
+#define _DefLibusbKDeviceGuid {6C696275-7362-2D77-696E-33322D574446}
+
+// USB Raw Device Interface GUID (DO NOT USE IN INF FILE)
+DEFINE_DEVICE_INTERFACE_GUID(RawDevice, \
+ _DefRawDeviceGuid, \
+ 0xA5DCBF10, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
+
+// libusb0 Filter Device Interface GUID (DO NOT USE IN INF FILE)
+DEFINE_DEVICE_INTERFACE_GUID(Libusb0Filter,
+ _DefLibusb0FilterGuid, \
+ 0xF9F3FF14, 0xAE21, 0x48A0, 0x8A, 0x25, 0x80, 0x11, 0xA7, 0xA9, 0x31, 0xD9);
+
+// libusb0 Default Device Interface GUID (DO NOT USE IN INF FILE)
+DEFINE_DEVICE_INTERFACE_GUID(Libusb0Device,
+ _DefLibusb0DeviceGuid, \
+ 0x20343A29, 0x6DA1, 0x4DB8, 0x8A, 0x3C, 0x16, 0xE7, 0x74, 0x05, 0x7B, 0xF5);
+
+// libusbK Default Device Interface GUID (DO NOT USE IN INF FILE)
+DEFINE_DEVICE_INTERFACE_GUID(LibusbKDevice,
+ _DefLibusbKDeviceGuid, \
+ 0x6C696275, 0x7362, 0x2D77, 0x69, 0x6E, 0x33, 0x32, 0x2D, 0x57, 0x44, 0x46);
+
+
+#endif
diff --git a/usb/driver/pnp.c b/usb/driver/pnp.c
new file mode 100644
index 0000000..b103650
--- /dev/null
+++ b/usb/driver/pnp.c
@@ -0,0 +1,302 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+static NTSTATUS DDKAPI
+on_start_complete(DEVICE_OBJECT *device_object, IRP *irp,
+ void *context);
+
+static NTSTATUS DDKAPI
+on_device_usage_notification_complete(DEVICE_OBJECT *device_object,
+ IRP *irp, void *context);
+
+static NTSTATUS DDKAPI
+on_query_capabilities_complete(DEVICE_OBJECT *device_object,
+ IRP *irp, void *context);
+
+
+NTSTATUS dispatch_pnp(libusb_device_t *dev, IRP *irp)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
+ UNICODE_STRING symbolic_link_name;
+ WCHAR tmp_name[128];
+
+ status = remove_lock_acquire(dev);
+
+ if (!NT_SUCCESS(status))
+ {
+ USBDBG("device %s is pending removal\n",dev->device_id);
+ return complete_irp(irp, status, 0);
+ }
+
+ switch (stack_location->MinorFunction)
+ {
+ case IRP_MN_REMOVE_DEVICE:
+
+ USBMSG("IRP_MN_REMOVE_DEVICE: is-filter=%c %s\n",
+ dev->is_filter ? 'Y' : 'N',
+ dev->device_id);
+
+ if (dev->device_interface_in_use && dev->is_started)
+ {
+ set_filter_interface_key(dev,(ULONG)-1);
+
+ status = IoSetDeviceInterfaceState(&dev->device_interface_name, FALSE);
+ if (!NT_SUCCESS(status))
+ {
+ USBERR0("IRP_MN_REMOVE_DEVICE: disabling device interface failed\n");
+ }
+ }
+
+ dev->is_started = FALSE;
+
+ /* wait until all outstanding requests are finished */
+ remove_lock_release_and_wait(dev);
+
+ status = pass_irp_down(dev, irp, NULL, NULL);
+
+ USBMSG("deleting device #%d %s\n", dev->id, dev->device_id);
+
+ _snwprintf(tmp_name, sizeof(tmp_name)/sizeof(WCHAR), L"%s%04d",
+ LIBUSB_SYMBOLIC_LINK_NAME, dev->id);
+
+ /* delete the symbolic link */
+ RtlInitUnicodeString(&symbolic_link_name, tmp_name);
+ IoDeleteSymbolicLink(&symbolic_link_name);
+
+ if (dev->device_interface_in_use && dev->device_interface_name.Buffer)
+ {
+ RtlFreeUnicodeString(&dev->device_interface_name);
+ }
+ UpdateContextConfigDescriptor(dev,NULL,0,0,-1);
+
+ /* delete the device object */
+ IoDetachDevice(dev->next_stack_device);
+ IoDeleteDevice(dev->self);
+
+ return status;
+
+ case IRP_MN_SURPRISE_REMOVAL:
+
+ dev->is_started = FALSE;
+ USBMSG("IRP_MN_SURPRISE_REMOVAL: is-filter=%c %s\n",
+ dev->is_filter ? 'Y' : 'N',
+ dev->device_id);
+
+ if (dev->device_interface_in_use)
+ {
+ set_filter_interface_key(dev,(ULONG)-1);
+ IoSetDeviceInterfaceState(&dev->device_interface_name, FALSE);
+ dev->device_interface_in_use=FALSE;
+ if (dev->device_interface_name.Buffer)
+ {
+ RtlFreeUnicodeString(&dev->device_interface_name);
+ dev->device_interface_name.Buffer = NULL;
+ }
+ }
+ UpdateContextConfigDescriptor(dev,NULL,0,0,-1);
+ status = STATUS_SUCCESS;
+
+ break;
+
+ case IRP_MN_START_DEVICE:
+ USBMSG("IRP_MN_START_DEVICE: is-filter=%c %s\n",
+ dev->is_filter ? 'Y' : 'N',
+ dev->device_id);
+
+ // A driver calls this routine after receiving a device set-power
+ // request and before calling PoStartNextPowerIrp. When handling a
+ // PnP IRP_MN_START_DEVICE request, the driver should call
+ // PoSetPowerState to notify the power manager that the device is
+ // in the D0 state.
+ //
+ PoSetPowerState(dev->self, DevicePowerState, dev->power_state);
+ if (dev->device_interface_in_use)
+ {
+ status = IoSetDeviceInterfaceState(&dev->device_interface_name, TRUE);
+ if (!NT_SUCCESS(status))
+ {
+ USBERR0("IRP_MN_START_DEVICE: enabling device interface failed\n");
+ }
+ }
+ return pass_irp_down(dev, irp, on_start_complete, NULL);
+
+ case IRP_MN_STOP_DEVICE:
+ dev->is_started = FALSE;
+ USBDBG("IRP_MN_STOP_DEVICE: is-filter=%c %s\n",
+ dev->is_filter ? 'Y' : 'N',
+ dev->device_id);
+ break;
+
+ case IRP_MN_DEVICE_USAGE_NOTIFICATION:
+ USBDBG("IRP_MN_DEVICE_USAGE_NOTIFICATION: is-filter=%c %s\n",
+ dev->is_filter ? 'Y' : 'N',
+ dev->device_id);
+
+ if (!dev->self->AttachedDevice
+ || (dev->self->AttachedDevice->Flags & DO_POWER_PAGABLE))
+ {
+ dev->self->Flags |= DO_POWER_PAGABLE;
+ }
+
+ return pass_irp_down(dev, irp, on_device_usage_notification_complete, NULL);
+
+ case IRP_MN_QUERY_CAPABILITIES:
+ USBDBG("IRP_MN_QUERY_CAPABILITIES: is-filter=%c %s\n",
+ dev->is_filter ? 'Y' : 'N',
+ dev->device_id);
+
+ if (!dev->is_filter)
+ {
+ /* apply registry setting */
+ stack_location->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = dev->surprise_removal_ok;
+ }
+
+ return pass_irp_down(dev, irp, on_query_capabilities_complete, NULL);
+
+ default:
+ break;
+
+ }
+
+ remove_lock_release(dev);
+ return pass_irp_down(dev, irp, NULL, NULL);
+}
+
+static NTSTATUS DDKAPI
+on_start_complete(DEVICE_OBJECT *device_object, IRP *irp, void *context)
+{
+ libusb_device_t *dev = device_object->DeviceExtension;
+
+ if (irp->PendingReturned)
+ {
+ IoMarkIrpPending(irp);
+ }
+
+ USBDBG("is-filter=%c %s\n",
+ dev->is_filter ? 'Y' : 'N',
+ dev->device_id);
+
+ if (dev->next_stack_device->Characteristics & FILE_REMOVABLE_MEDIA)
+ {
+ device_object->Characteristics |= FILE_REMOVABLE_MEDIA;
+ }
+#ifndef SKIP_CONFIGURE_NORMAL_DEVICES
+ // select initial configuration if not a filter
+ if (!dev->is_filter && !dev->is_started)
+ {
+ // optionally, the initial configuration value can be specified
+ // in the inf file. See reg_get_properties()
+ // HKR,,"InitialConfigValue",0x00010001,<your config value>
+
+ // If initial_config_value is negative, the configuration will
+ // only be set if the device is not already configured.
+ if (dev->initial_config_value)
+ {
+ if (dev->initial_config_value == SET_CONFIG_ACTIVE_CONFIG)
+ {
+ USBDBG("applying active configuration for %s\n",
+ dev->device_id);
+ }
+ else
+ {
+ USBDBG("applying InitialConfigValue %d for %s\n",
+ dev->initial_config_value, dev->device_id);
+ }
+
+ if(!NT_SUCCESS(set_configuration(dev, dev->initial_config_value, LIBUSB_DEFAULT_TIMEOUT)))
+ {
+ // we should always be able to apply the active configuration,
+ // even in the case of composite devices.
+ if (dev->initial_config_value == SET_CONFIG_ACTIVE_CONFIG)
+ {
+ USBERR("failed applying active configuration for %s\n",
+ dev->device_id);
+ }
+ else
+ {
+ USBERR("failed applying InitialConfigValue %d for %s\n",
+ dev->initial_config_value, dev->device_id);
+ }
+ }
+ }
+ }
+#endif
+ dev->is_started = TRUE;
+ remove_lock_release(dev);
+
+ return STATUS_SUCCESS;
+}
+
+static NTSTATUS DDKAPI
+on_device_usage_notification_complete(DEVICE_OBJECT *device_object,
+ IRP *irp, void *context)
+{
+ libusb_device_t *dev = device_object->DeviceExtension;
+
+ if (irp->PendingReturned)
+ {
+ IoMarkIrpPending(irp);
+ }
+
+ if (!(dev->next_stack_device->Flags & DO_POWER_PAGABLE))
+ {
+ device_object->Flags &= ~DO_POWER_PAGABLE;
+ }
+
+ remove_lock_release(dev);
+
+ return STATUS_SUCCESS;
+}
+
+static NTSTATUS DDKAPI
+on_query_capabilities_complete(DEVICE_OBJECT *device_object,
+ IRP *irp, void *context)
+{
+ libusb_device_t *dev = device_object->DeviceExtension;
+ IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
+
+ if (irp->PendingReturned)
+ {
+ IoMarkIrpPending(irp);
+ }
+
+ if (NT_SUCCESS(irp->IoStatus.Status))
+ {
+ if (!dev->is_filter)
+ {
+ /* apply registry setting */
+ stack_location->Parameters.DeviceCapabilities.Capabilities
+ ->SurpriseRemovalOK = dev->surprise_removal_ok;
+ }
+
+ /* save supported device power states */
+ memcpy(dev->device_power_states, stack_location
+ ->Parameters.DeviceCapabilities.Capabilities->DeviceState,
+ sizeof(dev->device_power_states));
+ }
+
+ remove_lock_release(dev);
+
+ return STATUS_SUCCESS;
+}
diff --git a/usb/driver/power.c b/usb/driver/power.c
new file mode 100644
index 0000000..d29dd9b
--- /dev/null
+++ b/usb/driver/power.c
@@ -0,0 +1,269 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+static NTSTATUS DDKAPI
+on_power_state_complete(DEVICE_OBJECT *device_object,
+ IRP *irp,
+ void *context);
+
+static NTSTATUS DDKAPI
+on_filter_power_state_complete(DEVICE_OBJECT *device_object,
+ IRP *irp,
+ void *context);
+
+static void DDKAPI
+on_power_set_device_state_complete(DEVICE_OBJECT *device_object,
+ UCHAR minor_function,
+ POWER_STATE power_state,
+ void *context,
+ IO_STATUS_BLOCK *io_status);
+
+/* [trobinso MOD 4/16/2010]
+ * If running as a filter, do not act as power policy owner.
+ */
+NTSTATUS dispatch_power(libusb_device_t *dev, IRP *irp)
+{
+ IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
+ POWER_STATE power_state;
+ NTSTATUS status;
+
+ status = remove_lock_acquire(dev);
+
+ if (!NT_SUCCESS(status))
+ {
+ irp->IoStatus.Status = status;
+ PoStartNextPowerIrp(irp);
+ IoCompleteRequest(irp, IO_NO_INCREMENT);
+ return status;
+ }
+
+ if (stack_location->MinorFunction == IRP_MN_SET_POWER)
+ {
+ power_state = stack_location->Parameters.Power.State;
+
+ if (stack_location->Parameters.Power.Type == SystemPowerState)
+ {
+ USBMSG("IRP_MN_SET_POWER: S%d %s\n",
+ power_state.SystemState - PowerSystemWorking, dev->device_id);
+ }
+ else
+ {
+ USBMSG("IRP_MN_SET_POWER: D%d %s\n",
+ power_state.DeviceState - PowerDeviceD0, dev->device_id);
+
+ if (power_state.DeviceState > dev->power_state.DeviceState)
+ {
+ /* device is powered down, report device state to the */
+ /* Power Manager before sending the IRP down */
+ /* (power up is handled by the completion routine) */
+ PoSetPowerState(dev->self, DevicePowerState, power_state);
+ }
+ }
+
+ /* TODO: should PoStartNextPowerIrp() be called here or from the */
+ /* completion routine? */
+ PoStartNextPowerIrp(irp);
+
+ IoCopyCurrentIrpStackLocationToNext(irp);
+ if (!dev->is_filter && !dev->disallow_power_control)
+ {
+ IoSetCompletionRoutine(irp,
+ on_power_state_complete,
+ dev,
+ TRUE, /* on success */
+ TRUE, /* on error */
+ TRUE);/* on cancel */
+ }
+ else
+ {
+ IoSetCompletionRoutine(irp,
+ on_filter_power_state_complete,
+ dev,
+ TRUE, /* on success */
+ TRUE, /* on error */
+ TRUE);/* on cancel */
+ }
+
+ return PoCallDriver(dev->next_stack_device, irp);
+ }
+ else
+ {
+ /* pass all other power IRPs down without setting a completion routine */
+ PoStartNextPowerIrp(irp);
+ IoSkipCurrentIrpStackLocation(irp);
+ status = PoCallDriver(dev->next_stack_device, irp);
+ remove_lock_release(dev);
+
+ return status;
+ }
+}
+
+
+static NTSTATUS DDKAPI
+on_power_state_complete(DEVICE_OBJECT *device_object,
+ IRP *irp,
+ void *context)
+{
+ libusb_device_t *dev = context;
+ IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
+ POWER_STATE power_state = stack_location->Parameters.Power.State;
+ DEVICE_POWER_STATE dev_power_state;
+
+ if (irp->PendingReturned)
+ {
+ IoMarkIrpPending(irp);
+ }
+
+ if (NT_SUCCESS(irp->IoStatus.Status))
+ {
+ if (stack_location->Parameters.Power.Type == SystemPowerState)
+ {
+ USBMSG("S%d %s\n",
+ power_state.SystemState - PowerSystemWorking, dev->device_id);
+
+ /* save current system state */
+ dev->power_state.SystemState = power_state.SystemState;
+
+ /* get supported device power state from the array reported by */
+ /* IRP_MN_QUERY_CAPABILITIES */
+ dev_power_state = dev->device_power_states[power_state.SystemState];
+
+ /* set the device power state, but don't block the thread */
+ power_set_device_state(dev, dev_power_state, FALSE);
+ }
+ else /* DevicePowerState */
+ {
+ USBMSG("D%d %s\n",
+ power_state.DeviceState - PowerDeviceD0, dev->device_id);
+
+ if (power_state.DeviceState <= dev->power_state.DeviceState)
+ {
+ /* device is powered up, */
+ /* report device state to Power Manager */
+ PoSetPowerState(dev->self, DevicePowerState, power_state);
+ }
+ /* save current device state */
+ dev->power_state.DeviceState = power_state.DeviceState;
+ }
+ }
+ else
+ {
+ USBMSG0("failed\n");
+ }
+
+ remove_lock_release(dev);
+
+ return STATUS_SUCCESS;
+}
+
+static NTSTATUS DDKAPI
+on_filter_power_state_complete(DEVICE_OBJECT *device_object,
+ IRP *irp,
+ void *context)
+{
+ libusb_device_t *dev = context;
+ IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
+ POWER_STATE power_state = stack_location->Parameters.Power.State;
+
+ if (NT_SUCCESS(irp->IoStatus.Status))
+ {
+ if (stack_location->Parameters.Power.Type == SystemPowerState)
+ {
+ USBMSG("S%d\n",
+ power_state.SystemState - PowerSystemWorking);
+
+ /* save current system state */
+ dev->power_state.SystemState = power_state.SystemState;
+
+
+ }
+ else /* DevicePowerState */
+ {
+ USBMSG("D%d\n",
+ power_state.DeviceState - PowerDeviceD0);
+
+ if (power_state.DeviceState <= dev->power_state.DeviceState)
+ {
+ /* device is powered up, */
+ /* report device state to Power Manager */
+ PoSetPowerState(dev->self, DevicePowerState, power_state);
+ }
+
+ /* save current device state */
+ dev->power_state.DeviceState = power_state.DeviceState;
+ }
+ }
+ else
+ {
+ USBMSG0("failed\n");
+ }
+
+ remove_lock_release(dev);
+
+ return STATUS_SUCCESS;
+}
+
+static void DDKAPI
+on_power_set_device_state_complete(DEVICE_OBJECT *device_object,
+ UCHAR minor_function,
+ POWER_STATE power_state,
+ void *context,
+ IO_STATUS_BLOCK *io_status)
+{
+ KeSetEvent((KEVENT *)context, EVENT_INCREMENT, FALSE);
+}
+
+
+void power_set_device_state(libusb_device_t *dev,
+ DEVICE_POWER_STATE device_state, bool_t block)
+{
+ NTSTATUS status;
+ KEVENT event;
+ POWER_STATE power_state;
+
+ power_state.DeviceState = device_state;
+
+ USBMSG("setting device power state to D%d %s\n",
+ power_state.DeviceState - PowerDeviceD0, dev->device_id);
+
+ if (block) /* wait for IRP to complete */
+ {
+ KeInitializeEvent(&event, NotificationEvent, FALSE);
+
+ /* set the device power state and wait for completion */
+ status = PoRequestPowerIrp(dev->physical_device_object,
+ IRP_MN_SET_POWER,
+ power_state,
+ on_power_set_device_state_complete,
+ &event, NULL);
+
+ if (status == STATUS_PENDING)
+ {
+ KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+ }
+ }
+ else
+ {
+ PoRequestPowerIrp(dev->physical_device_object, IRP_MN_SET_POWER,
+ power_state, NULL, NULL, NULL);
+ }
+}
diff --git a/usb/driver/release_interface.c b/usb/driver/release_interface.c
new file mode 100644
index 0000000..bcd483c
--- /dev/null
+++ b/usb/driver/release_interface.c
@@ -0,0 +1,105 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS release_interface(libusb_device_t *dev, FILE_OBJECT *file_object,
+ int interface)
+{
+ USBMSG("interface %d\n", interface);
+
+ if (!dev->config.value)
+ {
+ USBERR0("device is not configured\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ if (interface >= LIBUSB_MAX_NUMBER_OF_INTERFACES)
+ {
+ USBERR("interface number %d too high\n",
+ interface);
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (!dev->config.interfaces[interface].valid)
+ {
+ USBERR("invalid interface %02d\n", interface);
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (!dev->config.interfaces[interface].file_object)
+ {
+ USBERR("could not release interface %d, interface is not claimed\n", interface);
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ if (dev->config.interfaces[interface].file_object != file_object)
+ {
+ USBERR("could not release interface %d, interface is not bound to this file object\n", interface);
+ return STATUS_DEVICE_BUSY;
+ }
+
+ dev->config.interfaces[interface].file_object = NULL;
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS release_interface_ex(libusb_device_t *dev,
+ FILE_OBJECT *file_object,
+ interface_request_t* interface_request)
+{
+ PUSB_INTERFACE_DESCRIPTOR interface_descriptor;
+
+ USBMSG("interface-%s=%d\n",
+ interface_request->intf_use_index ? "index" : "number",
+ interface_request->intf_use_index ? interface_request->interface_index : interface_request->interface_number);
+
+ if (!dev->config.value || !dev->config.descriptor)
+ {
+ USBERR0("device is not configured\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ interface_request->altsetting_index=FIND_INTERFACE_INDEX_ANY;
+ interface_descriptor = find_interface_desc_ex(dev->config.descriptor,dev->config.total_size,interface_request,NULL);
+ if (!interface_descriptor)
+ {
+ return STATUS_NO_MORE_ENTRIES;
+ }
+ return release_interface(dev, file_object, interface_descriptor->bInterfaceNumber);
+}
+
+NTSTATUS release_all_interfaces(libusb_device_t *dev, FILE_OBJECT *file_object)
+{
+ int i;
+
+ USBMSG("releasing all interfaces bound to file object 0x%x\n", file_object);
+
+ for (i = 0; i < LIBUSB_MAX_NUMBER_OF_INTERFACES; i++)
+ {
+ if (dev->config.interfaces[i].file_object == file_object)
+ {
+ dev->config.interfaces[i].file_object = NULL;
+ }
+ }
+
+ return STATUS_SUCCESS;
+}
diff --git a/usb/driver/reset_device.c b/usb/driver/reset_device.c
new file mode 100644
index 0000000..a0fd97b
--- /dev/null
+++ b/usb/driver/reset_device.c
@@ -0,0 +1,56 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+NTSTATUS reset_device(libusb_device_t *dev, int timeout)
+{
+ return reset_device_ex(dev, timeout, USB_RESET_TYPE_FULL_RESET);
+}
+
+NTSTATUS reset_device_ex(libusb_device_t *dev, int timeout, unsigned int reset_type)
+{
+ NTSTATUS status = STATUS_INVALID_PARAMETER;
+
+ USBMSG0("resetting device\n");
+
+ if (reset_type & USB_RESET_TYPE_RESET_PORT)
+ {
+ status = call_usbd(dev, NULL, IOCTL_INTERNAL_USB_RESET_PORT, timeout);
+
+ if (!NT_SUCCESS(status))
+ {
+ USBERR("IOCTL_INTERNAL_USB_RESET_PORT failed: status: 0x%x\n", status);
+ }
+ }
+
+ if (reset_type & USB_RESET_TYPE_CYCLE_PORT)
+ {
+ status = call_usbd(dev, NULL, IOCTL_INTERNAL_USB_CYCLE_PORT, timeout);
+
+ if (!NT_SUCCESS(status))
+ {
+ USBERR("IOCTL_INTERNAL_USB_CYCLE_PORT failed: status: 0x%x\n", status);
+ }
+ }
+
+ UpdateContextConfigDescriptor(dev, NULL, 0, 0, -1);
+ return status;
+}
diff --git a/usb/driver/reset_endpoint.c b/usb/driver/reset_endpoint.c
new file mode 100644
index 0000000..3396b93
--- /dev/null
+++ b/usb/driver/reset_endpoint.c
@@ -0,0 +1,56 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS reset_endpoint(libusb_device_t *dev, int endpoint, int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("endpoint: 0x%02x timeout: %d\n", endpoint, timeout);
+
+ if (!dev->config.value)
+ {
+ USBERR0("invalid configuration 0\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ memset(&urb, 0, sizeof(struct _URB_PIPE_REQUEST));
+
+ urb.UrbHeader.Length = (USHORT) sizeof(struct _URB_PIPE_REQUEST);
+ urb.UrbHeader.Function = URB_FUNCTION_RESET_PIPE;
+
+ if (!get_pipe_handle(dev, endpoint, &urb.UrbPipeRequest.PipeHandle))
+ {
+ USBERR0("getting endpoint pipe failed\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("request failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ }
+
+ return status;
+}
diff --git a/usb/driver/set_configuration.c b/usb/driver/set_configuration.c
new file mode 100644
index 0000000..9f2fac1
--- /dev/null
+++ b/usb/driver/set_configuration.c
@@ -0,0 +1,205 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+#include <stdlib.h>
+
+
+NTSTATUS set_configuration(libusb_device_t *dev,
+ int configuration,
+ int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb, *urb_ptr = NULL;
+ USB_CONFIGURATION_DESCRIPTOR *configuration_descriptor = NULL;
+ USB_INTERFACE_DESCRIPTOR *interface_descriptor = NULL;
+ USBD_INTERFACE_LIST_ENTRY *interfaces = NULL;
+ int i, j, interface_number, desc_size, config_index, ret;
+
+ // check if this config value is already set
+ if ((configuration > 0) && dev->config.value == configuration)
+ {
+ return STATUS_SUCCESS;
+ }
+
+ // check if this config index is already set
+ if ((configuration < 0) && dev->config.value && dev->config.index == (abs(configuration)-1))
+ {
+ return STATUS_SUCCESS;
+ }
+
+ memset(&urb, 0, sizeof(URB));
+
+ if (configuration == 0)
+ {
+ urb.UrbHeader.Function = URB_FUNCTION_SELECT_CONFIGURATION;
+ urb.UrbHeader.Length = sizeof(struct _URB_SELECT_CONFIGURATION);
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("setting configuration %d failed: status: 0x%x, urb-status: 0x%x\n",
+ configuration, status, urb.UrbHeader.Status);
+ return status;
+ }
+
+ dev->config.handle = urb.UrbSelectConfiguration.ConfigurationHandle;
+ dev->config.value = 0;
+
+ clear_pipe_info(dev);
+
+ return status;
+ }
+
+ if (configuration <= SET_CONFIG_ACTIVE_CONFIG)
+ {
+ // note: as of v1.2.4.0, the active/default configuration is
+ // always the first configuration the device returns. (index 0)
+ configuration=-1;
+ }
+
+ USBMSG("setting configuration %s %d timeout=%d",
+ (configuration < 0) ? "index" : "value",
+ (configuration < 0) ? abs(configuration) - 1 : configuration,
+ timeout);
+
+
+ // If configuration is negative, it is retrieved by index.
+ //
+ configuration_descriptor = get_config_descriptor(dev, configuration,
+ &desc_size, &config_index);
+ if (!configuration_descriptor)
+ {
+ USBERR0("getting configuration descriptor failed");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ // if we passed an index in we can check here to see
+ // if the device is already configured with this value
+ if (dev->config.value == configuration_descriptor->bConfigurationValue)
+ {
+ UpdateContextConfigDescriptor(
+ dev,
+ configuration_descriptor,
+ desc_size,
+ configuration_descriptor->bConfigurationValue,
+ config_index);
+
+ status = STATUS_SUCCESS;
+ goto SetConfigurationDone;
+ }
+
+ // MEMORY ALLOCATION BEGINS
+ interfaces =
+ ExAllocatePool(NonPagedPool,(configuration_descriptor->bNumInterfaces + 1)
+ * sizeof(USBD_INTERFACE_LIST_ENTRY));
+
+ if (!interfaces)
+ {
+ USBERR0("memory allocation failed\n");
+ status = STATUS_NO_MEMORY;
+ ExFreePool(configuration_descriptor);
+ goto SetConfigurationDone;
+ }
+
+ memset(interfaces, 0, (configuration_descriptor->bNumInterfaces + 1)
+ * sizeof(USBD_INTERFACE_LIST_ENTRY));
+
+ interface_number = 0;
+
+ for (i = 0; i < configuration_descriptor->bNumInterfaces; i++)
+ {
+ for (j = interface_number; j < LIBUSB_MAX_NUMBER_OF_INTERFACES; j++)
+ {
+ interface_descriptor =
+ find_interface_desc(configuration_descriptor, desc_size, j, 0);
+ if (interface_descriptor)
+ {
+ interface_number = ++j;
+ break;
+ }
+ }
+
+ if (!interface_descriptor)
+ {
+ USBERR("unable to find interface descriptor at index %d\n", i);
+ status = STATUS_INVALID_PARAMETER;
+ ExFreePool(configuration_descriptor);
+ goto SetConfigurationDone;
+ }
+ else
+ {
+ USBMSG("found interface %d\n",
+ interface_descriptor->bInterfaceNumber);
+ interfaces[i].InterfaceDescriptor = interface_descriptor;
+ }
+ }
+
+ urb_ptr = USBD_CreateConfigurationRequestEx(configuration_descriptor, interfaces);
+ if (!urb_ptr)
+ {
+ USBERR0("memory allocation failed\n");
+ status = STATUS_NO_MEMORY;
+ ExFreePool(configuration_descriptor);
+ goto SetConfigurationDone;
+ }
+
+ for (i = 0; i < configuration_descriptor->bNumInterfaces; i++)
+ {
+ for (j = 0; j < (int)interfaces[i].Interface->NumberOfPipes; j++)
+ {
+ interfaces[i].Interface->Pipes[j].MaximumTransferSize = LIBUSB_MAX_READ_WRITE;
+ }
+ }
+
+ USBDBG("#%d %s passing configuration request to target-device.",
+ dev->id, dev->device_id);
+
+ status = call_usbd(dev, urb_ptr, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb_ptr->UrbHeader.Status))
+ {
+ USBERR("setting configuration %d failed: status: 0x%x, urb-status: 0x%x\n",
+ configuration, status, urb_ptr->UrbHeader.Status);
+ if (NT_SUCCESS(status)) status = urb_ptr->UrbHeader.Status;
+
+ ExFreePool(configuration_descriptor);
+ goto SetConfigurationDone;
+ }
+
+ dev->config.handle = urb_ptr->UrbSelectConfiguration.ConfigurationHandle;
+
+ clear_pipe_info(dev);
+
+ for (i = 0; i < configuration_descriptor->bNumInterfaces; i++)
+ {
+ update_pipe_info(dev, interfaces[i].Interface);
+ }
+ UpdateContextConfigDescriptor(dev, configuration_descriptor, desc_size, configuration_descriptor->bConfigurationValue, config_index);
+
+SetConfigurationDone:
+ if (interfaces)
+ ExFreePool(interfaces);
+
+ if (urb_ptr)
+ ExFreePool(urb_ptr);
+
+ return status;
+}
diff --git a/usb/driver/set_descriptor.c b/usb/driver/set_descriptor.c
new file mode 100644
index 0000000..46bbad7
--- /dev/null
+++ b/usb/driver/set_descriptor.c
@@ -0,0 +1,71 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS set_descriptor(libusb_device_t *dev,
+ void *buffer, int size, int type, int recipient,
+ int index, int language_id, int *sent, int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("buffer size: %d type: %04d recipient: %04d index: %04d language id: %04d timeout: %d\n",
+ size,type,recipient,index,language_id,timeout);
+
+ memset(&urb, 0, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
+
+
+ switch (recipient)
+ {
+ case USB_RECIP_DEVICE:
+ urb.UrbHeader.Function = URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE;
+ break;
+ case USB_RECIP_INTERFACE:
+ urb.UrbHeader.Function = URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE;
+ break;
+ case USB_RECIP_ENDPOINT:
+ urb.UrbHeader.Function = URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT;
+ break;
+ default:
+ USBERR0("invalid recipient\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
+ urb.UrbControlDescriptorRequest.TransferBufferLength = size;
+ urb.UrbControlDescriptorRequest.TransferBuffer = buffer;
+ urb.UrbControlDescriptorRequest.DescriptorType = (UCHAR)type;
+ urb.UrbControlDescriptorRequest.Index = (UCHAR)index;
+ urb.UrbControlDescriptorRequest.LanguageId = (USHORT)language_id;
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("setting descriptor failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ }
+ else
+ {
+ *sent = urb.UrbControlDescriptorRequest.TransferBufferLength;
+ }
+ return status;
+}
diff --git a/usb/driver/set_feature.c b/usb/driver/set_feature.c
new file mode 100644
index 0000000..12e7745
--- /dev/null
+++ b/usb/driver/set_feature.c
@@ -0,0 +1,67 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+
+NTSTATUS set_feature(libusb_device_t *dev, int recipient, int index,
+ int feature, int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ USBMSG("recipient: %02d index: %04d feature %04d timeout: %d\n",
+ recipient,index,feature,timeout);
+
+ memset(&urb, 0, sizeof(struct _URB_CONTROL_FEATURE_REQUEST));
+
+ switch (recipient)
+ {
+ case USB_RECIP_DEVICE:
+ urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_DEVICE;
+ break;
+ case USB_RECIP_INTERFACE:
+ urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_INTERFACE;
+ break;
+ case USB_RECIP_ENDPOINT:
+ urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_ENDPOINT;
+ break;
+ case USB_RECIP_OTHER:
+ urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_OTHER;
+ urb.UrbControlFeatureRequest.Index = 0;
+ break;
+ default:
+ USBERR0("invalid recipient\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_FEATURE_REQUEST);
+ urb.UrbControlFeatureRequest.FeatureSelector = (USHORT)feature;
+ urb.UrbControlFeatureRequest.Index = (USHORT)index;
+
+ status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("setting feature failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ }
+
+ return status;
+}
diff --git a/usb/driver/set_interface.c b/usb/driver/set_interface.c
new file mode 100644
index 0000000..840600e
--- /dev/null
+++ b/usb/driver/set_interface.c
@@ -0,0 +1,124 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+NTSTATUS set_interface(libusb_device_t *dev,
+ int interface_number,
+ int alt_interface_number,
+ int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB *urb;
+ int i, tmp_size;
+
+ USB_INTERFACE_DESCRIPTOR *interface_descriptor = NULL;
+ USBD_INTERFACE_INFORMATION *interface_information = NULL;
+
+
+ USBMSG("interface-number=%d alt-number=%d timeout=%d\n",
+ interface_number,alt_interface_number,timeout);
+
+ if (!dev->config.value || !dev->config.descriptor)
+ {
+ USBERR0("device is not configured\n");
+ return STATUS_INVALID_DEVICE_STATE;
+ }
+
+ interface_descriptor = find_interface_desc(dev->config.descriptor, dev->config.total_size, interface_number, alt_interface_number);
+
+ if (!interface_descriptor)
+ {
+ USBERR("interface-number=%d alt-number=%d does not exists.\n",
+ interface_number,alt_interface_number,timeout);
+
+ return STATUS_NO_MORE_ENTRIES;
+ }
+
+ tmp_size = sizeof(struct _URB_SELECT_INTERFACE) + interface_descriptor->bNumEndpoints * sizeof(USBD_PIPE_INFORMATION);
+
+ urb = ExAllocatePool(NonPagedPool, tmp_size);
+
+ if (!urb)
+ {
+ USBERR0("memory_allocation error\n");
+ return STATUS_NO_MEMORY;
+ }
+
+ memset(urb, 0, tmp_size);
+
+ urb->UrbHeader.Function = URB_FUNCTION_SELECT_INTERFACE;
+ urb->UrbHeader.Length = (USHORT)tmp_size;
+
+ urb->UrbSelectInterface.ConfigurationHandle = dev->config.handle;
+ urb->UrbSelectInterface.Interface.Length = sizeof(struct _USBD_INTERFACE_INFORMATION);
+ urb->UrbSelectInterface.Interface.NumberOfPipes = interface_descriptor->bNumEndpoints;
+ urb->UrbSelectInterface.Interface.Length += interface_descriptor->bNumEndpoints * sizeof(struct _USBD_PIPE_INFORMATION);
+
+ urb->UrbSelectInterface.Interface.InterfaceNumber = (UCHAR)interface_descriptor->bInterfaceNumber;
+ urb->UrbSelectInterface.Interface.AlternateSetting = (UCHAR)interface_descriptor->bAlternateSetting;
+
+ interface_information = &urb->UrbSelectInterface.Interface;
+
+ for (i = 0; i < interface_descriptor->bNumEndpoints; i++)
+ {
+ interface_information->Pipes[i].MaximumTransferSize = LIBUSB_MAX_READ_WRITE;
+ }
+
+ status = call_usbd(dev, urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
+
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb->UrbHeader.Status))
+ {
+ USBERR("setting interface failed: status: 0x%x, urb-status: 0x%x\n", status, urb->UrbHeader.Status);
+ ExFreePool(urb);
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ update_pipe_info(dev, interface_information);
+
+ ExFreePool(urb);
+
+ return status;
+}
+
+NTSTATUS set_interface_ex(libusb_device_t *dev,
+ interface_request_t* interface_request,
+ int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+
+ USB_INTERFACE_DESCRIPTOR *interface_descriptor = NULL;
+
+ USBMSG("interface-%s=%d alt-%s=%d timeout=%d\n",
+ interface_request->intf_use_index ? "index" : "number",
+ interface_request->intf_use_index ? interface_request->interface_index : interface_request->interface_number,
+ interface_request->altf_use_index ? "index" : "number",
+ interface_request->altf_use_index ? interface_request->altsetting_index : interface_request->altsetting_number,
+ timeout);
+
+ interface_descriptor = find_interface_desc_ex(dev->config.descriptor,dev->config.total_size,interface_request,NULL);
+ if (!interface_descriptor)
+ {
+ return STATUS_NO_MORE_ENTRIES;
+ }
+
+ return set_interface(dev,interface_descriptor->bInterfaceNumber, interface_descriptor->bAlternateSetting, timeout);
+}
diff --git a/usb/driver/transfer.c b/usb/driver/transfer.c
new file mode 100644
index 0000000..0a02aa1
--- /dev/null
+++ b/usb/driver/transfer.c
@@ -0,0 +1,1493 @@
+/* libusb-win32, Generic Windows USB Library
+* Copyright (c) 2010 Travis Robinson <libusbdotnet@gmail.com>
+* Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+*
+* 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+
+#include "libusb_driver.h"
+
+typedef struct
+{
+ URB *urb;
+ int sequence;
+} context_t;
+
+static LONG sequence = 0;
+
+static const char* read_pipe_display_names[] = {"ctrl-read", "iso-read", "bulk-read", "int-read"};
+static const char* write_pipe_display_names[] = {"ctrl-write","iso-write","bulk-write","int-write"};
+
+
+typedef struct _MAIN_REQUEST_CONTEXT
+{
+ // List of all sub requests (SUB_REQUEST_CONTEXT structures) that
+ // are allocated to handle the original main request irp.
+ //
+ LIST_ENTRY SubRequestList;
+ LONG sequenceID;
+ const char* dispTransfer;
+} MAIN_REQUEST_CONTEXT, *PMAIN_REQUEST_CONTEXT;
+
+// The MAIN_REQUEST_CONTEXT structure is overlaid on top of the main
+// request irp Tail.Overlay.DriverContext structure instead of being
+// allocated separately. Make sure it fits!
+//
+C_ASSERT(sizeof(MAIN_REQUEST_CONTEXT) <= sizeof(((PIRP)0)->Tail.Overlay.DriverContext));
+
+typedef struct _SUB_REQUEST_CONTEXT
+{
+ // Main request irp that caused this sub request to be allocated.
+ //
+ PIRP MainIrp;
+
+ // List entry that links this sub request into the main request irp
+ // context SubRequestList. The sub request will be inserted into
+ // the list as long as the sub request is outstanding. The sub
+ // request is only removed from the list by the sub request
+ // completion routine.
+ //
+ LIST_ENTRY ListEntry;
+
+ // List entry that is used only by the main request irp cancel
+ // routine to build a list of all currently outstanding sub
+ // requests in order to cancel them.
+ //
+ LIST_ENTRY CancelListEntry;
+
+ // Reference count incremented (set to one) before calling the sub
+ // request down the driver stack, decremented by the sub request
+ // completion routine, and incremented/decremented by the main
+ // request irp cancl routine. This is used to prevent the sub
+ // request from being freed by either the sub request completion
+ // routine or the main request irp cancel routine while the sub
+ // request is simultaneously being accessed by the other routine.
+ // The sub request is freed by the routine that last accesses the
+ // sub request and decrements the reference count to zero.
+ //
+ LONG ReferenceCount;
+
+ // irp, Urb, and Mdl allocated to send the sub request down the
+ // driver stack.
+ //
+ PIRP SubIrp;
+ PURB SubUrb;
+ PMDL SubMdl;
+
+ ULONG startOffset;
+
+} SUB_REQUEST_CONTEXT, *PSUB_REQUEST_CONTEXT;
+
+static const char* GetPipeDisplayName(libusb_endpoint_t* endpoint);
+
+NTSTATUS DDKAPI transfer_complete(DEVICE_OBJECT* device_object,
+ IRP *irp,
+ void *context);
+
+static NTSTATUS create_urb(libusb_device_t *dev,
+ URB **urb,
+ int direction,
+ int urbFunction,
+ libusb_endpoint_t* endpoint,
+ int packetSize,
+ MDL *buffer,
+ int size);
+
+VOID large_transfer_cancel_routine(IN PDEVICE_OBJECT DeviceObject, IN PIRP irp);
+VOID large_transfer_cancel(IN PIRP irp, BOOLEAN releaseCancelSpinlock);
+
+NTSTATUS large_transfer_complete(IN PDEVICE_OBJECT DeviceObjectIsNULL,
+ IN PIRP irp,
+ IN PVOID Context);
+
+static int get_iso_stagesize(int totalLength, int packetSize, int maxTransferSize);
+
+static NTSTATUS allocate_suburb(USHORT urbFunction,
+ int stageSize,
+ int packetSize,
+ ULONG* nPackets,
+ PURB* subUrbRef);
+
+void set_urb_transfer_flags(libusb_device_t* dev,
+ PIRP irp,
+ PURB subUrb,
+ int transfer_flags,
+ int isoLatency);
+
+NTSTATUS transfer(libusb_device_t* dev,
+ IN PIRP irp,
+ IN int direction,
+ IN int urbFunction,
+ IN libusb_endpoint_t* endpoint,
+ IN int packetSize,
+ IN int transferFlags,
+ IN int isoLatency,
+ IN PMDL mdlAddress,
+ IN int totalLength)
+{
+ IO_STACK_LOCATION *stack_location = NULL;
+ context_t *context;
+ NTSTATUS status = STATUS_SUCCESS;
+ int sequenceID = InterlockedIncrement(&sequence);
+ const char* dispTransfer = GetPipeDisplayName(endpoint);
+
+ // TODO: reset pipe flag
+ // status = reset_endpoint(dev,endpoint->address, LIBUSB_DEFAULT_TIMEOUT);
+ //
+ if (!packetSize)
+ packetSize = endpoint->maximum_packet_size;
+
+ if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ USBMSG("[%s #%d] EP%02Xh packet-size=%d length=%d reset-status=%08Xh\n",
+ dispTransfer, sequenceID, endpoint->address, packetSize, totalLength, status);
+ }
+ else
+ {
+ USBMSG("[%s #%d] EP%02Xh length %d\n",
+ dispTransfer, sequenceID, endpoint->address, totalLength);
+ }
+ context = ExAllocatePool(NonPagedPool, sizeof(context_t));
+
+ if (!context)
+ {
+ remove_lock_release(dev);
+ return complete_irp(irp, STATUS_NO_MEMORY, 0);
+ }
+
+ status = create_urb(dev, &context->urb, direction, urbFunction,
+ endpoint, packetSize, mdlAddress, totalLength);
+
+ if (!NT_SUCCESS(status))
+ {
+ ExFreePool(context);
+ remove_lock_release(dev);
+ return complete_irp(irp, status, 0);
+ }
+
+
+ context->sequence = sequenceID;
+
+ stack_location = IoGetNextIrpStackLocation(irp);
+
+ stack_location->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
+ stack_location->Parameters.Others.Argument1 = context->urb;
+ stack_location->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
+
+ IoSetCompletionRoutine(irp, transfer_complete, context, TRUE, TRUE, TRUE);
+
+ // Set the transfer flags just before we call the irp down.
+ // If this is an iso transfer, set_urb_transfer_flags() might need
+ // to get the start frame and set latency.
+ //
+ set_urb_transfer_flags(dev, irp, context->urb, transferFlags, isoLatency);
+
+ return IoCallDriver(dev->target_device, irp);
+}
+
+
+NTSTATUS DDKAPI transfer_complete(DEVICE_OBJECT *device_object, IRP *irp,
+ void *context)
+{
+ context_t *c = (context_t *)context;
+ int transmitted = 0;
+ libusb_device_t *dev = device_object->DeviceExtension;
+
+ if (irp->PendingReturned)
+ {
+ IoMarkIrpPending(irp);
+ }
+
+ if (NT_SUCCESS(irp->IoStatus.Status)
+ && USBD_SUCCESS(c->urb->UrbHeader.Status))
+ {
+ if (c->urb->UrbHeader.Function == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ transmitted = c->urb->UrbIsochronousTransfer.TransferBufferLength;
+ }
+ if (c->urb->UrbHeader.Function == URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER)
+ {
+ transmitted
+ = c->urb->UrbBulkOrInterruptTransfer.TransferBufferLength;
+ }
+
+ USBMSG("sequence %d: %d bytes transmitted\n",
+ c->sequence, transmitted);
+ }
+ else
+ {
+ if (irp->IoStatus.Status == STATUS_CANCELLED)
+ {
+ USBERR("sequence %d: timeout error\n",
+ c->sequence);
+ }
+ else
+ {
+ USBERR("sequence %d: transfer failed: status: 0x%x, urb-status: 0x%x\n",
+ c->sequence, irp->IoStatus.Status,
+ c->urb->UrbHeader.Status);
+ }
+ }
+
+ ExFreePool(c->urb);
+ ExFreePool(c);
+
+ irp->IoStatus.Information = transmitted;
+
+ remove_lock_release(dev);
+
+ return STATUS_SUCCESS;
+}
+
+
+static NTSTATUS create_urb(libusb_device_t *dev, URB **urb, int direction,
+ int urbFunction, libusb_endpoint_t* endpoint, int packetSize,
+ MDL *buffer, int size)
+{
+ USBD_PIPE_HANDLE pipe_handle = NULL;
+ int num_packets = 0;
+ int i, urb_size;
+
+ *urb = NULL;
+
+ pipe_handle = endpoint->handle;
+
+ /* isochronous transfer */
+ if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ if (packetSize <= 0)
+ {
+ USBERR("invalid packet size=%d\n", packetSize);
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ num_packets = size / packetSize;
+
+ if (num_packets <= 0)
+ {
+ USBERR("invalid number of packets=%d\n",
+ num_packets);
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (num_packets > 255)
+ {
+ USBERR0("transfer size too large\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ urb_size = sizeof(struct _URB_ISOCH_TRANSFER)
+ + sizeof(USBD_ISO_PACKET_DESCRIPTOR) * num_packets;
+ }
+ else /* bulk or interrupt transfer */
+ {
+ urb_size = sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER);
+ }
+
+ *urb = ExAllocatePool(NonPagedPool, urb_size);
+
+ if (!*urb)
+ {
+ USBERR0("memory allocation error\n");
+ return STATUS_NO_MEMORY;
+ }
+
+ memset(*urb, 0, urb_size);
+
+ (*urb)->UrbHeader.Length = (USHORT)urb_size;
+ (*urb)->UrbHeader.Function = (USHORT)urbFunction;
+
+ /* isochronous transfer */
+ if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ (*urb)->UrbIsochronousTransfer.PipeHandle = pipe_handle;
+ (*urb)->UrbIsochronousTransfer.TransferFlags = direction;
+ (*urb)->UrbIsochronousTransfer.TransferBufferLength = size;
+ (*urb)->UrbIsochronousTransfer.TransferBufferMDL = buffer;
+ (*urb)->UrbIsochronousTransfer.NumberOfPackets = num_packets;
+
+ for (i = 0; i < num_packets; i++)
+ {
+ (*urb)->UrbIsochronousTransfer.IsoPacket[i].Offset = i * packetSize;
+ (*urb)->UrbIsochronousTransfer.IsoPacket[i].Length = packetSize;
+ }
+ }
+ /* bulk or interrupt transfer */
+ else
+ {
+ (*urb)->UrbBulkOrInterruptTransfer.PipeHandle = pipe_handle;
+ (*urb)->UrbBulkOrInterruptTransfer.TransferFlags = direction;
+ (*urb)->UrbBulkOrInterruptTransfer.TransferBufferLength = size;
+ (*urb)->UrbBulkOrInterruptTransfer.TransferBufferMDL = buffer;
+ }
+
+ return STATUS_SUCCESS;
+}
+
+/*-----------------------------------------------------------------------------
+Routine Description:
+This routine splits up a main transfer request into one or more sub
+requests as necessary.
+
+[ISOCHRONOUS TRANSFERS]
+Each isoch irp/urb pair can span at most 255 packets.
+Each isoch irp/urb pair can request at the most 65536 bytes.
+
+[BULK OR INTERRUPT TRANSFERS]
+Each bulk/interrupt irp/urb pair can request at the most 65536 bytes.
+
+1. It creates a SUB_REQUEST_CONTEXT for each irp/urb pair and
+attaches it to the main request irp.
+
+2. It intializes all of the sub request irp/urb pairs, and sub mdls
+too.
+
+3. It passes down the driver stack all of the sub request irps.
+
+4. It leaves the completion of the main request irp as the
+responsibility of the sub request irp completion routine, except
+in the exception case where the main request irp is canceled
+prior to passing any of the the sub request irps down the driver
+stack.
+
+Arguments:
+
+dev - pointer to device object
+irp - I/O request packet
+direction - URB I/O direction (IN/OUT)
+urbFunction - urb transfer function
+endpoint - libusb_endpoint_t*
+packetSize - isochronous packet size
+maxTransferSize,
+transferFlags,
+isoLatency -
+mdlAddress - transfer mdl buffer
+totalLength - no. of bytes to be transferred
+
+Return Value:
+
+NT status value
+*/
+NTSTATUS large_transfer(IN libusb_device_t* dev,
+ IN PIRP irp,
+ IN int direction,
+ IN int urbFunction,
+ IN libusb_endpoint_t* endpoint,
+ IN int packetSize,
+ IN int maxTransferSize,
+ IN int transferFlags,
+ IN int isoLatency,
+ IN PMDL mdlAddress,
+ IN int totalLength)
+{
+ PIO_STACK_LOCATION irpStack;
+ BOOLEAN read;
+ ULONG stageSize;
+ ULONG numIrps;
+ PMAIN_REQUEST_CONTEXT mainRequestContext;
+ PSUB_REQUEST_CONTEXT * subRequestContextArray;
+ PSUB_REQUEST_CONTEXT subRequestContext;
+ CCHAR stackSize;
+ PUCHAR virtualAddress;
+ ULONG i;
+ ULONG j;
+ NTSTATUS ntStatus;
+ PIO_STACK_LOCATION nextStack;
+ USBD_PIPE_HANDLE pipeHandle;
+
+ LONG sequenceID;
+ const char* dispTransfer;
+ int startOffset;
+
+ // TODO: reset pipe flag
+ // if (urbFunction != URB_FUNCTION_ISOCH_TRANSFER && pipe_flags & RESET)
+ // status = reset_endpoint(dev,endpoint->address, LIBUSB_DEFAULT_TIMEOUT);
+ //
+ //reset the pipe (if irps are pending this will fail)
+ //
+ //if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ // reset_endpoint(dev,endpoint->address,LIBUSB_DEFAULT_TIMEOUT);
+
+ //
+ // initialize vars
+ //
+ irpStack = IoGetCurrentIrpStackLocation(irp);
+ sequenceID = InterlockedIncrement(&sequence);
+ subRequestContextArray = NULL;
+
+ if (!maxTransferSize)
+ maxTransferSize = endpoint->maximum_transfer_size;
+
+ if (!packetSize)
+ packetSize = endpoint->maximum_packet_size;
+
+ startOffset = 0;
+
+ read = (direction == USBD_TRANSFER_DIRECTION_IN) ? TRUE : FALSE;
+ dispTransfer = GetPipeDisplayName(endpoint);
+ pipeHandle = endpoint->handle;
+
+ // defaults
+ stageSize = totalLength;
+ numIrps = 1;
+
+ // Full speed ISO note:
+ // There is an inherent limit on the number of packets that can be
+ // passed down the stack with each irp/urb pair (255)
+ //
+ // If the number of required packets is > 255, we shall create
+ // "(required-packets / 255) [+ 1]" number of irp/urb pairs.
+ //
+ // Each irp/urb pair transfer is also called a stage transfer.
+ //
+
+ // TODO: detect and optimize for high speed devices.
+ //
+ if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ stageSize = get_iso_stagesize(totalLength, packetSize, maxTransferSize);
+ numIrps = (totalLength + stageSize - 1) / stageSize;
+ USBMSG("[%s #%d] EP%02Xh total-size=%d stage-size=%d IRPs=%d packet-size=%d\n",
+ dispTransfer, sequenceID, endpoint->address, totalLength, stageSize, numIrps, packetSize);
+ }
+ else
+ {
+ if (totalLength > (maxTransferSize))
+ stageSize = maxTransferSize;
+ numIrps = (totalLength + stageSize - 1) / stageSize;
+ USBMSG("[%s #%d] EP%02Xh total-size=%d stage-size=%d IRPs=%d\n",
+ dispTransfer, sequenceID, endpoint->address, totalLength, stageSize, numIrps);
+ }
+
+ // Initialize the main request irp read/write context, which is
+ // overlaid on top of irp->Tail.Overlay.DriverContext.
+ //
+ mainRequestContext = (PMAIN_REQUEST_CONTEXT)irp->Tail.Overlay.DriverContext;
+
+ mainRequestContext->dispTransfer = dispTransfer;
+ mainRequestContext->sequenceID = sequenceID;
+
+ InitializeListHead(&mainRequestContext->SubRequestList);
+
+ stackSize = dev->target_device->StackSize;
+
+ virtualAddress = (PUCHAR) MmGetMdlVirtualAddress(mdlAddress);
+ if (!virtualAddress)
+ {
+ USBERR("[%s #%d] MmGetMdlVirtualAddress failed\n",
+ dispTransfer, sequenceID);
+ ntStatus = STATUS_INSUFFICIENT_RESOURCES;
+ goto transfer_Free;
+ }
+
+ // Allocate an array to keep track of the sub requests that will be
+ // allocated below. This array exists only during the execution of
+ // this routine and is used only to keep track of the sub requests
+ // before calling them down the driver stack.
+ //
+ subRequestContextArray = (PSUB_REQUEST_CONTEXT *)
+ ExAllocatePool(NonPagedPool,
+ numIrps * sizeof(PSUB_REQUEST_CONTEXT));
+
+ if (subRequestContextArray == NULL)
+ {
+ USBERR("[%s #%d] failed allocating sub request context array\n",
+ dispTransfer, sequenceID);
+
+ ntStatus = STATUS_INSUFFICIENT_RESOURCES;
+
+ goto transfer_Free;
+ }
+
+ RtlZeroMemory(subRequestContextArray, numIrps * sizeof(PSUB_REQUEST_CONTEXT));
+
+ //
+ // Allocate the sub requests
+ //
+ for (i = 0; i < numIrps; i++)
+ {
+ PIRP subIrp;
+ PURB subUrb;
+ PMDL subMdl;
+ // ULONG urbSize;
+ ULONG offset;
+ ULONG nPackets=0;
+
+ // The following outer scope variables are updated during each
+ // iteration of the loop: virtualAddress, totalLength, stageSize
+
+ //
+ // For every stage of transfer we need to do the following
+ // tasks:
+ //
+ // 1. Allocate a sub request context (SUB_REQUEST_CONTEXT).
+ // 2. Allocate a sub request irp.
+ // 3. Allocate a sub request urb.
+ // 4. Allocate a sub request mdl.
+ // 5. Initialize the above allocations.
+ //
+
+ //
+ // 1. Allocate a Sub Request Context (SUB_REQUEST_CONTEXT)
+ //
+
+ subRequestContext = (PSUB_REQUEST_CONTEXT)
+ ExAllocatePool(NonPagedPool, sizeof(SUB_REQUEST_CONTEXT));
+
+ if (subRequestContext == NULL)
+ {
+ USBERR("[%s #%d] failed allocating sub request context\n",
+ dispTransfer, sequenceID);
+
+ ntStatus = STATUS_INSUFFICIENT_RESOURCES;
+
+ goto transfer_Free;
+ }
+
+ RtlZeroMemory(subRequestContext, sizeof(SUB_REQUEST_CONTEXT));
+
+ // Attach it to the main request irp.
+ //
+ InsertTailList(&mainRequestContext->SubRequestList, &subRequestContext->ListEntry);
+
+ // Remember it independently so we can refer to it later without
+ // walking the sub request list.
+ //
+ subRequestContextArray[i] = subRequestContext;
+
+ // Set the master irp that all the sub-requests originated from.
+ subRequestContext->MainIrp = irp;
+
+ // Remember the start offset
+ subRequestContext->startOffset = startOffset;
+
+ // The reference count on the sub request prevents it from being
+ // freed until the completion routine for the sub request
+ // executes.
+ //
+ subRequestContext->ReferenceCount = 1;
+
+ //
+ // 2. Allocate a sub request irp
+ //
+ subIrp = IoAllocateIrp(stackSize, FALSE);
+
+ if (subIrp == NULL)
+ {
+ USBERR("[%s #%d] failed allocating subIrp\n", dispTransfer, sequenceID);
+
+ ntStatus = STATUS_INSUFFICIENT_RESOURCES;
+
+ goto transfer_Free;
+ }
+
+ subRequestContext->SubIrp = subIrp;
+
+ ntStatus = allocate_suburb((USHORT)urbFunction, stageSize, packetSize, &nPackets, &subUrb);
+ if (!NT_SUCCESS(ntStatus))
+ {
+ USBERR("[%s #%d] failed allocating subUrb\n", dispTransfer, sequenceID);
+ goto transfer_Free;
+ }
+ else
+ {
+ USBDBG("[%s #%d] packets=%d irp-urb = #%d\n",
+ dispTransfer, sequenceID, nPackets, i);
+ }
+
+ subRequestContext->SubUrb = subUrb;
+
+ //
+ // 4. Allocate a sub request mdl.
+ //
+ subMdl = IoAllocateMdl((PVOID) virtualAddress,
+ stageSize,
+ FALSE,
+ FALSE,
+ NULL);
+
+ if (subMdl == NULL)
+ {
+ USBERR("[%s #%d] failed allocating subMdl\n", dispTransfer, sequenceID);
+
+ ntStatus = STATUS_INSUFFICIENT_RESOURCES;
+
+ goto transfer_Free;
+ }
+
+ subRequestContext->SubMdl = subMdl;
+
+ IoBuildPartialMdl(irp->MdlAddress,
+ subMdl,
+ (PVOID)virtualAddress,
+ stageSize);
+
+ // Update loop variables for next iteration.
+ //
+ virtualAddress += stageSize;
+
+ totalLength -= stageSize;
+
+ //
+ // Initialize the sub request urb.
+ //
+ if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ USBDBG("[%s #%d] stage-size=%d nPackets=%d\n",
+ dispTransfer, sequenceID, stageSize, nPackets);
+
+ subUrb->UrbIsochronousTransfer.PipeHandle = pipeHandle;
+
+ // The direction is set here, other flags are set in the
+ // set_urb_transfer_flags() function.
+ //
+ subUrb->UrbIsochronousTransfer.TransferFlags = direction;
+
+ subUrb->UrbIsochronousTransfer.TransferBufferLength = stageSize;
+ subUrb->UrbIsochronousTransfer.TransferBufferMDL = subMdl;
+
+ //
+ // when the client driver sets the ASAP flag, it basically
+ // guarantees that it will make data available to the HC
+ // and that the HC should transfer it in the next transfer frame
+ // for the endpoint.(The HC maintains a next transfer frame
+ // state variable for each endpoint). By resetting the pipe,
+ // we make the pipe as virgin. If the data does not get to the HC
+ // fast enough, the USBD_ISO_PACKET_DESCRIPTOR - Status is
+ // USBD_STATUS_BAD_START_FRAME on uhci. On ohci it is 0xC000000E.
+ //
+
+ subUrb->UrbIsochronousTransfer.NumberOfPackets = nPackets;
+ //
+ // Set the offsets for every packet for reads/writes
+ //
+ if (read)
+ {
+ offset = 0;
+
+ for (j = 0; j < nPackets; j++)
+ {
+ subUrb->UrbIsochronousTransfer.IsoPacket[j].Offset = offset;
+
+ if (stageSize > (ULONG)packetSize)
+ {
+ subUrb->UrbIsochronousTransfer.IsoPacket[j].Length = 0;
+ offset += packetSize;
+ stageSize -= packetSize;
+ }
+ else
+ {
+ subUrb->UrbIsochronousTransfer.IsoPacket[j].Length = 0;
+ offset += stageSize;
+ stageSize = 0;
+ }
+ }
+ }
+ else
+ {
+ offset = 0;
+
+ for (j = 0; j < nPackets; j++)
+ {
+ subUrb->UrbIsochronousTransfer.IsoPacket[j].Offset = offset;
+
+ if (stageSize > (ULONG)packetSize)
+ {
+ subUrb->UrbIsochronousTransfer.IsoPacket[j].Length = packetSize;
+ offset += packetSize;
+ stageSize -= packetSize;
+ }
+ else
+ {
+ subUrb->UrbIsochronousTransfer.IsoPacket[j].Length = stageSize;
+ offset += stageSize;
+ stageSize = 0;
+ /*
+ ASSERT(offset == (subUrb->UrbIsochronousTransfer.IsoPacket[j].Length +
+ subUrb->UrbIsochronousTransfer.IsoPacket[j].Offset));
+ */
+ }
+ }
+ }
+ }
+ else
+ {
+ USBDBG("[%s #%d] stage-size=%d\n",dispTransfer, sequenceID, stageSize);
+
+ subUrb->UrbBulkOrInterruptTransfer.PipeHandle = pipeHandle;
+
+ subUrb->UrbBulkOrInterruptTransfer.TransferFlags = direction;
+
+ subUrb->UrbBulkOrInterruptTransfer.TransferBufferLength = stageSize;
+ subUrb->UrbBulkOrInterruptTransfer.TransferBufferMDL = subMdl;
+ }
+ // Initialize the sub irp stack location
+ //
+ nextStack = IoGetNextIrpStackLocation(subIrp);
+
+ nextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
+
+ nextStack->Parameters.Others.Argument1 = (PVOID) subUrb;
+
+ nextStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
+
+ IoSetCompletionRoutine(subIrp,
+ (PIO_COMPLETION_ROUTINE)large_transfer_complete,
+ (PVOID)subRequestContext,
+ TRUE,
+ TRUE,
+ TRUE);
+
+ // Update loop variables for next iteration.
+ //
+ if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ stageSize = get_iso_stagesize(totalLength, packetSize, maxTransferSize);
+ else
+ {
+ if (totalLength > (maxTransferSize))
+ stageSize = maxTransferSize;
+ else
+ stageSize = totalLength;
+ }
+ startOffset += stageSize;
+ }
+
+ //
+ // While we were busy create subsidiary irp/urb pairs..
+ // the main read/write irp may have been cancelled !!
+ //
+
+ if (!irp->Cancel)
+ {
+ //
+ // normal processing
+ //
+
+ USBDBG("[%s #%d] normal processing\n", dispTransfer, sequenceID);
+
+ IoMarkIrpPending(irp);
+
+ // The cancel routine might run simultaneously as soon as it is
+ // set. Do not access the main request irp in any way after
+ // setting the cancel routine.
+ //
+ // Note that it is still safe to access the sub requests up to
+ // the point where each sub request is called down the driver
+ // stack due to the sub request reference count which must be
+ // decremented by the completion routine. Do not access a sub
+ // request in any way after it is called down the driver stack.
+ //
+ // After setting the main request irp cancel routine we are
+ // committed to calling each of the sub requests down the
+ // driver stack.
+ //
+ IoSetCancelRoutine(irp, large_transfer_cancel_routine);
+
+ for (i = 0; i < numIrps; i++)
+ {
+ subRequestContext = subRequestContextArray[i];
+
+ USBDBG("[%s #%d] IoCallDriver subIrp %d\n", dispTransfer, sequenceID, i);
+
+ // Set the transfer flags just before we call the irp down.
+ // If this is an iso transfer, set_urb_transfer_flags() might need
+ // to get the start frame and set latency.
+ //
+ set_urb_transfer_flags(dev,irp, subRequestContext->SubUrb, transferFlags, isoLatency);
+
+ IoCallDriver(dev->target_device, subRequestContext->SubIrp);
+ }
+
+ // The sub requests are freed in either the sub request
+ // completion routine or in the main request irp cancel routine.
+ //
+ // Main request irp is completed only in sub request completion
+ // routine.
+
+ ExFreePool(subRequestContextArray);
+
+ return STATUS_PENDING;
+ }
+ else
+ {
+ //
+ // The Cancel flag for the irp has been set.
+ //
+ USBDBG("[%s #%d] Cancel flag set\n", dispTransfer, sequenceID);
+
+ ntStatus = STATUS_CANCELLED;
+ }
+
+ //
+ // Resource allocation failure, or the main request irp was
+ // cancelled before the cancel routine was set. Free any resource
+ // allocations and complete the main request irp.
+ //
+ // No sub requests were ever called down the driver stack in this
+ // case.
+ //
+
+transfer_Free:
+
+ if (subRequestContextArray != NULL)
+ {
+ for (i = 0; i < numIrps; i++)
+ {
+ subRequestContext = subRequestContextArray[i];
+
+ if (subRequestContext != NULL)
+ {
+ if (subRequestContext->SubIrp != NULL)
+ {
+ IoFreeIrp(subRequestContext->SubIrp);
+ }
+
+ if (subRequestContext->SubUrb != NULL)
+ {
+ ExFreePool(subRequestContext->SubUrb);
+ }
+
+ if (subRequestContext->SubMdl != NULL)
+ {
+ IoFreeMdl(subRequestContext->SubMdl);
+ }
+
+ ExFreePool(subRequestContext);
+ }
+ }
+
+ ExFreePool(subRequestContextArray);
+ }
+
+ irp->IoStatus.Status = ntStatus;
+ irp->IoStatus.Information = 0;
+
+ IoCompleteRequest(irp, IO_NO_INCREMENT);
+
+ USBERR("[%s #%d] ntStatus=%Xh\n",
+ dispTransfer, sequenceID, ntStatus);
+
+ remove_lock_release(dev);
+
+ return ntStatus;
+}
+
+/*-----------------------------------------------------------------------------
+Routine Description:
+
+This routine handles the completion of a Sub Request irp that was
+created to handle part (or all) of the transfer for a Main Request
+irp.
+
+It updates the transfer length (IoStatus.Information) of the Main
+Request irp, and completes the Main Request irp if this Sub Request
+irp is the final outstanding one.
+
+The Sub Request irp and Sub Request Context may either be freed
+here, or by large_transfer_cancel(), according to which routine is
+the last one to reference the Sub Request irp.
+
+Arguments:
+
+DeviceObject - NULL as this Sub Request irp was allocated without a
+stack location for this driver to use itself.
+
+irp - Sub Request irp
+
+Context - Sub Request Context (PSUB_REQUEST_CONTEXT)
+
+Return Value:
+
+STATUS_MORE_PROCESSING_REQUIRED - Tells IoMgr not to free the Sub
+Request irp as it is either explicitly freed here, or by
+large_transfer_cancel()
+
+*/
+NTSTATUS large_transfer_complete(IN PDEVICE_OBJECT DeviceObjectIsNULL,
+ IN PIRP irp,
+ IN PVOID Context)
+{
+ PSUB_REQUEST_CONTEXT subRequestContext;
+ PURB subUrb;
+ PIRP mainIrp;
+ PMAIN_REQUEST_CONTEXT mainRequestContext;
+ PDEVICE_OBJECT deviceObject;
+ NTSTATUS ntStatus;
+ ULONG information;
+ ULONG i;
+ KIRQL irql;
+ BOOLEAN completeMainRequest;
+ int subRequestByteOffset;
+ int subRequestByteCount;
+
+ LONG sequenceID;
+ const char* dispTransfer;
+ PUCHAR outBuffer;
+ BOOLEAN needs_cancelled = FALSE;
+
+ UNREFERENCED_PARAMETER( DeviceObjectIsNULL );
+ subRequestContext = (PSUB_REQUEST_CONTEXT)Context;
+
+ subUrb = subRequestContext->SubUrb;
+ mainIrp = subRequestContext->MainIrp;
+
+ // The main request irp context is overlaid on top of
+ // irp->Tail.Overlay.DriverContext. Get a pointer to it.
+ //
+ mainRequestContext = (PMAIN_REQUEST_CONTEXT)
+ mainIrp->Tail.Overlay.DriverContext;
+
+ sequenceID = mainRequestContext->sequenceID;
+ dispTransfer = mainRequestContext->dispTransfer;
+
+ subRequestByteCount = 0;
+
+ deviceObject = IoGetCurrentIrpStackLocation(mainIrp)->DeviceObject;
+
+ ntStatus = irp->IoStatus.Status;
+
+ if (NT_SUCCESS(ntStatus) && USBD_SUCCESS(subUrb->UrbHeader.Status))
+ {
+ if (subUrb->UrbHeader.Function == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ information = subUrb->UrbIsochronousTransfer.TransferBufferLength;
+ USBDBG("[%s #%d] transferred=%d\n",
+ dispTransfer,
+ sequenceID,
+ information);
+
+ for (i = 0; i < subUrb->UrbIsochronousTransfer.NumberOfPackets; i++)
+ {
+ if (subUrb->UrbIsochronousTransfer.IsoPacket[i].Status != 0)
+ {
+ USBDBG("[%s #%d] IsoPacket[%d].Length=%d IsoPacket[%d].Status=%08Xh\n",
+ dispTransfer,
+ sequenceID,
+ i,
+ subUrb->UrbIsochronousTransfer.IsoPacket[i].Length,
+ i,
+ subUrb->UrbIsochronousTransfer.IsoPacket[i].Status);
+ }
+ }
+ }
+ else
+ {
+ subRequestByteCount = MmGetMdlByteCount(subUrb->UrbBulkOrInterruptTransfer.TransferBufferMDL);
+ subRequestByteOffset = MmGetMdlByteOffset(subUrb->UrbBulkOrInterruptTransfer.TransferBufferMDL);
+ information = subUrb->UrbBulkOrInterruptTransfer.TransferBufferLength;
+ USBDBG("[%s #%d] offset=%d requested=%d transferred=%d\n",
+ dispTransfer,
+ sequenceID,
+ subRequestByteOffset,
+ subRequestByteCount,
+ information);
+ }
+
+ }
+ else
+ {
+ information = 0;
+
+ if (ntStatus == STATUS_CANCELLED)
+ {
+ USBDBG("[%s #%d] cancelled\n",
+ dispTransfer,
+ sequenceID);
+ }
+ else
+ {
+ USBERR("[%s #%d] failed. status=%Xh urb-status=%Xh\n",
+ dispTransfer,
+ sequenceID,
+ ntStatus,
+ subUrb->UrbHeader.Status);
+ }
+ }
+
+ // Prevent the cancel routine from executing simultaneously
+ //
+ IoAcquireCancelSpinLock(&irql);
+
+ if (subUrb->UrbHeader.Function == URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER)
+ {
+ /*
+ USBDBG("[%s #%d] MdlAddress:0x%x Function:0x%x TransferFlags:0x%x information:%d srcOffset:%d dstOffset:%d\n",
+ dispTransfer,
+ sequenceID,
+ mainIrp->MdlAddress,
+ subUrb->UrbHeader.Function,
+ subUrb->UrbBulkOrInterruptTransfer.TransferFlags,
+ information,
+ mainIrp->IoStatus.Information,
+ subRequestContext->startOffset);
+ */
+
+ // If this bulk read was valid, returned a length > 0 and a
+ // previous sub irp/urb pair in this batch was short then the
+ // data was written to the wrong offset in the output buffer.
+ // We need to move this data to the correct location in the
+ // output buffer.
+ //
+ if ((mainIrp->MdlAddress) &&
+ ((subUrb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_TRANSFER_DIRECTION_IN) == USBD_TRANSFER_DIRECTION_IN) &&
+ (information > 0))
+ {
+ if (mainIrp->IoStatus.Information < subRequestContext->startOffset)
+ {
+ // Translate a virtual address range described in the MDL for a user buffer
+ // to a system-space address range.
+ //
+ outBuffer = MmGetSystemAddressForMdlSafe(mainIrp->MdlAddress, HighPagePriority);
+
+ if (!outBuffer)
+ {
+ information = 0;
+
+ USBERR("[%s #%d] failed translating a virtual address range\n",
+ dispTransfer,sequenceID);
+ }
+ else
+ {
+ USBDBG("[%s #%d] adjusting outBuffer old-offset %d to new-offset %d (length=%d)\n",
+ dispTransfer,
+ sequenceID,
+ subRequestContext->startOffset,
+ mainIrp->IoStatus.Information,
+ information);
+
+ // move the data this subirp just put in the output buffer to the correct
+ // location.
+ //
+ RtlMoveMemory(outBuffer+mainIrp->IoStatus.Information,
+ outBuffer+subRequestContext->startOffset,
+ information);
+ }
+ }
+ else if (information < (ULONG)subRequestByteCount)
+ {
+ needs_cancelled = TRUE;
+ }
+ }
+ }
+
+ // add the sub transfer length to the main transfer length.
+ //
+ mainIrp->IoStatus.Information += information;
+
+ // Remove the sub request from the main request sub request list.
+ //
+ RemoveEntryList(&subRequestContext->ListEntry);
+
+ // If the sub request list is now empty clear the main request
+ // cancel routine and note that the main request should be
+ // completed.
+ //
+ if (IsListEmpty(&mainRequestContext->SubRequestList))
+ {
+ completeMainRequest = TRUE;
+ needs_cancelled = FALSE;
+ IoSetCancelRoutine(mainIrp, NULL);
+ }
+ else
+ {
+ completeMainRequest = FALSE;
+
+ // If this is a bulk/interrupt transfer and we transmit less
+ // bytes then what we requested, cancel the pending subIrps.
+ // If the subirp(s) cannot be cancelled, any data they return
+ // must be moved to the correct location in the output buffer.
+ //
+ if (needs_cancelled)
+ {
+ // IoSetCancelRoutine returns the previous value of
+ // mainIrp->CancelRoutine. If no Cancel routine was previously
+ // set, or if IRP cancellation is already in progress,
+ // IoSetCancelRoutine returns NULL.
+ needs_cancelled = (IoSetCancelRoutine(mainIrp, NULL) == NULL) ? FALSE : TRUE;
+ }
+
+ }
+
+ // The cancel routine may now execute simultaneously, unless of
+ // course the cancel routine was just cleared above.
+ //
+ // Do not access the main irp or the mainRequestContext in any way
+ // beyond this point, unless this is the single instance of the sub
+ // request completion routine which will complete the main irp.
+ //
+ IoReleaseCancelSpinLock(irql);
+
+ // needs_cancelled is set for the first subrequest that returns "short".
+ // provided it is not the final subrequest.
+ if (needs_cancelled)
+ {
+ // we can only do this (after IoReleaseCancelSpinLock) because the
+ // cancel routine for mainIrp was removed above.
+ large_transfer_cancel(mainIrp, FALSE);
+ }
+
+ if (InterlockedDecrement(&subRequestContext->ReferenceCount) == 0)
+ {
+ // If the reference count is now zero then the cancel routine
+ // will not free the sub request. (Either the cancel routine
+ // ran and accessed the sub request and incremented the
+ // reference count and then decremented it again without freeing
+ // the sub request, or the cancel routine did not access the
+ // sub request and can no longer access it because it has been
+ // removed from the main request sub request list.)
+ //
+ IoFreeIrp(subRequestContext->SubIrp);
+
+ ExFreePool(subRequestContext->SubUrb);
+
+ IoFreeMdl(subRequestContext->SubMdl);
+
+ ExFreePool(subRequestContext);
+ }
+ else
+ {
+ // In this case the cancel routine for the main request must be
+ // executing and is accessing the sub request after
+ // incrementing its reference count. When the cancel routine
+ // decrements the reference count again it will take care of
+ // freeing the sub request.
+ }
+
+ if (completeMainRequest)
+ {
+ // The final sub request for the main request has completed so
+ // now complete the main request.
+ //
+ USBMSG("[%s #%d] done. total transferred=%d\n",
+ dispTransfer,
+ sequenceID,
+ mainIrp->IoStatus.Information);
+
+ mainIrp->IoStatus.Status = STATUS_SUCCESS;
+
+ IoCompleteRequest(mainIrp, IO_NO_INCREMENT);
+
+ // the remove lock was referenced in dispatch_ioctl() when the main irp
+ // was first submitted.
+ remove_lock_release(deviceObject->DeviceExtension);
+ }
+
+ return STATUS_MORE_PROCESSING_REQUIRED;
+}
+
+/*++
+
+Routine Description:
+
+This is the cancellation routine for the main read/write irp.
+
+It cancels all currently outstanding sub requests for the main
+request.
+
+Completing the main request is the responsibility of the sub
+request completion routine after all outstanding sub requests have
+completed.
+
+Return Value:
+
+None
+
+--*/
+VOID large_transfer_cancel_routine(IN PDEVICE_OBJECT DeviceObject, IN PIRP irp)
+{
+ large_transfer_cancel(irp, TRUE);
+}
+
+/*++
+
+Routine Description:
+
+Cancels all currently outstanding sub requests for the main
+request.
+
+Completing the main request is the responsibility of the sub
+request completion routine after all outstanding sub requests have
+completed.
+
+Return Value:
+
+None
+
+--*/
+VOID large_transfer_cancel(IN PIRP irp, BOOLEAN releaseCancelSpinlock)
+{
+ PMAIN_REQUEST_CONTEXT mainRequestContext;
+ LIST_ENTRY cancelList;
+ PLIST_ENTRY subRequestEntry;
+ PSUB_REQUEST_CONTEXT subRequestContext;
+
+ // The main request irp context is overlaid on top of
+ // irp->Tail.Overlay.DriverContext. Get a pointer to it.
+ //
+ mainRequestContext = (PMAIN_REQUEST_CONTEXT)
+ irp->Tail.Overlay.DriverContext;
+
+ // The mainRequestContext SubRequestList cannot be simultaneously
+ // changed by anything else as long as the cancel spin lock is still
+ // held, but can be changed immediately by the completion routine
+ // after the cancel spin lock is released.
+ //
+ // Iterate over the mainRequestContext SubRequestList and add all of
+ // the currently outstanding sub requests to the list of sub
+ // requests to be cancelled.
+ //
+ InitializeListHead(&cancelList);
+
+ subRequestEntry = mainRequestContext->SubRequestList.Flink;
+
+ while (subRequestEntry != &mainRequestContext->SubRequestList)
+ {
+ subRequestContext = CONTAINING_RECORD(subRequestEntry,
+ SUB_REQUEST_CONTEXT,
+ ListEntry);
+
+ // Prevent the sub request from being freed as soon as the
+ // cancel spin lock is released by incrementing the reference
+ // count on the sub request.
+ //
+ InterlockedIncrement(&subRequestContext->ReferenceCount);
+
+ InsertTailList(&cancelList, &subRequestContext->CancelListEntry);
+
+ subRequestEntry = subRequestEntry->Flink;
+ }
+
+ USBDBG("[%s #%d] cancel-reason=%s\n",
+ mainRequestContext->dispTransfer,
+ mainRequestContext->sequenceID,
+ releaseCancelSpinlock?"User":"ShortTransfer");
+
+ if (releaseCancelSpinlock)
+ {
+
+ // The main read/write irp can be completed immediately after
+ // releasing the cancel spin lock. Do not access the main
+ // read/write irp or the mainRequestContext in any way beyond this
+ // point.
+ //
+ IoReleaseCancelSpinLock(irp->CancelIrql);
+ }
+
+ // Iterate over the list that was built of sub requests to cancel
+ // and cancel each sub request.
+ //
+ while (!IsListEmpty(&cancelList))
+ {
+ subRequestEntry = RemoveHeadList(&cancelList);
+
+ subRequestContext = CONTAINING_RECORD(subRequestEntry,
+ SUB_REQUEST_CONTEXT,
+ CancelListEntry);
+
+ if (!subRequestContext->SubIrp->Cancel)
+ {
+ IoCancelIrp(subRequestContext->SubIrp);
+ }
+
+ if (InterlockedDecrement(&subRequestContext->ReferenceCount) == 0)
+ {
+ // If the reference count is now zero then the completion
+ // routine already ran for the sub request but did not free
+ // the sub request so it can be freed now.
+ //
+ IoFreeIrp(subRequestContext->SubIrp);
+
+ ExFreePool(subRequestContext->SubUrb);
+
+ IoFreeMdl(subRequestContext->SubMdl);
+
+ ExFreePool(subRequestContext);
+ }
+ else
+ {
+ // The completion routine for the sub request has not yet
+ // executed and decremented the sub request reference count.
+ // Do not free the sub request here. It will be freed when
+ // the sub request completion routine executes.
+ }
+ }
+}
+
+static int get_iso_stagesize(int totalLength, int packetSize, int maxTransferSize)
+{
+ int stageSize;
+
+ if (totalLength > (packetSize * 255) || totalLength > maxTransferSize)
+ {
+ stageSize = packetSize * 255;
+ if (stageSize > maxTransferSize)
+ stageSize = maxTransferSize;
+
+ // stageSize = stageSize - (stageSize % packetSize);
+
+ }
+ else
+ {
+ stageSize = totalLength;
+ }
+
+ return stageSize;
+}
+
+static NTSTATUS allocate_suburb(USHORT urbFunction,
+ int stageSize,
+ int packetSize,
+ ULONG* nPackets,
+ PURB* subUrbRef)
+{
+ int urbSize;
+ //
+ // 3. Allocate a sub request urb.
+ //
+ if (urbFunction == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ *nPackets = (stageSize + packetSize - 1) / packetSize;
+ urbSize = GET_ISO_URB_SIZE(*nPackets);
+ }
+ else
+ {
+ *nPackets = 0;
+ urbSize = sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER);
+ }
+
+ *subUrbRef = (PURB)ExAllocatePool(NonPagedPool, urbSize);
+
+ if ((*subUrbRef) == NULL)
+ return STATUS_INSUFFICIENT_RESOURCES;
+
+ RtlZeroMemory(*subUrbRef, urbSize);
+
+ (*subUrbRef)->UrbHeader.Length = (USHORT)urbSize;
+ (*subUrbRef)->UrbHeader.Function = urbFunction;
+
+ return STATUS_SUCCESS;
+}
+
+static const char* GetPipeDisplayName(libusb_endpoint_t* endpoint)
+{
+ if (endpoint->address & 0x80)
+ return read_pipe_display_names[(endpoint->pipe_type & 3)];
+ else
+ return write_pipe_display_names[(endpoint->pipe_type & 3)];
+}
+
+void set_urb_transfer_flags(libusb_device_t* dev, PIRP irp, PURB subUrb,int transfer_flags, int isoLatency)
+{
+ if (subUrb->UrbHeader.Function == URB_FUNCTION_ISOCH_TRANSFER)
+ {
+ // only keep the direction bit
+ subUrb->UrbIsochronousTransfer.TransferFlags &= 1;
+
+ // If true, allow short tranfers.
+ if (!(transfer_flags & TRANSFER_FLAGS_SHORT_NOT_OK))
+ subUrb->UrbIsochronousTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
+
+ if (!(transfer_flags & TRANSFER_FLAGS_ISO_SET_START_FRAME))
+ subUrb->UrbIsochronousTransfer.TransferFlags |= USBD_START_ISO_TRANSFER_ASAP;
+ else
+ {
+ subUrb->UrbIsochronousTransfer.StartFrame = get_current_frame(dev, irp);
+ if (transfer_flags & TRANSFER_FLAGS_ISO_ADD_LATENCY)
+ subUrb->UrbIsochronousTransfer.StartFrame += isoLatency;
+ }
+ }
+
+ else if (subUrb->UrbHeader.Function == URB_FUNCTION_CONTROL_TRANSFER)
+ {
+ // TODO: large control transfers
+
+ // only keep the direction bit
+ subUrb->UrbControlTransfer.TransferFlags &= 1;
+ if (!(transfer_flags & TRANSFER_FLAGS_SHORT_NOT_OK))
+ subUrb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
+
+ }
+ else
+ {
+ // Default is bulk or interrupt.
+
+ // only keep the direction bit
+ subUrb->UrbBulkOrInterruptTransfer.TransferFlags &= 1;
+
+ // If true, allow short tranfers.
+ if (!(transfer_flags & TRANSFER_FLAGS_SHORT_NOT_OK))
+ subUrb->UrbBulkOrInterruptTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
+ }
+}
+
+NTSTATUS control_transfer(libusb_device_t* dev,
+ PIRP irp,
+ PMDL mdl,
+ int size,
+ int usbd_direction,
+ int *ret,
+ int timeout,
+ UCHAR request_type,
+ UCHAR request,
+ USHORT value,
+ USHORT index,
+ USHORT length)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ *ret = 0;
+
+ memset(&urb, 0, sizeof(struct _URB_CONTROL_TRANSFER));
+ urb.UrbControlTransfer.SetupPacket[0]=request_type;
+ urb.UrbControlTransfer.SetupPacket[1]=request;
+
+ urb.UrbControlTransfer.SetupPacket[2]=LBYTE(value);
+ urb.UrbControlTransfer.SetupPacket[3]=HBYTE(value);
+
+ urb.UrbControlTransfer.SetupPacket[4]=LBYTE(index);
+ urb.UrbControlTransfer.SetupPacket[5]=HBYTE(index);
+
+ urb.UrbControlTransfer.SetupPacket[6]=LBYTE(length);
+ urb.UrbControlTransfer.SetupPacket[7]=HBYTE(length);
+
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_TRANSFER);
+ urb.UrbHeader.Function=URB_FUNCTION_CONTROL_TRANSFER;
+ urb.UrbControlTransfer.TransferFlags=usbd_direction | USBD_DEFAULT_PIPE_TRANSFER | USBD_SHORT_TRANSFER_OK;
+ urb.UrbControlTransfer.TransferBufferLength = size;
+ urb.UrbControlTransfer.TransferBufferMDL = mdl;
+ urb.UrbControlTransfer.TransferBuffer = NULL;
+
+ USBMSG("[%s] timeout=%d request_type=%02Xh request=%02Xh value=%04Xh index=%04Xh length=%04Xh\n",
+ (usbd_direction==USBD_TRANSFER_DIRECTION_IN) ? "read" : "write",
+ timeout, request_type, request, value, index, length);
+
+ // no maximum timeout check for control request.
+ status = call_usbd_ex(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout, 0);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("request failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ }
+ else
+ {
+ *ret = urb.UrbControlTransfer.TransferBufferLength;
+ USBMSG("%d bytes transmitted\n",
+ urb.UrbControlTransfer.TransferBufferLength);
+ }
+
+ return status;
+}
diff --git a/usb/driver/usbd.def b/usb/driver/usbd.def
new file mode 100644
index 0000000..5c283bb
--- /dev/null
+++ b/usb/driver/usbd.def
@@ -0,0 +1,35 @@
+
+EXPORTS
+USBD_AllocateDeviceName
+USBD_CalculateUsbBandwidth
+USBD_CompleteRequest
+USBD_CreateConfigurationRequest
+USBD_CreateConfigurationRequestEx
+USBD_CreateDevice
+USBD_Debug_GetHeap
+USBD_Debug_LogEntry
+USBD_Debug_RetHeap
+USBD_Dispatch
+USBD_FreeDeviceMutex
+USBD_FreeDeviceName
+USBD_GetDeviceInformation
+USBD_GetInterfaceLength
+USBD_GetPdoRegistryParameter
+USBD_GetSuspendPowerState
+USBD_GetUSBDIVersion
+USBD_InitializeDevice
+USBD_MakePdoName
+USBD_ParseConfigurationDescriptor
+USBD_ParseConfigurationDescriptorEx
+USBD_ParseDescriptors
+USBD_QueryBusTime
+USBD_RegisterHcDeviceCapabilities
+USBD_RegisterHcFilter
+USBD_RegisterHostController
+USBD_RemoveDevice
+USBD_RestoreDevice
+USBD_SetSuspendPowerState
+USBD_WaitDeviceMutex
+USBD_CreateConfigurationRequestEx@8=_USBD_CreateConfigurationRequestEx@8
+USBD_ParseConfigurationDescriptorEx@28=_USBD_ParseConfigurationDescriptorEx@28
+USBD_ParseDescriptors@16=_USBD_ParseDescriptors@16
diff --git a/usb/driver/usbdlib_gcc.h b/usb/driver/usbdlib_gcc.h
new file mode 100644
index 0000000..5dec851
--- /dev/null
+++ b/usb/driver/usbdlib_gcc.h
@@ -0,0 +1,310 @@
+
+#ifndef __USBDLIB_H
+#define __USBDLIB_H
+
+#if __GNUC__ >=3
+#pragma GCC system_header
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#pragma pack(push,4)
+
+
+ typedef struct _USBD_INTERFACE_LIST_ENTRY
+ {
+ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
+ PUSBD_INTERFACE_INFORMATION Interface;
+ } USBD_INTERFACE_LIST_ENTRY, *PUSBD_INTERFACE_LIST_ENTRY;
+
+
+#define URB_STATUS(urb) ((urb)->UrbHeader.Status)
+
+#define GET_SELECT_CONFIGURATION_REQUEST_SIZE(totalInterfaces, totalPipes) \
+ (sizeof(struct _URB_SELECT_CONFIGURATION) \
+ + ((totalInterfaces - 1) * sizeof(USBD_INTERFACE_INFORMATION)) \
+ + ((totalPipes - 1) * sizeof(USBD_PIPE_INFORMATION)))
+
+#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes) \
+ (sizeof(struct _URB_SELECT_INTERFACE) \
+ + ((totalPipes - 1) * sizeof(USBD_PIPE_INFORMATION)))
+
+#define GET_USBD_INTERFACE_SIZE(numEndpoints) \
+ (sizeof(USBD_INTERFACE_INFORMATION) \
+ + (sizeof(USBD_PIPE_INFORMATION)*(numEndpoints)) \
+ - sizeof(USBD_PIPE_INFORMATION))
+
+#define GET_ISO_URB_SIZE(n) (sizeof(struct _URB_ISOCH_TRANSFER) \
+ + sizeof(USBD_ISO_PACKET_DESCRIPTOR) * n)
+
+
+#define UsbBuildInterruptOrBulkTransferRequest(urb, \
+ length, \
+ pipeHandle, \
+ transferBuffer, \
+ transferBufferMDL, \
+ transferBufferLength, \
+ transferFlags, \
+ link) { \
+ (urb)->UrbHeader.Function = \
+ URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER; \
+ (urb)->UrbHeader.Length = (length); \
+ (urb)->UrbBulkOrInterruptTransfer.PipeHandle = (pipeHandle); \
+ (urb)->UrbBulkOrInterruptTransfer.TransferBufferLength = \
+ (transferBufferLength); \
+ (urb)->UrbBulkOrInterruptTransfer.TransferBufferMDL = \
+ (transferBufferMDL); \
+ (urb)->UrbBulkOrInterruptTransfer.TransferBuffer = \
+ (transferBuffer); \
+ (urb)->UrbBulkOrInterruptTransfer.TransferFlags = \
+ (transferFlags); \
+ (urb)->UrbBulkOrInterruptTransfer.UrbLink = (link); }
+
+
+#define UsbBuildGetDescriptorRequest(urb, \
+ length, \
+ descriptorType, \
+ descriptorIndex, \
+ languageId, \
+ transferBuffer, \
+ transferBufferMDL, \
+ transferBufferLength, \
+ link) { \
+ (urb)->UrbHeader.Function = \
+ URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE; \
+ (urb)->UrbHeader.Length = (length); \
+ (urb)->UrbControlDescriptorRequest.TransferBufferLength = \
+ (transferBufferLength); \
+ (urb)->UrbControlDescriptorRequest.TransferBufferMDL = \
+ (transferBufferMDL); \
+ (urb)->UrbControlDescriptorRequest.TransferBuffer = \
+ (transferBuffer); \
+ (urb)->UrbControlDescriptorRequest.DescriptorType = \
+ (descriptorType); \
+ (urb)->UrbControlDescriptorRequest.Index = (descriptorIndex); \
+ (urb)->UrbControlDescriptorRequest.LanguageId = (languageId); \
+ (urb)->UrbControlDescriptorRequest.UrbLink = (link); }
+
+
+
+#define UsbBuildGetStatusRequest(urb, \
+ op, \
+ index, \
+ transferBuffer, \
+ transferBufferMDL, \
+ link) { \
+ (urb)->UrbHeader.Function = (op); \
+ (urb)->UrbHeader.Length = \
+ sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST); \
+ (urb)->UrbControlGetStatusRequest.TransferBufferLength = \
+ sizeof(USHORT); \
+ (urb)->UrbControlGetStatusRequest.TransferBufferMDL = \
+ (transferBufferMDL); \
+ (urb)->UrbControlGetStatusRequest.TransferBuffer = \
+ (transferBuffer); \
+ (urb)->UrbControlGetStatusRequest.Index = (index); \
+ (urb)->UrbControlGetStatusRequest.UrbLink = (link); }
+
+
+#define UsbBuildFeatureRequest(urb, \
+ op, \
+ featureSelector, \
+ index, \
+ link) { \
+ (urb)->UrbHeader.Function = (op); \
+ (urb)->UrbHeader.Length = \
+ sizeof(struct _URB_CONTROL_FEATURE_REQUEST); \
+ (urb)->UrbControlFeatureRequest.FeatureSelector = \
+ (featureSelector); \
+ (urb)->UrbControlFeatureRequest.Index = (index); \
+ (urb)->UrbControlFeatureRequest.UrbLink = (link); }
+
+
+
+#define UsbBuildSelectConfigurationRequest(urb, \
+ length, \
+ configurationDescriptor) { \
+ (urb)->UrbHeader.Function = URB_FUNCTION_SELECT_CONFIGURATION; \
+ (urb)->UrbHeader.Length = (length); \
+ (urb)->UrbSelectConfiguration.ConfigurationDescriptor = \
+ (configurationDescriptor); }
+
+#define UsbBuildSelectInterfaceRequest(urb, \
+ length, \
+ configurationHandle, \
+ interfaceNumber, \
+ alternateSetting) { \
+ (urb)->UrbHeader.Function = URB_FUNCTION_SELECT_INTERFACE; \
+ (urb)->UrbHeader.Length = (length); \
+ (urb)->UrbSelectInterface.Interface.AlternateSetting = \
+ (alternateSetting); \
+ (urb)->UrbSelectInterface.Interface.InterfaceNumber = \
+ (interfaceNumber); \
+ (urb)->UrbSelectInterface.ConfigurationHandle = \
+ (configurationHandle); }
+
+
+#define UsbBuildVendorRequest(urb, \
+ cmd, \
+ length, \
+ transferFlags, \
+ reservedbits, \
+ request, \
+ value, \
+ index, \
+ transferBuffer, \
+ transferBufferMDL, \
+ transferBufferLength, \
+ link) { \
+ (urb)->UrbHeader.Function = cmd; \
+ (urb)->UrbHeader.Length = (length); \
+ (urb)->UrbControlVendorClassRequest.TransferBufferLength = \
+ (transferBufferLength); \
+ (urb)->UrbControlVendorClassRequest.TransferBufferMDL = \
+ (transferBufferMDL); \
+ (urb)->UrbControlVendorClassRequest.TransferBuffer = \
+ (transferBuffer); \
+ (urb)->UrbControlVendorClassRequest.RequestTypeReservedBits = \
+ (reservedbits); \
+ (urb)->UrbControlVendorClassRequest.Request = (request); \
+ (urb)->UrbControlVendorClassRequest.Value = (value); \
+ (urb)->UrbControlVendorClassRequest.Index = (index); \
+ (urb)->UrbControlVendorClassRequest.TransferFlags = \
+ (transferFlags); \
+ (urb)->UrbControlVendorClassRequest.UrbLink = (link); }
+
+
+#define UsbBuildOsFeatureDescriptorRequest(urb, \
+ length, \
+ interface, \
+ index, \
+ transferBuffer, \
+ transferBufferMDL, \
+ transferBufferLength, \
+ link) { \
+ (urb)->UrbHeader.Function = \
+ URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR; \
+ (urb)->UrbHeader.Length = (length); \
+ (urb)->UrbOSFeatureDescriptorRequest.TransferBufferLength = \
+ (transferBufferLength); \
+ (urb)->UrbOSFeatureDescriptorRequest.TransferBufferMDL = \
+ (transferBufferMDL); \
+ (urb)->UrbOSFeatureDescriptorRequest.TransferBuffer = \
+ (transferBuffer); \
+ (urb)->UrbOSFeatureDescriptorRequest.InterfaceNumber = \
+ (interface); \
+ (urb)->UrbOSFeatureDescriptorRequest.MS_FeatureDescriptorIndex = \
+ (index); \
+ (urb)->UrbOSFeatureDescriptorRequest.UrbLink = (link); }
+
+
+ VOID
+ DDKAPI
+ USBD_Debug_LogEntry(
+ IN CHAR *Name,
+ IN ULONG Info1,
+ IN ULONG Info2,
+ IN ULONG Info3
+ );
+
+ VOID
+ DDKAPI
+ USBD_GetUSBDIVersion(
+ PUSBD_VERSION_INFORMATION VersionInformation
+ );
+
+
+ PUSB_INTERFACE_DESCRIPTOR
+ DDKAPI
+ USBD_ParseConfigurationDescriptor(
+ IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
+ IN UCHAR InterfaceNumber,
+ IN UCHAR AlternateSetting
+ );
+
+ PURB
+ DDKAPI
+ USBD_CreateConfigurationRequest(
+ IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
+ IN OUT PUSHORT Siz
+ );
+
+ PUSB_COMMON_DESCRIPTOR
+ DDKAPI
+ USBD_ParseDescriptors(
+ IN PVOID DescriptorBuffer,
+ IN ULONG TotalLength,
+ IN PVOID StartPosition,
+ IN LONG DescriptorType
+ );
+
+ PUSB_INTERFACE_DESCRIPTOR
+ DDKAPI
+ USBD_ParseConfigurationDescriptorEx(
+ IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
+ IN PVOID StartPosition,
+ IN LONG InterfaceNumber,
+ IN LONG AlternateSetting,
+ IN LONG InterfaceClass,
+ IN LONG InterfaceSubClass,
+ IN LONG InterfaceProtocol
+ );
+
+ PURB
+ DDKAPI
+ USBD_CreateConfigurationRequestEx(
+ IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
+ IN PUSBD_INTERFACE_LIST_ENTRY InterfaceList
+ );
+
+ ULONG
+ DDKAPI
+ USBD_GetInterfaceLength(
+ IN PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
+ IN PUCHAR BufferEnd
+ );
+
+ VOID
+ DDKAPI
+ USBD_RegisterHcFilter(
+ PDEVICE_OBJECT DeviceObject,
+ PDEVICE_OBJECT FilterDeviceObject
+ );
+
+ NTSTATUS
+ DDKAPI
+ USBD_GetPdoRegistryParameter(
+ IN PDEVICE_OBJECT PhysicalDeviceObject,
+ IN OUT PVOID Parameter,
+ IN ULONG ParameterLength,
+ IN PWCHAR KeyName,
+ IN ULONG KeyNameLength
+ );
+
+ NTSTATUS
+ DDKAPI
+ USBD_QueryBusTime(
+ IN PDEVICE_OBJECT RootHubPdo,
+ IN PULONG CurrentFrame
+ );
+
+ ULONG
+ DDKAPI
+ USBD_CalculateUsbBandwidth(
+ ULONG MaxPacketSize,
+ UCHAR EndpointType,
+ BOOLEAN LowSpeed
+ );
+
+
+#pragma pack(pop)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __USBDLIB_H */
+
diff --git a/usb/driver/vendor_request.c b/usb/driver/vendor_request.c
new file mode 100644
index 0000000..f3a898b
--- /dev/null
+++ b/usb/driver/vendor_request.c
@@ -0,0 +1,143 @@
+/* libusb-win32, Generic Windows USB Library
+ * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "libusb_driver.h"
+
+
+NTSTATUS vendor_class_request(libusb_device_t *dev,
+ int type, int recipient,
+ int request, int value, int index,
+ void *buffer, int size, int direction,
+ int *ret, int timeout)
+{
+ NTSTATUS status = STATUS_SUCCESS;
+ URB urb;
+
+ *ret = 0;
+
+ memset(&urb, 0, sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST));
+
+ switch (type)
+ {
+ case USB_TYPE_CLASS:
+ USBMSG0("type: class\n");
+ switch (recipient)
+ {
+ case USB_RECIP_DEVICE:
+ USBMSG0("recipient: device\n");
+ urb.UrbHeader.Function = URB_FUNCTION_CLASS_DEVICE;
+ break;
+ case USB_RECIP_INTERFACE:
+ USBMSG0("recipient: interface\n");
+ urb.UrbHeader.Function = URB_FUNCTION_CLASS_INTERFACE;
+ break;
+ case USB_RECIP_ENDPOINT:
+ USBMSG0("recipient: endpoint\n");
+ urb.UrbHeader.Function = URB_FUNCTION_CLASS_ENDPOINT;
+ break;
+ case USB_RECIP_OTHER:
+ USBMSG0("recipient: other\n");
+ urb.UrbHeader.Function = URB_FUNCTION_CLASS_OTHER;
+ break;
+ default:
+ USBERR0("invalid recipient\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+ break;
+ case USB_TYPE_VENDOR:
+ USBMSG0("type: vendor\n");
+ switch (recipient)
+ {
+ case USB_RECIP_DEVICE:
+ USBMSG0("recipient: device\n");
+ urb.UrbHeader.Function = URB_FUNCTION_VENDOR_DEVICE;
+ break;
+ case USB_RECIP_INTERFACE:
+ USBMSG0("recipient: interface\n");
+ urb.UrbHeader.Function = URB_FUNCTION_VENDOR_INTERFACE;
+ break;
+ case USB_RECIP_ENDPOINT:
+ USBMSG0("recipient: endpoint\n");
+ urb.UrbHeader.Function = URB_FUNCTION_VENDOR_ENDPOINT;
+ break;
+ case USB_RECIP_OTHER:
+ USBMSG0("recipient: other\n");
+ urb.UrbHeader.Function = URB_FUNCTION_VENDOR_OTHER;
+ break;
+ default:
+ // [Kevin Timmerman Patch]
+ USBMSG("recipient: reserved (0x%02x)\n", recipient);
+ urb.UrbHeader.Function = URB_FUNCTION_VENDOR_DEVICE;
+ urb.UrbControlVendorClassRequest.RequestTypeReservedBits = (UCHAR)recipient;
+ break;
+ /*
+ USBERR0("invalid recipient\n");
+ return STATUS_INVALID_PARAMETER;
+ */
+ }
+ break;
+ default:
+ USBERR0("invalid type\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ USBMSG("request: 0x%02x\n", request);
+ USBMSG("value: 0x%04x\n", value);
+ USBMSG("index: 0x%04x\n", index);
+ USBMSG("size: %d\n", size);
+
+ if (direction == USBD_TRANSFER_DIRECTION_IN)
+ {
+ USBMSG0("direction: in\n");
+ }
+ else
+ {
+ USBMSG0("direction: out\n");
+ }
+
+ USBMSG("timeout: %d\n", timeout);
+
+ urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
+ urb.UrbControlVendorClassRequest.TransferFlags
+ = direction | USBD_SHORT_TRANSFER_OK ;
+ urb.UrbControlVendorClassRequest.TransferBufferLength = size;
+ urb.UrbControlVendorClassRequest.TransferBufferMDL = NULL;
+ urb.UrbControlVendorClassRequest.TransferBuffer = buffer;
+ urb.UrbControlVendorClassRequest.Request = (UCHAR)request;
+ urb.UrbControlVendorClassRequest.Value = (USHORT)value;
+ urb.UrbControlVendorClassRequest.Index = (USHORT)index;
+
+ // no maximum timeout check for vendor request.
+ status = call_usbd_ex(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout, 0);
+
+ if (!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
+ {
+ USBERR("request failed: status: 0x%x, urb-status: 0x%x\n", status, urb.UrbHeader.Status);
+ }
+ else
+ {
+ if (direction == USBD_TRANSFER_DIRECTION_IN)
+ *ret = urb.UrbControlVendorClassRequest.TransferBufferLength;
+ USBMSG("%d bytes transmitted\n",
+ urb.UrbControlVendorClassRequest.TransferBufferLength);
+ }
+
+ return status;
+}
+
diff --git a/usb/install_kext.sh b/usb/install_kext.sh
new file mode 100644
index 0000000..22c181a
--- /dev/null
+++ b/usb/install_kext.sh
@@ -0,0 +1,6 @@
+# Install OS X HCFR codeless kernel extension
+echo "Installing OS X HCFR codeless kernel extension"
+sudo cp -R Argyll.kext /System/Library/Extensions/
+sudo chown -R root:wheel /System/Library/Extensions/Argyll.kext
+sudo kextload -t /System/Library/Extensions/Argyll.kext
+echo "Reboot to finish installation"