Hi folks,

I find it is a little tricky to make a NDIS_PACKET by myself. I allocate
memory, write the content, allocate NDIS_BUFFER, NDIS_PACKET and chain the
NDIS_BUFFER into a packet. However, I don't know how to set the parameters
in NDIS_PACKET.

for example, I suppose the struct of _NDIS_PACKET_PRIVATE contains the
information of the packet.
typedef struct _NDIS_PACKET_PRIVATE
{
UINT PhysicalCount; // number of physical pages in packet.
UINT TotalLength; // Total amount of data in the packet.
PNDIS_BUFFER Head; // first buffer in the chain
PNDIS_BUFFER Tail; // last buffer in the chain

// if Head is NULL the chain is empty; Tail doesn't have to be NULL also

PNDIS_PACKET_POOL Pool; // so we know where to free it back to
UINT Count;
ULONG Flags;
BOOLEAN ValidCounts;
UCHAR NdisPacketFlags; // See fPACKET_xxx bits below
USHORT NdisPacketOobOffset;
} NDIS_PACKET_PRIVATE, * PNDIS_PACKET_PRIVATE;

And the functions could configure the parameters of my packet:
NDIS_SET_ORIGINAL_PACKET
NDIS_SET_PACKET_CANCEL_ID
NDIS_SET_PACKET_HEADER_SIZE
NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO
NDIS_SET_PACKET_STATUS

Unfortunately, there is few samples on how the set the parameters from
scratch. Could anyone here kindly give me a hint?

Thanks!

-Liang

RE: How to build a NDIS_PACKET for receiving? by pavel_a

pavel_a
Wed Jan 04 04:07:04 CST 2006

Have a look at this sample (file protocol.c)
http://www.wd-3.com/archive/ExtendingPassthru2.htm

--PA

"Liang Chen" wrote:
> Hi folks,
>
> I find it is a little tricky to make a NDIS_PACKET by myself. I allocate
> memory, write the content, allocate NDIS_BUFFER, NDIS_PACKET and chain the
> NDIS_BUFFER into a packet. However, I don't know how to set the parameters
> in NDIS_PACKET.
>
> for example, I suppose the struct of _NDIS_PACKET_PRIVATE contains the
> information of the packet.
> typedef struct _NDIS_PACKET_PRIVATE
> {
> UINT PhysicalCount; // number of physical pages in packet.
> UINT TotalLength; // Total amount of data in the packet.
> PNDIS_BUFFER Head; // first buffer in the chain
> PNDIS_BUFFER Tail; // last buffer in the chain
>
> // if Head is NULL the chain is empty; Tail doesn't have to be NULL also
>
> PNDIS_PACKET_POOL Pool; // so we know where to free it back to
> UINT Count;
> ULONG Flags;
> BOOLEAN ValidCounts;
> UCHAR NdisPacketFlags; // See fPACKET_xxx bits below
> USHORT NdisPacketOobOffset;
> } NDIS_PACKET_PRIVATE, * PNDIS_PACKET_PRIVATE;
>
> And the functions could configure the parameters of my packet:
> NDIS_SET_ORIGINAL_PACKET
> NDIS_SET_PACKET_CANCEL_ID
> NDIS_SET_PACKET_HEADER_SIZE
> NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO
> NDIS_SET_PACKET_STATUS
>
> Unfortunately, there is few samples on how the set the parameters from
> scratch. Could anyone here kindly give me a hint?
>
> Thanks!
>
> -Liang
>

RE: How to build a NDIS_PACKET for receiving? by LiangChen

LiangChen
Wed Jan 04 05:45:03 CST 2006

Hi Pavel,

I read the passthru sample as you refer to. However, there is a gap between
copying a packet and build a new packet.

In the PtReceive, the packet is allocated by
NdisDprAllocatePacket(&Status,
&MyPacket,
pAdapt->RecvPacketPoolHandle);

and configured by:
MyPacket->Private.Head = Packet->Private.Head;
MyPacket->Private.Tail = Packet->Private.Tail;
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);

Because I make my packet from scratch, I have no pervious knowledge on the
original packet.

Could you eleborate on the detail of NDIS_PACKET configuration?

Thanks

-Liang
"Pavel A." wrote:

> Have a look at this sample (file protocol.c)
> http://www.wd-3.com/archive/ExtendingPassthru2.htm
>
> --PA
>
> "Liang Chen" wrote:
> > Hi folks,
> >
> > I find it is a little tricky to make a NDIS_PACKET by myself. I allocate
> > memory, write the content, allocate NDIS_BUFFER, NDIS_PACKET and chain the
> > NDIS_BUFFER into a packet. However, I don't know how to set the parameters
> > in NDIS_PACKET.
> >
> > for example, I suppose the struct of _NDIS_PACKET_PRIVATE contains the
> > information of the packet.
> > typedef struct _NDIS_PACKET_PRIVATE
> > {
> > UINT PhysicalCount; // number of physical pages in packet.
> > UINT TotalLength; // Total amount of data in the packet.
> > PNDIS_BUFFER Head; // first buffer in the chain
> > PNDIS_BUFFER Tail; // last buffer in the chain
> >
> > // if Head is NULL the chain is empty; Tail doesn't have to be NULL also
> >
> > PNDIS_PACKET_POOL Pool; // so we know where to free it back to
> > UINT Count;
> > ULONG Flags;
> > BOOLEAN ValidCounts;
> > UCHAR NdisPacketFlags; // See fPACKET_xxx bits below
> > USHORT NdisPacketOobOffset;
> > } NDIS_PACKET_PRIVATE, * PNDIS_PACKET_PRIVATE;
> >
> > And the functions could configure the parameters of my packet:
> > NDIS_SET_ORIGINAL_PACKET
> > NDIS_SET_PACKET_CANCEL_ID
> > NDIS_SET_PACKET_HEADER_SIZE
> > NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO
> > NDIS_SET_PACKET_STATUS
> >
> > Unfortunately, there is few samples on how the set the parameters from
> > scratch. Could anyone here kindly give me a hint?
> >
> > Thanks!
> >
> > -Liang
> >

RE: How to build a NDIS_PACKET for receiving? by pavel_a

pavel_a
Wed Jan 04 11:27:03 CST 2006

Look also in the DDK ndisprot sample, send.c.
There it makes ndis packet form scratch as you want.
Basically, all it does is NdisChainBufferAtFront.

--PA