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 NDIS_VERSION 0x00040000 /* the version of NDIS we claim to be to miniport drivers */
37 #define PARAMETERS_KEY L"Parameters" /* The parameters subkey under the device-specific key */
44 NdisWriteConfiguration(
45 OUT PNDIS_STATUS Status
,
46 IN NDIS_HANDLE ConfigurationHandle
,
47 IN PNDIS_STRING Keyword
,
48 IN PNDIS_CONFIGURATION_PARAMETER ParameterValue
)
50 * FUNCTION: Writes a configuration value to the registry
52 * Status: Pointer to a caller-supplied NDIS_STATUS where we return status
53 * ConfigurationHandle: The Configuration Handle passed back from the call to one of the Open functions
54 * Keyword: The registry value name to write
55 * ParameterValue: The value data to write
57 * NDIS_STATUS_SUCCESS - the operation completed successfully
58 * NDIS_STATUS_NOT_SUPPORTED - The parameter type is not supported
59 * NDIS_STATUS_RESOURCES - out of memory, etc.
60 * NDIS_STATUS_FAILURE - any other failure
62 * There's a cryptic comment in the ddk implying that this function allocates and keeps memory.
63 * I don't know why tho so i free everything before return. comments welcome.
66 ULONG ParameterType
= ParameterValue
->ParameterType
;
71 if(ParameterType
!= NdisParameterInteger
&&
72 ParameterType
!= NdisParameterHexInteger
&&
73 ParameterType
!= NdisParameterString
&&
74 ParameterType
!= NdisParameterMultiString
&&
75 ParameterType
!= NdisParameterBinary
78 *Status
= NDIS_STATUS_NOT_SUPPORTED
;
82 /* reset parameter type to standard reg types */
85 case NdisParameterHexInteger
:
86 case NdisParameterInteger
:
90 Str
.Buffer
= (PWSTR
) &Buff
;
91 Str
.MaximumLength
= (USHORT
)sizeof(Buff
);
94 ParameterType
= REG_SZ
;
95 if (!NT_SUCCESS(RtlIntegerToUnicodeString(
96 ParameterValue
->ParameterData
.IntegerData
,
97 (ParameterType
== NdisParameterInteger
) ? 10 : 16, &Str
)))
99 *Status
= NDIS_STATUS_FAILURE
;
103 DataSize
= Str
.Length
;
106 case NdisParameterString
:
107 case NdisParameterMultiString
:
108 ParameterType
= REG_SZ
;
109 Data
= ParameterValue
->ParameterData
.StringData
.Buffer
;
110 DataSize
= ParameterValue
->ParameterData
.StringData
.Length
;
113 /* New (undocumented) addition to 2k ddk */
114 case NdisParameterBinary
:
115 ParameterType
= REG_BINARY
;
116 Data
= ParameterValue
->ParameterData
.BinaryData
.Buffer
;
117 DataSize
= ParameterValue
->ParameterData
.BinaryData
.Length
;
121 *Status
= NDIS_STATUS_FAILURE
;
125 *Status
= ZwSetValueKey(((PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
)->Handle
,
126 Keyword
, 0, ParameterType
, Data
, DataSize
);
128 if(*Status
!= STATUS_SUCCESS
)
129 *Status
= NDIS_STATUS_FAILURE
;
131 *Status
= NDIS_STATUS_SUCCESS
;
140 NdisCloseConfiguration(
141 IN NDIS_HANDLE ConfigurationHandle
)
143 * FUNCTION: Closes handles and releases per-handle resources
145 * ConfigurationHandle - pointer to the context with the resources to free
148 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
149 PMINIPORT_RESOURCE Resource
;
151 while(!IsListEmpty(&ConfigurationContext
->ResourceListHead
))
153 Resource
= (PMINIPORT_RESOURCE
)RemoveTailList(&ConfigurationContext
->ResourceListHead
);
154 if(Resource
->ResourceType
== MINIPORT_RESOURCE_TYPE_MEMORY
)
156 NDIS_DbgPrint(MAX_TRACE
,("freeing 0x%x\n", Resource
->Resource
));
157 ExFreePool(Resource
->Resource
);
160 ExFreePool(Resource
);
163 ZwClose(ConfigurationContext
->Handle
);
172 NdisOpenConfiguration(
173 OUT PNDIS_STATUS Status
,
174 OUT PNDIS_HANDLE ConfigurationHandle
,
175 IN NDIS_HANDLE WrapperConfigurationContext
)
177 * FUNCTION: Opens the configuration key and sets up resource tracking for the returned handle
179 * Status: Pointer to a caller-supplied NDIS_STATUS that is filled in with a return value
180 * ConfigurationHandle: Pointer to an opaque configuration handle returned on success
181 * WrapperConfigurationContext: handle originally passed back from NdisInitializeWrapper
183 * NDIS_STATUS_SUCCESS: the operation completed successfully
184 * NDIS_STATUS_FAILURE: the operation failed
186 * I think this is the parameters key; please verify.
190 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
191 PNDIS_WRAPPER_CONTEXT WrapperContext
= (PNDIS_WRAPPER_CONTEXT
)WrapperConfigurationContext
;
192 HANDLE RootKeyHandle
= WrapperContext
->RegistryHandle
;
194 NDIS_DbgPrint(MAX_TRACE
, ("Called\n"));
196 *Status
= ZwDuplicateObject(NtCurrentProcess(), RootKeyHandle
,
197 NtCurrentProcess(), &KeyHandle
, 0, 0,
198 DUPLICATE_SAME_ACCESS
);
199 if(!NT_SUCCESS(*Status
))
201 NDIS_DbgPrint(MID_TRACE
, ("Failed to open registry configuration for this miniport\n"));
202 *ConfigurationHandle
= NULL
;
203 *Status
= NDIS_STATUS_FAILURE
;
207 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
208 if(!ConfigurationContext
)
210 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
212 *Status
= NDIS_STATUS_RESOURCES
;
216 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
217 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
219 ConfigurationContext
->Handle
= KeyHandle
;
221 *ConfigurationHandle
= (NDIS_HANDLE
)ConfigurationContext
;
222 *Status
= NDIS_STATUS_SUCCESS
;
224 NDIS_DbgPrint(MAX_TRACE
,("returning success\n"));
233 NdisOpenProtocolConfiguration(
234 OUT PNDIS_STATUS Status
,
235 OUT PNDIS_HANDLE ConfigurationHandle
,
236 IN PNDIS_STRING ProtocolSection
)
238 * FUNCTION: Open the configuration key and set up resource tracking for the protocol
240 * Status: caller-allocated buffer where status is returned
241 * ConfigurationHandle: spot to return the opaque configuration context
242 * ProtocolSection: configuration string originally passed in to ProtocolBindAdapter
244 * NDIS_STATUS_SUCCESS: the operation was a success
245 * NDIS_STATUS_FAILURE: the operation was not a success
247 * I think this is the per-device (adapter) parameters\{ProtocolName} key; please verify.
250 OBJECT_ATTRIBUTES KeyAttributes
;
251 UNICODE_STRING KeyNameU
;
253 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
256 KeyNameU
.MaximumLength
= ProtocolSection
->Length
+ sizeof(PARAMETERS_KEY
) + sizeof(UNICODE_NULL
);
257 KeyNameU
.Buffer
= ExAllocatePool(PagedPool
, KeyNameU
.MaximumLength
);
260 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
261 *ConfigurationHandle
= NULL
;
262 *Status
= NDIS_STATUS_FAILURE
;
266 RtlCopyUnicodeString(&KeyNameU
, ProtocolSection
);
267 RtlAppendUnicodeToString(&KeyNameU
, PARAMETERS_KEY
);
268 InitializeObjectAttributes(&KeyAttributes
, &KeyNameU
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
270 *Status
= ZwOpenKey(&KeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
272 ExFreePool(KeyNameU
.Buffer
);
274 if(*Status
!= NDIS_STATUS_SUCCESS
)
276 *ConfigurationHandle
= NULL
;
277 *Status
= NDIS_STATUS_FAILURE
;
281 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
282 if(!ConfigurationContext
)
284 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
285 *ConfigurationHandle
= NULL
;
286 *Status
= NDIS_STATUS_FAILURE
;
290 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
291 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
293 ConfigurationContext
->Handle
= KeyHandle
;
295 *ConfigurationHandle
= (NDIS_HANDLE
)ConfigurationContext
;
296 *Status
= NDIS_STATUS_SUCCESS
;
305 NdisReadConfiguration(
306 OUT PNDIS_STATUS Status
,
307 OUT PNDIS_CONFIGURATION_PARAMETER
* ParameterValue
,
308 IN NDIS_HANDLE ConfigurationHandle
,
309 IN PNDIS_STRING Keyword
,
310 IN NDIS_PARAMETER_TYPE ParameterType
)
312 * FUNCTION: Read a configuration value from the registry, tracking its resources
314 * Status: points to a place to write status into
315 * ParameterValue: Pointer to receive a newly-allocated parameter structure
316 * ConfigurationHandle: handle originally returned by an open function
317 * Keyword: Value name to read, or one of the following constants:
318 * Environment - returns NdisEnvironmentWindowsNt
319 * ProcessorType - returns NdisProcessorX86 until more architectures are added
320 * NdisVersion - returns NDIS_VERSION
321 * ParameterType: the type of the value to be queried
323 * - A status in Status
324 * - A parameter value in ParameterValue
327 KEY_VALUE_PARTIAL_INFORMATION
*KeyInformation
;
329 PMINIPORT_RESOURCE MiniportResource
;
330 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
332 *ParameterValue
= NULL
;
333 *Status
= NDIS_STATUS_FAILURE
;
335 if(ParameterType
!= NdisParameterInteger
&&
336 ParameterType
!= NdisParameterHexInteger
&&
337 ParameterType
!= NdisParameterString
&&
338 ParameterType
!= NdisParameterMultiString
&&
339 ParameterType
!= NdisParameterBinary
342 NDIS_DbgPrint(MID_TRACE
,("unsupported parameter type\n"));
346 NDIS_DbgPrint(MAX_TRACE
,("requested read of %wZ\n", Keyword
));
349 !wcsncmp(Keyword
->Buffer
, L
"Environment", Keyword
->Length
/sizeof(WCHAR
)) &&
350 wcslen(L
"Environment") == Keyword
->Length
/sizeof(WCHAR
)
353 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
356 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
357 *Status
= NDIS_STATUS_RESOURCES
;
361 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
362 if(!MiniportResource
)
364 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
365 ExFreePool(*ParameterValue
);
366 *ParameterValue
= NULL
;
367 *Status
= NDIS_STATUS_RESOURCES
;
371 MiniportResource
->ResourceType
= 0;
372 MiniportResource
->Resource
= *ParameterValue
;
374 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n",
375 MiniportResource
->Resource
));
377 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
378 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
380 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
381 (*ParameterValue
)->ParameterData
.IntegerData
= NdisEnvironmentWindowsNt
;
382 *Status
= NDIS_STATUS_SUCCESS
;
388 !wcsncmp(Keyword
->Buffer
, L
"ProcessorType", Keyword
->Length
/sizeof(WCHAR
)) &&
389 wcslen(L
"ProcessorType") == Keyword
->Length
/sizeof(WCHAR
)
392 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
395 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
396 *Status
= NDIS_STATUS_RESOURCES
;
400 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
401 if(!MiniportResource
)
403 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
404 ExFreePool(*ParameterValue
);
405 *ParameterValue
= NULL
;
406 *Status
= NDIS_STATUS_RESOURCES
;
410 MiniportResource
->ResourceType
= 0;
411 MiniportResource
->Resource
= *ParameterValue
;
412 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
413 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
414 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
416 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
417 (*ParameterValue
)->ParameterData
.IntegerData
= NdisProcessorX86
; /* XXX non-portable */
418 *Status
= NDIS_STATUS_SUCCESS
;
424 !wcsncmp(Keyword
->Buffer
, L
"NdisVersion", Keyword
->Length
/sizeof(WCHAR
)) &&
425 wcslen(L
"NdisVersion") == Keyword
->Length
/sizeof(WCHAR
)
428 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
431 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
432 *Status
= NDIS_STATUS_RESOURCES
;
436 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
437 if(!MiniportResource
)
439 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
440 ExFreePool(*ParameterValue
);
441 *ParameterValue
= NULL
;
442 *Status
= NDIS_STATUS_RESOURCES
;
446 MiniportResource
->ResourceType
= 0;
447 MiniportResource
->Resource
= *ParameterValue
;
448 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
449 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
450 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
452 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
453 (*ParameterValue
)->ParameterData
.IntegerData
= NDIS_VERSION
;
454 *Status
= NDIS_STATUS_SUCCESS
;
456 NDIS_DbgPrint(MAX_TRACE
,("ParameterType = %0x%x, ParameterValue = 0x%x\n",
457 (*ParameterValue
)->ParameterType
, (*ParameterValue
)->ParameterData
.IntegerData
));
461 /* figure out how much buffer i should allocate */
462 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
, NULL
, 0, &KeyDataLength
);
463 if(*Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_SUCCESS
)
465 NDIS_DbgPrint(MID_TRACE
,("ZwQueryValueKey #1 failed for %wZ, status 0x%x\n", Keyword
, *Status
));
466 *Status
= NDIS_STATUS_FAILURE
;
471 KeyInformation
= ExAllocatePool(PagedPool
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
));
474 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
475 *Status
= NDIS_STATUS_RESOURCES
;
480 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
,
481 KeyInformation
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
), &KeyDataLength
);
482 if(*Status
!= STATUS_SUCCESS
)
484 ExFreePool(KeyInformation
);
485 NDIS_DbgPrint(MID_TRACE
,("ZwQueryValueKey #2 failed for %wZ, status 0x%x\n", Keyword
, *Status
));
486 *Status
= NDIS_STATUS_FAILURE
;
490 switch(ParameterType
)
492 case NdisParameterInteger
:
493 case NdisParameterHexInteger
:
497 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
500 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
501 ExFreePool(KeyInformation
);
502 *Status
= NDIS_STATUS_RESOURCES
;
506 str
.Length
= str
.MaximumLength
= (USHORT
)KeyInformation
->DataLength
;
507 str
.Buffer
= (PWCHAR
)KeyInformation
->Data
;
509 (*ParameterValue
)->ParameterType
= ParameterType
;
512 If ParameterType is NdisParameterInteger then the base of str is decimal.
513 If ParameterType is NdisParameterHexInteger then the base of str is hexadecimal.
515 if (ParameterType
== NdisParameterInteger
)
516 *Status
= RtlUnicodeStringToInteger(&str
, 10, &(*ParameterValue
)->ParameterData
.IntegerData
);
517 else if (ParameterType
== NdisParameterHexInteger
)
518 *Status
= RtlUnicodeStringToInteger(&str
, 16, &(*ParameterValue
)->ParameterData
.IntegerData
);
521 ExFreePool(KeyInformation
);
523 if(*Status
!= STATUS_SUCCESS
)
524 *Status
= NDIS_STATUS_FAILURE
;
526 *Status
= NDIS_STATUS_SUCCESS
;
531 case NdisParameterString
:
532 case NdisParameterMultiString
:
536 if(KeyInformation
->Type
!= REG_SZ
&& KeyInformation
->Type
!= REG_MULTI_SZ
)
538 NDIS_DbgPrint(MID_TRACE
,("requested type does not match actual value type\n"));
539 ExFreePool(KeyInformation
);
540 *ParameterValue
= NULL
;
541 *Status
= NDIS_STATUS_FAILURE
;
545 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
548 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
549 ExFreePool(KeyInformation
);
550 *Status
= NDIS_STATUS_RESOURCES
;
554 RegData
= ExAllocatePool(PagedPool
, KeyInformation
->DataLength
);
557 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
558 ExFreePool(KeyInformation
);
559 ExFreePool(*ParameterValue
);
560 *ParameterValue
= NULL
;
561 *Status
= NDIS_STATUS_FAILURE
;
565 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
566 if(!MiniportResource
)
568 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
569 ExFreePool(KeyInformation
);
570 ExFreePool(*ParameterValue
);
571 *ParameterValue
= NULL
;
572 *Status
= NDIS_STATUS_RESOURCES
;
576 MiniportResource
->ResourceType
= 0;
577 MiniportResource
->Resource
= *ParameterValue
;
578 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
579 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
581 memcpy(RegData
, KeyInformation
->Data
, KeyInformation
->DataLength
);
583 (*ParameterValue
)->ParameterType
= ParameterType
;
584 (*ParameterValue
)->ParameterData
.StringData
.Length
= (USHORT
)KeyInformation
->DataLength
;
585 (*ParameterValue
)->ParameterData
.StringData
.Buffer
= RegData
;
587 ExFreePool(KeyInformation
);
589 *Status
= NDIS_STATUS_SUCCESS
;
594 case NdisParameterBinary
:
596 if(KeyInformation
->Type
!= REG_BINARY
)
598 NDIS_DbgPrint(MIN_TRACE
,("requested type does not match actual value type\n"));
599 *Status
= NDIS_STATUS_FAILURE
;
600 ExFreePool(KeyInformation
);
604 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
) + KeyInformation
->DataLength
);
607 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
608 ExFreePool(KeyInformation
);
609 *Status
= NDIS_STATUS_RESOURCES
;
613 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
614 if(!MiniportResource
)
616 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
617 ExFreePool(KeyInformation
);
618 ExFreePool(*ParameterValue
);
619 *ParameterValue
= NULL
;
620 *Status
= NDIS_STATUS_RESOURCES
;
624 MiniportResource
->ResourceType
= 0;
625 MiniportResource
->Resource
= *ParameterValue
;
626 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
627 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
629 (*ParameterValue
)->ParameterType
= ParameterType
;
630 memcpy(&((*ParameterValue
)->ParameterData
.BinaryData
), KeyInformation
->Data
, KeyInformation
->DataLength
);
632 ExFreePool(KeyInformation
);
634 *Status
= NDIS_STATUS_SUCCESS
;
642 UCHAR
UnicodeToHexByte(WCHAR chr
)
644 * FUNCTION: Converts a unicode hex character to its numerical value
646 * chr: Unicode character to convert
648 * The numerical value of chr
691 NdisReadNetworkAddress(
692 OUT PNDIS_STATUS Status
,
693 OUT PVOID
* NetworkAddress
,
694 OUT PUINT NetworkAddressLength
,
695 IN NDIS_HANDLE ConfigurationHandle
)
697 * FUNCTION: Reads the network address from the registry
699 * Status - variable to receive status
700 * NetworkAddress - pointer to a buffered network address array
701 * NetworkAddressLength - length of the NetworkAddress array
702 * ConfigurationHandle: handle passed back from one of the open routines
704 * NDIS_STATUS_SUCCESS on success
705 * NDIS_STATUS_FAILURE on failure
706 * The network address is placed in the NetworkAddress buffer
709 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
710 PMINIPORT_RESOURCE MiniportResource
= NULL
;
711 PNDIS_CONFIGURATION_PARAMETER ParameterValue
= NULL
;
716 /* FIXME - We don't quite support this yet due to buggy code below */
718 *Status
= NDIS_STATUS_FAILURE
;
722 *NetworkAddress
= NULL
;
723 *NetworkAddressLength
= 6;/* XXX magic constant */
725 NdisInitUnicodeString(&Keyword
, L
"NetworkAddress");
726 NdisReadConfiguration(Status
, &ParameterValue
, ConfigurationHandle
, &Keyword
, NdisParameterString
);
727 if(*Status
!= NDIS_STATUS_SUCCESS
)
729 *Status
= NDIS_STATUS_FAILURE
;
733 /* 6 bytes for ethernet, tokenring, fddi, everything else? */
734 IntArray
= ExAllocatePool(PagedPool
, 6*sizeof(UINT
));
737 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
738 *Status
= NDIS_STATUS_RESOURCES
;
742 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
743 if(!MiniportResource
)
745 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
746 *Status
= NDIS_STATUS_FAILURE
;
750 MiniportResource
->ResourceType
= 0;
751 MiniportResource
->Resource
= IntArray
;
752 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
753 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
755 /* convert from string to bytes */
758 IntArray
[i
] = (UnicodeToHexByte((ParameterValue
->ParameterData
.StringData
.Buffer
)[2*i
]) << 4) +
759 UnicodeToHexByte((ParameterValue
->ParameterData
.StringData
.Buffer
)[2*i
+1]);
762 *NetworkAddress
= IntArray
;
764 *Status
= NDIS_STATUS_SUCCESS
;
773 NdisOpenConfigurationKeyByIndex(
774 OUT PNDIS_STATUS Status
,
775 IN NDIS_HANDLE ConfigurationHandle
,
777 OUT PNDIS_STRING KeyName
,
778 OUT PNDIS_HANDLE KeyHandle
)
780 * FUNCTION: Opens a configuration subkey by index number
782 * Status: pointer to an NDIS_STATUS to receive status info
783 * ConfigurationHandle: the handle passed back from a previous open function
784 * Index: the zero-based index of the subkey to open
785 * KeyName: the name of the key that was opened
786 * KeyHandle: a handle to the key that was opened
788 * NDIS_STATUS_SUCCESS on success
789 * NDIS_STATUS_FAILURE on failure
790 * KeyName holds the name of the opened key
791 * KeyHandle holds a handle to the new key
794 KEY_BASIC_INFORMATION
*KeyInformation
;
795 ULONG KeyInformationLength
;
796 OBJECT_ATTRIBUTES KeyAttributes
;
797 NDIS_HANDLE RegKeyHandle
;
798 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
800 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, NULL
, 0, &KeyInformationLength
);
801 if(*Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_SUCCESS
)
803 *Status
= NDIS_STATUS_FAILURE
;
807 KeyInformation
= ExAllocatePool(PagedPool
, KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
));
810 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
811 *Status
= NDIS_STATUS_FAILURE
;
815 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, KeyInformation
,
816 KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
), &KeyInformationLength
);
818 if(*Status
!= STATUS_SUCCESS
)
820 ExFreePool(KeyInformation
);
821 *Status
= NDIS_STATUS_FAILURE
;
825 /* should i fail instead if the passed-in string isn't long enough? */
826 wcsncpy(KeyName
->Buffer
, KeyInformation
->Name
, KeyName
->MaximumLength
/sizeof(WCHAR
));
827 KeyName
->Length
= (USHORT
)KeyInformation
->NameLength
;
829 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, NULL
);
831 *Status
= ZwOpenKey(&RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
833 ExFreePool(KeyInformation
);
835 if(*Status
!= STATUS_SUCCESS
)
837 *Status
= NDIS_STATUS_FAILURE
;
841 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
842 if(!ConfigurationContext
)
844 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
845 *Status
= NDIS_STATUS_FAILURE
;
849 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
850 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
852 ConfigurationContext
->Handle
= RegKeyHandle
;
854 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
856 *Status
= NDIS_STATUS_SUCCESS
;
865 NdisOpenConfigurationKeyByName(
866 OUT PNDIS_STATUS Status
,
867 IN NDIS_HANDLE ConfigurationHandle
,
868 IN PNDIS_STRING KeyName
,
869 OUT PNDIS_HANDLE KeyHandle
)
871 * FUNCTION: Opens a configuration subkey by name
873 * Status: points to an NDIS_STATUS where status is returned
874 * ConfigurationHandle: handle returned by a previous open call
875 * KeyName: the name of the key to open
876 * KeyHandle: a handle to the opened key
878 * NDIS_STATUS_SUCCESS on success
879 * NDIS_STATUS_FAILURE on failure
880 * KeyHandle holds a handle to the newly-opened key
884 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
885 OBJECT_ATTRIBUTES KeyAttributes
;
886 NDIS_HANDLE RegKeyHandle
;
888 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, 0);
889 *Status
= ZwOpenKey(&RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
891 if(*Status
!= STATUS_SUCCESS
)
893 *Status
= NDIS_STATUS_FAILURE
;
897 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
898 if(!ConfigurationContext
)
900 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
901 *Status
= NDIS_STATUS_FAILURE
;
905 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
906 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
908 ConfigurationContext
->Handle
= RegKeyHandle
;
910 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
912 *Status
= NDIS_STATUS_SUCCESS
;