Ndis IM deviceIOcontrol

Hi,

I’m working on an NDIS IM. I’ve generated an IP packet complete with all
the
headers for a particular destination and sent it down to NDIS IM using
deviceIOcontrol. In the NDIS IM, I pack the IP Packet accordingly and sent
it out through the LAN. The destination is able to receive the IP packet
correctly. However at my source, my NDIS, after completing the irp via
IoCompleteRequest, gave me the blue screen. The bug check code is C9
(DRIVER_VERIFIER_IOMANAGER_VIOLATION) P1=5, P2=some address, P3=0, P4=2.

The sendcomplete routine has not been entered yet so I guess it is not a
result of mine calling ndissendcomplete for my packet. I’ve also make sure
that will not happen.

What is the reason for the bug check? What could have raise my IRQL to 2?
Thanks.

Regards
Hau Shian

> What could have raise my IRQL to 2?

The answer is in you dispatch routine. Did you acquire a spinlock and forget
to release?
Or did you call a function that raises the IRQL but forget to undo it before
returning from your dispatch routine?

Calvin Guan (Windows DDK MVP)
Staff SW Engineer NetXtreme MINIPORT
Broadcom Corp. Irvine, CA
www.broadcom.com

I called NdisReleaseSpinLock() before I call IoCompleteRequest. When I send
a text string down, it is fine. When I indicate an IP packet up the TCP/IP
stack (using the same IO code), it is ok. However, when I try to send the IP
packet out, then it happened.

The code for sending the ip packet out is
1)NdisAllocatePacket()
2)NdisAllocateMemorywithTag()
3)NdisAllocateBuffer
4)NdisMoveMemory() - copy the entire ip packet to the buffer
5)NDIS_SET_PACKET_STATUS(Mypacket, NDIS_STATUS_RESOURCE)
6)NdisSend()
7)free buffer, free memory and free packet if status is NDIS_STATUS_RESOURCE

This part of the code exit properly.

Thanks.

----- Original Message -----
From: “Calvin Guan”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, July 19, 2005 3:43 PM
Subject: Re: [ntdev] Ndis IM deviceIOcontrol

>> What could have raise my IRQL to 2?
>
> The answer is in you dispatch routine. Did you acquire a spinlock and
> forget to release?
> Or did you call a function that raises the IRQL but forget to undo it
> before returning from your dispatch routine?
>
> Calvin Guan (Windows DDK MVP)
> Staff SW Engineer NetXtreme MINIPORT
> Broadcom Corp. Irvine, CA
> www.broadcom.com
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@singnet.com.sg
> To unsubscribe send a blank email to xxxxx@lists.osr.com

To clarify. The IP packet is generated by my user application. I’ve used the
same piece of code to indicate up and to send out. To indicate up, I use
NdisMIndicateReceivePacket() . That works fine. Next, I simply modify the
code from NdisMIndicateReceivePacket() to NdisSend(). Then I encountered the
blue screen. My destination receives the packet perfectly all right though.

What I don’t understand is why would this fail when NdisSend is called but
not NdisMIndicateReceivePacket? How do I go about fixing this? Thanks.

----- Original Message -----
From: “Wong Hau Shian”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, July 19, 2005 4:08 PM
Subject: Re: [ntdev] Ndis IM deviceIOcontrol

>I called NdisReleaseSpinLock() before I call IoCompleteRequest. When I send
>a text string down, it is fine. When I indicate an IP packet up the TCP/IP
>stack (using the same IO code), it is ok. However, when I try to send the
>IP packet out, then it happened.
>
> The code for sending the ip packet out is
> 1)NdisAllocatePacket()
> 2)NdisAllocateMemorywithTag()
> 3)NdisAllocateBuffer
> 4)NdisMoveMemory() - copy the entire ip packet to the buffer
> 5)NDIS_SET_PACKET_STATUS(Mypacket, NDIS_STATUS_RESOURCE)
> 6)NdisSend()
> 7)free buffer, free memory and free packet if status is
> NDIS_STATUS_RESOURCE
>
> This part of the code exit properly.
>
> Thanks.
>
>
> ----- Original Message -----
> From: “Calvin Guan”
> To: “Windows System Software Devs Interest List”
> Sent: Tuesday, July 19, 2005 3:43 PM
> Subject: Re: [ntdev] Ndis IM deviceIOcontrol
>
>
>>> What could have raise my IRQL to 2?
>>
>> The answer is in you dispatch routine. Did you acquire a spinlock and
>> forget to release?
>> Or did you call a function that raises the IRQL but forget to undo it
>> before returning from your dispatch routine?
>>
>> Calvin Guan (Windows DDK MVP)
>> Staff SW Engineer NetXtreme MINIPORT
>> Broadcom Corp. Irvine, CA
>> www.broadcom.com
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: xxxxx@singnet.com.sg
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@singnet.com.sg
> To unsubscribe send a blank email to xxxxx@lists.osr.com

“Wong Hau Shian” wrote in message
news:xxxxx@ntdev…
>I called NdisReleaseSpinLock() before I call IoCompleteRequest. When I send
>a text string down, it is fine. When I indicate an IP packet up the TCP/IP
>stack (using the same IO code), it is ok. However, when I try to send the
>IP packet out, then it happened.
>
> The code for sending the ip packet out is
> 1)NdisAllocatePacket()
> 2)NdisAllocateMemorywithTag()
> 3)NdisAllocateBuffer
> 4)NdisMoveMemory() - copy the entire ip packet to the buffer

This is a little scarey. Does your “ip packet” include the MAC header.

> 5)NDIS_SET_PACKET_STATUS(Mypacket, NDIS_STATUS_RESOURCE)

Have you used NDIS_SET_PACKET_HEADER_SIZE?

> 6)NdisSend()
> 7)free buffer, free memory and free packet if status is
> NDIS_STATUS_RESOURCE

Do you insure that in your SendComplet handler you do NOT pass the send
completion status upwards? IOW, in your SendComplete handler you must treat
packets that you send from your IOCTL differently from packets that were
sent via your MiniportSend and friends.

Good luck,

Thomas F. Divine, Windows DDK MVP
http://www.rawether.net

> This part of the code exit properly.
>
> Thanks.
>

> “Wong Hau Shian” wrote in message
> news:xxxxx@ntdev…
>>I called NdisReleaseSpinLock() before I call IoCompleteRequest. When I
>>send a text string down, it is fine. When I indicate an IP packet up the
>>TCP/IP stack (using the same IO code), it is ok. However, when I try to
>>send the IP packet out, then it happened.
>>
>> The code for sending the ip packet out is
>> 1)NdisAllocatePacket()
>> 2)NdisAllocateMemorywithTag()
>> 3)NdisAllocateBuffer
>> 4)NdisMoveMemory() - copy the entire ip packet to the buffer
>
> This is a little scarey. Does your “ip packet” include the MAC header.

Ya, the MAC header is in. The destination is able to received the packet
properly.

>> 5)NDIS_SET_PACKET_STATUS(Mypacket, NDIS_STATUS_RESOURCE)
>
> Have you used NDIS_SET_PACKET_HEADER_SIZE?

Yes I did.

>> 6)NdisSend()
>> 7)free buffer, free memory and free packet if status is
>> NDIS_STATUS_RESOURCE
>
> Do you insure that in your SendComplet handler you do NOT pass the send
> completion status upwards? IOW, in your SendComplete handler you must
> treat packets that you send from your IOCTL differently from packets that
> were sent via your MiniportSend and friends.

My understanding is that when I set NDIS_SET_PACKET_STATUS(Mypacket,
NDIS_STATUS_RESOURCE), my SendComplete Handler will not be called? When
NdisSend() returns, I free all resources after ensuring that the return
status is NDIS_STATUS_RESOURCE. My sendComplete handler has not been called.
It died when my IRP is about to complete.

Thanks.

Regards
Hau Shian

The DDK doesn’t say that you can set NDIS_STATUS_RESOURCES for NdisSend
call. Are you checking and only completing the IRP when NdisSend returns
something other than STATUS_PENDING? You might want to paste some portion of
code where you call NdisSend to make things more clear.


Pankaj Garg
This posting is provided “AS IS” with no warranties and confers no rights.

“Wong Hau Shian” wrote in message
news:xxxxx@ntdev…
> > “Wong Hau Shian” wrote in message
> > news:xxxxx@ntdev…
> >>I called NdisReleaseSpinLock() before I call IoCompleteRequest. When I
> >>send a text string down, it is fine. When I indicate an IP packet up the
> >>TCP/IP stack (using the same IO code), it is ok. However, when I try to
> >>send the IP packet out, then it happened.
> >>
> >> The code for sending the ip packet out is
> >> 1)NdisAllocatePacket()
> >> 2)NdisAllocateMemorywithTag()
> >> 3)NdisAllocateBuffer
> >> 4)NdisMoveMemory() - copy the entire ip packet to the buffer
> >
> > This is a little scarey. Does your “ip packet” include the MAC header.
>
> Ya, the MAC header is in. The destination is able to received the packet
> properly.
>
> >> 5)NDIS_SET_PACKET_STATUS(Mypacket, NDIS_STATUS_RESOURCE)
> >
> > Have you used NDIS_SET_PACKET_HEADER_SIZE?
>
> Yes I did.
>
> >> 6)NdisSend()
> >> 7)free buffer, free memory and free packet if status is
> >> NDIS_STATUS_RESOURCE
> >
> > Do you insure that in your SendComplet handler you do NOT pass the send
> > completion status upwards? IOW, in your SendComplete handler you must
> > treat packets that you send from your IOCTL differently from packets
that
> > were sent via your MiniportSend and friends.
>
> My understanding is that when I set NDIS_SET_PACKET_STATUS(Mypacket,
> NDIS_STATUS_RESOURCE), my SendComplete Handler will not be called? When
> NdisSend() returns, I free all resources after ensuring that the return
> status is NDIS_STATUS_RESOURCE. My sendComplete handler has not been
called.
> It died when my IRP is about to complete.
>
> Thanks.
>
> Regards
> Hau Shian
>
>

Have you forgotten NDIS_SET_PACKET_HEADER_SIZE?

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Wong Hau Shian”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, July 19, 2005 12:08 PM
Subject: Re: [ntdev] Ndis IM deviceIOcontrol

> I called NdisReleaseSpinLock() before I call IoCompleteRequest. When I send
> a text string down, it is fine. When I indicate an IP packet up the TCP/IP
> stack (using the same IO code), it is ok. However, when I try to send the IP
> packet out, then it happened.
>
> The code for sending the ip packet out is
> 1)NdisAllocatePacket()
> 2)NdisAllocateMemorywithTag()
> 3)NdisAllocateBuffer
> 4)NdisMoveMemory() - copy the entire ip packet to the buffer
> 5)NDIS_SET_PACKET_STATUS(Mypacket, NDIS_STATUS_RESOURCE)
> 6)NdisSend()
> 7)free buffer, free memory and free packet if status is NDIS_STATUS_RESOURCE
>
> This part of the code exit properly.
>
> Thanks.
>
>
> ----- Original Message -----
> From: “Calvin Guan”
> To: “Windows System Software Devs Interest List”
> Sent: Tuesday, July 19, 2005 3:43 PM
> Subject: Re: [ntdev] Ndis IM deviceIOcontrol
>
>
> >> What could have raise my IRQL to 2?
> >
> > The answer is in you dispatch routine. Did you acquire a spinlock and
> > forget to release?
> > Or did you call a function that raises the IRQL but forget to undo it
> > before returning from your dispatch routine?
> >
> > Calvin Guan (Windows DDK MVP)
> > Staff SW Engineer NetXtreme MINIPORT
> > Broadcom Corp. Irvine, CA
> > www.broadcom.com
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@singnet.com.sg
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com