阅读:1797回复:7
Passthru的应用,只要答的好,分随意,但一定要解决问题
软件环境:
Win2000 Professional + SP2 硬件环境: Realtek RTL8139(A) PCI Fast Ethernet Adapter 列一下PtReceive函数处理(:D,是以前讨论过的源码,基本没做改动,如果熟悉请跳过) NDIS_STATUS PtReceive( IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_HANDLE MacReceiveContext, IN PVOID HeaderBuffer, IN UINT HeaderBufferSize, IN PVOID LookAheadBuffer, IN UINT LookAheadBufferSize, IN UINT PacketSize ) /*++ Routine Description: LBFO - need to use primary for all receives Arguments: Return Value: --*/ { PADAPT OutAdapt,pAdapt =(PADAPT)ProtocolBindingContext; PNDIS_PACKET MyPacket, Packet,MyPacket1; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; PNDIS_BUFFER pPacketBuffer,pBakBuffer; PUCHAR pPacketContent,pBakContent; UINT PacketLen; UINT OffsetSize; UINT BytesTransferred; PRSVD Rsvd=NULL; PVOID MediaSpecificInfo=NULL; ULONG MediaSpecificSize=0; if(!pAdapt->MiniportHandle) { Status = NDIS_STATUS_FAILURE; } else do { // // We should not be getting Receives on a Secondary, this is just specific to our LBFO driver // if(pAdapt->isSecondary) { DBGPRINT(\"PASSTHRU GETTING RECIEVES ON SECONDARY\\n\"); ASSERT(0); } // // If this was indicated by the miniport below as a packet, then get that packet pointer and indicate // it as a packet as well(with appropriate status). This way the OOB stuff is accessible to the // transport above us. // Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext); if(Packet != NULL) { // // Get a packet off the pool and indicate that up // NdisDprAllocatePacket(&Status, &MyPacket, pAdapt->RecvPacketPoolHandle); if(Status == NDIS_STATUS_SUCCESS) { MyPacket->Private.Head = Packet->Private.Head; MyPacket->Private.Tail = Packet->Private.Tail; // // Get the original packet(it could be the same packet as one received or a different one // based on # of layered MPs) and set it on the indicated packet so the OOB stuff is visible // correctly at the top. // NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize); // // Set Packet Flags // NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); // // Make sure the status is set to NDIS_STATUS_RESOURCES. // NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES); if (ProcessPacket(MyPacket)==NDIS_STATUS_NOT_ACCEPTED) return(NDIS_STATUS_NOT_ACCEPTED); //************************************************************************************* NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); ASSERT(NDIS_GET_PACKET_STATUS(MyPacket) == NDIS_STATUS_RESOURCES); NdisDprFreePacket(MyPacket); break; } } // // Fall through if the miniport below us has either not indicated a packet or we could not // allocate one // else if(PacketSize<=LookAheadBufferSize) { Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax); if(Status!=NDIS_STATUS_SUCCESS) { DbgPrint(\"PTReceive:NdisAllocateMemory Failed\\n\"); return(NDIS_STATUS_NOT_ACCEPTED); } if(pPacketContent==NULL) { DbgPrint(\"PTReceive:pPacketContent==NULL\\n\"); return(NDIS_STATUS_NOT_ACCEPTED); } NdisZeroMemory(pPacketContent,BUFFER_SIZE); NdisMoveMemory(pPacketContent,HeaderBuffer,HeaderBufferSize); NdisMoveMemory(pPacketContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize); PacketLen=PacketSize+HeaderBufferSize; NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle); if(Status==NDIS_STATUS_SUCCESS) { NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketLen); NdisChainBufferAtFront(MyPacket,pPacketBuffer); MyPacket->Private.Head->Next=NULL; MyPacket->Private.Tail=NULL; Rsvd=(PRSVD)(MyPacket->MiniportReserved); Rsvd->OriginalPkt=NULL; NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize); if (ProcessPacket(MyPacket)==NDIS_STATUS_NOT_ACCEPTED) return(NDIS_STATUS_NOT_ACCEPTED); //************************************************************************************* NdisMIndicateReceivePacket(pAdapt->MiniportHandle,&MyPacket,1); if(NDIS_GET_PACKET_STATUS(MyPacket)!=NDIS_STATUS_PENDING) { DBGPRINT((\"In PtReceive And Free Memory\\n\")); NdisFreeBuffer(pPacketBuffer); NdisFreeMemory(pPacketContent,BUFFER_SIZE,0); NdisDprFreePacket(MyPacket); } } break; } else { Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax); if(Status!=NDIS_STATUS_SUCCESS) { DbgPrint(\"PtReceive:NdisAllocateMemory Failed.\\n\"); return(NDIS_STATUS_NOT_ACCEPTED); } if(pPacketContent==NULL) { DbgPrint(\"PTReceive:pPacketContent==NULL\\n\"); return(NDIS_STATUS_NOT_ACCEPTED); } NdisZeroMemory(pPacketContent,BUFFER_SIZE); NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle); Status=NdisAllocateMemory(&pBakContent,BUFFER_SIZE,0,HighestAcceptableMax); if(Status!=NDIS_STATUS_SUCCESS) { DbgPrint(\"PtReceive:NdisAllocateMemory Failed.\\n\"); return(NDIS_STATUS_NOT_ACCEPTED); } if(pBakContent==NULL) { DbgPrint(\"PTReceive:pPacketContent==NULL\\n\"); return(NDIS_STATUS_NOT_ACCEPTED); } NdisZeroMemory(pBakContent,BUFFER_SIZE); NdisMoveMemory(pBakContent,HeaderBuffer,HeaderBufferSize); NdisMoveMemory(pBakContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize); PacketLen=HeaderBufferSize+PacketSize; NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketSize-LookAheadBufferSize); NdisChainBufferAtFront(MyPacket,pPacketBuffer); MyPacket->Private.Head->Next=NULL; MyPacket->Private.Tail=NULL; OffsetSize=HeaderBufferSize+LookAheadBufferSize; NdisDprAllocatePacket(&Status,&MyPacket1,pAdapt->RecvPacketPoolHandle); NdisAllocateBuffer(&Status,&pBakBuffer,pAdapt->RecvBufferPoolHandle,pBakContent,OffsetSize); NdisChainBufferAtFront(MyPacket1,pBakBuffer); Rsvd=(PRSVD)(MyPacket->MiniportReserved); Rsvd->OriginalPkt=(PNDIS_PACKET)MyPacket1; NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize); NdisTransferData(&Status,pAdapt->BindingHandle,MacReceiveContext,LookAheadBufferSize,PacketSize-LookAheadBufferSize,MyPacket,&BytesTransferred); if(Status!=NDIS_STATUS_PENDING) { PtTransferDataComplete((NDIS_HANDLE)pAdapt,MyPacket,Status,BytesTransferred); } break; } pAdapt->IndicateRcvComplete = TRUE; } while(FALSE); // DBGPRINT((\"In PtReceive\\n\")); return Status; } 因网卡是RTL8139(A)故NdisGetReceivedPacket返回的是NULL,经过else if(PacketSize<=LookAheadBufferSize)执行函数组成包MyPacket,在调用NdisMIndicateReceivePacket前执行我的包处理函数ProcessPacket 问题: NDIS_STATUS ProcessPacket( IN PNDIS_PACKET Packet ) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; if(Packet != NULL) { ................ ................ ................ ................ ................ ................ DBGPRINT((\"\\nProcessPacket\\n\")); } return Status; } 现在我想在ProcessPacket函数中从Packet包显示数据,不过我用了很多种方法,不是死机就是直接蓝屏,百般无奈,只有劳烦各位老大帮忙,指点迷津,最好把这段代码指明,不然真的无法下手 另:如果我想改包的内容,是不是也可以在ProcessPacket函数中完成呢,请明示................................... |
|
沙发#
发布于:2002-08-08 15:48
伙计,搞清楚passthru imd的流程,仔细看几遍ddk吧!
|
|
|
板凳#
发布于:2002-08-08 15:58
:(
自认为已经搞清楚了流程,我现在的问题是我一处理Packet就当机,让我无从下手 经过前人的研究流程如下 包发送: app -> tcp/ipc...-> tdi(协议层接口) ->imd的miniport接口 -> miniport ->nic 包收接: nic -> miniport -> imd的protocal接口-> tdi(协议层接口) -> tcp/ipc...-> app 也就是说在处理包在protocal或miniport都可以,按上面的做法是在protocal中处理的,也就是在NdisMIndicateReceivePacket继续通知前,检查这个包并处理,请问楼上,有什么不妥吗? |
|
地板#
发布于:2002-08-08 16:25
:( 我实在受不了了,老兄,哎。。。。。 怎么说呢,你现在所能做的就是看上2,3个月ddk和passthru.另外,浏览一下以前的贴子,尽量少问多看吧! “懂“字,是不能怎么轻易的就说的,有的人学了几年,都不认为自己懂了。你说你懂了,我有点出汗了。 另外,最近很多新人来,有些问的问题都是让人无法回答的。千万不能随便就问别人要代码,我指的是前面要分片的代码。不能说,把别人的东西贴上自己的标签,就出售吧。尽管,斑竹可能也贴过。 当你问的问题没人回答时,想想问题是不是处在自己身上吧。 其实,大家都是来学东西的,可能刚来时,着急找不到方法,是在所难免的,每个人都可以理解的,大家开始时都是这样。 不过我只能说,静下心,踏踏实实的做吧。 可能今天这一贴得罪不少人,不过是我的心里话。 如果伤害了某些人,在此说sorry了。 嗬嗬! |
|
|
地下室#
发布于:2002-08-08 16:43
看来老大们都很清楚了,那我只能慢慢走了,为了保证我不多问,我提问之前已经把本论坛所有的贴子看过了,我尽量的看了,看来问出无济于事,我整理的都是各版主以前的贴子(自认为精华),而且运行没问题,今天是遇到小问题,想联系一下感情,我已经达到了要求
不过看样子问题是不能解决了,楼上的,我从头到尾没说一个“懂”字,我编程也有3年多了,最近接触驱动,在其他方面我也有你这种感觉,就是希望初学者要多看少问。所以我来这里的日子里从没有提问过,就今天问一下,我从不把别人的东西贴上自己的标签,因为在我眼里别人的东西不可信,但我喜欢听别人的,而且我也不想把我的代码贴出来,贴这个代码只是原理相似,看看别人是怎么处理了。 写了不少字,希望高手们不要看不起我,我也没什么意思,我从不生气,呵呵,一起进步,我再看几遍DDK 。。。。。。。。。。。。 |
|
5楼#
发布于:2002-08-09 14:44
fenger_li兄,那你就教教我们吧,你是怎么理解的?
我也是新人呀?刚刚搞NIDS驱动不到2周,但现在的路由协议已经快完了,也是上面的8139网卡的问题,数据通过我的路由协议后能到达驱动程序中,但在Winsock中却不能得到,网络监视也能得到数据,你看问题出在什么地方呀? |
|
|
6楼#
发布于:2002-08-09 15:10
感谢关注,以上问题我自己解决了...
PS:有什么办法在驱动中打开文本文件吗,希望不会被骂,:) |
|
7楼#
发布于:2002-08-09 15:53
ZwCreateFile等函数
顺便问一下,我的数据在到达我的路由协议后怎么也被丢了,如果不经过路由协议进行转发则没有问题,如果是我的路由协议的问题,那么数据怎么还能进行转发呢? |
|
|