Example #1
0
NDIS_STATUS 
DriverEntry(
    IN  PDRIVER_OBJECT      DriverObject,
    IN  PUNICODE_STRING     RegistryPath )
{
    NDIS_FILTER_DRIVER_CHARACTERISTICS  FilterCharacteristics;
    NDIS_STATUS NdisStatus;

    DPF(("%s!%s DriverObject=%p RegistryPath=%wZ\n", __MODULE__, __FUNCTION__, 
        DriverObject, RegistryPath )); 

    DriverObject->DriverUnload = DriverUnload;

    GlobalNDISLWF.FilterDriverHandle = NULL;

    // Setup the FilterCharacteristics structure
    // Handlers implemented by the driver are :
    // AttachHandler, DetachHandler, RestartHandler, PauseHandler, StatusHandler
    // ReceiveNetBufferListsHandler, ReturnNetBufferListsHandler
    NdisZeroMemory(&FilterCharacteristics, sizeof(NDIS_FILTER_DRIVER_CHARACTERISTICS));

    FilterCharacteristics.Header.Type = NDIS_OBJECT_TYPE_FILTER_DRIVER_CHARACTERISTICS;
    FilterCharacteristics.Header.Size = sizeof(NDIS_FILTER_DRIVER_CHARACTERISTICS);
    FilterCharacteristics.Header.Revision = NDIS_FILTER_CHARACTERISTICS_REVISION_1;
    FilterCharacteristics.MajorNdisVersion = NDISLWF_NDIS_MAJOR_VERSION;
    FilterCharacteristics.MinorNdisVersion = NDISLWF_NDIS_MINOR_VERSION;
    FilterCharacteristics.MajorDriverVersion = NDISLWF_DRIVER_MAJOR_VERSION;
    FilterCharacteristics.MinorDriverVersion = NDISLWF_DRIVER_MINOR_VERSION;
    FilterCharacteristics.Flags = 0;
    NdisInitUnicodeString ( &FilterCharacteristics.FriendlyName, NDISLWF_FRIENDLY_NAME );
    NdisInitUnicodeString ( &FilterCharacteristics.UniqueName, NDISLWF_UNIQUE_NAME);
    NdisInitUnicodeString ( &FilterCharacteristics.ServiceName, NDISLWF_SERVICE_NAME);
    FilterCharacteristics.AttachHandler = NDISLWF_AttachHandler;
    FilterCharacteristics.DetachHandler = NDISLWF_DetachHandler;
    FilterCharacteristics.RestartHandler = NDISLWF_RestartHandler;
    FilterCharacteristics.PauseHandler = NDISLWF_PauseHandler;
    FilterCharacteristics.StatusHandler = NDISLWF_StatusHandler;
    FilterCharacteristics.ReceiveNetBufferListsHandler = NDISLWF_ReceiveNetBufferListsHandler;
    FilterCharacteristics.ReturnNetBufferListsHandler = NDISLWF_ReturnNetBufferListsHandler;

    // Register the filter driver using the FilterCharacteristics structure
    // NdisFRegisterFilterDriver())
    NdisStatus = NdisFRegisterFilterDriver(
        DriverObject,
        (NDIS_HANDLE)DriverObject, // no driver-wide context
        &FilterCharacteristics, 
        &GlobalNDISLWF.FilterDriverHandle);

    if (NdisStatus != NDIS_STATUS_SUCCESS) {
        DPF(("%s!%s NdisFRegisterFilterDriver() FAIL=%08x\n", __MODULE__, __FUNCTION__, NdisStatus));
        goto Exit1;
    }

    DPF(("%s!%s NdisFRegisterFilterDriver() FilterDriverHandle=%p\n", __MODULE__, __FUNCTION__, 
        GlobalNDISLWF.FilterDriverHandle )); 

Exit1 :
    return NdisStatus;
}
Example #2
0
/*
 * --------------------------------------------------------------------------
 * Init/Load function for the OVSEXT filter Driver.
 * --------------------------------------------------------------------------
 */
NTSTATUS
DriverEntry(PDRIVER_OBJECT driverObject,
            PUNICODE_STRING registryPath)
{
    NDIS_STATUS status;
    NDIS_FILTER_DRIVER_CHARACTERISTICS driverChars;

    UNREFERENCED_PARAMETER(registryPath);

    gOvsExtDriverObject = driverObject;

    RtlZeroMemory(&driverChars, sizeof driverChars);
    driverChars.Header.Type = NDIS_OBJECT_TYPE_FILTER_DRIVER_CHARACTERISTICS;
    driverChars.Header.Size = sizeof driverChars;
    driverChars.Header.Revision = NDIS_FILTER_CHARACTERISTICS_REVISION_2;
    driverChars.MajorNdisVersion = NDIS_FILTER_MAJOR_VERSION;
    driverChars.MinorNdisVersion = NDIS_FILTER_MINOR_VERSION;
    driverChars.MajorDriverVersion = 1;
    driverChars.MinorDriverVersion = 0;
    driverChars.Flags = 0;

    RtlInitUnicodeString(&driverChars.ServiceName, ovsExtServiceName);
    RtlInitUnicodeString(&ovsExtFriendlyNameUC, ovsExtFriendlyName);
    RtlInitUnicodeString(&ovsExtGuidUC, ovsExtGuidStr);

    driverChars.FriendlyName = ovsExtFriendlyNameUC;
    driverChars.UniqueName = ovsExtGuidUC;

    driverChars.AttachHandler = OvsExtAttach;
    driverChars.DetachHandler = OvsExtDetach;
    driverChars.RestartHandler = OvsExtRestart;
    driverChars.PauseHandler = OvsExtPause;

    driverChars.SendNetBufferListsHandler = OvsExtSendNBL;
    driverChars.SendNetBufferListsCompleteHandler = OvsExtSendNBLComplete;
    driverChars.CancelSendNetBufferListsHandler = OvsExtCancelSendNBL;
    driverChars.ReceiveNetBufferListsHandler = NULL;
    driverChars.ReturnNetBufferListsHandler = NULL;

    driverChars.OidRequestHandler = OvsExtOidRequest;
    driverChars.OidRequestCompleteHandler = OvsExtOidRequestComplete;
    driverChars.CancelOidRequestHandler = OvsExtCancelOidRequest;

    driverChars.DevicePnPEventNotifyHandler = NULL;
    driverChars.NetPnPEventHandler = OvsExtNetPnPEvent;
    driverChars.StatusHandler = NULL;

    driverObject->DriverUnload = OvsExtUnload;

    status = NdisFRegisterFilterDriver(driverObject,
                                       (NDIS_HANDLE) gOvsExtDriverObject,
                                       &driverChars, &gOvsExtDriverHandle);
    if (status != NDIS_STATUS_SUCCESS) {
        return status;
    }

    /* Create the communication channel for usersapce. */
    status = OvsCreateDeviceObject(gOvsExtDriverHandle);
    if (status != NDIS_STATUS_SUCCESS) {
        NdisFDeregisterFilterDriver(gOvsExtDriverHandle);
        gOvsExtDriverHandle = NULL;
    }

    return status;
}
Example #3
0
//
// DriverEntry
// http://msdn.microsoft.com/en-us/library/ff544113(v=VS.85).aspx
//
_Use_decl_annotations_
NTSTATUS
DriverEntry(
    PDRIVER_OBJECT DriverObject,
    PUNICODE_STRING RegistryPath
    )
{
    NDIS_STATUS status;
    NDIS_FILTER_DRIVER_CHARACTERISTICS fChars;
    NDIS_STRING serviceName;

    UNREFERENCED_PARAMETER(RegistryPath);
    
    //
    // Initialize extension specific data.
    //
    status = SxExtInitialize();
    if (status != NDIS_STATUS_SUCCESS)
    {
        goto Cleanup;
    }

    RtlInitUnicodeString(&serviceName, SxExtServiceName);
    RtlInitUnicodeString(&SxExtensionFriendlyName, SxExtFriendlyName);
    RtlInitUnicodeString(&SxExtensionGuid, SxExtUniqueName);
    SxDriverObject = DriverObject;

    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_2;
    fChars.MajorNdisVersion = SxExtMajorNdisVersion;
    fChars.MinorNdisVersion = SxExtMinorNdisVersion;
    fChars.MajorDriverVersion = 1;
    fChars.MinorDriverVersion = 0;
    fChars.Flags = 0;
    fChars.FriendlyName = SxExtensionFriendlyName;
    fChars.UniqueName = SxExtensionGuid;
    fChars.ServiceName = serviceName;
    
    fChars.SetOptionsHandler = SxNdisSetOptions;
    fChars.SetFilterModuleOptionsHandler = SxNdisSetFilterModuleOptions;
    
    fChars.AttachHandler = SxNdisAttach;
    fChars.DetachHandler = SxNdisDetach;
    fChars.PauseHandler = SxNdisPause;
    fChars.RestartHandler = SxNdisRestart;

    fChars.SendNetBufferListsHandler = SxNdisSendNetBufferLists;
    fChars.SendNetBufferListsCompleteHandler = SxNdisSendNetBufferListsComplete;
    fChars.CancelSendNetBufferListsHandler = SxNdisCancelSendNetBufferLists;
    fChars.ReceiveNetBufferListsHandler = SxNdisReceiveNetBufferLists;
    fChars.ReturnNetBufferListsHandler = SxNdisReturnNetBufferLists;
    
    fChars.OidRequestHandler = SxNdisOidRequest;
    fChars.OidRequestCompleteHandler = SxNdisOidRequestComplete;
    fChars.CancelOidRequestHandler = SxNdisCancelOidRequest;
    
    fChars.NetPnPEventHandler = SxNdisNetPnPEvent;
    fChars.StatusHandler = SxNdisStatus;
    
    NdisAllocateSpinLock(&SxExtensionListLock);
    InitializeListHead(&SxExtensionList);

    DriverObject->DriverUnload = SxNdisUnload;

    status = NdisFRegisterFilterDriver(DriverObject,
                                       (NDIS_HANDLE)SxDriverObject,
                                       &fChars,
                                       &SxDriverHandle);

Cleanup:

    if (status != NDIS_STATUS_SUCCESS)
    {
        if (SxDriverHandle != NULL)
        {
            NdisFDeregisterFilterDriver(SxDriverHandle);
            SxDriverHandle = NULL;
        }

        NdisFreeSpinLock(&SxExtensionListLock);
        
        SxExtUninitialize();
    }

    return status;
}