How to generate new copy of NDIS_PACKET?

Given code is working perfect to generate new copy of NDIS_PACKET,

NDIS_STATUS
CreateNewSendNdisPacket(IN NDIS_HANDLE SendPacketPoolHandle,
                        IN PNDIS_PACKET pkt_old,
                        IN PGUINT8 pkt_raw,
                        IN GUINT32 pkt_len,
                        OUT PNDIS_PACKET * pkt_new)
{
  NDIS_STATUS Status;
  NdisDprAllocatePacket(&Status, pkt_new, SendPacketPoolHandle);
  if(Status == NDIS_STATUS_SUCCESS)
  {
    PNDIS_BUFFER  MyBuffer;
    PSEND_RSVD    SendRsvd;

    SendRsvd = (PSEND_RSVD)((*pkt_new)->ProtocolReserved);
    SendRsvd->OriginalPkt = pkt_old;
    NdisAllocateBuffer(&Status, &MyBuffer, SendPacketPoolHandle, pkt_raw, pkt_len);
    if(Status == NDIS_STATUS_SUCCESS)
    {
      NdisChainBufferAtFront((*pkt_new), MyBuffer);
      (*pkt_new)->Private.Flags = NdisGetPacketFlags(pkt_old);
    }
  }
  return Status;
}

NDIS_STATUS
CreateNewRecvNdisPacket(IN NDIS_HANDLE RecvPacketPoolHandle,
                        IN PNDIS_PACKET pkt_old,
                        IN PGUINT8 pkt_raw,
                        IN GUINT32 pkt_len,
                        OUT PNDIS_PACKET * pkt_new)
{
  NDIS_STATUS Status;

  NdisDprAllocatePacket(&Status, pkt_new, RecvPacketPoolHandle);
  if(Status == NDIS_STATUS_SUCCESS)
  {
    PNDIS_BUFFER MyBuffer;
    PRECV_RSVD   RecvRsvd;

    RecvRsvd = (PSEND_RSVD)((*pkt_new)->MiniportReserved);
    RecvRsvd->OriginalPkt = pkt_old;

    NdisAllocateBuffer(&Status, &MyBuffer, RecvPacketPoolHandle, pkt_raw, pkt_len);
    if(Status == NDIS_STATUS_SUCCESS)
    {
      NdisChainBufferAtFront((*pkt_new), MyBuffer);
      (*pkt_new)->Private.Flags = NdisGetPacketFlags(pkt_old);
    }
  }
  return Status;
}

Don’t forget to delete memory after send complete. I have used above functions in PassThru example of NDIS-WDK.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s