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.

194 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1989, 1990, 1991 Microsoft Corporation
  3. Module Name:
  4. event.c
  5. Abstract:
  6. This module contains code which performs the following TDI services:
  7. o TdiSetEventHandler
  8. Author:
  9. David Beaver (dbeaver) 1-July-1991
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. NTSTATUS
  17. NbfTdiSetEventHandler(
  18. IN PIRP Irp
  19. )
  20. /*++
  21. Routine Description:
  22. This routine performs the TdiSetEventHandler request for the
  23. transport provider. The caller (request dispatcher) verifies
  24. that this routine will not be executed on behalf of a user-mode
  25. client, as this request enables direct callouts at DISPATCH_LEVEL.
  26. Arguments:
  27. Irp - Pointer to the IRP for this request
  28. Return Value:
  29. NTSTATUS - status of operation.
  30. --*/
  31. {
  32. NTSTATUS rc=STATUS_SUCCESS;
  33. KIRQL oldirql;
  34. PTDI_REQUEST_KERNEL_SET_EVENT parameters;
  35. PIO_STACK_LOCATION irpSp;
  36. PTP_ADDRESS address;
  37. PTP_ADDRESS_FILE addressFile;
  38. NTSTATUS status;
  39. //
  40. // Get the Address this is associated with; if there is none, get out.
  41. //
  42. irpSp = IoGetCurrentIrpStackLocation (Irp);
  43. if (irpSp->FileObject->FsContext2 != (PVOID) TDI_TRANSPORT_ADDRESS_FILE) {
  44. return STATUS_INVALID_ADDRESS;
  45. }
  46. addressFile = irpSp->FileObject->FsContext;
  47. status = NbfVerifyAddressObject (addressFile);
  48. if (!NT_SUCCESS (status)) {
  49. return status;
  50. }
  51. address = addressFile->Address;
  52. ACQUIRE_SPIN_LOCK (&address->SpinLock, &oldirql);
  53. parameters = (PTDI_REQUEST_KERNEL_SET_EVENT)&irpSp->Parameters;
  54. switch (parameters->EventType) {
  55. case TDI_EVENT_RECEIVE:
  56. if (parameters->EventHandler == NULL) {
  57. addressFile->ReceiveHandler =
  58. (PTDI_IND_RECEIVE)TdiDefaultReceiveHandler;
  59. addressFile->ReceiveHandlerContext = NULL;
  60. addressFile->RegisteredReceiveHandler = FALSE;
  61. } else {
  62. addressFile->ReceiveHandler =
  63. (PTDI_IND_RECEIVE)parameters->EventHandler;
  64. addressFile->ReceiveHandlerContext = parameters->EventContext;
  65. addressFile->RegisteredReceiveHandler = TRUE;
  66. }
  67. break;
  68. case TDI_EVENT_RECEIVE_EXPEDITED:
  69. if (parameters->EventHandler == NULL) {
  70. addressFile->ExpeditedDataHandler =
  71. (PTDI_IND_RECEIVE_EXPEDITED)TdiDefaultRcvExpeditedHandler;
  72. addressFile->ExpeditedDataHandlerContext = NULL;
  73. addressFile->RegisteredExpeditedDataHandler = FALSE;
  74. } else {
  75. addressFile->ExpeditedDataHandler =
  76. (PTDI_IND_RECEIVE_EXPEDITED)parameters->EventHandler;
  77. addressFile->ExpeditedDataHandlerContext = parameters->EventContext;
  78. addressFile->RegisteredExpeditedDataHandler = TRUE;
  79. }
  80. break;
  81. case TDI_EVENT_RECEIVE_DATAGRAM:
  82. if (parameters->EventHandler == NULL) {
  83. addressFile->ReceiveDatagramHandler =
  84. (PTDI_IND_RECEIVE_DATAGRAM)TdiDefaultRcvDatagramHandler;
  85. addressFile->ReceiveDatagramHandlerContext = NULL;
  86. addressFile->RegisteredReceiveDatagramHandler = FALSE;
  87. } else {
  88. addressFile->ReceiveDatagramHandler =
  89. (PTDI_IND_RECEIVE_DATAGRAM)parameters->EventHandler;
  90. addressFile->ReceiveDatagramHandlerContext = parameters->EventContext;
  91. addressFile->RegisteredReceiveDatagramHandler = TRUE;
  92. }
  93. break;
  94. case TDI_EVENT_ERROR:
  95. if (parameters->EventHandler == NULL) {
  96. addressFile->ErrorHandler =
  97. (PTDI_IND_ERROR)TdiDefaultErrorHandler;
  98. addressFile->ErrorHandlerContext = NULL;
  99. addressFile->RegisteredErrorHandler = FALSE;
  100. } else {
  101. addressFile->ErrorHandler =
  102. (PTDI_IND_ERROR)parameters->EventHandler;
  103. addressFile->ErrorHandlerContext = parameters->EventContext;
  104. addressFile->RegisteredErrorHandler = TRUE;
  105. }
  106. break;
  107. case TDI_EVENT_DISCONNECT:
  108. if (parameters->EventHandler == NULL) {
  109. addressFile->DisconnectHandler =
  110. (PTDI_IND_DISCONNECT)TdiDefaultDisconnectHandler;
  111. addressFile->DisconnectHandlerContext = NULL;
  112. addressFile->RegisteredDisconnectHandler = FALSE;
  113. } else {
  114. addressFile->DisconnectHandler =
  115. (PTDI_IND_DISCONNECT)parameters->EventHandler;
  116. addressFile->DisconnectHandlerContext = parameters->EventContext;
  117. addressFile->RegisteredDisconnectHandler = TRUE;
  118. }
  119. break;
  120. case TDI_EVENT_CONNECT:
  121. if (parameters->EventHandler == NULL) {
  122. addressFile->ConnectionHandler =
  123. (PTDI_IND_CONNECT)TdiDefaultConnectHandler;
  124. addressFile->ConnectionHandlerContext = NULL;
  125. addressFile->RegisteredConnectionHandler = FALSE;
  126. } else {
  127. addressFile->ConnectionHandler =
  128. (PTDI_IND_CONNECT)parameters->EventHandler;
  129. addressFile->ConnectionHandlerContext = parameters->EventContext;
  130. addressFile->RegisteredConnectionHandler = TRUE;
  131. }
  132. break;
  133. default:
  134. rc = STATUS_INVALID_PARAMETER;
  135. } /* switch */
  136. RELEASE_SPIN_LOCK (&address->SpinLock, oldirql);
  137. NbfDereferenceAddress ("Set event handler", address, AREF_VERIFY);
  138. return rc;
  139. } /* TdiSetEventHandler */
  140.