Discussion Forum

KUsbInterface:BuildClassRequest

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Zaheer Khan
Posted
16-Nov-2009 07:14 GMT
Toolset
None
New! KUsbInterface:BuildClassRequest

I am trying to port a usb driver from wdm to wdf framework. In wdm there is an api KUsbInterface:BuildClassRequest which "USB client drivers set up this structure to issue a vendor or class-specific command to a device".

I am trying to find a similar api in WDF.

Please help me on the same.

Regards,
Zaheer.

Read-Only
Author
Andy Neil
Posted
16-Nov-2009 07:30 GMT
Toolset
None
New! WDF?

That's Windows, isn't it?

So nothing to do with Keil?

Read-Only
Author
Tsuneo Chinzei
Posted
16-Nov-2009 19:49 GMT
Toolset
None
New! RE: KUsbInterface:BuildClassRequest

For KMDF,
WDF_USB_CONTROL_SETUP_PACKET_INIT_CLASS()

"Initialization Functions for USB Structures"
http://msdn.microsoft.com/en-us/library/aa939125.aspx

And send it using
WdfUsbTargetDeviceSendControlTransferSynchronously()
http://msdn.microsoft.com/en-us/library/aa501719.aspx

Tsuneo

Read-Only
Author
Zaheer Khan
Posted
23-Nov-2009 15:27 GMT
Toolset
None
New! RE: KUsbInterface:BuildClassRequest

I have to port the code from WDM to wdf for dfu driver.
Below is the code :

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 ?

Read-Only
Author
I B Shy
Posted
23-Nov-2009 15:52 GMT
Toolset
None
New! "Does the above code look good ?. "

NO - It does not!

Try using the "pre" tag.

Next Thread | Thread List | Previous Thread Start a Thread | Settings