Leaked source code of windows server 2003
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.

209 lines
7.2 KiB

  1. /***************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Dot4Usb.sys - Lower Filter Driver for Dot4.sys for USB connected
  5. IEEE 1284.4 devices.
  6. File Name:
  7. InitUnld.c
  8. Abstract:
  9. Driver globals, initialization (DriverEntry) and Unload routines
  10. Environment:
  11. Kernel mode only
  12. Notes:
  13. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  14. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  16. PURPOSE.
  17. Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
  18. Revision History:
  19. 01/18/2000 : created
  20. ToDo in this file:
  21. - code review w/Joby
  22. Author(s):
  23. Doug Fritz (DFritz)
  24. Joby Lafky (JobyL)
  25. ****************************************************************************/
  26. #include "pch.h"
  27. //
  28. // Globals
  29. //
  30. UNICODE_STRING gRegistryPath = {0,0,0}; // yes globals are automatically initialized
  31. ULONG gTrace = 0; // to 0's, but let's be explicit.
  32. ULONG gBreak = 0;
  33. /************************************************************************/
  34. /* DriverEntry */
  35. /************************************************************************/
  36. //
  37. // Routine Description:
  38. //
  39. // - Save a copy of RegistryPath in a global gRegistryPath for use
  40. // throughout the lifetime of the driver load.
  41. //
  42. // - Initialize DriverObject function pointer table to point to
  43. // our entry points.
  44. //
  45. // - Initialize Debug globals gTrace and gBreak based on registry
  46. // settings.
  47. //
  48. // Arguments:
  49. //
  50. // DriverObject - pointer to Dot4Usb.sys driver object
  51. // RegistryPath - pointer to RegistryPath for the driver, expected
  52. // to be of the form (ControlSet may vary):
  53. // \REGISTRY\MACHINE\SYSTEM\ControlSet001\Services\dot4usb
  54. //
  55. // Return Value:
  56. //
  57. // NTSTATUS
  58. //
  59. // Log:
  60. // 2000-05-03 Code Reviewed - TomGreen, JobyL, DFritz
  61. //
  62. /************************************************************************/
  63. NTSTATUS
  64. DriverEntry(
  65. IN PDRIVER_OBJECT DriverObject,
  66. IN PUNICODE_STRING RegistryPath
  67. )
  68. {
  69. NTSTATUS status = STATUS_SUCCESS;
  70. //
  71. // Save a copy of RegistryPath in global gRegistryPath for use
  72. // over the lifetime of the driver load.
  73. // - UNICODE_NULL terminate gRegistryPath.Buffer for added flexibility.
  74. // - gRegistryPath.Buffer should be freed in DriverUnload()
  75. //
  76. { // new scope for gRegistryPath initialization - begin
  77. USHORT newMaxLength = (USHORT)(RegistryPath->Length + sizeof(WCHAR));
  78. PWSTR p = ExAllocatePool( PagedPool, newMaxLength );
  79. if( p ) {
  80. gRegistryPath.Length = 0;
  81. gRegistryPath.MaximumLength = newMaxLength;
  82. gRegistryPath.Buffer = p;
  83. RtlCopyUnicodeString( &gRegistryPath, RegistryPath );
  84. gRegistryPath.Buffer[ gRegistryPath.Length/2 ] = UNICODE_NULL;
  85. } else {
  86. TR_FAIL(("DriverEntry - exit - FAIL - no Pool for gRegistryPath.Buffer"));
  87. status = STATUS_INSUFFICIENT_RESOURCES;
  88. goto targetExit;
  89. }
  90. } // new scope for gRegistryPath initialization - end
  91. //
  92. // Initialize DriverObject function pointer table to point to our entry points.
  93. //
  94. // Start by initializing dispatch table to point to our passthrough function and
  95. // then override the entry points that we actually handle.
  96. //
  97. {// new scope for index variable - begin
  98. ULONG i;
  99. for( i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++ ) {
  100. DriverObject->MajorFunction[i] = DispatchPassThrough;
  101. }
  102. } // new scope for index variable - end
  103. DriverObject->MajorFunction[ IRP_MJ_PNP ] = DispatchPnp;
  104. DriverObject->MajorFunction[ IRP_MJ_POWER ] = DispatchPower;
  105. DriverObject->MajorFunction[ IRP_MJ_CREATE ] = DispatchCreate;
  106. DriverObject->MajorFunction[ IRP_MJ_CLOSE ] = DispatchClose;
  107. DriverObject->MajorFunction[ IRP_MJ_READ ] = DispatchRead;
  108. DriverObject->MajorFunction[ IRP_MJ_WRITE ] = DispatchWrite;
  109. DriverObject->MajorFunction[ IRP_MJ_DEVICE_CONTROL ] = DispatchDeviceControl;
  110. DriverObject->MajorFunction[ IRP_MJ_INTERNAL_DEVICE_CONTROL ] = DispatchInternalDeviceControl;
  111. DriverObject->DriverExtension->AddDevice = AddDevice;
  112. DriverObject->DriverUnload = DriverUnload;
  113. //
  114. // Get driver debug settings (gTrace, gBreak) from registry
  115. //
  116. // Expected Key Path is of the form (ControlSet may vary):
  117. //
  118. // \REGISTRY\MACHINE\SYSTEM\ControlSet001\Services\dot4usb
  119. //
  120. RegGetDword( gRegistryPath.Buffer, (PCWSTR)L"gBreak", &gBreak );
  121. RegGetDword( gRegistryPath.Buffer, (PCWSTR)L"gTrace", &gTrace );
  122. TR_LD_UNLD(("DriverEntry - RegistryPath = <%wZ>", RegistryPath));
  123. TR_LD_UNLD(("DriverEntry - gBreak=%x", gBreak));
  124. TR_LD_UNLD(("DriverEntry - gTrace=%x", gTrace));
  125. //
  126. // Check if user requested a breakpoint here. A breakpoint herew is
  127. // typically used so that we can insert breakpoints on other
  128. // functions or change debug settings to differ from those that we
  129. // just read from the registry.
  130. //
  131. if( gBreak & BREAK_ON_DRIVER_ENTRY ) {
  132. DbgPrint( "D4U: Breakpoint requested via registry setting - (gBreak & BREAK_ON_DRIVER_ENTRY)\n" );
  133. DbgBreakPoint();
  134. }
  135. targetExit:
  136. return status;
  137. }
  138. /************************************************************************/
  139. /* DriverUnload */
  140. /************************************************************************/
  141. //
  142. // Routine Description:
  143. //
  144. // - Free any copy of RegistryPath that might have been saved in
  145. // global gRegistryPath during DriverEntry().
  146. //
  147. // Arguments:
  148. //
  149. // DriverObject - pointer to Dot4Usb.sys driver object
  150. //
  151. // Return Value:
  152. //
  153. // NONE
  154. //
  155. // Log:
  156. // 2000-05-03 Code Reviewed - TomGreen, JobyL, DFritz
  157. //
  158. /************************************************************************/
  159. VOID
  160. DriverUnload(
  161. IN PDRIVER_OBJECT DriverObject
  162. )
  163. {
  164. UNREFERENCED_PARAMETER( DriverObject );
  165. TR_LD_UNLD(("DriverUnload"));
  166. if( gRegistryPath.Buffer ) {
  167. RtlFreeUnicodeString( &gRegistryPath );
  168. }
  169. }