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.

229 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. openclos.c
  5. Abstract:
  6. This module contains the code that is very specific to initialization
  7. and unload operations in the irenum driver
  8. Author:
  9. Brian Lieuallen, 7-13-2000
  10. Environment:
  11. Kernel mode
  12. Revision History :
  13. --*/
  14. #include "internal.h"
  15. #include "ircomm.h"
  16. NTSTATUS
  17. IrCommCreate(
  18. PDEVICE_OBJECT DeviceObject,
  19. PIRP Irp
  20. )
  21. {
  22. NTSTATUS Status=STATUS_SUCCESS;
  23. IRDA_HANDLE Handle;
  24. PFDO_DEVICE_EXTENSION DeviceExtension=(PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  25. UCHAR ControlBuffer[4];
  26. IRCOMM_BUS_INFO BusInfo;
  27. if (InterlockedIncrement(&DeviceExtension->OpenCount) > 1) {
  28. D_ERROR(DbgPrint("IRCOMM: Create already open\n");)
  29. InterlockedDecrement(&DeviceExtension->OpenCount);
  30. Irp->IoStatus.Status=STATUS_ACCESS_DENIED;
  31. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  32. return STATUS_ACCESS_DENIED;
  33. }
  34. Status=QueryPdoInformation(
  35. DeviceExtension->Pdo,
  36. IRENUM_CONFIG_SPACE_INFO,
  37. &BusInfo,
  38. sizeof(BusInfo)
  39. );
  40. if (NT_SUCCESS(Status)) {
  41. DeviceExtension->DeviceAddress=BusInfo.DeviceAddress;
  42. }
  43. Status=IrdaConnect(
  44. DeviceExtension->DeviceAddress,
  45. "IrDA:IrCOMM",
  46. BusInfo.OutGoingConnection,
  47. &DeviceExtension->ConnectionHandle,
  48. DataAvailibleHandler,
  49. EventNotification,
  50. DeviceExtension
  51. );
  52. D_TRACE(DbgPrint("IRCOMM: Create %08lx\n",Status);)
  53. if (NT_SUCCESS(Status)) {
  54. DeviceExtension->HandFlow.ControlHandShake=SERIAL_DTR_CONTROL | SERIAL_CTS_HANDSHAKE;
  55. DeviceExtension->HandFlow.FlowReplace=SERIAL_RTS_HANDSHAKE;
  56. } else {
  57. //
  58. // could not creat the connection
  59. //
  60. goto CleanUp;
  61. }
  62. Irp->IoStatus.Status=Status;
  63. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  64. return Status;
  65. CleanUp:
  66. //
  67. // something failed, undo what we did in this function
  68. //
  69. if (DeviceExtension->ConnectionHandle != NULL) {
  70. FreeConnection(DeviceExtension->ConnectionHandle);
  71. DeviceExtension->ConnectionHandle=NULL;
  72. }
  73. InterlockedDecrement(&DeviceExtension->OpenCount);
  74. Irp->IoStatus.Status=Status;
  75. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  76. return Status;
  77. }
  78. NTSTATUS
  79. IrCommClose(
  80. PDEVICE_OBJECT DeviceObject,
  81. PIRP Irp
  82. )
  83. {
  84. PFDO_DEVICE_EXTENSION DeviceExtension=(PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  85. NTSTATUS Status=STATUS_SUCCESS;
  86. FreeConnection(DeviceExtension->ConnectionHandle);
  87. DeviceExtension->ConnectionHandle=NULL;
  88. InterlockedDecrement(&DeviceExtension->OpenCount);
  89. Irp->IoStatus.Status=Status;
  90. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  91. return Status;
  92. }
  93. VOID
  94. CleanupIoRequests(
  95. PFDO_DEVICE_EXTENSION DeviceExtension
  96. )
  97. {
  98. KIRQL OldIrql;
  99. PIRP WaitIrp=NULL;
  100. FlushQueuedPackets(&DeviceExtension->Write.Queue,FLUSH_ALL_IRPS);
  101. FlushQueuedPackets(&DeviceExtension->Read.Queue,FLUSH_ALL_IRPS);
  102. ReadPurge(DeviceExtension,0);
  103. FlushQueuedPackets(&DeviceExtension->Mask.Queue,FLUSH_ALL_IRPS);
  104. FlushQueuedPackets(&DeviceExtension->Uart.Queue,FLUSH_ALL_IRPS);
  105. KeAcquireSpinLock(&DeviceExtension->Mask.Lock,&OldIrql);
  106. WaitIrp=DeviceExtension->Mask.CurrentWaitMaskIrp;
  107. DeviceExtension->Mask.CurrentWaitMaskIrp=NULL;
  108. KeReleaseSpinLock(&DeviceExtension->Mask.Lock,OldIrql);
  109. if (WaitIrp != NULL) {
  110. WaitIrp->IoStatus.Status=STATUS_CANCELLED;
  111. WaitIrp->IoStatus.Information=0;
  112. IoCompleteRequest(WaitIrp,IO_NO_INCREMENT);
  113. }
  114. return;
  115. }
  116. NTSTATUS
  117. IrCommCleanup(
  118. PDEVICE_OBJECT DeviceObject,
  119. PIRP Irp
  120. )
  121. {
  122. PFDO_DEVICE_EXTENSION DeviceExtension=(PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  123. NTSTATUS Status=STATUS_SUCCESS;
  124. D_TRACE(DbgPrint("IRCOMM: Cleanup\n");)
  125. CleanupIoRequests(DeviceExtension);
  126. Irp->IoStatus.Status=Status;
  127. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  128. return Status;
  129. }
  130. NTSTATUS
  131. IrCommQueryInformation(
  132. PDEVICE_OBJECT DeviceObject,
  133. PIRP Irp
  134. )
  135. {
  136. PFDO_DEVICE_EXTENSION DeviceExtension=(PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  137. NTSTATUS Status=STATUS_SUCCESS;
  138. Irp->IoStatus.Status=Status;
  139. Irp->IoStatus.Information=0;
  140. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  141. return Status;
  142. }