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
37 #define NDIS_VERSION 0x00040000 /* the version of NDIS we claim to be to miniport drivers */
38 #define PARAMETERS_KEY L"Parameters" /* The parameters subkey under the device-specific key */
45 NdisWriteConfiguration(
46 OUT PNDIS_STATUS Status
,
47 IN NDIS_HANDLE ConfigurationHandle
,
48 IN PNDIS_STRING Keyword
,
49 IN PNDIS_CONFIGURATION_PARAMETER ParameterValue
)
51 * FUNCTION: Writes a configuration value to the registry
53 * Status: Pointer to a caller-supplied NDIS_STATUS where we return status
54 * ConfigurationHandle: The Configuration Handle passed back from the call to one of the Open functions
55 * Keyword: The registry value name to write
56 * ParameterValue: The value data to write
58 * NDIS_STATUS_SUCCESS - the operation completed successfully
59 * NDIS_STATUS_NOT_SUPPORTED - The parameter type is not supported
60 * NDIS_STATUS_RESOURCES - out of memory, etc.
61 * NDIS_STATUS_FAILURE - any other failure
63 * There's a cryptic comment in the ddk implying that this function allocates and keeps memory.
64 * I don't know why tho so i free everything before return. comments welcome.
67 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 /* TODO: figure out what do do with these; are they different? */
86 case NdisParameterHexInteger
:
87 case NdisParameterInteger
:
88 ParameterType
= REG_SZ
;
89 Data
= &ParameterValue
->ParameterData
.IntegerData
;
90 DataSize
= sizeof(ULONG
);
93 case NdisParameterString
:
94 case NdisParameterMultiString
:
95 ParameterType
= REG_SZ
;
96 Data
= ParameterValue
->ParameterData
.StringData
.Buffer
;
97 DataSize
= ParameterValue
->ParameterData
.StringData
.Length
;
100 /* New (undocumented) addition to 2k ddk */
101 case NdisParameterBinary
:
102 ParameterType
= REG_BINARY
;
103 Data
= ParameterValue
->ParameterData
.BinaryData
.Buffer
;
104 DataSize
= ParameterValue
->ParameterData
.BinaryData
.Length
;
108 *Status
= ZwSetValueKey(((PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
)->Handle
,
109 Keyword
, 0, ParameterType
, Data
, DataSize
);
111 if(*Status
!= STATUS_SUCCESS
)
112 *Status
= NDIS_STATUS_FAILURE
;
114 *Status
= NDIS_STATUS_SUCCESS
;
123 NdisCloseConfiguration(
124 IN NDIS_HANDLE ConfigurationHandle
)
126 * FUNCTION: Closes handles and releases per-handle resources
128 * ConfigurationHandle - pointer to the context with the resources to free
131 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
132 PMINIPORT_RESOURCE Resource
;
134 while(!IsListEmpty(&ConfigurationContext
->ResourceListHead
))
136 Resource
= (PMINIPORT_RESOURCE
)RemoveTailList(&ConfigurationContext
->ResourceListHead
);
137 if(Resource
->ResourceType
== MINIPORT_RESOURCE_TYPE_MEMORY
)
139 NDIS_DbgPrint(MAX_TRACE
,("freeing 0x%x\n", Resource
->Resource
));
140 ExFreePool(Resource
->Resource
);
143 ExFreePool(Resource
);
146 ZwClose(ConfigurationContext
->Handle
);
155 NdisOpenConfiguration(
156 OUT PNDIS_STATUS Status
,
157 OUT PNDIS_HANDLE ConfigurationHandle
,
158 IN NDIS_HANDLE WrapperConfigurationContext
)
160 * FUNCTION: Opens the configuration key and sets up resource tracking for the returned handle
162 * Status: Pointer to a caller-supplied NDIS_STATUS that is filled in with a return value
163 * ConfigurationHandle: Pointer to an opaque configuration handle returned on success
164 * WrapperConfigurationContext: handle originally passed back from NdisInitializeWrapper
166 * NDIS_STATUS_SUCCESS: the operation completed successfully
167 * NDIS_STATUS_FAILURE: the operation failed
169 * I think this is the parameters key; please verify.
173 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
174 PNDIS_WRAPPER_CONTEXT WrapperContext
= (PNDIS_WRAPPER_CONTEXT
)WrapperConfigurationContext
;
175 HANDLE RootKeyHandle
= WrapperContext
->RegistryHandle
;
177 NDIS_DbgPrint(MAX_TRACE
, ("Called\n"));
179 *Status
= ZwDuplicateObject(NtCurrentProcess(), RootKeyHandle
,
180 NtCurrentProcess(), &KeyHandle
, 0, FALSE
,
181 DUPLICATE_SAME_ACCESS
);
182 if(!NT_SUCCESS(*Status
))
184 NDIS_DbgPrint(MID_TRACE
, ("Failed to open registry configuration for this miniport\n"));
185 *ConfigurationHandle
= NULL
;
186 *Status
= NDIS_STATUS_FAILURE
;
190 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
191 if(!ConfigurationContext
)
193 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
195 *Status
= NDIS_STATUS_RESOURCES
;
199 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
200 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
202 ConfigurationContext
->Handle
= KeyHandle
;
204 *ConfigurationHandle
= (NDIS_HANDLE
)ConfigurationContext
;
205 *Status
= NDIS_STATUS_SUCCESS
;
207 NDIS_DbgPrint(MAX_TRACE
,("returning success\n"));
216 NdisOpenProtocolConfiguration(
217 OUT PNDIS_STATUS Status
,
218 OUT PNDIS_HANDLE ConfigurationHandle
,
219 IN PNDIS_STRING ProtocolSection
)
221 * FUNCTION: Open the configuration key and set up resource tracking for the protocol
223 * Status: caller-allocated buffer where status is returned
224 * ConfigurationHandle: spot to return the opaque configuration context
225 * ProtocolSection: configuration string originally passed in to ProtocolBindAdapter
227 * NDIS_STATUS_SUCCESS: the operation was a success
228 * NDIS_STATUS_FAILURE: the operation was not a success
230 * I think this is the per-device (adapter) parameters\{ProtocolName} key; please verify.
233 OBJECT_ATTRIBUTES KeyAttributes
;
234 UNICODE_STRING KeyNameU
;
237 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
239 KeyName
= ExAllocatePool(PagedPool
, ProtocolSection
->Length
+ sizeof(PARAMETERS_KEY
) + sizeof(WCHAR
));
242 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
243 *ConfigurationHandle
= NULL
;
244 *Status
= NDIS_STATUS_FAILURE
;
248 wcsncpy(KeyName
, ProtocolSection
->Buffer
, ProtocolSection
->Length
/sizeof(WCHAR
));
249 wcscpy(KeyName
+ ProtocolSection
->Length
, PARAMETERS_KEY
);
250 RtlInitUnicodeString(&KeyNameU
, KeyName
);
251 InitializeObjectAttributes(&KeyAttributes
, &KeyNameU
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
253 *Status
= ZwOpenKey(&KeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
257 if(*Status
!= NDIS_STATUS_SUCCESS
)
259 *ConfigurationHandle
= NULL
;
260 *Status
= NDIS_STATUS_FAILURE
;
264 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
265 if(!ConfigurationContext
)
267 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
268 *ConfigurationHandle
= NULL
;
269 *Status
= NDIS_STATUS_FAILURE
;
273 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
274 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
276 ConfigurationContext
->Handle
= KeyHandle
;
278 *ConfigurationHandle
= (NDIS_HANDLE
)ConfigurationContext
;
279 *Status
= NDIS_STATUS_SUCCESS
;
288 NdisReadConfiguration(
289 OUT PNDIS_STATUS Status
,
290 OUT PNDIS_CONFIGURATION_PARAMETER
* ParameterValue
,
291 IN NDIS_HANDLE ConfigurationHandle
,
292 IN PNDIS_STRING Keyword
,
293 IN NDIS_PARAMETER_TYPE ParameterType
)
295 * FUNCTION: Read a configuration value from the registry, tracking its resources
297 * Status: points to a place to write status into
298 * ParameterValue: Pointer to receive a newly-allocated parameter structure
299 * ConfigurationHandle: handle originally returned by an open function
300 * Keyword: Value name to read, or one of the following constants:
301 * Environment - returns NdisEnvironmentWindowsNt
302 * ProcessorType - returns NdisProcessorX86 until more architectures are added
303 * NdisVersion - returns NDIS_VERSION
304 * ParameterType: the type of the value to be queried
306 * - A status in Status
307 * - A parameter value in ParameterValue
310 KEY_VALUE_PARTIAL_INFORMATION
*KeyInformation
;
312 PMINIPORT_RESOURCE MiniportResource
;
313 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
315 *ParameterValue
= NULL
;
316 *Status
= NDIS_STATUS_FAILURE
;
318 if(ParameterType
!= NdisParameterInteger
&&
319 ParameterType
!= NdisParameterHexInteger
&&
320 ParameterType
!= NdisParameterString
&&
321 ParameterType
!= NdisParameterMultiString
&&
322 ParameterType
!= NdisParameterBinary
325 NDIS_DbgPrint(MID_TRACE
,("unsupported parameter type\n"));
329 NDIS_DbgPrint(MAX_TRACE
,("requested read of %wZ\n", Keyword
));
332 !wcsncmp(Keyword
->Buffer
, L
"Environment", Keyword
->Length
/sizeof(WCHAR
)) &&
333 wcslen(L
"Environment") == Keyword
->Length
/sizeof(WCHAR
)
336 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
339 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
340 *Status
= NDIS_STATUS_RESOURCES
;
344 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
345 if(!MiniportResource
)
347 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
348 ExFreePool(*ParameterValue
);
349 *ParameterValue
= NULL
;
350 *Status
= NDIS_STATUS_RESOURCES
;
354 MiniportResource
->ResourceType
= 0;
355 MiniportResource
->Resource
= *ParameterValue
;
357 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n",
358 MiniportResource
->Resource
));
360 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
361 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
363 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
364 (*ParameterValue
)->ParameterData
.IntegerData
= NdisEnvironmentWindowsNt
;
365 *Status
= NDIS_STATUS_SUCCESS
;
371 !wcsncmp(Keyword
->Buffer
, L
"ProcessorType", Keyword
->Length
/sizeof(WCHAR
)) &&
372 wcslen(L
"ProcessorType") == Keyword
->Length
/sizeof(WCHAR
)
375 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
378 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
379 *Status
= NDIS_STATUS_RESOURCES
;
383 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
384 if(!MiniportResource
)
386 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
387 ExFreePool(*ParameterValue
);
388 *ParameterValue
= NULL
;
389 *Status
= NDIS_STATUS_RESOURCES
;
393 MiniportResource
->ResourceType
= 0;
394 MiniportResource
->Resource
= *ParameterValue
;
395 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
396 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
397 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
399 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
400 (*ParameterValue
)->ParameterData
.IntegerData
= NdisProcessorX86
; /* XXX non-portable */
401 *Status
= NDIS_STATUS_SUCCESS
;
407 !wcsncmp(Keyword
->Buffer
, L
"NdisVersion", Keyword
->Length
/sizeof(WCHAR
)) &&
408 wcslen(L
"NdisVersion") == Keyword
->Length
/sizeof(WCHAR
)
411 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
414 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
415 *Status
= NDIS_STATUS_RESOURCES
;
419 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
420 if(!MiniportResource
)
422 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
423 ExFreePool(*ParameterValue
);
424 *ParameterValue
= NULL
;
425 *Status
= NDIS_STATUS_RESOURCES
;
429 MiniportResource
->ResourceType
= 0;
430 MiniportResource
->Resource
= *ParameterValue
;
431 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
432 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
433 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
435 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
436 (*ParameterValue
)->ParameterData
.IntegerData
= NDIS_VERSION
;
437 *Status
= NDIS_STATUS_SUCCESS
;
439 NDIS_DbgPrint(MAX_TRACE
,("ParameterType = %0x%x, ParameterValue = 0x%x\n",
440 (*ParameterValue
)->ParameterType
, (*ParameterValue
)->ParameterData
.IntegerData
));
444 /* figure out how much buffer i should allocate */
445 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
, NULL
, 0, &KeyDataLength
);
446 if(*Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_SUCCESS
)
448 NDIS_DbgPrint(MID_TRACE
,("ZwQueryValueKey #1 failed for %wZ, status 0x%x\n", Keyword
, *Status
));
449 *Status
= NDIS_STATUS_FAILURE
;
454 KeyInformation
= ExAllocatePool(PagedPool
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
));
457 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
458 *Status
= NDIS_STATUS_RESOURCES
;
463 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
,
464 KeyInformation
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
), &KeyDataLength
);
465 if(*Status
!= STATUS_SUCCESS
)
467 ExFreePool(KeyInformation
);
468 NDIS_DbgPrint(MID_TRACE
,("ZwQueryValueKey #2 failed for %wZ, status 0x%x\n", Keyword
, *Status
));
469 *Status
= NDIS_STATUS_FAILURE
;
473 switch(ParameterType
)
475 case NdisParameterInteger
:
476 case NdisParameterHexInteger
:
480 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
483 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
484 ExFreePool(KeyInformation
);
485 *Status
= NDIS_STATUS_RESOURCES
;
489 str
.Length
= str
.MaximumLength
= KeyInformation
->DataLength
;
490 str
.Buffer
= (PWCHAR
)KeyInformation
->Data
;
492 (*ParameterValue
)->ParameterType
= ParameterType
;
493 *Status
= RtlUnicodeStringToInteger(&str
, 16, &(*ParameterValue
)->ParameterData
.IntegerData
);
495 ExFreePool(KeyInformation
);
497 if(*Status
!= STATUS_SUCCESS
)
498 *Status
= NDIS_STATUS_FAILURE
;
500 *Status
= NDIS_STATUS_SUCCESS
;
505 case NdisParameterString
:
506 case NdisParameterMultiString
:
508 PMINIPORT_RESOURCE MiniportResource
= 0;
511 if(KeyInformation
->Type
!= REG_SZ
&& KeyInformation
->Type
!= REG_MULTI_SZ
)
513 NDIS_DbgPrint(MID_TRACE
,("requested type does not match actual value type\n"));
514 ExFreePool(KeyInformation
);
515 *ParameterValue
= NULL
;
516 *Status
= NDIS_STATUS_FAILURE
;
520 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
523 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
524 ExFreePool(KeyInformation
);
525 *Status
= NDIS_STATUS_RESOURCES
;
529 RegData
= ExAllocatePool(PagedPool
, KeyInformation
->DataLength
);
532 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
533 ExFreePool(KeyInformation
);
534 ExFreePool(*ParameterValue
);
535 *ParameterValue
= NULL
;
536 *Status
= NDIS_STATUS_FAILURE
;
540 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
541 if(!MiniportResource
)
543 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
544 ExFreePool(KeyInformation
);
545 ExFreePool(*ParameterValue
);
546 *ParameterValue
= NULL
;
547 *Status
= NDIS_STATUS_RESOURCES
;
551 MiniportResource
->ResourceType
= 0;
552 MiniportResource
->Resource
= *ParameterValue
;
553 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
554 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
556 memcpy(RegData
, KeyInformation
->Data
, KeyInformation
->DataLength
);
558 (*ParameterValue
)->ParameterType
= ParameterType
;
559 (*ParameterValue
)->ParameterData
.StringData
.Length
= KeyInformation
->DataLength
;
560 (*ParameterValue
)->ParameterData
.StringData
.Buffer
= RegData
;
562 ExFreePool(KeyInformation
);
564 *Status
= NDIS_STATUS_SUCCESS
;
569 case NdisParameterBinary
:
571 PMINIPORT_RESOURCE MiniportResource
;
573 if(KeyInformation
->Type
!= REG_BINARY
)
575 NDIS_DbgPrint(MIN_TRACE
,("requested type does not match actual value type\n"));
576 *Status
= NDIS_STATUS_FAILURE
;
577 ExFreePool(KeyInformation
);
581 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
) + KeyInformation
->DataLength
);
584 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
585 ExFreePool(KeyInformation
);
586 *Status
= NDIS_STATUS_RESOURCES
;
590 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
591 if(!MiniportResource
)
593 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
594 ExFreePool(KeyInformation
);
595 ExFreePool(*ParameterValue
);
596 *ParameterValue
= NULL
;
597 *Status
= NDIS_STATUS_RESOURCES
;
601 MiniportResource
->ResourceType
= 0;
602 MiniportResource
->Resource
= *ParameterValue
;
603 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
604 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
606 (*ParameterValue
)->ParameterType
= ParameterType
;
607 memcpy(&((*ParameterValue
)->ParameterData
.BinaryData
), KeyInformation
->Data
, KeyInformation
->DataLength
);
609 ExFreePool(KeyInformation
);
611 *Status
= NDIS_STATUS_SUCCESS
;
619 UCHAR
UnicodeToHexByte(WCHAR chr
)
621 * FUNCTION: Converts a unicode hex character to its numerical value
623 * chr: Unicode character to convert
625 * The numerical value of chr
668 NdisReadNetworkAddress(
669 OUT PNDIS_STATUS Status
,
670 OUT PVOID
* NetworkAddress
,
671 OUT PUINT NetworkAddressLength
,
672 IN NDIS_HANDLE ConfigurationHandle
)
674 * FUNCTION: Reads the network address from the registry
676 * Status - variable to receive status
677 * NetworkAddress - pointer to a buffered network address array
678 * NetworkAddressLength - length of the NetworkAddress array
679 * ConfigurationHandle: handle passed back from one of the open routines
681 * NDIS_STATUS_SUCCESS on success
682 * NDIS_STATUS_FAILURE on failure
683 * The network address is placed in the NetworkAddress buffer
686 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
687 PMINIPORT_RESOURCE MiniportResource
= NULL
;
688 PNDIS_CONFIGURATION_PARAMETER ParameterValue
= NULL
;
693 /* FIXME - We don't quite support this yet due to buggy code below */
695 *Status
= NDIS_STATUS_FAILURE
;
699 *NetworkAddress
= NULL
;
700 *NetworkAddressLength
= 6;/* XXX magic constant */
702 NdisInitUnicodeString(&Keyword
, L
"NetworkAddress");
703 NdisReadConfiguration(Status
, &ParameterValue
, ConfigurationHandle
, &Keyword
, NdisParameterString
);
704 if(*Status
!= NDIS_STATUS_SUCCESS
)
706 *Status
= NDIS_STATUS_FAILURE
;
710 /* 6 bytes for ethernet, tokenring, fddi, everything else? */
711 IntArray
= ExAllocatePool(PagedPool
, 6*sizeof(UINT
));
714 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
715 *Status
= NDIS_STATUS_RESOURCES
;
719 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
720 if(!MiniportResource
)
722 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
723 *Status
= NDIS_STATUS_FAILURE
;
727 MiniportResource
->ResourceType
= 0;
728 MiniportResource
->Resource
= IntArray
;
729 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
730 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
732 /* convert from string to bytes */
735 IntArray
[i
] = (UnicodeToHexByte((ParameterValue
->ParameterData
.StringData
.Buffer
)[2*i
]) << 4) +
736 UnicodeToHexByte((ParameterValue
->ParameterData
.StringData
.Buffer
)[2*i
+1]);
739 *NetworkAddress
= IntArray
;
741 *Status
= NDIS_STATUS_SUCCESS
;
750 NdisOpenConfigurationKeyByIndex(
751 OUT PNDIS_STATUS Status
,
752 IN NDIS_HANDLE ConfigurationHandle
,
754 OUT PNDIS_STRING KeyName
,
755 OUT PNDIS_HANDLE KeyHandle
)
757 * FUNCTION: Opens a configuration subkey by index number
759 * Status: pointer to an NDIS_STATUS to receive status info
760 * ConfigurationHandle: the handle passed back from a previous open function
761 * Index: the zero-based index of the subkey to open
762 * KeyName: the name of the key that was opened
763 * KeyHandle: a handle to the key that was opened
765 * NDIS_STATUS_SUCCESS on success
766 * NDIS_STATUS_FAILURE on failure
767 * KeyName holds the name of the opened key
768 * KeyHandle holds a handle to the new key
771 KEY_BASIC_INFORMATION
*KeyInformation
;
772 ULONG KeyInformationLength
;
773 OBJECT_ATTRIBUTES KeyAttributes
;
774 NDIS_HANDLE RegKeyHandle
;
775 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
777 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, NULL
, 0, &KeyInformationLength
);
778 if(*Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_SUCCESS
)
780 *Status
= NDIS_STATUS_FAILURE
;
784 KeyInformation
= ExAllocatePool(PagedPool
, KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
));
787 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
788 *Status
= NDIS_STATUS_FAILURE
;
792 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, KeyInformation
,
793 KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
), &KeyInformationLength
);
795 if(*Status
!= STATUS_SUCCESS
)
797 ExFreePool(KeyInformation
);
798 *Status
= NDIS_STATUS_FAILURE
;
802 /* should i fail instead if the passed-in string isn't long enough? */
803 wcsncpy(KeyName
->Buffer
, KeyInformation
->Name
, KeyName
->MaximumLength
/sizeof(WCHAR
));
804 KeyName
->Length
= KeyInformation
->NameLength
;
806 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, NULL
);
808 *Status
= ZwOpenKey(&RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
810 ExFreePool(KeyInformation
);
812 if(*Status
!= STATUS_SUCCESS
)
814 *Status
= NDIS_STATUS_FAILURE
;
818 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
819 if(!ConfigurationContext
)
821 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
822 *Status
= NDIS_STATUS_FAILURE
;
826 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
827 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
829 ConfigurationContext
->Handle
= RegKeyHandle
;
831 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
833 *Status
= NDIS_STATUS_SUCCESS
;
842 NdisOpenConfigurationKeyByName(
843 OUT PNDIS_STATUS Status
,
844 IN NDIS_HANDLE ConfigurationHandle
,
845 IN PNDIS_STRING KeyName
,
846 OUT PNDIS_HANDLE KeyHandle
)
848 * FUNCTION: Opens a configuration subkey by name
850 * Status: points to an NDIS_STATUS where status is returned
851 * ConfigurationHandle: handle returned by a previous open call
852 * KeyName: the name of the key to open
853 * KeyHandle: a handle to the opened key
855 * NDIS_STATUS_SUCCESS on success
856 * NDIS_STATUS_FAILURE on failure
857 * KeyHandle holds a handle to the newly-opened key
861 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
862 OBJECT_ATTRIBUTES KeyAttributes
;
863 NDIS_HANDLE RegKeyHandle
;
865 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, 0);
866 *Status
= ZwOpenKey(&RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
868 if(*Status
!= STATUS_SUCCESS
)
870 *Status
= NDIS_STATUS_FAILURE
;
874 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
875 if(!ConfigurationContext
)
877 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
878 *Status
= NDIS_STATUS_FAILURE
;
882 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
883 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
885 ConfigurationContext
->Handle
= RegKeyHandle
;
887 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
889 *Status
= NDIS_STATUS_SUCCESS
;