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.

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