sbni
驱动牛犊
驱动牛犊
  • 注册日期2001-07-06
  • 最后登录2013-05-05
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望5点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
阅读:2038回复:7

高手帮忙看看。

楼主#
更多 发布于:2002-04-22 21:58
这是我的一段代码,在机器上运行非常稳定,高手帮忙看以下,有什么问题吗?(没想到的)

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;
PUCHAR pPacketContent;
PRSVD Rsvd;
UINT OffsetSize,Result,PacketLen;

PNDIS_BUFFER pPacketBuffer;
PNDIS_PACKET pBakPacket;
PNDIS_BUFFER pBakBuffer;

PUCHAR pBakContent;
UINT BufferLen;

DBGPRINT((\"In PtTransferDataComplete\\n\"));

//
// Returning the Send on the Primary, will point to itself if there is no LBFO
//
pAdapt = pAdapt->pPrimaryAdapt;
Rsvd =(PRSVD)(Packet->MiniportReserved);
pBakPacket=(PNDIS_PACKET)(Rsvd->OriginalPkt);

if(pAdapt->MiniportHandle)
{
if(pBakPacket==NULL)
NdisMTransferDataComplete(pAdapt->MiniportHandle,Packet,Status,BytesTransferred);
else
{
Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax);
CopyPacket2Buffer(pBakPacket,pPacketContent,&OffsetSize);
CopyPacket2Buffer(Packet,pPacketContent+OffsetSize,&PacketLen);
PacketLen+=OffsetSize;

NdisUnchainBufferAtFront(pBakPacket,&pBakBuffer);
NdisQueryBufferSafe(pBakBuffer,&pBakContent,&BufferLen,32);
NdisFreeBuffer(pBakBuffer);
NdisFreeMemory(pBakContent,BUFFER_SIZE,0);
NdisFreePacket(pBakPacket);

memset(Packet->MiniportReserved,0,sizeof(Packet->MiniportReserved));

NdisUnchainBufferAtFront(Packet,&pPacketBuffer);
NdisQueryBufferSafe(pPacketBuffer,&pBakContent,&BufferLen,32);
NdisFreeBuffer(pPacketBuffer);
NdisFreeMemory(pBakContent,BUFFER_SIZE,0);
NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketLen);
NdisChainBufferAtFront(Packet,pPacketBuffer);
Packet->Private.Head->Next=NULL;
Packet->Private.Tail=NULL;
NDIS_SET_PACKET_HEADER_SIZE(Packet,14);
NdisMIndicateReceivePacket(pAdapt->MiniportHandle,&Packet,1);
if(NDIS_GET_PACKET_STATUS(Packet)!=NDIS_STATUS_PENDING)
{
MPReturnPacket((NDIS_HANDLE)pAdapt,Packet);
}
}
}
return;
}


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 OutAdapt,pAdapt =(PADAPT)ProtocolBindingContext;
PNDIS_PACKET MyPacket, Packet,MyPacket1;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;

/* PUCHAR pEnetAddrDest=NULL;
UINT nDataSize=0,i;
PNDIS_BUFFER pNdisBuffer=NULL;
UCHAR *BufferVa=NULL;

PMACHEADER pMACHeader=NULL;
PIPHEADER pIPHeader=NULL;
PICMPHEADER pICMPHeader=NULL;
PTCPHEADER pTCPHeader=NULL;
PUDPHEADER pUDPHeader=NULL;
*/

PNDIS_BUFFER pPacketBuffer,pBakBuffer;
PUCHAR pPacketContent,pBakContent;
UINT PacketLen;

UINT OffsetSize;
UINT BytesTransferred;

PRSVD Rsvd=NULL;
PVOID MediaSpecificInfo=NULL;
ULONG MediaSpecificSize=0;

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)
{
//
// 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;
}
}

//
// Fall through if the miniport below us has either not indicated a packet or we could not
// allocate one
//
else if(PacketSize<=LookAheadBufferSize)
{
Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax);
if(Status!=NDIS_STATUS_SUCCESS)
{
DbgPrint(\"PTReceive:NdisAllocateMemory Failed\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
if(pPacketContent==NULL)
{
DbgPrint(\"PTReceive:pPacketContent==NULL\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}

NdisZeroMemory(pPacketContent,BUFFER_SIZE);
NdisMoveMemory(pPacketContent,HeaderBuffer,HeaderBufferSize);
NdisMoveMemory(pPacketContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize);
PacketLen=PacketSize+HeaderBufferSize;

NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle);

if(Status==NDIS_STATUS_SUCCESS)
{
NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketLen);
NdisChainBufferAtFront(MyPacket,pPacketBuffer);
MyPacket->Private.Head->Next=NULL;
MyPacket->Private.Tail=NULL;
Rsvd=(PRSVD)(MyPacket->MiniportReserved);
Rsvd->OriginalPkt=NULL;
NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize);
NdisMIndicateReceivePacket(pAdapt->MiniportHandle,&MyPacket,1);
if(NDIS_GET_PACKET_STATUS(MyPacket)!=NDIS_STATUS_PENDING)
{
DBGPRINT((\"In PtReceive And Free Memory\\n\"));
NdisFreeBuffer(pPacketBuffer);
NdisFreeMemory(pPacketContent,BUFFER_SIZE,0);
NdisDprFreePacket(MyPacket);
}
}
break;
}
else
{
Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax);
if(Status!=NDIS_STATUS_SUCCESS)
{
DbgPrint(\"PtReceive:NdisAllocateMemory Failed.\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
if(pPacketContent==NULL)
{
DbgPrint(\"PTReceive:pPacketContent==NULL\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
NdisZeroMemory(pPacketContent,BUFFER_SIZE);

NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle);

Status=NdisAllocateMemory(&pBakContent,BUFFER_SIZE,0,HighestAcceptableMax);
if(Status!=NDIS_STATUS_SUCCESS)
{
DbgPrint(\"PtReceive:NdisAllocateMemory Failed.\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
if(pBakContent==NULL)
{
DbgPrint(\"PTReceive:pPacketContent==NULL\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
NdisZeroMemory(pBakContent,BUFFER_SIZE);
NdisMoveMemory(pBakContent,HeaderBuffer,HeaderBufferSize);
NdisMoveMemory(pBakContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize);
PacketLen=HeaderBufferSize+PacketSize;
NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketSize-LookAheadBufferSize);

NdisChainBufferAtFront(MyPacket,pPacketBuffer);
MyPacket->Private.Head->Next=NULL;
MyPacket->Private.Tail=NULL;

OffsetSize=HeaderBufferSize+LookAheadBufferSize;

NdisDprAllocatePacket(&Status,&MyPacket1,pAdapt->RecvPacketPoolHandle);
NdisAllocateBuffer(&Status,&pBakBuffer,pAdapt->RecvBufferPoolHandle,pBakContent,OffsetSize);
NdisChainBufferAtFront(MyPacket1,pBakBuffer);

Rsvd=(PRSVD)(MyPacket->MiniportReserved);
Rsvd->OriginalPkt=(PNDIS_PACKET)MyPacket1;

NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize);

NdisTransferData(&Status,pAdapt->BindingHandle,MacReceiveContext,LookAheadBufferSize,PacketSize-LookAheadBufferSize,MyPacket,&BytesTransferred);

if(Status!=NDIS_STATUS_PENDING)
{
PtTransferDataComplete((NDIS_HANDLE)pAdapt,MyPacket,Status,BytesTransferred);
}
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);

DBGPRINT((\"In PtReceive\\n\"));

return Status;
}

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

Routine Description:


Arguments:


Return Value:


--*/
{
PADAPT pAdapt = (PADAPT)MiniportAdapterContext;
PNDIS_PACKET MyPacket;
PRSVD Resvd;
PNDIS_BUFFER pNdisBuffer;
PUCHAR pPacketContent;
UINT BufferLen;

Resvd = (PRSVD)(Packet->MiniportReserved);
MyPacket = Resvd->OriginalPkt;

if(MyPacket)
{
NdisFreePacket(Packet);
NdisReturnPackets(&MyPacket, 1);
}
/*=========================================================================
I Add This Code for NdisIndicateReceivePacket
=========================================================================*/
else
{
DBGPRINT((\"In MPReturnPacket And Free Memory\\n\"));
NdisUnchainBufferAtFront(Packet,&pNdisBuffer);
NdisQueryBufferSafe(pNdisBuffer,(PVOID *)&pPacketContent,&BufferLen,32);
NdisFreeBuffer(pNdisBuffer);
NdisFreeMemory(pPacketContent,BUFFER_SIZE,0);
NdisFreePacket(Packet);
DBGPRINT((\"In MPReturnPacket And Free Memory\\n\"));
}
}

最新喜欢:

moqingsongmoqing... znsoftznsoft
sbni
驱动牛犊
驱动牛犊
  • 注册日期2001-07-06
  • 最后登录2013-05-05
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望5点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-04-24 12:55
补充函数
void CopyPacket2Buffer(IN PNDIS_PACKET pPacket,IN OUT PUCHAR pBuff,IN OUT PUINT pLength)
{
PNDIS_BUFFER BuffDT;
PUCHAR BuffVA;
UINT BuffLen;

*pLength=0;
BuffLen=0;

NdisQueryPacket(pPacket,NULL,NULL,&BuffDT,NULL);

while(BuffDT!=(PNDIS_BUFFER)NULL)
{
NdisQueryBuffer(BuffDT,&BuffVA,&BuffLen);
NdisMoveMemory(pBuff,BuffVA,BuffLen);
pBuff=pBuff+BuffLen;
*pLength+=BuffLen;
NdisGetNextBuffer(BuffDT,&BuffDT);
}
return;
}
Zer0
驱动牛犊
驱动牛犊
  • 注册日期2002-04-26
  • 最后登录2002-10-08
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-06-11 16:26
请问PRSVD和PADAPT是如何定义的,PADAPT的定义和PASSTHRU里的定义好像不太一样?
请指点,多谢!
HuYuguang
论坛版主
论坛版主
  • 注册日期2001-04-25
  • 最后登录2013-04-29
  • 粉丝3
  • 关注1
  • 积分92分
  • 威望11点
  • 贡献值0点
  • 好评度9点
  • 原创分1分
  • 专家分0分
地板#
发布于:2002-06-11 17:23
老弟,我想冒昧问一句,你这段代码是从哪里来的?
从军队的某个单位?

我想说的是,如果不是的话,那么巧合实在太多,包括
一些历史遗留的bug,以及一些特有的变量命名习惯。

我大致看了看,第一个函数每一行都几乎完全一样。
包括变量名称。



这是我的一段代码,在机器上运行非常稳定,高手帮忙看以下,有什么问题吗?(没想到的)

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;
PUCHAR pPacketContent;
PRSVD Rsvd;
UINT OffsetSize,Result,PacketLen;

PNDIS_BUFFER pPacketBuffer;
PNDIS_PACKET pBakPacket;
PNDIS_BUFFER pBakBuffer;

PUCHAR pBakContent;
UINT BufferLen;

DBGPRINT((\"In PtTransferDataComplete\\n\"));

//
// Returning the Send on the Primary, will point to itself if there is no LBFO
//
pAdapt = pAdapt->pPrimaryAdapt;
Rsvd =(PRSVD)(Packet->MiniportReserved);
pBakPacket=(PNDIS_PACKET)(Rsvd->OriginalPkt);

if(pAdapt->MiniportHandle)
{
if(pBakPacket==NULL)
NdisMTransferDataComplete(pAdapt->MiniportHandle,Packet,Status,BytesTransferred);
else
{
Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax);
CopyPacket2Buffer(pBakPacket,pPacketContent,&OffsetSize);
CopyPacket2Buffer(Packet,pPacketContent+OffsetSize,&PacketLen);
PacketLen+=OffsetSize;

NdisUnchainBufferAtFront(pBakPacket,&pBakBuffer);
NdisQueryBufferSafe(pBakBuffer,&pBakContent,&BufferLen,32);
NdisFreeBuffer(pBakBuffer);
NdisFreeMemory(pBakContent,BUFFER_SIZE,0);
NdisFreePacket(pBakPacket);

memset(Packet->MiniportReserved,0,sizeof(Packet->MiniportReserved));

NdisUnchainBufferAtFront(Packet,&pPacketBuffer);
NdisQueryBufferSafe(pPacketBuffer,&pBakContent,&BufferLen,32);
NdisFreeBuffer(pPacketBuffer);
NdisFreeMemory(pBakContent,BUFFER_SIZE,0);
NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketLen);
NdisChainBufferAtFront(Packet,pPacketBuffer);
Packet->Private.Head->Next=NULL;
Packet->Private.Tail=NULL;
NDIS_SET_PACKET_HEADER_SIZE(Packet,14);
NdisMIndicateReceivePacket(pAdapt->MiniportHandle,&Packet,1);
if(NDIS_GET_PACKET_STATUS(Packet)!=NDIS_STATUS_PENDING)
{
MPReturnPacket((NDIS_HANDLE)pAdapt,Packet);
}
}
}
return;
}


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 OutAdapt,pAdapt =(PADAPT)ProtocolBindingContext;
PNDIS_PACKET MyPacket, Packet,MyPacket1;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;

/* PUCHAR pEnetAddrDest=NULL;
UINT nDataSize=0,i;
PNDIS_BUFFER pNdisBuffer=NULL;
UCHAR *BufferVa=NULL;

PMACHEADER pMACHeader=NULL;
PIPHEADER pIPHeader=NULL;
PICMPHEADER pICMPHeader=NULL;
PTCPHEADER pTCPHeader=NULL;
PUDPHEADER pUDPHeader=NULL;
*/

PNDIS_BUFFER pPacketBuffer,pBakBuffer;
PUCHAR pPacketContent,pBakContent;
UINT PacketLen;

UINT OffsetSize;
UINT BytesTransferred;

PRSVD Rsvd=NULL;
PVOID MediaSpecificInfo=NULL;
ULONG MediaSpecificSize=0;

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)
{
//
// 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;
}
}

//
// Fall through if the miniport below us has either not indicated a packet or we could not
// allocate one
//
else if(PacketSize<=LookAheadBufferSize)
{
Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax);
if(Status!=NDIS_STATUS_SUCCESS)
{
DbgPrint(\"PTReceive:NdisAllocateMemory Failed\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
if(pPacketContent==NULL)
{
DbgPrint(\"PTReceive:pPacketContent==NULL\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}

NdisZeroMemory(pPacketContent,BUFFER_SIZE);
NdisMoveMemory(pPacketContent,HeaderBuffer,HeaderBufferSize);
NdisMoveMemory(pPacketContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize);
PacketLen=PacketSize+HeaderBufferSize;

NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle);

if(Status==NDIS_STATUS_SUCCESS)
{
NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketLen);
NdisChainBufferAtFront(MyPacket,pPacketBuffer);
MyPacket->Private.Head->Next=NULL;
MyPacket->Private.Tail=NULL;
Rsvd=(PRSVD)(MyPacket->MiniportReserved);
Rsvd->OriginalPkt=NULL;
NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize);
NdisMIndicateReceivePacket(pAdapt->MiniportHandle,&MyPacket,1);
if(NDIS_GET_PACKET_STATUS(MyPacket)!=NDIS_STATUS_PENDING)
{
DBGPRINT((\"In PtReceive And Free Memory\\n\"));
NdisFreeBuffer(pPacketBuffer);
NdisFreeMemory(pPacketContent,BUFFER_SIZE,0);
NdisDprFreePacket(MyPacket);
}
}
break;
}
else
{
Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax);
if(Status!=NDIS_STATUS_SUCCESS)
{
DbgPrint(\"PtReceive:NdisAllocateMemory Failed.\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
if(pPacketContent==NULL)
{
DbgPrint(\"PTReceive:pPacketContent==NULL\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
NdisZeroMemory(pPacketContent,BUFFER_SIZE);

NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle);

Status=NdisAllocateMemory(&pBakContent,BUFFER_SIZE,0,HighestAcceptableMax);
if(Status!=NDIS_STATUS_SUCCESS)
{
DbgPrint(\"PtReceive:NdisAllocateMemory Failed.\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
if(pBakContent==NULL)
{
DbgPrint(\"PTReceive:pPacketContent==NULL\\n\");
return(NDIS_STATUS_NOT_ACCEPTED);
}
NdisZeroMemory(pBakContent,BUFFER_SIZE);
NdisMoveMemory(pBakContent,HeaderBuffer,HeaderBufferSize);
NdisMoveMemory(pBakContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize);
PacketLen=HeaderBufferSize+PacketSize;
NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketSize-LookAheadBufferSize);

NdisChainBufferAtFront(MyPacket,pPacketBuffer);
MyPacket->Private.Head->Next=NULL;
MyPacket->Private.Tail=NULL;

OffsetSize=HeaderBufferSize+LookAheadBufferSize;

NdisDprAllocatePacket(&Status,&MyPacket1,pAdapt->RecvPacketPoolHandle);
NdisAllocateBuffer(&Status,&pBakBuffer,pAdapt->RecvBufferPoolHandle,pBakContent,OffsetSize);
NdisChainBufferAtFront(MyPacket1,pBakBuffer);

Rsvd=(PRSVD)(MyPacket->MiniportReserved);
Rsvd->OriginalPkt=(PNDIS_PACKET)MyPacket1;

NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize);

NdisTransferData(&Status,pAdapt->BindingHandle,MacReceiveContext,LookAheadBufferSize,PacketSize-LookAheadBufferSize,MyPacket,&BytesTransferred);

if(Status!=NDIS_STATUS_PENDING)
{
PtTransferDataComplete((NDIS_HANDLE)pAdapt,MyPacket,Status,BytesTransferred);
}
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);

DBGPRINT((\"In PtReceive\\n\"));

return Status;
}

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

Routine Description:


Arguments:


Return Value:


--*/
{
PADAPT pAdapt = (PADAPT)MiniportAdapterContext;
PNDIS_PACKET MyPacket;
PRSVD Resvd;
PNDIS_BUFFER pNdisBuffer;
PUCHAR pPacketContent;
UINT BufferLen;

Resvd = (PRSVD)(Packet->MiniportReserved);
MyPacket = Resvd->OriginalPkt;

if(MyPacket)
{
NdisFreePacket(Packet);
NdisReturnPackets(&MyPacket, 1);
}
/*=========================================================================
I Add This Code for NdisIndicateReceivePacket
=========================================================================*/
else
{
DBGPRINT((\"In MPReturnPacket And Free Memory\\n\"));
NdisUnchainBufferAtFront(Packet,&pNdisBuffer);
NdisQueryBufferSafe(pNdisBuffer,(PVOID *)&pPacketContent,&BufferLen,32);
NdisFreeBuffer(pNdisBuffer);
NdisFreeMemory(pPacketContent,BUFFER_SIZE,0);
NdisFreePacket(Packet);
DBGPRINT((\"In MPReturnPacket And Free Memory\\n\"));
}
}
 
不再回忆从前,我已经生活在幸福当中。
fenger_li
驱动老牛
驱动老牛
  • 注册日期2002-03-26
  • 最后登录2005-04-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2002-06-12 08:24
好眼熟呀,嗬嗬!
有点意思。。。 呵呵!
Zer0
驱动牛犊
驱动牛犊
  • 注册日期2002-04-26
  • 最后登录2002-10-08
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2002-06-12 09:26
to Huyg:
他好像在另一张帖子中说是从你的代码中修改的,另一篇帖子有人问起过这个问题。
moqingsong
论坛版主
论坛版主
  • 注册日期2002-04-07
  • 最后登录2011-02-03
  • 粉丝0
  • 关注0
  • 积分74分
  • 威望71点
  • 贡献值0点
  • 好评度10点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2002-06-12 17:19
对MPReturnPacket的处理好象有点不充分。
另外,当出现else if(PacketSize<=LookAheadBufferSize)的情况时似乎也不会很顺利。
按第一贴的“给分”键,给分。
sirroom
驱动大牛
驱动大牛
  • 注册日期2001-07-30
  • 最后登录2018-05-29
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望11点
  • 贡献值1点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2002-06-12 18:10
怎么这张贴子又翻出来了,他不是说过就是用的版主贴出来的代码?
111
游客

返回顶部