กก |
Project Maintainer: Yu Lu |
![]() |
|
|
|
|
|
|
|
|
URB urb ;
pch = (PUCHAR) ioBuffer;
UsbBuildInterruptOrBulkTransferRequest(&urb,
           sizeof( _URB_BULK_OR_INTERRUPT_TRANSFER),
           pdx->Pipe1,
           pch,
           NULL,
           cbin,
           USBD_SHORT_TRANSFER_OK,
           NULL);
          
here pdx->Pipe1
indicates the endpoint number.
pch
is a pointer pointing to the address of the buffer we want to send to hardware.
For the meaning of other arguments, please read the reference.
DeviceIoControl
to perform such an operation.
I don't provide function call like ReadFile()
or WriteFile()
because I think
DeviceIoControl()
is enough for this project.
For example, I define I/O control code like this ( from ioctls.h):
#define IOCTL_USBGPS_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
The processing of this I/O control code is given below in Control.cpp:
NTSTATUS DispatchControl(PDEVICE_OBJECT fdo, PIRP Irp){
           ...
           ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
          
           switch (code)
           { // process request
           ...
          
           case IOCTL_USBGPS_BULK_WRITE: // code == 0x803
           { // IOCTL_USBGPS_USBGPS_WRITE
           if(ioBuffer && cbin >= 0 && cbout >= 0)
           {
           URB urb ;
          
           pch = (PUCHAR) ioBuffer;
           UsbBuildInterruptOrBulkTransferRequest(&urb,
           sizeof( _URB_BULK_OR_INTERRUPT_TRANSFER),
           pdx->Pipe1,
           pch,
           NULL,
           cbin,
           USBD_SHORT_TRANSFER_OK,
           NULL);
           status = SendAwaitUrb(fdo,&urb);
          
           if(NT_SUCCESS(status))
           info = cbin;
           else
           info = 0;
          
           // TODO insert code here to handle this IOCTL, which uses METHOD_BUFFERED
           }
           break;
           }
           ...
           }