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.

218 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. nbflog.c
  5. Abstract:
  6. This module contains code which performs various logging activities:
  7. o NbfLogRcvPacket
  8. o NbfLogSndPacket
  9. Author:
  10. Chaitanya Kodeboyina 27-April-1998
  11. Environment:
  12. Kernel mode
  13. Revision History:
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. #if PKT_LOG
  18. VOID
  19. NbfLogRcvPacket(
  20. PTP_CONNECTION Connection,
  21. PTP_LINK Link,
  22. PUCHAR Header,
  23. UINT TotalLength,
  24. UINT AvailLength
  25. )
  26. {
  27. PKT_LOG_QUE *PktLogQueue;
  28. PKT_LOG_ELM *PktLogItem;
  29. ULONG BytesSaved;
  30. LARGE_INTEGER TickCounts;
  31. if (Connection == NULL) {
  32. PktLogQueue = &Link->LastNRecvs;
  33. IF_NBFDBG (NBF_DEBUG_PKTLOG) {
  34. DbgPrint("Logging Recv Packet on LNK %08x: Hdr: %08x, TLen: %5d, ILen: %5d\n",
  35. Link,
  36. Header, TotalLength, AvailLength);
  37. }
  38. }
  39. else {
  40. PktLogQueue = &Connection->LastNRecvs;
  41. IF_NBFDBG (NBF_DEBUG_PKTLOG) {
  42. DbgPrint("Logging Recv Packet on CON %08x: Hdr: %08x, TLen: %5d, ILen: %5d\n",
  43. Connection,
  44. Header, TotalLength, AvailLength);
  45. }
  46. }
  47. PktLogItem = &PktLogQueue->PktQue[PktLogQueue->PktNext++];
  48. PktLogQueue->PktNext %= PKT_QUE_SIZE;
  49. KeQueryTickCount(&TickCounts);
  50. PktLogItem->TimeLogged = (USHORT) TickCounts.LowPart;
  51. PktLogItem->BytesTotal = (USHORT) TotalLength;
  52. PktLogItem->BytesSaved = (USHORT) AvailLength;
  53. BytesSaved = AvailLength > PKT_LOG_SIZE ?
  54. PKT_LOG_SIZE :
  55. AvailLength;
  56. RtlCopyMemory (PktLogItem->PacketData,
  57. Header,
  58. BytesSaved);
  59. }
  60. VOID
  61. NbfLogSndPacket(
  62. PTP_LINK Link,
  63. PTP_PACKET Packet
  64. )
  65. {
  66. PKT_LOG_QUE *PktLogQueue;
  67. PKT_LOG_ELM *PktLogItem;
  68. LARGE_INTEGER TickCounts;
  69. PTP_CONNECTION Connection;
  70. ULONG BytesSaved;
  71. // Check if this is a packet on a connection
  72. switch (Packet->Action) {
  73. case PACKET_ACTION_CONNECTION:
  74. case PACKET_ACTION_END:
  75. ASSERT(Packet->Owner != NULL);
  76. Connection = Packet->Owner;
  77. break;
  78. case PACKET_ACTION_IRP_SP:
  79. ASSERT(Packet->Owner != NULL);
  80. Connection = IRP_SEND_CONNECTION((PIO_STACK_LOCATION)(Packet->Owner));
  81. break;
  82. case PACKET_ACTION_NULL:
  83. case PACKET_ACTION_RR:
  84. Connection = NULL;
  85. break;
  86. default:
  87. Connection = NULL;
  88. IF_NBFDBG (NBF_DEBUG_PKTLOG) {
  89. PVOID Caller1, Caller2;
  90. RtlGetCallersAddress(&Caller1, &Caller2);
  91. DbgPrint("Callers: @1: %08x, @2: %08x\n",
  92. Caller1, Caller2);
  93. }
  94. ASSERT(FALSE);
  95. }
  96. if (Connection == NULL) {
  97. PktLogQueue = &Link->LastNSends;
  98. BytesSaved = sizeof(DLC_S_FRAME);
  99. IF_NBFDBG (NBF_DEBUG_PKTLOG) {
  100. DbgPrint("Logging Send Packet on LNK %08x: Hdr: %08x, TLen: %5d, ILen: %5d\n",
  101. Link, &Packet->Header, Packet->NdisIFrameLength, BytesSaved);
  102. }
  103. }
  104. else {
  105. // Make sure connection is on this link
  106. ASSERT(Connection->Link == Link);
  107. PktLogQueue = &Connection->LastNSends;
  108. BytesSaved = sizeof(DLC_I_FRAME) + sizeof(NBF_HDR_CONNECTION);
  109. IF_NBFDBG (NBF_DEBUG_PKTLOG) {
  110. DbgPrint("Logging Send Packet on CON %08x: Hdr: %08x, TLen: %5d, ILen: %5d\n",
  111. Connection, &Packet->Header, Packet->NdisIFrameLength, BytesSaved);
  112. }
  113. }
  114. PktLogItem = &PktLogQueue->PktQue[PktLogQueue->PktNext++];
  115. PktLogQueue->PktNext %= PKT_QUE_SIZE;
  116. PktLogItem->BytesTotal = (USHORT) Packet->NdisIFrameLength;
  117. RtlCopyMemory (PktLogItem->PacketData,
  118. &Packet->Header[Link->HeaderLength],
  119. BytesSaved);
  120. PktLogItem->BytesSaved = (USHORT) BytesSaved;
  121. KeQueryTickCount(&TickCounts);
  122. PktLogItem->TimeLogged = (USHORT) TickCounts.LowPart;
  123. }
  124. VOID
  125. NbfLogIndPacket(
  126. PTP_CONNECTION Connection,
  127. PUCHAR Header,
  128. UINT TotalLength,
  129. UINT AvailLength,
  130. UINT TakenLength,
  131. ULONG Status
  132. )
  133. {
  134. PKT_IND_QUE *PktIndQueue;
  135. PKT_IND_ELM *PktIndItem;
  136. ULONG BytesSaved;
  137. LARGE_INTEGER TickCounts;
  138. PktIndQueue = &Connection->LastNIndcs;
  139. IF_NBFDBG (NBF_DEBUG_PKTLOG) {
  140. DbgPrint("Indicate the client on CON %08x: Hdr: %08x, TLen: %5d, ILen: %5d, PLen: %5d, ST: %08x\n",
  141. Connection, Header, TotalLength, AvailLength, TakenLength, Status);
  142. }
  143. PktIndItem = &PktIndQueue->PktQue[PktIndQueue->PktNext++];
  144. PktIndQueue->PktNext %= PKT_QUE_SIZE;
  145. KeQueryTickCount(&TickCounts);
  146. PktIndItem->TimeLogged = (USHORT) TickCounts.LowPart;
  147. PktIndItem->BytesTotal = (USHORT) TotalLength;
  148. PktIndItem->BytesIndic = (USHORT) AvailLength;
  149. PktIndItem->BytesTaken = (USHORT) TakenLength;
  150. PktIndItem->IndcnStatus = Status;
  151. BytesSaved = AvailLength > PKT_IND_SIZE ?
  152. PKT_IND_SIZE :
  153. AvailLength;
  154. RtlCopyMemory (PktIndItem->PacketData,
  155. Header,
  156. BytesSaved);
  157. }
  158. #endif // PKT_LOG