Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.1 KiB

  1. #include <ntddk.h>
  2. #include "devdesc.h"
  3. #ifdef PNP_IDENTIFY
  4. #ifdef ALLOC_PRAGMA
  5. #pragma alloc_text(INIT,LinkDeviceToDescription)
  6. #endif
  7. NTSTATUS
  8. LinkDeviceToDescription(
  9. IN PUNICODE_STRING RegistryPath,
  10. IN PUNICODE_STRING DeviceName,
  11. IN INTERFACE_TYPE BusType,
  12. IN ULONG BusNumber,
  13. IN CONFIGURATION_TYPE ControllerType,
  14. IN ULONG ControllerNumber,
  15. IN CONFIGURATION_TYPE PeripheralType,
  16. IN ULONG PeripheralNumber
  17. )
  18. {
  19. //
  20. // This routine will create a volatile "Description" key under the
  21. // drivers service key. It will store values of the following form
  22. // in that key:
  23. //
  24. // \\Device\\PointerPortX:REG_BINARY:...
  25. // \\Device\\KeyboardPortX:REG_BINARY:...
  26. //
  27. // Where the binary data is six ULONG values (passed as parameters
  28. // to this routine) that describe the physical location of the device.
  29. //
  30. NTSTATUS Status = STATUS_SUCCESS;
  31. HANDLE ServiceKey = NULL, DescriptionKey = NULL;
  32. UNICODE_STRING RegString;
  33. OBJECT_ATTRIBUTES ObjectAttributes;
  34. ULONG disposition;
  35. HWDESC_INFO HwDescInfo;
  36. HwDescInfo.InterfaceType = BusType;
  37. HwDescInfo.InterfaceNumber = BusNumber;
  38. HwDescInfo.ControllerType = ControllerType;
  39. HwDescInfo.ControllerNumber = ControllerNumber;
  40. HwDescInfo.PeripheralType = PeripheralType;
  41. HwDescInfo.PeripheralNumber = PeripheralNumber;
  42. //
  43. // Open the service subkey
  44. //
  45. InitializeObjectAttributes(&ObjectAttributes,
  46. RegistryPath,
  47. OBJ_CASE_INSENSITIVE,
  48. NULL,
  49. NULL);
  50. Status = ZwOpenKey(&ServiceKey,
  51. KEY_WRITE,
  52. &ObjectAttributes);
  53. if (!NT_SUCCESS(Status)) {
  54. goto Clean0;
  55. }
  56. //
  57. // Create a volatile Description subkey under the service subkey
  58. //
  59. RtlInitUnicodeString(&RegString, L"Description");
  60. InitializeObjectAttributes(&ObjectAttributes,
  61. &RegString,
  62. OBJ_CASE_INSENSITIVE,
  63. ServiceKey,
  64. NULL);
  65. Status = ZwCreateKey(&DescriptionKey,
  66. KEY_ALL_ACCESS,
  67. &ObjectAttributes,
  68. 0,
  69. (PUNICODE_STRING)NULL,
  70. REG_OPTION_VOLATILE,
  71. &disposition);
  72. if (!NT_SUCCESS(Status)) {
  73. goto Clean0;
  74. }
  75. //
  76. // The description data is stored under a REG_BINARY value (name
  77. // is the DeviceName passed in as a parameter)
  78. //
  79. Status = ZwSetValueKey(DescriptionKey,
  80. DeviceName,
  81. 0,
  82. REG_BINARY,
  83. &HwDescInfo,
  84. sizeof(HwDescInfo));
  85. Clean0:
  86. if (DescriptionKey) {
  87. ZwClose(DescriptionKey);
  88. }
  89. if (ServiceKey) {
  90. ZwClose(ServiceKey);
  91. }
  92. return Status;
  93. }
  94. #endif