supcent
驱动牛犊
驱动牛犊
  • 注册日期2003-12-18
  • 最后登录2005-11-27
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1058回复:0

创建新的IRP问题,帮忙看看?

楼主#
更多 发布于:2004-02-16 17:56
NTSTATUS NewIrp(PDEVICE_OBJECT fido, PIRP Irp)
{
#if DBG
KdPrint(("NewIrp  ======================>\n"));
#endif
    NTSTATUS status=STATUS_SUCCESS;
USHORT USBfunction;
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(pdx->NowIrp);

PURB urb = (PURB)stack->Parameters.Others.Argument1;
USBfunction = urb->UrbHeader.Function;
USBD_PIPE_HANDLE  pipehandle=urb->UrbBulkOrInterruptTransfer.PipeHandle;
ULONG IoControlCode = stack->Parameters.DeviceIoControl.IoControlCode;
USHORT  UrbSize = sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER);

pdx->pNewUrb  = (PURB)ExAllocatePool(NonPagedPool, UrbSize);
if( pdx->pNewUrb==NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
USHORT  IoBufferLen = 10;
PVOID   pIoBuffer = ExAllocatePool(NonPagedPool, IoBufferLen);
if( pIoBuffer==NULL)
{
ExFreePool(pdx->pNewUrb);  
return STATUS_INSUFFICIENT_RESOURCES;
}
pdx->pBuffer = pIoBuffer;
//----
    KEVENT event;
    KeInitializeEvent(&event, NotificationEvent, FALSE);
//----

UsbBuildInterruptOrBulkTransferRequest
(pdx->pNewUrb,UrbSize,
   pipehandle,
pIoBuffer,NULL,7,
USBD_TRANSFER_DIRECTION_IN,NULL);

IO_STATUS_BLOCK IoStatus;
//
PIRP NewIrp = IoBuildDeviceIoControlRequest(
IOCTL_INTERNAL_USB_SUBMIT_URB, pdx->LowerDeviceObject,
NULL,0, // Input buffer
NULL, 0, // Output buffer
//        pIoBuffer,8,
//        pIoBuffer,8,
TRUE,&event, &IoStatus);
// TRUE, &event, &IoStatus);
if(NewIrp==NULL){
ExFreePool(pdx->pNewUrb);  
ExFreePool(pIoBuffer);
return STATUS_INSUFFICIENT_RESOURCES;
}
//
    PIO_STACK_LOCATION NextIrpStack = IoGetNextIrpStackLocation(Irp);///pdx->NowIrp);
    NextIrpStack->Parameters.Others.Argument1 = pdx->pNewUrb;
NextIrpStack->Parameters.Others.Argument2 = NULL;//(PVOID)Arg2;
// pdx->IsOnNewIrp=TRUE;
status = IoCallDriver( pdx->LowerDeviceObject, NewIrp);
if (status == STATUS_PENDING)
{
LARGE_INTEGER timeout;
timeout.QuadPart = -10000 ;//   *dx->UsbTimeout;
status = KeWaitForSingleObject(
&event,
Suspended,
KernelMode,
FALSE, &timeout);
// Method 2 : NULL);
if (status == STATUS_TIMEOUT)
{
IoCancelIrp(NewIrp);
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
}
KeClearEvent(&event);
}
else
{
IoStatus.Status = status;
////===========================
//!NT_SUCCESS(status) || !USBD_SUCCESS( Newurb->UrbHeader.Status)
if( !NT_SUCCESS(status)|| !USBD_SUCCESS( pdx->pNewUrb->UrbHeader.Status) )
{
KdPrint(("status %x URB status %x", status, pdx->pNewUrb->UrbHeader.Status));
status = STATUS_UNSUCCESSFUL;
   //pdx->IsMouseStart=FALSE;
}
        else{
// Give up if count of bytes transferred was not 8
if( pdx->pNewUrb->UrbBulkOrInterruptTransfer.TransferBufferLength==7){

unsigned char* ReportBuffer = (unsigned char*)pdx->pNewUrb->UrbBulkOrInterruptTransfer.TransferBuffer;
pdx->IsMouseStart=FALSE;
KdPrint(("<------------------------------->"));
memset(pdx->globedata,0x0,8);
RtlCopyMemory( pdx->globedata,ReportBuffer,7);  
if(g_Flag){
//g_Flag1=g_Flag;
IsGo=TRUE;
KeyMap(pdx);
}else{
   pdx->IsMouseStart=FALSE;
}
if(pdx->IsMouseStart==FALSE){
pdx->g_DpcCount=500;
}
}
}
/////========================================
}

status = IoStatus.Status;
/// pdx->IsOnNewIrp=FALSE;
   ExFreePool(pIoBuffer);
ExFreePool(pdx->pNewUrb);
pdx->pNewUrb=NULL;
pdx->pBuffer=NULL;
#if DBG
    KdPrint(("NewIrp  return======================>\n"));
#endif
   return status;

}
游客

返回顶部