In your completion routine you need to tell the OS how many bytes of
data you are returning. You can do this by calling
WdfRequestCompleteWithInformation() and providing the number of bytes
you are returning in the “information” parameter.
-p
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of shaikh abdul
kareem
Sent: Monday, February 26, 2007 1:35 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to handel CompletionRoutine to send data back
to client
Hi Peter,
I modified the code as per user suggestion. I am using the memory buffer
of original request.
But after implementing the changes also My client app. is not getting
the data from the driver. Where as if i see the contents of the request
in MyDataComplition routine the data from device is present. What may be
the problem?
Please check the below code:
MAIN CONTROL function:
EvtIoDeviceControl( IN WDFQUEUE Queue, IN WDFREQUEST Request,
IN size_t OutputBufferLength, IN size_t InputBufferLength,
IN ULONG IoControlCode )
{
switch (IoControlCode) {
case IOCTL_MY_REQ_R:
////For ASynchronously READ call to device
status =
IoctlVREAD_ASynchronously(Queue,Request,OutputBufferLength,InputBufferLe
ngth);
break;
case IOCTL_MY_REQ_W:
////For ASynchronously WRITE call to device
status =
IoctlVWRITE_ASynchronously(Queue,Request,OutputBufferLength,InputBufferL
ength);
break ;
default :
status = STATUS_INVALID_DEVICE_REQUEST;
break ;
}
if (!NT_SUCCESS(status))
{
WdfRequestComplete(Request, status);
}
return ;
}
}
MY READ FUNCTION:
NTSTATUS IoctlVREAD_ASynchronously(IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength)
{
PMY_STRUCT pReqData = NULL; // client send request
//it contains vendor specific request id and a array of char which
//will be gets filed by device
status = WdfRequestRetrieveOutputBuffer(Request,
sizeof(PMY_STRUCT),
&pReqData,
NULL);
status = WdfMemoryCreatePreallocated(&attributes,
&pReqData->Data,//array
of char
pReqData->wLength,
&memHandle);
WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(
&controlSetupPacket,
BmRequestDeviceToHost,
BmRequestToDevice,
pReqData->bRequest,
pReqData->wValue,
pReqData->wIndex);
status = WdfUsbTargetDeviceFormatRequestForControlTransfer(
pDevContext->WdfUsbTargetDevice,
Request,
&controlSetupPacket,
memHandle,
NULL
);
WdfRequestSetCompletionRoutine(Request,
MYCompletionRoutine,
NULL
);
if (WdfRequestSend( Request,
WdfUsbTargetDeviceGetIoTarget(pDevContext->WdfUsbTargetDevice),
NULL
) == FALSE)
{
status = WdfRequestGetStatus(Request);
}
return STATUS_SUCCESS; //End of the function
}
MY Completion Routine FUNCTION:
VOID MYCompletionRoutine (
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
IN PWDF_REQUEST_COMPLETION_PARAMS Params,
IN WDFCONTEXT Context
)
{
status = Params->Parameters.Usb.Completion->UsbdStatus;
if ( SetupPacket.Packet.bm.Request.Dir == BMREQUEST_HOST_TO_DEVICE)
{
KdPrint((“WRITE REQUEST\n”));
}
else
{
KdPrint((“READ REQUEST\n”));
}
//The request object has the client request data from the device that’s
why I am not doing and processing and just completing the request
WdfRequestComplete(Request,status);
KdPrint(( “DatGuardCompletionGetData … END\n”));
return ;
}
This is how i implemeted my code.
Please look into it.
Why its not returing the data to the client I don’t understand.
Thanks,
kareem
On 2/25/07, Peter Wieland wrote:
In your read request handler you made a new request with a new
memory object.
You need to copy the data from that new memory object to the
memory object for the original request and then you need to set the
information and status properties on the original request and complete
that.
If you want to avoid the copy you can see if you can use the
memory buffer from the original request in the new request.
-p
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of shaikh abdul
kareem
Sent: Saturday, February 24, 2007 9:39 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to handel CompletionRoutine to send
data back to client
Hi Peter,
Thanks for your reply.
I am new to WDF. Whats why i dont know that WDF never returns
STATUS_PENDING. I dont want to complete the request. Rather i want it to
wait until my CompletionRoutine gets called.
In step 7 i just returns from the IOControlRead(My own function
which takes care of reading the device, means from 1-7 steps are
implemented in this function) funtion setting the status =
STATUS_PENDING.
My problem is how to send the device data back to client app.
Thanks,
abdul
On 2/24/07, Peter Wieland
wrote:
Can you explain what you do in step 7? WDF drivers never return
STATUS_PENDING. You aren’t completing the request with
STATUS_PENDING
are you?
-p
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Saturday, February 24, 2007 3:33 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to handel CompletionRoutine to send data
back to
client
Hi All,
I am writing a USB driver. I have to read and write requests
asynchronously. The pseudo code I followed to send a client
request to
Device is as follows:
1. In IOControlRead function i create a new request.
2. Create a memory object and sets its parent as newly created
request.
3. Setting WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR as per my
vendor
device spec.
4. calls WdfUsbTargetDeviceFormatRequestForControlTransfer
5. calls WdfRequestSetCompletionRoutine
6. calls WdfRequestSend
7. finishing the IOControlRead function with status
STATUS_PENDING
The problem is when my completion routine gets called with a
request
object; I can not access that request object. Means if I call
WdfRequestRetrieveInputBuffer or if I call WdfRequestComplete on
the
request object my system crashes. I can get the data send by the
lower
device in PWDF_REQUEST_COMPLETION_PARAMS. But i am not able to
send this
data back to client.
If i do not use the request object and just return completion
routine
with status success, my client application did not receive any
data from
driver.
Please help to solve this problem. How can i send back the
requested
data to the client app? Is any thing i am missing or my logic to
send
request to lower device is wrong? Is any thing i have to do with
the
orginal request got from client?
Thanks,
Abdul
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer