I think there is nothing wrong with the memory allocation and initializaiton, but i still get blue screen.
I list all the codes:
NDIS_STATUS
filterCreateNewMACRequest(
IN NDIS_HANDLE FilterModuleContext,
IN NDIS_OID Oid
)
/* Routine Description:
Send OID to underlying driver to create a new MAC
Arguments:
FilterModuleContext - pointer to filter module context
Oid – OID_DOT11_CREATE_MAC
*/
{
PMS_FILTER pFilter =(PMS_FILTER)FilterModuleContext;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PVOID InformationBuffer = NULL;
ULONG InformationBufferLength;
ULONG OutputBufferLength;
ULONG MethodId;
PULONG pBytesProcessed = NULL;
//PUCHAR DataExample = “Hello World!”;
DEBUGP(DL_TEST,(“==>FilterCreateNEwMACRequest!\n”));
InformationBuffer = NdisAllocateMemoryWithTagPriority(pFilter->FilterHandle,sizeof(DOT11_MAC_INFO),FILTER_ALLOC_TAG, LowPoolPriority);
NdisZeroMemory(InformationBuffer, sizeof(DOT11_MAC_INFO));
InformationBufferLength = OutputBufferLength = sizeof(DOT11_MAC_INFO);
// RtlCopyMemory(InformationBuffer,DataExample,sizeof(“HelloWorld!”));
MethodId = 0;
pBytesProcessed = (PULONG)NdisAllocateMemoryWithTagPriority(pFilter->FilterHandle,sizeof(ULONG),FILTER_ALLOC_TAG, LowPoolPriority);
*pBytesProcessed = 0;
//DEBUGP(DL_TEST,(“Infomation Buffer is %s and length is %u, and byteprocessed is %u”,InformationBuffer,InformationBufferLength,*pBytesProcessed));
Status = filterDoInternalRequest(pFilter,
NdisRequestMethod,
Oid,
InformationBuffer,
InformationBufferLength,
OutputBufferLength,
MethodId,
pBytesProcessed);
if(Status == NDIS_STATUS_SUCCESS)
{
DEBUGP(DL_TEST,(“Create new mac successfully, and the length is %u!\n”,InformationBufferLength));
goto Exit;
}else
{
DEBUGP(DL_TEST,(“Fail to create new MAC!\n”));
goto Exit;
}
Exit:
return Status;
}
The function of filterDoInternalRequest:
NDIS_STATUS
filterDoInternalRequest(
IN PMS_FILTER FilterModuleContext,
IN NDIS_REQUEST_TYPE RequestType,
IN NDIS_OID Oid,
IN PVOID InformationBuffer,
IN ULONG InformationBufferLength,
IN ULONG OutputBufferLength, OPTIONAL
IN ULONG MethodId, OPTIONAL
OUT PULONG pBytesProcessed
)
/*++
Routine Description:
Utility routine that forms and sends an NDIS_OID_REQUEST to the
miniport, waits for it to complete, and returns status
to the caller.
NOTE: this assumes that the calling routine ensures validity
of the filter handle until this returns.
Arguments:
FilterModuleContext - pointer to our filter module context
RequestType - NdisRequest[Set|Query|method]Information
Oid - the object being set/queried
InformationBuffer - data for the request
InformationBufferLength - length of the above
OutputBufferLength - valid only for method request
MethodId - valid only for method request
pBytesProcessed - place to return bytes read/written
Return Value:
Status of the set/query request
–*/
{
FILTER_REQUEST FilterRequest;
PNDIS_OID_REQUEST NdisRequest = &FilterRequest.Request;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
DEBUGP(DL_TEST,(“==>filterDoInternalRequest\n”))
NdisZeroMemory(NdisRequest, sizeof(NDIS_OID_REQUEST));
NdisInitializeEvent(&FilterRequest.ReqEvent);
NdisRequest->Header.Type = NDIS_OBJECT_TYPE_OID_REQUEST;
NdisRequest->Header.Revision = NDIS_OID_REQUEST_REVISION_1;
NdisRequest->Header.Size = sizeof(NDIS_OID_REQUEST);
NdisRequest->RequestType = RequestType;
switch (RequestType)
{
case NdisRequestQueryInformation:
NdisRequest->DATA.QUERY_INFORMATION.Oid = Oid;
NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer =
InformationBuffer;
NdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength =
InformationBufferLength;
break;
case NdisRequestSetInformation:
NdisRequest->DATA.SET_INFORMATION.Oid = Oid;
NdisRequest->DATA.SET_INFORMATION.InformationBuffer =
InformationBuffer;
NdisRequest->DATA.SET_INFORMATION.InformationBufferLength =
InformationBufferLength;
break;
case NdisRequestMethod:
NdisRequest->DATA.METHOD_INFORMATION.Oid = Oid;
NdisRequest->DATA.METHOD_INFORMATION.MethodId = MethodId;
NdisRequest->DATA.METHOD_INFORMATION.InformationBuffer =
InformationBuffer;
NdisRequest->DATA.METHOD_INFORMATION.InputBufferLength =
InformationBufferLength;
NdisRequest->DATA.METHOD_INFORMATION.OutputBufferLength = OutputBufferLength;
break;
default:
FILTER_ASSERT(FALSE);
break;
}
NdisRequest->RequestId = (PVOID)FILTER_REQUEST_ID;
Status = NdisFOidRequest(FilterModuleContext->FilterHandle,
NdisRequest);
if (Status == NDIS_STATUS_PENDING)
{
NdisWaitEvent(&FilterRequest.ReqEvent, 0);
Status = FilterRequest.Status;
}
if (Status == NDIS_STATUS_SUCCESS)
{
if (RequestType == NdisRequestSetInformation)
{
*pBytesProcessed = NdisRequest->DATA.SET_INFORMATION.BytesRead;
}
if (RequestType == NdisRequestQueryInformation)
{
*pBytesProcessed = NdisRequest->DATA.QUERY_INFORMATION.BytesWritten;
}
if (RequestType == NdisRequestMethod)
{
*pBytesProcessed = NdisRequest->DATA.METHOD_INFORMATION.BytesWritten;
}
//
// The driver below should set the correct value to BytesWritten
// or BytesRead. But now, we just truncate the value to InformationBufferLength
// It still need to be process …
if (RequestType == NdisRequestMethod)
{
if (*pBytesProcessed > OutputBufferLength)
{
*pBytesProcessed = OutputBufferLength;
}
}
else
{
if (*pBytesProcessed > InformationBufferLength)
{
*pBytesProcessed = InformationBufferLength;
}
}
}
return (Status);
}
I hava a test there is nothing wrong before the program calls the NdisFOidRequest(). So, maybe the parameters in the NdisRequest are invalid? or still memory problem? I have no idea!