Ejemplo n.º 1
0
NDIS_STATUS
	natpReceive(
		IN  NDIS_HANDLE	ProtocolBindingContext,
		IN  NDIS_HANDLE	MacReceiveContext,
		IN  PVOID		HeaderBuffer,
		IN  UINT		HeaderBufferSize,
		IN  PVOID		LookAheadBuffer,
		IN  UINT		LookAheadBufferSize,
		IN  UINT		PacketSize
		)
{
	PFILTER_ADAPTER	pAdapt;
	PNDIS_PACKET Packet;
	NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
	NDIS_STATUS PacketStatus;
	PNDIS_PACKET pNewPacket;
	ULONG nDataSize;
	FLT_PKT *pFltPkt;
	PNDIS_BUFFER pNewBuffer;

	pAdapt = (PFILTER_ADAPTER)ProtocolBindingContext;

	if ((!pAdapt->MiniportHandle) || (pAdapt->natmDeviceState > NdisDeviceStateD0)){
		return NDIS_STATUS_FAILURE;
	}

	nDataSize = HeaderBufferSize + PacketSize;
	if ( nDataSize > MAX_ETHER_SIZE ){
		return NDIS_STATUS_FAILURE;
	}

	Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext);
	if (NULL == Packet)
		return NDIS_STATUS_NOT_ACCEPTED;

	pFltPkt = AllocateFltPacket();
	if(NULL == pFltPkt)
		return NDIS_STATUS_NOT_ACCEPTED;

	if(!natbParsePacket(Packet, pFltPkt)){

		if(g_LogPktDrop) PrintFtlPkt("DROP ", pFltPkt, 0, FALSE);
		FreeFltPkt(pFltPkt);
		return NDIS_STATUS_NOT_ACCEPTED;
	}

	//
	// Translate
	//
	TranslatePktIncoming(&pAdapt->ctrl, pFltPkt);

	//
	// Filter
	//
	if(!FilterPkt(&pAdapt->ctrl, pFltPkt, FALSE)){

		if(g_LogPktDrop) PrintFtlPkt("DROP ", pFltPkt, 0, FALSE);
		FreeFltPkt(pFltPkt);
		return NDIS_STATUS_NOT_ACCEPTED;
	}

	if(g_LogPktPass) PrintFtlPkt("PASS ", pFltPkt, 0, FALSE);

	if(NULL == pFltPkt->pBuf){

		FreeFltPkt(pFltPkt);
		pFltPkt = NULL;

		NdisDprAllocatePacket(
			&Status,
			&pNewPacket,
			pAdapt->RcvPP1
			);

		if (Status != NDIS_STATUS_SUCCESS)
		{
			return NDIS_STATUS_NOT_ACCEPTED;
		}

		*((PVOID*)&pNewPacket->MiniportReserved) = NULL;

		pNewPacket->Private.Head = Packet->Private.Head;
		pNewPacket->Private.Tail = Packet->Private.Tail;

	}else{

		NdisDprAllocatePacket(
			&Status,
			&pNewPacket,
			pAdapt->RcvPP2
			);

		if (Status != NDIS_STATUS_SUCCESS)
			return NDIS_STATUS_NOT_ACCEPTED;

		*((PVOID*)&pNewPacket->MiniportReserved) = pFltPkt;

		NdisAllocateBuffer(
			&Status,
			&pNewBuffer,
			pAdapt->RcvBP,
			pFltPkt->pBuf,
			pFltPkt->uLen
			);

		if ( Status != NDIS_STATUS_SUCCESS ){

			NdisReinitializePacket (pNewPacket);
			NdisFreePacket (pNewPacket);

			return NDIS_STATUS_NOT_ACCEPTED;
		}

		NdisChainBufferAtFront(pNewPacket, pNewBuffer );
	}

	NdisGetPacketFlags(pNewPacket) = NdisGetPacketFlags(Packet);

	NDIS_SET_PACKET_STATUS(pNewPacket, NDIS_STATUS_RESOURCES);

	NDIS_SET_ORIGINAL_PACKET(pNewPacket, NDIS_GET_ORIGINAL_PACKET(Packet));
	NDIS_SET_PACKET_HEADER_SIZE(pNewPacket, HeaderBufferSize);

	natpQueueReceivedPacket(pAdapt, pNewPacket, TRUE);

	natmReturnPacket(
		ProtocolBindingContext,
		pNewPacket
		);

	return Status;
}
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:

	Handle receive data indicated up by the miniport below. We pass
	it along to the protocol above us.

	If the miniport below indicates packets, NDIS would more
	likely call us at our ReceivePacket handler. However we
	might be called here in certain situations even though
	the miniport below has indicated a receive packet, e.g.
	if the miniport had set packet status to NDIS_STATUS_RESOURCES.
		
Arguments:

	<see DDK ref page for ProtocolReceive>
Return Value:

	NDIS_STATUS_SUCCESS if we processed the receive successfully,
	NDIS_STATUS_XXX error code if we discarded it.

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

	if (!pAdapt->MiniportHandle)
	{
		Status = NDIS_STATUS_FAILURE;
	}
	else do
	{
		//
		// Get at the packet, if any, indicated up by the miniport below.
		//
		Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext);
		if (Packet != NULL)
		{
			//------------------------------WestChamber---------------------------------
			BOOLEAN result=WestChamberReceiverMain(Packet,pAdapt);
			if(result==FALSE) {
				//Simply drop the packet.
				return NDIS_STATUS_NOT_ACCEPTED;
			}
			//------------------------------WestChamber---------------------------------
		    //
		    // The miniport below did indicate up a packet. Use information
		    // from that packet to construct a new packet to indicate up.
		    //

#ifdef NDIS51
			//
			// NDIS 5.1 NOTE: Do not reuse the original packet in indicating
			// up a receive, even if there is sufficient packet stack space.
			// If we had to do so, we would have had to overwrite the
			// status field in the original packet to NDIS_STATUS_RESOURCES,
			// and it is not allowed for protocols to overwrite this field
			// in received packets.
			//
#endif // NDIS51

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

			if (Status == NDIS_STATUS_SUCCESS)
			{
				//
				// Make our packet point to data from the original
				// packet. NOTE: this works only because we are
				// indicating a receive directly from the context of
				// our receive indication. If we need to queue this
				// packet and indicate it from another thread context,
				// we will also have to allocate a new buffer and copy
				// over the packet contents, OOB data and per-packet
				// information. This is because the packet data
				// is available only for the duration of this
				// receive indication call.
				//
				MyPacket->Private.Head = Packet->Private.Head;
				MyPacket->Private.Tail = Packet->Private.Tail;

				//
				// Get the original packet (it could be the same packet as the
				// one received or a different one based on the number of layered
				// miniports below) and set it on the indicated packet so the OOB
				// data is visible correctly at protocols above.
				//
				NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet));
				NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize);

				//
				// Copy packet flags.
				//
				NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet);

				//
				// Force protocols above to make a copy if they want to hang
				// on to data in this packet. This is because we are in our
				// Receive handler (not ReceivePacket) and we can't return a
				// ref count from here.
				//
				NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES);

				//
				// By setting NDIS_STATUS_RESOURCES, we also know that we can reclaim
				// this packet as soon as the call to NdisMIndicateReceivePacket
				// returns.
				//

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

				//
				// Reclaim the indicated packet. Since we had set its status
				// to NDIS_STATUS_RESOURCES, we are guaranteed that protocols
				// above are done with it.
				//
				NdisDprFreePacket(MyPacket);

				break;
			}
		}
		else
		{
			//
			// The miniport below us uses the old-style (not packet)
			// receive indication. Fall through.
			//
		}

		//
		// Fall through if the miniport below us has either not
		// indicated a packet or we could not allocate one
		//
		pAdapt->IndicateRcvComplete = TRUE;
		switch (pAdapt->Medium)
		{
		  case NdisMedium802_3:
		  case NdisMediumWan:
			 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(FALSE);
			 break;
		}

	} while(FALSE);

	return Status;
}