Windows Driver Kit: WDM Devices
USB ISO Transfer Driver Sample
Description
The Isousb sample driver is a function driver that is based on the Microsoft Windows Driver Model (WDM). This sample driver supports Plug and Play(PnP), power management, Windows Management Instrumentation (WMI), and the Selective Suspend (SS) features.
This sample is based on the selSusp sample in the Windows Driver Kit (WDK). For more information about how to handle PnP, power management, WMI, and SS features and implementations, see the selSusp sample and the WDK documentation.
The USB device that this sample uses is a generic Intel I82930 USB evaluation board that is programmed with a simple loopback test that uses a 64KB circular buffer. The code in the sample is not specific to this controller chip.
Theory of Operation
This section describes the driver routines that allow a user-mode application to perform isochronous read and write operations or stream transfers. You can perform the isochronous read/write by opening a handle to the device and using the standard Microsoft Win32 Read/Write command. The stream transfer is a continuous streaming of isochronous IN data that you can explicitly initiate or stop by using the driver-supported I/O control codes (IOCTLs) from the user application.
Isousb Read/Write Operations and Stream Transfers
| Requests | Dispatch routines |
| IRP_MJ_CREATE | IsoUsb_DispatchCreate() |
| IRP_MJ_CLOSE | IsoUsb_DispatchClose() |
| IRP_MJ_READ | IsoUsb_DispatchReadWrite() |
| IRP_MJ_WRITE | IsoUsb_DispatchReadWrite() |
| IOCTL_ISOUSB_START_ISO_STREAM | IsoUsb_StartIsoStream() |
| IOCTL_ISOUSB_STOP_ISO_STREAM | IsoUsb_StopIsoStream() |
Notes:
- The IsoUsb_DispatchCreate() routine allows a user-mode application to open handles to the device or to the pipe.
- Pipe # 5 and Pipe # 6 correspond to the Isoch IN and Isoch OUT respectively. The driver does not define and use a specific pipe number for read and write operations.
- The IsoUsb_DispatchClose() routine closes the handles to the pipe or the device.
Stream Transfers
The following driver routines implement stream transfers:
- IsoUsb_StartIsoStream()
- IsoUsb_StopIsoStream()
- IsoUsb_InitializeStreamUrb()
- IsoUsb_IsoIrp_Complete()
- IsoUsb_ProcessTransfer()
- IsoUsb_StreamObjectCleanup()
- A stream transfer can be initiated from a device control request and consists of data continuously streaming IN.
- A stream transfer circulates ISOUSB_MAX_IRP number of requests at any time.
- A stream transfer stops when it receives an explicit device control request or when the user-mode application terminates or stops.
- A stream transfer context information is maintained in the ISOUSB_STREAM_OBJECT structure, which is saved in the FileObject pointer.
- There are ISOUSB_MAX_IRP number of Irp/Urb pairs that are re-circulated and used for transfers. The ISOUSB_TRANSFER_OBJECT structure maintains context information for each of the Irp/Urb pair.
- To stop or abort a transfer, use the IsoUsb_StreamObjectCleanup routine to cancel the re-circulating Irps and waits on an event that the completion routine triggers for the last cancelled Irp. Thereafter, IsoUsb_StreamObjectCleanup releases memory allocation for the stream object and the transfer objects.
- Because the driver saves the stream object structure in the FileObject pointer, the driver is multi-threaded safe across applications, but with a major caveat. User applications should not use the same handle to initiate multiple stream transfers. However, you can easily support this functionality by forming a list of stream-object structures in FileObject (rather than storing a single stream object structure).
Isochronous Read/Write Operations
- The Isoch read/write transfer requires an Irp/Urb pair with the function code of URB_FUNCTION_ISOCH_TRANSFER.
- The upper bound on the number of packets that can be transferred with each of the Irp/Urb pairs is given as 255. You should create multiple subsidiary Irp/Urb pairs to transfer the requested length of data.
- The IsoUsb_DispatchReadWrite routine creates the required number of subsidiary Irp/Urb pairs, initializes them, and sets a completion routine (IsoUsb_SinglePairComplete) for each of the Irps in the pair.
- The dispatch routine sets a cancellation routine (IsoUsb_CancelReadWrite) for the original read/write Irp and appends the Irp.
- The dispatch routine now passes the subsidiary Irp/Urb pair down the stack.
- You can abort the read/write transfers at any point. The driver is responsible for canceling or freeing the Irp/Urb pairs, releasing all of the resources, and terminating gracefully.
- The IsoUsb_DispatchReadWrite, IsoUsb_SinglePairComplete and IsoUsb_CancelReadWrite routines include descriptive comments to help you understand how the driver works.
- Because the driver does not save the read/write context information in the driver, but passes it to the completion routine, the driver is multithreaded safe.
High-Speed Isochronous Read/Write Operations
- The WDK sample driver (Isousb) has been updated for high-speed isochronous transfers.
- There are two significant differences between high-speed and full-speed transfers:
- The upper bound on the number of packets that can be transferred with each Irp/Urb pair is 1024.
- The number of packets that are sent down with each Irp/Urb pair should be a multiple of 8.
- PerformHighSpeedIsochTransfer gives one implementation of creating packets that are multiples of 8.
Known Bugs
- When you use the Intel I82930 evaluation board to perform loopback transfers with OUT transfers that are not in multiples of 8, the IN pipe is stalled. A firmware error causes this stall. You cannot solve this problem by resetting the pipe. Instead, you must reconfigure the device or driver unload and load.
RwIso.exe
RwIso.exe is a console application that initiates isochronous transfer and obtains a dump of information on the device's I/O endpoints. The application also demonstrates how to use GUID-based device names and pipe names that the operating system generates by using the SetupDiXxx user-mode APIs.
Implementation and Design
Use the Isousb sample as a template for designing an isochronous USB function driver. Content will be published Building the Sample
The Isousb sample builds two binaries: RwIso.exe and Isousb.sys. Installation
General
The Isousb sample demonstrates basic isochronous I/O under WDM with the Intel i82930 USB controller.
For more information about basic architectural issues and Plug and Play and power management IRP handling, see the document for the corresponding bulk I/O sample, "BulkUsb.Doc," because it is basically the same as in this sample.
Rwiso.exe is the console test application that accompanies Isousb.sys, and it operates similarly to Rwbulk.Exe, which is the console test application for Bulkusb.sys.
Installing Isousb.sys
- Make an OEM installation disk or equivalent installation source directory for Isousb.sys by copying Isousb.sys and Isousb.inf into the disk (or directory). You can find Isousb.inf in the WDK's IsoUsb\Sys source directory.
- Make sure that your device has been programmed with the device VID/PID in the Isousb.inf file. If not, edit the device VID, PID, and description text to match your test board and device.
- Do one of the following, depending on which operating system you are using:
- On Windows 2000:
- Plug in your device. The Found New Hardware Wizard dialog box will appear with the subheading "Install Hardware Device Drivers".
- Click the Search for a suitable driver for your device (Recommended) button, and then click Next.
- Specify your installation source floppy disk or directory, and then click Next.
- On the next screen, when you see the full source path to Isousb.inf, click Next button.
- In the Found New Hardware Wizard dialog box that displays "Hardware Install: The hardware installation is complete", click Finish button. You should now have a copy of Isousb.sys in your \System32\Drivers directory, Isousb.inf in your \Winnt\Inf directory, and a newly-created Isoisb.pnf file, which is a precompiled setup information file that Windows 2000 creates.
- If the Found New Hardware Wizard dialog box in the preceding step indicates an error, or if the operating system indicates that you must restart your computer to finish installing the device, an error has occurred. Check your INF file, Install directory, or driver code and follow the instructions in the following Simulating a First-Time Install section, and start the installation again.
- On Windows 98:
- Plug in the device. The Add New Hardware Wizard dialog box will appear and inform you that "This wizard searches for new drivers for: [your deviceName as programmed into your board's hardware]."
- Click Next.
- Click the Search for the best driver for your device (Recommended) button, and then click Next.
- Specify your installation source floppy disk or directory, and then Next.
- On the next screen, when you see the full source path to Isousb.inf under Location of Driver, click Next. The Building Driver Information Database message box appears, and if the installation and loading of the driver succeed, an informative message box appears and says "Windows has finished installing the software that your new hardware device requires."
- Click Finish.
- If the final Add New Hardware Wizard dialog box indicates any error, or if the operating system says that you must restart your computer to finish installing the device, an error has occurred. Check your INF file, Install directory, or driver code and follow the instructions in the following Simulating a First-Time Install section, and start over.
Updating the Driver
To install a new version of your driver after a successful initial installation, simply replace the binary in the \System32\Drivers directory. If the initial or last installation failed for any reason, complete the following instructions.
Simulating a First-Time Install
If you want to test modifications to an INF file or installation program, or if your first installation failed for any reason and you need to complete a new "first-time" driver installation without reinstalling Windows 2000 or Windows 98, do the following:
- Delete Isousb.inf from the \Windows\Inf or \Winnt\Inf directory. On Windows NT, also delete Isousb.pnf from the \Winnt\Inf directory.
- Delete Isousb.sys from the \System32\Drivers directory.
- By using RegEdt32 on Windows 2000, or RegEdit on Windows 98, ,delete the following information from the registry, depending on which operating system you are using:
For Windows 2000, delete the following registry key:
\LocalMachine\System\CurrentControlSet\Enum\USB\[the key with your deviceId/PID]
On Windows 2000, you must restart your computer before your reinstall the driver; this restart is not necessary on Windows 98.
- For Windows 98, delete the following registry key:
\LocalMachine\System\Enum\USB\[the key with your device ID/PID]
For the Isousb sample, this registry key would be:
\LocalMachine\System\Enum\USB\VID_045E&PID_930A
Isousb.inf is in the Sys subdirectory and allows you to set registry overrides for "DebugLevel" debug verbosity level. For this level, 0 indicates no debug output, 1 is the default, and higher values indicate more verbose.
End User
Content will be published Alternate Installation
Content will be published Testing
Content will be published Code Tour
File Manifest
| File | Description |
| Isodev.c | Contains dispatch routines for Create, Close, and Selective Suspend |
| Isodev.h | Definitions for functions that are contained in Isodev.c |
| Isopnp.c | Handler functions for Plug and Play (PnP) |
| Isopnp.h | Definitions for functions that are contained in Isopnp.c |
| Isopwr.c | Handler functions for WDM Power requests |
| Isopwr.h | Definitions for functions that are contained in Isopwr.c |
| Isorwr.c | Initializes and submits ISO transfers to the bus driver |
| Isorwr.h | Definitions for functions that are contained in Isorwr.c |
| Isostrm.c | Initializes and maintains a sample ISO data transfer stream |
| Isostrm.h | Definitions for functions that are contained in Isostrm.c |
| Isousb.c | Contains DriverEntry and core initialization functions |
| Isousb.h | Primary definitions for the Isousb driver |
| Isousb.inf | Sample INF file to install the driver |
| Isousb.mof | Definitions of WMI data structures |
| Isousb.rc | Resource file |
| Isousr.h | Contains definitions for user-mode IOCTL interfaces |
| Isowmi.c | Dispatch and handler routines for SYSTEM_CONTROL requests |
| Isowmi.h | Definitions for functions that are contained in Isowmi.c |
| Sources | Build file |
Build machine: CAPEBUILD