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.

267 lines
6.3 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1995 Microsoft Corporation
  4. *
  5. * File: irlaplog.c
  6. *
  7. * Description: IRLAP state machine logging and errors
  8. *
  9. * Author: mbert
  10. *
  11. * Date: 4/15/95
  12. *
  13. */
  14. #include <irda.h>
  15. #include <irioctl.h>
  16. #include <irlap.h>
  17. #include <irlapp.h>
  18. #include <irlaplog.h>
  19. #include <decdirda.h>
  20. #include <stdarg.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #undef offsetof
  24. #include "irlaplog.tmh"
  25. #define _IRLAPLOG_C_
  26. #if 1 //DBG
  27. TCHAR _ABuf[512];
  28. #ifndef PEG
  29. TCHAR _DecodeStr1[1000];
  30. TCHAR _DecodeStr2[1000];
  31. #else
  32. TCHAR _DecodeStr1[] = TEXT("(null)");
  33. TCHAR _DecodeStr2[] = TEXT("(null)");
  34. #endif
  35. // Keep in sync with IRLAP_STATE in irlap.h
  36. TCHAR *IRLAP_StateStr[] = {
  37. TEXT("NDM"),
  38. TEXT("DSCV_MEDIA_SENSE"),
  39. TEXT("DSCV_QUERY"),
  40. TEXT("DSCV_REPLY"),
  41. TEXT("CONN_MEDIA_SENSE"),
  42. TEXT("SNRM_SENT"),
  43. TEXT("BACKOFF_WAIT"),
  44. TEXT("SNRM_RECEIVED"),
  45. TEXT("P_XMIT"),
  46. TEXT("P_RECV"),
  47. TEXT("P_DISCONNECT_PEND"),
  48. TEXT("P_CLOSE"),
  49. TEXT("S_NRM"),
  50. TEXT("S_DISCONNECT_PEND"),
  51. TEXT("S_ERROR"),
  52. TEXT("S_CLOSE")
  53. };
  54. // Keep in sync with IRDA_SERVICE_PRIM in irda.h
  55. TCHAR *IRDA_PrimStr[] =
  56. {
  57. TEXT("MAC_DATA_REQ"),
  58. TEXT("MAC_DATA_IND"),
  59. TEXT("MAC_DATA_RESP"),
  60. TEXT("MAC_DATA_CONF"),
  61. TEXT("MAC_CONTROL_REQ"),
  62. TEXT("MAC_CONTROL_CONF"),
  63. TEXT("IRLAP_DISCOVERY_REQ"),
  64. TEXT("IRLAP_DISCOVERY_IND"),
  65. TEXT("IRLAP_DISCOVERY_CONF"),
  66. TEXT("IRLAP_CONNECT_REQ"),
  67. TEXT("IRLAP_CONNECT_IND"),
  68. TEXT("IRLAP_CONNECT_RESP"),
  69. TEXT("IRLAP_CONNECT_CONF"),
  70. TEXT("IRLAP_DISCONNECT_REQ"),
  71. TEXT("IRLAP_DISCONNECT_IND"),
  72. TEXT("IRLAP_DATA_REQ"),
  73. TEXT("IRLAP_DATA_IND"),
  74. TEXT("IRLAP_DATA_CONF"),
  75. TEXT("IRLAP_UDATA_REQ"),
  76. TEXT("IRLAP_UDATA_IND"),
  77. TEXT("IRLAP_UDATA_CONF"),
  78. TEXT("IRLAP_STATUS_REQ"),
  79. TEXT("IRLAP_STATUS_IND"),
  80. TEXT("IRLAP_FLOWON_REQ"),
  81. TEXT("IRLMP_DISCOVERY_REQ"),
  82. TEXT("IRLMP_DISCOVERY_CONF"),
  83. TEXT("IRLMP_CONNECT_REQ"),
  84. TEXT("IRLMP_CONNECT_IND"),
  85. TEXT("IRLMP_CONNECT_RESP"),
  86. TEXT("IRLMP_CONNECT_CONF"),
  87. TEXT("IRLMP_DISCONNECT_REQ"),
  88. TEXT("IRLMP_DISCONNECT_IND"),
  89. TEXT("IRLMP_DATA_REQ"),
  90. TEXT("IRLMP_DATA_IND"),
  91. TEXT("IRLMP_DATA_CONF"),
  92. TEXT("IRLMP_UDATA_REQ"),
  93. TEXT("IRLMP_UDATA_IND"),
  94. TEXT("IRLMP_UDATA_CONF"),
  95. TEXT("IRLMP_ACCESSMODE_REQ"),
  96. TEXT("IRLMP_ACCESSMODE_IND"),
  97. TEXT("IRLMP_ACCESSMODE_CONF"),
  98. };
  99. // keep in sync with IRDA_ServiceStatus in irda.h
  100. TCHAR *IRDA_StatStr[] =
  101. {
  102. TEXT(" - MEDIA_BUSY"),
  103. TEXT(" - MEDIA_CLEAR"),
  104. TEXT(" - DISCOVERY_COLLISION"),
  105. TEXT(" - REMOTE_DISCOVERY_IN_PROGRESS"),
  106. TEXT(" - REMOTE_CONNECT_IN_PROGRSS"),
  107. TEXT(" - DISCOVERY_COMPLETED"),
  108. TEXT(" - REMOTE_CONNECTION_IN_PROGRESS"),
  109. TEXT(" - CONNECTION_COMPLETED"),
  110. TEXT(" - REMOTE_INITIATED"),
  111. TEXT(" - PRIMARY_CONFLICT"),
  112. TEXT(" - DISCONNECT_COMPLETE"),
  113. TEXT(" - NO_RESPONSE"),
  114. TEXT(" - IRLAP_DECLINE_RESET"),
  115. TEXT(" - DATA_REQUEST_COMPLETED"),
  116. TEXT(" - DATA_REQUEST_FAILED_LINK_RESET"),
  117. TEXT(" - DATA_REQUEST_FAILED_REMOTE_BUSY")
  118. };
  119. // Keep in sync with MAC_CONTROL_OPERATION in irda.h
  120. TCHAR *MAC_OpStr[] =
  121. {
  122. TEXT("initialize link"),
  123. TEXT("close link"),
  124. TEXT("reconfig link"),
  125. TEXT("media sense")
  126. };
  127. TCHAR
  128. *FrameToStr(IRDA_MSG *pMsg)
  129. {
  130. #ifndef PEG
  131. UCHAR *ptr;
  132. int i = 0;
  133. int j;
  134. TCHAR *pD1 = _DecodeStr1;
  135. TCHAR *pD2 = _DecodeStr2;
  136. // copy the frame to a contiguous buffer
  137. ptr = pMsg->IRDA_MSG_pHdrRead;
  138. while (ptr != pMsg->IRDA_MSG_pHdrWrite)
  139. {
  140. _ABuf[i++] = *ptr++;
  141. }
  142. ptr = pMsg->IRDA_MSG_pRead;
  143. while (ptr != pMsg->IRDA_MSG_pWrite)
  144. {
  145. _ABuf[i++] = *ptr++;
  146. }
  147. // DecodeIRDA(&_FrameType, (char *)_ABuf, i, _DecodeStr1, 2, FALSE, 1);
  148. // insert spaces and break-up into multiple lines
  149. i = 0;
  150. do
  151. {
  152. if (i++%69 == 0)
  153. {
  154. *pD2++ = TEXT('\r');
  155. *pD2++ = TEXT('\n');
  156. for (j = 0; j<7;j++)
  157. {
  158. *pD2++ = TEXT(' ');
  159. }
  160. }
  161. *pD2++ = *pD1++;
  162. } while (*pD1 != TEXT('\0'));
  163. *pD2 = TEXT('\0');
  164. #endif
  165. return (_DecodeStr2);
  166. }
  167. void
  168. IRLAP_EventLogStart(PIRLAP_CB pIrlapCb, TCHAR *pFormat, ...)
  169. {
  170. va_list ArgList;
  171. ++pIrlapCb->NestedEvent;
  172. if (!WPP_LEVEL_ENABLED(DBG_IRLAPLOG)) {
  173. return;
  174. }
  175. va_start (ArgList, pFormat);
  176. if (pIrlapCb->NestedEvent == 1)
  177. {
  178. DEBUGMSG(DBG_IRLAPLOG, (TEXT("----------------")));
  179. }
  180. else
  181. {
  182. DEBUGMSG(DBG_IRLAPLOG, (TEXT("!!!!!!!!!!!!!!!!")));
  183. }
  184. pIrlapCb->ActCnt[pIrlapCb->NestedEvent % 0xf] = 0;
  185. vsprintf(_ABuf, pFormat, ArgList);
  186. DEBUGMSG(DBG_IRLAPLOG,("Ev%d: %s",pIrlapCb->NestedEvent, _ABuf));
  187. DEBUGMSG(DBG_IRLAPLOG, (TEXT("Start State: %s"),
  188. IRLAP_StateStr[pIrlapCb->State]));
  189. DEBUGMSG(DBG_IRLAPLOG, (TEXT("Actions:")));
  190. va_end (ArgList);
  191. }
  192. void __cdecl
  193. IRLAP_LogAction(PIRLAP_CB pIrlapCb, TCHAR *pFormat, ...)
  194. {
  195. va_list ArgList;
  196. if (!WPP_LEVEL_ENABLED(DBG_IRLAPLOG)) {
  197. return;
  198. }
  199. va_start (ArgList, pFormat);
  200. vsprintf(_ABuf, pFormat, ArgList);
  201. DEBUGMSG(DBG_IRLAPLOG, (" %d. %s",++pIrlapCb->ActCnt[pIrlapCb->NestedEvent & 0xf],_ABuf));
  202. va_end (ArgList);
  203. }
  204. #define PRINT_IF_TRUE(bool, str) (bool == TRUE ? str : TEXT(""))
  205. void
  206. IRLAP_EventLogComplete(PIRLAP_CB pIrlapCb)
  207. {
  208. --pIrlapCb->NestedEvent;
  209. if (!WPP_LEVEL_ENABLED(DBG_IRLAPLOG)) {
  210. return;
  211. }
  212. DEBUGMSG(DBG_IRLAPLOG,
  213. (TEXT("Vs=%d Vr=%d RxWin(%d,%d) TxWin(%d,%d)"),
  214. pIrlapCb->Vs, pIrlapCb->Vr,
  215. pIrlapCb->RxWin.Start, pIrlapCb->RxWin.End,
  216. pIrlapCb->TxWin.Start, pIrlapCb->TxWin.End));
  217. DEBUGMSG(DBG_IRLAPLOG, (TEXT("Ev%d End St: %s"),
  218. pIrlapCb->NestedEvent, IRLAP_StateStr[pIrlapCb->State]));
  219. if (pIrlapCb->NestedEvent > 0)
  220. {
  221. DEBUGMSG(DBG_IRLAPLOG, (TEXT("!!!!!!!!!!!!!!!!")));
  222. }
  223. ASSERT(pIrlapCb->NestedEvent >= 0);
  224. }
  225. #endif