Filter发送NetBufferList蓝屏问题
[复制链接]
VOID
filterSendOriginatedBufferList(
IN PMS_FILTER pFilter
)
/*
Descriptions:
This function is used to generate a net buffer list first,
and then send it out!
Arguments:
pFilter - points to the filter module context
SendFlags- used by NdisFSendNetBufferList
*/
{
NET_BUFFER_LIST_POOL_PARAMETERS PoolParameters;
ULONG PoolTag = 'TAG';
NDIS_HANDLE SendNetBufferListPool;// a pool used to allocate netbufferlst
//NDIS_STATUS Status;
PMDL pMdl;
ULONG BufferSize = 68;// packet size>=64
PNET_BUFFER_LIST pNetBufferList;
USHORT EthType = 0x8e88;
PTESTPROV_ETH_HEADER pEthHeader;
PUCHAR pWriteBuf = NULL;//all the data should be sent out
UCHAR SrcMacAddr[TESTPROV_MAC_ADDR_LEN];
UCHAR DstMacAddr[TESTPROV_MAC_ADDR_LEN];
ULONG MacAddrUlong[TESTPROV_MAC_ADDR_LEN];
PUCHAR pData;
PUCHAR pEthFrameNew = NULL;
UINT j;
ULONG SendFlags = 0;
DEBUGP(DL_TEST,("========>filterSendOriginatedBufferList\n"));
#if DBG
_asm int 3
#endif
//
NdisZeroMemory(&PoolParameters, sizeof(NET_BUFFER_LIST_POOL_PARAMETERS));
PoolParameters.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
PoolParameters.Header.Revision = NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1;
PoolParameters.Header.Size = sizeof(PoolParameters);
PoolParameters.ProtocolId = NDIS_PROTOCOL_ID_IPX ;
PoolParameters.ContextSize = 0;//unknown
PoolParameters.fAllocateNetBuffer = TRUE;
PoolParameters.PoolTag = PoolTag;
SendNetBufferListPool = NdisAllocateNetBufferListPool(
pFilter->FilterHandle,
&PoolParameters);
if(SendNetBufferListPool == NULL)
{
//Status = NDIS_STATUS_RESOURCES;
DEBUGP(DL_TEST,("Fail to allocate net buffer list pool\n"));
goto Exit;
}
//
pWriteBuf = (PUCHAR)NdisAllocateMemoryWithTagPriority(pFilter->FilterHandle,BufferSize,FILTER_ALLOC_TAG, LowPoolPriority);
NdisZeroMemory(pWriteBuf,BufferSize);
// Try to fill this buffer with some necessary data like Ethernet Header
pEthHeader = (PTESTPROV_ETH_HEADER)pWriteBuf;
//prepare the source and destination mac address, and get mac of wireless NIC is 00-14-78-7A-02-A3
MacAddrUlong[0]=0x00;
MacAddrUlong[1]=0x14;
MacAddrUlong[2]=0x78;
MacAddrUlong[3]=0x7A;
MacAddrUlong[4]=0x02;
MacAddrUlong[5]=0xA3;
for (j = 0; j < TESTPROV_MAC_ADDR_LEN; j++)
{
DstMacAddr[j] = (UCHAR)MacAddrUlong[j];
}
NdisMoveMemory(pEthHeader->SrcAddr, DstMacAddr, TESTPROV_MAC_ADDR_LEN);//set the source address
NdisMoveMemory(pEthHeader->DstAddr, DstMacAddr, TESTPROV_MAC_ADDR_LEN);//set the destionation address with the same to source address
pEthHeader->EthType = EthType;
//fill the packet into unused buffer
pData = (PUCHAR)(pEthHeader +1);
for(j=0; j< (BufferSize - sizeof(TESTPROV_ETH_HEADER));j++)
{
*pData++ = (UCHAR)j;
}
//<-------------Allocate a MDL------------------------------------------------------->
//now allocate MDL and initialize it
pEthFrameNew = (PUCHAR)pWriteBuf + BufferSize;//Bytes following the pWriteBuf
pMdl = NdisAllocateMdl(pFilter->FilterHandle,
pEthFrameNew,
BufferSize);
if(pMdl == NULL)
{
DEBUGP(DL_TEST,("Fail allocate a MDL\n"));
goto Exit;
}
//<-------Copy the data into the MDL--------------------------------------------->
//copy the Ethernet Header to MDL
NdisMoveMemory(pEthFrameNew,pEthHeader, BufferSize);
//Now allocate a net_buffer_list and NB
pNetBufferList = NdisAllocateNetBufferAndNetBufferList(
SendNetBufferListPool,
0, //Request control offset delta
0, // back fill size
pMdl,
0, // Data offset
BufferSize);
if(pNetBufferList == NULL)
{
DEBUGP(DL_TEST,("Fail allocate a Buffer and bufferlist\n"));
goto Exit;
}
//<------Send out the packet--------------------------->
pNetBufferList->SourceHandle = pFilter->FilterHandle;
SendFlags |= NDIS_SEND_FLAGS_CHECK_FOR_LOOPBACK;
NdisFSendNetBufferLists(
pFilter->FilterHandle,
pNetBufferList,
NDIS_DEFAULT_PORT_NUMBER,
SendFlags);
//最后函数NdisFSendNetBufferLists调用处了问题,蓝屏
DEBUGP(DL_TEST,("filterSendOriginatedBufferList<========\n"));
Exit:
return;
} 复制代码
我是想发送一个带有EtherNet header的数据,我想src,和dst MAC地址一样应该没有问题吧。而且我判断过了,pMDL, pNetBufferList都不是NULL,就是到了最后调用发送函数发生问题。可以帮我看看,前面那里出问题了。多谢。