ReactOS 0.4.17-dev-1321-g5c122a9
config.c File Reference
#include "ndissys.h"
#include <ntifs.h>
Include dependency graph for config.c:

Go to the source code of this file.

Macros

#define PARAMETERS_KEY   L"Parameters" /* The parameters subkey under the device-specific key */
 

Functions

static PMINIPORT_CONFIGURATION_CONTEXT AllocateConfigurationContext (_In_ POBJECT_ATTRIBUTES ObjectAttributes)
 
static VOID AddConfigurationParameter (_In_ PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext, _Out_ PMINIPORT_RESOURCE MiniportResource, _In_ ULONG Type, _In_ PVOID ConfigParameter)
 
VOID EXPORT NdisWriteConfiguration (OUT PNDIS_STATUS Status, IN NDIS_HANDLE ConfigurationHandle, IN PNDIS_STRING Keyword, IN PNDIS_CONFIGURATION_PARAMETER ParameterValue)
 
VOID EXPORT NdisCloseConfiguration (IN NDIS_HANDLE ConfigurationHandle)
 
VOID EXPORT NdisOpenConfiguration (OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE ConfigurationHandle, IN NDIS_HANDLE WrapperConfigurationContext)
 
VOID EXPORT NdisOpenProtocolConfiguration (OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE ConfigurationHandle, IN PNDIS_STRING ProtocolSection)
 
static UCHAR UnicodeToHexByte (WCHAR chr)
 
static BOOLEAN IsValidNumericString (PNDIS_STRING String, ULONG Base)
 
VOID EXPORT NdisReadConfiguration (_At_(*Status, _Must_inspect_result_) _Out_ PNDIS_STATUS Status, _Out_ PNDIS_CONFIGURATION_PARAMETER *ParameterValue, _In_ NDIS_HANDLE ConfigurationHandle, _In_ PNDIS_STRING Keyword, _In_ NDIS_PARAMETER_TYPE ParameterType)
 
VOID EXPORT NdisReadNetworkAddress (OUT PNDIS_STATUS Status, OUT PVOID *NetworkAddress, OUT PUINT NetworkAddressLength, IN NDIS_HANDLE ConfigurationHandle)
 
VOID EXPORT NdisOpenConfigurationKeyByIndex (OUT PNDIS_STATUS Status, IN NDIS_HANDLE ConfigurationHandle, IN ULONG Index, OUT PNDIS_STRING KeyName, OUT PNDIS_HANDLE KeyHandle)
 
VOID EXPORT NdisOpenConfigurationKeyByName (OUT PNDIS_STATUS Status, IN NDIS_HANDLE ConfigurationHandle, IN PNDIS_STRING KeyName, OUT PNDIS_HANDLE KeyHandle)
 

Variables

ULONG NdisEnableTxRxFlowControl
 

Macro Definition Documentation

◆ PARAMETERS_KEY

#define PARAMETERS_KEY   L"Parameters" /* The parameters subkey under the device-specific key */

Definition at line 38 of file config.c.

Function Documentation

◆ AddConfigurationParameter()

static VOID AddConfigurationParameter ( _In_ PMINIPORT_CONFIGURATION_CONTEXT  ConfigurationContext,
_Out_ PMINIPORT_RESOURCE  MiniportResource,
_In_ ULONG  Type,
_In_ PVOID  ConfigParameter 
)
static

Definition at line 80 of file config.c.

85{
86 MiniportResource->ResourceType = Type;
87 MiniportResource->Resource = ConfigParameter;
88
89 NDIS_DbgPrint(MID_TRACE, ("inserting %p into the resource list\n",
90 MiniportResource->Resource));
91
92 ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
93 &MiniportResource->ListEntry,
94 &ConfigurationContext->ResourceLock);
95}
Type
Definition: Type.h:7
#define MID_TRACE
Definition: debug.h:15
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140

Referenced by NdisReadConfiguration(), and NdisReadNetworkAddress().

◆ AllocateConfigurationContext()

static PMINIPORT_CONFIGURATION_CONTEXT AllocateConfigurationContext ( _In_ POBJECT_ATTRIBUTES  ObjectAttributes)
static

Definition at line 44 of file config.c.

46{
47 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
50
52 if (!NT_SUCCESS(Status))
53 {
54 NDIS_DbgPrint(MIN_TRACE, ("Failed to open registry configuration for this miniport "
55 "'%wZ', status 0x%lx\n",
56 ObjectAttributes->ObjectName, Status));
57 return NULL;
58 }
59
60 ConfigurationContext = ExAllocatePoolUninitialized(NonPagedPool,
61 sizeof(*ConfigurationContext),
63 if (!ConfigurationContext)
64 {
65 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
67 return NULL;
68 }
69
70 ConfigurationContext->Handle = KeyHandle;
71
72 KeInitializeSpinLock(&ConfigurationContext->ResourceLock);
73 InitializeListHead(&ConfigurationContext->ResourceListHead);
74
75 return ConfigurationContext;
76}
#define ExAllocatePoolUninitialized
LONG NTSTATUS
Definition: precomp.h:26
#define MIN_TRACE
Definition: debug.h:14
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
Status
Definition: gdiplustypes.h:24
return ZwOpenKey(Handle, KEY_READ, &Attributes)
ZwClose(Handle)
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4717
#define TAG_CONFIG
Definition: ndissys.h:31
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044

Referenced by NdisOpenConfiguration(), NdisOpenConfigurationKeyByIndex(), NdisOpenConfigurationKeyByName(), and NdisOpenProtocolConfiguration().

◆ IsValidNumericString()

static BOOLEAN IsValidNumericString ( PNDIS_STRING  String,
ULONG  Base 
)
static

Definition at line 403 of file config.c.

411{
412 ULONG i;
413
414 /* I don't think this will ever happen, but we warn it if it does */
415 if (String->Length == 0)
416 {
417 NDIS_DbgPrint(MIN_TRACE, ("Got an empty string; not sure what to do here\n"));
418 return FALSE;
419 }
420
421 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
422 {
423 /* Skip any NULL characters we find */
424 if (String->Buffer[i] == UNICODE_NULL)
425 continue;
426
427 /* Make sure the character is valid for a numeric string of this base */
428 if (UnicodeToHexByte(String->Buffer[i]) >= Base)
429 return FALSE;
430 }
431
432 /* It's valid */
433 return TRUE;
434}
Walk Base
Definition: desccheck.cpp:2270
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static UCHAR UnicodeToHexByte(WCHAR chr)
Definition: config.c:358
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define UNICODE_NULL
short WCHAR
Definition: pedump.c:58
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439

Referenced by NdisReadConfiguration().

◆ NdisCloseConfiguration()

VOID EXPORT NdisCloseConfiguration ( IN NDIS_HANDLE  ConfigurationHandle)

Definition at line 193 of file config.c.

200{
204 PLIST_ENTRY CurrentEntry;
205
206 while((CurrentEntry = ExInterlockedRemoveHeadList(&ConfigurationContext->ResourceListHead,
207 &ConfigurationContext->ResourceLock)) != NULL)
208 {
209 Resource = CONTAINING_RECORD(CurrentEntry, MINIPORT_RESOURCE, ListEntry);
210 switch(Resource->ResourceType)
211 {
213 ParameterValue = Resource->Resource;
214
215 switch (ParameterValue->ParameterType)
216 {
218 ExFreePoolWithTag(ParameterValue->ParameterData.BinaryData.Buffer, TAG_CONFIG);
219 break;
220
223 ExFreePoolWithTag(ParameterValue->ParameterData.StringData.Buffer, TAG_CONFIG);
224 break;
225
226 default:
227 break;
228 }
229
230 /* Fall through to free NDIS_CONFIGURATION_PARAMETER struct */
231
233 NDIS_DbgPrint(MAX_TRACE,("freeing 0x%x\n", Resource->Resource));
235 break;
236
237 default:
238 NDIS_DbgPrint(MIN_TRACE,("Unknown resource type: %d\n", Resource->ResourceType));
239 break;
240 }
241
243 }
244
245 ZwClose(ConfigurationContext->Handle);
246}
#define MAX_TRACE
Definition: debug.h:16
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
_In_opt_ PWSTR _In_ PWSTR _Inout_ PULONG ParameterValue
Definition: cdrom.h:963
#define MINIPORT_RESOURCE_TYPE_REGISTRY_DATA
Definition: miniport.h:41
#define MINIPORT_RESOURCE_TYPE_MEMORY
Definition: miniport.h:42
struct _MINIPORT_CONFIGURATION_CONTEXT * PMINIPORT_CONFIGURATION_CONTEXT
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
@ NdisParameterBinary
Definition: ndis.h:932
@ NdisParameterString
Definition: ndis.h:930
@ NdisParameterMultiString
Definition: ndis.h:931
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE ConfigurationHandle
Definition: ndis.h:3947
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by DcReadConfiguration(), MiniportInitialize(), NdisIPnPStartDevice(), NvNetReadConfiguration(), and ReadNicConfiguration().

◆ NdisOpenConfiguration()

VOID EXPORT NdisOpenConfiguration ( OUT PNDIS_STATUS  Status,
OUT PNDIS_HANDLE  ConfigurationHandle,
IN NDIS_HANDLE  WrapperConfigurationContext 
)

Definition at line 254 of file config.c.

270{
271 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
273 HANDLE RootKeyHandle = WrapperContext->RegistryHandle;
276
277 NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
278
280
282 &NoName,
284 RootKeyHandle,
285 NULL);
286
287 ConfigurationContext = AllocateConfigurationContext(&ObjectAttributes);
288 if(!ConfigurationContext)
289 {
290 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
292 return;
293 }
294
295 *ConfigurationHandle = (NDIS_HANDLE)ConfigurationContext;
297
298 NDIS_DbgPrint(MAX_TRACE,("returning success\n"));
299}
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
#define L(x)
Definition: resources.c:13
struct _NDIS_WRAPPER_CONTEXT * PNDIS_WRAPPER_CONTEXT
static PMINIPORT_CONFIGURATION_CONTEXT AllocateConfigurationContext(_In_ POBJECT_ATTRIBUTES ObjectAttributes)
Definition: config.c:44
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
PVOID NDIS_HANDLE
Definition: ndis.h:338
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _In_ NDIS_HANDLE WrapperConfigurationContext
Definition: ndis.h:3948
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by DcReadConfiguration(), MiniportInitialize(), NdisIPnPStartDevice(), NvNetReadConfiguration(), and ParaNdis_OpenNICConfiguration().

◆ NdisOpenConfigurationKeyByIndex()

VOID EXPORT NdisOpenConfigurationKeyByIndex ( OUT PNDIS_STATUS  Status,
IN NDIS_HANDLE  ConfigurationHandle,
IN ULONG  Index,
OUT PNDIS_STRING  KeyName,
OUT PNDIS_HANDLE  KeyHandle 
)

Definition at line 876 of file config.c.

896{
897 KEY_BASIC_INFORMATION *KeyInformation;
898 ULONG KeyInformationLength;
900 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
901
902 *KeyHandle = NULL;
903
904 *Status = ZwEnumerateKey(ConfigurationHandle, Index, KeyBasicInformation, NULL, 0, &KeyInformationLength);
906 {
907 NDIS_DbgPrint(MIN_TRACE, ("ZwEnumerateKey failed (%x)\n", *Status));
909 return;
910 }
911
912 KeyInformation = ExAllocatePoolUninitialized(PagedPool,
913 KeyInformationLength + sizeof(*KeyInformation),
914 TAG_CONFIG);
915 if(!KeyInformation)
916 {
917 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
919 return;
920 }
921
922 *Status = ZwEnumerateKey(ConfigurationHandle, Index, KeyBasicInformation, KeyInformation,
923 KeyInformationLength + sizeof(KEY_BASIC_INFORMATION), &KeyInformationLength);
924
925 if(*Status != STATUS_SUCCESS)
926 {
927 NDIS_DbgPrint(MIN_TRACE, ("ZwEnumerateKey failed (%x)\n", *Status));
928 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
930 return;
931 }
932
933 /* should i fail instead if the passed-in string isn't long enough? */
934 wcsncpy(KeyName->Buffer, KeyInformation->Name, KeyName->MaximumLength/sizeof(WCHAR));
935 KeyName->Length = (USHORT)min(KeyInformation->NameLength, KeyName->MaximumLength);
936
938
939 ConfigurationContext = AllocateConfigurationContext(&KeyAttributes);
940 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
941 if(!ConfigurationContext)
942 {
943 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
945 return;
946 }
947
948 *KeyHandle = (NDIS_HANDLE)ConfigurationContext;
950}
#define PagedPool
Definition: env_spec_w32.h:308
#define min(a, b)
Definition: monoChain.cc:55
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
@ KeyBasicInformation
Definition: nt_native.h:1134
unsigned short USHORT
Definition: pedump.c:61
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
wcsncpy
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES KeyAttributes
Definition: wdfdevice.h:2666
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705

◆ NdisOpenConfigurationKeyByName()

VOID EXPORT NdisOpenConfigurationKeyByName ( OUT PNDIS_STATUS  Status,
IN NDIS_HANDLE  ConfigurationHandle,
IN PNDIS_STRING  KeyName,
OUT PNDIS_HANDLE  KeyHandle 
)

Definition at line 958 of file config.c.

976{
977 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
979
980 *KeyHandle = NULL;
981
983
984 ConfigurationContext = AllocateConfigurationContext(&KeyAttributes);
985 if(!ConfigurationContext)
986 {
987 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
989 return;
990 }
991
992 *KeyHandle = (NDIS_HANDLE)ConfigurationContext;
994}

◆ NdisOpenProtocolConfiguration()

VOID EXPORT NdisOpenProtocolConfiguration ( OUT PNDIS_STATUS  Status,
OUT PNDIS_HANDLE  ConfigurationHandle,
IN PNDIS_STRING  ProtocolSection 
)

Definition at line 307 of file config.c.

323{
325 UNICODE_STRING KeyNameU;
326 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
327
328 KeyNameU.Length = 0;
329 KeyNameU.MaximumLength = ProtocolSection->Length + sizeof(PARAMETERS_KEY) + sizeof(UNICODE_NULL);
331 if(!KeyNameU.Buffer)
332 {
333 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
336 return;
337 }
338
342
343 ConfigurationContext = AllocateConfigurationContext(&KeyAttributes);
345 if(!ConfigurationContext)
346 {
347 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
350 return;
351 }
352
353 *ConfigurationHandle = (NDIS_HANDLE)ConfigurationContext;
355}
#define PARAMETERS_KEY
Definition: config.c:38
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_Out_ PNDIS_HANDLE _In_ PNDIS_STRING ProtocolSection
Definition: ndis.h:6075
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
USHORT MaximumLength
Definition: env_spec_w32.h:370

◆ NdisReadConfiguration()

VOID EXPORT NdisReadConfiguration ( _At_ *, _Must_inspect_result_ _Out_ PNDIS_STATUS  Status,
_Out_ PNDIS_CONFIGURATION_PARAMETER *  ParameterValue,
_In_ NDIS_HANDLE  ConfigurationHandle,
_In_ PNDIS_STRING  Keyword,
_In_ NDIS_PARAMETER_TYPE  ParameterType 
)

Definition at line 441 of file config.c.

462{
464 PKEY_VALUE_PARTIAL_INFORMATION KeyInformation = NULL;
465 PNDIS_CONFIGURATION_PARAMETER ConfigParameter = NULL;
466 PMINIPORT_RESOURCE MiniportResource = NULL;
467 NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
468 NTSTATUS NtStatus;
469 ULONG LocalUlong;
471 ULONG RegType;
472 ULONG RegDataLength;
473 static const UNICODE_STRING NdisVersionKey = RTL_CONSTANT_STRING(L"NdisVersion");
474 static const UNICODE_STRING EnvironmentKey = RTL_CONSTANT_STRING(L"Environment");
475 static const UNICODE_STRING ProcessorTypeKey = RTL_CONSTANT_STRING(L"ProcessorType");
476 static const UNICODE_STRING FlowControlKey = RTL_CONSTANT_STRING(L"*FlowControl");
477
478 NDIS_DbgPrint(MAX_TRACE, ("requested read type %d of '%wZ'\n", ParameterType, Keyword));
479
480 ASSERT(ConfigurationContext);
481
482 /* Check for predefined entry names */
484 {
485 NDIS_DbgPrint(MID_TRACE, ("Disable TX/RX flow control for this miniport\n"));
486 LocalUlong = 0;
487
488 RegType = REG_DWORD;
489 RegData = &LocalUlong;
490 RegDataLength = sizeof(LocalUlong);
491 }
492 else if (RtlEqualUnicodeString(Keyword, &NdisVersionKey, TRUE))
493 {
494 LocalUlong = NDIS_VERSION;
495
496 RegType = REG_DWORD;
497 RegData = &LocalUlong;
498 RegDataLength = sizeof(LocalUlong);
499 }
500 else if (RtlEqualUnicodeString(Keyword, &EnvironmentKey, TRUE))
501 {
502 LocalUlong = NdisEnvironmentWindowsNt;
503
504 RegType = REG_DWORD;
505 RegData = &LocalUlong;
506 RegDataLength = sizeof(LocalUlong);
507 }
508 else if (RtlEqualUnicodeString(Keyword, &ProcessorTypeKey, TRUE))
509 {
510#if defined(_M_IX86)
511 LocalUlong = NdisProcessorX86;
512#elif defined(_M_MIPS)
513 LocalUlong = NdisProcessorMips;
514#elif defined(_M_ALPHA)
515 LocalUlong = NdisProcessorAlpha;
516#elif defined(_M_MPPC)
517 LocalUlong = NdisProcessorPpc;
518#elif defined(_M_AMD64)
519 LocalUlong = NdisProcessorAmd64;
520#elif defined(_M_IA64)
521 LocalUlong = NdisProcessorIA64;
522#elif defined(_M_ARM)
523 LocalUlong = NdisProcessorArm;
524#elif defined(_M_ARM64)
525 LocalUlong = NdisProcessorArm64;
526#else
527#error Unknown architecture
528#endif
529
530 RegType = REG_DWORD;
531 RegData = &LocalUlong;
532 RegDataLength = sizeof(LocalUlong);
533 }
534 else
535 {
536 ULONG KeyDataLength, RetryCount;
537
538 /* The most common case is NdisParameterInteger (REG_DWORD) */
539 KeyDataLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + sizeof(ULONG);
540
541 for (RetryCount = 0; RetryCount < 2; ++RetryCount)
542 {
543 KeyInformation = ExAllocatePoolUninitialized(PagedPool, KeyDataLength, TAG_CONFIG);
544 if (!KeyInformation)
545 {
546 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
548 return;
549 }
550
551 /* Query the value */
552 NtStatus = ZwQueryValueKey(ConfigurationContext->Handle,
553 Keyword,
555 KeyInformation,
556 KeyDataLength,
557 &KeyDataLength);
558
559 /* Increase the allocation size if it's too small */
560 if (NtStatus == STATUS_BUFFER_OVERFLOW || NtStatus == STATUS_BUFFER_TOO_SMALL)
561 {
562 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
563 KeyInformation = NULL;
564 continue;
565 }
566
567 break;
568 }
569
570 if (!NT_SUCCESS(NtStatus))
571 {
572 NDIS_DbgPrint(MIN_TRACE, ("ZwQueryValueKey failed for '%wZ', status 0x%lx\n",
573 Keyword, NtStatus));
574 NdisStatus = NDIS_STATUS_FAILURE;
575 goto Exit;
576 }
577
578 RegType = KeyInformation->Type;
579 RegData = &KeyInformation->Data[0];
580 RegDataLength = KeyInformation->DataLength;
581 }
582
583 MiniportResource = ExAllocatePoolUninitialized(PagedPool,
584 sizeof(*MiniportResource),
585 TAG_CONFIG);
586 if (!MiniportResource)
587 {
588 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
589 NdisStatus = NDIS_STATUS_RESOURCES;
590 goto Exit;
591 }
592
593 ConfigParameter = ExAllocatePoolZero(PagedPool, sizeof(*ConfigParameter), TAG_CONFIG);
594 if (!ConfigParameter)
595 {
596 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
597 NdisStatus = NDIS_STATUS_RESOURCES;
598 goto Exit;
599 }
600
601 switch (RegType)
602 {
603 case REG_DWORD:
604 {
605 ASSERT(RegDataLength == sizeof(ULONG));
606
607 ConfigParameter->ParameterType = NdisParameterInteger;
608 ConfigParameter->ParameterData.IntegerData = *(PULONG)RegData;
609
610 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterInteger 0x%lX (%lu)\n",
611 ConfigParameter->ParameterData.IntegerData,
612 ConfigParameter->ParameterData.IntegerData));
613 break;
614 }
615 case REG_BINARY:
616 {
618
619 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterBinary\n"));
620
622 if (!Buffer)
623 {
624 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
625 NdisStatus = NDIS_STATUS_RESOURCES;
626 goto Exit;
627 }
628 RtlCopyMemory(Buffer, RegData, RegDataLength);
629
630 ConfigParameter->ParameterData.BinaryData.Buffer = Buffer;
631 ConfigParameter->ParameterData.BinaryData.Length = RegDataLength;
632 break;
633 }
634 case REG_MULTI_SZ:
635 {
637
638 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterMultiString\n"));
639
641 if (!Buffer)
642 {
643 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
644 NdisStatus = NDIS_STATUS_RESOURCES;
645 goto Exit;
646 }
647 RtlCopyMemory(Buffer, RegData, RegDataLength);
648
649 ConfigParameter->ParameterType = NdisParameterMultiString;
650 ConfigParameter->ParameterData.StringData.Buffer = Buffer;
651 ConfigParameter->ParameterData.StringData.Length = RegDataLength;
652 break;
653 }
654 case REG_SZ:
655 {
657 ULONG Base;
659
661 Base = 10;
663 Base = 16;
664 else
665 Base = 0;
666
667 String.Length = String.MaximumLength = (USHORT)RegDataLength;
668 String.Buffer = RegData;
669
670 if (Base != 0 && IsValidNumericString(&String, Base))
671 {
673 Base,
674 &ConfigParameter->ParameterData.IntegerData);
675 ASSERT(NT_SUCCESS(NtStatus));
676
677 NDIS_DbgPrint(MAX_TRACE, ("NdisParameter(Hex)Integer 0x%lX (%lu)\n",
678 ConfigParameter->ParameterData.IntegerData,
679 ConfigParameter->ParameterData.IntegerData));
680
681 /*
682 * MSDN documents that this is returned for all integers,
683 * regardless of the ParameterType passed in.
684 */
685 ConfigParameter->ParameterType = NdisParameterInteger;
686 }
687 else
688 {
689 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterString\n"));
690
691 ConfigParameter->ParameterType = NdisParameterString;
692
694 RegDataLength,
695 TAG_CONFIG);
696 if (!Buffer)
697 {
698 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
699 NdisStatus = NDIS_STATUS_RESOURCES;
700 goto Exit;
701 }
702 RtlCopyMemory(Buffer, RegData, RegDataLength);
703
704 ConfigParameter->ParameterData.StringData.Buffer = Buffer;
705 ConfigParameter->ParameterData.StringData.Length = RegDataLength;
706 }
707 break;
708 }
709 default:
710 {
711 NDIS_DbgPrint(MIN_TRACE, ("Invalid type for NdisReadConfiguration (%d)\n", RegType));
712 NDIS_DbgPrint(MIN_TRACE, ("Requested type: %lu\n", ParameterType));
713 NDIS_DbgPrint(MIN_TRACE, ("Registry entry: '%wZ'\n", Keyword));
714
715 NdisStatus = NDIS_STATUS_FAILURE;
716 goto Exit;
717 }
718 }
719
720 if ((ConfigParameter->ParameterType != ParameterType) &&
722 (ConfigParameter->ParameterType == NdisParameterInteger)))
723 {
724 NDIS_DbgPrint(MIN_TRACE, ("Parameter type mismatch! (Requested: %d | Received: %d)\n",
725 ParameterType, ConfigParameter->ParameterType));
726 NDIS_DbgPrint(MIN_TRACE, ("Registry entry: '%wZ'\n", Keyword));
727 }
728
729 ASSERT(NdisStatus == NDIS_STATUS_SUCCESS);
730
731 *ParameterValue = ConfigParameter;
732
733 AddConfigurationParameter(ConfigurationContext,
734 MiniportResource,
736 ConfigParameter);
737Exit:
738 *Status = NdisStatus;
739
740 if (NdisStatus != NDIS_STATUS_SUCCESS)
741 {
742 if (ConfigParameter)
743 ExFreePoolWithTag(ConfigParameter, TAG_CONFIG);
744 if (MiniportResource)
745 ExFreePoolWithTag(MiniportResource, TAG_CONFIG);
746 }
747
748 if (KeyInformation)
749 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
750}
#define REG_SZ
Definition: layer.c:22
REGISTRY_DATA RegData
Definition: registry.c:14
Definition: bufpool.h:45
ULONG NdisEnableTxRxFlowControl
Definition: main.c:25
static BOOLEAN IsValidNumericString(PNDIS_STRING String, ULONG Base)
Definition: config.c:403
static VOID AddConfigurationParameter(_In_ PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext, _Out_ PMINIPORT_RESOURCE MiniportResource, _In_ ULONG Type, _In_ PVOID ConfigParameter)
Definition: config.c:80
#define ASSERT(a)
Definition: mode.c:44
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_CONFIGURATION_PARAMETER _In_ NDIS_HANDLE _In_ PNDIS_STRING _In_ NDIS_PARAMETER_TYPE ParameterType
Definition: ndis.h:4419
@ NdisParameterInteger
Definition: ndis.h:928
@ NdisParameterHexInteger
Definition: ndis.h:929
@ NdisProcessorPpc
Definition: ndis.h:888
@ NdisProcessorAlpha
Definition: ndis.h:887
@ NdisProcessorMips
Definition: ndis.h:886
@ NdisProcessorAmd64
Definition: ndis.h:889
@ NdisProcessorArm
Definition: ndis.h:891
@ NdisProcessorArm64
Definition: ndis.h:892
@ NdisProcessorIA64
Definition: ndis.h:890
@ NdisProcessorX86
Definition: ndis.h:885
@ NdisEnvironmentWindowsNt
Definition: ndis.h:897
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_CONFIGURATION_PARAMETER _In_ NDIS_HANDLE _In_ PNDIS_STRING Keyword
Definition: ndis.h:4418
#define NDIS_VERSION
Definition: ndissys.h:27
#define REG_BINARY
Definition: nt_native.h:1499
@ KeyValuePartialInformation
Definition: nt_native.h:1185
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
#define REG_MULTI_SZ
Definition: nt_native.h:1504
int NDIS_STATUS
Definition: ntddndis.h:496
#define REG_DWORD
Definition: sdbapi.c:615
static void Exit(void)
Definition: sock.c:1330
USHORT Length
Definition: ndis.h:936
BINARY_DATA BinaryData
Definition: ndis.h:945
NDIS_STRING StringData
Definition: ndis.h:944
NDIS_PARAMETER_TYPE ParameterType
Definition: ndis.h:941
union _NDIS_CONFIGURATION_PARAMETER::@2557 ParameterData
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by DcConfigQueryInteger(), GetConfigurationEntry(), MiniportInitialize(), NdisIPnPStartDevice(), NdisReadNetworkAddress(), and QueryInteger().

◆ NdisReadNetworkAddress()

VOID EXPORT NdisReadNetworkAddress ( OUT PNDIS_STATUS  Status,
OUT PVOID *  NetworkAddress,
OUT PUINT  NetworkAddressLength,
IN NDIS_HANDLE  ConfigurationHandle 
)

Definition at line 757 of file config.c.

774{
776 PMINIPORT_RESOURCE MiniportResource = NULL;
779 UINT *IntArray = 0;
780 UINT i,j = 0;
781 WCHAR Buff[11];
783
784 NdisInitUnicodeString(&Keyword, L"NetworkAddress");
787 {
788 NDIS_DbgPrint(MID_TRACE, ("NdisReadConfiguration failed (%x)\n", *Status));
790 return;
791 }
792
793 if (ParameterValue->ParameterType == NdisParameterInteger)
794 {
795 NDIS_DbgPrint(MAX_TRACE, ("Read integer data %lx\n",
796 ParameterValue->ParameterData.IntegerData));
797
798 str.Buffer = Buff;
799 str.MaximumLength = (USHORT)sizeof(Buff);
800 str.Length = 0;
801
802 *Status = RtlIntegerToUnicodeString(ParameterValue->ParameterData.IntegerData,
803 10,
804 &str);
805
807 {
808 NDIS_DbgPrint(MIN_TRACE, ("RtlIntegerToUnicodeString failed (%x)\n", *Status));
810 return;
811 }
812
813 NDIS_DbgPrint(MAX_TRACE, ("Converted integer data into %wZ\n", &str));
814 }
815 else
816 {
817 ASSERT(ParameterValue->ParameterType == NdisParameterString);
818 str = ParameterValue->ParameterData.StringData;
819 }
820
821 while (j < str.Length && str.Buffer[j] != '\0') j++;
822
823 *NetworkAddressLength = (j+1) >> 1;
824
825 if ((*NetworkAddressLength) == 0)
826 {
827 NDIS_DbgPrint(MIN_TRACE,("Empty NetworkAddress registry entry.\n"));
829 return;
830 }
831
833 (*NetworkAddressLength) * sizeof(*IntArray),
834 TAG_CONFIG);
835 if(!IntArray)
836 {
837 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
839 return;
840 }
841
842 MiniportResource = ExAllocatePoolUninitialized(PagedPool,
843 sizeof(*MiniportResource),
844 TAG_CONFIG);
845 if(!MiniportResource)
846 {
847 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
848 ExFreePoolWithTag(IntArray, TAG_CONFIG);
850 return;
851 }
852
853 AddConfigurationParameter(ConfigurationContext,
854 MiniportResource,
856 IntArray);
857
858 /* convert from string to bytes */
859 for(i=0; i<(*NetworkAddressLength); i++)
860 {
861 IntArray[i] = (UnicodeToHexByte((str.Buffer)[2*i]) << 4) +
862 UnicodeToHexByte((str.Buffer)[2*i+1]);
863 }
864
865 *NetworkAddress = IntArray;
866
868}
VOID EXPORT NdisReadConfiguration(_At_(*Status, _Must_inspect_result_) _Out_ PNDIS_STATUS Status, _Out_ PNDIS_CONFIGURATION_PARAMETER *ParameterValue, _In_ NDIS_HANDLE ConfigurationHandle, _In_ PNDIS_STRING Keyword, _In_ NDIS_PARAMETER_TYPE ParameterType)
Definition: config.c:441
VOID EXPORT NdisInitUnicodeString(IN OUT PNDIS_STRING DestinationString, IN PCWSTR SourceString)
Definition: string.c:130
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
unsigned int UINT
Definition: sysinfo.c:13
_Must_inspect_result_ _Out_ PNDIS_STATUS _Outptr_result_bytebuffer_to_ NetworkAddressLength PVOID * NetworkAddress
Definition: ndis.h:3958
_Must_inspect_result_ _Out_ PNDIS_STATUS _Outptr_result_bytebuffer_to_ NetworkAddressLength PVOID _Out_ PUINT NetworkAddressLength
Definition: ndis.h:3960
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
const WCHAR * str

Referenced by DcReadConfiguration(), MiniportInitialize(), NvNetReadConfiguration(), and ReadNicConfiguration().

◆ NdisWriteConfiguration()

VOID EXPORT NdisWriteConfiguration ( OUT PNDIS_STATUS  Status,
IN NDIS_HANDLE  ConfigurationHandle,
IN PNDIS_STRING  Keyword,
IN PNDIS_CONFIGURATION_PARAMETER  ParameterValue 
)

Definition at line 102 of file config.c.

123{
126 PVOID Data;
127 WCHAR Buff[11];
128
129 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
130
131 NDIS_DbgPrint(MID_TRACE, ("Parameter type: %d\n", ParameterValue->ParameterType));
132
133 /* reset parameter type to standard reg types */
134 switch(ParameterValue->ParameterType)
135 {
138 {
140
141 Str.Buffer = (PWSTR) &Buff;
142 Str.MaximumLength = (USHORT)sizeof(Buff);
143 Str.Length = 0;
144
147 ParameterValue->ParameterData.IntegerData,
148 (ParameterValue->ParameterType == NdisParameterInteger) ? 10 : 16, &Str)))
149 {
150 NDIS_DbgPrint(MIN_TRACE, ("RtlIntegerToUnicodeString failed (%x)\n", *Status));
152 return;
153 }
154 Data = Str.Buffer;
155 DataSize = Str.Length;
156 }
157 break;
161 Data = ParameterValue->ParameterData.StringData.Buffer;
162 DataSize = ParameterValue->ParameterData.StringData.Length;
163 break;
164
165 /* New (undocumented) addition to 2k ddk */
168 Data = ParameterValue->ParameterData.BinaryData.Buffer;
169 DataSize = ParameterValue->ParameterData.BinaryData.Length;
170 break;
171
172 default:
174 return;
175 }
176
179
180 if(*Status != STATUS_SUCCESS) {
181 NDIS_DbgPrint(MIN_TRACE, ("ZwSetValueKey failed (%x)\n", *Status));
183 } else
185}
ULONG Handle
Definition: gdb_input.c:15
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4757
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
uint16_t * PWSTR
Definition: typedefs.h:56

◆ UnicodeToHexByte()

static UCHAR UnicodeToHexByte ( WCHAR  chr)
static

Definition at line 358 of file config.c.

366{
367 switch(chr)
368 {
369 case L'0': return 0;
370 case L'1': return 1;
371 case L'2': return 2;
372 case L'3': return 3;
373 case L'4': return 4;
374 case L'5': return 5;
375 case L'6': return 6;
376 case L'7': return 7;
377 case L'8': return 8;
378 case L'9': return 9;
379 case L'A':
380 case L'a':
381 return 10;
382 case L'B':
383 case L'b':
384 return 11;
385 case L'C':
386 case L'c':
387 return 12;
388 case L'D':
389 case L'd':
390 return 13;
391 case L'E':
392 case L'e':
393 return 14;
394 case L'F':
395 case L'f':
396 return 15;
397 }
398 return 0xFF;
399}

Referenced by IsValidNumericString(), and NdisReadNetworkAddress().

Variable Documentation

◆ NdisEnableTxRxFlowControl

ULONG NdisEnableTxRxFlowControl
extern

Definition at line 25 of file main.c.

Referenced by NdisReadConfiguration(), and NdisReadRegistryEntries().