阅读:1116回复:0
为什么一进入PacketReceiveIndicate就重启机器
在PacketReceiveIndicate中自己想得到接受到的包的内容,代码如下,但是一运行就重启。
请教这是因为什么,谢谢。 NDIS_STATUS PacketReceiveIndicate ( IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_HANDLE MacReceiveContext, IN PVOID HeaderBuffer, IN UINT HeaderBufferSize, IN PVOID LookAheadBuffer, IN UINT LookaheadBufferSize, IN UINT PacketSize ) { POPEN_INSTANCE open; PIO_STACK_LOCATION irpSp; PIRP irp; PLIST_ENTRY packetListEntry; PNDIS_PACKET pPacket; ULONG sizeToTransfer; NDIS_STATUS status; UINT bytesTransfered = 0; ULONG bufferLength; PPACKET_RESERVED reserved; PMDL pMdl; unsigned char pPacket_content[1524]; ARPSTRUCT *pARP ; DebugPrint(("--------->ReceiveIndicate<--------------")); if( PacketSize <= LookaheadBufferSize ) { // 这是一个完整的数据包,直接存储 bufferLength = HeaderBufferSize + PacketSize; if( bufferLength == 0 || bufferLength > sizeof( pPacket_content) ) { DebugPrint(( "The packet total length is invalid: %d", bufferLength )); return NDIS_STATUS_SUCCESS; } // 先拷贝头部数据 NdisMoveMemory( &pPacket_content[0], HeaderBuffer, HeaderBufferSize ); // 再拷贝剩余的数据 NdisMoveMemory( &pPacket_content[HeaderBufferSize], LookAheadBuffer, PacketSize ); pARP = (ARPSTRUCT*)pPacket_content; } // 以下为原来的内容 open= (POPEN_INSTANCE)ProtocolBindingContext; if (HeaderBufferSize > ETHERNET_HEADER_LENGTH) { return NDIS_STATUS_SUCCESS; } // // See if there are any pending read that we can satisfy // packetListEntry=ExInterlockedRemoveHeadList( &open->RcvList, &open->RcvQSpinLock ); if (packetListEntry == NULL) { DebugPrint(("No pending read, dropping packets\n")); return NDIS_STATUS_NOT_ACCEPTED; } reserved=CONTAINING_RECORD(packetListEntry,PACKET_RESERVED,ListElement); pPacket=CONTAINING_RECORD(reserved,NDIS_PACKET,ProtocolReserved); irp=RESERVED(pPacket)->Irp; irpSp = IoGetCurrentIrpStackLocation(irp); // // We don't have to worry about the situation where the IRP is cancelled // after we remove it from the queue and before we reset the cancel // routine because the cancel routine has been coded to cancel an IRP // only if it's in the queue. // IoSetCancelRoutine(irp, NULL); // // This is the length of our partial MDL // bufferLength=irpSp->Parameters.Read.Length-ETHERNET_HEADER_LENGTH; // // Find out how much to transfer // sizeToTransfer = (PacketSize < bufferLength) ? PacketSize : bufferLength; // // copy the ethernet header into the actual readbuffer // NdisMoveMappedMemory( MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority), HeaderBuffer, HeaderBufferSize ); // // Allocate an MDL to map the portion of the buffer following the // header // pMdl=IoAllocateMdl( MmGetMdlVirtualAddress(irp->MdlAddress), MmGetMdlByteCount(irp->MdlAddress), FALSE, FALSE, NULL ); if (pMdl == NULL) { DebugPrint(("Packet: Read-Failed to allocate Mdl\n")); status = NDIS_STATUS_RESOURCES; goto ERROR; } // // Build the mdl to point to the the portion of the buffer following // the header // IoBuildPartialMdl( irp->MdlAddress, pMdl, ((PUCHAR)MmGetMdlVirtualAddress(irp->MdlAddress))+ETHERNET_HEADER_LENGTH, 0 ); // // Clear the next link in the new MDL // pMdl->Next=NULL; RESERVED(pPacket)->pMdl=pMdl; // // Attach our partial MDL to the packet // NdisChainBufferAtFront(pPacket,pMdl); // // Call the Mac to transfer the packet // //接收包的其余部分 NdisTransferData( &status, open->AdapterHandle, MacReceiveContext, 0, sizeToTransfer, pPacket, &bytesTransfered); if (status == NDIS_STATUS_PENDING) { return NDIS_STATUS_SUCCESS; } ERROR: // // If it didn't pend, call the completeion routine now // PacketTransferDataComplete( open, pPacket, status, bytesTransfered); return NDIS_STATUS_SUCCESS; } |
|
|