lxglxg
驱动牛犊
驱动牛犊
  • 注册日期2002-12-16
  • 最后登录2009-08-20
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望50点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:856回复:1

控制传输怎么就是不可以用?取描述符都可以

楼主#
更多 发布于:2003-04-17 15:07
我的callusbd的代码:

NTSTATUS CallUSBDI( IN PUSBKBD_DEVICE_EXTENSION dx, IN PVOID UrbEtc,
IN ULONG IoControlCode/*=IOCTL_INTERNAL_USB_SUBMIT_URB*/,
   IN ULONG Arg2/*=0*/)
{
IO_STATUS_BLOCK IoStatus;
KEVENT event;

// Initialise IRP completion event
KeInitializeEvent(&event, NotificationEvent, FALSE);

// Build Internal IOCTL IRP
PIRP Irp = IoBuildDeviceIoControlRequest(
IoControlCode,
dx->NextStackDevice,
NULL,
0, // Input buffer
NULL,
0, // Output buffer
TRUE,
&event,
&IoStatus);

// Get IRP stack location for next driver down (already set up)
PIO_STACK_LOCATION NextIrpStack = IoGetNextIrpStackLocation(Irp);

// Store pointer to the URB etc
NextIrpStack->Parameters.Others.Argument1 = UrbEtc;
NextIrpStack->Parameters.Others.Argument2 = (PVOID)Arg2;

// Call the driver and wait for completion if necessary
NTSTATUS status = IoCallDriver( dx->NextStackDevice, Irp);

if (status == STATUS_PENDING)
{
DebugPrintMsg(\"CallUSBDI: waiting for URB completion\");

status = KeWaitForSingleObject( &event, Suspended, KernelMode, FALSE, NULL);
}

return status;
}
lxglxg
驱动牛犊
驱动牛犊
  • 注册日期2002-12-16
  • 最后登录2009-08-20
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望50点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-04-17 15:09
调用写例程如下:

//2003年4月,by xigang.li
NTSTATUS UsbWriteBytes( IN PUSBKBD_DEVICE_EXTENSION dx, IN PIRP Irp,IN PIO_STACK_LOCATION Pio_stack)
{
// PIO_BLOCK ioBlock;
PVOID                           ioBuffer;

//测试
UCHAR     ttt[10];

ttt[0]=0;

// Allocate memory for URB
USHORT UrbSize = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
PURB urb = (PURB)ExAllocatePool(NonPagedPool, UrbSize);

if( urb==NULL)
{
DebugPrintMsg(\"No URB memory\");
return STATUS_INSUFFICIENT_RESOURCES;
}

ioBuffer = Irp->AssociatedIrp.SystemBuffer;
// ioBlock = (PIO_BLOCK) ioBuffer;
    
/* VOID
    UsbBuildVendorRequest(
    IN PURB Urb,
    IN USHORT Function,
    IN USHORT Length,
    IN ULONG TransferFlags,
    IN UCHAR ReservedBits,
    IN UCHAR Request,
    IN USHORT Value,
    IN USHORT Index,
    IN PVOID TransferBuffer    OPTIONAL,
    IN PMDL TransferBufferMDL    OPTIONAL,
    IN ULONG TransferBufferLength,
    IN PURB Link    OPTIONAL,
    );
*/
// Build URB to send Class interface control request on Default pipe
UsbBuildVendorRequest(
urb,
URB_FUNCTION_VENDOR_DEVICE,
UrbSize,
USBD_TRANSFER_DIRECTION_OUT, // Direction out
0, // Reserved bits
0, // Request
0, // Output report type, Report id zero
0, // interface index
ttt,
NULL,
1,//Pio_stack->Parameters.DeviceIoControl.InputBufferLength, // Output data
NULL);

NTSTATUS status = CallUSBDI( dx, urb);

// Check statuses
if( !NT_SUCCESS(status) || !USBD_SUCCESS( urb->UrbHeader.Status))
{
DebugPrint(\"status %x URB status %x\", status, urb->UrbHeader.Status);
status = STATUS_UNSUCCESSFUL;
}

ExFreePool(urb);

return status;
}
游客

返回顶部