The Bulkusb driver
The USB device used for this sample is a generic Intel I82930 USB evaluation board programmed with a simple loopback test using a 64 KB circular buffer. None of the code in the sample is specific to this controller chip.
The bulkusb.sys is a minidriver that transfers asynchronous bulk data packets to and from this board. The USB Request Block (URBs) allow an abstracted chip-independent transfer to and from the core USB stack. The sample also consists of a console application
The section below describes the driver routines that allow a user-mode application to perform bulk reads and writes.
Bulkusb Reads/Writes
Requests | Dispatch Routines |
IRP_MJ_CREATE | BulkUsb_DispatchCreate() |
IRP_MJ_CLOSE | BulkUsb_DispatchClose() |
IRP_MJ_READ | BulkUsb_DispatchReadWrite() |
IRP_MJ_WRITE | BulkUsb_DispatchReadWrite() |
Notes
The BulkUsb_DispatchReadWrite, transforms the original read/write request into an internal device control request, creates and initializes an URB for this request and sets a completion routine for this request (BulkUsb_ReadWriteCompletion). The amount of data transferred is limited by the BULKUSB_MAX_TRANSFER_SIZE (64KB circular buffer limitation). For additional data transfers, the request (Irp/Urb pair) is re-initialized and re-submitted in the completion routine.
Since the driver does not save the read-write context information anywhere in the driver, but passes it along to the completion routine, it is multi-threaded safe.
Please refer the detailed inline comments in the bulkusb driver for implementation details.
The rwbulk.exe console application is used to initiate bulk transfers and obtain 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 generated by the operating system using the SetupDiXXX user-mode APIs.