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.

133 lines
4.5 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. AddDev.c
  8. Abstract:
  9. AddDevice - Create and initialize device object and attach device
  10. object to the device stack.
  11. Environment:
  12. Kernel mode only
  13. Notes:
  14. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  15. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  17. PURPOSE.
  18. Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
  19. Revision History:
  20. 01/18/2000 : created
  21. ToDo in this File:
  22. Author(s):
  23. Doug Fritz (DFritz)
  24. Joby Lafky (JobyL)
  25. ****************************************************************************/
  26. #include "pch.h"
  27. /************************************************************************/
  28. /* AddDevice */
  29. /************************************************************************/
  30. //
  31. // Routine Description:
  32. //
  33. // Create and initialize device object and attach device
  34. // object to the device stack.
  35. //
  36. // Arguments:
  37. //
  38. // DriverObject - pointer to Dot4Usb.sys driver object
  39. // Pdo - pointer to the PDO of the device stack that
  40. // we attach our device object to
  41. //
  42. // Return Value:
  43. //
  44. // NTSTATUS
  45. //
  46. // Log:
  47. // 2000-05-03 Code Reviewed - TomGreen, JobyL, DFritz
  48. //
  49. /************************************************************************/
  50. NTSTATUS
  51. AddDevice(
  52. IN PDRIVER_OBJECT DriverObject,
  53. IN PDEVICE_OBJECT Pdo
  54. )
  55. {
  56. PDEVICE_OBJECT devObj;
  57. NTSTATUS status = IoCreateDevice( DriverObject,
  58. sizeof(DEVICE_EXTENSION),
  59. NULL, // no name
  60. FILE_DEVICE_UNKNOWN,
  61. FILE_DEVICE_SECURE_OPEN,
  62. FALSE, // not exclusive
  63. &devObj );
  64. if( NT_SUCCESS(status) ) {
  65. PDEVICE_OBJECT lowerDevObj = IoAttachDeviceToDeviceStack( devObj, Pdo );
  66. if( lowerDevObj ) {
  67. PDEVICE_EXTENSION devExt = (PDEVICE_EXTENSION)devObj->DeviceExtension;
  68. RtlZeroMemory(devExt, sizeof(DEVICE_EXTENSION));
  69. devExt->LowerDevObj = lowerDevObj; // send IRPs to this device
  70. devExt->Signature1 = DOT4USBTAG; // constant over the lifetime of object
  71. devExt->Signature2 = DOT4USBTAG;
  72. devExt->PnpState = STATE_INITIALIZED;
  73. devExt->DevObj = devObj;
  74. devExt->Pdo = Pdo;
  75. devExt->ResetWorkItemPending=0;
  76. devExt->SystemPowerState = PowerSystemWorking;
  77. devExt->DevicePowerState = PowerDeviceD0;
  78. devExt->CurrentPowerIrp = NULL;
  79. IoInitializeRemoveLock( &devExt->RemoveLock,
  80. DOT4USBTAG,
  81. 5, // MaxLockedMinutes - only used on chk'd builds
  82. 255 ); // HighWaterMark - only used on chk'd builds
  83. KeInitializeSpinLock( &devExt->SpinLock );
  84. KeInitializeEvent( &devExt->PollIrpEvent, NotificationEvent, FALSE );
  85. devObj->Flags |= DO_DIRECT_IO;
  86. devObj->Flags |= ( devExt->LowerDevObj->Flags & DO_POWER_PAGABLE );
  87. devObj->Flags &= ~DO_DEVICE_INITIALIZING; // DO_POWER_PAGABLE must be set appropriately
  88. // before clearing this bit to avoid a bugcheck
  89. } else {
  90. TR_FAIL(("AddDevice - IoAttachDeviceToDeviceStack - FAIL"));
  91. status = STATUS_UNSUCCESSFUL; // for lack of a more appropriate status code
  92. }
  93. } else {
  94. TR_FAIL(("AddDevice - IoCreateDevice - FAIL - status= %x", status));
  95. }
  96. return status;
  97. }