Prev: Help disabling a device using SetupDiXXX fns after WM_DEVICECHANGE
Next: WDK build error , but XP DDK build ok
From: Peter Schmitz on 26 Oct 2005 15:32 Thanks for replying! So, I discarded the two bogus lines (containing the copying of the private parts), and recreated the PtSendcomplete handler like this: VOID PtSendComplete( IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status ) { PADAPT pAdapt =(PADAPT)ProtocolBindingContext; PNDIS_PACKET Pkt; NDIS_HANDLE PoolHandle; PSEND_RSVD SendRsvd; UINT nDataSize, nBufferCount; PNDIS_BUFFER pBuffer; SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved); Pkt = SendRsvd->OriginalPkt; if( Pkt ) { NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); NdisMSendComplete(pAdapt->MiniportHandle,Pkt,Status); } else { NdisQueryPacket(Packet,NULL,&nBufferCount,&pBuffer,&nDataSize); while(nBufferCount-- > 0L) { NdisUnchainBufferAtFront(Packet,&pBuffer); if(pBuffer)NdisFreeBuffer(pBuffer); } } NdisFreePacket(Packet); } Unfortunately, this source code results in an error when I try to send the packet DuplicatePacket created for me: DRIVER_IRQL_NOT_LESS_OR_EQUAL (d1) Arg1: 835eca10, memory referenced Arg2: 00000002, IRQL Arg3: 00000000, value 0 = read operation, 1 = write operation Arg4: f871ffc5, address which referenced memory just at the lines: NdisSend(&Status,padapt->BindingHandle,looppacket->packet); if(Status != NDIS_STATUS_PENDING) { UINT nDataSize, nBufferCount; PNDIS_BUFFER pBuffer; NdisQueryPacket(looppacket->packet,NULL,&nBufferCount,&pBuffer,&nDataSize); while( nBufferCount-- > 0L ) { NdisUnchainBufferAtFront(looppacket->packet,&pBuffer); NdisFreeBuffer(pBuffer); } NdisFreePacket(looppacket->packet); } NdisSend is the cause for the error. By the way, the passthru sample contains some lines in the MPSendPackets function (only covered in NDIS 5.1 config) that don't seem to create a copy of the NDIS_PACKET, but instead use the original packet directly... (I commented them out for now). Greetings, and thanks a lot, Peter
From: Thomas F. Divine [DDK MVP] on 26 Oct 2005 16:30 "Peter Schmitz" <PeterSchmitz(a)discussions.microsoft.com> wrote in message news:49AEB8A7-E564-4AE8-A9FB-B35BA74BD730(a)microsoft.com... > Thanks for replying! > > So, I discarded the two bogus lines (containing the copying of the private > parts), and recreated the PtSendcomplete handler like this: > > VOID > PtSendComplete( > IN NDIS_HANDLE ProtocolBindingContext, > IN PNDIS_PACKET Packet, > IN NDIS_STATUS Status > ) > { > PADAPT pAdapt =(PADAPT)ProtocolBindingContext; > PNDIS_PACKET Pkt; > NDIS_HANDLE PoolHandle; > > PSEND_RSVD SendRsvd; > UINT nDataSize, nBufferCount; > PNDIS_BUFFER pBuffer; > > SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved); > Pkt = SendRsvd->OriginalPkt; > > if( Pkt ) > { > NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); > NdisMSendComplete(pAdapt->MiniportHandle,Pkt,Status); > } > else > { You must ALWAYS free your own packet! Not just in the case where OriginalPkt != NULL. > NdisQueryPacket(Packet,NULL,&nBufferCount,&pBuffer,&nDataSize); > while(nBufferCount-- > 0L) > { > NdisUnchainBufferAtFront(Packet,&pBuffer); > if(pBuffer)NdisFreeBuffer(pBuffer); > } > } > NdisFreePacket(Packet); > > } > > Unfortunately, this source code results in an error when I try to send the > packet DuplicatePacket created for me: > > DRIVER_IRQL_NOT_LESS_OR_EQUAL (d1) > > Arg1: 835eca10, memory referenced > Arg2: 00000002, IRQL > Arg3: 00000000, value 0 = read operation, 1 = write operation > Arg4: f871ffc5, address which referenced memory > > just at the lines: > > NdisSend(&Status,padapt->BindingHandle,looppacket->packet); > if(Status != NDIS_STATUS_PENDING) > { Just call PtSendComplete. It should know what to do in this case. > > UINT nDataSize, nBufferCount; > PNDIS_BUFFER pBuffer; > > > NdisQueryPacket(looppacket->packet,NULL,&nBufferCount,&pBuffer,&nDataSize); > while( nBufferCount-- > 0L ) > { > NdisUnchainBufferAtFront(looppacket->packet,&pBuffer); > NdisFreeBuffer(pBuffer); > } > NdisFreePacket(looppacket->packet); > } > > NdisSend is the cause for the error. > > By the way, the passthru sample contains some lines in the MPSendPackets > function (only covered in NDIS 5.1 config) that don't seem to create a > copy > of the NDIS_PACKET, but instead use the original packet directly... (I > commented them out for now). For sure, the PassThru chaining code simply links the original packet's NDIS buffer's into the new "wrapper" packet for simple passthru. It does NOT duplicate the original packet's contents. Thomas > > > Greetings, and thanks a lot, > > Peter
From: Peter Schmitz on 26 Oct 2005 16:47 Thanks again. Unfortunately, when I use the code above and free every packet this way I receive a BAD_POOL_CALLER on startup, saying that my NdisFreeBuffer function tries to free a buffer that was already freed... - Peter "Thomas F. Divine [DDK MVP]" wrote: > "Peter Schmitz" <PeterSchmitz(a)discussions.microsoft.com> wrote in message > news:49AEB8A7-E564-4AE8-A9FB-B35BA74BD730(a)microsoft.com... > > Thanks for replying! > > > > So, I discarded the two bogus lines (containing the copying of the private > > parts), and recreated the PtSendcomplete handler like this: > > > > VOID > > PtSendComplete( > > IN NDIS_HANDLE ProtocolBindingContext, > > IN PNDIS_PACKET Packet, > > IN NDIS_STATUS Status > > ) > > { > > PADAPT pAdapt =(PADAPT)ProtocolBindingContext; > > PNDIS_PACKET Pkt; > > NDIS_HANDLE PoolHandle; > > > > PSEND_RSVD SendRsvd; > > UINT nDataSize, nBufferCount; > > PNDIS_BUFFER pBuffer; > > > > SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved); > > Pkt = SendRsvd->OriginalPkt; > > > > if( Pkt ) > > { > > NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); > > NdisMSendComplete(pAdapt->MiniportHandle,Pkt,Status); > > } > > else > > { > > > You must ALWAYS free your own packet! Not just in the case where OriginalPkt > != NULL. > > > > NdisQueryPacket(Packet,NULL,&nBufferCount,&pBuffer,&nDataSize); > > while(nBufferCount-- > 0L) > > { > > NdisUnchainBufferAtFront(Packet,&pBuffer); > > if(pBuffer)NdisFreeBuffer(pBuffer); > > } > > } > > NdisFreePacket(Packet); > > > > } > > > > Unfortunately, this source code results in an error when I try to send the > > packet DuplicatePacket created for me: > > > > DRIVER_IRQL_NOT_LESS_OR_EQUAL (d1) > > > > Arg1: 835eca10, memory referenced > > Arg2: 00000002, IRQL > > Arg3: 00000000, value 0 = read operation, 1 = write operation > > Arg4: f871ffc5, address which referenced memory > > > > just at the lines: > > > > NdisSend(&Status,padapt->BindingHandle,looppacket->packet); > > if(Status != NDIS_STATUS_PENDING) > > { > > Just call PtSendComplete. It should know what to do in this case. > > > > > > UINT nDataSize, nBufferCount; > > PNDIS_BUFFER pBuffer; > > > > > > NdisQueryPacket(looppacket->packet,NULL,&nBufferCount,&pBuffer,&nDataSize); > > while( nBufferCount-- > 0L ) > > { > > NdisUnchainBufferAtFront(looppacket->packet,&pBuffer); > > NdisFreeBuffer(pBuffer); > > } > > NdisFreePacket(looppacket->packet); > > } > > > > NdisSend is the cause for the error. > > > > By the way, the passthru sample contains some lines in the MPSendPackets > > function (only covered in NDIS 5.1 config) that don't seem to create a > > copy > > of the NDIS_PACKET, but instead use the original packet directly... (I > > commented them out for now). > > For sure, the PassThru chaining code simply links the original packet's NDIS > buffer's into the new "wrapper" packet for simple passthru. It does NOT > duplicate the original packet's contents. > > Thomas > > > > > > > > Greetings, and thanks a lot, > > > > Peter > >
From: Thomas F. Divine [DDK MVP] on 26 Oct 2005 17:00 Ok, Peter. It looks like you are really having a hard time with this. Here is my advice. Throw away all of the code you have written. Start with the PassThru sample code from the Windows Server 2003 DDK. Start with the send path and set breakpoints in MPSend, MPSendPackets and PtReceive. Step through every line of code and learn what it is doing. Pay particular attention to how the OriginalPkt field is used. Learn what each line is actually doing. Your code has a lot of the pieces right - but some details are terribly wrong. You've just got to 1.) understand what you're doing and 2.) debug your code. Good luck, Thomas F. Divine "Peter Schmitz" <PeterSchmitz(a)discussions.microsoft.com> wrote in message news:422C50C2-2330-4AD9-B2CD-311DD62AAFE5(a)microsoft.com... > Thanks again. > > Unfortunately, when I use the code above and free every packet this way I > receive a BAD_POOL_CALLER on startup, saying that my NdisFreeBuffer > function > tries to free a buffer that was already freed... > > - Peter > > > > > "Thomas F. Divine [DDK MVP]" wrote: > >> "Peter Schmitz" <PeterSchmitz(a)discussions.microsoft.com> wrote in message >> news:49AEB8A7-E564-4AE8-A9FB-B35BA74BD730(a)microsoft.com... >> > Thanks for replying! >> > >> > So, I discarded the two bogus lines (containing the copying of the >> > private >> > parts), and recreated the PtSendcomplete handler like this: >> > >> > VOID >> > PtSendComplete( >> > IN NDIS_HANDLE ProtocolBindingContext, >> > IN PNDIS_PACKET Packet, >> > IN NDIS_STATUS Status >> > ) >> > { >> > PADAPT pAdapt =(PADAPT)ProtocolBindingContext; >> > PNDIS_PACKET Pkt; >> > NDIS_HANDLE PoolHandle; >> > >> > PSEND_RSVD SendRsvd; >> > UINT nDataSize, nBufferCount; >> > PNDIS_BUFFER pBuffer; >> > >> > SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved); >> > Pkt = SendRsvd->OriginalPkt; >> > >> > if( Pkt ) >> > { >> > NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); >> > NdisMSendComplete(pAdapt->MiniportHandle,Pkt,Status); >> > } >> > else >> > { >> >> >> You must ALWAYS free your own packet! Not just in the case where >> OriginalPkt >> != NULL. >> >> >> > NdisQueryPacket(Packet,NULL,&nBufferCount,&pBuffer,&nDataSize); >> > while(nBufferCount-- > 0L) >> > { >> > NdisUnchainBufferAtFront(Packet,&pBuffer); >> > if(pBuffer)NdisFreeBuffer(pBuffer); >> > } >> > } >> > NdisFreePacket(Packet); >> > >> > } >> > >> > Unfortunately, this source code results in an error when I try to send >> > the >> > packet DuplicatePacket created for me: >> > >> > DRIVER_IRQL_NOT_LESS_OR_EQUAL (d1) >> > >> > Arg1: 835eca10, memory referenced >> > Arg2: 00000002, IRQL >> > Arg3: 00000000, value 0 = read operation, 1 = write operation >> > Arg4: f871ffc5, address which referenced memory >> > >> > just at the lines: >> > >> > NdisSend(&Status,padapt->BindingHandle,looppacket->packet); >> > if(Status != NDIS_STATUS_PENDING) >> > { >> >> Just call PtSendComplete. It should know what to do in this case. >> >> >> > >> > UINT nDataSize, nBufferCount; >> > PNDIS_BUFFER pBuffer; >> > >> > >> > NdisQueryPacket(looppacket->packet,NULL,&nBufferCount,&pBuffer,&nDataSize); >> > while( nBufferCount-- > 0L ) >> > { >> > NdisUnchainBufferAtFront(looppacket->packet,&pBuffer); >> > NdisFreeBuffer(pBuffer); >> > } >> > NdisFreePacket(looppacket->packet); >> > } >> > >> > NdisSend is the cause for the error. >> > >> > By the way, the passthru sample contains some lines in the >> > MPSendPackets >> > function (only covered in NDIS 5.1 config) that don't seem to create a >> > copy >> > of the NDIS_PACKET, but instead use the original packet directly... (I >> > commented them out for now). >> >> For sure, the PassThru chaining code simply links the original packet's >> NDIS >> buffer's into the new "wrapper" packet for simple passthru. It does NOT >> duplicate the original packet's contents. >> >> Thomas >> >> >> > >> > >> > Greetings, and thanks a lot, >> > >> > Peter >> >>
From: Stephan Wolf [MVP] on 27 Oct 2005 03:56
Thomas F. Divine [DDK MVP] wrote: > It looks like you are really having a hard time with this. Here is my > advice. Hi Tom, Wish there was some book covering NDIS. As many people seem to have difficulties trying to understand NDIS, maybe we should write some more online articles that cover the "basics" of the NDIS philosophy. Stephan |