none
WEC7 - NDIS 6.0 - Timing problem? RRS feed

  • Question

  • Hi,

    I'm debugging my NDIS 6.0 driver under WEC7. Right after my Initialize function returns NDIS_STATUS_SUCCESS, the folowing is on the debug port:

    ==>NdisOpenConfigurationEx: ConfigObject ACF7EC40
    ==>NdisOpenConfiguration: WrapperConfigurationContext B8801D30
    <==NdisOpenConfiguration: WrapperConfigurationContext B8801D30
    <==NdisOpenConfigurationEx: ConfigObject ACF7EC40, Status 0
    ==>NdisReadConfiguration: Keyword: *IfType
    <==NdisReadConfiguration
    Unknown: DEBUGCHK failed in file d:\bt\1581\private\winceos\net\ndis\sys\miniport.c at line 12464

    The callstack goes like this:

    NDIS!ndisCheckIfTypeMismatch(_NDIS_MINIPORT_BLOCK * ...) miniport.c line 12464 + 28 bytes
    NDIS!ndisMInitializeAdapter(_NDIS_M_DRIVER_BLOCK * ...) miniport.c line 1315 + 19 bytes
    NDIS!ndisInitializeAdapter(_NDIS_M_DRIVER_BLOCK * ...) initpnp.c line 1389 + 37 bytes
    NDIS!ndisPnPStartDevice(_CEDEVICE_OBJECT * ...) configm.c line 4449 + 39 bytes
    NDIS!ndisAddDevice(_CEDRIVER_OBJECT * ...) configm.c line 5549 + 11 bytes
    NDIS!CeDeviceCreateDeviceForLoadedDriver(_CEDRIVER_OBJECT * ...) cedevice.c line 247 + 21 bytes
    NDIS!CeDeviceLoadDriverAndCreateDevice(unsigned short * 0xef691b94 "\Comm", unsigned short * 0xb860dfe0 "DAVEDRIVER", unsigned short * 0xef691ba0 "NDIS", unsigned short * 0xb860dff6 "DAVEDRIVER1", unsigned long 0x00000000, unsigned long 0x00000000, long (_CEDRIVER_OBJECT *, _UNICODE_STRING *, _CEDEVICE_OBJECT *, unsigned long, void *)* ...) cedevice.c line 295 + 33 bytes
    NDIS!CeDeviceLoadDriverAndCreateNonPnPDevice(unsigned short * 0xef691b94 "\Comm", unsigned short * 0xb860dfe0 "DAVEDRIVER", unsigned short * 0xef691ba0 "NDIS", unsigned short * 0xb860dff6 "DAVEDRIVER1", long (_CEDRIVER_OBJECT *, _UNICODE_STRING *, _CEDEVICE_OBJECT *, unsigned long, void *)* ...) cedevice.c line 339 + 39 bytes
    NDIS!NdisRegisterAdapter(int * 0xacf7fa44, unsigned short * 0xb860dfe0 "DAVEDRIVER", unsigned short * 0xb860dff6 "DAVEDRIVER1") cestreamdrv.c line 1559 + 28 bytes
    NDIS!NDS_IOControl(unsigned long 0x4d15ba5e, unsigned long 0x00170026, unsigned char * 0x0002ee18 "D", unsigned long 0x00000030, unsigned char * 0x00000000 <Bad Ptr>, unsigned long 0x00000000, unsigned long * 0xacf7fb30) cestreamdrv.c line 2646 + 17 bytes
    DEVMGR!DriverFilterMgr::DriverControl(unsigned long 0x4d15ba5e, unsigned long 0x00170026, unsigned char * 0x0002ee18 "D", unsigned long 0x00000030, unsigned char * 0x00000000 <Bad Ptr>, unsigned long 0x00000000, unsigned long * 0xacf7fb30, void * 0xb860df40) filter.h line 107 + 116 bytes
    DEVMGR!DriverControl(fsdev_t * 0xacf05614 {list={Flink=0xacf0a054 {Flink=0xac86d8d4 {Flink=0xac86e914 Blink=0xacf0a054 } Blink=0xacf05614 {Flink=0xacf0a054 Blink=0xacf05154 } } Blink=0xacf05154 {Flink=0xacf05614 {Flink=0xacf0a054 Blink=0xacf05154 } Blink=0xacf04e74 {Flink=0xacf05154 Blink=0xacf04934 } } } fnInit=0xef6b00e0 NDS_Init(unsigned long) fnInitEx=0x00000000 ...}, ...) filt
    DEVMGR!IoPckManager::DevDeviceIoControl(unsigned long 0x00170026, void * 0x0002ee18, unsigned long 0x00000030, void * 0x00000000, unsigned long 0x00000000, unsigned long * 0x00000000, _OVERLAPPED * 0x00000000 {Internal=??? InternalHigh=??? Offset=??? ...}) filemgr.cpp line 369 + 47 bytes
    DEVMGR!DevDeviceIoControl(fsopendev_t * ...) filemgr.cpp line 103 + 41 bytes
    DEVMGR!DM_DevDeviceIoControl(fsopendev_t * ...) devfile.c line 491 + 37 bytes
    COREDLL!xxx_DeviceIoControl(void * 0x01c81903, unsigned long 0x00170026, void * 0x0002ee18, unsigned long 0x00000030, void * 0x00000000, unsigned long 0x00000000, unsigned long * 0x00000000, _OVERLAPPED * 0x00000000 {Internal=??? InternalHigh=??? Offset=??? ...}) twinbase.cpp line 32 + 50 bytes
    startdd!RegisterAdapter(int * 0x0002f0c4, wchar_t * 0x00015a54 "DAVEDRIVER", wchar_t * 0x0002f0d4 "DAVEDRIVER1") startdd.cpp line 111 + 33 bytes
    startdd!OpenNdisAdapter(unsigned long 0x00000001, unsigned long 0x65000001, unsigned long 0xffffff00, wchar_t * 0x0002f744 "DaveDriver", unsigned long 0x0000000a, unsigned long 0x0001c200) startdd.cpp line 73 + 6 bytes
    startdd!wmain(int 0x00000001, wchar_t * * 0x00030810, wchar_t * * 0x182caf48) startdd.cpp line 134 + 26 bytes
    startdd!mainCRTStartupHelper(HINSTANCE__ * 0x09140052 {unused=??? }, const wchar_t * 0x573542d3 <Bad Ptr>) crtstrta.cxx line 351 + 7 bytes
    startdd!mainWCRTStartup(HINSTANCE__ * 0x09140052 {unused=??? }, HINSTANCE__ * 0x00000000 {unused=??? }, wchar_t * 0x0002fc70 "", int 0x00000005) crtstrta.cxx line 383 + 11 bytes
    COREDLL!MainThreadBaseFunc(void * 0x00011e1d mainWCRTStartup(HINSTANCE__ *, HINSTANCE__ *, wchar_t *, int), const wchar_t * 0x0002fc58 "startdd.EXE", const wchar_t * 0x0002fc70 "", HINSTANCE__ * 0xa0410520 {unused=0xa04d41a8 }, HINSTANCE__ * 0x00000000 {unused=??? }, HINSTANCE__ * 0x00000000 {unused=??? }) loader.cpp line 1209 + 60 bytes

    The dissassembly is:

    --- d:\bt\1581\private\winceos\net\ndis\sys\miniport.c
    ndisCheckIfTypeMismatch:
    EF6E79C0    push        ebp
    EF6E79C1    mov         ebp,esp
    EF6E79C3    sub         esp,4F8h
    EF6E79C9    mov         eax,dword ptr [___security_cookie (ef75f5ac)]
    EF6E79CE    xor         eax,ebp
    EF6E79D0    mov         dword ptr [ebp-14h],eax
    EF6E79D3    push        esi
    EF6E79D4    mov         dword ptr [ebp-4D4h],0
    EF6E79DE    mov         eax,0Eh
    EF6E79E3    mov         word ptr [ebp-4B8h],ax
    EF6E79EA    mov         ecx,10h
    EF6E79EF    mov         word ptr [ebp-4B6h],cx
    EF6E79F6    mov         dword ptr [ebp-4B4h],offset string L"*IfType" (ef69b154)
    EF6E7A00    mov         edx,18h
    EF6E7A05    mov         word ptr [ebp-4D0h],dx
    EF6E7A0C    mov         eax,1Ah
    EF6E7A11    mov         word ptr [ebp-4CEh],ax
    EF6E7A18    mov         dword ptr [ebp-4CCh],offset string L"NetLuidIndex" (ef69b38c)
    EF6E7A22    mov         dword ptr [ebp-4B0h],0
    EF6E7A2C    mov         dword ptr [ebp-4E0h],0
    EF6E7A36    mov         byte ptr [ebp-4C4h],0A9h
    EF6E7A3D    mov         byte ptr [ebp-4C3h],1
    EF6E7A44    mov         ecx,0Ch
    EF6E7A49    mov         word ptr [ebp-4C2h],cx
    EF6E7A50    mov         edx,dword ptr [ebp+8]
    EF6E7A53    mov         dword ptr [ebp-4C0h],edx
    EF6E7A59    mov         dword ptr [ebp-4BCh],0
    EF6E7A63    lea         eax,[ebp-4B0h]
    EF6E7A69    push        eax
    EF6E7A6A    lea         ecx,[ebp-4C4h]
    EF6E7A70    push        ecx
    EF6E7A71    call        NdisOpenConfigurationEx (ef6f0760)
    EF6E7A76    add         esp,8
    EF6E7A79    mov         dword ptr [ebp-4D4h],eax
    EF6E7A7F    cmp         dword ptr [ebp-4D4h],0
    EF6E7A86    je          ndisCheckIfTypeMismatch+0CDh (ef6e7a8d)
    EF6E7A88    jmp         ndisCheckIfTypeMismatch+712h (ef6e80d2)
    EF6E7A8D    push        0
    EF6E7A8F    lea         edx,[ebp-4B8h]
    EF6E7A95    push        edx
    EF6E7A96    mov         eax,dword ptr [ebp-4B0h]
    EF6E7A9C    push        eax
    EF6E7A9D    lea         ecx,[ebp-4E4h]
    EF6E7AA3    push        ecx
    EF6E7AA4    lea         edx,[ebp-4D4h]
    EF6E7AAA    push        edx
    EF6E7AAB    call        NdisReadConfiguration (ef6ef640)
    EF6E7AB0    add         esp,14h
    EF6E7AB3    cmp         dword ptr [ebp-4D4h],0
    EF6E7ABA    je          ndisCheckIfTypeMismatch+11Eh (ef6e7ade)
    EF6E7ABC    push        309Dh
    EF6E7AC1    push        offset string L"d:\\bt\\1581\\private\\w"... (ef698c50)
    EF6E7AC6    push        offset string L"Unknown" (ef6910cc)
    EF6E7ACB    push        offset string L"%s: DEBUGCHK failed "... (ef691070)
    EF6E7AD0    call        NKDbgPrintfW (ef74bc5e)
    EF6E7AD5    add         esp,10h
    EF6E7AD8    int         3
    EF6E7AD9    jmp         ndisCheckIfTypeMismatch+712h (ef6e80d2)
    EF6E7ADE    mov         eax,dword ptr [ebp-4E4h]
    EF6E7AE4    mov         cx,word ptr [eax+4]
    EF6E7AE8    mov         word ptr [ebp-4ACh],cx
    EF6E7AEF    movzx       edx,word ptr [ebp-4ACh]
    EF6E7AF6    mov         eax,dword ptr [ebp+0Ch]
    EF6E7AF9    movzx       ecx,word ptr [eax+0A8h]
    EF6E7B00    cmp         edx,ecx
    EF6E7B02    je          ndisCheckIfTypeMismatch+70Ah (ef6e80ca)
    EF6E7B08    mov         edx,dword ptr [ebp+8]
    EF6E7B0B    movzx       eax,byte ptr [edx+10h]
    EF6E7B0F    cmp         eax,6
    EF6E7B12    jl          ndisCheckIfTypeMismatch+180h (ef6e7b40)
    EF6E7B14    push        30B0h
    EF6E7B19    push        offset string L"d:\\bt\\1581\\private\\w"... (ef698c50)
    EF6E7B1E    push        offset string L"Unknown" (ef6910cc)
    EF6E7B23    push        offset string L"%s: DEBUGCHK failed "... (ef691070)
    EF6E7B28    call        NKDbgPrintfW (ef74bc5e)
    EF6E7B2D    add         esp,10h
    EF6E7B30    int         3

    It breaks at the last line included.

    I validated my registry values, they are valid:

    BusNumber = 0
    BusType = 0
    RebindOnResume = 0
    *IfType = 0x1c // IF_TYPE_SLIP
    *MediaType = 0
    *PhysicalMediaType = 0
    DisablePowerManagement = 1

    I validated the content of the the general attributes structure:

            // Setting generic attributes
            generalAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
            generalAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
            generalAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
            generalAttributes.MediaType = NdisMedium802_3;
    ...
            generalAttributes.PhysicalMediumType = NdisPhysicalMediumUnspecified;
    ...
            generalAttributes.IfType = IF_TYPE_SLIP;
    ...

    Any idea of what can cause this error?

    I'm having a really hard time to get this driver working...

    Thanks.


    Wednesday, November 20, 2013 6:47 PM

Answers

  • Found it... and it took a while!

    I had this:

            // Port name
            memset(pAdapter->portName, 0, sizeof(pAdapter->portName));
            _tcsncpy(pAdapter->portName, _T("COM1:"), sizeof(pAdapter->portName) - 1);
            pAdapter->portName[sizeof(pAdapter->portName) - 1] = 0;

    instead of:

            // Port name
            memset(pAdapter->portName, 0, sizeof(pAdapter->portName));
            _tcscpy(pAdapter->portName, _T("COM1:"));
    

    I'm an idiot :)     Imagine how bad was the memory after the string copy...

    My driver loads just fine now...

    Thanks for your help, it is greatly appreciated!

    David

    • Marked as answer by David Mercier Friday, November 22, 2013 7:21 PM
    Friday, November 22, 2013 7:21 PM

All replies

  • Hi,

    I understand from your previous posts that you are trying to accomplish something related to NDIS on COM.

    The call stack seem to specify some issue with interface types used. ndisCheckIfTypeMismatch is where the call stack points.

    Also, debug logs show it is trying to read something from registry (NdisReadConfiguration).

    Can you change your interface types for time being to IF_TYPE_OTHER.

    I feel changing this in general attributes and registry should resolve your issues.

    Good Luck.

    Regards,

    Balaji.

    • Marked as answer by David Mercier Thursday, November 21, 2013 2:16 PM
    • Unmarked as answer by David Mercier Thursday, November 21, 2013 2:22 PM
    Thursday, November 21, 2013 5:36 AM
  • I remember trying that earlier but it was before I got the Initialize function to be called...

    Now that it is being called, I failed to try that again... and now it works because you took the time to help !

    Thank you for your help. It sometimes helps a lot to share our little problems to others! :)

    \> ipconfig /all
    Windows IP configuration

    IP connection: IPv4 Address ...... : 0.0.0.0 Subnet Mask ....... : 0.0.0.0 Default Gateway ... : 0.0.0.0 Adapter Name ...... : DAVEDRIVER1 Description ....... : DAVEDRIVER1 Adapter Index ..... : 6 Physical Address... : 20-44-41-56-44-ff DHCP Enabled....... : NO Primary WinsServer : 0.0.0.0 Secondary WinsServer:

    The driver is doing nothing, but at least it starts and registers the adapter, which is a good starting point.

    Thanks again

    David

    Thursday, November 21, 2013 2:09 PM
  • Actually, I restarted the device without modifying the code and I still have the same debugchk...

    Unknown: DEBUGCHK failed in file d:\bt\1581\private\winceos\net\ndis\sys\miniport.c at line 12464

    When I step in the code, I can see that registry values are OK (IfType == 1) and general attributes too. 

    Any idea on why it worked once and not again? I feel there is someting strange happening in my OS/registry... 

    David

    Thursday, November 21, 2013 2:25 PM
  • Hi,

    Are you by any chance using an OS design with hive registry. This is the only thing that comes to my mind when you say it worked once but not on a restart. If hive is being used maybe while debugging you can use RAM based registry or recheck that the entries are taking proper effects and not reverting back to old values.

    Regards,

    Balaji.

    Thursday, November 21, 2013 2:56 PM
  • Yes, I am using a hive registry but it is not persisted.

    I'm going to try it anyway. I'll get back to you with the result of the RAM registry.

    Thanks for the suggestion, it is appreciated!

    David

    Thursday, November 21, 2013 3:37 PM
  • Same behavior with RAM registry... Any other suggestion?

    Thanks

    Thursday, November 21, 2013 4:26 PM
  • Ok I have some new stuff...

    It appears that when I step in the dissassembly, I can follow the values of the pointers and structures and there is no problem. The problem appears when I let the code run without any breakpoint and code stepping. It seems to be a timing problem.

    So here is the code. Please let me know if you have any idea.

    If you look at the dissassembly included in the previous posts, the failing line is the one at EF6E7B00

    cpp file

    // DaveDriver.cpp : Defines the entry point for the DLL application.
    //
    
    #include <Windows.h>
    #include <ndis.h>
    #include <ndiswan.h>
    #include <pegdser.h>
    #include <wdm.h>
    #include "DaveDriver.h"
    
    NTSTATUS DriverEntry (PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath);
    
    #pragma NDIS_INIT_FUNCTION(DriverEntry)
    
    #ifdef DEBUG
    DBGPARAM dpCurSettings = {
        TEXT("DaveDriver"), {
            TEXT("Init"),     TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),
                TEXT("Undefined"),TEXT("Send"),        TEXT("Undefined"),TEXT("Undefined"),
                TEXT("Undefined"),TEXT("Recv"),     TEXT("Interface"),TEXT("Misc"),
                TEXT("Alloc"),    TEXT("Function"), TEXT("Warning"),  TEXT("Error") },
                0x0000C000
    };
    #endif // DEBUG
    
    PDRIVER_OBJECT g_pDriverObject;
    NDIS_HANDLE    g_hDriver;
    NDIS_HANDLE    g_hMiniportDriverContext = NULL;
    PDAVEDRIVER_CONTEXT g_pDriverContext;
    DWORD               g_globalAdapterCount;
    
    NDIS_OID NICSupportedOids[57] =
    {
        OID_GEN_SUPPORTED_LIST,
        OID_GEN_HARDWARE_STATUS,
        OID_GEN_MEDIA_SUPPORTED,
        OID_GEN_MEDIA_IN_USE,
        OID_GEN_MAXIMUM_LOOKAHEAD,
        OID_GEN_MAXIMUM_FRAME_SIZE,
        OID_GEN_LINK_SPEED,
        OID_GEN_TRANSMIT_BUFFER_SPACE,
        OID_GEN_RECEIVE_BUFFER_SPACE,
        OID_GEN_TRANSMIT_BLOCK_SIZE,
        OID_GEN_RECEIVE_BLOCK_SIZE,
        OID_GEN_VENDOR_ID,
        OID_GEN_VENDOR_DESCRIPTION,
        OID_GEN_VENDOR_DRIVER_VERSION,
        OID_GEN_CURRENT_PACKET_FILTER,
        OID_GEN_CURRENT_LOOKAHEAD,
        OID_GEN_DRIVER_VERSION,
        OID_GEN_MAXIMUM_TOTAL_SIZE,
        OID_GEN_MAC_OPTIONS,
        OID_GEN_MEDIA_CONNECT_STATUS,
        OID_GEN_MAXIMUM_SEND_PACKETS,
        OID_GEN_SUPPORTED_GUIDS,
        OID_GEN_XMIT_OK,
        OID_GEN_RCV_OK,
        OID_GEN_XMIT_ERROR,
        OID_GEN_RCV_ERROR,
        OID_GEN_RCV_NO_BUFFER,
        OID_GEN_STATISTICS,
        OID_GEN_RCV_CRC_ERROR,
        OID_GEN_TRANSMIT_QUEUE_LENGTH,
        OID_GEN_PHYSICAL_MEDIUM,
        OID_GEN_DIRECTED_BYTES_XMIT,
        OID_GEN_DIRECTED_FRAMES_XMIT,
        OID_GEN_MULTICAST_BYTES_XMIT,
        OID_GEN_MULTICAST_FRAMES_XMIT,
        OID_GEN_BROADCAST_BYTES_XMIT,
        OID_GEN_BROADCAST_FRAMES_XMIT,
        OID_GEN_DIRECTED_BYTES_RCV,
        OID_GEN_DIRECTED_FRAMES_RCV,
        OID_GEN_MULTICAST_BYTES_RCV,
        OID_GEN_MULTICAST_FRAMES_RCV,
        OID_GEN_BROADCAST_BYTES_RCV,
        OID_GEN_BROADCAST_FRAMES_RCV,
        OID_802_3_PERMANENT_ADDRESS,
        OID_802_3_CURRENT_ADDRESS,
        OID_802_3_MULTICAST_LIST,
        OID_802_3_MAXIMUM_LIST_SIZE,
        OID_802_3_RCV_ERROR_ALIGNMENT,
        OID_802_3_XMIT_ONE_COLLISION,
        OID_802_3_XMIT_MORE_COLLISIONS,
        OID_802_3_XMIT_DEFERRED,
        OID_802_3_XMIT_MAX_COLLISIONS,
        OID_802_3_RCV_OVERRUN,
        OID_802_3_XMIT_UNDERRUN,
        OID_802_3_XMIT_HEARTBEAT_FAILURE,
        OID_802_3_XMIT_TIMES_CRS_LOST,
        OID_802_3_XMIT_LATE_COLLISIONS,
        //
        // TBD: Supporting this OID is mandatory for NDIS 6.0 miniports
        // OID_GEN_LINK_PARAMETERS,
        // 
    };
    
    void* DDAllocateMemory(NDIS_HANDLE hNdis, UINT nBytes)
    {
        void *pMem;
        pMem = NdisAllocateMemoryWithTagPriority(hNdis, nBytes, 'maDN', NormalPoolPriority);
        if(pMem == NULL)
        {
            DEBUGMSG (ZONE_ERROR, (TEXT("+DAVED: AllocMem %d bytes failed\n")));
        }
        else
        {
            memset(pMem, 0, nBytes);
        }
        return pMem;
    }
    
    void DDFreeMemory(void *pMem, UINT nBytes)
    {
        NdisFreeMemory(pMem, nBytes, 0);
    }
    
    
    BOOL APIENTRY DllEntry( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
    {
        switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
            DEBUGREGISTER(hModule);
            DisableThreadLibraryCalls ((HMODULE)hModule);
            DEBUGMSG(ZONE_INIT, (TEXT("DAVED: DLL_PROCESS_ATTACH\n")));
            RETAILMSG(1, (TEXT("DAVED: DLL_PROCESS_ATTACH\n")));
            break;
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
        }
        return TRUE;
    }
    
    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));
    
        g_pDriverObject = DriverObject;
        g_pDriverContext = (PDAVEDRIVER_CONTEXT)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 = 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 = NULL; //MpCheckForHangEx;
        mpCharacteristics.ResetHandlerEx = MpResetEx;
        mpCharacteristics.DevicePnPEventNotifyHandler = MpDevicePnPEventNotify;
        mpCharacteristics.ShutdownHandlerEx = MpShutdownEx;
        mpCharacteristics.CancelOidRequestHandler = MpCancelOidRequest;
    
        initStatus = NdisMRegisterMiniportDriver(DriverObject, RegistryPath, g_hMiniportDriverContext, &mpCharacteristics, &g_hDriver);
        RETAILMSG(1, (TEXT("DAVED: DriverEntry: MiniportHandle = 0x%08x\r\n"), g_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(g_hDriver);
            return NDIS_STATUS_FAILURE;
        }
    
        g_pDriverContext = (PDAVEDRIVER_CONTEXT)DDAllocateMemory(g_hDriver, sizeof(DAVEDRIVER_CONTEXT));
        g_globalAdapterCount = 0;
    
        RETAILMSG(1, (TEXT("-DAVED: DriverEntry: Returning STATUS_SUCCESS\r\n"), DriverObject, RegistryPath));
        return NDIS_STATUS_SUCCESS;
    }
    
    NDIS_STATUS MpSetOptions(NDIS_HANDLE NdisDriverHandle, NDIS_HANDLE DriverContext)
    {
        return NDIS_STATUS_SUCCESS;
    }
    
    NDIS_STATUS MpInitialize(NDIS_HANDLE MiniportAdapterHandle, NDIS_HANDLE MiniportDriverContext, PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters)
    {
        NDIS_STATUS status = NDIS_STATUS_SUCCESS;
        PDAVEDRIVER_ADAPTER pAdapter = NULL;
    
        NDIS_HANDLE hRegistryConfiguration;
        NDIS_CONFIGURATION_OBJECT configObject;
        PNDIS_CONFIGURATION_PARAMETER   returnedValue;
        NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES registrationAttributes;
        NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES generalAttributes;
        NDIS_STRING                     maxFrameSizeStr = NDIS_STRING_CONST("MaxFrameSize");
        NDIS_STRING                     maxSendFrameSizeStr = NDIS_STRING_CONST("MaxSendFrameSize");
        NDIS_STRING                     maxRecvFrameSizeStr = NDIS_STRING_CONST("MaxRecvFrameSize");
        NDIS_STRING                     maxTxPacketsStr = NDIS_STRING_CONST("MaxTxPackets");
        NDIS_STRING                     recvBufSizeStr = NDIS_STRING_CONST("ReceiveBufferSize");
        NDIS_STRING                     recvThreadPrioStr = NDIS_STRING_CONST("ReceiveThreadPriority256");
        NDIS_STRING                     sendThreadPrioStr = NDIS_STRING_CONST("TransmitThreadPriority256");
        NDIS_STRING                     driverNameStr = NDIS_STRING_CONST("Port");
        NDIS_STRING                     speedStr = NDIS_STRING_CONST("Speed");
        NDIS_STRING                     typeStr = NDIS_STRING_CONST("Interface485");
        NDIS_STRING                     ifTypeStr = NDIS_STRING_CONST("*IfType");
        NDIS_STRING                     mediaTypeStr = NDIS_STRING_CONST("*MediaType");
        NDIS_STRING                     physicalMediaTypeStr = NDIS_STRING_CONST("*PhysicalMediaType");
        UCHAR                           macAddress[6] = {' ','D','A','V','D',0xFF};
        DWORD ifType = 0;
    
        RETAILMSG(1, (TEXT("+DAVED: MpInitialize\r\n")));
    
        do 
        {
            //
            // We only support a single instance of DaveDriver
            //
            if(g_globalAdapterCount != 0)
            {
                RETAILMSG(1, (TEXT("DAVED: Can't instantiate more than 1 adapter.\r\n")));
                status = NDIS_STATUS_FAILURE;
                break;
            }
    
            //
            // Let's allocate a DaveDriver adapter structure.
            //
            pAdapter = DDAllocateMemory(g_hDriver, sizeof(DAVEDRIVER_ADAPTER));
            //pAdapter = malloc(sizeof(DAVEDRIVER_ADAPTER));
            //memset(pAdapter, 0, sizeof(DAVEDRIVER_ADAPTER));
            if (pAdapter == NULL)
            {
                status = NDIS_STATUS_RESOURCES;
                break;
            }
            pAdapter->hMiniportAdapter = MiniportAdapterHandle;
    
            NdisZeroMemory(&registrationAttributes, sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES));
            NdisZeroMemory(&generalAttributes, sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES));
    
            // Setting registration attributes
            registrationAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;
            registrationAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
            registrationAttributes.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES);
            registrationAttributes.MiniportAdapterContext = (NDIS_HANDLE)pAdapter;
            registrationAttributes.AttributeFlags = NDIS_MINIPORT_ATTRIBUTES_NDIS_WDM;
            registrationAttributes.CheckForHangTimeInSeconds = 0;
            registrationAttributes.InterfaceType = NdisInterfaceInternal;
    
            status = NdisMSetMiniportAttributes(MiniportAdapterHandle, (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&registrationAttributes);
            if(status != NDIS_STATUS_SUCCESS)
            {
                RETAILMSG(1, (TEXT("DAVED: Can't set adapter attributes.\r\n")));
                break;
            }
    
            // Setting generic attributes
            generalAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
            generalAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
            generalAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
            generalAttributes.MediaType = NdisMedium802_3;
            generalAttributes.MtuSize = NIC_MAX_PACKET_SIZE - NIC_HEADER_SIZE;
            generalAttributes.MaxXmitLinkSpeed = NIC_MEDIA_MAX_SPEED;
            generalAttributes.MaxRcvLinkSpeed = NIC_MEDIA_MAX_SPEED;
            generalAttributes.XmitLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;
            generalAttributes.RcvLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;
            generalAttributes.MediaConnectState = MediaConnectStateUnknown;
            generalAttributes.MediaDuplexState = MediaDuplexStateUnknown;
            generalAttributes.LookaheadSize = NIC_MAX_PACKET_SIZE - NIC_HEADER_SIZE;
            generalAttributes.PowerManagementCapabilities = NULL;
            generalAttributes.MacOptions = NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
                                           NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
                                           NDIS_MAC_OPTION_NO_LOOPBACK;
            generalAttributes.SupportedPacketFilters = NDIS_PACKET_TYPE_DIRECTED;
            generalAttributes.MaxMulticastListSize = NIC_MAX_MCAST_LIST;
            generalAttributes.MacAddressLength = ETH_LENGTH_OF_ADDRESS;
            NdisMoveMemory(generalAttributes.PermanentMacAddress, macAddress, ETH_LENGTH_OF_ADDRESS);
            NdisMoveMemory(generalAttributes.CurrentMacAddress, macAddress, ETH_LENGTH_OF_ADDRESS);
            generalAttributes.PhysicalMediumType = NdisPhysicalMediumUnspecified;
            generalAttributes.RecvScaleCapabilities = NULL;
            generalAttributes.AccessType = NET_IF_ACCESS_BROADCAST; // TODO DM: verify this one for p2p maybe...
            generalAttributes.DirectionType = NET_IF_DIRECTION_SENDRECEIVE;
            generalAttributes.ConnectionType = NET_IF_CONNECTION_DEDICATED;
            generalAttributes.IfType = IF_TYPE_OTHER; // TODO DM: VERIFY this one for IF_TYPE_PROP_POINT2POINT_SERIAL
            generalAttributes.IfConnectorPresent = FALSE;
            
            // TODO DM: Doc says as an NDIS 6.0, we should support all statistics... which is not the case here... to be validated
            generalAttributes.SupportedStatistics = NDIS_STATISTICS_XMIT_OK_SUPPORTED |
                                                    NDIS_STATISTICS_RCV_OK_SUPPORTED |
                                                    NDIS_STATISTICS_XMIT_ERROR_SUPPORTED |
                                                    NDIS_STATISTICS_RCV_ERROR_SUPPORTED |
                                                    NDIS_STATISTICS_RCV_CRC_ERROR_SUPPORTED |
                                                    NDIS_STATISTICS_RCV_NO_BUFFER_SUPPORTED |
                                                    NDIS_STATISTICS_TRANSMIT_QUEUE_LENGTH_SUPPORTED |
                                                    NDIS_STATISTICS_GEN_STATISTICS_SUPPORTED;
            generalAttributes.SupportedOidList = NICSupportedOids;
            generalAttributes.SupportedOidListLength = sizeof(NICSupportedOids);
            
            RETAILMSG(1, (TEXT("DAVED: IfType is %u.\r\n"), generalAttributes.IfType));
            RETAILMSG(1, (TEXT("DAVED: MediaType is %u.\r\n"), generalAttributes.MediaType));
            RETAILMSG(1, (TEXT("DAVED: PhysicalMediumType is %u.\r\n"), generalAttributes.PhysicalMediumType));
    
            status = NdisMSetMiniportAttributes(MiniportAdapterHandle,
                (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&generalAttributes);
    
            if(status != NDIS_STATUS_SUCCESS)
            {
                RETAILMSG(1, (TEXT("DAVED: Can't set general attributes.\r\n")));
                break;
            }
    
            // Initialize the configuration object with the adapter handle:
            configObject.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT;
            configObject.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1;
            configObject.Header.Size = sizeof(NDIS_CONFIGURATION_OBJECT);
            configObject.NdisHandle = MiniportAdapterHandle;
            configObject.Flags = 0;
    
            // Get the configuration handle:
            status = NdisOpenConfigurationEx(&configObject, &hRegistryConfiguration);
            if (status != NDIS_STATUS_SUCCESS)
            {
                DDFreeMemory(pAdapter, sizeof(DAVEDRIVER_ADAPTER));
                RETAILMSG(1, (TEXT("DAVED:Initialize: NdisOpenConfigurationEx failed 0x%x\r\n"), status));
                break;
            }
    
            // RecvThreadPrio
            //pAdapter->dwRecvThreadPrio = DEFAULT_RX_THREAD_PRIORITY;
            //NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration, &recvThreadPrioStr, NdisParameterInteger);
            //if (status == NDIS_STATUS_SUCCESS)
            //    pAdapter->dwRecvThreadPrio = returnedValue->ParameterData.IntegerData;
            //RETAILMSG(1,(TEXT("DAVED: RecvThreadPrio=%d\r\n"), pAdapter->dwRecvThreadPrio));
    
            //// SendThreadPrio
            //pAdapter->dwSendThreadPrio = DEFAULT_TX_THREAD_PRIORITY;
            //NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration, &sendThreadPrioStr, NdisParameterInteger);
            //if (status == NDIS_STATUS_SUCCESS)
            //    pAdapter->dwSendThreadPrio = returnedValue->ParameterData.IntegerData;
            //RETAILMSG(1,(TEXT("DAVED: SendThreadPrio=%d\r\n"), pAdapter->dwSendThreadPrio));
    
            // Port name
            memset(pAdapter->portName, 0, sizeof(pAdapter->portName));
            _tcsncpy(pAdapter->portName, _T("COM1:"), sizeof(pAdapter->portName) - 1);
            pAdapter->portName[sizeof(pAdapter->portName) - 1] = 0;
            //NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration,  &driverNameStr, NdisParameterString);
            //if (status == NDIS_STATUS_SUCCESS)
            //{
            //    memset(pAdapter->portName, 0, sizeof(pAdapter->portName));
            //    _tcsncpy(pAdapter->portName, returnedValue->ParameterData.StringData.Buffer, sizeof(pAdapter->portName) - 1);
            //    pAdapter->portName[sizeof(pAdapter->portName) - 1] = 0;
            //    RETAILMSG(1, (TEXT("DAVED: Serial Port is: \"%s\"\r\n"), pAdapter->portName));
            //}
            //else
            //{
            //    RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Port\".\r\n")));
            //    break;
            //}
    
            //pAdapter->dwBaudRate = DEFAULT_BAUDRATE;
            //NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration,  &speedStr, NdisParameterInteger);
            //if (status == NDIS_STATUS_SUCCESS)
            //{
            //    pAdapter->dwBaudRate = returnedValue->ParameterData.IntegerData;
            //    RETAILMSG(1, (TEXT("DAVED: Serial speed is %d.\r\n"), pAdapter->dwBaudRate));
            //}
            //else
            //{
            //    RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Speed\".\r\n")));
            //    break;
            //}
    
            //NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration,  &typeStr, NdisParameterInteger);
            //if (status == NDIS_STATUS_SUCCESS)
            //{
            //    if(returnedValue->ParameterData.IntegerData)
            //    {
            //        pAdapter->dwType = 1;//SCC_INTERFACE_RS485;
            //        RETAILMSG(1, (TEXT("DAVED:  Interface type is 485.\r\n")));
            //    }
            //    else
            //    {
            //        pAdapter->dwType = 0;//SCC_INTERFACE_RS232;
            //        RETAILMSG(1, (TEXT("DAVED:  Interface type is 232.\r\n")));
            //    }
            //    // TODO dm
            //    pAdapter->dwType = 0;//SCC_INTERFACE_RS232;
            //    RETAILMSG(1, (TEXT("DAVED:  Interface type is 232.\r\n")));
            //}
            //else
            //{
            //    // TODO DM: Remettre la valeur 485 dans le registr.
            //    RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Interface485\".\r\n")));
            //    RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Interface485\".\r\n")));
            //    RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Interface485\".\r\n")));
            //    RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Interface485\".\r\n")));
            //    RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Interface485\".\r\n")));
            //    RETAILMSG(1, (TEXT("DAVED: Forcing value to 232.\r\n")));
            //    // TODO dm
            //    pAdapter->dwType = 0;//SCC_INTERFACE_RS232;
            //    status = NDIS_STATUS_SUCCESS;
            //    //RETAILMSG(1, (TEXT("DAVED: Missing registry key \"Interface485\".\r\n")));
            //    //break;
            //}
    
            // *IfTyppe
            NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration, &ifTypeStr, NdisParameterInteger);
            if (status == NDIS_STATUS_SUCCESS)
            {
                RETAILMSG(1,(TEXT("DAVED: *IfType=%d\r\n"), returnedValue->ParameterData.IntegerData));
                ASSERT(generalAttributes.IfType == returnedValue->ParameterData.IntegerData);
            }
            else
                RETAILMSG(1,(TEXT("DAVED: FAILURE *IfType=%d\r\n"), returnedValue->ParameterData.IntegerData));
    
            // *MediaType
            NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration, &mediaTypeStr, NdisParameterInteger);
            if (status == NDIS_STATUS_SUCCESS)
            {
                RETAILMSG(1,(TEXT("DAVED: *MediaType=%d\r\n"), returnedValue->ParameterData.IntegerData));
                ASSERT(generalAttributes.MediaType == returnedValue->ParameterData.IntegerData);
            }
            else
                RETAILMSG(1,(TEXT("DAVED: FAILURE *MediaType=%d\r\n"), returnedValue->ParameterData.IntegerData));
    
            // *PhysicalMediaType
            NdisReadConfiguration(&status, &returnedValue, hRegistryConfiguration, &physicalMediaTypeStr, NdisParameterInteger);
            if (status == NDIS_STATUS_SUCCESS)
            {
                RETAILMSG(1,(TEXT("DAVED: *PhysicalMediaType=%d\r\n"), returnedValue->ParameterData.IntegerData));
                ASSERT(generalAttributes.PhysicalMediumType == returnedValue->ParameterData.IntegerData);
            }
            else
                RETAILMSG(1,(TEXT("DAVED: FAILURE *PhysicalMediaType=%d\r\n"), returnedValue->ParameterData.IntegerData));
    
            // Just close the config handle
            NdisCloseConfiguration (hRegistryConfiguration);
        } while(FALSE);
    
        return status;
    }
    
    void MpHalt(NDIS_HANDLE MiniportAdapterContext, NDIS_HALT_ACTION HaltAction)
    {
    }
    
    void MpDriverUnload(PDRIVER_OBJECT DriverObject)
    {
        RETAILMSG(1, (TEXT("+DAVED: MpDriverUnload: Unloading the driver with driver object 0x%08x.\r\n"), *DriverObject));
        DDFreeMemory(g_pDriverContext, sizeof(DAVEDRIVER_CONTEXT));
        NdisMDeregisterMiniportDriver(g_hDriver);
        RETAILMSG(1, (TEXT("-DAVED: MpDriverUnload.\r\n")));
    }
    
    NDIS_STATUS MpPause(NDIS_HANDLE MiniportAdapterContext, PNDIS_MINIPORT_PAUSE_PARAMETERS MiniportPauseParameters)
    {
        return NDIS_STATUS_SUCCESS;
    }
    
    NDIS_STATUS MpRestart(NDIS_HANDLE MiniportAdapterContext, PNDIS_MINIPORT_RESTART_PARAMETERS MiniportRestartParameters)
    {
        return NDIS_STATUS_SUCCESS;
    }
    
    NDIS_STATUS MpOidRequest(NDIS_HANDLE MiniportAdapterContext, PNDIS_OID_REQUEST OidRequest)
    {
        RETAILMSG(1, (TEXT("+DAVED: MpOidRequest with OID 0x%08x.\r\n"), OidRequest->RequestType));
    
        switch(OidRequest->RequestType)
        {
        case OID_GEN_PHYSICAL_MEDIUM :
            break;
        default:
            break;
        }
    
        RETAILMSG(1, (TEXT("-DAVED: MpOidRequest.\r\n")));
        return NDIS_STATUS_SUCCESS;
    }
    
    void MpSendNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUFFER_LIST NetBufferList, NDIS_PORT_NUMBER PortNumber, ULONG SendFlags)
    {
    }
    
    void MpReturnNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUFFER_LIST NetBufferLists, ULONG ReturnFlags)
    {
    }
    
    void MpCancelSend(NDIS_HANDLE MiniportAdapterContext, PVOID CancelId)
    {
    }
    
    BOOLEAN MpCheckForHangEx(NDIS_HANDLE MiniportAdapterContext)
    {
        return TRUE;
    }
    
    NDIS_STATUS MpResetEx(NDIS_HANDLE MiniportAdapterContext, PBOOLEAN AddressingReset)
    {
        return NDIS_STATUS_SUCCESS;
    }
    
    void MpDevicePnPEventNotify(NDIS_HANDLE MiniportAdapterContext, PNET_DEVICE_PNP_EVENT NetDevicePnPEvent)
    {
        RETAILMSG(1, (TEXT("+DAVED: MpDevicePnPEventNotify.\r\n")));
    }
    
    void MpShutdownEx(NDIS_HANDLE MiniportAdapterContext, NDIS_SHUTDOWN_ACTION ShutdownAction)
    {
    }
    
    void MpCancelOidRequest(NDIS_HANDLE MiniportAdapterContext, PVOID RequestId)
    {
    }


    h file

    #include <ndis.h>
    
    // ----------------------------------------------------------------
    //
    // Debug Defines
    //
    // ----------------------------------------------------------------
    #ifdef DEBUG
    #define ZONE_INIT      DEBUGZONE(0)        // 0x0001
    //#define ZONE_???     DEBUGZONE(1)        // 0x0002
    //#define ZONE_???     DEBUGZONE(2)        // 0x0004
    //#define ZONE_???     DEBUGZONE(3)        // 0x0008
    //#define ZONE_???     DEBUGZONE(4)        // 0x0010
    #define ZONE_SEND      DEBUGZONE(5)        // 0x0020
    //#define ZONE_???     DEBUGZONE(6)        // 0x0040
    #define ZONE_NDIS      DEBUGZONE(7)        // 0x0080
    #define ZONE_TAPI      DEBUGZONE(8)        // 0x0100
    #define ZONE_RECV      DEBUGZONE(9)        // 0x0200
    #define ZONE_INTERFACE DEBUGZONE(10)        // 0x0400
    #define ZONE_MISC      DEBUGZONE(11)        // 0x0800
    #define ZONE_ALLOC     DEBUGZONE(12)        // 0x1000
    #define ZONE_FUNCTION  DEBUGZONE(13)        // 0x2000
    #define ZONE_WARN      DEBUGZONE(14)        // 0x4000
    #define ZONE_ERROR     DEBUGZONE(15)        // 0x8000
    #endif
    
    //
    //    The bigger this value is, the fewer the number of calls to ReadFile
    //    to receive bytes.
    //
    //    This value may be overridden with the registry setting:
    //        HKLM\Comm\AsyncMac1\Parms\ReceiveBufferSize
    //
    #define DEFAULT_RX_BUF_SIZE    2000
    
    //
    //    Maximum number of simultaneous pending transmits to allow.
    //
    //    This value may be overridden with the registry setting:
    //        HKLM\Comm\AsyncMac1\Parms\MaxTxPackets
    //
    #define MAX_TRANSMIT    16
    #define DEFAULT_BAUDRATE    115200
    #define ROUND_UP_TO_MULTIPLE_OF_N(value, N)    ((value + N - 1) & ~(N - 1))
    
    //
    //    Default send/receive thread priority.
    //
    //    This value may be overridden with the registry setting:
    //        HKLM\Comm\AsyncMac1\Parms\ReceiveThreadPriority256
    //        HKLM\Comm\AsyncMac1\Parms\TransmitThreadPriority256
    //
    //
    #define DEFAULT_RX_THREAD_PRIORITY  130
    #define DEFAULT_TX_THREAD_PRIORITY  130
    #define MAX_FRAME_SIZE              1502
    #define FRAME_PADDING               256
    #define DEFAULT_DESIRED_ACCM        0
    
    #define NIC_MAX_PACKET_SIZE             1514
    #define NIC_MIN_PACKET_SIZE             60
    #define NIC_HEADER_SIZE                 14
    #define NIC_MEDIA_MAX_SPEED             1000000 // maximum link speed for send dna recv in bps
    #define NIC_MAX_MCAST_LIST              32
    
    
    typedef struct _DAVEDRIVER_ADAPTER_ *PDAVEDRIVER_ADAPTER;
    typedef struct _DAVEDRIVER_CONTEXT_ *PDAVEDRIVER_CONTEXT;
    
    typedef struct _DAVEDRIVER_CONTEXT_
    {
        DWORD               dwflag;
        NDIS_HANDLE         hMiniportHandle;
    } DAVEDRIVER_CONTEXT, *PDAVEDRIVER_CONTEXT;
    
    typedef struct _DAVEDRIVER_ADAPTER_
    {
        NDIS_HANDLE         hMiniportAdapter;
        NDIS_HANDLE         hNdisLinkContext;
        DWORD               dwMaxSendFrameSize;
        DWORD               dwMaxRecvFrameSize;
        DWORD               dwRecvBufSize;        // Size of buffer passed to ReadFile
        DWORD               dwRecvThreadPrio;    // Priority of RxThread
        DWORD               dwSendThreadPrio;    // Priority of RxThread
        NDIS_SPIN_LOCK      lock;
        TCHAR               portName[_MAX_PATH];
        HANDLE              hPort;        // The serial port handle
        DWORD               dwType;     // The serial mode (232, 485)
        DWORD               dwBaudRate;    // The link baud rate (in 100's b/s)
        DWORD               dwFlags;    // Some state flags
    #define AOL_FLAGS_RUN_RXTHREAD    0x00000001
    #define AOL_FLAGS_RUN_TXTHREAD    0x00000002
        HANDLE                  hRxThrd;    // Recv Thread handle
        HANDLE                  hTxThrd;    // Send Thread handle
        LIST_ENTRY              txPacketList;
        NDIS_EVENT              txPacketEvent;
        UCHAR                   permanentAddress[ETH_LENGTH_OF_ADDRESS];
        UCHAR                   currentAddress[ETH_LENGTH_OF_ADDRESS];
    } DAVEDRIVER_ADAPTER, *PDAVEDRIVER_ADAPTER;
    
    extern NDIS_OID NICSupportedOids[57];
    
    NDIS_STATUS MpSetOptions(NDIS_HANDLE NdisDriverHandle, NDIS_HANDLE DriverContext);
    NDIS_STATUS MpInitialize(NDIS_HANDLE MiniportAdapterHandle, NDIS_HANDLE MiniportDriverContext, PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters);
    void MpHalt(NDIS_HANDLE MiniportAdapterContext, NDIS_HALT_ACTION HaltAction);
    void MpDriverUnload(PDRIVER_OBJECT DriverObject);
    NDIS_STATUS MpPause(NDIS_HANDLE MiniportAdapterContext, PNDIS_MINIPORT_PAUSE_PARAMETERS MiniportPauseParameters);
    NDIS_STATUS MpRestart(NDIS_HANDLE MiniportAdapterContext, PNDIS_MINIPORT_RESTART_PARAMETERS MiniportRestartParameters);
    NDIS_STATUS MpOidRequest(NDIS_HANDLE MiniportAdapterContext, PNDIS_OID_REQUEST OidRequest);
    void MpSendNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUFFER_LIST NetBufferList, NDIS_PORT_NUMBER PortNumber, ULONG SendFlags);
    void MpReturnNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUFFER_LIST NetBufferLists, ULONG ReturnFlags);
    void MpCancelSend(NDIS_HANDLE MiniportAdapterContext, PVOID CancelId);
    BOOLEAN MpCheckForHangEx(NDIS_HANDLE MiniportAdapterContext);
    NDIS_STATUS MpResetEx(NDIS_HANDLE MiniportAdapterContext, PBOOLEAN AddressingReset);
    void MpDevicePnPEventNotify(NDIS_HANDLE MiniportAdapterContext, PNET_DEVICE_PNP_EVENT NetDevicePnPEvent);
    void MpShutdownEx(NDIS_HANDLE MiniportAdapterContext, NDIS_SHUTDOWN_ACTION ShutdownAction);
    void MpCancelOidRequest(NDIS_HANDLE MiniportAdapterContext, PVOID RequestId);

    Thanks

    David


    Friday, November 22, 2013 4:24 PM
  • Hi,

    I just went through MpInitialize alone. Can i know why you are trying to read IfType, Mediatype and PhysicalmediaType entries.  If my understanding is correct , you are trying to check the registry entries against what you provide in general attributes. 

    if so , then is the NdisReadConfiguration entry shown on the debug port part of your driver call. If that's the case i am not entirely sure how to read these standardized keywords (Refer:http://msdn.microsoft.com/en-us/library/windows/hardware/hh205409(v=vs.85).aspx)

    Can you just comment out all ReadConfig portions(for iftype, physicalmediatype, mediatype) except for ones you are sure about and give it a try.

    I am saying this because i haven't seen code that tries to read IfType or PhysicalMediaType entries. Maybe you can exclude the * in *IfType. This is a wild guess. Maybe it works out.

    Regards,

    Balaji.


    • Edited by balajitrv1 Friday, November 22, 2013 4:58 PM
    Friday, November 22, 2013 4:49 PM
  • Found it... and it took a while!

    I had this:

            // Port name
            memset(pAdapter->portName, 0, sizeof(pAdapter->portName));
            _tcsncpy(pAdapter->portName, _T("COM1:"), sizeof(pAdapter->portName) - 1);
            pAdapter->portName[sizeof(pAdapter->portName) - 1] = 0;

    instead of:

            // Port name
            memset(pAdapter->portName, 0, sizeof(pAdapter->portName));
            _tcscpy(pAdapter->portName, _T("COM1:"));
    

    I'm an idiot :)     Imagine how bad was the memory after the string copy...

    My driver loads just fine now...

    Thanks for your help, it is greatly appreciated!

    David

    • Marked as answer by David Mercier Friday, November 22, 2013 7:21 PM
    Friday, November 22, 2013 7:21 PM