#include "ndissys.h"
-#define NDIS_VERSION 0x00040000 /* the version of NDIS we claim to be to miniport drivers */
#define PARAMETERS_KEY L"Parameters" /* The parameters subkey under the device-specific key */
/*
* I don't know why tho so i free everything before return. comments welcome.
*/
{
- ULONG ParameterType = ParameterValue->ParameterType;
+ ULONG ParameterType;
ULONG DataSize;
PVOID Data;
- WCHAR Buff[25];
+ WCHAR Buff[11];
+
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
/* reset parameter type to standard reg types */
- switch(ParameterType)
+ switch(ParameterValue->ParameterType)
{
case NdisParameterHexInteger:
case NdisParameterInteger:
ParameterType = REG_SZ;
if (!NT_SUCCESS(RtlIntegerToUnicodeString(
ParameterValue->ParameterData.IntegerData,
- (ParameterType == NdisParameterInteger) ? 10 : 16, &Str)))
+ (ParameterValue->ParameterType == NdisParameterInteger) ? 10 : 16, &Str)))
{
+ NDIS_DbgPrint(MIN_TRACE, ("RtlIntegerToUnicodeString failed (%x)\n", *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
break;
case NdisParameterString:
case NdisParameterMultiString:
- ParameterType = REG_SZ;
+ ParameterType = (ParameterValue->ParameterType == NdisParameterString) ? REG_SZ : REG_MULTI_SZ;
Data = ParameterValue->ParameterData.StringData.Buffer;
DataSize = ParameterValue->ParameterData.StringData.Length;
break;
*Status = ZwSetValueKey(((PMINIPORT_CONFIGURATION_CONTEXT)ConfigurationHandle)->Handle,
Keyword, 0, ParameterType, Data, DataSize);
- if(*Status != STATUS_SUCCESS)
+ if(*Status != STATUS_SUCCESS) {
+ NDIS_DbgPrint(MIN_TRACE, ("ZwSetValueKey failed (%x)\n", *Status));
*Status = NDIS_STATUS_FAILURE;
- else
+ } else
*Status = NDIS_STATUS_SUCCESS;
}
{
PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext = (PMINIPORT_CONFIGURATION_CONTEXT)ConfigurationHandle;
PMINIPORT_RESOURCE Resource;
+ PNDIS_CONFIGURATION_PARAMETER ParameterValue;
+ PLIST_ENTRY CurrentEntry;
- while(!IsListEmpty(&ConfigurationContext->ResourceListHead))
+ while((CurrentEntry = ExInterlockedRemoveHeadList(&ConfigurationContext->ResourceListHead,
+ &ConfigurationContext->ResourceLock)) != NULL)
{
- Resource = (PMINIPORT_RESOURCE)ExInterlockedRemoveHeadList(&ConfigurationContext->ResourceListHead, &ConfigurationContext->ResourceLock);
- if(Resource->ResourceType == MINIPORT_RESOURCE_TYPE_MEMORY)
+ Resource = CONTAINING_RECORD(CurrentEntry, MINIPORT_RESOURCE, ListEntry);
+ switch(Resource->ResourceType)
{
+ case MINIPORT_RESOURCE_TYPE_REGISTRY_DATA:
+ ParameterValue = Resource->Resource;
+
+ switch (ParameterValue->ParameterType)
+ {
+ case NdisParameterBinary:
+ ExFreePool(ParameterValue->ParameterData.BinaryData.Buffer);
+ break;
+
+ case NdisParameterString:
+ case NdisParameterMultiString:
+ ExFreePool(ParameterValue->ParameterData.StringData.Buffer);
+ break;
+
+ default:
+ break;
+ }
+
+ /* Fall through to free NDIS_CONFIGURATION_PARAMETER struct */
+
+ case MINIPORT_RESOURCE_TYPE_MEMORY:
NDIS_DbgPrint(MAX_TRACE,("freeing 0x%x\n", Resource->Resource));
ExFreePool(Resource->Resource);
+ break;
+
+ default:
+ NDIS_DbgPrint(MIN_TRACE,("Unknown resource type: %d\n", Resource->ResourceType));
+ break;
}
ExFreePool(Resource);
DUPLICATE_SAME_ACCESS);
if(!NT_SUCCESS(*Status))
{
- NDIS_DbgPrint(MID_TRACE, ("Failed to open registry configuration for this miniport\n"));
+ NDIS_DbgPrint(MIN_TRACE, ("Failed to open registry configuration for this miniport\n"));
*Status = NDIS_STATUS_FAILURE;
return;
}
- ConfigurationContext = ExAllocatePool(PagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
+ ConfigurationContext = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
if(!ConfigurationContext)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
if(*Status != NDIS_STATUS_SUCCESS)
{
+ NDIS_DbgPrint(MIN_TRACE, ("ZwOpenKey failed (%x)\n", *Status));
*ConfigurationHandle = NULL;
*Status = NDIS_STATUS_FAILURE;
return;
}
- ConfigurationContext = ExAllocatePool(PagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
+ ConfigurationContext = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
if(!ConfigurationContext)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
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(MAX_TRACE,("requested read of %wZ\n", Keyword));
+
+ if (ConfigurationContext == NULL)
{
- NDIS_DbgPrint(MID_TRACE,("unsupported parameter type\n"));
- *Status = NDIS_STATUS_NOT_SUPPORTED;
- return;
+ NDIS_DbgPrint(MIN_TRACE,("invalid parameter ConfigurationContext (0x%x)\n",ConfigurationContext));
+ return;
}
- NDIS_DbgPrint(MAX_TRACE,("requested read of %wZ\n", Keyword));
-
if(
!wcsncmp(Keyword->Buffer, L"Environment", Keyword->Length/sizeof(WCHAR)) &&
wcslen(L"Environment") == Keyword->Length/sizeof(WCHAR)
return;
}
- MiniportResource->ResourceType = 0;
+ MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
MiniportResource->Resource = *ParameterValue;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n",
return;
}
- MiniportResource->ResourceType = 0;
+ MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
MiniportResource->Resource = *ParameterValue;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
return;
}
- MiniportResource->ResourceType = 0;
+ MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
MiniportResource->Resource = *ParameterValue;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
*Status = ZwQueryValueKey(ConfigurationContext->Handle, Keyword, KeyValuePartialInformation, NULL, 0, &KeyDataLength);
if(*Status != STATUS_BUFFER_OVERFLOW && *Status != STATUS_BUFFER_TOO_SMALL && *Status != STATUS_SUCCESS)
{
- NDIS_DbgPrint(MID_TRACE,("ZwQueryValueKey #1 failed for %wZ, status 0x%x\n", Keyword, *Status));
+ NDIS_DbgPrint(MIN_TRACE,("ZwQueryValueKey #1 failed for %wZ, status 0x%x\n", Keyword, *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
if(*Status != STATUS_SUCCESS)
{
ExFreePool(KeyInformation);
- NDIS_DbgPrint(MID_TRACE,("ZwQueryValueKey #2 failed for %wZ, status 0x%x\n", Keyword, *Status));
+ NDIS_DbgPrint(MIN_TRACE,("ZwQueryValueKey #2 failed for %wZ, status 0x%x\n", Keyword, *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
return;
}
- switch(ParameterType)
+ *ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
+ if (!*ParameterValue)
{
- case NdisParameterInteger:
- case NdisParameterHexInteger:
- {
- 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;
+ NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+ ExFreePool(MiniportResource);
+ ExFreePool(KeyInformation);
+ *Status = NDIS_STATUS_RESOURCES;
+ return;
+ }
- (*ParameterValue)->ParameterType = ParameterType;
+ RtlZeroMemory(*ParameterValue, sizeof(NDIS_CONFIGURATION_PARAMETER));
- /*
- 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);
+ if (KeyInformation->Type == REG_BINARY)
+ {
+ NDIS_DbgPrint(MAX_TRACE, ("NdisParameterBinary\n"));
+ (*ParameterValue)->ParameterType = NdisParameterBinary;
+ Buffer = ExAllocatePool(NonPagedPool, KeyInformation->DataLength);
+ if (!Buffer)
+ {
+ 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:
- {
- PWCHAR RegData = 0;
+ RtlCopyMemory(Buffer, KeyInformation->Data, KeyInformation->DataLength);
- if(KeyInformation->Type != REG_SZ && KeyInformation->Type != REG_MULTI_SZ)
- {
- NDIS_DbgPrint(MID_TRACE,("requested type does not match actual value type\n"));
- ExFreePool(KeyInformation);
- *ParameterValue = NULL;
- *Status = NDIS_STATUS_FAILURE;
- return;
- }
+ (*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 = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
- if(!*ParameterValue)
- {
- NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
- ExFreePool(KeyInformation);
- *Status = NDIS_STATUS_RESOURCES;
- return;
- }
+ (*ParameterValue)->ParameterType = NdisParameterMultiString;
- 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;
- }
+ Buffer = ExAllocatePool(NonPagedPool, KeyInformation->DataLength);
+ if (!Buffer)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+ ExFreePool(MiniportResource);
+ ExFreePool(KeyInformation);
+ *Status = NDIS_STATUS_RESOURCES;
+ 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);
+ RtlCopyMemory(Buffer, KeyInformation->Data, KeyInformation->DataLength);
- memcpy(RegData, KeyInformation->Data, KeyInformation->DataLength);
+ (*ParameterValue)->ParameterData.StringData.Buffer = Buffer;
+ (*ParameterValue)->ParameterData.StringData.Length = KeyInformation->DataLength;
+ }
+ else
+ {
+ UNICODE_STRING str;
- (*ParameterValue)->ParameterType = ParameterType;
- (*ParameterValue)->ParameterData.StringData.Length = (USHORT)KeyInformation->DataLength;
- (*ParameterValue)->ParameterData.StringData.Buffer = RegData;
+ str.Length = str.MaximumLength = (USHORT)KeyInformation->DataLength;
+ str.Buffer = (PWCHAR)KeyInformation->Data;
- ExFreePool(KeyInformation);
+ if ((*Status = RtlUnicodeStringToInteger(&str, 0,
+ &(*ParameterValue)->ParameterData.IntegerData)) == STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MAX_TRACE, ("NdisParameterInteger\n"));
- *Status = NDIS_STATUS_SUCCESS;
+ (*ParameterValue)->ParameterType = NdisParameterInteger;
+ }
+ else
+ {
+ NDIS_DbgPrint(MAX_TRACE, ("NdisParameterString\n"));
- return;
- }
+ (*ParameterValue)->ParameterType = NdisParameterString;
- 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;
- }
+ Buffer = ExAllocatePool(NonPagedPool, KeyInformation->DataLength);
+ if (!Buffer)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+ ExFreePool(MiniportResource);
+ ExFreePool(KeyInformation);
+ *Status = NDIS_STATUS_RESOURCES;
+ 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;
- }
+ RtlCopyMemory(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);
+ (*ParameterValue)->ParameterData.StringData.Buffer = Buffer;
+ (*ParameterValue)->ParameterData.StringData.Length = KeyInformation->DataLength;
+ }
+ }
- (*ParameterValue)->ParameterType = ParameterType;
- memcpy(&((*ParameterValue)->ParameterData.BinaryData), KeyInformation->Data, KeyInformation->DataLength);
+ MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
+ MiniportResource->Resource = *ParameterValue;
- ExFreePool(KeyInformation);
+ ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
- *Status = NDIS_STATUS_SUCCESS;
+ ExFreePool(KeyInformation);
- return;
- }
- }
+ *Status = NDIS_STATUS_SUCCESS;
}
NDIS_STRING Keyword;
UINT *IntArray = 0;
UINT i,j = 0;
+ NDIS_STRING str;
NdisInitUnicodeString(&Keyword, L"NetworkAddress");
NdisReadConfiguration(Status, &ParameterValue, ConfigurationHandle, &Keyword, NdisParameterString);
if(*Status != NDIS_STATUS_SUCCESS)
{
+ NDIS_DbgPrint(MIN_TRACE, ("NdisReadConfiguration failed (%x)\n", *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
- while (ParameterValue->ParameterData.StringData.Buffer[j] != '\0') j++;
+ if (ParameterValue->ParameterType == NdisParameterInteger)
+ {
+ WCHAR Buff[11];
+
+ NDIS_DbgPrint(MAX_TRACE, ("Read integer data %lx\n",
+ ParameterValue->ParameterData.IntegerData));
+
+ str.Buffer = Buff;
+ str.MaximumLength = (USHORT)sizeof(Buff);
+ str.Length = 0;
- *NetworkAddressLength = (UINT)((j/2)+0.5);
+ *Status = RtlIntegerToUnicodeString(ParameterValue->ParameterData.IntegerData,
+ 10,
+ &str);
- if (j == 0)
+ if (*Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("RtlIntegerToUnicodeString failed (%x)\n", *Status));
+ *Status = NDIS_STATUS_FAILURE;
+ return;
+ }
+
+ NDIS_DbgPrint(MAX_TRACE, ("Converted integer data into %wZ\n", &str));
+ }
+ else
+ {
+ ASSERT(ParameterValue->ParameterType == NdisParameterString);
+ str = ParameterValue->ParameterData.StringData;
+ }
+
+ while (j < str.Length && str.Buffer[j] != '\0') j++;
+
+ *NetworkAddressLength = (j+1) >> 1;
+
+ if ((*NetworkAddressLength) == 0)
{
NDIS_DbgPrint(MIN_TRACE,("Empty NetworkAddress registry entry.\n"));
*Status = NDIS_STATUS_FAILURE;
return;
}
- MiniportResource->ResourceType = 0;
+ MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_MEMORY;
MiniportResource->Resource = IntArray;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
/* convert from string to bytes */
for(i=0; i<(*NetworkAddressLength); i++)
{
- IntArray[i] = (UnicodeToHexByte((ParameterValue->ParameterData.StringData.Buffer)[2*i]) << 4) +
- UnicodeToHexByte((ParameterValue->ParameterData.StringData.Buffer)[2*i+1]);
+ IntArray[i] = (UnicodeToHexByte((str.Buffer)[2*i]) << 4) +
+ UnicodeToHexByte((str.Buffer)[2*i+1]);
}
*NetworkAddress = IntArray;
*Status = ZwEnumerateKey(ConfigurationHandle, Index, KeyBasicInformation, NULL, 0, &KeyInformationLength);
if(*Status != STATUS_BUFFER_TOO_SMALL && *Status != STATUS_BUFFER_OVERFLOW && *Status != STATUS_SUCCESS)
{
+ NDIS_DbgPrint(MIN_TRACE, ("ZwEnumerateKey failed (%x)\n", *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
if(*Status != STATUS_SUCCESS)
{
+ NDIS_DbgPrint(MIN_TRACE, ("ZwEnumerateKey failed (%x)\n", *Status));
ExFreePool(KeyInformation);
*Status = NDIS_STATUS_FAILURE;
return;
if(*Status != STATUS_SUCCESS)
{
+ NDIS_DbgPrint(MIN_TRACE, ("ZwOpenKey failed (%x)\n", *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
- ConfigurationContext = ExAllocatePool(PagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
+ ConfigurationContext = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
if(!ConfigurationContext)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
if(*Status != STATUS_SUCCESS)
{
+ NDIS_DbgPrint(MIN_TRACE, ("ZwOpenKey failed (%x)\n", *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
- ConfigurationContext = ExAllocatePool(PagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
+ ConfigurationContext = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
if(!ConfigurationContext)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
*Status = NDIS_STATUS_SUCCESS;
}
-