// kusb.cpp - functions for USB classes
//=============================================================================
//
// Compuware Corporation
// NuMega Lab
// 9 Townsend West
// Nashua, NH 03063 USA
//
// Copyright (c) 2004 Compuware Corporation. All Rights Reserved.
// Unpublished - rights reserved under the Copyright laws of the
// United States.
//
// U.S. GOVERNMENT RIGHTS-Use, duplication, or disclosure by the
// U.S. Government is subject to restrictions as set forth in
// Compuware Corporation license agreement and as provided in
// DFARS 227.7202-1(a) and 227.7202-3(a) (1995),
// DFARS 252.227-7013(c)(1)(ii)(OCT 1988), FAR 12.212(a) (1995),
// FAR 52.227-19, or FAR 52.227-14 (ALT III), as applicable.
// Compuware Corporation.
//
// This product contains confidential information and trade secrets
// of Compuware Corporation. Use, disclosure, or reproduction is
// prohibited without the prior express written permission of Compuware
// Corporation.
//
//=============================================================================
#include <vdw.h>
#if _WDM_
#include <kusb.h>
////////////////////////////////////////////////////////////////////
// KUsbLowerDevice::SubmitUrb - this form builds a new IRP
//
// Parameters
// pUrb Pointer to URB to submit
// CompletionRoutine IRP completion routine, or NULL
// Context IRP completion context
// mSecTimeOut Timeout period for synchronous requests
//
// If the caller provides a completion routine, that completion routine
// must NOT deallocate the IRP that this function allocates to submit
// the URB. The return value of the completion routine is ignored.
//
NTSTATUS KUsbLowerDevice::SubmitUrb(
PURB pUrb,
PIO_COMPLETION_ROUTINE CompletionRoutine,
PVOID Context,
ULONG mSecTimeOut
)
{
NTSTATUS status;
// Allocate and initialize the IRP for IOCTL request
KIrp I = KIrp::Allocate(StackRequirement());
if (I.IsNull())
{
if ( CompletionRoutine )
{
IRP irp;
memset(&irp, 0, sizeof(IRP));
irp.IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
CompletionRoutine(PDO(), &irp, Context);
}
return STATUS_INSUFFICIENT_RESOURCES;
}
// Setup Irp
I.MajorFunction(NEXT) = IRP_MJ_INTERNAL_DEVICE_CONTROL;
I.IoctlCode(NEXT) = IOCTL_INTERNAL_USB_SUBMIT_URB;
// Put the address of the URB in the IRP
I.Urb(NEXT) = pUrb;
// If completion routine is not NULL we will be calling asynchronously,
// otherwise we will be calling synchronously.
if (CompletionRoutine != NULL)
{
// Allocate context structure, which will hold the user's completion routine
AsyncCompleteSubmitUrbContext_t* pCtx =
new (NonPagedPool) AsyncCompleteSubmitUrbContext_t;
if (pCtx == NULL)
{
I.Status()=STATUS_INSUFFICIENT_RESOURCES;
CompletionRoutine(PDO(), I, Context);
I.Deallocate(I);
BOUNDS_CHECKER(OUT_OF_MEMORY_ERROR, (this, "SubmitUrb", sizeof(AsyncCompleteSubmitUrbContext_t)));
return STATUS_INSUFFICIENT_RESOURCES;
}
// Initialize context structure with user's completion routine and context
pCtx->CompletionRoutine = CompletionRoutine;
pCtx->Context = Context;
#if DBG
pCtx->pLD = this;
pCtx->pUrb = pUrb;
#endif
I.SetCompletionRoutine(AsyncCompleteSubmitUrb, pCtx);
// Pass the IRP/URB to USBD
BOUNDS_CHECKER(SUBMIT_URB, (this, pUrb, PIRP(I)));
status = Call(I);
}
else // synchronous case
{
// We will wait on an event, so we must be at PASSIVE_LEVEL
ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
// Careful not call this ctor if CompletionRoutine is not NULL -
// because caller may be at DISPATCH_LEVEL, and this ctor is in
// pageable code
KEvent Synch(NotificationEvent, FALSE);
// Allocate and initialize context structure on stack
SyncCompleteSubmitUrbContext_t Ctx;
Ctx.pEvent = &Synch;
#if DBG
Ctx.pLD = this;
Ctx.pUrb = pUrb;
#endif
// Set up completion routine
I.SetCompletionRoutine(SyncCompleteSubmitUrb, &Ctx);
// Pass the IRP/URB to USBD
BOUNDS_CHECKER(SUBMIT_URB, (this, pUrb, PIRP(I)));
status = Call(I);
if ( status == STATUS_PENDING )
{
// calculate the time out interval
ULONGLONG TimeOut100nSec;
PLARGE_INTEGER pTimeOut;
if ( mSecTimeOut != 0 )
{
// the input value may be negative or positive. Make sure
// it's positive, and then convert to negative afterwards.
LONG mSecTimeOutSigned = LONG(mSecTimeOut);
if (mSecTimeOutSigned < 0)
mSecTimeOutSigned = -mSecTimeOutSigned;
mSecTimeOut = ULONG(mSecTimeOutSigned);
// Calculate wait as 100ns intervals. Negative is relative
TimeOut100nSec = mSecTimeOut;
TimeOut100nSec *= -10000; // convert units
pTimeOut = PLARGE_INTEGER(&TimeOut100nSec);
}
else
pTimeOut = NULL;
// Wait for the event to be signaled, or timeout if specified
status = Synch.Wait(KernelMode, FALSE, pTimeOut);
if (status != STATUS_SUCCESS)
{
BOUNDS_CHECKER(URB_TIMEOUT, (this, pUrb));
IoCancelIrp(I);
// Cancelling the IRP should result in a speedy completion. We have
// to wait because we don't want the completion routine to run
// after the event (Synch) has gone out of scope.
Synch.Wait(KernelMode, FALSE, NULL);
}
else
status = Ctx.Status;
} // end STATUS_PENDING returned clause
BOUNDS_CHECKER(COMPLETED_URB, (this, pUrb, PIRP(I), status));
// Deallocate Irp
I.Deallocate(I);
} // End synchronous case
return status;
}
////////////////////////////////////////////////////////////////////
// KUsbLowerDevice::SyncCompleteSubmitUrb
//
// This completion routine signals an event to allow execution to
// resume in the case of a synchronous SubmitUrb.
//
// Parameters
// DeviceObject pointer to device object
// pIrp Irp that just completed
// Context Context structure for Irp to be completed
//
NTSTATUS KUsbLowerDevice::SyncCompleteSubmitUrb(
PDEVICE_OBJECT DeviceObject,
PIRP pIrp,
PVOID Context
)
{
SyncCompleteSubmitUrbContext_t* pCtx =
(SyncCompleteSubmitUrbContext_t*)Context;
BOUNDS_CHECKER(COMPLETED_URB, (pCtx->pLD, pCtx->pUrb, pIrp, pIrp->IoStatus.Status));
// load up the context structure
pCtx->Status = pIrp->IoStatus.Status;
// signal the event to release waiting thread
(pCtx->pEvent)->Set();
return STATUS_MORE_PROCESSING_REQUIRED;
UNREFERENCED_PARAMETER(DeviceObject);
}
////////////////////////////////////////////////////////////////////
// KUsbLowerDevice::AsyncCompleteSubmitUrb
//
// This completion routine calls the user's completion routine,
// which is stored in the context structure. It then deallocates
// the context structure and the Irp that was allocated by the
// SubmitUrb() method.
//
// Parameters
// DeviceObject pointer to device object
// Irp Irp that just completed
// Context Context structure for Irp to be completed
//
NTSTATUS
KUsbLowerDevice::AsyncCompleteSubmitUrb(
PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context
)
{
AsyncCompleteSubmitUrbContext_t* pCtx =
(AsyncCompleteSubmitUrbContext_t*)Context;
BOUNDS_CHECKER(COMPLETED_URB, (pCtx->pLD, pCtx->pUrb, Irp, Irp->IoStatus.Status));
// Call the completion routine stored in the context structure.
// In this case, the user originally supplied a completion routine and
// context but no Irp. The status returned by the completion routine is
// useless since the Irp was allocated by SubmitUrb() and is
// about to be deallocated. The completion routine must propagate
// any result of the Urb in some (user defined) manner other than
// its return value.
pCtx->CompletionRoutine( DeviceObject, Irp, pCtx->Context );
// Deallocate Irp
KIrp::Deallocate(KIrp(Irp));
// Deallocate the context structure
delete pCtx;
// Return STATUS_MORE_PROCESSING_REQUIRED so the IO subsystem doesn't
// try to deal
没有合适的资源?快使用搜索试试~ 我知道了~
DriverStudio 3.2 Code For VisualStudio 2005
共5个文件
cpp:3个
h:2个
4星 · 超过85%的资源 需积分: 9 248 下载量 94 浏览量
2008-01-18
19:38:08
上传
评论
收藏 26KB RAR 举报
温馨提示
DriverStudio 3.2 For VisualStudio 2005 程序代码补丁<br><br>解决DriverStudio 3.2的库代码在VisualStudio 2005中无法编译通过的问题。<br><br>由于VC++ 2005编译器更加符合C++标准,所以DriverStudio的DriverWorks库的代码不能在VC++ 2005下成功编译,这主要是由于DriverWorks两方面的程序设计缺陷:一是循环变量生命期问题,一是函数返回值的缺省类型问题。修改后DriverWorks可以在VC++ 2005 SP1下成功编译。<br>
资源推荐
资源详情
资源评论
收起资源包目录
PatchedDriverStudioFiles.rar (5个子文件)
suballoc.cpp 14KB
kustring.cpp 9KB
kaddress.h 27KB
kusb.cpp 90KB
kustring.h 6KB
共 5 条
- 1
资源评论
- zhjianwei2012-07-21可以用,不过现在不用了,呵呵
- wangjin5202013-05-30可以使用,多谢楼主
- jianggc232013-04-17可以,不过对我没多大用,谢谢!
gongbingchen
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功