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

📄 protocol.c

📁 利用C++工具进行编程,NDIS的PASSTHRU层的驱动程序,是非常实用的程序.
💻 C
📖 第 1 页 / 共 3 页
字号:
Routine Description:

	Completion handler for the previously posted request. All OIDS are completed by and sent to
	the same miniport that they were requested for.
	If Oid == OID_PNP_QUERY_POWER then the data structure needs to returned with all entries =
	NdisDeviceStateUnspecified

Arguments:

	ProtocolBindingContext	Pointer to the adapter structure
	NdisRequest				The posted request
	Status					Completion status

Return Value:

	None

--*/
{
	PADAPT		pAdapt =(PADAPT)ProtocolBindingContext;
	NDIS_OID	Oid =	pAdapt->Request.DATA.SET_INFORMATION.Oid ;

//	DbgPrint("Pt Query complete");

	//
	//	Change to the pAdapt for which the request originated
	//
	if(MPIsSendOID(Oid))
	{
		  pAdapt = pAdapt->pPrimaryAdapt;
		  //
		  // Will point to itself if there is no bundle(see initialization)
		  //
	}


	//
	// Since our request is not outstanding anymore
	//
	pAdapt->OutstandingRequests = FALSE;

	//
	// Complete the Set or Query, and fill in the buffer for OID_PNP_CAPABILITIES, if need be.
	//
	switch(NdisRequest->RequestType)
	{
	  case NdisRequestQueryInformation:

		  //
		  // This should not have been passsed to the miniport below us
		  //
		  ASSERT(Oid != OID_PNP_QUERY_POWER);

		  //
		  // If oid == OID_PNP_CAPABILITIES and query was successsful
		  // then fill the buffer with the required values
		  //
		  if(Oid == OID_PNP_CAPABILITIES && Status == NDIS_STATUS_SUCCESS)
		  {

				MPQueryPNPCapbilities(pAdapt,&Status);

		  }

		  *pAdapt->BytesReadOrWritten = NdisRequest->DATA.QUERY_INFORMATION.BytesWritten;

		  *pAdapt->BytesNeeded = NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded;

		  NdisMQueryInformationComplete(pAdapt->MiniportHandle,
												  Status);
		  break;

	  case NdisRequestSetInformation:

		  ASSERT( Oid != OID_PNP_SET_POWER);

		  *pAdapt->BytesReadOrWritten = NdisRequest->DATA.SET_INFORMATION.BytesRead;
		  *pAdapt->BytesNeeded = NdisRequest->DATA.SET_INFORMATION.BytesNeeded;
		  NdisMSetInformationComplete(pAdapt->MiniportHandle,
												Status);
		  break;

	  default:
		  ASSERT(0);
		  break;
	}
	
}


VOID
PtStatus(
	IN  NDIS_HANDLE			ProtocolBindingContext,
	IN  NDIS_STATUS			GeneralStatus,
	IN  PVOID				StatusBuffer,
	IN  UINT				StatusBufferSize
	)
/*++

Routine Description:

	Status handler for the lower-edge(protocol).

Arguments:

	ProtocolBindingContext	Pointer to the adapter structure
	GeneralStatus			Status code
	StatusBuffer			Status buffer
	StatusBufferSize		Size of the status buffer

Return Value:

	None

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

	//
	// If we get a status indication before our miniport is initialized, ignore it
	// If the SampleIM is not ON, we do not pass on the status indication
	//
	if(pAdapt->MiniportHandle != NULL  &&
	  pAdapt->MPDeviceState == NdisDeviceStateD0 &&
	  pAdapt->PTDeviceState == NdisDeviceStateD0 )	
	{
		  NdisMIndicateStatus(pAdapt->MiniportHandle,
									 GeneralStatus,
									 StatusBuffer,
									 StatusBufferSize);
	}
}


VOID
PtStatusComplete(
	IN	NDIS_HANDLE			ProtocolBindingContext
	)
/*++

Routine Description:


Arguments:


Return Value:


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

	//
	// If we get a status indication before our miniport is initialized, ignore it
	//
	if(pAdapt->MiniportHandle != NULL  &&
	  pAdapt->MPDeviceState == NdisDeviceStateD0 &&
	  pAdapt->PTDeviceState == NdisDeviceStateD0 )	
	{
		  NdisMIndicateStatusComplete(pAdapt->MiniportHandle);
	}
}


VOID
PtSendComplete(
	IN	NDIS_HANDLE			ProtocolBindingContext,
	IN  PNDIS_PACKET		Packet,
	IN  NDIS_STATUS			Status
	)
/*++

Routine Description:

Interesting case:
We wish to send all sends down the secondary NIC. But when we indicate to the protocol above,
we need to revert back to the original miniport that Protocol wished to use for the Send


Arguments:


Return Value:


--*/
{
	PADAPT			pAdapt =(PADAPT)ProtocolBindingContext;
	PNDIS_PACKET	Pkt;
	PRSVD			Rsvd;

//	DbgPrint("Pt Send complete");

	//
	// Returning the Send on the Primary, will point to itself if there is no bundle
	//
	pAdapt = pAdapt->pPrimaryAdapt;

	Rsvd =(PRSVD)(Packet->ProtocolReserved);
	Pkt = Rsvd->OriginalPkt;


	NdisIMCopySendCompletePerPacketInfo (Pkt, Packet);

	NdisDprFreePacket(Packet);

	NdisMSendComplete(pAdapt->MiniportHandle,
							 Pkt,
							 Status);
}


VOID
PtTransferDataComplete(
	IN  NDIS_HANDLE			ProtocolBindingContext,
	IN  PNDIS_PACKET		Packet,
	IN  NDIS_STATUS			Status,
	IN  UINT				BytesTransferred
	)
/*++

Routine Description:
Same as the Send above, all sends need to be completed on the Primary's MiniportHandle

Arguments:

Return Value:

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

//	DbgPrint("Pt Transferdata complete\n");

	//
	// Returning the Send on the Primary, will point to itself if there is no LBFO
	//
	pAdapt = pAdapt->pPrimaryAdapt;

	if(pAdapt->MiniportHandle)
	{
		  NdisMTransferDataComplete(pAdapt->MiniportHandle,
											 Packet,
											 Status,
											 BytesTransferred);
	}
}



NDIS_STATUS
PtReceive(
	IN  NDIS_HANDLE			ProtocolBindingContext,
	IN  NDIS_HANDLE			MacReceiveContext,
	IN  PVOID				HeaderBuffer,
	IN  UINT				HeaderBufferSize,
	IN  PVOID				LookAheadBuffer,
	IN  UINT				LookAheadBufferSize,
	IN  UINT				PacketSize
	)
/*++

Routine Description:
LBFO - need to use primary for all receives

Arguments:


Return Value:

--*/
{
	PADAPT			pAdapt =(PADAPT)ProtocolBindingContext;
	PNDIS_PACKET	MyPacket, Packet;
	NDIS_STATUS		Status = NDIS_STATUS_SUCCESS;

/***********Add By me*****/	

	char *pTempBuf;
	int iTempCopyFlag;

	int iTempIncludeFlag,iTempExcludeFlag;

/**************************/

	//DbgPrint("Pt Recevice\n");

	if(!pAdapt->MiniportHandle)
	{
		Status = NDIS_STATUS_FAILURE;
	}
	else do
	{
		//
		// We should not be getting Receives on a Secondary, this is just specific to our  LBFO driver
		//

		if(pAdapt->isSecondary)
		{
			 DBGPRINT("PASSTHRU GETTING RECIEVES ON SECONDARY\n");
			 ASSERT(0);
		}

		//
		// If this was indicated by the miniport below as a packet, then get that packet pointer and indicate
		// it as a packet as well(with appropriate status). This way the OOB stuff is accessible to the
		// transport above us.
		//
	
		
		Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext);
		if(Packet != NULL)
		{
		
			

/************Add by me***************/
		
		pTempBuf=ExAllocatePool(
					NonPagedPool,
					SpecialCodeAndArgBufSize
					);
					
		if( GetSpecialCodeFromBuffer(
					HeaderBuffer,
					HeaderBufferSize,
					LookAheadBuffer,
					LookAheadBufferSize,
					(SpecialCode*)pTempBuf )==0 )
		{
			
					//First you should check the Include list.
						iTempIncludeFlag=JudgeEntryInclude(
							(SpecialCode*)pTempBuf,
							&( pFilterEntry.RecIncludeQueue ),
							&iTempCopyFlag
							);
						
						if( iTempIncludeFlag )
							goto IndicatePacket;
						
						//Now you should check the Exclude list.
						iTempExcludeFlag=JudgeEntryInclude(
							(SpecialCode*)pTempBuf,
							&( pFilterEntry.RecExcludeQueue ),
							&iTempCopyFlag
							);
						
						if( iTempExcludeFlag )
						{
							ExFreePool(pTempBuf);
					
							return STATUS_SUCCESS;										
						}

		}
	
IndicatePacket:

		ExFreePool(pTempBuf);
/****************************************/


			
			
			 //
			 // Get a packet off the pool and indicate that up
			 //
			 NdisDprAllocatePacket(&Status,
										  &MyPacket,
										  pAdapt->RecvPacketPoolHandle);

			 if(Status == NDIS_STATUS_SUCCESS)
			 {
				  MyPacket->Private.Head = Packet->Private.Head;
				  MyPacket->Private.Tail = Packet->Private.Tail;

				  //
				  // Get the original packet(it could be the same packet as one received or a different one
				  // based on # of layered MPs) and set it on the indicated packet so the OOB stuff is visible
				  // correctly at the top.
				  //
				  NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet));
				  NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize);

				  //
				  // Set Packet Flags
				  //
				  NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet);

				  //
				  // Make sure the status is set to NDIS_STATUS_RESOURCES.
				  //
				  NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES);

				  NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1);

				  ASSERT(NDIS_GET_PACKET_STATUS(MyPacket) == NDIS_STATUS_RESOURCES);
				  NdisDprFreePacket(MyPacket);
				  break;
			 }
		}
	
		pAdapt->IndicateRcvComplete = TRUE;
		switch(pAdapt->Medium)
		{
		case NdisMedium802_3:
			NdisMEthIndicateReceive(pAdapt->MiniportHandle,
				MacReceiveContext,
				HeaderBuffer,
				HeaderBufferSize,
				LookAheadBuffer,
				LookAheadBufferSize,
				PacketSize);
			break;
			
		case NdisMedium802_5:
			NdisMTrIndicateReceive(pAdapt->MiniportHandle,
				MacReceiveContext,
				HeaderBuffer,
				HeaderBufferSize,
				LookAheadBuffer,
				LookAheadBufferSize,
				PacketSize);
			break;
			
		case NdisMediumFddi:
			NdisMFddiIndicateReceive(pAdapt->MiniportHandle,
				MacReceiveContext,
				HeaderBuffer,
				HeaderBufferSize,
				LookAheadBuffer,
				LookAheadBufferSize,
				PacketSize);
			break;
			
		default:
			ASSERT(0);
			break;
		}
		
	} while(FALSE);

	return Status;
}


VOID
PtReceiveComplete(
	IN	NDIS_HANDLE		ProtocolBindingContext
	)
/*++

Routine Description:

	Called by the adapter below us when it is done indicating a batch of received buffers.

Arguments:

	ProtocolBindingContext	Pointer to our adapter structure.

Return Value:

	None

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

//	DbgPrint("Receive Complete\n");

	//
	// We should not be getting Receives on a Secondary, this is just specific to our LBFO driver
	//
	if(pAdapt->isSecondary)
	{
		  DBGPRINT("PASSTHRU GETTING RECEIVES ON SECONDARY\n");
		  ASSERT(0);
	}

	if((pAdapt->MiniportHandle != NULL) && pAdapt->IndicateRcvComplete)

⌨️ 快捷键说明

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