wdm
========
DeviceControl(KIrp I)
{
switch (I.IoctlCode ())
{
case GETSTATE:
GetState();
}
GetState (KIrp I)
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
I.Information () = 0;
if (I.IoctlBuffer () &&
I.IoctlInputBufferSize () == 0 &&
I.IoctlOutputBufferSize ())
{
status = SendCommand ((UCHAR *) I.IoctlBuffer (), I.IoctlOutputBufferSize (),
GETSTATE, 0, true, true, 0);
I.Information () = sizeof UCHAR;
}
else
{
status = STATUS_INVALID_PARAMETER;
}
return status;
}
SendCommand (UCHAR * buffer, ULONG size, UCHAR request, USHORT value,
bool In, bool ShortOk, ULONG * info)
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
T.Trace (TraceInfo, "> " __FUNCTION__ "\n");
PURB pUrb = m_DfuInterface.BuildClassRequest (buffer, // Transfer buffer
size, // Transfer buffer size
0, // Request reserved bits
request, // Request
value, // Value
In, // In
ShortOk, // Short OK
NULL, // Link URB
NULL); // URB
if (pUrb != NULL)
{
status = m_DfuInterface.SubmitUrb (pUrb);
if (NT_SUCCESS (status) && info)
{
*info = (USHORT)pUrb->UrbControlVendorClassRequest.TransferBufferLength;
}
if (NT_ERROR (status))
{
t << "SendCommand (" << request << "): FAILED\n";
t << " NTSTATUS = " << ULONG (status) << "\n";
t << " URB status = " << ULONG (pUrb->UrbHeader.Status) << "\n";
}
delete pUrb;
}
else
{
T << "SendCommand: STATUS_INSUFFICIENT_RESOURCES" << "\n";
status = STATUS_INSUFFICIENT_RESOURCES;
}
return status;
}
wdf
=====
EvtIoDeviceControl(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength,
IN ULONG IoControlCode
)
{
device = WdfIoQueueGetDevice(Queue);
pDevContext = GetDeviceContext(device);
switch(IoControlCode) {
code GETSTATE:
getstate(pDevContext->WdfUsbTargetDevice,Request);
}
NTSTATUS getstate(WDFUSBDEVICE Device,WDFREQUEST request)
{
PURB pUrb = NULL;
WDFMEMORY urbMemory;
WDF_OBJECT_ATTRIBUTES objectAttribs;
PULONG nbytes;
USHORT usUrbSize;
WDF_MEMORY_DESCRIPTOR memoryDesc;
PWDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
usUrbSize = (USHORT)sizeof(struct
_URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
WDF_OBJECT_ATTRIBUTES_INIT(&objectAttribs);
objectAttribs.ParentObject = Device;
status = WdfMemoryCreate(&objectAttribs,
NonPagedPool,
POOL_TAG,
usUrbSize,
&urbMemory,
(PVOID*) &pUrb);
if (!NT_SUCCESS(status)) {
UsbDfu_DbgPrint(1, ("Failed to alloc mem for urb\n"));
status = STATUS_INSUFFICIENT_RESOURCES;
return status;
}
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&memoryDesc, urbMemory,
(USHORT)sizeof(URB));
WDF_USB_CONTROL_SETUP_PACKET_INIT_CLASS(&controlSetupPacket,
BMREQUEST_DEVICE_TO_HOST,
BMREQUEST_TO_INTERFACE,
DFU_GETSTATE,// Request(DFU_DETACH,DFU_DNLOAD etc)
0, //value
0); //Index
status = WdfUsbTargetDeviceFormatRequestForControlTransfer(
Device,
WDF_NO_HANDLE,
&controlSetupPacket,
memoryDesc,
NULL
);
if (!NT_SUCCESS(status)){
return status;
}
WdfRequestSetCompletionRoutine(
request,
MyCompletionRoutine,
NULL
);
if (WdfRequestSend(request, FmDeviceData->WdfUsbTargetDevice,NULL) == FALSE)
{
status = WdfRequestGetStatus(request);
}
}
VOID
MyCompletionRoutine (
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
IN PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
IN WDFCONTEXT Context
)
{
NTSTATUS status;
WDFMEMORY memoryHandle=Context;
PUCHAR charPointer=NULL;
UCHAR count =0;
size_t length=0;
PWDF_USB_REQUEST_COMPLETION_PARAMS usbCompletionParams;
UNREFERENCED_PARAMETER(Target);
UNREFERENCED_PARAMETER(Context);
DbgPrint("Entered %s\n",__FUNCTION__);
status = CompletionParams->IoStatus.Status;
usbCompletionParams = CompletionParams->Parameters.Usb.Completion;
DbgPrint("%s: request Status 0x%x UsbdStatus 0x%x\n",__FUNCTION__,status,
usbCompletionParams->UsbdStatus);
WdfObjectDelete(Request);
DbgPrint("Leaving %s\n",__FUNCTION__);
return;
}
===============================================
Does the above code look good ?. Also how do I get the outputbuffersize and inputbuffersize ?
EggHeadCafe - Software Developer Portal of Choice
Programming ASP.NET
http://www.eggheadcafe.com/tutorials/aspnet/07b4ad09-b631-42d6-9333-86aa25b1a9e5/programming-aspnet.aspx
"Zaheer Khan" wrote in message news:2009112310...@yahoo.com...
should be
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&memoryDesc, urbMemory, usUrbSize );
and you should probably also set a timeout on the send in case your control
transfer fails
d
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Zaheer Khan" wrote in message news:2009112310...@yahoo.com...
>
How do I get hold of the "output or input buffer address" being passed to EvtIoDeviceControl, from where I can transfer data from/to the device.
Doron Holan [MSFT] wrote:
this:WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&memoryDesc,
23-Nov-09
this:
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&memoryDesc, urbMemory,
(USHORT)sizeof(URB));
should be
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&memoryDesc, urbMemory, usUrbSize );
and you should probably also set a timeout on the send in case your control
transfer fails
d
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Previous Posts In This Thread:
EggHeadCafe - Software Developer Portal of Choice
CSS Stylesheet Sampler Script
http://www.eggheadcafe.com/tutorials/aspnet/6414b26b-a720-4174-8bd0-64466ee722bc/css-stylesheet-sampler-sc.aspx
WdfRequestRetrieveInputBuffer
WdfRequestRetrieveOutputMemory
WdfRequestRetrieveOutputWdmMdl
return the buffers in various forms
d
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Zaheer Khan" wrote in message news:2009112415...@yahoo.com...