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.

250 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. Module Name:
  4. Tapi.c
  5. Abstract:
  6. Author:
  7. Tony Bell (TonyBe) June 06, 1995
  8. Environment:
  9. Kernel Mode
  10. Revision History:
  11. TonyBe 06/06/95 Created
  12. --*/
  13. //
  14. // We want to initialize all of the global variables now!
  15. //
  16. #include "wan.h"
  17. #define __FILE_SIG__ TAPI_FILESIG
  18. ULONG gulNdistapiMissedCount = 0;
  19. EXPORT
  20. VOID
  21. NdisTapiCompleteRequest(
  22. IN NDIS_HANDLE Handle,
  23. IN PVOID NdisRequest,
  24. IN NDIS_STATUS Status
  25. );
  26. EXPORT
  27. VOID
  28. NdisTapiIndicateStatus(
  29. IN NDIS_HANDLE Handle,
  30. IN PVOID StatusBuffer,
  31. IN UINT StatusBufferSize
  32. );
  33. NDIS_STATUS
  34. NdisWanTapiRequestProc(
  35. HANDLE NdisTapiKey,
  36. PNDIS_REQUEST NdisRequest
  37. )
  38. /*++
  39. Routine Name:
  40. NdisWanTapiRequestProc
  41. Routine Description:
  42. Procedure is called by the NdisTapi.sys driver to send
  43. requests to the WanMiniport driver. We intercept this
  44. just to moderate. NdisTapi could call the miniport directly
  45. if we wanted but we don't.
  46. Arguments:
  47. Return Values:
  48. --*/
  49. {
  50. NDIS_STATUS Status;
  51. PWAN_REQUEST WanRequest;
  52. PNDIS_REQUEST MyNdisRequest;
  53. POPENCB OpenCB = NULL;
  54. OPENCB *pOpenCBTemp;
  55. LIST_ENTRY *pEntry;
  56. NdisWanDbgOut(DBG_TRACE, DBG_TAPI, ("NdisWanTapiRequestProc - Enter"));
  57. NdisWanDbgOut(DBG_INFO, DBG_TAPI, ("NdisRequest: Type: 0x%x OID: 0x%x",
  58. NdisRequest->RequestType,NdisRequest->DATA.QUERY_INFORMATION.Oid));
  59. //
  60. // Map the NdisTapiKey to OpenCB
  61. //
  62. NdisAcquireSpinLock(&OpenCBList.Lock);
  63. for(pEntry = OpenCBList.List.Flink;
  64. pEntry != &OpenCBList.List;
  65. pEntry = pEntry->Flink)
  66. {
  67. pOpenCBTemp = CONTAINING_RECORD(pEntry, OPENCB, Linkage);
  68. if( (NULL != pOpenCBTemp->NdisTapiKey)
  69. && (pOpenCBTemp->NdisTapiKey == NdisTapiKey))
  70. {
  71. OpenCB = pOpenCBTemp;
  72. break;
  73. }
  74. }
  75. if(OpenCB == NULL)
  76. {
  77. //
  78. // Miniport is already removed from the list.
  79. //
  80. NdisReleaseSpinLock(&OpenCBList.Lock);
  81. NdisWanInterlockedInc(&gulNdistapiMissedCount);
  82. return NDIS_STATUS_FAILURE;
  83. }
  84. //
  85. // Take a ref on the opencb and release locks.
  86. //
  87. NdisAcquireSpinLock(&OpenCB->Lock);
  88. if (OpenCB->Flags & OPEN_CLOSING) {
  89. NdisReleaseSpinLock(&OpenCB->Lock);
  90. NdisReleaseSpinLock(&OpenCBList.Lock);
  91. return (NDIS_STATUS_FAILURE);
  92. }
  93. REF_OPENCB(OpenCB);
  94. NdisReleaseSpinLock(&OpenCB->Lock);
  95. NdisReleaseSpinLock(&OpenCBList.Lock);
  96. WanRequest =
  97. NdisAllocateFromNPagedLookasideList(&WanRequestList);
  98. if (WanRequest == NULL) {
  99. DEREF_OPENCB(OpenCB);
  100. return (NDIS_STATUS_RESOURCES);
  101. }
  102. WanRequest->Type = ASYNC;
  103. WanRequest->Origin = NDISTAPI;
  104. WanRequest->OpenCB = OpenCB;
  105. WanRequest->OriginalRequest = NdisRequest;
  106. NdisWanInitializeNotificationEvent(&WanRequest->NotificationEvent);
  107. MyNdisRequest = &WanRequest->NdisRequest;
  108. MyNdisRequest->RequestType =
  109. NdisRequest->RequestType;
  110. if (NdisRequest->RequestType == NdisRequestQueryInformation) {
  111. MyNdisRequest->DATA.QUERY_INFORMATION.Oid =
  112. NdisRequest->DATA.QUERY_INFORMATION.Oid;
  113. MyNdisRequest->DATA.QUERY_INFORMATION.InformationBuffer =
  114. NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer;
  115. MyNdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength =
  116. NdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength;
  117. MyNdisRequest->DATA.QUERY_INFORMATION.BytesWritten =
  118. NdisRequest->DATA.QUERY_INFORMATION.BytesWritten;
  119. } else if (NdisRequest->RequestType == NdisRequestSetInformation) {
  120. MyNdisRequest->DATA.SET_INFORMATION.Oid =
  121. NdisRequest->DATA.SET_INFORMATION.Oid;
  122. MyNdisRequest->DATA.SET_INFORMATION.InformationBuffer =
  123. NdisRequest->DATA.SET_INFORMATION.InformationBuffer;
  124. MyNdisRequest->DATA.SET_INFORMATION.InformationBufferLength =
  125. NdisRequest->DATA.SET_INFORMATION.InformationBufferLength;
  126. MyNdisRequest->DATA.SET_INFORMATION.BytesRead =
  127. NdisRequest->DATA.SET_INFORMATION.BytesRead;
  128. }
  129. Status = NdisWanSubmitNdisRequest(OpenCB, WanRequest);
  130. NdisWanDbgOut(DBG_INFO, DBG_TAPI, ("Status: 0x%x", Status));
  131. NdisWanDbgOut(DBG_TRACE, DBG_TAPI, ("NdisWanTapiRequestProc - Exit"));
  132. DEREF_OPENCB(OpenCB);
  133. return (Status);
  134. }
  135. VOID
  136. NdisWanTapiRequestComplete(
  137. POPENCB OpenCB,
  138. PWAN_REQUEST WanRequest
  139. )
  140. {
  141. PNDIS_REQUEST NdisRequest, MyNdisRequest;
  142. NdisWanDbgOut(DBG_TRACE, DBG_TAPI,
  143. ("NdisWanTapiRequestComplete - Enter"));
  144. NdisRequest = WanRequest->OriginalRequest;
  145. MyNdisRequest = &WanRequest->NdisRequest;
  146. if (NdisRequest->RequestType == NdisRequestQueryInformation) {
  147. NdisRequest->DATA.QUERY_INFORMATION.BytesWritten =
  148. MyNdisRequest->DATA.QUERY_INFORMATION.BytesWritten;
  149. } else if (NdisRequest->RequestType == NdisRequestSetInformation) {
  150. NdisRequest->DATA.SET_INFORMATION.BytesRead =
  151. MyNdisRequest->DATA.SET_INFORMATION.BytesRead;
  152. }
  153. NdisWanDbgOut(DBG_INFO, DBG_TAPI,
  154. ("NdisRequest: Type: 0x%x OID: 0x%x",
  155. NdisRequest->RequestType,
  156. NdisRequest->DATA.QUERY_INFORMATION.Oid));
  157. NdisWanDbgOut(DBG_INFO, DBG_TAPI,
  158. ("Status: 0x%x", WanRequest->NotificationStatus));
  159. NdisTapiCompleteRequest(OpenCB->NdisTapiKey,
  160. NdisRequest,
  161. WanRequest->NotificationStatus);
  162. NdisFreeToNPagedLookasideList(&WanRequestList, WanRequest);
  163. }
  164. VOID
  165. NdisWanTapiIndication(
  166. POPENCB OpenCB,
  167. PUCHAR StatusBuffer,
  168. ULONG StatusBufferSize
  169. )
  170. /*++
  171. Routine Name:
  172. Routine Description:
  173. Arguments:
  174. Return Values:
  175. --*/
  176. {
  177. NdisWanDbgOut(DBG_TRACE, DBG_TAPI, ("NdisWanTapiIndication - Enter"));
  178. //
  179. // If tapi is present and this miniport has registered for
  180. // connectionwrapper services give this to tapi
  181. //
  182. if (OpenCB->WanInfo.FramingBits & TAPI_PROVIDER) {
  183. NdisTapiIndicateStatus(OpenCB,
  184. StatusBuffer,
  185. StatusBufferSize);
  186. }
  187. NdisWanDbgOut(DBG_TRACE, DBG_TAPI, ("NdisWanTapiIndication - Exit"));
  188. }