阅读:1662回复:3
关于NdisQueryPacket
请教:为什么我用这个函数是,softice跟踪时它里面的参数好像没有返回!谢谢
注:函数原型 VOID NdisQueryPacket( IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL ); 即 ? TotalPacketLength 它提示:没定义 |
|
沙发#
发布于:2005-06-28 15:52
把你的代码show出来先.
|
|
板凳#
发布于:2005-06-28 23:51
INT
PtReceivePacket( IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_PACKET Packet ) /*++ Routine Description: ReceivePacket handler. Called by NDIS if the miniport below supports NDIS 4.0 style receives. Re-package the buffer chain in a new packet and indicate the new packet to protocols above us. Any context for packets indicated up must be kept in the MiniportReserved field. NDIS 5.1 - packet stacking - if there is sufficient "stack space" in the packet passed to us, we can use the same packet in a receive indication. Arguments: ProtocolBindingContext - Pointer to our adapter structure. Packet - Pointer to the packet Return Value: == 0 -> We are done with the packet != 0 -> We will keep the packet and call NdisReturnPackets() this many times when done. --*/ { PADAPT pAdapt =(PADAPT)ProtocolBindingContext; NDIS_STATUS Status; PNDIS_PACKET MyPacket; BOOLEAN Remaining; // BEGIN_PTEX_FILTER ULONG RcvFltAction; /**********************************************************************/ PVOID lpBufferIn; //PULONG lpNumberOfBytesRead ; PNDIS_BUFFER CurrentBuffer; ULONG nBufferCount, TotalPacketLength; ULONG nNumberOfBytesToRead; // lpNumberOfBytesRead = NULL; nNumberOfBytesToRead = 0; /********************************************************************/ // END_PTEX_FILTER // // Drop the packet silently if the upper miniport edge isn't initialized or // the miniport edge is in low power state // if ((!pAdapt->MiniportHandle) || (pAdapt->MPDeviceState > NdisDeviceStateD0)) { return 0; } // BEGIN_PTEX_FILTER DBGPRINT(("Before NdisQueryPacket")); /**********************************************************************************************/ NdisQueryPacket( (PNDIS_PACKET )Packet, (PUINT )NULL, // Physical Buffer Count (PUINT )&nBufferCount, // Buffer Count &CurrentBuffer, // First Buffer &TotalPacketLength // TotalPacketLength ); NdisAllocateMemoryWithTag(&lpBufferIn,TotalPacketLength,TAG); ReadPackets(Packet, lpBufferIn, nNumberOfBytesToRead); if(nNumberOfBytesToRead < TotalPacketLength) DBGPRINT(("read packets error")); NdisFreeMemory(lpBufferIn,0,0); /******************************************************************************************/ // // Call Receive Packet Filter // NdisDprAcquireSpinLock(&pAdapt->Lock); if (pAdapt->bFilterStatus != FILTER_STATUS_PASS) //系统设置为1或者2,既是过滤或者拒绝 { if ( pAdapt->bFilterStatus == FILTER_STATUS_REJECT) //直接拒绝 { NdisDprReleaseSpinLock(&pAdapt->Lock); return 0; } else //过滤 { ULONG RcvFltAction; NdisDprReleaseSpinLock(&pAdapt->Lock); RcvFltAction = FltFilterReceivePacket( pAdapt, Packet ); // // Possibly Block (Drop) Packet // if( RcvFltAction ) { return 0; } NdisDprAcquireSpinLock(&pAdapt->Lock); } } NdisDprReleaseSpinLock(&pAdapt->Lock); // END_PTEX_FILTER #ifdef NDIS51 // // Check if we can reuse the same packet for indicating up. // See also: PtReceive(). // (VOID)NdisIMGetCurrentPacketStack(Packet, &Remaining); if (Remaining) { // // We can reuse "Packet". Indicate it up and be done with it. // Status = NDIS_GET_PACKET_STATUS(Packet); NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &Packet, 1); return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); } #endif // NDIS51 /********************************************************************************************** NdisQueryPacket( (PNDIS_PACKET )Packet, (PUINT )NULL, // Physical Buffer Count (PUINT )&nBufferCount, // Buffer Count &CurrentBuffer, // First Buffer &TotalPacketLength // TotalPacketLength ); NdisAllocateMemoryWithTag(&lpBufferIn,TotalPacketLength,TAG); ReadPackets(Packet, lpBufferIn, nNumberOfBytesToRead, lpNumberOfBytesRead); if(nNumberOfBytesToRead < TotalPacketLength) DBGPRINT(("read packets error")); NdisFreeMemory(lpBufferIn,0,0); ******************************************************************************************/ // // Get a packet off the pool and indicate that up // NdisDprAllocatePacket(&Status, &MyPacket, pAdapt->RecvPacketPoolHandle); if (Status == NDIS_STATUS_SUCCESS) { PRECV_RSVD RecvRsvd; RecvRsvd = (PRECV_RSVD)(MyPacket->MiniportReserved); RecvRsvd->OriginalPkt = Packet; MyPacket->Private.Head = Packet->Private.Head; MyPacket->Private.Tail = Packet->Private.Tail; // // Get the original packet (it could be the same packet as the one // received or a different one based on the number of layered miniports // below) and set it on the indicated packet so the OOB data is visible // correctly to protocols above us. // NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); // // Set Packet Flags // NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); Status = NDIS_GET_PACKET_STATUS(Packet); NDIS_SET_PACKET_STATUS(MyPacket, Status); NDIS_SET_PACKET_HEADER_SIZE(MyPacket, NDIS_GET_PACKET_HEADER_SIZE(Packet)); NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); // // Check if we had indicated up the packet with NDIS_STATUS_RESOURCES // NOTE -- do not use NDIS_GET_PACKET_STATUS(MyPacket) for this since // it might have changed! Use the value saved in the local variable. // if (Status == NDIS_STATUS_RESOURCES) { // // Our ReturnPackets handler will not be called for this packet. // We should reclaim it right here. // NdisDprFreePacket(MyPacket); } return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); } else { // // We are out of packets. Silently drop it. // return(0); } } |
|
地板#
发布于:2005-06-28 23:53
VOID ReadPackets(IN PNDIS_PACKET Packet,//包
IN PVOID lpBufferIn, //存放数据包的地址 IN ULONG nNumberOfBytesToRead//接收到的数据包要读的字节数 /*OUT PULONG lpNumberOfBytesRead*/)//返回的数据包读的字节数 { PNDIS_BUFFER CurrentBuffer; UINT nBufferCount, TotalPacketLength; PUCHAR VirtualAddress = NULL; PUCHAR lpBuffer = (PUCHAR )lpBufferIn; UINT CurrentLength; // Sanity Check // if( !Packet || !lpBuffer ) { return; } //*lpNumberOfBytesRead = 0; if (!nNumberOfBytesToRead)//如果nNumberOfBytesToRead=0时return return; // // Query Packet // NdisQueryPacket( (PNDIS_PACKET )Packet, (PUINT )NULL, // Physical Buffer Count (PUINT )&nBufferCount, // Buffer Count &CurrentBuffer, // First Buffer &TotalPacketLength // TotalPacketLength );//returns information about a given packet // // Query The First Buffer // #if (defined(NDIS50) || defined(NDIS51)) NdisQueryBufferSafe( CurrentBuffer,//Pointer to the buffer descriptor &VirtualAddress,//Pointer to a caller-supplied variable in which this function returns the base virtual address of the range described, or set to NULL &CurrentLength,//Pointer to a caller-supplied variable in which this function returns the number of bytes in the virtual range. NormalPagePriority//Indicates the priority of the request );//retrieves the size of the range, and optionally the base virtual address, from a buffer descriptor. #else NdisQueryBuffer( CurrentBuffer, &VirtualAddress, &CurrentLength ); #endif // // Handle Possible Low-Resource Failure Of NdisQueryBufferSafe // if( !VirtualAddress )//如果VirtualAddress=0时return { return; } __try { // Copy the data.把VirtualAddress指向的长度为CurrentLength的内容copy到lpBuffer中去 NdisMoveMemory( lpBuffer, &VirtualAddress, CurrentLength ); // Update destination pointer lpBuffer += CurrentLength; //lpNumberOfBytesRead +=CurrentLength; do { NdisGetNextBuffer( CurrentBuffer, &CurrentBuffer );//returns the next buffer descriptor in a chain, given a pointer to the current buffer descriptor. //NdisGetNextBuffer returns NULL at NextBuffer if CurrentBuffer points to the last buffer descriptor in the chain. // If we've reached the end of the packet. We return with what // we've done so far (which must be shorter than requested). if (!CurrentBuffer)//如果CurrentBuffer point=NULL时return return; #if (defined(NDIS50) || defined(NDIS51)) NdisQueryBufferSafe( CurrentBuffer, &VirtualAddress, &CurrentLength, NormalPagePriority ); #else NdisQueryBuffer( CurrentBuffer, &VirtualAddress, &CurrentLength ); #endif // // Handle Possible Low-Resource Failure Of NdisQueryBufferSafe // if( !VirtualAddress ) { __leave; // Leave __try and eventually return... } // Copy the data. NdisMoveMemory( lpBuffer, &VirtualAddress, CurrentLength ); // Update destination pointer lpBuffer += CurrentLength; // lpNumberOfBytesRead +=CurrentLength; }while (1); } __finally { // // lpNumberOfBytesRead may be less then specified if exception // occured... // } } |
|