⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miniport.c

📁 基于Passthru的扩展
💻 C
📖 第 1 页 / 共 3 页
字号:
		{
			pAdapt->StandingBy = TRUE;
		}

		//
		// If the miniport is transitioning from a low power state to ON (D0), then clear the StandingBy flag
		// All incoming requests will be pended until the physical miniport turns ON.
		//
		if (pAdapt->MPDeviceState > NdisDeviceStateD0 &&  NewDeviceState == NdisDeviceStateD0)
		{
			pAdapt->StandingBy = FALSE;
		}
		
		//
		// Now update the state in the pAdapt structure;
		//
		pAdapt->MPDeviceState = NewDeviceState;
		
		*pNdisStatus = NDIS_STATUS_SUCCESS;
	

	} while (FALSE);	
		
	if (*pNdisStatus == NDIS_STATUS_SUCCESS)
	{
        //
        // The miniport resume from low power state
        // 
        if (pAdapt->StandingBy == FALSE)
        {
            //
            // If we need to indicate the media connect state
            // 
            if (pAdapt->LastIndicatedStatus != pAdapt->LatestUnIndicateStatus)
            {
               NdisMIndicateStatus(pAdapt->MiniportHandle,
                                        pAdapt->LatestUnIndicateStatus,
                                        (PVOID)NULL,
                                        0);
               NdisMIndicateStatusComplete(pAdapt->MiniportHandle);
               pAdapt->LastIndicatedStatus = pAdapt->LatestUnIndicateStatus;
            }
        }
        else
        {
            //
            // Initialize LatestUnIndicatedStatus
            //
            pAdapt->LatestUnIndicateStatus = pAdapt->LastIndicatedStatus;
        }
		*BytesRead = sizeof(NDIS_DEVICE_POWER_STATE);
		*BytesNeeded = 0;
	}
	else
	{
		*BytesRead = 0;
		*BytesNeeded = sizeof (NDIS_DEVICE_POWER_STATE);
	}

	DBGPRINT(("<==MPProcessSetPowerOid: Adapt %p\n", pAdapt)); 
}


VOID
MPReturnPacket(
	IN	NDIS_HANDLE				MiniportAdapterContext,
	IN	PNDIS_PACKET			Packet
	)
/*++

Routine Description:

	NDIS Miniport entry point called whenever protocols are done with
	a packet that we had indicated up and they had queued up for returning
	later.

Arguments:

	MiniportAdapterContext	- pointer to ADAPT structure
	Packet	- packet being returned.

Return Value:

	None.

--*/
{
	PADAPT			pAdapt = (PADAPT)MiniportAdapterContext;

#ifdef NDIS51
	//
	// Packet stacking: Check if this packet belongs to us.
	//
	if (NdisGetPoolFromPacket(Packet) != pAdapt->RecvPacketPoolHandle)
	{
		//
		// We reused the original packet in a receive indication.
		// Simply return it to the miniport below us.
		//
		NdisReturnPackets(&Packet, 1);
	}
	else
#endif // NDIS51
	{
		//
		// This is a packet allocated from this IM's receive packet pool.
		// Reclaim our packet, and return the original to the driver below.
		//

		PNDIS_PACKET	MyPacket;
		PRECV_RSVD		RecvRsvd;
	
		RecvRsvd = (PRECV_RSVD)(Packet->MiniportReserved);
		MyPacket = RecvRsvd->OriginalPkt;
	
		NdisFreePacket(Packet);
		NdisReturnPackets(&MyPacket, 1);
	}
}


NDIS_STATUS
MPTransferData(
	OUT PNDIS_PACKET			Packet,
	OUT PUINT					BytesTransferred,
	IN	NDIS_HANDLE				MiniportAdapterContext,
	IN	NDIS_HANDLE				MiniportReceiveContext,
	IN	UINT					ByteOffset,
	IN	UINT					BytesToTransfer
	)
/*++

Routine Description:

	Miniport's transfer data handler.

Arguments:

	Packet					Destination packet
	BytesTransferred		Place-holder for how much data was copied
	MiniportAdapterContext	Pointer to the adapter structure
	MiniportReceiveContext	Context
	ByteOffset				Offset into the packet for copying data
	BytesToTransfer			How much to copy.

Return Value:

	Status of transfer

--*/
{
	PADAPT		pAdapt = (PADAPT)MiniportAdapterContext;
	NDIS_STATUS	Status;

	//
	// Return, if the device is OFF
	//

	if (IsIMDeviceStateOn(pAdapt) == FALSE)
	{
		return NDIS_STATUS_FAILURE;
	}

	NdisTransferData(&Status,
					 pAdapt->BindingHandle,
					 MiniportReceiveContext,
					 ByteOffset,
					 BytesToTransfer,
					 Packet,
					 BytesTransferred);

	return(Status);
}

VOID
MPHalt(
	IN	NDIS_HANDLE				MiniportAdapterContext
	)
/*++

Routine Description:

	Halt handler. All the hard-work for clean-up is done here.

Arguments:

	MiniportAdapterContext	Pointer to the Adapter

Return Value:

	None.

--*/
{
	PADAPT			pAdapt = (PADAPT)MiniportAdapterContext;
	NDIS_STATUS		Status;
	PADAPT			pCursor, *ppCursor;
	PADAPT			pPromoteAdapt = NULL;

	DBGPRINT(("==>MiniportHalt: Adapt %p\n", pAdapt));

	//
	// Remove this adapter from the global list
	//
	NdisAcquireSpinLock(&GlobalLock);

	for (ppCursor = &pAdaptList; *ppCursor != NULL; ppCursor = &(*ppCursor)->Next)
	{
		if (*ppCursor == pAdapt)
		{
			*ppCursor = pAdapt->Next;
			break;
		}
	}

	NdisReleaseSpinLock(&GlobalLock);

	//
	// Delete the ioctl interface that was created when the miniport
	// was created.
	//
	(VOID)PtDeregisterDevice();

	//
	// If we have a valid bind, close the miniport below the protocol
	//
	if (pAdapt->BindingHandle != NULL)
	{
		//
		// Close the binding below. and wait for it to complete
		//
		NdisResetEvent(&pAdapt->Event);

		NdisCloseAdapter(&Status, pAdapt->BindingHandle);

		if (Status == NDIS_STATUS_PENDING)
		{
			NdisWaitEvent(&pAdapt->Event, 0);
			Status = pAdapt->Status;
		}

		ASSERT (Status == NDIS_STATUS_SUCCESS);

		pAdapt->BindingHandle = NULL;
	}

	//
	//  Free all resources on this adapter structure.
	//

	MPFreeAllPacketPools (pAdapt);

	NdisFreeMemory(pAdapt, sizeof(ADAPT), 0);

	DBGPRINT(("<== MiniportHalt: pAdapt %p\n", pAdapt));
}


NDIS_STATUS
MPReset(
	OUT PBOOLEAN				AddressingReset,
	IN	NDIS_HANDLE				MiniportAdapterContext
	)
/*++

Routine Description:

	Reset Handler. We just don't do anything.

Arguments:

	AddressingReset			To let NDIS know whether we need help from it with our reset
	MiniportAdapterContext	Pointer to our adapter

Return Value:


--*/
{
	PADAPT	pAdapt = (PADAPT)MiniportAdapterContext;

	*AddressingReset = FALSE;

	return(NDIS_STATUS_SUCCESS);
}


#ifdef NDIS51_MINIPORT

VOID
MPCancelSendPackets(
	IN	NDIS_HANDLE			MiniportAdapterContext,
	IN	PVOID				CancelId
	)
/*++

Routine Description:

	The miniport entry point to handle cancellation of all send packets
	that match the given CancelId. If we have queued any packets that match
	this, then we should dequeue them and call NdisMSendComplete for all
	such packets, with a status of NDIS_STATUS_REQUEST_ABORTED.

	We should also call NdisCancelSendPackets in turn, on each lower binding
	that this adapter corresponds to. This is to let miniports below cancel
	any matching packets.

Arguments:

	MiniportAdapterContext	- pointer to ADAPT structure
	CancelId	- ID of packets to be cancelled.

Return Value:

	None

--*/
{
	PADAPT	pAdapt = (PADAPT)MiniportAdapterContext;

	//
	// If we queue packets on our adapter structure, this would be 
	// the place to acquire a spinlock to it, unlink any packets whose
	// Id matches CancelId, release the spinlock and call NdisMSendComplete
	// with NDIS_STATUS_REQUEST_ABORTED for all unlinked packets.
	//

	//
	// Next, pass this down so that we let the miniport(s) below cancel
	// any packets that they might have queued.
	//
	NdisCancelSendPackets(pAdapt->BindingHandle, CancelId);

	return;
}

VOID
MPDevicePnPEvent(
	IN NDIS_HANDLE				MiniportAdapterContext,
	IN NDIS_DEVICE_PNP_EVENT	DevicePnPEvent,
	IN PVOID					InformationBuffer,
	IN ULONG					InformationBufferLength
	)
/*++

Routine Description:

	This handler is called to notify us of PnP events directed to
	our miniport device object.

Arguments:

	MiniportAdapterContext	- pointer to ADAPT structure
	DevicePnPEvent - the event
	InformationBuffer - Points to additional event-specific information
	InformationBufferLength - length of above

Return Value:

	None
--*/
{
	// TBD - add code/comments about processing this.

	return;
}

VOID
MPAdapterShutdown(
	IN NDIS_HANDLE				MiniportAdapterContext
	)
/*++

Routine Description:

	This handler is called to notify us of an impending system shutdown.

Arguments:

	MiniportAdapterContext	- pointer to ADAPT structure

Return Value:

	None
--*/
{
	return;
}

#endif


VOID
MPFreeAllPacketPools(
	PADAPT					pAdapt
	)
/*++

Routine Description:

	Free all packet pools on the specified adapter.
	
Arguments:

	pAdapt	- pointer to ADAPT structure

Return Value:

	None

--*/
{
	if (pAdapt->RecvPacketPoolHandle != NULL)
	{
		//
		// Free the packet pool that is used to indicate receives
		//
		NdisFreePacketPool(pAdapt->RecvPacketPoolHandle);

		pAdapt->RecvPacketPoolHandle = NULL;
	}

	if (pAdapt->SendPacketPoolHandle != NULL)
	{

		//
		//  Free the packet pool that is used to send packets below
		//

		NdisFreePacketPool(pAdapt->SendPacketPoolHandle);

		pAdapt->SendPacketPoolHandle = NULL;

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -