Hi all,

I am trying to build a packet to be received by netvmini adapter. In
initialization phrase, I allocate the packet buffer bool and packet
descripter pool:

//
// Allocate a buffer pool for receive buffers. by lchen
//
NdisAllocateBufferPool(
&Status,
&Adapter->RecvBufferPool,
1024 );

if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, ("NdisAllocateBufferPool for recv buffer
failed\n"));
break;
}


//
// Allocate packet pool for receive indications
//
NdisAllocatePacketPool(
&Status,
&Adapter->RecvPacketPool,
1024,
PROTOCOL_RESERVED_SIZE_IN_PACKET);

if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, ("NdisAllocatePacketPool failed\n"));
break;
}

When I build my packet triggered by the IoControl from my application, I
allocate memory, NDIS_BUFFER and NDIS_PACKET:

status = NdisAllocateMemoryWithTag( &pBufVA, uBufLen, NIC_TAG );
if( status != NDIS_STATUS_SUCCESS )
{
DEBUGP(MP_ERROR, ("Fail to allocate memory for the generated
packet.\n"));
break;
}
//
// Allocate packet buffer
//
NdisAllocateBuffer(
&status,
&pNdisBuffer,
pAdapter->RecvBufferPool,
pBufVA,
NIC_BUFFER_SIZE );

if(status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, ("NdisAllocateBuffer failed, status =
0x%x\n", status));
break;
}

//
// Allocate a packet descriptor for receive packets from a preallocated pool.
//
NdisAllocatePacket(
&status,
&MyPacket,
pAdapter->RecvPacketPool );

if( status != NDIS_STATUS_SUCCESS )
{
DEBUGP(MP_ERROR, ("NdisAllocatePacket failed, status = 0x%x\n",
status));
break;
}

NdisChainBufferAtFront( MyPacket, pNdisBuffer );

MyPacket->Private.Head->Next =NULL;
MyPacket->Private.Tail=NULL;


NdisMIndicateReceivePacket(
pAdapter->AdapterHandle,
&MyPacket,
1);


NdisFreeBuffer( pNdisBuffer );
pNdisBuffer = NULL;

NdisDprFreePacket(MyPacket);

However, the driver crashes due to the page fault error, when calling
NdisAllocatePacket(
&status,
&MyPacket,
pAdapter->RecvPacketPool );

How can I fix the bug?

Thanks!

-Liang

Re: Why I can not make a packet for NdisMIndicateReceive? by Thomas

Thomas
Tue Jan 03 08:53:49 CST 2006

Leave out thes two lines of code:

MyPacket->Private.Head->Next =NULL;
MyPacket->Private.Tail=NULL;

Thomas F. Divine



"Liang Chen" <LiangChen@discussions.microsoft.com> wrote in message
news:5BF72823-24E4-487F-BB57-A5E738569EF5@microsoft.com...
> Hi all,
>
> I am trying to build a packet to be received by netvmini adapter. In
> initialization phrase, I allocate the packet buffer bool and packet
> descripter pool:
>
> //
> // Allocate a buffer pool for receive buffers. by lchen
> //
> NdisAllocateBufferPool(
> &Status,
> &Adapter->RecvBufferPool,
> 1024 );
>
> if(Status != NDIS_STATUS_SUCCESS)
> {
> DEBUGP(MP_ERROR, ("NdisAllocateBufferPool for recv buffer
> failed\n"));
> break;
> }
>
>
> //
> // Allocate packet pool for receive indications
> //
> NdisAllocatePacketPool(
> &Status,
> &Adapter->RecvPacketPool,
> 1024,
> PROTOCOL_RESERVED_SIZE_IN_PACKET);
>
> if(Status != NDIS_STATUS_SUCCESS)
> {
> DEBUGP(MP_ERROR, ("NdisAllocatePacketPool failed\n"));
> break;
> }
>
> When I build my packet triggered by the IoControl from my application, I
> allocate memory, NDIS_BUFFER and NDIS_PACKET:
>
> status = NdisAllocateMemoryWithTag( &pBufVA, uBufLen, NIC_TAG );
> if( status != NDIS_STATUS_SUCCESS )
> {
> DEBUGP(MP_ERROR, ("Fail to allocate memory for the generated
> packet.\n"));
> break;
> }
> //
> // Allocate packet buffer
> //
> NdisAllocateBuffer(
> &status,
> &pNdisBuffer,
> pAdapter->RecvBufferPool,
> pBufVA,
> NIC_BUFFER_SIZE );
>
> if(status != NDIS_STATUS_SUCCESS)
> {
> DEBUGP(MP_ERROR, ("NdisAllocateBuffer failed, status =
> 0x%x\n", status));
> break;
> }
>
> //
> // Allocate a packet descriptor for receive packets from a preallocated
> pool.
> //
> NdisAllocatePacket(
> &status,
> &MyPacket,
> pAdapter->RecvPacketPool );
>
> if( status != NDIS_STATUS_SUCCESS )
> {
> DEBUGP(MP_ERROR, ("NdisAllocatePacket failed, status = 0x%x\n",
> status));
> break;
> }
>
> NdisChainBufferAtFront( MyPacket, pNdisBuffer );
>
> MyPacket->Private.Head->Next =NULL;
> MyPacket->Private.Tail=NULL;
>
>
> NdisMIndicateReceivePacket(
> pAdapter->AdapterHandle,
> &MyPacket,
> 1);
>
>
> NdisFreeBuffer( pNdisBuffer );
> pNdisBuffer = NULL;
>
> NdisDprFreePacket(MyPacket);
>
> However, the driver crashes due to the page fault error, when calling
> NdisAllocatePacket(
> &status,
> &MyPacket,
> pAdapter->RecvPacketPool );
>
> How can I fix the bug?
>
> Thanks!
>
> -Liang


Re: Why I can not make a packet for NdisMIndicateReceive? by LiangChen

LiangChen
Tue Jan 03 23:10:02 CST 2006

Hi Thomas,

Thanks for your response. I find my bug is introduced by the wrong pointer
of pAdpater when I call the IoDispatch function.

However, another problem arises for theNdisMIndicateReceivePacket().
Followed by the same code, I can capture my packet by netmonitor. However,
when the procedure repeats 3-4 times, the driver will crash at
nt!NtWaitForSingleObject+0x7b.

How can I solve the new problem?

Thanks!

-Liang

"Thomas F. Divine [DDK MVP]" wrote:

> Leave out thes two lines of code:
>
> MyPacket->Private.Head->Next =NULL;
> MyPacket->Private.Tail=NULL;
>
> Thomas F. Divine
>
>
>
> "Liang Chen" <LiangChen@discussions.microsoft.com> wrote in message
> news:5BF72823-24E4-487F-BB57-A5E738569EF5@microsoft.com...
> > Hi all,
> >
> > I am trying to build a packet to be received by netvmini adapter. In
> > initialization phrase, I allocate the packet buffer bool and packet
> > descripter pool:
> >
> > //
> > // Allocate a buffer pool for receive buffers. by lchen
> > //
> > NdisAllocateBufferPool(
> > &Status,
> > &Adapter->RecvBufferPool,
> > 1024 );
> >
> > if(Status != NDIS_STATUS_SUCCESS)
> > {
> > DEBUGP(MP_ERROR, ("NdisAllocateBufferPool for recv buffer
> > failed\n"));
> > break;
> > }
> >
> >
> > //
> > // Allocate packet pool for receive indications
> > //
> > NdisAllocatePacketPool(
> > &Status,
> > &Adapter->RecvPacketPool,
> > 1024,
> > PROTOCOL_RESERVED_SIZE_IN_PACKET);
> >
> > if(Status != NDIS_STATUS_SUCCESS)
> > {
> > DEBUGP(MP_ERROR, ("NdisAllocatePacketPool failed\n"));
> > break;
> > }
> >
> > When I build my packet triggered by the IoControl from my application, I
> > allocate memory, NDIS_BUFFER and NDIS_PACKET:
> >
> > status = NdisAllocateMemoryWithTag( &pBufVA, uBufLen, NIC_TAG );
> > if( status != NDIS_STATUS_SUCCESS )
> > {
> > DEBUGP(MP_ERROR, ("Fail to allocate memory for the generated
> > packet.\n"));
> > break;
> > }
> > //
> > // Allocate packet buffer
> > //
> > NdisAllocateBuffer(
> > &status,
> > &pNdisBuffer,
> > pAdapter->RecvBufferPool,
> > pBufVA,
> > NIC_BUFFER_SIZE );
> >
> > if(status != NDIS_STATUS_SUCCESS)
> > {
> > DEBUGP(MP_ERROR, ("NdisAllocateBuffer failed, status =
> > 0x%x\n", status));
> > break;
> > }
> >
> > //
> > // Allocate a packet descriptor for receive packets from a preallocated
> > pool.
> > //
> > NdisAllocatePacket(
> > &status,
> > &MyPacket,
> > pAdapter->RecvPacketPool );
> >
> > if( status != NDIS_STATUS_SUCCESS )
> > {
> > DEBUGP(MP_ERROR, ("NdisAllocatePacket failed, status = 0x%x\n",
> > status));
> > break;
> > }
> >
> > NdisChainBufferAtFront( MyPacket, pNdisBuffer );
> >
> > MyPacket->Private.Head->Next =NULL;
> > MyPacket->Private.Tail=NULL;
> >
> >
> > NdisMIndicateReceivePacket(
> > pAdapter->AdapterHandle,
> > &MyPacket,
> > 1);
> >
> >
> > NdisFreeBuffer( pNdisBuffer );
> > pNdisBuffer = NULL;
> >
> > NdisDprFreePacket(MyPacket);
> >
> > However, the driver crashes due to the page fault error, when calling
> > NdisAllocatePacket(
> > &status,
> > &MyPacket,
> > pAdapter->RecvPacketPool );
> >
> > How can I fix the bug?
> >
> > Thanks!
> >
> > -Liang
>
>

Re: Why I can not make a packet for NdisMIndicateReceive? by LiangChen

LiangChen
Tue Jan 03 23:40:02 CST 2006

To be clear, how does NDIS manager the packet? Should I release my allocated
packet by myself or NDIS will do this job by itself?

Thanks!

-Liang


"Liang Chen" wrote:

> Hi Thomas,
>
> Thanks for your response. I find my bug is introduced by the wrong pointer
> of pAdpater when I call the IoDispatch function.
>
> However, another problem arises for theNdisMIndicateReceivePacket().
> Followed by the same code, I can capture my packet by netmonitor. However,
> when the procedure repeats 3-4 times, the driver will crash at
> nt!NtWaitForSingleObject+0x7b.
>
> How can I solve the new problem?
>
> Thanks!
>
> -Liang
>
> "Thomas F. Divine [DDK MVP]" wrote:
>
> > Leave out thes two lines of code:
> >
> > MyPacket->Private.Head->Next =NULL;
> > MyPacket->Private.Tail=NULL;
> >
> > Thomas F. Divine
> >
> >
> >
> > "Liang Chen" <LiangChen@discussions.microsoft.com> wrote in message
> > news:5BF72823-24E4-487F-BB57-A5E738569EF5@microsoft.com...
> > > Hi all,
> > >
> > > I am trying to build a packet to be received by netvmini adapter. In
> > > initialization phrase, I allocate the packet buffer bool and packet
> > > descripter pool:
> > >
> > > //
> > > // Allocate a buffer pool for receive buffers. by lchen
> > > //
> > > NdisAllocateBufferPool(
> > > &Status,
> > > &Adapter->RecvBufferPool,
> > > 1024 );
> > >
> > > if(Status != NDIS_STATUS_SUCCESS)
> > > {
> > > DEBUGP(MP_ERROR, ("NdisAllocateBufferPool for recv buffer
> > > failed\n"));
> > > break;
> > > }
> > >
> > >
> > > //
> > > // Allocate packet pool for receive indications
> > > //
> > > NdisAllocatePacketPool(
> > > &Status,
> > > &Adapter->RecvPacketPool,
> > > 1024,
> > > PROTOCOL_RESERVED_SIZE_IN_PACKET);
> > >
> > > if(Status != NDIS_STATUS_SUCCESS)
> > > {
> > > DEBUGP(MP_ERROR, ("NdisAllocatePacketPool failed\n"));
> > > break;
> > > }
> > >
> > > When I build my packet triggered by the IoControl from my application, I
> > > allocate memory, NDIS_BUFFER and NDIS_PACKET:
> > >
> > > status = NdisAllocateMemoryWithTag( &pBufVA, uBufLen, NIC_TAG );
> > > if( status != NDIS_STATUS_SUCCESS )
> > > {
> > > DEBUGP(MP_ERROR, ("Fail to allocate memory for the generated
> > > packet.\n"));
> > > break;
> > > }
> > > //
> > > // Allocate packet buffer
> > > //
> > > NdisAllocateBuffer(
> > > &status,
> > > &pNdisBuffer,
> > > pAdapter->RecvBufferPool,
> > > pBufVA,
> > > NIC_BUFFER_SIZE );
> > >
> > > if(status != NDIS_STATUS_SUCCESS)
> > > {
> > > DEBUGP(MP_ERROR, ("NdisAllocateBuffer failed, status =
> > > 0x%x\n", status));
> > > break;
> > > }
> > >
> > > //
> > > // Allocate a packet descriptor for receive packets from a preallocated
> > > pool.
> > > //
> > > NdisAllocatePacket(
> > > &status,
> > > &MyPacket,
> > > pAdapter->RecvPacketPool );
> > >
> > > if( status != NDIS_STATUS_SUCCESS )
> > > {
> > > DEBUGP(MP_ERROR, ("NdisAllocatePacket failed, status = 0x%x\n",
> > > status));
> > > break;
> > > }
> > >
> > > NdisChainBufferAtFront( MyPacket, pNdisBuffer );
> > >
> > > MyPacket->Private.Head->Next =NULL;
> > > MyPacket->Private.Tail=NULL;
> > >
> > >
> > > NdisMIndicateReceivePacket(
> > > pAdapter->AdapterHandle,
> > > &MyPacket,
> > > 1);
> > >
> > >
> > > NdisFreeBuffer( pNdisBuffer );
> > > pNdisBuffer = NULL;
> > >
> > > NdisDprFreePacket(MyPacket);
> > >
> > > However, the driver crashes due to the page fault error, when calling
> > > NdisAllocatePacket(
> > > &status,
> > > &MyPacket,
> > > pAdapter->RecvPacketPool );
> > >
> > > How can I fix the bug?
> > >
> > > Thanks!
> > >
> > > -Liang
> >
> >

Re: Why I can not make a packet for NdisMIndicateReceive? by Thomas

Thomas
Wed Jan 04 00:34:07 CST 2006


"Liang Chen" <LiangChen@discussions.microsoft.com> wrote in message
news:171E35BE-D600-4FF1-A948-B50A9975D155@microsoft.com...
> To be clear, how does NDIS manager the packet? Should I release my
> allocated
> packet by myself or NDIS will do this job by itself?
>
> Thanks!
>
> -Liang
>
<Snip...>

Actually the DDK Help documentation for NDISMIndicateReceivePacket provides
the answer. Read it carefully.

The PassThru driver PtReceivePacket callback proovides the clearest example
of how to deal with asynchronous completion of a call to
NdisMIndicateReceivePacket. PassThru also includes other examples of calling
NdisMIndicateReceivePacket with immediate completion.

Good luck,

Thomas F. Divine, Windows DDL MVP
http://www.pcausa.com