whiteyoung
驱动牛犊
驱动牛犊
  • 注册日期2004-03-28
  • 最后登录2004-11-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1018回复:0

大家帮忙看看这段代码有问题吗?

楼主#
更多 发布于:2004-06-28 21:35
NDIS_STATUS
ProtocolReceive(
   IN NDIS_HANDLE hProtocolBindingContext,
   IN NDIS_HANDLE hMacReceiveContext,
   IN PVOID pvHeaderBuffer,
   IN UINT uiHeaderBufferSize,
   IN PVOID pvLookAheadBuffer,
   IN UINT uiLookAheadBufferSize,
   IN UINT uiPacketSize
   )
/*++

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.

--*/
{
   BINDING* pBinding = (BINDING*)hProtocolBindingContext;
   NDIS_PACKET* pRecvPacket;
   NDIS_PACKET* pPacket;
   NDIS_STATUS status = NDIS_STATUS_SUCCESS;


   //---added by yhy start---------------
   //int PacketSize = 0;
   PUCHAR pPacketContent;
   PNDIS_BUFFER pPacketBuffer;
   UINT PacketLen;
   int i;
   NDIS_PHYSICAL_ADDRESS HighestAcceptableMax =  NDIS_PHYSICAL_ADDRESS_CONST(-1,-1);
   int ipTotalLength=0,ipHeaderLength=0,tcpHeaderLen=0,tcpLen=0;
   PASSTHRU_PR_RECV* pProtocolRecv;
   //---added by yhy end---------------

   if (pBinding->hMPBinding == NULL) {
      status = NDIS_STATUS_FAILURE;
      goto cleanUp;
   }
  
   //
   // Get at the packet, if any, indicated up by the miniport below.
   //
   pRecvPacket = NdisGetReceivedPacket(
      pBinding->hPTBinding, hMacReceiveContext
   );

   if (pRecvPacket != NULL) {

  DBGPRINT(("ProtocolReceive : pRecvPacket != NULL"));
      //
      // 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

       status=NdisAllocateMemory(&pPacketContent,2000,0,HighestAcceptableMax);
if(status!=NDIS_STATUS_SUCCESS)
{
DbgPrint("PTReceive:NdisAllocateMemory Failedn");
return(NDIS_STATUS_NOT_ACCEPTED);
}
if(pPacketContent==NULL)
{
DbgPrint("PTReceive:pPacketContent==NULLn");
return(NDIS_STATUS_NOT_ACCEPTED);
}

NdisZeroMemory(pPacketContent,2000);
//NdisMoveMemory(pPacketContent,pvHeaderBuffer,uiHeaderBufferSize);
//NdisMoveMemory(pPacketContent+uiHeaderBufferSize,pvLookAheadBuffer,uiLookAheadBufferSize);
//PacketLen=uiPacketSize+uiHeaderBufferSize;

CopyPacket2Buffer(pRecvPacket,pPacketContent,&PacketLen);

if(pPacketContent[12] == 8 && pPacketContent[13] == 0 && pPacketContent[23] == 6)
{
ipTotalLength = (*(pPacketContent+16*sizeof(UCHAR))<<8) + *(pPacketContent+17*sizeof(UCHAR));
ipHeaderLength = ((USHORT)pPacketContent[14] - 64) * 32 / 8 ;
tcpHeaderLen = ((USHORT)pPacketContent[ipHeaderLength + 26]>>4) * 32 / 8 ;
tcpLen = ipTotalLength - ipHeaderLength;

if((tcpLen - tcpHeaderLen) > 0)
{
DbgPrint("PTReceive: tcp length = %d",(tcpLen - tcpHeaderLen));

DEAL_IN_PACKET(pPacketContent,TRUE);

}
}


      //
      // Get a packet off the pool and indicate that up
      //
      NdisAllocatePacket(&status, &pPacket, pBinding->hRecvPacketPool);
      if (status == NDIS_STATUS_SUCCESS) {
        
NdisAllocateBuffer(&status,&pPacketBuffer,pBinding->RecvBufferPoolHandle,pPacketContent,PacketLen);
NdisChainBufferAtFront(pPacket,pPacketBuffer);
pPacket->Private.Head->Next=NULL;
pPacket->Private.Tail=NULL;
pProtocolRecv = (PASSTHRU_PR_RECV*)(pPacket->MiniportReserved);
pProtocolRecv->pOriginalPacket = NULL;
NDIS_SET_PACKET_HEADER_SIZE(pPacket,uiHeaderBufferSize);

NdisSetPacketFlags(pPacket, NdisGetPacketFlags(pRecvPacket));
//
// Make sure the status is set to NDIS_STATUS_RESOURCES.
//
NDIS_SET_PACKET_STATUS(pPacket, NDIS_STATUS_RESOURCES);

NdisMIndicateReceivePacket(pBinding->hMPBinding, &pPacket, 1);

//ASSERT(NDIS_GET_PACKET_STATUS(pPacket) == NDIS_STATUS_RESOURCES);
NdisUnchainBufferAtFront(pPacket,&pPacketBuffer);
NdisFreeBuffer(pPacketBuffer);
NdisFreeMemory(pPacketContent,2000,0);
NdisFreePacket(pPacket);
        

         // We are done so exit
         goto cleanUp;
      }

   }

  
   //
   // Fall through if the miniport below us has either not
   // indicated a packet or we could not allocate one
   //
   pBinding->bIndicateRecvComplete = TRUE;
   switch (pBinding->medium) {

   case NdisMedium802_3:
   case NdisMediumWan:
      NdisMEthIndicateReceive(
         pBinding->hMPBinding, hMacReceiveContext, pvHeaderBuffer,
         uiHeaderBufferSize, pvLookAheadBuffer, uiLookAheadBufferSize,
         uiPacketSize
      );
      break;

   case NdisMedium802_5:
      NdisMTrIndicateReceive(
         pBinding->hMPBinding, hMacReceiveContext, pvHeaderBuffer,
         uiHeaderBufferSize, pvLookAheadBuffer, uiLookAheadBufferSize,
         uiPacketSize
      );
      break;

   case NdisMediumFddi:
      NdisMFddiIndicateReceive(
         pBinding->hMPBinding, hMacReceiveContext, pvHeaderBuffer,
         uiHeaderBufferSize, pvLookAheadBuffer, uiLookAheadBufferSize,
         uiPacketSize
      );
      break;

   default:
      ASSERT(0);
      break;
   }

cleanUp:
   return status;
}
游客

返回顶部