ReactOS 0.4.17-dev-1321-g5c122a9
config.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
4 * FILE: ndis/config.c
5 * PURPOSE: NDIS Configuration Services
6 * PROGRAMMERS: Vizzini (vizzini@plasmic.com)
7 * REVISIONS:
8 * Vizzini 07-28-2003 Created
9 * NOTES:
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 Configuration 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
30 * it'll break things.
31 * - All the routines in this file are PASSIVE_LEVEL only, and all memory is PagedPool
32 */
33
34#include "ndissys.h"
35
36#include <ntifs.h>
37
38#define PARAMETERS_KEY L"Parameters" /* The parameters subkey under the device-specific key */
39
41
42static
46{
47 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
50
52 if (!NT_SUCCESS(Status))
53 {
54 NDIS_DbgPrint(MIN_TRACE, ("Failed to open registry configuration for this miniport "
55 "'%wZ', status 0x%lx\n",
56 ObjectAttributes->ObjectName, Status));
57 return NULL;
58 }
59
60 ConfigurationContext = ExAllocatePoolUninitialized(NonPagedPool,
61 sizeof(*ConfigurationContext),
63 if (!ConfigurationContext)
64 {
65 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
67 return NULL;
68 }
69
70 ConfigurationContext->Handle = KeyHandle;
71
72 KeInitializeSpinLock(&ConfigurationContext->ResourceLock);
73 InitializeListHead(&ConfigurationContext->ResourceListHead);
74
75 return ConfigurationContext;
76}
77
78static
79VOID
81 _In_ PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext,
82 _Out_ PMINIPORT_RESOURCE MiniportResource,
84 _In_ PVOID ConfigParameter)
85{
86 MiniportResource->ResourceType = Type;
87 MiniportResource->Resource = ConfigParameter;
88
89 NDIS_DbgPrint(MID_TRACE, ("inserting %p into the resource list\n",
90 MiniportResource->Resource));
91
92 ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
93 &MiniportResource->ListEntry,
94 &ConfigurationContext->ResourceLock);
95}
96
97/*
98 * @implemented
99 */
100VOID
101EXPORT
107/*
108 * FUNCTION: Writes a configuration value to the registry
109 * ARGUMENTS:
110 * Status: Pointer to a caller-supplied NDIS_STATUS where we return status
111 * ConfigurationHandle: The Configuration Handle passed back from the call to one of the Open functions
112 * Keyword: The registry value name to write
113 * ParameterValue: The value data to write
114 * RETURNS:
115 * NDIS_STATUS_SUCCESS - the operation completed successfully
116 * NDIS_STATUS_NOT_SUPPORTED - The parameter type is not supported
117 * NDIS_STATUS_RESOURCES - out of memory, etc.
118 * NDIS_STATUS_FAILURE - any other failure
119 * NOTES:
120 * There's a cryptic comment in the ddk implying that this function allocates and keeps memory.
121 * I don't know why tho so i free everything before return. comments welcome.
122 */
123{
126 PVOID Data;
127 WCHAR Buff[11];
128
129 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
130
131 NDIS_DbgPrint(MID_TRACE, ("Parameter type: %d\n", ParameterValue->ParameterType));
132
133 /* reset parameter type to standard reg types */
134 switch(ParameterValue->ParameterType)
135 {
138 {
140
141 Str.Buffer = (PWSTR) &Buff;
142 Str.MaximumLength = (USHORT)sizeof(Buff);
143 Str.Length = 0;
144
147 ParameterValue->ParameterData.IntegerData,
148 (ParameterValue->ParameterType == NdisParameterInteger) ? 10 : 16, &Str)))
149 {
150 NDIS_DbgPrint(MIN_TRACE, ("RtlIntegerToUnicodeString failed (%x)\n", *Status));
152 return;
153 }
154 Data = Str.Buffer;
155 DataSize = Str.Length;
156 }
157 break;
161 Data = ParameterValue->ParameterData.StringData.Buffer;
162 DataSize = ParameterValue->ParameterData.StringData.Length;
163 break;
164
165 /* New (undocumented) addition to 2k ddk */
168 Data = ParameterValue->ParameterData.BinaryData.Buffer;
169 DataSize = ParameterValue->ParameterData.BinaryData.Length;
170 break;
171
172 default:
174 return;
175 }
176
179
180 if(*Status != STATUS_SUCCESS) {
181 NDIS_DbgPrint(MIN_TRACE, ("ZwSetValueKey failed (%x)\n", *Status));
183 } else
185}
186
187
188/*
189 * @implemented
190 */
191VOID
192EXPORT
195/*
196 * FUNCTION: Closes handles and releases per-handle resources
197 * ARGUMENTS:
198 * ConfigurationHandle - pointer to the context with the resources to free
199 */
200{
204 PLIST_ENTRY CurrentEntry;
205
206 while((CurrentEntry = ExInterlockedRemoveHeadList(&ConfigurationContext->ResourceListHead,
207 &ConfigurationContext->ResourceLock)) != NULL)
208 {
209 Resource = CONTAINING_RECORD(CurrentEntry, MINIPORT_RESOURCE, ListEntry);
210 switch(Resource->ResourceType)
211 {
213 ParameterValue = Resource->Resource;
214
215 switch (ParameterValue->ParameterType)
216 {
218 ExFreePoolWithTag(ParameterValue->ParameterData.BinaryData.Buffer, TAG_CONFIG);
219 break;
220
223 ExFreePoolWithTag(ParameterValue->ParameterData.StringData.Buffer, TAG_CONFIG);
224 break;
225
226 default:
227 break;
228 }
229
230 /* Fall through to free NDIS_CONFIGURATION_PARAMETER struct */
231
233 NDIS_DbgPrint(MAX_TRACE,("freeing 0x%x\n", Resource->Resource));
235 break;
236
237 default:
238 NDIS_DbgPrint(MIN_TRACE,("Unknown resource type: %d\n", Resource->ResourceType));
239 break;
240 }
241
243 }
244
245 ZwClose(ConfigurationContext->Handle);
246}
247
248
249/*
250 * @implemented
251 */
252VOID
253EXPORT
258/*
259 * FUNCTION: Opens the configuration key and sets up resource tracking for the returned handle
260 * ARGUMENTS:
261 * Status: Pointer to a caller-supplied NDIS_STATUS that is filled in with a return value
262 * ConfigurationHandle: Pointer to an opaque configuration handle returned on success
263 * WrapperConfigurationContext: handle originally passed back from NdisInitializeWrapper
264 * RETURNS:
265 * NDIS_STATUS_SUCCESS: the operation completed successfully
266 * NDIS_STATUS_FAILURE: the operation failed
267 * NOTES:
268 * I think this is the parameters key; please verify.
269 */
270{
271 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
273 HANDLE RootKeyHandle = WrapperContext->RegistryHandle;
276
277 NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
278
280
282 &NoName,
284 RootKeyHandle,
285 NULL);
286
287 ConfigurationContext = AllocateConfigurationContext(&ObjectAttributes);
288 if(!ConfigurationContext)
289 {
290 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
292 return;
293 }
294
295 *ConfigurationHandle = (NDIS_HANDLE)ConfigurationContext;
297
298 NDIS_DbgPrint(MAX_TRACE,("returning success\n"));
299}
300
301
302/*
303 * @implemented
304 */
305VOID
306EXPORT
311/*
312 * FUNCTION: Open the configuration key and set up resource tracking for the protocol
313 * ARGUMENTS:
314 * Status: caller-allocated buffer where status is returned
315 * ConfigurationHandle: spot to return the opaque configuration context
316 * ProtocolSection: configuration string originally passed in to ProtocolBindAdapter
317 * RETURNS:
318 * NDIS_STATUS_SUCCESS: the operation was a success
319 * NDIS_STATUS_FAILURE: the operation was not a success
320 * NOTES:
321 * I think this is the per-device (adapter) parameters\{ProtocolName} key; please verify.
322 */
323{
325 UNICODE_STRING KeyNameU;
326 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
327
328 KeyNameU.Length = 0;
329 KeyNameU.MaximumLength = ProtocolSection->Length + sizeof(PARAMETERS_KEY) + sizeof(UNICODE_NULL);
331 if(!KeyNameU.Buffer)
332 {
333 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
336 return;
337 }
338
342
343 ConfigurationContext = AllocateConfigurationContext(&KeyAttributes);
345 if(!ConfigurationContext)
346 {
347 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
350 return;
351 }
352
353 *ConfigurationHandle = (NDIS_HANDLE)ConfigurationContext;
355}
356
357static
359/*
360 * FUNCTION: Converts a unicode hex character to its numerical value
361 * ARGUMENTS:
362 * chr: Unicode character to convert
363 * RETURNS:
364 * The numerical value of chr
365 */
366{
367 switch(chr)
368 {
369 case L'0': return 0;
370 case L'1': return 1;
371 case L'2': return 2;
372 case L'3': return 3;
373 case L'4': return 4;
374 case L'5': return 5;
375 case L'6': return 6;
376 case L'7': return 7;
377 case L'8': return 8;
378 case L'9': return 9;
379 case L'A':
380 case L'a':
381 return 10;
382 case L'B':
383 case L'b':
384 return 11;
385 case L'C':
386 case L'c':
387 return 12;
388 case L'D':
389 case L'd':
390 return 13;
391 case L'E':
392 case L'e':
393 return 14;
394 case L'F':
395 case L'f':
396 return 15;
397 }
398 return 0xFF;
399}
400
401static
404/*
405 * FUNCTION: Determines if a string is a valid number
406 * ARGUMENTS:
407 * String: Unicode string to evaluate
408 * RETURNS:
409 * TRUE if it is valid, FALSE if not
410 */
411{
412 ULONG i;
413
414 /* I don't think this will ever happen, but we warn it if it does */
415 if (String->Length == 0)
416 {
417 NDIS_DbgPrint(MIN_TRACE, ("Got an empty string; not sure what to do here\n"));
418 return FALSE;
419 }
420
421 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
422 {
423 /* Skip any NULL characters we find */
424 if (String->Buffer[i] == UNICODE_NULL)
425 continue;
426
427 /* Make sure the character is valid for a numeric string of this base */
428 if (UnicodeToHexByte(String->Buffer[i]) >= Base)
429 return FALSE;
430 }
431
432 /* It's valid */
433 return TRUE;
434}
435
436/*
437 * @implemented
438 */
439VOID
440EXPORT
447/*
448 * FUNCTION: Read a configuration value from the registry, tracking its resources
449 * ARGUMENTS:
450 * Status: points to a place to write status into
451 * ParameterValue: Pointer to receive a newly-allocated parameter structure
452 * ConfigurationHandle: handle originally returned by an open function
453 * Keyword: Value name to read, or one of the following constants:
454 * Environment - returns NdisEnvironmentWindowsNt
455 * ProcessorType - returns NdisProcessorX86 until more architectures are added
456 * NdisVersion - returns NDIS_VERSION
457 * ParameterType: the type of the value to be queried
458 * RETURNS:
459 * - A status in Status
460 * - A parameter value in ParameterValue
461 */
462{
464 PKEY_VALUE_PARTIAL_INFORMATION KeyInformation = NULL;
465 PNDIS_CONFIGURATION_PARAMETER ConfigParameter = NULL;
466 PMINIPORT_RESOURCE MiniportResource = NULL;
467 NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
468 NTSTATUS NtStatus;
469 ULONG LocalUlong;
471 ULONG RegType;
472 ULONG RegDataLength;
473 static const UNICODE_STRING NdisVersionKey = RTL_CONSTANT_STRING(L"NdisVersion");
474 static const UNICODE_STRING EnvironmentKey = RTL_CONSTANT_STRING(L"Environment");
475 static const UNICODE_STRING ProcessorTypeKey = RTL_CONSTANT_STRING(L"ProcessorType");
476 static const UNICODE_STRING FlowControlKey = RTL_CONSTANT_STRING(L"*FlowControl");
477
478 NDIS_DbgPrint(MAX_TRACE, ("requested read type %d of '%wZ'\n", ParameterType, Keyword));
479
480 ASSERT(ConfigurationContext);
481
482 /* Check for predefined entry names */
484 {
485 NDIS_DbgPrint(MID_TRACE, ("Disable TX/RX flow control for this miniport\n"));
486 LocalUlong = 0;
487
488 RegType = REG_DWORD;
489 RegData = &LocalUlong;
490 RegDataLength = sizeof(LocalUlong);
491 }
492 else if (RtlEqualUnicodeString(Keyword, &NdisVersionKey, TRUE))
493 {
494 LocalUlong = NDIS_VERSION;
495
496 RegType = REG_DWORD;
497 RegData = &LocalUlong;
498 RegDataLength = sizeof(LocalUlong);
499 }
500 else if (RtlEqualUnicodeString(Keyword, &EnvironmentKey, TRUE))
501 {
502 LocalUlong = NdisEnvironmentWindowsNt;
503
504 RegType = REG_DWORD;
505 RegData = &LocalUlong;
506 RegDataLength = sizeof(LocalUlong);
507 }
508 else if (RtlEqualUnicodeString(Keyword, &ProcessorTypeKey, TRUE))
509 {
510#if defined(_M_IX86)
511 LocalUlong = NdisProcessorX86;
512#elif defined(_M_MIPS)
513 LocalUlong = NdisProcessorMips;
514#elif defined(_M_ALPHA)
515 LocalUlong = NdisProcessorAlpha;
516#elif defined(_M_MPPC)
517 LocalUlong = NdisProcessorPpc;
518#elif defined(_M_AMD64)
519 LocalUlong = NdisProcessorAmd64;
520#elif defined(_M_IA64)
521 LocalUlong = NdisProcessorIA64;
522#elif defined(_M_ARM)
523 LocalUlong = NdisProcessorArm;
524#elif defined(_M_ARM64)
525 LocalUlong = NdisProcessorArm64;
526#else
527#error Unknown architecture
528#endif
529
530 RegType = REG_DWORD;
531 RegData = &LocalUlong;
532 RegDataLength = sizeof(LocalUlong);
533 }
534 else
535 {
536 ULONG KeyDataLength, RetryCount;
537
538 /* The most common case is NdisParameterInteger (REG_DWORD) */
539 KeyDataLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + sizeof(ULONG);
540
541 for (RetryCount = 0; RetryCount < 2; ++RetryCount)
542 {
543 KeyInformation = ExAllocatePoolUninitialized(PagedPool, KeyDataLength, TAG_CONFIG);
544 if (!KeyInformation)
545 {
546 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
548 return;
549 }
550
551 /* Query the value */
552 NtStatus = ZwQueryValueKey(ConfigurationContext->Handle,
553 Keyword,
555 KeyInformation,
556 KeyDataLength,
557 &KeyDataLength);
558
559 /* Increase the allocation size if it's too small */
560 if (NtStatus == STATUS_BUFFER_OVERFLOW || NtStatus == STATUS_BUFFER_TOO_SMALL)
561 {
562 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
563 KeyInformation = NULL;
564 continue;
565 }
566
567 break;
568 }
569
570 if (!NT_SUCCESS(NtStatus))
571 {
572 NDIS_DbgPrint(MIN_TRACE, ("ZwQueryValueKey failed for '%wZ', status 0x%lx\n",
573 Keyword, NtStatus));
574 NdisStatus = NDIS_STATUS_FAILURE;
575 goto Exit;
576 }
577
578 RegType = KeyInformation->Type;
579 RegData = &KeyInformation->Data[0];
580 RegDataLength = KeyInformation->DataLength;
581 }
582
583 MiniportResource = ExAllocatePoolUninitialized(PagedPool,
584 sizeof(*MiniportResource),
585 TAG_CONFIG);
586 if (!MiniportResource)
587 {
588 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
589 NdisStatus = NDIS_STATUS_RESOURCES;
590 goto Exit;
591 }
592
593 ConfigParameter = ExAllocatePoolZero(PagedPool, sizeof(*ConfigParameter), TAG_CONFIG);
594 if (!ConfigParameter)
595 {
596 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
597 NdisStatus = NDIS_STATUS_RESOURCES;
598 goto Exit;
599 }
600
601 switch (RegType)
602 {
603 case REG_DWORD:
604 {
605 ASSERT(RegDataLength == sizeof(ULONG));
606
607 ConfigParameter->ParameterType = NdisParameterInteger;
608 ConfigParameter->ParameterData.IntegerData = *(PULONG)RegData;
609
610 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterInteger 0x%lX (%lu)\n",
611 ConfigParameter->ParameterData.IntegerData,
612 ConfigParameter->ParameterData.IntegerData));
613 break;
614 }
615 case REG_BINARY:
616 {
618
619 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterBinary\n"));
620
622 if (!Buffer)
623 {
624 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
625 NdisStatus = NDIS_STATUS_RESOURCES;
626 goto Exit;
627 }
628 RtlCopyMemory(Buffer, RegData, RegDataLength);
629
630 ConfigParameter->ParameterData.BinaryData.Buffer = Buffer;
631 ConfigParameter->ParameterData.BinaryData.Length = RegDataLength;
632 break;
633 }
634 case REG_MULTI_SZ:
635 {
637
638 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterMultiString\n"));
639
641 if (!Buffer)
642 {
643 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
644 NdisStatus = NDIS_STATUS_RESOURCES;
645 goto Exit;
646 }
647 RtlCopyMemory(Buffer, RegData, RegDataLength);
648
649 ConfigParameter->ParameterType = NdisParameterMultiString;
650 ConfigParameter->ParameterData.StringData.Buffer = Buffer;
651 ConfigParameter->ParameterData.StringData.Length = RegDataLength;
652 break;
653 }
654 case REG_SZ:
655 {
657 ULONG Base;
659
661 Base = 10;
663 Base = 16;
664 else
665 Base = 0;
666
667 String.Length = String.MaximumLength = (USHORT)RegDataLength;
668 String.Buffer = RegData;
669
670 if (Base != 0 && IsValidNumericString(&String, Base))
671 {
673 Base,
674 &ConfigParameter->ParameterData.IntegerData);
675 ASSERT(NT_SUCCESS(NtStatus));
676
677 NDIS_DbgPrint(MAX_TRACE, ("NdisParameter(Hex)Integer 0x%lX (%lu)\n",
678 ConfigParameter->ParameterData.IntegerData,
679 ConfigParameter->ParameterData.IntegerData));
680
681 /*
682 * MSDN documents that this is returned for all integers,
683 * regardless of the ParameterType passed in.
684 */
685 ConfigParameter->ParameterType = NdisParameterInteger;
686 }
687 else
688 {
689 NDIS_DbgPrint(MAX_TRACE, ("NdisParameterString\n"));
690
691 ConfigParameter->ParameterType = NdisParameterString;
692
694 RegDataLength,
695 TAG_CONFIG);
696 if (!Buffer)
697 {
698 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
699 NdisStatus = NDIS_STATUS_RESOURCES;
700 goto Exit;
701 }
702 RtlCopyMemory(Buffer, RegData, RegDataLength);
703
704 ConfigParameter->ParameterData.StringData.Buffer = Buffer;
705 ConfigParameter->ParameterData.StringData.Length = RegDataLength;
706 }
707 break;
708 }
709 default:
710 {
711 NDIS_DbgPrint(MIN_TRACE, ("Invalid type for NdisReadConfiguration (%d)\n", RegType));
712 NDIS_DbgPrint(MIN_TRACE, ("Requested type: %lu\n", ParameterType));
713 NDIS_DbgPrint(MIN_TRACE, ("Registry entry: '%wZ'\n", Keyword));
714
715 NdisStatus = NDIS_STATUS_FAILURE;
716 goto Exit;
717 }
718 }
719
720 if ((ConfigParameter->ParameterType != ParameterType) &&
722 (ConfigParameter->ParameterType == NdisParameterInteger)))
723 {
724 NDIS_DbgPrint(MIN_TRACE, ("Parameter type mismatch! (Requested: %d | Received: %d)\n",
725 ParameterType, ConfigParameter->ParameterType));
726 NDIS_DbgPrint(MIN_TRACE, ("Registry entry: '%wZ'\n", Keyword));
727 }
728
729 ASSERT(NdisStatus == NDIS_STATUS_SUCCESS);
730
731 *ParameterValue = ConfigParameter;
732
733 AddConfigurationParameter(ConfigurationContext,
734 MiniportResource,
736 ConfigParameter);
737Exit:
738 *Status = NdisStatus;
739
740 if (NdisStatus != NDIS_STATUS_SUCCESS)
741 {
742 if (ConfigParameter)
743 ExFreePoolWithTag(ConfigParameter, TAG_CONFIG);
744 if (MiniportResource)
745 ExFreePoolWithTag(MiniportResource, TAG_CONFIG);
746 }
747
748 if (KeyInformation)
749 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
750}
751
752/*
753 * @implemented
754 */
755VOID
756EXPORT
762/*
763 * FUNCTION: Reads the network address from the registry
764 * ARGUMENTS:
765 * Status - variable to receive status
766 * NetworkAddress - pointer to a buffered network address array
767 * NetworkAddressLength - length of the NetworkAddress array
768 * ConfigurationHandle: handle passed back from one of the open routines
769 * RETURNS:
770 * NDIS_STATUS_SUCCESS on success
771 * NDIS_STATUS_FAILURE on failure
772 * The network address is placed in the NetworkAddress buffer
773 */
774{
776 PMINIPORT_RESOURCE MiniportResource = NULL;
779 UINT *IntArray = 0;
780 UINT i,j = 0;
781 WCHAR Buff[11];
783
784 NdisInitUnicodeString(&Keyword, L"NetworkAddress");
787 {
788 NDIS_DbgPrint(MID_TRACE, ("NdisReadConfiguration failed (%x)\n", *Status));
790 return;
791 }
792
793 if (ParameterValue->ParameterType == NdisParameterInteger)
794 {
795 NDIS_DbgPrint(MAX_TRACE, ("Read integer data %lx\n",
796 ParameterValue->ParameterData.IntegerData));
797
798 str.Buffer = Buff;
799 str.MaximumLength = (USHORT)sizeof(Buff);
800 str.Length = 0;
801
802 *Status = RtlIntegerToUnicodeString(ParameterValue->ParameterData.IntegerData,
803 10,
804 &str);
805
807 {
808 NDIS_DbgPrint(MIN_TRACE, ("RtlIntegerToUnicodeString failed (%x)\n", *Status));
810 return;
811 }
812
813 NDIS_DbgPrint(MAX_TRACE, ("Converted integer data into %wZ\n", &str));
814 }
815 else
816 {
817 ASSERT(ParameterValue->ParameterType == NdisParameterString);
818 str = ParameterValue->ParameterData.StringData;
819 }
820
821 while (j < str.Length && str.Buffer[j] != '\0') j++;
822
823 *NetworkAddressLength = (j+1) >> 1;
824
825 if ((*NetworkAddressLength) == 0)
826 {
827 NDIS_DbgPrint(MIN_TRACE,("Empty NetworkAddress registry entry.\n"));
829 return;
830 }
831
833 (*NetworkAddressLength) * sizeof(*IntArray),
834 TAG_CONFIG);
835 if(!IntArray)
836 {
837 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
839 return;
840 }
841
842 MiniportResource = ExAllocatePoolUninitialized(PagedPool,
843 sizeof(*MiniportResource),
844 TAG_CONFIG);
845 if(!MiniportResource)
846 {
847 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
848 ExFreePoolWithTag(IntArray, TAG_CONFIG);
850 return;
851 }
852
853 AddConfigurationParameter(ConfigurationContext,
854 MiniportResource,
856 IntArray);
857
858 /* convert from string to bytes */
859 for(i=0; i<(*NetworkAddressLength); i++)
860 {
861 IntArray[i] = (UnicodeToHexByte((str.Buffer)[2*i]) << 4) +
862 UnicodeToHexByte((str.Buffer)[2*i+1]);
863 }
864
865 *NetworkAddress = IntArray;
866
868}
869
870
871/*
872 * @implemented
873 */
874VOID
875EXPORT
879 IN ULONG Index,
882/*
883 * FUNCTION: Opens a configuration subkey by index number
884 * ARGUMENTS:
885 * Status: pointer to an NDIS_STATUS to receive status info
886 * ConfigurationHandle: the handle passed back from a previous open function
887 * Index: the zero-based index of the subkey to open
888 * KeyName: the name of the key that was opened
889 * KeyHandle: a handle to the key that was opened
890 * RETURNS:
891 * NDIS_STATUS_SUCCESS on success
892 * NDIS_STATUS_FAILURE on failure
893 * KeyName holds the name of the opened key
894 * KeyHandle holds a handle to the new key
895 */
896{
897 KEY_BASIC_INFORMATION *KeyInformation;
898 ULONG KeyInformationLength;
900 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
901
902 *KeyHandle = NULL;
903
904 *Status = ZwEnumerateKey(ConfigurationHandle, Index, KeyBasicInformation, NULL, 0, &KeyInformationLength);
906 {
907 NDIS_DbgPrint(MIN_TRACE, ("ZwEnumerateKey failed (%x)\n", *Status));
909 return;
910 }
911
912 KeyInformation = ExAllocatePoolUninitialized(PagedPool,
913 KeyInformationLength + sizeof(*KeyInformation),
914 TAG_CONFIG);
915 if(!KeyInformation)
916 {
917 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
919 return;
920 }
921
922 *Status = ZwEnumerateKey(ConfigurationHandle, Index, KeyBasicInformation, KeyInformation,
923 KeyInformationLength + sizeof(KEY_BASIC_INFORMATION), &KeyInformationLength);
924
925 if(*Status != STATUS_SUCCESS)
926 {
927 NDIS_DbgPrint(MIN_TRACE, ("ZwEnumerateKey failed (%x)\n", *Status));
928 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
930 return;
931 }
932
933 /* should i fail instead if the passed-in string isn't long enough? */
934 wcsncpy(KeyName->Buffer, KeyInformation->Name, KeyName->MaximumLength/sizeof(WCHAR));
935 KeyName->Length = (USHORT)min(KeyInformation->NameLength, KeyName->MaximumLength);
936
938
939 ConfigurationContext = AllocateConfigurationContext(&KeyAttributes);
940 ExFreePoolWithTag(KeyInformation, TAG_CONFIG);
941 if(!ConfigurationContext)
942 {
943 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
945 return;
946 }
947
948 *KeyHandle = (NDIS_HANDLE)ConfigurationContext;
950}
951
952
953/*
954 * @implemented
955 */
956VOID
957EXPORT
963/*
964 * FUNCTION: Opens a configuration subkey by name
965 * ARGUMENTS:
966 * Status: points to an NDIS_STATUS where status is returned
967 * ConfigurationHandle: handle returned by a previous open call
968 * KeyName: the name of the key to open
969 * KeyHandle: a handle to the opened key
970 * RETURNS:
971 * NDIS_STATUS_SUCCESS on success
972 * NDIS_STATUS_FAILURE on failure
973 * KeyHandle holds a handle to the newly-opened key
974 * NOTES:
975 */
976{
977 PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
979
980 *KeyHandle = NULL;
981
983
984 ConfigurationContext = AllocateConfigurationContext(&KeyAttributes);
985 if(!ConfigurationContext)
986 {
987 NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
989 return;
990 }
991
992 *KeyHandle = (NDIS_HANDLE)ConfigurationContext;
994}
#define ExAllocatePoolUninitialized
Type
Definition: Type.h:7
unsigned char BOOLEAN
Definition: actypes.h:127
#define REG_SZ
Definition: layer.c:22
LONG NTSTATUS
Definition: precomp.h:26
REGISTRY_DATA RegData
Definition: registry.c:14
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
#define MAX_TRACE
Definition: debug.h:16
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
_In_opt_ PWSTR _In_ PWSTR _Inout_ PULONG ParameterValue
Definition: cdrom.h:963
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
Walk Base
Definition: desccheck.cpp:2270
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
#define L(x)
Definition: resources.c:13
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define MINIPORT_RESOURCE_TYPE_REGISTRY_DATA
Definition: miniport.h:41
#define MINIPORT_RESOURCE_TYPE_MEMORY
Definition: miniport.h:42
struct _NDIS_WRAPPER_CONTEXT * PNDIS_WRAPPER_CONTEXT
struct _MINIPORT_CONFIGURATION_CONTEXT * PMINIPORT_CONFIGURATION_CONTEXT
VOID EXPORT NdisOpenConfigurationKeyByName(OUT PNDIS_STATUS Status, IN NDIS_HANDLE ConfigurationHandle, IN PNDIS_STRING KeyName, OUT PNDIS_HANDLE KeyHandle)
Definition: config.c:958
VOID EXPORT NdisCloseConfiguration(IN NDIS_HANDLE ConfigurationHandle)
Definition: config.c:193
VOID EXPORT NdisWriteConfiguration(OUT PNDIS_STATUS Status, IN NDIS_HANDLE ConfigurationHandle, IN PNDIS_STRING Keyword, IN PNDIS_CONFIGURATION_PARAMETER ParameterValue)
Definition: config.c:102
static UCHAR UnicodeToHexByte(WCHAR chr)
Definition: config.c:358
VOID EXPORT NdisOpenProtocolConfiguration(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE ConfigurationHandle, IN PNDIS_STRING ProtocolSection)
Definition: config.c:307
static PMINIPORT_CONFIGURATION_CONTEXT AllocateConfigurationContext(_In_ POBJECT_ATTRIBUTES ObjectAttributes)
Definition: config.c:44
VOID EXPORT NdisReadNetworkAddress(OUT PNDIS_STATUS Status, OUT PVOID *NetworkAddress, OUT PUINT NetworkAddressLength, IN NDIS_HANDLE ConfigurationHandle)
Definition: config.c:757
#define PARAMETERS_KEY
Definition: config.c:38
ULONG NdisEnableTxRxFlowControl
Definition: main.c:25
VOID EXPORT NdisOpenConfiguration(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE ConfigurationHandle, IN NDIS_HANDLE WrapperConfigurationContext)
Definition: config.c:254
static BOOLEAN IsValidNumericString(PNDIS_STRING String, ULONG Base)
Definition: config.c:403
VOID EXPORT NdisOpenConfigurationKeyByIndex(OUT PNDIS_STATUS Status, IN NDIS_HANDLE ConfigurationHandle, IN ULONG Index, OUT PNDIS_STRING KeyName, OUT PNDIS_HANDLE KeyHandle)
Definition: config.c:876
VOID EXPORT NdisReadConfiguration(_At_(*Status, _Must_inspect_result_) _Out_ PNDIS_STATUS Status, _Out_ PNDIS_CONFIGURATION_PARAMETER *ParameterValue, _In_ NDIS_HANDLE ConfigurationHandle, _In_ PNDIS_STRING Keyword, _In_ NDIS_PARAMETER_TYPE ParameterType)
Definition: config.c:441
static VOID AddConfigurationParameter(_In_ PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext, _Out_ PMINIPORT_RESOURCE MiniportResource, _In_ ULONG Type, _In_ PVOID ConfigParameter)
Definition: config.c:80
VOID EXPORT NdisInitUnicodeString(IN OUT PNDIS_STRING DestinationString, IN PCWSTR SourceString)
Definition: string.c:130
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define PagedPool
Definition: env_spec_w32.h:308
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
unsigned int UINT
Definition: sysinfo.c:13
return ZwOpenKey(Handle, KEY_READ, &Attributes)
ZwClose(Handle)
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
#define min(a, b)
Definition: monoChain.cc:55
_Must_inspect_result_ _Out_ PNDIS_STATUS _Outptr_result_bytebuffer_to_ NetworkAddressLength PVOID * NetworkAddress
Definition: ndis.h:3958
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_CONFIGURATION_PARAMETER _In_ NDIS_HANDLE _In_ PNDIS_STRING _In_ NDIS_PARAMETER_TYPE ParameterType
Definition: ndis.h:4419
@ NdisParameterBinary
Definition: ndis.h:932
@ NdisParameterInteger
Definition: ndis.h:928
@ NdisParameterString
Definition: ndis.h:930
@ NdisParameterMultiString
Definition: ndis.h:931
@ NdisParameterHexInteger
Definition: ndis.h:929
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4757
unsigned int * PUINT
Definition: ndis.h:50
PVOID NDIS_HANDLE
Definition: ndis.h:338
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
@ NdisProcessorPpc
Definition: ndis.h:888
@ NdisProcessorAlpha
Definition: ndis.h:887
@ NdisProcessorMips
Definition: ndis.h:886
@ NdisProcessorAmd64
Definition: ndis.h:889
@ NdisProcessorArm
Definition: ndis.h:891
@ NdisProcessorArm64
Definition: ndis.h:892
@ NdisProcessorIA64
Definition: ndis.h:890
@ NdisProcessorX86
Definition: ndis.h:885
_Must_inspect_result_ _Out_ PNDIS_STATUS _Outptr_result_bytebuffer_to_ NetworkAddressLength PVOID _Out_ PUINT NetworkAddressLength
Definition: ndis.h:3960
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _In_ NDIS_HANDLE WrapperConfigurationContext
Definition: ndis.h:3948
@ NdisEnvironmentWindowsNt
Definition: ndis.h:897
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE ConfigurationHandle
Definition: ndis.h:3947
enum _NDIS_PARAMETER_TYPE NDIS_PARAMETER_TYPE
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_CONFIGURATION_PARAMETER _In_ NDIS_HANDLE _In_ PNDIS_STRING Keyword
Definition: ndis.h:4418
* PNDIS_STATUS
Definition: ndis.h:45
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4717
_Out_ PNDIS_HANDLE _In_ PNDIS_STRING ProtocolSection
Definition: ndis.h:6075
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define NDIS_VERSION
Definition: ndissys.h:27
#define TAG_CONFIG
Definition: ndissys.h:31
#define _At_(t, a)
Definition: no_sal2.h:40
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
@ KeyBasicInformation
Definition: nt_native.h:1134
#define REG_BINARY
Definition: nt_native.h:1499
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
#define REG_MULTI_SZ
Definition: nt_native.h:1504
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
#define UNICODE_NULL
int NDIS_STATUS
Definition: ntddndis.h:496
short WCHAR
Definition: pedump.c:58
unsigned short USHORT
Definition: pedump.c:61
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
const WCHAR * str
#define REG_DWORD
Definition: sdbapi.c:615
wcsncpy
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
static void Exit(void)
Definition: sock.c:1330
USHORT Length
Definition: ndis.h:936
Definition: typedefs.h:120
BINARY_DATA BinaryData
Definition: ndis.h:945
NDIS_STRING StringData
Definition: ndis.h:944
NDIS_PARAMETER_TYPE ParameterType
Definition: ndis.h:941
union _NDIS_CONFIGURATION_PARAMETER::@2557 ParameterData
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES KeyAttributes
Definition: wdfdevice.h:2666
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439