阅读:1429回复:0
MpSend中数据报处理的问题,多谢帮助!
我在PassThru基础上做一个中间层驱动。现在遇到一些问题。当上层发出一个Arp数据报时,我要禁止它发出
然后自己构造一个相应的回应包,通知上层接收。在MpSend中调用NdisSend之前我加入了如下代码: UINT PhysicalBufferCount; UINT BufferCount,k; UINT TotalPacketLength; PNDIS_BUFFER CurrentBuffer,NextBuffer,pArpBuffer; UINT CurrentBufferLength; PVOID CurrentBufferVA; NDIS_HANDLE PacketCopy=NULL; PNDIS_STATUS Sts=NDIS_STATUS_SUCCESS; PETHHDR DownEthhdr;//,UpEthhdr; PARPHDR DownArphdr;//,UpArphdr; //PIPHDR DownIphdr; PUCHAR pArpContent; UINT PacketLen; //×××以上是原PassThru中NdisSend之前的代码,主要是构造MyPacket.. NdisQueryPacket(MyPacket , &PhysicalBufferCount , &BufferCount , &CurrentBuffer , &TotalPacketLength ); DbgPrint(\"BufferCount:%u.\\n\",BufferCount); DbgPrint(\"TotalPacketLength:%u.\\n\",TotalPacketLength); /*if(!BufferCount) { // Output debug information DbgPrint(\" Debug Report @ MPSend: BufferCount of Packet is 0,\\n\"); DbgPrint(\"and MPSend will return NDIS_STATUS_FAILURE\\n\"); return (NDIS_STATUS_FAILURE); }*/ NdisQueryBuffer(CurrentBuffer, &CurrentBufferVA, &CurrentBufferLength); DbgPrint(\"CurrentBufferLength: %u \\n\",CurrentBufferLength); DownEthhdr=(PETHHDR)CurrentBufferVA; if(DownEthhdr->ProtocolType==ARP_PROTOCOL) { //this is an arp packet... DbgPrint(\"This is an arp packet...\\n\"); //修改包内容,通知上层接收 DownArphdr=(PARPHDR)((UINT)CurrentBufferVA+14); //申请内存 Status=NdisAllocateMemory(&pArpContent,100,0,HighestAcceptableMax); if(Status==NDIS_STATUS_SUCCESS) { DbgPrint(\"In MPSend:NdisAllocatePacketPool Successed.\\n\"); if(pArpContent!=NULL) { DbgPrint(\"In MPSend:pPacketContent!=NULL\\n\"); //NdisZeroMemory(pArpContent,2000); //拷贝内容数据 DbgPrint(\"In MPSend:Begin copy packet to mybuffer.\\n\"); CopyPacket2Buffer(MyPacket,pArpContent,&TotalPacketLength); PacketLen=TotalPacketLength; NdisAllocatePacketPool(Sts,PacketCopy,1,0); if (*Sts== NDIS_STATUS_SUCCESS) { DbgPrint(\"In MPSend:NdisAllocatePacketPool successed\\n\"); NdisAllocatePacket(&Status,&MyArpPacket,&PacketCopy); if(Status=NDIS_STATUS_SUCCESS) { DbgPrint(\"In MPSend:NdisAllocatePacket successed\\n\"); NdisAllocateBuffer(&Status,&pArpBuffer,pAdapt->SendBufferPoolHandle,pArpContent,PacketLen); NdisChainBufferAtFront(MyArpPacket,pArpBuffer); MyArpPacket->Private.Head->Next=NULL; MyArpPacket->Private.Tail=NULL; NDIS_SET_PACKET_HEADER_SIZE(MyArpPacket,14); DbgPrint(\"In MPSend:Packet copy down,begin query new arp packet.\\n\"); NdisQueryPacket(MyArpPacket, &PhysicalBufferCount, &BufferCount, &CurrentBuffer, &TotalPacketLength); DbgPrint(\"BufferCount:%u.\\n\",BufferCount); DbgPrint(\"TotalPacketLength:%u.\\n\",TotalPacketLength); NdisQueryBuffer(CurrentBuffer, &CurrentBufferVA, &CurrentBufferLength); DbgPrint(\"CurrentBufferLength: %u \\n\",CurrentBufferLength); DBGPRINT(\"In Mpsend,Free Memory\\n\"); NdisFreeBuffer(pArpBuffer); NdisFreePacket(MyArpPacket); } NdisFreePacketPool(PacketCopy); } } NdisFreeMemory(pArpContent,100,0); } } NdisSend(&Status, pAdapt->BindingHandle, MyPacket); if (Status != NDIS_STATUS_PENDING) { NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket); NdisFreePacket(MyPacket); } 现在没有修改数据报,只是申请内存,复制了一个数据报,然后释放掉。安装时兰屏,错误代码是 Xmode_exception_not_handled. 我的问题是我的代码问题出在什么地方?下一步我要修改我申请的内存,我应该怎么做呢?如何通知上层 接收我构造的数据报?如何解决返回的问题?Pending的时候如何处理?时间比较紧张,恳请各位大侠帮忙, 感谢!! |
|