Hi,
I am new to WDF Programming but I will try to help. Looking at EvtIoRead
you can put some Kdprint statements in an hookup the kernel debugger to look
at the output. I put some suggestions in all CAPS.
VOID EvtIoRead( IN WDFQUEUE Queue, IN WDFREQUEST Request, IN size_t Length )
{
NTSTATUS status;
PDEVICE_EXTENSION devExt = GetDeviceContext(WdfIoQueueGetDevice(Queue));
ULONG information = 0;
PUCHAR systemBuffer = NULL;
size_t bufLen;
status = WdfRequestRetrieveOutputBuffer(Request, Length, &systemBuffer,
&bufLen);
if (!NT_SUCCESS(status))
{
WdfRequestComplete(Request, status);
return;
}
if (devExt->BytesInReadBuffer > 0)
{
ProcessReadBuffer(devExt, systemBuffer, (ULONG) Length,
&information);
// PUT KDPRINT HERE COULD BE A SYNCHROUSCOMPLETEION
// Got a question here just because BytesInReadBuffer > 0 how do know
that this will satisfy the Read IRP
WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS,
information);
return;
}
else
{
//
// No data to read. Queue the request for later processing.
//
status = WdfRequestForwardToIoQueue(Request, devExt->ReadQueue);
// PUT KDPRINT HERE COULD BE A ASYNCHRONCOMPLETEION
if (!NT_SUCCESS(status))
{
KdPrint( (“EvtIoRead: ForwardToIoQueue failed with Status code
0x%x\n”, status));
WdfRequestCompleteWithInformation(Request, status, 0);
return;
}
}
}
VOID EvtIoWrite( IN WDFQUEUE Queue, IN WDFREQUEST Request, IN size_t
Length )
{
NTSTATUS status;
PDEVICE_EXTENSION devExt = GetDeviceContext(WdfIoQueueGetDevice(Queue));
PUCHAR systemBuffer = NULL;
size_t length;
ULONG information = 0;
WDFREQUEST readRequest;
WDFREQUEST currentWaitRequest = NULL;
status = WdfRequestRetrieveInputBuffer(Request, Length, &systemBuffer,
&length);
if (!NT_SUCCESS(status))
{
WdfRequestComplete(Request, status);
return;
}
ProcessWriteBuffer(devExt, systemBuffer, Length);
//
// Process read requests and complete them here.
//
while (devExt->BytesInReadBuffer > 0)
{
ULONG bytesToMove;
// PUT KDPRINT
status = WdfIoQueueRetrieveNextRequest(devExt->ReadQueue,
&readRequest);
if (!NT_SUCCESS(status))
{
break;
}
status = WdfRequestRetrieveOutputBuffer(readRequest, 0, &systemBuffer,
&length);
ASSERT(NT_SUCCESS(status));
ProcessReadBuffer(devExt, systemBuffer, (ULONG) length, &bytesToMove);
// PUT KDPRINT !!! NOTE THAT THE IRP_MJ_READ IS COMPLETED HERE and
NOT in EvtIoRead
WdfRequestCompleteWithInformation(readRequest, STATUS_SUCCESS,
bytesToMove);
}
//
// process event
//
if (devExt->BytesInReadBuffer > 0)
{
// PUT KDPRINT !!! Note that this will Fire you event in MSComm.
if (devExt->CurrentMask & SERIAL_EV_RXCHAR)
{
// PUT KDPRINT !!!
status = WdfIoQueueRetrieveNextRequest(devExt->MaskWaitQueue,
¤tWaitRequest);
if (NT_SUCCESS(status) && currentWaitRequest != NULL)
{
PULONG outBuffer;
size_t bufSize;
KdPrint((“VCom: process event\n”));
//
// The length was validated already.
//
(VOID)WdfRequestRetrieveOutputBuffer(currentWaitRequest,
sizeof(ULONG), &outBuffer, &bufSize);
if (outBuffer)
{ // FIXME SAL
*outBuffer =
SERIAL_EV_RXCHAR;//SERIAL_EV_RXFLAG,SERIAL_EV_RLSD
}
// PUT KDPRINT !!! Here you compete the IRP_SERIAL_WAIT_MASK
WdfRequestCompleteWithInformation(currentWaitRequest,
STATUS_SUCCESS, sizeof(ULONG));
}
}
}
// PUT KDPRINT !!! Here you Synchronizely complete the IRP_MJ_WRITE
WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Length);
}
Now just trying to help you know. To complete everything synchronizely
which I have my doubts about but anyway since I have analyzed MSComm for
real only read the Internet lets assume this is true. I would get rid of
completing the Read Irp in your IoEvWrite routine. I would copy the the
Write Data to a buffer in you in Virtural Com Driver. You will have to
allocate the memory for this. That I would do instead of Completing the
IRP. I would then always complete the READ in the EvIoRead routine.
-William Michael Jones
wrote in message news:xxxxx@ntdev…
> i’ve written a virtual com driver, this driver is kind of like a pipe,
> tranfers write to read.
>
> when i test this driver by mscomm control, the write works fine, but read
> returns run time error 8020 in oncomm event handler.
>
> anyone can tell me what’s wrong with the driver ? any IOCTL didn’t handle
> properly ?
>
> thanks in advance.
>