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.

234 lines
4.8 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. } else {
  43. goto CleanUp;
  44. }
  45. Status=IrdaConnect(
  46. DeviceExtension->TdiObjects,
  47. DeviceExtension->DeviceAddress,
  48. "IrDA:IrCOMM",
  49. DeviceExtension->OutgoingConnection,
  50. &DeviceExtension->ConnectionHandle,
  51. DataAvailibleHandler,
  52. EventNotification,
  53. DeviceExtension
  54. );
  55. D_TRACE(DbgPrint("IRCOMM: Create %08lx\n",Status);)
  56. if (NT_SUCCESS(Status)) {
  57. DeviceExtension->HandFlow.ControlHandShake=SERIAL_DTR_CONTROL | SERIAL_CTS_HANDSHAKE;
  58. DeviceExtension->HandFlow.FlowReplace=SERIAL_RTS_HANDSHAKE;
  59. } else {
  60. //
  61. // could not creat the connection
  62. //
  63. goto CleanUp;
  64. }
  65. Irp->IoStatus.Status=Status;
  66. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  67. return Status;
  68. CleanUp:
  69. //
  70. // something failed, undo what we did in this function
  71. //
  72. if (DeviceExtension->ConnectionHandle != NULL) {
  73. FreeConnection(DeviceExtension->ConnectionHandle);
  74. DeviceExtension->ConnectionHandle=NULL;
  75. }
  76. InterlockedDecrement(&DeviceExtension->OpenCount);
  77. Irp->IoStatus.Status=Status;
  78. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  79. return Status;
  80. }
  81. NTSTATUS
  82. IrCommClose(
  83. PDEVICE_OBJECT DeviceObject,
  84. PIRP Irp
  85. )
  86. {
  87. PFDO_DEVICE_EXTENSION DeviceExtension=(PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  88. NTSTATUS Status=STATUS_SUCCESS;
  89. FreeConnection(DeviceExtension->ConnectionHandle);
  90. DeviceExtension->ConnectionHandle=NULL;
  91. InterlockedDecrement(&DeviceExtension->OpenCount);
  92. Irp->IoStatus.Status=Status;
  93. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  94. return Status;
  95. }
  96. VOID
  97. CleanupIoRequests(
  98. PFDO_DEVICE_EXTENSION DeviceExtension
  99. )
  100. {
  101. KIRQL OldIrql;
  102. PIRP WaitIrp=NULL;
  103. FlushQueuedPackets(&DeviceExtension->Write.Queue,FLUSH_ALL_IRPS);
  104. FlushQueuedPackets(&DeviceExtension->Read.Queue,FLUSH_ALL_IRPS);
  105. ReadPurge(DeviceExtension,0);
  106. FlushQueuedPackets(&DeviceExtension->Mask.Queue,FLUSH_ALL_IRPS);
  107. FlushQueuedPackets(&DeviceExtension->Uart.Queue,FLUSH_ALL_IRPS);
  108. KeAcquireSpinLock(&DeviceExtension->Mask.Lock,&OldIrql);
  109. WaitIrp=DeviceExtension->Mask.CurrentWaitMaskIrp;
  110. DeviceExtension->Mask.CurrentWaitMaskIrp=NULL;
  111. KeReleaseSpinLock(&DeviceExtension->Mask.Lock,OldIrql);
  112. if (WaitIrp != NULL) {
  113. WaitIrp->IoStatus.Status=STATUS_CANCELLED;
  114. WaitIrp->IoStatus.Information=0;
  115. IoCompleteRequest(WaitIrp,IO_NO_INCREMENT);
  116. }
  117. return;
  118. }
  119. NTSTATUS
  120. IrCommCleanup(
  121. PDEVICE_OBJECT DeviceObject,
  122. PIRP Irp
  123. )
  124. {
  125. PFDO_DEVICE_EXTENSION DeviceExtension=(PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  126. NTSTATUS Status=STATUS_SUCCESS;
  127. D_TRACE(DbgPrint("IRCOMM: Cleanup\n");)
  128. CleanupIoRequests(DeviceExtension);
  129. Irp->IoStatus.Status=Status;
  130. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  131. return Status;
  132. }
  133. NTSTATUS
  134. IrCommQueryInformation(
  135. PDEVICE_OBJECT DeviceObject,
  136. PIRP Irp
  137. )
  138. {
  139. PFDO_DEVICE_EXTENSION DeviceExtension=(PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  140. NTSTATUS Status=STATUS_SUCCESS;
  141. Irp->IoStatus.Status=Status;
  142. Irp->IoStatus.Information=0;
  143. IoCompleteRequest(Irp,IO_NO_INCREMENT);
  144. return Status;
  145. }