双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

请教USB驱动开发

kondykuang kondykuang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
鉴于使用DriverStudio开发WDM驱动地便捷。我使用DriverWorks生成了一个具有一个中断输入,
一个中断输出端点的USB驱动程序。并且生成了Read和Write例程。

我想请问下,DS生成的Read和Write例程可以不用添加代码直接使用吗?为什么我直接使用地时候。
用应用程序读,写,还回的操作数都是0呢?

然后我查看驱动地读写例程。发现中间根本就没有URB的发送过程,操作数也是直接被赋0.于是添加了建立URB并传送URB的
代码。结果系统蓝屏了。。
一下是写地代码。其中//////////之间的代码是我添加地。请指教。



NTSTATUS UsbIntDevice::Write(KIrp I)
{
T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I);

NTSTATUS status = STATUS_SUCCESS;

// TODO: Validate the parameters of the IRP. Replace "FALSE"
// in the following line with error checking code that
// evaulates to TRUE if the request is not valid.
if (FALSE)
{
status = STATUS_INVALID_PARAMETER;
I.Information() = 0;
I.PnpComplete(status);

T.Trace(TraceWarning, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status);

return status;
}

// Always ok to write 0 elements
if (I.WriteSize() == 0)
{
I.Information() = 0;
I.PnpComplete(this, status);

T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status);

return status;
}

KMemory Mem(I.Mdl()); // Declare a memory object

// Get a pointer to the caller's buffer. Note that this
// routine is safe on all platforms.
PUCHAR pBuffer = (PUCHAR) Mem.MapToSystemSpace();
ULONG writeSize = I.WriteSize();
ULONG bytesSent = 0;
// TODO: At this point, perform any processing for IRP_MJ_WRITE
// To satisfy the write now, transfer data to the driver
// from the caller's buffer at "pBuffer". Then, indicate
// how much data was transferred:



//////////////////////////////////////////////////// Kondy Add Start
PURB pUrb =EP2_OUT.BuildBulkTransfer(

Mem,
I.IoctlInputBufferSize(),
FALSE,
NULL);
if(pUrb==NULL)
{

I.Information()=0;
return I.PnpComplete(this,STATUS_INSUFFICIENT_RESOURCES);
}
status=EP2_OUT.SubmitUrb(pUrb,NULL,NULL,1500L);
bytesSent=pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength;
////////////////////////////////////////////////////Kondy Add End

I.Information() = bytesSent;

I.PnpComplete(this, status);

T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status);

return status;
}
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
kondykuang
硬件/系统 2,644 成员 17,229 内容