Exemple #1
0
NTSTATUS Pipe_Stop(__in PPIPE_CONTEXT pipeContext,
                   __in WDF_IO_TARGET_SENT_IO_ACTION WdfIoTargetSentIoAction,
                   __in BOOLEAN purgeQueue,
				   __in BOOLEAN stopIoTarget)
{
	NTSTATUS status = STATUS_SUCCESS;
	PAGED_CODE();

	if (pipeContext->IsValid == TRUE)
	{
		pipeContext->IsValid = FALSE; // mark context invalid.

		if (pipeContext->Queue && purgeQueue)	// stop queue, cancel any outstanding requests
			WdfIoQueuePurgeSynchronously(pipeContext->Queue);

		if (pipeContext->Pipe && stopIoTarget)
			PipeStop(pipeContext, WdfIoTargetSentIoAction); // stop pipe, cancel any outstanding requests
	}
	else
	{
		USBERRN("Invalid pipeContext");
		status = STATUS_INVALID_PIPE_STATE;
	}
	return status;
}
VOID
NdisProtEvtFileCleanup(
    IN WDFFILEOBJECT    FileObject
    )
/*++

Routine Description:

   EvtFileCleanup is called when the handle represented by the FileObject
   is closed. This callback is invoked in the context of the thread that
   closed the handle.

Arguments:

    FileObject - Pointer to fileobject that represents the open handle.

Return Value:

   VOID

--*/
{
    NTSTATUS                NtStatus;
    NDIS_STATUS             NdisStatus;
    PNDISPROT_OPEN_CONTEXT  pOpenContext;
    ULONG                   PacketFilter;
    ULONG                   BytesProcessed;
    PFILE_OBJECT_CONTEXT    fileContext;

    fileContext = GetFileObjectContext(FileObject);

    pOpenContext = fileContext->OpenContext;

    DEBUGP(DL_VERY_LOUD, ("Cleanup: FileObject %p, Open %p\n",
                                FileObject, pOpenContext));

    if (pOpenContext != NULL)
    {
        NPROT_STRUCT_ASSERT(pOpenContext, oc);

        //
        //  Mark this endpoint.
        //
        NPROT_ACQUIRE_LOCK(&pOpenContext->Lock, FALSE);

        NPROT_SET_FLAGS(pOpenContext->Flags, NPROTO_OPEN_FLAGS, NPROTO_OPEN_IDLE);
        pOpenContext->pFileObject = NULL;

        NPROT_RELEASE_LOCK(&pOpenContext->Lock, FALSE);

        //
        //  Set the packet filter to 0, telling NDIS that we aren't
        //  interested in any more receives.
        //
        PacketFilter = 0;
        NdisStatus = ndisprotValidateOpenAndDoRequest(
                        pOpenContext,
                        NdisRequestSetInformation,
                        OID_GEN_CURRENT_PACKET_FILTER,
                        &PacketFilter,
                        sizeof(PacketFilter),
                        &BytesProcessed,
                        FALSE   // Don't wait for device to be powered on
                        );

        if (NdisStatus != NDIS_STATUS_SUCCESS)
        {
            DEBUGP(DL_INFO, ("Cleanup: Open %p, set packet filter (%x) failed: %x\n",
                    pOpenContext, PacketFilter, NdisStatus));
            //
            //  Ignore the result. If this failed, we may continue
            //  to get indicated receives, which will be handled
            //  appropriately.
            //
            NdisStatus = NDIS_STATUS_SUCCESS;
        }


        NPROT_ACQUIRE_LOCK(&pOpenContext->Lock, FALSE);

        if (NPROT_TEST_FLAGS(pOpenContext->Flags, NPROTO_BIND_FLAGS, NPROTO_BIND_ACTIVE)){

            NPROT_RELEASE_LOCK(&pOpenContext->Lock, FALSE);

            //
            //  Cancel any pending reads.
            //
            WdfIoQueuePurgeSynchronously(pOpenContext->ReadQueue);
            //
            // Cancel pending control request for status indication.
            //
            WdfIoQueuePurgeSynchronously(pOpenContext->StatusIndicationQueue);
        } else {

            NPROT_RELEASE_LOCK(&pOpenContext->Lock, FALSE);
        }

        //
        // Clean up the receive packet queue
        //
        ndisprotFlushReceiveQueue(pOpenContext);
    }

    NtStatus = STATUS_SUCCESS;

    DEBUGP(DL_INFO, ("Cleanup: OpenContext %p\n", pOpenContext));

    return;
}