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.

225 lines
11 KiB

  1. // COMM MONITOR CODE
  2. // 2/11/95 JosephJ Created
  3. //
  4. // The functions MonInit, MonDeInit, MonPut and MonDump may be used
  5. // to timestamp and log all reads from/writes using the comm apis.
  6. // MonDump creates two files, one a byte buffer, and the 2nd
  7. // an array of MONREC structures, each structure containing a timestamp
  8. // and an offset into the first file that points to the actual comm data.
  9. // Following two macros to be called before each write attempt
  10. // and after each non-zero read.
  11. # define INMON(pTG, lpb, cb) \
  12. (pTG->gMonInfo.fInited && MonPutComm(pTG, fMON_COMM_IN, lpb,cb))
  13. # define OUTMON(pTG, lpb, cb) \
  14. (pTG->gMonInfo.fInited && MonPutComm(pTG, fMON_COMM_OUT, lpb,cb))
  15. # define PUTEVENT(pTG, wFlags, ID, SubID, dw0, dw1, lpsz)\
  16. (pTG->gMonInfo.fInited && MonPutEvent(pTG, wFlags, ID, SubID, dw0, dw1, lpsz))
  17. //File extensions for the mon-file
  18. #define szMON_EXT "mon"
  19. // Min and Max sizes of internal buffers allocated for monitoring.
  20. // MonInit will enforce that the sizes fall within this range.
  21. #define MIN_MRBUFSIZE (65536L>>2)
  22. #define MIN_DATABUFSIZE 65536L
  23. #define MAX_MRBUFSIZE 1000000L
  24. #define MAX_DATABUFSIZE 1000000L
  25. // Following structure records time of each call to read/write
  26. // to comm. It also contains an offset into a circular buffer which
  27. // contains all data writen to/read from comm port.
  28. // wFlags is a word of information that was specified in the call to MonPut
  29. // Currently it is a combination of the fMON_* flags above.
  30. typedef struct
  31. {
  32. WORD wFlags; // One of fMON_* flags above. (A parameter to MonPut)
  33. WORD wcb; // Number of bytes of variable-lenghth data
  34. DWORD dwTickCount; // GetTickCount at time of MonPut call
  35. DWORD dwOffset; // Offset into circular byte-buffer where data is.
  36. } MONREC, FAR *LPMONREC;
  37. #define MFR_COMMDATA 1
  38. #define MFR_EVENT 2
  39. // Following flags are specified in the wFlags param of MonPut. They
  40. // are saved in the corresponding field of the MONREC structures.
  41. #define fMON_COMM_RESERVED (0x1<<15) // Should never be used.
  42. #define fMON_COMM_IN (0x1<<0) // Read operation
  43. #define fMON_COMM_OUT (0x1<<1) // Write operation
  44. #define fMON_COMM_CMDRESP (0x1<<3) // We believe modem is in command mode
  45. #define fMON_COMM_DATA (0x1<<4) // We believe modem is in data mode
  46. #define EVENT_ID_TXTMSG 1 // Generic text message.
  47. #define EVENT_ID_MON 10 // Related to the monitoring processitself.
  48. #define EVENT_ID_T30_BASE 100 // T30-protocol-stack related.
  49. #define EVENT_ID_T30_CALLSTATE 100 // T30-protocol: call state related.
  50. #define EVENT_ID_MODEM_BASE 200 // Modem-related
  51. #define EVENT_ID_MODEM_STATE 200 // Initialize modem
  52. #define EVENT_SubID_NULL 0 // Nothing.
  53. #define EVENT_SubID_MON_DUMP 1 // Dump (write to file) of in-memory record
  54. // TextID contains timestamp of start, as
  55. // well as number of puts, and bytes written
  56. // dwData0=dwData1=0
  57. // SubID=0
  58. #define EVENT_SubID_T30_CS_SEND_START 1 // Initiate T.30 Send
  59. // Displayable phone number is embedded in
  60. // TxtMessage.
  61. // dwData0=dwData1=0;
  62. #define EVENT_SubID_T30_CS_SEND_END 2 // End T.30 Send
  63. // dwData0=result code
  64. #define EVENT_SubID_T30_CS_RECV_START 11 // Initiate T.30 Recv
  65. // dwData0=dwData1=0;
  66. #define EVENT_SubID_T30_CS_RECV_END 12 // End T.30 Recv
  67. // dwData0=result code
  68. #define EVENT_SubID_MODEM_INIT_START 1 // About to issue commands to Init modem
  69. #define EVENT_SubID_MODEM_INIT_END 2 // Done initing.
  70. // dwData0=return code
  71. #define EVENT_SubID_MODEM_DEINIT_START 11 // About to issue commands to deinit
  72. #define EVENT_SubID_MODEM_DEINIT_END 12 // Done deiniting.
  73. // dwData0=return code
  74. #define EVENT_SubID_MODEM_SENDMODE_START 21 // About to issue commands to deinit
  75. #define EVENT_SubID_MODEM_SENDMODE_END 22 // Done deiniting.
  76. // dwData0=return code
  77. #define EVENT_SubID_MODEM_RECVMODE_START 31 // About to issue commands to deinit
  78. #define EVENT_SubID_MODEM_RECVMODE_END 32 // Done deiniting.
  79. // dwData0=return code
  80. #define EVENT_SubID_MODEM_DIAL_START 41 // About to issue commands to dial
  81. // szTxtMsg contains dial string
  82. // In retail, digits after first 4
  83. // are zapped.
  84. #define EVENT_SubID_MODEM_DIAL_END 42 // Done dialing
  85. // dwData0=return code
  86. #define EVENT_SubID_MODEM_ANSWER_START 51 // About to issue commands to answer
  87. #define EVENT_SubID_MODEM_ANSWER_END 52 // Done with the answer command
  88. // dwData0=return code
  89. #define EVENT_SubID_MODEM_HANGUP_START 61 // About to issue commands to answer
  90. #define EVENT_SubID_MODEM_HANGUP_END 62 // Done with the answer command
  91. // dwData0=return code
  92. #pragma pack(1)
  93. typedef struct {
  94. WORD wTotalSize;
  95. WORD wHeaderSize;
  96. WORD wType; // One of the MFR_* defines
  97. WORD wFlags; // type dependant
  98. DWORD dwTickCount; // GetTickCount() at time of call to MonPut.
  99. } MONFRAME_BASE, FAR *LPMONFRAME_BASE;
  100. #pragma pack()
  101. // Following inserted in mon file to document data structure.
  102. // Make sure it matches above structure.
  103. #define szMONFRM_DESC001\
  104. "struct{WORD wcbTot; WORD wcbHdr; WORD wTyp; WORD wFlg; DWORD dwTick}"
  105. // Update version when structure changes.
  106. #define szMONFRM_VER001 "V.100"
  107. #pragma pack(1)
  108. typedef struct {
  109. WORD wTotalSize;
  110. WORD wHeaderSize;
  111. WORD wType; // One of the MFR_* defines
  112. WORD wFlags; // One of the fMON_COMM_* values.
  113. DWORD dwTickCount; // GetTickCount() at time of call to MonPut.
  114. WORD wcb; // Count of bytes following.
  115. BYTE rgb[]; // Actuall bytes of comm data.
  116. } MONFRAME_COMM, FAR *LPMONFRAME_COMM;
  117. #pragma pack()
  118. #define fEVENT_ERROR_MASK 0x111
  119. #define fEVENT_ERROR_NONE 0x000
  120. #define fEVENT_ERROR_FATAL 0x001
  121. #define fEVENT_ERROR_SERIOUS 0x010
  122. #define fEVENT_ERROR_MSGFAIL 0x011
  123. #define fEVENT_ERROR_OTHER 0x100
  124. #define fEVENT_ERROR_WARNING 0x101
  125. #define fEVENT_TRACELEVEL_MASK 0x11000
  126. #define fEVENT_TRACELEVEL_0 0x00000 // Vital: MUST display
  127. #define fEVENT_TRACELEVEL_1 0x01000 // Important
  128. #define fEVENT_TRACELEVEL_2 0x10000 // Less important
  129. #define fEVENT_TRACELEVEL_3 0x11000 // Least important
  130. #define MAX_TXTMSG_SIZE 128 // Max size of text msg in a MONFRAME_EVENT structure.
  131. #pragma pack(1)
  132. typedef struct {
  133. WORD wTotalSize;
  134. WORD wHeaderSize;
  135. WORD wType; // Should be MFR_EVENT
  136. WORD wFlags; // One of the fEVENT_* flags.
  137. DWORD dwTickCount; // GetTickCount() at time of call to MonPut.
  138. WORD wID; // ID of event. One of the EVENT_ID_* defines
  139. WORD wSubID; // Sub ID of event. One of the EVENT_SubID_* defines
  140. DWORD dwInstanceID; // Instance ID of event within this file.
  141. DWORD dwData0; // ID-specific data
  142. DWORD dwData1; // ID-specific data
  143. SYSTEMTIME st; // SystemTime at time of call to MonPut
  144. WORD wTxtMsgOff;// Offset to null-terminated text message, if any
  145. WORD wcbTxtMsg; // Size of null-terminated text message, if any
  146. } MONFRAME_EVENT, FAR *LPMONFRAME_EVENT;
  147. #pragma pack()
  148. // Monitor Options -- passed into MonInit
  149. typedef struct {
  150. // Buffer options
  151. DWORD dwMRBufSize; // preferred size -- actual size may be different
  152. DWORD dwDataBufSize; // preferred size -- actual size may be different
  153. // File options
  154. DWORD dwMaxExistingSize;// If the size of the existing file
  155. // is > this, we will rename the existing file
  156. // and create a new one.
  157. char rgchDir[64]; // Directory where fax0.mon is to be created.
  158. } MONOPTIONS, FAR * LPMONOPTIONS;
  159. // Global monitor state
  160. typedef struct {
  161. SYSTEMTIME stStart; // Set by MonInit.
  162. SYSTEMTIME stDump; // Set by MonDump.
  163. BOOL fFreeOnExit; // TRUE iff buffers must be freed on exit.
  164. BOOL fInited; // Set in MonInit. Cleared in MonDeInit.
  165. DWORD dwNumPuts; // Number of calls to MonPut
  166. DWORD dwNumBytes; // Cumulative number of bytes specified to MonPut
  167. UINT uRefCount; // Incremented each time MonDump is called
  168. // Used to new file for each MonDump
  169. // Cleared in MonInit and MonDeInit
  170. DWORD dwEventInstanceID; // ID which is supposed to uniquely identify
  171. // each event within a file.
  172. LPMONREC lpmrBuf; // Pointer to MONREC circular buffer
  173. DWORD dwcmrBuf; // Size (in units of MONREC) if circular buffer
  174. LPMONREC lpmrNext; // Pointer to next available MR
  175. LPBYTE lpbBuf; // Pointer to circular byte buffer.
  176. DWORD dwcbBuf; // Size (in bytes) of above buffer.
  177. LPBYTE lpbNext; // Pointer to next place to write bytes in this buf.
  178. MONOPTIONS mo; // Passed in to MonInit();
  179. } MONINFO;