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
;
70 if(ParameterType
!= NdisParameterInteger
&&
71 ParameterType
!= NdisParameterHexInteger
&&
72 ParameterType
!= NdisParameterString
&&
73 ParameterType
!= NdisParameterMultiString
&&
74 ParameterType
!= NdisParameterBinary
77 *Status
= NDIS_STATUS_NOT_SUPPORTED
;
81 /* reset parameter type to standard reg types */
84 /* HexInteger is stored as a string on 9x (as are other dwords), but we don't have to worry about that */
85 case NdisParameterHexInteger
:
86 case NdisParameterInteger
:
87 ParameterType
= REG_DWORD
;
88 Data
= &ParameterValue
->ParameterData
.IntegerData
;
89 DataSize
= sizeof(ULONG
);
92 case NdisParameterString
:
93 case NdisParameterMultiString
:
94 ParameterType
= REG_SZ
;
95 Data
= ParameterValue
->ParameterData
.StringData
.Buffer
;
96 DataSize
= ParameterValue
->ParameterData
.StringData
.Length
;
99 /* New (undocumented) addition to 2k ddk */
100 case NdisParameterBinary
:
101 ParameterType
= REG_BINARY
;
102 Data
= ParameterValue
->ParameterData
.BinaryData
.Buffer
;
103 DataSize
= ParameterValue
->ParameterData
.BinaryData
.Length
;
107 *Status
= ZwSetValueKey(((PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
)->Handle
,
108 Keyword
, 0, ParameterType
, Data
, DataSize
);
110 if(*Status
!= STATUS_SUCCESS
)
111 *Status
= NDIS_STATUS_FAILURE
;
113 *Status
= NDIS_STATUS_SUCCESS
;
122 NdisCloseConfiguration(
123 IN NDIS_HANDLE ConfigurationHandle
)
125 * FUNCTION: Closes handles and releases per-handle resources
127 * ConfigurationHandle - pointer to the context with the resources to free
130 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
131 PMINIPORT_RESOURCE Resource
;
133 while(!IsListEmpty(&ConfigurationContext
->ResourceListHead
))
135 Resource
= (PMINIPORT_RESOURCE
)RemoveTailList(&ConfigurationContext
->ResourceListHead
);
136 if(Resource
->ResourceType
== MINIPORT_RESOURCE_TYPE_MEMORY
)
138 NDIS_DbgPrint(MAX_TRACE
,("freeing 0x%x\n", Resource
->Resource
));
139 ExFreePool(Resource
->Resource
);
142 ExFreePool(Resource
);
145 ZwClose(ConfigurationContext
->Handle
);
154 NdisOpenConfiguration(
155 OUT PNDIS_STATUS Status
,
156 OUT PNDIS_HANDLE ConfigurationHandle
,
157 IN NDIS_HANDLE WrapperConfigurationContext
)
159 * FUNCTION: Opens the configuration key and sets up resource tracking for the returned handle
161 * Status: Pointer to a caller-supplied NDIS_STATUS that is filled in with a return value
162 * ConfigurationHandle: Pointer to an opaque configuration handle returned on success
163 * WrapperConfigurationContext: handle originally passed back from NdisInitializeWrapper
165 * NDIS_STATUS_SUCCESS: the operation completed successfully
166 * NDIS_STATUS_FAILURE: the operation failed
168 * I think this is the parameters key; please verify.
171 OBJECT_ATTRIBUTES KeyAttributes
;
172 UNICODE_STRING KeyNameU
;
174 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
175 HANDLE RootKeyHandle
= (HANDLE
)WrapperConfigurationContext
;
177 NDIS_DbgPrint(MAX_TRACE
, ("Called\n"));
179 RtlInitUnicodeString(&KeyNameU
, PARAMETERS_KEY
);
180 InitializeObjectAttributes(&KeyAttributes
, &KeyNameU
, OBJ_CASE_INSENSITIVE
, RootKeyHandle
, NULL
);
182 *Status
= ZwOpenKey(&KeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
183 if(*Status
!= STATUS_SUCCESS
)
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
);
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(ULONG
));
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 *ParameterValue
= NULL
;
349 *Status
= NDIS_STATUS_RESOURCES
;
353 MiniportResource
->ResourceType
= 0;
354 MiniportResource
->Resource
= *ParameterValue
;
356 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n",
357 MiniportResource
->Resource
));
359 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
360 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
362 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
363 (*ParameterValue
)->ParameterData
.IntegerData
= NdisEnvironmentWindowsNt
;
364 *Status
= NDIS_STATUS_SUCCESS
;
370 !wcsncmp(Keyword
->Buffer
, L
"ProcessorType", Keyword
->Length
/sizeof(WCHAR
)) &&
371 wcslen(L
"ProcessorType") == Keyword
->Length
/sizeof(WCHAR
)
374 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(ULONG
));
377 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
378 *Status
= NDIS_STATUS_RESOURCES
;
382 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
383 if(!MiniportResource
)
385 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
386 *ParameterValue
= NULL
;
387 *Status
= NDIS_STATUS_RESOURCES
;
391 MiniportResource
->ResourceType
= 0;
392 MiniportResource
->Resource
= *ParameterValue
;
393 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
394 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
395 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
397 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
398 (*ParameterValue
)->ParameterData
.IntegerData
= NdisProcessorX86
; /* XXX non-portable */
399 *Status
= NDIS_STATUS_SUCCESS
;
405 !wcsncmp(Keyword
->Buffer
, L
"NdisVersion", Keyword
->Length
/sizeof(WCHAR
)) &&
406 wcslen(L
"NdisVersion") == Keyword
->Length
/sizeof(WCHAR
)
409 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(ULONG
));
412 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
413 *Status
= NDIS_STATUS_RESOURCES
;
417 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
418 if(!MiniportResource
)
420 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
421 *ParameterValue
= NULL
;
422 *Status
= NDIS_STATUS_RESOURCES
;
426 MiniportResource
->ResourceType
= 0;
427 MiniportResource
->Resource
= *ParameterValue
;
428 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
429 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
,
430 &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
432 (*ParameterValue
)->ParameterType
= NdisParameterInteger
;
433 (*ParameterValue
)->ParameterData
.IntegerData
= NDIS_VERSION
;
434 *Status
= NDIS_STATUS_SUCCESS
;
439 /* figure out how much buffer i should allocate */
440 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
, NULL
, 0, &KeyDataLength
);
441 if(*Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_SUCCESS
)
443 NDIS_DbgPrint(MID_TRACE
,("ZwQueryValueKey #1 failed, status 0x%x\n", *Status
));
444 *Status
= NDIS_STATUS_FAILURE
;
449 KeyInformation
= ExAllocatePool(PagedPool
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
));
452 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
453 *Status
= NDIS_STATUS_RESOURCES
;
458 *Status
= ZwQueryValueKey(ConfigurationContext
->Handle
, Keyword
, KeyValuePartialInformation
,
459 KeyInformation
, KeyDataLength
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION
), &KeyDataLength
);
460 if(*Status
!= STATUS_SUCCESS
)
462 ExFreePool(KeyInformation
);
463 NDIS_DbgPrint(MID_TRACE
,("ZwQueryValueKey #2 failed, status 0x%x\n", *Status
));
464 *Status
= NDIS_STATUS_FAILURE
;
468 switch(ParameterType
)
470 case NdisParameterInteger
:
471 case NdisParameterHexInteger
:
473 if(KeyInformation
->Type
!= REG_DWORD
)
475 NDIS_DbgPrint(MIN_TRACE
,("requested type does not match actual value type\n"));
476 ExFreePool(KeyInformation
);
477 *ParameterValue
= NULL
;
478 *Status
= NDIS_STATUS_FAILURE
;
482 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
485 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
486 ExFreePool(KeyInformation
);
487 *Status
= NDIS_STATUS_RESOURCES
;
491 (*ParameterValue
)->ParameterType
= ParameterType
;
492 (*ParameterValue
)->ParameterData
.IntegerData
= *((ULONG
*)KeyInformation
->Data
);
494 ExFreePool(KeyInformation
);
496 *Status
= NDIS_STATUS_SUCCESS
;
501 case NdisParameterString
:
502 case NdisParameterMultiString
:
504 PMINIPORT_RESOURCE MiniportResource
= 0;
507 if(KeyInformation
->Type
!= REG_SZ
&& KeyInformation
->Type
!= REG_MULTI_SZ
)
509 NDIS_DbgPrint(MID_TRACE
,("requested type does not match actual value type\n"));
510 ExFreePool(KeyInformation
);
511 *ParameterValue
= NULL
;
512 *Status
= NDIS_STATUS_FAILURE
;
516 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
));
519 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
520 ExFreePool(KeyInformation
);
521 *Status
= NDIS_STATUS_RESOURCES
;
525 RegData
= ExAllocatePool(PagedPool
, KeyInformation
->DataLength
);
528 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
529 ExFreePool(KeyInformation
);
530 ExFreePool(*ParameterValue
);
531 *ParameterValue
= NULL
;
532 *Status
= NDIS_STATUS_FAILURE
;
536 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
537 if(!MiniportResource
)
539 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
540 ExFreePool(KeyInformation
);
541 ExFreePool(*ParameterValue
);
542 *ParameterValue
= NULL
;
543 *Status
= NDIS_STATUS_RESOURCES
;
547 MiniportResource
->ResourceType
= 0;
548 MiniportResource
->Resource
= *ParameterValue
;
549 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
550 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
552 memcpy(RegData
, KeyInformation
->Data
, KeyInformation
->DataLength
);
554 (*ParameterValue
)->ParameterType
= ParameterType
;
555 (*ParameterValue
)->ParameterData
.StringData
.Length
= KeyInformation
->DataLength
;
556 (*ParameterValue
)->ParameterData
.StringData
.Buffer
= RegData
;
558 ExFreePool(KeyInformation
);
560 *Status
= NDIS_STATUS_SUCCESS
;
565 case NdisParameterBinary
:
567 PMINIPORT_RESOURCE MiniportResource
;
569 if(KeyInformation
->Type
!= REG_BINARY
)
571 NDIS_DbgPrint(MIN_TRACE
,("requested type does not match actual value type\n"));
572 *Status
= NDIS_STATUS_FAILURE
;
573 ExFreePool(KeyInformation
);
577 *ParameterValue
= ExAllocatePool(PagedPool
, sizeof(NDIS_CONFIGURATION_PARAMETER
) + KeyInformation
->DataLength
);
580 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
581 ExFreePool(KeyInformation
);
582 *Status
= NDIS_STATUS_RESOURCES
;
586 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
587 if(!MiniportResource
)
589 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
590 ExFreePool(KeyInformation
);
591 ExFreePool(*ParameterValue
);
592 *ParameterValue
= NULL
;
593 *Status
= NDIS_STATUS_RESOURCES
;
597 MiniportResource
->ResourceType
= 0;
598 MiniportResource
->Resource
= *ParameterValue
;
599 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
600 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
602 (*ParameterValue
)->ParameterType
= ParameterType
;
603 memcpy(&((*ParameterValue
)->ParameterData
.BinaryData
), KeyInformation
->Data
, KeyInformation
->DataLength
);
605 ExFreePool(KeyInformation
);
607 *Status
= NDIS_STATUS_SUCCESS
;
615 UCHAR
UnicodeToHexByte(WCHAR chr
)
617 * FUNCTION: Converts a unicode hex character to its numerical value
619 * chr: Unicode character to convert
621 * The numerical value of chr
664 NdisReadNetworkAddress(
665 OUT PNDIS_STATUS Status
,
666 OUT PVOID
* NetworkAddress
,
667 OUT PUINT NetworkAddressLength
,
668 IN NDIS_HANDLE ConfigurationHandle
)
670 * FUNCTION: Reads the network address from the registry
672 * Status - variable to receive status
673 * NetworkAddress - pointer to a buffered network address array
674 * NetworkAddressLength - length of the NetworkAddress array
675 * ConfigurationHandle: handle passed back from one of the open routines
677 * NDIS_STATUS_SUCCESS on success
678 * NDIS_STATUS_FAILURE on failure
679 * The network address is placed in the NetworkAddress buffer
682 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
= (PMINIPORT_CONFIGURATION_CONTEXT
)ConfigurationHandle
;
683 PMINIPORT_RESOURCE MiniportResource
= NULL
;
684 PNDIS_CONFIGURATION_PARAMETER ParameterValue
= NULL
;
689 *NetworkAddress
= NULL
;
690 *NetworkAddressLength
= 6;/* XXX magic constant */
692 NdisInitUnicodeString(&Keyword
, L
"NetworkAddress");
693 NdisReadConfiguration(Status
, &ParameterValue
, ConfigurationHandle
, &Keyword
, NdisParameterString
);
694 if(*Status
!= NDIS_STATUS_SUCCESS
)
696 *Status
= NDIS_STATUS_FAILURE
;
700 /* 6 bytes for ethernet, tokenring, fddi, everything else? */
701 IntArray
= ExAllocatePool(PagedPool
, 6*sizeof(UINT
));
704 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
705 *Status
= NDIS_STATUS_RESOURCES
;
709 MiniportResource
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_RESOURCE
));
710 if(!MiniportResource
)
712 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
713 *Status
= NDIS_STATUS_FAILURE
;
717 MiniportResource
->ResourceType
= 0;
718 MiniportResource
->Resource
= IntArray
;
719 NDIS_DbgPrint(MID_TRACE
,("inserting 0x%x into the resource list\n", MiniportResource
->Resource
));
720 ExInterlockedInsertTailList(&ConfigurationContext
->ResourceListHead
, &MiniportResource
->ListEntry
, &ConfigurationContext
->ResourceLock
);
722 /* convert from string to bytes */
725 IntArray
[i
] = (UnicodeToHexByte((ParameterValue
->ParameterData
.StringData
.Buffer
)[2*i
]) << 4) +
726 UnicodeToHexByte((ParameterValue
->ParameterData
.StringData
.Buffer
)[2*i
+1]);
729 *NetworkAddress
= IntArray
;
731 *Status
= NDIS_STATUS_SUCCESS
;
740 NdisOpenConfigurationKeyByIndex(
741 OUT PNDIS_STATUS Status
,
742 IN NDIS_HANDLE ConfigurationHandle
,
744 OUT PNDIS_STRING KeyName
,
745 OUT PNDIS_HANDLE KeyHandle
)
747 * FUNCTION: Opens a configuration subkey by index number
749 * Status: pointer to an NDIS_STATUS to receive status info
750 * ConfigurationHandle: the handle passed back from a previous open function
751 * Index: the zero-based index of the subkey to open
752 * KeyName: the name of the key that was opened
753 * KeyHandle: a handle to the key that was opened
755 * NDIS_STATUS_SUCCESS on success
756 * NDIS_STATUS_FAILURE on failure
757 * KeyName holds the name of the opened key
758 * KeyHandle holds a handle to the new key
761 KEY_BASIC_INFORMATION
*KeyInformation
;
762 ULONG KeyInformationLength
;
763 OBJECT_ATTRIBUTES KeyAttributes
;
764 NDIS_HANDLE RegKeyHandle
;
765 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
767 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, NULL
, 0, &KeyInformationLength
);
768 if(*Status
!= STATUS_BUFFER_TOO_SMALL
&& *Status
!= STATUS_BUFFER_OVERFLOW
&& *Status
!= STATUS_SUCCESS
)
770 *Status
= NDIS_STATUS_FAILURE
;
774 KeyInformation
= ExAllocatePool(PagedPool
, KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
));
777 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
778 *Status
= NDIS_STATUS_FAILURE
;
782 *Status
= ZwEnumerateKey(ConfigurationHandle
, Index
, KeyBasicInformation
, KeyInformation
,
783 KeyInformationLength
+ sizeof(KEY_BASIC_INFORMATION
), &KeyInformationLength
);
785 if(*Status
!= STATUS_SUCCESS
)
787 ExFreePool(KeyInformation
);
788 *Status
= NDIS_STATUS_FAILURE
;
792 /* should i fail instead if the passed-in string isn't long enough? */
793 wcsncpy(KeyName
->Buffer
, KeyInformation
->Name
, KeyName
->MaximumLength
);
794 KeyName
->Length
= KeyInformation
->NameLength
;
796 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, NULL
);
798 *Status
= ZwOpenKey(&RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
800 ExFreePool(KeyInformation
);
802 if(*Status
!= STATUS_SUCCESS
)
804 *Status
= NDIS_STATUS_FAILURE
;
808 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
809 if(!ConfigurationContext
)
811 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
812 *Status
= NDIS_STATUS_FAILURE
;
816 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
817 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
819 ConfigurationContext
->Handle
= RegKeyHandle
;
821 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
823 *Status
= NDIS_STATUS_SUCCESS
;
832 NdisOpenConfigurationKeyByName(
833 OUT PNDIS_STATUS Status
,
834 IN NDIS_HANDLE ConfigurationHandle
,
835 IN PNDIS_STRING KeyName
,
836 OUT PNDIS_HANDLE KeyHandle
)
838 * FUNCTION: Opens a configuration subkey by name
840 * Status: points to an NDIS_STATUS where status is returned
841 * ConfigurationHandle: handle returned by a previous open call
842 * KeyName: the name of the key to open
843 * KeyHandle: a handle to the opened key
845 * NDIS_STATUS_SUCCESS on success
846 * NDIS_STATUS_FAILURE on failure
847 * KeyHandle holds a handle to the newly-opened key
851 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext
;
852 OBJECT_ATTRIBUTES KeyAttributes
;
853 NDIS_HANDLE RegKeyHandle
;
855 InitializeObjectAttributes(&KeyAttributes
, KeyName
, OBJ_CASE_INSENSITIVE
, ConfigurationHandle
, 0);
856 *Status
= ZwOpenKey(RegKeyHandle
, KEY_ALL_ACCESS
, &KeyAttributes
);
858 if(*Status
!= STATUS_SUCCESS
)
860 *Status
= NDIS_STATUS_FAILURE
;
864 ConfigurationContext
= ExAllocatePool(PagedPool
, sizeof(MINIPORT_CONFIGURATION_CONTEXT
));
865 if(!ConfigurationContext
)
867 NDIS_DbgPrint(MIN_TRACE
,("Insufficient resources.\n"));
868 *Status
= NDIS_STATUS_FAILURE
;
872 KeInitializeSpinLock(&ConfigurationContext
->ResourceLock
);
873 InitializeListHead(&ConfigurationContext
->ResourceListHead
);
875 ConfigurationContext
->Handle
= RegKeyHandle
;
877 *KeyHandle
= (NDIS_HANDLE
)ConfigurationContext
;
879 *Status
= NDIS_STATUS_SUCCESS
;