This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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.

  • That's Windows, isn't it?

    So nothing to do with Keil?

  • For KMDF,
    WDF_USB_CONTROL_SETUP_PACKET_INIT_CLASS()

    "Initialization Functions for USB Structures"
    msdn.microsoft.com/.../aa939125.aspx

    And send it using
    WdfUsbTargetDeviceSendControlTransferSynchronously()
    msdn.microsoft.com/.../aa501719.aspx

    Tsuneo

  • 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 ?

  • NO - It does not!

    Try using the "pre" tag.