Why does NdisFRegisterFilterDriver return NDIS_STATUS_FAILURE?
Вопрос
I'm trying to write an NDIS Intermediate Filter driver, but I'm stuck before anything at all happens.
My code doesn't do anything yet, beyond trying to register the filter driver:
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
{
NDIS_FILTER_DRIVER_CHARACTERISTICS FChars;
NDIS_STRING ServiceName, UniqueName, FriendlyName;
NDIS_STATUS Status;
UNUSED(RegistryPath);
g_FilterObject = DriverObject;
RtlInitUnicodeString(&ServiceName, MIP_SERVICE_NAME);
RtlInitUnicodeString(&FriendlyName, MIP_FRIENDLY_NAME);
RtlInitUnicodeString(&UniqueName, MIP_UNIQUE_NAME);
NdisZeroMemory(&FChars, sizeof(NDIS_FILTER_DRIVER_CHARACTERISTICS));
FChars.Header.Type = NDIS_OBJECT_TYPE_FILTER_DRIVER_CHARACTERISTICS;
FChars.Header.Size = sizeof(NDIS_FILTER_DRIVER_CHARACTERISTICS);
FChars.Header.Revision = NDIS_FILTER_CHARACTERISTICS_REVISION_1;
FChars.MajorNdisVersion = 6;
FChars.MinorNdisVersion = 0;
FChars.MajorDriverVersion = 1;
FChars.MinorDriverVersion = 0;
FChars.Flags = 0;
FChars.FriendlyName = FriendlyName;
FChars.UniqueName = UniqueName;
FChars.ServiceName = ServiceName;
FChars.AttachHandler = FilterAttach;
FChars.DetachHandler = FilterDetach;
FChars.RestartHandler = FilterRestart;
FChars.PauseHandler = FilterPause;
FChars.SetOptionsHandler = FilterRegisterOptions;
FChars.SetFilterModuleOptionsHandler = FilterSetModuleOptions;
FChars.SendNetBufferListsHandler = FilterSend;
FChars.ReturnNetBufferListsHandler = FilterReturnNetBufferLists;
FChars.SendNetBufferListsCompleteHandler = FilterSendComplete;
FChars.ReceiveNetBufferListsHandler = FilterReceive;
FChars.CancelSendNetBufferListsHandler = FilterCancelSend;
FChars.DevicePnPEventNotifyHandler = FilterDevicePnPEvent;
FChars.NetPnPEventHandler = FilterNetPnPEvent;
FChars.StatusHandler = FilterStatus;
DriverObject->DriverUnload = FilterUnload;
Status = NdisFRegisterFilterDriver(DriverObject,
(NDIS_HANDLE)g_FilterObject,
&FChars,
&g_FilterHandle);
if (Status != NDIS_STATUS_SUCCESS)
{
MDBG("Failed to register filter driver %x", Status);
return Status;
}
return NDIS_STATUS_SUCCESS;
}
All of the other functions are empty (except for some tracing code). They don't matter here.
NdisFRegisterFilterDriver always returns NDIS_STATUS_FAILURE. The documentation does not describe why this can happen. (It shouldn't be a problem with the .inf file, as I've tried with a literal copy of the sample driver from the DDK.)
Решение
I don't see anything wrong with the code you've posted. Is MIP_UNIQUE_NAME
defined to be identical to the NetCfgInstanceId
from the INF? (Incidentally, remember to generate a new GUID different from the sample GUID — I've seen collisions, and it's not pretty).