2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
5 * PURPOSE: NDIS Configuration Services
6 * PROGRAMMERS: Vizzini (vizzini@plasmic.com)
8 * Vizzini 07-28-2003 Created
10 * - Resource tracking has to be implemented here because of the design of the NDIS API.
11 * Whenever a read operation is performed, the NDIS library allocates space and returns
12 * it. A linked list is kept associated with every handle of the memory allocated to
13 * it. When the handle is closed, the resources are systematically released.
14 * - The NDIS_HANDLE Configuraiton context is no longer a registry handle. An opaque struct
15 * had to be created to allow for resource tracking. This means that Miniports cannot just
16 * pass this NDIS_HANDLE to things like ZwQueryValueKey(). I don't thknk they do (they
17 * certainly should not), but it should be kept in mind.
18 * UPDATE: I just found this in the NTDDK:
19 * NdisOpenProtocolConfiguration returns a handle for the
20 * HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\NICDriverInstance\Parameters\ProtocolName
21 * registry key. XXX This is a problem. Following that, the DDK instructs programmers
22 * to use NdisReadConfiguration and NdisWriteConfiguration. No telling what the world's idiots
23 * have done with this.
24 * - I have tried to stick to the DDK's definition of what return values are possible, which
25 * has resulted in stupid return values in some cases. I do use STATUS_RESOURCES in a few
26 * places that the DDK doesn't explicitly mention it, though.
27 * - There's a general reliance on the fact that UNICODE_STRING.Length doesn't include a trailing
28 * 0, which it shouldn't
29 * - I added support for NdisParameterBinary. It's at the end of the struct. I wonder if
31 * - All the routines in this file are PASSIVE_LEVEL only, and all memory is PagedPool
36 #define PARAMETERS_KEY L"Parameters" /* The parameters subkey under the device-specific key */
43 NdisWriteConfiguration(
44 OUT PNDIS_STATUS Status
,
45 IN NDIS_HANDLE ConfigurationHandle
,
46 IN PNDIS_STRING Keyword
,
47 IN PNDIS_CONFIGURATION_PARAMETER ParameterValue
)
49 * FUNCTION: Writes a configuration value to the registry
51 * Status: Pointer to a caller-supplied NDIS_STATUS where we return status
52 * ConfigurationHandle: The Configuration Handle passed back from the call to one of the Open functions
53 * Keyword: The registry value name to write
54 * ParameterValue: The value data to write
56 * NDIS_STATUS_SUCCESS - the operation completed successfully
57 * NDIS_STATUS_NOT_SUPPORTED - The parameter type is not supported
58 * NDIS_STATUS_RESOURCES - out of memory, etc.
59 * NDIS_STATUS_FAILURE - any other failure
61 * There's a cryptic comment in the ddk implying that this function allocates and keeps memory.
62 * I don't know why tho so i free everything before return. comments welcome.
70 NDIS_DbgPrint(MAX_TRACE
, ("Called.\n"));
72 /* reset parameter type to standard reg types */
73 switch(ParameterValue
->ParameterType
)
75 case NdisParameterHexInteger
:
76 case NdisParameterInteger
:
80 Str
.Buffer
= (PWSTR
) &Buff
;
81 Str
.MaximumLength
= (USHORT
)sizeof(Buff
);
84 ParameterType
= REG_SZ
;
85 if (!NT_SUCCESS(RtlIntegerToUnicodeString(
86 ParameterValue
->ParameterData
.IntegerData
,
87 (ParameterValue
->ParameterType
== NdisParameterInteger
) ? 10 : 16, &Str
)))
89 NDIS_DbgPrint(MIN_TRACE
, ("RtlIntegerToUnicodeString failed (%x)\n", *Status
));
90 *Status
= NDIS_STATUS_FAILURE
;
94 DataSize
= Str
.Length
;
97 case NdisParameterString
:
98 case NdisParameterMultiString
:
99 ParameterType
= (ParameterValue
->ParameterType
== NdisParameterString
) ? REG_SZ
: REG_MULTI_SZ
;
100 Data
= ParameterValue
->ParameterData
.StringData
.Buffer
;
101 DataSize
= ParameterValue
->ParameterData
.StringData
.Length
;
104 /* New (undocumented) addition to 2k ddk */
105 case NdisParameterBinary
:
106 ParameterType
= REG_BINARY
;
107 Data
= ParameterValue
->ParameterData
.BinaryData
.Buffer
;
108 DataSize
= ParameterValue
->ParameterData
.BinaryData
.Length
;
112 *Status
= NDIS_STATUS_NOT_SUPPORTED
;
116 *Status
= ZwSetValueKey(((PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
)->Handle
,
117 Keyword
, 0, ParameterType
, Data
, DataSize
);
119 if(*Status
!= STATUS_SUCCESS
) {
120 NDIS_DbgPrint(MIN_TRACE
, ("ZwSetValueKey failed (%x)\n", *Status
));
121 *Status
= NDIS_STATUS_FAILURE
;
123 *Status
= NDIS_STATUS_SUCCESS
;
132 NdisCloseConfiguration(
133 IN NDIS_HANDLE ConfigurationHandle
)
135 * FUNCTION: Closes handles and releases per-handle resources
137 * ConfigurationHandle - pointer to the context with the resources to free
140 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
141 PMINIPORT_RESOURCE Resource
;
142 PNDIS_CONFIGURATION_PARAMETER ParameterValue
;
143 PLIST_ENTRY CurrentEntry
;
145 while((CurrentEntry
= ExInterlockedRemoveHeadList(&ConfigurationContext
->ResourceListHead
,
146 &ConfigurationContext
->ResourceLock
)) != NULL
)
148 Resource
= CONTAINING_RECORD(CurrentEntry
, MINIPORT_RESOURCE
, ListEntry
);
149 switch(Resource
->ResourceType
)
151 case MINIPORT_RESOURCE_TYPE_REGISTRY_DATA
:
152 ParameterValue
= Resource
->Resource
;
154 switch (ParameterValue
->ParameterType
)
156 case NdisParameterBinary
:
157 ExFreePool(ParameterValue
->ParameterData
.BinaryData
.Buffer
);
160 case NdisParameterString
:
161 case NdisParameterMultiString
:
162 ExFreePool(ParameterValue
->ParameterData
.StringData
.Buffer
);
169 /* Fall through to free NDIS_CONFIGURATION_PARAMETER struct */
171 case MINIPORT_RESOURCE_TYPE_MEMORY
:
172 NDIS_DbgPrint(MAX_TRACE
,("freeing 0x%x\n", Resource
->Resource
));
173 ExFreePool(Resource
->Resource
);
177 NDIS_DbgPrint(MIN_TRACE
,("Unknown resource type: %d\n", Resource
->ResourceType
));
181 ExFreePool(Resource
);
184 ZwClose(ConfigurationContext
->Handle
);
193 NdisOpenConfiguration(
194 OUT PNDIS_STATUS Status
,
195 OUT PNDIS_HANDLE ConfigurationHandle
,
196 IN NDIS_HANDLE WrapperConfigurationContext
)
198 * FUNCTION: Opens the configuration key and sets up resource tracking for the returned handle
200 * Status: Pointer to a caller-supplied NDIS_STATUS that is filled in with a return value
201 * ConfigurationHandle: Pointer to an opaque configuration handle returned on success
202 * WrapperConfigurationContext: handle originally passed back from NdisInitializeWrapper
204 * NDIS_STATUS_SUCCESS: the operation completed successfully
205 * NDIS_STATUS_FAILURE: the operation failed
207 * I think this is the parameters key; please verify.
211 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
212 PNDIS_WRAPPER_CONTEXT WrapperContext
= (PNDIS_WRAPPER_CONTEXT
)WrapperConfigurationContext
;
213 HANDLE RootKeyHandle
= WrapperContext
->RegistryHandle
;
215 NDIS_DbgPrint(MAX_TRACE
, ("Called\n"));
217 *ConfigurationHandle
= NULL
;
219 *Status
= ZwDuplicateObject(NtCurrentProcess(), RootKeyHandle
,
220 NtCurrentProcess(), &KeyHandle
, 0, 0,
221 DUPLICATE_SAME_ACCESS
);
222 if(!NT_SUCCESS(*Status
))
224 NDIS_DbgPrint(MIN_TRACE
, ("Failed to open registry configuration for this miniport\n"));
225 *Status
= NDIS_STATUS_FAILURE
;
229 ConfigurationContext
= ExAllocatePool(NonPagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
230 if(!ConfigurationContext
)
232 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
234 *Status
= NDIS_STATUS_RESOURCES
;
238 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
239 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
241 ConfigurationContext
->Handle
= KeyHandle
;
243 *ConfigurationHandle
= (NDIS_HANDLE
)ConfigurationContext
;
244 *Status
= NDIS_STATUS_SUCCESS
;
246 NDIS_DbgPrint(MAX_TRACE
,("returning success\n"));
255 NdisOpenProtocolConfiguration(
256 OUT PNDIS_STATUS Status
,
257 OUT PNDIS_HANDLE ConfigurationHandle
,
258 IN PNDIS_STRING ProtocolSection
)
260 * FUNCTION: Open the configuration key and set up resource tracking for the protocol
262 * Status: caller-allocated buffer where status is returned
263 * ConfigurationHandle: spot to return the opaque configuration context
264 * ProtocolSection: configuration string originally passed in to ProtocolBindAdapter
266 * NDIS_STATUS_SUCCESS: the operation was a success
267 * NDIS_STATUS_FAILURE: the operation was not a success
269 * I think this is the per-device (adapter) parameters\{ProtocolName} key; please verify.
272 OBJECT_ATTRIBUTES KeyAttributes
;
273 UNICODE_STRING KeyNameU
;
275 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
278 KeyNameU
.MaximumLength
= ProtocolSection
->Length
+ sizeof(PARAMETERS_KEY
) + sizeof(UNICODE_NULL
);
279 KeyNameU
.Buffer
= ExAllocatePool(PagedPool
, KeyNameU
.MaximumLength
);
282 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
283 *ConfigurationHandle
= NULL
;
284 *Status
= NDIS_STATUS_FAILURE
;
288 RtlCopyUnicodeString(&KeyNameU
, ProtocolSection
);
289 RtlAppendUnicodeToString(&KeyNameU
, PARAMETERS_KEY
);
290 InitializeObjectAttributes(&KeyAttributes
, &KeyNameU
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
292 *Status
= ZwOpenKey(&KeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
294 ExFreePool(KeyNameU
.Buffer
);
296 if(*Status
!= NDIS_STATUS_SUCCESS
)
298 NDIS_DbgPrint(MIN_TRACE
, ("ZwOpenKey failed (%x)\n", *Status
));
299 *ConfigurationHandle
= NULL
;
300 *Status
= NDIS_STATUS_FAILURE
;
304 ConfigurationContext
= ExAllocatePool(NonPagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
305 if(!ConfigurationContext
)
307 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
309 *ConfigurationHandle
= NULL
;
310 *Status
= NDIS_STATUS_FAILURE
;
314 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
315 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
317 ConfigurationContext
->Handle
= KeyHandle
;
319 *ConfigurationHandle
= (NDIS_HANDLE
)ConfigurationContext
;
320 *Status
= NDIS_STATUS_SUCCESS
;
329 NdisReadConfiguration(
330 OUT PNDIS_STATUS Status
,
331 OUT PNDIS_CONFIGURATION_PARAMETER
* ParameterValue
,
332 IN NDIS_HANDLE ConfigurationHandle
,
333 IN PNDIS_STRING Keyword
,
334 IN NDIS_PARAMETER_TYPE ParameterType
)
336 * FUNCTION: Read a configuration value from the registry, tracking its resources
338 * Status: points to a place to write status into
339 * ParameterValue: Pointer to receive a newly-allocated parameter structure
340 * ConfigurationHandle: handle originally returned by an open function
341 * Keyword: Value name to read, or one of the following constants:
342 * Environment - returns NdisEnvironmentWindowsNt
343 * ProcessorType - returns NdisProcessorX86 until more architectures are added
344 * NdisVersion - returns NDIS_VERSION
345 * ParameterType: the type of the value to be queried
347 * - A status in Status
348 * - A parameter value in ParameterValue
351 KEY_VALUE_PARTIAL_INFORMATION
*KeyInformation
;
353 PMINIPORT_RESOURCE MiniportResource
;
354 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
357 *ParameterValue
= NULL
;
358 *Status
= NDIS_STATUS_FAILURE
;
360 NDIS_DbgPrint(MAX_TRACE
,("requested read of %wZ\n", Keyword
));
362 if (ConfigurationContext
== NULL
)
364 NDIS_DbgPrint(MIN_TRACE
,("invalid parameter ConfigurationContext (0x%x)\n",ConfigurationContext
));
369 !wcsncmp(Keyword
->Buffer
, L
"Environment", Keyword
->Length
/sizeof(WCHAR
)) &&
370 wcslen(L
"Environment") == Keyword
->Length
/sizeof(WCHAR
)
373 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
376 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
377 *Status
= NDIS_STATUS_RESOURCES
;
381 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
382 if(!MiniportResource
)
384 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
385 ExFreePool(*ParameterValue
);
386 *ParameterValue
= NULL
;
387 *Status
= NDIS_STATUS_RESOURCES
;
391 MiniportResource
->ResourceType
= MINIPORT_RESOURCE_TYPE_REGISTRY_DATA
;
392 MiniportResource
->Resource
= *ParameterValue
;
394 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n",
395 MiniportResource
->Resource
));
397 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
398 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
400 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
401 (*ParameterValue
)->ParameterData
.IntegerData
= NdisEnvironmentWindowsNt
;
402 *Status
= NDIS_STATUS_SUCCESS
;
408 !wcsncmp(Keyword
->Buffer
, L
"ProcessorType", Keyword
->Length
/sizeof(WCHAR
)) &&
409 wcslen(L
"ProcessorType") == Keyword
->Length
/sizeof(WCHAR
)
412 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
415 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
416 *Status
= NDIS_STATUS_RESOURCES
;
420 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
421 if(!MiniportResource
)
423 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
424 ExFreePool(*ParameterValue
);
425 *ParameterValue
= NULL
;
426 *Status
= NDIS_STATUS_RESOURCES
;
430 MiniportResource
->ResourceType
= MINIPORT_RESOURCE_TYPE_REGISTRY_DATA
;
431 MiniportResource
->Resource
= *ParameterValue
;
432 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
433 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
434 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
436 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
437 (*ParameterValue
)->ParameterData
.IntegerData
= NdisProcessorX86
; /* XXX non-portable */
438 *Status
= NDIS_STATUS_SUCCESS
;
444 !wcsncmp(Keyword
->Buffer
, L
"NdisVersion", Keyword
->Length
/sizeof(WCHAR
)) &&
445 wcslen(L
"NdisVersion") == Keyword
->Length
/sizeof(WCHAR
)
448 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
451 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
452 *Status
= NDIS_STATUS_RESOURCES
;
456 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
457 if(!MiniportResource
)
459 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
460 ExFreePool(*ParameterValue
);
461 *ParameterValue
= NULL
;
462 *Status
= NDIS_STATUS_RESOURCES
;
466 MiniportResource
->ResourceType
= MINIPORT_RESOURCE_TYPE_REGISTRY_DATA
;
467 MiniportResource
->Resource
= *ParameterValue
;
468 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
469 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
470 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
472 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
473 (*ParameterValue
)->ParameterData
.IntegerData
= NDIS_VERSION
;
474 *Status
= NDIS_STATUS_SUCCESS
;
476 NDIS_DbgPrint(MAX_TRACE
,("ParameterType = %0x%x, ParameterValue = 0x%x\n",
477 (*ParameterValue
)->ParameterType
, (*ParameterValue
)->ParameterData
.IntegerData
));
481 /* figure out how much buffer i should allocate */
482 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
, NULL
, 0, &KeyDataLength
);
483 if(*Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_SUCCESS
)
485 NDIS_DbgPrint(MID_TRACE
,("ZwQueryValueKey #1 failed for %wZ, status 0x%x\n", Keyword
, *Status
));
486 *Status
= NDIS_STATUS_FAILURE
;
491 KeyInformation
= ExAllocatePool(PagedPool
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
));
494 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
495 *Status
= NDIS_STATUS_RESOURCES
;
500 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
,
501 KeyInformation
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
), &KeyDataLength
);
502 if(*Status
!= STATUS_SUCCESS
)
504 ExFreePool(KeyInformation
);
505 NDIS_DbgPrint(MIN_TRACE
,("ZwQueryValueKey #2 failed for %wZ, status 0x%x\n", Keyword
, *Status
));
506 *Status
= NDIS_STATUS_FAILURE
;
510 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
511 if(!MiniportResource
)
513 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
514 ExFreePool(KeyInformation
);
515 *Status
= NDIS_STATUS_RESOURCES
;
519 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
520 if (!*ParameterValue
)
522 NDIS_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
523 ExFreePool(MiniportResource
);
524 ExFreePool(KeyInformation
);
525 *Status
= NDIS_STATUS_RESOURCES
;
529 RtlZeroMemory(*ParameterValue
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
531 if (KeyInformation
->Type
== REG_BINARY
)
533 NDIS_DbgPrint(MAX_TRACE
, ("NdisParameterBinary\n"));
535 (*ParameterValue
)->ParameterType
= NdisParameterBinary
;
537 Buffer
= ExAllocatePool(NonPagedPool
, KeyInformation
->DataLength
);
540 NDIS_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
541 ExFreePool(MiniportResource
);
542 ExFreePool(KeyInformation
);
543 *Status
= NDIS_STATUS_RESOURCES
;
547 RtlCopyMemory(Buffer
, KeyInformation
->Data
, KeyInformation
->DataLength
);
549 (*ParameterValue
)->ParameterData
.BinaryData
.Buffer
= Buffer
;
550 (*ParameterValue
)->ParameterData
.BinaryData
.Length
= KeyInformation
->DataLength
;
552 else if (KeyInformation
->Type
== REG_MULTI_SZ
)
554 NDIS_DbgPrint(MAX_TRACE
, ("NdisParameterMultiString\n"));
556 (*ParameterValue
)->ParameterType
= NdisParameterMultiString
;
558 Buffer
= ExAllocatePool(NonPagedPool
, KeyInformation
->DataLength
);
561 NDIS_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
562 ExFreePool(MiniportResource
);
563 ExFreePool(KeyInformation
);
564 *Status
= NDIS_STATUS_RESOURCES
;
568 RtlCopyMemory(Buffer
, KeyInformation
->Data
, KeyInformation
->DataLength
);
570 (*ParameterValue
)->ParameterData
.StringData
.Buffer
= Buffer
;
571 (*ParameterValue
)->ParameterData
.StringData
.Length
= KeyInformation
->DataLength
;
577 str
.Length
= str
.MaximumLength
= (USHORT
)KeyInformation
->DataLength
;
578 str
.Buffer
= (PWCHAR
)KeyInformation
->Data
;
580 if ((*Status
= RtlUnicodeStringToInteger(&str
, 0,
581 &(*ParameterValue
)->ParameterData
.IntegerData
)) == STATUS_SUCCESS
)
583 NDIS_DbgPrint(MAX_TRACE
, ("NdisParameterInteger\n"));
585 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
589 NDIS_DbgPrint(MAX_TRACE
, ("NdisParameterString\n"));
591 (*ParameterValue
)->ParameterType
= NdisParameterString
;
593 Buffer
= ExAllocatePool(NonPagedPool
, KeyInformation
->DataLength
);
596 NDIS_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
597 ExFreePool(MiniportResource
);
598 ExFreePool(KeyInformation
);
599 *Status
= NDIS_STATUS_RESOURCES
;
603 RtlCopyMemory(Buffer
, KeyInformation
->Data
, KeyInformation
->DataLength
);
605 (*ParameterValue
)->ParameterData
.StringData
.Buffer
= Buffer
;
606 (*ParameterValue
)->ParameterData
.StringData
.Length
= KeyInformation
->DataLength
;
610 MiniportResource
->ResourceType
= MINIPORT_RESOURCE_TYPE_REGISTRY_DATA
;
611 MiniportResource
->Resource
= *ParameterValue
;
613 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
615 ExFreePool(KeyInformation
);
617 *Status
= NDIS_STATUS_SUCCESS
;
621 UCHAR
UnicodeToHexByte(WCHAR chr
)
623 * FUNCTION: Converts a unicode hex character to its numerical value
625 * chr: Unicode character to convert
627 * The numerical value of chr
670 NdisReadNetworkAddress(
671 OUT PNDIS_STATUS Status
,
672 OUT PVOID
* NetworkAddress
,
673 OUT PUINT NetworkAddressLength
,
674 IN NDIS_HANDLE ConfigurationHandle
)
676 * FUNCTION: Reads the network address from the registry
678 * Status - variable to receive status
679 * NetworkAddress - pointer to a buffered network address array
680 * NetworkAddressLength - length of the NetworkAddress array
681 * ConfigurationHandle: handle passed back from one of the open routines
683 * NDIS_STATUS_SUCCESS on success
684 * NDIS_STATUS_FAILURE on failure
685 * The network address is placed in the NetworkAddress buffer
688 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
689 PMINIPORT_RESOURCE MiniportResource
= NULL
;
690 PNDIS_CONFIGURATION_PARAMETER ParameterValue
= NULL
;
696 NdisInitUnicodeString(&Keyword
, L
"NetworkAddress");
697 NdisReadConfiguration(Status
, &ParameterValue
, ConfigurationHandle
, &Keyword
, NdisParameterString
);
698 if(*Status
!= NDIS_STATUS_SUCCESS
)
700 NDIS_DbgPrint(MID_TRACE
, ("NdisReadConfiguration failed (%x)\n", *Status
));
701 *Status
= NDIS_STATUS_FAILURE
;
705 if (ParameterValue
->ParameterType
== NdisParameterInteger
)
709 NDIS_DbgPrint(MAX_TRACE
, ("Read integer data %lx\n",
710 ParameterValue
->ParameterData
.IntegerData
));
713 str
.MaximumLength
= (USHORT
)sizeof(Buff
);
716 *Status
= RtlIntegerToUnicodeString(ParameterValue
->ParameterData
.IntegerData
,
720 if (*Status
!= NDIS_STATUS_SUCCESS
)
722 NDIS_DbgPrint(MIN_TRACE
, ("RtlIntegerToUnicodeString failed (%x)\n", *Status
));
723 *Status
= NDIS_STATUS_FAILURE
;
727 NDIS_DbgPrint(MAX_TRACE
, ("Converted integer data into %wZ\n", &str
));
731 ASSERT(ParameterValue
->ParameterType
== NdisParameterString
);
732 str
= ParameterValue
->ParameterData
.StringData
;
735 while (j
< str
.Length
&& str
.Buffer
[j
] != '\0') j
++;
737 *NetworkAddressLength
= (j
+1) >> 1;
739 if ((*NetworkAddressLength
) == 0)
741 NDIS_DbgPrint(MIN_TRACE
,("Empty NetworkAddress registry entry.\n"));
742 *Status
= NDIS_STATUS_FAILURE
;
746 IntArray
= ExAllocatePool(PagedPool
, (*NetworkAddressLength
)*sizeof(UINT
));
749 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
750 *Status
= NDIS_STATUS_RESOURCES
;
754 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
755 if(!MiniportResource
)
757 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
758 ExFreePool(IntArray
);
759 *Status
= NDIS_STATUS_RESOURCES
;
763 MiniportResource
->ResourceType
= MINIPORT_RESOURCE_TYPE_MEMORY
;
764 MiniportResource
->Resource
= IntArray
;
765 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
766 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
768 /* convert from string to bytes */
769 for(i
=0; i
<(*NetworkAddressLength
); i
++)
771 IntArray
[i
] = (UnicodeToHexByte((str
.Buffer
)[2*i
]) << 4) +
772 UnicodeToHexByte((str
.Buffer
)[2*i
+1]);
775 *NetworkAddress
= IntArray
;
777 *Status
= NDIS_STATUS_SUCCESS
;
786 NdisOpenConfigurationKeyByIndex(
787 OUT PNDIS_STATUS Status
,
788 IN NDIS_HANDLE ConfigurationHandle
,
790 OUT PNDIS_STRING KeyName
,
791 OUT PNDIS_HANDLE KeyHandle
)
793 * FUNCTION: Opens a configuration subkey by index number
795 * Status: pointer to an NDIS_STATUS to receive status info
796 * ConfigurationHandle: the handle passed back from a previous open function
797 * Index: the zero-based index of the subkey to open
798 * KeyName: the name of the key that was opened
799 * KeyHandle: a handle to the key that was opened
801 * NDIS_STATUS_SUCCESS on success
802 * NDIS_STATUS_FAILURE on failure
803 * KeyName holds the name of the opened key
804 * KeyHandle holds a handle to the new key
807 KEY_BASIC_INFORMATION
*KeyInformation
;
808 ULONG KeyInformationLength
;
809 OBJECT_ATTRIBUTES KeyAttributes
;
810 NDIS_HANDLE RegKeyHandle
;
811 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
815 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, NULL
, 0, &KeyInformationLength
);
816 if(*Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_SUCCESS
)
818 NDIS_DbgPrint(MIN_TRACE
, ("ZwEnumerateKey failed (%x)\n", *Status
));
819 *Status
= NDIS_STATUS_FAILURE
;
823 KeyInformation
= ExAllocatePool(PagedPool
, KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
));
826 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
827 *Status
= NDIS_STATUS_FAILURE
;
831 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, KeyInformation
,
832 KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
), &KeyInformationLength
);
834 if(*Status
!= STATUS_SUCCESS
)
836 NDIS_DbgPrint(MIN_TRACE
, ("ZwEnumerateKey failed (%x)\n", *Status
));
837 ExFreePool(KeyInformation
);
838 *Status
= NDIS_STATUS_FAILURE
;
842 /* should i fail instead if the passed-in string isn't long enough? */
843 wcsncpy(KeyName
->Buffer
, KeyInformation
->Name
, KeyName
->MaximumLength
/sizeof(WCHAR
));
844 KeyName
->Length
= (USHORT
)min(KeyInformation
->NameLength
, KeyName
->MaximumLength
);
846 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, NULL
);
848 *Status
= ZwOpenKey(&RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
850 ExFreePool(KeyInformation
);
852 if(*Status
!= STATUS_SUCCESS
)
854 NDIS_DbgPrint(MIN_TRACE
, ("ZwOpenKey failed (%x)\n", *Status
));
855 *Status
= NDIS_STATUS_FAILURE
;
859 ConfigurationContext
= ExAllocatePool(NonPagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
860 if(!ConfigurationContext
)
862 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
863 ZwClose(RegKeyHandle
);
864 *Status
= NDIS_STATUS_FAILURE
;
868 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
869 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
871 ConfigurationContext
->Handle
= RegKeyHandle
;
873 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
875 *Status
= NDIS_STATUS_SUCCESS
;
884 NdisOpenConfigurationKeyByName(
885 OUT PNDIS_STATUS Status
,
886 IN NDIS_HANDLE ConfigurationHandle
,
887 IN PNDIS_STRING KeyName
,
888 OUT PNDIS_HANDLE KeyHandle
)
890 * FUNCTION: Opens a configuration subkey by name
892 * Status: points to an NDIS_STATUS where status is returned
893 * ConfigurationHandle: handle returned by a previous open call
894 * KeyName: the name of the key to open
895 * KeyHandle: a handle to the opened key
897 * NDIS_STATUS_SUCCESS on success
898 * NDIS_STATUS_FAILURE on failure
899 * KeyHandle holds a handle to the newly-opened key
903 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
904 OBJECT_ATTRIBUTES KeyAttributes
;
905 NDIS_HANDLE RegKeyHandle
;
909 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, 0);
910 *Status
= ZwOpenKey(&RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
912 if(*Status
!= STATUS_SUCCESS
)
914 NDIS_DbgPrint(MIN_TRACE
, ("ZwOpenKey failed (%x)\n", *Status
));
915 *Status
= NDIS_STATUS_FAILURE
;
919 ConfigurationContext
= ExAllocatePool(NonPagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
920 if(!ConfigurationContext
)
922 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
923 ZwClose(RegKeyHandle
);
924 *Status
= NDIS_STATUS_FAILURE
;
928 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
929 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
931 ConfigurationContext
->Handle
= RegKeyHandle
;
933 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
935 *Status
= NDIS_STATUS_SUCCESS
;