[ros-diffs] [cgutman] 41521: - Partial rewrite of NdisReadConfiguration - It now determines the parameter type based on the key instead of the ParameterType passed by the caller (documented on MSDN) - It also always sets (*ParameterValue)->ParameterType to NdisParameterInteger when reading an integer or hex integer value (documented on MSDN) - This will fix miniport drivers that supply a bogus ParameterType value because it is ignored by NDIS on NT

cgutman at svn.reactos.org cgutman at svn.reactos.org
Mon Jun 22 02:49:07 CEST 2009


Author: cgutman
Date: Mon Jun 22 04:49:06 2009
New Revision: 41521

URL: http://svn.reactos.org/svn/reactos?rev=41521&view=rev
Log:
 - Partial rewrite of NdisReadConfiguration
 - It now determines the parameter type based on the key instead of the ParameterType passed by the caller (documented on MSDN)
 - It also always sets (*ParameterValue)->ParameterType to NdisParameterInteger when reading an integer or hex integer value (documented on MSDN)
 - This will fix miniport drivers that supply a bogus ParameterType value because it is ignored by NDIS on NT

Modified:
    trunk/reactos/drivers/network/ndis/ndis/config.c

Modified: trunk/reactos/drivers/network/ndis/ndis/config.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/ndis/config.c?rev=41521&r1=41520&r2=41521&view=diff
==============================================================================
--- trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] Mon Jun 22 04:49:06 2009
@@ -323,21 +323,10 @@
     ULONG KeyDataLength;
     PMINIPORT_RESOURCE MiniportResource;
     PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext = (PMINIPORT_CONFIGURATION_CONTEXT)ConfigurationHandle;
+    PVOID Buffer;
 
     *ParameterValue = NULL;
     *Status = NDIS_STATUS_FAILURE;
-
-    if(ParameterType != NdisParameterInteger &&
-        ParameterType != NdisParameterHexInteger &&
-        ParameterType != NdisParameterString &&
-        ParameterType != NdisParameterMultiString &&
-        ParameterType != NdisParameterBinary
-      )
-    {
-        NDIS_DbgPrint(MIN_TRACE,("unsupported parameter type\n"));
-        *Status = NDIS_STATUS_NOT_SUPPORTED;
-        return;
-    }
 
     NDIS_DbgPrint(MAX_TRACE,("requested read of %wZ\n", Keyword));
 
@@ -498,152 +487,105 @@
        return;
     }
 
-    switch(ParameterType)
-    {
-        case NdisParameterInteger:
-        case NdisParameterHexInteger:
+    *ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
+    if (!*ParameterValue)
+    {
+        NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+        ExFreePool(MiniportResource);
+        ExFreePool(KeyInformation);
+        *Status = NDIS_STATUS_RESOURCES;
+        return;
+    }
+
+    RtlZeroMemory(*ParameterValue, sizeof(NDIS_CONFIGURATION_PARAMETER));
+
+    if (KeyInformation->Type == REG_BINARY)
+    {
+        NDIS_DbgPrint(MAX_TRACE, ("NdisParameterBinary\n"));
+
+        (*ParameterValue)->ParameterType = NdisParameterBinary;
+
+        Buffer = ExAllocatePool(NonPagedPool, KeyInformation->DataLength);
+        if (!Buffer)
         {
-            UNICODE_STRING str;
-
-            *ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
-            if(!*ParameterValue)
-            {
-                NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
-                ExFreePool(KeyInformation);
-                *Status = NDIS_STATUS_RESOURCES;
-                return;
-            }
-
-            str.Length = str.MaximumLength = (USHORT)KeyInformation->DataLength;
-            str.Buffer = (PWCHAR)KeyInformation->Data;
-
-            (*ParameterValue)->ParameterType = ParameterType;
-
-            /*
-                 If ParameterType is NdisParameterInteger then the base of str is decimal.
-                 If ParameterType is NdisParameterHexInteger then the base of str is hexadecimal.
-            */
-            if (ParameterType == NdisParameterInteger)
-               *Status = RtlUnicodeStringToInteger(&str, 10, &(*ParameterValue)->ParameterData.IntegerData);
-            else if (ParameterType == NdisParameterHexInteger)
-               *Status = RtlUnicodeStringToInteger(&str, 16, &(*ParameterValue)->ParameterData.IntegerData);
-
-
+            NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+            ExFreePool(MiniportResource);
             ExFreePool(KeyInformation);
-
-            if(*Status != STATUS_SUCCESS) {
-                ExFreePool(*ParameterValue);
-                *ParameterValue = NULL;
-                *Status = NDIS_STATUS_FAILURE;
-                return;
-            }
-
-            MiniportResource->ResourceType = 0;
-            MiniportResource->Resource = *ParameterValue;
-            NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
-            ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
-
-            *Status = NDIS_STATUS_SUCCESS;
-
+            *Status = NDIS_STATUS_RESOURCES;
             return;
         }
 
-        case NdisParameterString:
-        case NdisParameterMultiString:
+        RtlCopyMemory(Buffer, KeyInformation->Data, KeyInformation->DataLength);
+
+        (*ParameterValue)->ParameterData.BinaryData.Buffer = Buffer;
+        (*ParameterValue)->ParameterData.BinaryData.Length = KeyInformation->DataLength;
+    }
+    else if (KeyInformation->Type == REG_MULTI_SZ)
+    {
+        NDIS_DbgPrint(MAX_TRACE, ("NdisParameterMultiString\n"));
+
+        (*ParameterValue)->ParameterType = NdisParameterMultiString;
+
+        Buffer = ExAllocatePool(NonPagedPool, KeyInformation->DataLength);
+        if (!Buffer)
         {
-            PWCHAR RegData = 0;
-
-            if(KeyInformation->Type != REG_SZ && KeyInformation->Type != REG_MULTI_SZ)
-            {
-                NDIS_DbgPrint(MIN_TRACE,("requested type does not match actual value type\n"));
-                ExFreePool(KeyInformation);
-                *ParameterValue = NULL;
-                *Status = NDIS_STATUS_FAILURE;
-                return;
-            }
-
-            *ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
-            if(!*ParameterValue)
-            {
-                NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
-                ExFreePool(KeyInformation);
-                *Status = NDIS_STATUS_RESOURCES;
-                return;
-            }
-
-            RegData = ExAllocatePool(PagedPool, KeyInformation->DataLength);
-            if(!RegData)
-            {
-                NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
-                ExFreePool(KeyInformation);
-                ExFreePool(*ParameterValue);
-                *ParameterValue = NULL;
-                *Status = NDIS_STATUS_FAILURE;
-                return;
-            }
-
-            MiniportResource->ResourceType = 0;
-            MiniportResource->Resource = *ParameterValue;
-            NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
-            ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
-
-            memcpy(RegData, KeyInformation->Data, KeyInformation->DataLength);
-
-            (*ParameterValue)->ParameterType = ParameterType;
-            (*ParameterValue)->ParameterData.StringData.Length = (USHORT)KeyInformation->DataLength;
-            (*ParameterValue)->ParameterData.StringData.Buffer = RegData;
-
+            NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+            ExFreePool(MiniportResource);
             ExFreePool(KeyInformation);
-
-            *Status = NDIS_STATUS_SUCCESS;
-
+            *Status = NDIS_STATUS_RESOURCES;
             return;
         }
 
-        case NdisParameterBinary:
-        {
-            if(KeyInformation->Type != REG_BINARY)
-            {
-                NDIS_DbgPrint(MIN_TRACE,("requested type does not match actual value type\n"));
-                *Status = NDIS_STATUS_FAILURE;
-                ExFreePool(KeyInformation);
-                return;
-            }
-
-            *ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER) + KeyInformation->DataLength);
-            if(!*ParameterValue)
-            {
-                NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
-                ExFreePool(KeyInformation);
-                *Status = NDIS_STATUS_RESOURCES;
-                return;
-            }
-
-            (*ParameterValue)->ParameterData.BinaryData.Buffer = ExAllocatePool(PagedPool, KeyInformation->DataLength);
-            if (!(*ParameterValue)->ParameterData.BinaryData.Buffer)
-            {
-                NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
-                ExFreePool(KeyInformation);
-                *Status = NDIS_STATUS_RESOURCES;
-                return;
-            }
-
-            (*ParameterValue)->ParameterType = ParameterType;
-            (*ParameterValue)->ParameterData.BinaryData.Length = KeyInformation->DataLength;
-            memcpy((*ParameterValue)->ParameterData.BinaryData.Buffer, KeyInformation->Data, KeyInformation->DataLength);
-
-            MiniportResource->ResourceType = 0;
-            MiniportResource->Resource = *ParameterValue;
-            NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
-            ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
-
-            ExFreePool(KeyInformation);
-
-            *Status = NDIS_STATUS_SUCCESS;
-
-            return;
-        }
-    }
+        RtlCopyMemory(Buffer, KeyInformation->Data, KeyInformation->DataLength);
+
+        (*ParameterValue)->ParameterData.StringData.Buffer = Buffer;
+        (*ParameterValue)->ParameterData.StringData.Length = KeyInformation->DataLength;
+    }
+    else
+    {
+         UNICODE_STRING str;
+
+         str.Length = str.MaximumLength = (USHORT)KeyInformation->DataLength;
+         str.Buffer = (PWCHAR)KeyInformation->Data;
+
+         if ((*Status = RtlUnicodeStringToInteger(&str, 0,
+                             &(*ParameterValue)->ParameterData.IntegerData)) == STATUS_SUCCESS)
+         {
+             NDIS_DbgPrint(MAX_TRACE, ("NdisParameterInteger\n"));
+
+             (*ParameterValue)->ParameterType = NdisParameterInteger;
+         }
+         else
+         {
+             NDIS_DbgPrint(MAX_TRACE, ("NdisParameterString\n"));
+
+             (*ParameterValue)->ParameterType = NdisParameterString;
+
+             Buffer = ExAllocatePool(NonPagedPool, KeyInformation->DataLength);
+             if (!Buffer)
+             {
+                 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+                 ExFreePool(MiniportResource);
+                 ExFreePool(KeyInformation);
+                 *Status = NDIS_STATUS_RESOURCES;
+                 return;
+             }
+
+             RtlCopyMemory(Buffer, KeyInformation->Data, KeyInformation->DataLength);
+
+             (*ParameterValue)->ParameterData.StringData.Buffer = Buffer;
+             (*ParameterValue)->ParameterData.StringData.Length = KeyInformation->DataLength;
+         }
+    }
+
+    MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_MEMORY;
+    MiniportResource->Resource = *ParameterValue;
+
+    ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
+
+    ExFreePool(KeyInformation);
+
+    *Status = NDIS_STATUS_SUCCESS;
 }
 
 



More information about the Ros-diffs mailing list