no of bytes read are zero in read completion routine?

Discussion in 'Windows Vista Drivers' started by amitsam, Apr 27, 2009.

  1. amitsam

    amitsam Guest

    Hi all i am very new to wdf device driver development. I am doing basic usb
    read write functionality in which i am trying to communicate with nokia n85'
    modem. I am sending some AT commands n trying to read response of it. I have
    referred osrusbfx2 wdk sample for this. before sending read request i am
    formatting it by calling
    status = WdfUsbTargetPipeFormatRequestForRead(pipe,
    Request,
    reqMemory,
    //pDeviceContext->memoryHandle,
    NULL // Offsets
    );

    where reqMemory is the WDFMEMORY handle retrieved from
    WdfRequestRetrieveOutputMemory.

    in this case inside my read completion routine
    bytesRead = usbCompletionParams->Parameters.PipeRead.Length;
    are coming out to be zero.

    n when i format read request by calling

    status = WdfUsbTargetPipeFormatRequestForRead(pipe,
    Request,
    pDeviceContext->memoryHandle,
    NULL // Offsets
    );

    where memoryHandle is my own WDFMEMORY handle stored in context.
    in this case inside my read completion routine
    bytesRead = usbCompletionParams->Parameters.PipeRead.Length;
    are not coming out to be zero. bytesRead is having some value.

    can any one tell me why is this happening?
    thanks in advance.
     
    amitsam, Apr 27, 2009
    #1
    1. Advertisements

  2. Okay, and how big was the buffer that you got passed from user-mode?
    Zero bytes, I bet... can you post your user-mode code?
    What is that WDFMEMORY wrapping? How or where did you allocate it?
     
    chris.aseltine, Apr 27, 2009
    #2
    1. Advertisements

  3. amitsam

    amitsam Guest

    In user mode i a passing char ReadBuffer[BUFFER_SIZE] = {0};
    as
    BOOL readReturn=ReadFile(hComm, ReadBuffer, BUFFER_SIZE-2, &dwBytesRead,
    NULL);

    where BUFFER_SIZE=20.

    and i have allocated WDFMEMORY in EvtDeviceAdd callback.


    WDF_OBJECT_ATTRIBUTES_INIT(&objectAttribs);
    objectAttribs.ParentObject = FmDeviceData->UsbDevice;
    status =
    WdfMemoryCreate(&objectAttribs,NonPagedPool,0,READ_BUFFER_SIZE,&FmDeviceData->memoryHandle,(PVOID)&FmDeviceData->memoryBuffer);
    if (!NT_SUCCESS(status)) {
    DbgPrint("%s:cannot create memory object %x\n",__FUNCTION__,status);
    return status;
    }
     
    amitsam, Apr 28, 2009
    #3
  4. Could you use the KMDF debugger extension (wdfkd.dll) to dump the reqMemory
    object? !wdfkd.wdfmemory is the extension you will need to use.
    Also, after you have formatted the request using
    WdfUsbTargetPipeFormatRequestForRead, could you dump the request object?
    !wdfkd.wdfrequest is the extension you will need to use.
    You could perform the above steps for the case where you get data and the
    case where you don't to see what is different.

    Couple of other suggestions -
    - In the read completion routine, you could retrieve the request status and
    see if the request failed in the case where you don't get data.
    - You could use the !wdfkd.wdflogdump to dump the log for your driver and
    see if it has any clues. In order to view the log you'll first need to set
    the tmf path using the !wdfkd.wdftmffile extension. The tmf file should be
    available in the WDK in tools\tracing directory.
     
    Abhishek R [MSFT], Apr 29, 2009
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.