locked
WEC7 ndis 6.0 driver question RRS feed

  • Question

  • Hi, I'm writing (or I try to...) an NDIS 6.0 device driver. My goal is to have an adapter on which I can send and receive ip packets over a serial (232 or 485) link.

    I send an DeviceIoCtl from an application to register the adapter using IOCTL_NDIS_REGISTER_ADAPTER.

    My driver is being loaded. DllEntry is being called. DriverEntry is being called and returns NDIS_STATUS_SUCCESS. My problem is after that, the initialize function is never being called. I get the following output:

    OSAXST1: >>> Loading Module 'davedriver.dll' (0xA04F6C08) at address 0xB8E40000-0xB8E44000 in Process 'NK.EXE' (0x8392E108)
    DAVED: DLL_PROCESS_ATTACH
    +DAVED: DriverEntry(0xB8602A90, 0xB8602AA0)
    ==>NdisMRegisterMiniportDriver: DriverObject B8602A90
    <==NdisMRegisterMiniportDriver: MiniBlock B85FE2B0
    DAVED: DriverEntry: MiniportHandle = 0xb85fe2b0
    -DAVED: DriverEntry: Returning STATUS_SUCCESS
    ==>ndisMUnloadEx: DriverObject B8602A90
    +DAVED: MpDriverUnload: Unloading the driver with driver object 0xa4475490.
    ==>NdisMDeregisterMiniportDriver: NdisMiniportDriverHandle B85FE2B0
    <==NdisMDeregisterMiniportDriver: NdisMiniportDriverHandle B85FE2B0
    -DAVED: MpDriverUnload.
    <==ndisMUnloadEx: DriverObject B8602A90, IoMiniBlock B85FE2B0, IMMiniBlock 00000000
    startdd: DeviceIoontrol GetLastError: -1073741823

    Registry looks like this:

    [HKEY_LOCAL_MACHINE\Drivers\DAVEDRIVER]
       "Dll"="ndis.dll"
       "Prefix"="NDS"
       "Miniport"="DAVEDRIVER"

    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER]
       "DisplayName"="Dave Driver for Serial Redundancy"
       "Group"="NDIS"
       "ImagePath"="davedriver.dll"
       "*IfType"=dword:16               ; for IF_TYPE_PROP_POINT2POINT_SERIAL 22 Proprietary serial
       "*MediaType"=dword:3             ; for NdisMediumWan 3
       "*PhysicalMediaType"=dword:12    ; for NdisPhysicalMediumWiredWAN 18
       "*NdisDeviceType"=dword:1        ; for NDIS_DEVICE_TYPE_ENDPOINT 0x00000001

    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER\Linkage]
       "Route"=multi_sz:"DAVEDRIVER1"

    The DriverEntry:

    NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    {
        NDIS_STATUS initStatus;
        NDIS_MINIPORT_DRIVER_CHARACTERISTICS mpCharacteristics;
    
        RETAILMSG(1, (TEXT("+DAVED: DriverEntry(0x%X, 0x%X)\r\n"), DriverObject, RegistryPath));
    
        v_pDriverObject = DriverObject;
        v_pDriverContext = (PDAVEDRIVER_CONTEXT)NULL;
        v_pAdapter = (PDAVEDRIVER_ADAPTER)NULL;
    
        NdisZeroMemory(&mpCharacteristics, sizeof(mpCharacteristics));
        mpCharacteristics.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_DRIVER_CHARACTERISTICS;
        mpCharacteristics.Header.Revision = NDIS_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_1; // For NDIS 6.0
        mpCharacteristics.Header.Size = NDIS_SIZEOF_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_1;
        mpCharacteristics.MajorNdisVersion = 0x06; // For NDIS 6.0
        mpCharacteristics.MinorNdisVersion = 0x00; // For NDIS 6.0
        mpCharacteristics.MajorDriverVersion = 0x01;
        mpCharacteristics.MinorDriverVersion = 0x00;
        mpCharacteristics.Flags = 0; //NDIS_WDM_DRIVER; // TODO DM: Not sure of this one.
        // Function pointers
        mpCharacteristics.SetOptionsHandler = MpSetOptions;
        mpCharacteristics.InitializeHandlerEx = MpInitialize;
        mpCharacteristics.HaltHandlerEx = MpHalt;
        mpCharacteristics.UnloadHandler = MpDriverUnload;
        mpCharacteristics.PauseHandler = MpPause;
        mpCharacteristics.RestartHandler = MpRestart;
        mpCharacteristics.OidRequestHandler = MpOidRequest;
        mpCharacteristics.SendNetBufferListsHandler = MpSendNetBufferLists;
        mpCharacteristics.ReturnNetBufferListsHandler = MpReturnNetBufferLists;
        mpCharacteristics.CancelSendHandler = MpCancelSend;
        mpCharacteristics.CheckForHangHandlerEx = MpCheckForHangEx;
        mpCharacteristics.ResetHandlerEx = MpResetEx;
        mpCharacteristics.DevicePnPEventNotifyHandler = MpDevicePnPEventNotify;
        mpCharacteristics.ShutdownHandlerEx = MpShutdownEx;
        mpCharacteristics.CancelOidRequestHandler = MpCancelOidRequest;
    
        initStatus = NdisMRegisterMiniportDriver(DriverObject, RegistryPath, v_hMiniportDriverContext, &mpCharacteristics, &v_hDriver);
        RETAILMSG(1, (TEXT("DAVED: DriverEntry: MiniportHandle = 0x%08x\r\n"), v_hDriver));
    
        if(initStatus == NDIS_STATUS_BAD_CHARACTERISTICS)
        {
            RETAILMSG(1, (TEXT("DAVED: DriverEntry: Error NDIS_STATUS_BAD_CHARACTERISTICS")));
        }
    
        if(initStatus == NDIS_STATUS_BAD_VERSION)
        {
            RETAILMSG(1, (TEXT("DAVED: DriverEntry: Error NDIS_STATUS_BAD_VERSION")));
        }
    
        if(initStatus == NDIS_STATUS_RESOURCES)
        {
            RETAILMSG(1, (TEXT("DAVED: DriverEntry: Error NDIS_STATUS_RESOURCES")));
        }
    
        if (initStatus != NDIS_STATUS_SUCCESS)
        {
            RETAILMSG(1, (TEXT("-DAVED: DriverEntry: Returning STATUS_FAILURE.\r\n"),
                DriverObject, RegistryPath));
    
            NdisMDeregisterMiniportDriver(v_hDriver);
            return NDIS_STATUS_FAILURE;
        }
    
        v_pDriverContext = (PDAVEDRIVER_CONTEXT)DDAllocateMemory(v_hDriver, sizeof(DAVEDRIVER_CONTEXT));
        v_GlobalAdapterCount = 0;
    
        RETAILMSG(1, (TEXT("-DAVED: DriverEntry: Returning STATUS_SUCCESS\r\n"), DriverObject, RegistryPath));
        return NDIS_STATUS_SUCCESS;
    }

    Any hint on why it is failing?

    Thanks

    David

    Tuesday, November 12, 2013 5:24 PM

Answers

  • Got it!!!

    Look at this before/after of the .reg file:

    [HKEY_LOCAL_MACHINE\Drivers\DAVEDRIVER]
       "Dll"="ndis.dll"
       "Prefix"="NDS"
       "Miniport"="DAVEDRIVER"
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER]
       "DisplayName"="Dave Driver for Serial Redundancy"
       "Group"="NDIS"
       "ImagePath"="davedriver.dll"
       "*IfType"=dword:1               ; for IF_TYPE_OTHER
       "*MediaType"=dword:0             ; for NdisMedium802_3 0
       "*PhysicalMediaType"=dword:0    ; for NdisPhysicalMediumUnspecified 0
       "*NdisDeviceType"=dword:1        ; for NDIS_DEVICE_TYPE_ENDPOINT 0x00000001
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER\Linkage]
       "Route"=multi_sz:"DAVEDRIVER1"
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms]
       "BusNumber"=dword:0
       "BusType"=dword:0
       "RebindOnResume"=dword:0
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms\TcpIp]
       "EnableDHCP"=dword:0
       "IpAddress"=multi_sz:"100.0.0.1"
       "Subnetmask"=multi_sz:"255.255.255.0"

    [HKEY_LOCAL_MACHINE\Drivers\DAVEDRIVER]
       "Dll"="ndis.dll"
       "Prefix"="NDS"
       "Miniport"="DAVEDRIVER"
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER]
       "DisplayName"="Dave Driver for Serial Redundancy"
       "Group"="NDIS"
       "ImagePath"="davedriver.dll"
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER\Linkage]
       "Route"=multi_sz:"DAVEDRIVER1"
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms]
       "BusNumber"=dword:0
       "BusType"=dword:0
       "RebindOnResume"=dword:0
       "*IfType"=dword:1               ; for IF_TYPE_OTHER
       "*MediaType"=dword:0             ; for NdisMedium802_3 0
       "*PhysicalMediaType"=dword:0    ; for NdisPhysicalMediumUnspecified 0
       "*NdisDeviceType"=dword:1        ; for NDIS_DEVICE_TYPE_ENDPOINT 0x00000001
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms\TcpIp]
       "EnableDHCP"=dword:0
       "IpAddress"=multi_sz:"100.0.0.1"
       "Subnetmask"=multi_sz:"255.255.255.0"
       

    The params are by adapter!!! A simple copy/paste in the right section and it now works.

    Thanks for your help!

    David

    • Marked as answer by David Mercier Wednesday, November 13, 2013 8:02 PM
    Wednesday, November 13, 2013 8:02 PM

All replies

  • Anyone has an NDIS 6.0 sample driver working so I can compare the code, the registry values and other stuff??
    Tuesday, November 12, 2013 8:40 PM
  • Hi,

    Just checked the code for DriverEntry provided by you. To me it seems perfectly normal. 

    The registry settings also play a key role in NDIS drivers and hence you may focus on the same. Particularly some points that can cause this could be the registry wherein you specify interface types :

    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER]
       "DisplayName"="Dave Driver for Serial Redundancy"
       "Group"="NDIS"
       "ImagePath"="davedriver.dll"
       "*IfType"=dword:16               ; for IF_TYPE_PROP_POINT2POINT_SERIAL 22 Proprietary serial
       "*MediaType"=dword:3             ; for NdisMediumWan 3
       "*PhysicalMediaType"=dword:12    ; for NdisPhysicalMediumWiredWAN 18
       "*NdisDeviceType"=dword:1        ; for NDIS_DEVICE_TYPE_ENDPOINT 0x00000001

    This link http://msdn.microsoft.com/en-us/library/windows/hardware/ff557037(v=vs.85).aspx gives a solid explanation. I have a few doubts though , as to why are you choosing MediaType as WAN. The link specifies NdisMediumWAN is not supported starting from vista. If you are using WEC7 or WEC 2013 it is highly probable that the above settings is faulty.

    Also why not set MediaType as NdisMedium802_3 and PhysicalMediaType as NdisPhysicalMediumOther. 

    Various combinations of trial and errors might resolve the issue.

    Also you asked for some samples:

    If you are using WEC7 refer to public\common\oak\drivers\netcard\ for driver samples e.g. e100bex.

    Also the registry settings for the above driver can be seen under common.reg.

    Regards,

    Balaji.

    Wednesday, November 13, 2013 6:48 PM
  • Got it!!!

    Look at this before/after of the .reg file:

    [HKEY_LOCAL_MACHINE\Drivers\DAVEDRIVER]
       "Dll"="ndis.dll"
       "Prefix"="NDS"
       "Miniport"="DAVEDRIVER"
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER]
       "DisplayName"="Dave Driver for Serial Redundancy"
       "Group"="NDIS"
       "ImagePath"="davedriver.dll"
       "*IfType"=dword:1               ; for IF_TYPE_OTHER
       "*MediaType"=dword:0             ; for NdisMedium802_3 0
       "*PhysicalMediaType"=dword:0    ; for NdisPhysicalMediumUnspecified 0
       "*NdisDeviceType"=dword:1        ; for NDIS_DEVICE_TYPE_ENDPOINT 0x00000001
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER\Linkage]
       "Route"=multi_sz:"DAVEDRIVER1"
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms]
       "BusNumber"=dword:0
       "BusType"=dword:0
       "RebindOnResume"=dword:0
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms\TcpIp]
       "EnableDHCP"=dword:0
       "IpAddress"=multi_sz:"100.0.0.1"
       "Subnetmask"=multi_sz:"255.255.255.0"

    [HKEY_LOCAL_MACHINE\Drivers\DAVEDRIVER]
       "Dll"="ndis.dll"
       "Prefix"="NDS"
       "Miniport"="DAVEDRIVER"
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER]
       "DisplayName"="Dave Driver for Serial Redundancy"
       "Group"="NDIS"
       "ImagePath"="davedriver.dll"
    
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER\Linkage]
       "Route"=multi_sz:"DAVEDRIVER1"
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms]
       "BusNumber"=dword:0
       "BusType"=dword:0
       "RebindOnResume"=dword:0
       "*IfType"=dword:1               ; for IF_TYPE_OTHER
       "*MediaType"=dword:0             ; for NdisMedium802_3 0
       "*PhysicalMediaType"=dword:0    ; for NdisPhysicalMediumUnspecified 0
       "*NdisDeviceType"=dword:1        ; for NDIS_DEVICE_TYPE_ENDPOINT 0x00000001
       
    [HKEY_LOCAL_MACHINE\Comm\DAVEDRIVER1\Parms\TcpIp]
       "EnableDHCP"=dword:0
       "IpAddress"=multi_sz:"100.0.0.1"
       "Subnetmask"=multi_sz:"255.255.255.0"
       

    The params are by adapter!!! A simple copy/paste in the right section and it now works.

    Thanks for your help!

    David

    • Marked as answer by David Mercier Wednesday, November 13, 2013 8:02 PM
    Wednesday, November 13, 2013 8:02 PM