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.

317 lines
9.6 KiB

  1. /******************************************************************************
  2. *
  3. * File: h245recv.c
  4. *
  5. * INTEL Corporation Proprietary Information
  6. * Copyright (c) 1994, 1995, 1996 Intel Corporation.
  7. *
  8. * This listing is supplied under the terms of a license agreement
  9. * with INTEL Corporation and may not be used, copied, nor disclosed
  10. * except in accordance with the terms of that agreement.
  11. *
  12. *****************************************************************************/
  13. /******************************************************************************
  14. *
  15. * $Workfile: h245recv.c $
  16. * $Revision: 1.13 $
  17. * $Modtime: 06 Feb 1997 18:17:22 $
  18. * $Log: S:\sturgeon\src\h245\src\vcs\h245recv.c_v $
  19. *
  20. * Fixed warnings.
  21. *
  22. * Rev 1.11 01 Nov 1996 15:24:56 EHOWARDX
  23. *
  24. * Added check for link not disconnected before re-posting receive buffer
  25. * to link layer to eliminate annoying error message from link layer.
  26. *
  27. * Rev 1.10 22 Jul 1996 17:33:42 EHOWARDX
  28. * Updated to latest Interop API.
  29. *
  30. * Rev 1.9 01 Jul 1996 16:14:32 EHOWARDX
  31. * locks
  32. * Added FunctionNotSupported if ossDecode fails.
  33. *
  34. * Rev 1.8 10 Jun 1996 16:53:46 EHOWARDX
  35. * Removed special handling of EndSession since shutdown moved to InstanceUnlo
  36. *
  37. * Rev 1.7 05 Jun 1996 17:14:28 EHOWARDX
  38. * Further work on converting to HRESULT; added PrintOssError to eliminate
  39. * pErrorString from instance structure.
  40. *
  41. * Rev 1.6 04 Jun 1996 18:18:16 EHOWARDX
  42. * Interop Logging changes inside #if defined(PCS_COMPLIANCE) conditionals.
  43. *
  44. * Rev 1.5 30 May 1996 23:39:10 EHOWARDX
  45. * Cleanup.
  46. *
  47. * Rev 1.4 28 May 1996 14:25:08 EHOWARDX
  48. * Tel Aviv update.
  49. *
  50. * Rev 1.3 21 May 1996 13:40:46 EHOWARDX
  51. * Added LOGGING switch to log PDUs to the file H245.OUT.
  52. * Add /D "LOGGING" to project options to enable this feature.
  53. *
  54. * Rev 1.2 17 May 1996 16:44:22 EHOWARDX
  55. * Changed to use LINK_RECV_CLOSED to signal link layer close.
  56. *
  57. * Rev 1.1 17 May 1996 16:20:32 EHOWARDX
  58. * Added code to change API state if zero-length buffer received
  59. * signalling link layer closed.
  60. *
  61. * Rev 1.0 09 May 1996 21:06:24 EHOWARDX
  62. * Initial revision.
  63. *
  64. * Rev 1.8.1.5 09 May 1996 19:33:58 EHOWARDX
  65. * Redesigned locking logic.
  66. * Simplified link API.
  67. *
  68. * Rev 1.17 29 Apr 1996 16:05:12 EHOWARDX
  69. * Added special case handling of EndSessionCommand to ReceiveComplete().
  70. *
  71. * Rev 1.16 27 Apr 1996 21:13:14 EHOWARDX
  72. * Hope we finally got ossDecode() failure handling right...
  73. *
  74. * Rev 1.15 27 Apr 1996 13:08:54 EHOWARDX
  75. * Also need to terminate while loop if ossDecode fails!
  76. *
  77. * Rev 1.8.1.4 27 Apr 1996 11:25:36 EHOWARDX
  78. * Changed to not call FsmIncoming if ossDecode fails...
  79. *
  80. *
  81. * Rev 1.8.1.3 25 Apr 1996 21:26:46 EHOWARDX
  82. * Changed to use pInstance->p_ossWorld instead of bAsnInitialized.
  83. *
  84. * Rev 1.8.1.2 23 Apr 1996 14:44:30 EHOWARDX
  85. * Updated.
  86. *
  87. * Rev 1.8.1.1 15 Apr 1996 15:12:00 EHOWARDX
  88. * Updated.
  89. *
  90. * Rev 1.8.1.0 26 Mar 1996 19:15:24 EHOWARDX
  91. *
  92. * Commented out hTraceFile for H.323
  93. *
  94. * Rev 1.8 21 Mar 1996 17:21:36 dabrown1
  95. *
  96. * - put in test1/2 trace fdwrite
  97. *
  98. * Rev 1.7 13 Mar 1996 11:31:56 DABROWN1
  99. *
  100. * Enable logging for ring0
  101. *
  102. * Rev 1.6 06 Mar 1996 13:13:04 DABROWN1
  103. *
  104. * flush receive buffer functionality
  105. *
  106. * Rev 1.5 01 Mar 1996 17:25:54 DABROWN1
  107. *
  108. * moved oss 'world' context to h245instance
  109. * changed oss delete from ossFreeBuf to ossFreePDU
  110. *
  111. * Rev 1.4 23 Feb 1996 13:56:04 DABROWN1
  112. *
  113. * added H245TRACE / ASSERT calls
  114. *
  115. * Rev 1.3 21 Feb 1996 12:09:56 EHOWARDX
  116. * Eliminated unused local variables.
  117. *
  118. * Rev 1.2 21 Feb 1996 08:25:08 DABROWN1
  119. *
  120. * Provide multiple buffers receiving > 1 message (ie., link ACKs).
  121. *
  122. * Rev 1.1 13 Feb 1996 14:46:06 DABROWN1
  123. *
  124. * changed asnexp.h (no longer there) to fsmexp.h
  125. *
  126. * Rev 1.0 09 Feb 1996 17:36:20 cjutzi
  127. * Initial revision.
  128. *
  129. *****************************************************************************/
  130. #ifndef STRICT
  131. #define STRICT
  132. #endif
  133. /***********************/
  134. /* SYSTEM INCLUDES */
  135. /***********************/
  136. #include <stdio.h>
  137. #include <stdlib.h>
  138. #include <stddef.h>
  139. #include <limits.h>
  140. #include "precomp.h"
  141. /***********************/
  142. /* H245 INCLUDES */
  143. /***********************/
  144. #ifdef _IA_SPOX_
  145. # define _DLL
  146. #endif //_IA_SPOX_
  147. #include "h245com.h"
  148. #include "sr_api.h"
  149. #if defined(_DEBUG) || defined(PCS_COMPLIANCE)
  150. #include "interop.h"
  151. #include "h245plog.h"
  152. extern LPInteropLogger H245Logger;
  153. #endif // (PCS_COMPLIANCE)
  154. #ifdef _IA_SPOX_
  155. # undef _DLL
  156. #endif //_IA_SPOX_
  157. /**************************************************************************
  158. ** Function : h245ReceiveComplete
  159. ** Description : Receive Completion Callback routine from link layer
  160. ***************************************************************************/
  161. HRESULT
  162. H245FunctionNotSupported(struct InstanceStruct *pInstance, unsigned short wChoice, unsigned char *pBuf, unsigned uLength)
  163. {
  164. MltmdSystmCntrlMssg Pdu = {0};
  165. Pdu.choice = indication_chosen;
  166. Pdu.u.indication.choice = IndicationMessage_functionNotSupported_chosen;
  167. Pdu.u.indication.u.functionNotSupported.cause.choice = wChoice;
  168. if (pBuf != NULL && uLength != 0)
  169. {
  170. Pdu.u.indication.u.functionNotSupported.bit_mask = returnedFunction_present;
  171. Pdu.u.indication.u.functionNotSupported.returnedFunction.length = (WORD)uLength;
  172. Pdu.u.indication.u.functionNotSupported.returnedFunction.value = pBuf;
  173. }
  174. else
  175. {
  176. Pdu.u.indication.u.functionNotSupported.bit_mask = 0;
  177. }
  178. return sendPDU(pInstance, &Pdu);
  179. } // H245FunctionNotSupported()
  180. void h245ReceiveComplete(DWORD_PTR h245Inst,
  181. HRESULT dwMessage,
  182. PBYTE pbDataBuf,
  183. DWORD dwLength)
  184. {
  185. struct InstanceStruct *pInstance;
  186. int pduNum = MltmdSystmCntrlMssg_PDU;
  187. ASN1_BUF Asn1Buf;
  188. MltmdSystmCntrlMssg *pPdu;
  189. int nRet;
  190. // Validate the instance handle
  191. pInstance = InstanceLock(h245Inst);
  192. if (pInstance == NULL) {
  193. H245TRACE(h245Inst, 1, "h245ReceiveComplete: Instance not found");
  194. return;
  195. }
  196. // ONLY submit buffers to the decoder if it's for data received,
  197. // skip for flushes
  198. switch (dwMessage) {
  199. case LINK_RECV_CLOSED:
  200. H245TRACE(h245Inst, 3, "h245ReceiveComplete: Link Layer closed");
  201. pInstance->API.SystemState = APIST_Disconnected;
  202. InstanceUnlock(pInstance);
  203. return;
  204. case LINK_RECV_DATA:
  205. if (pInstance->pWorld == NULL) {
  206. H245TRACE(h245Inst, 1, "h245ReceiveComplete: ASN.1 Decoder not initialized");
  207. InstanceUnlock(pInstance);
  208. return;
  209. }
  210. switch (pInstance->Configuration) {
  211. case H245_CONF_H324:
  212. Asn1Buf.value = &pbDataBuf[2];
  213. Asn1Buf.length = dwLength;
  214. break;
  215. default:
  216. Asn1Buf.value = pbDataBuf;
  217. Asn1Buf.length = dwLength;
  218. } // switch
  219. // Loop around as long as the length field is positive.
  220. // ASN.1 decoder will update the length for each PDU it decodes until
  221. // a 0 length is achieved.
  222. while (Asn1Buf.length > 0)
  223. {
  224. int savePduLength = Asn1Buf.length;
  225. PBYTE savePdu = Asn1Buf.value;
  226. pPdu = NULL;
  227. #if defined(_DEBUG) || defined(PCS_COMPLIANCE)
  228. if (H245Logger)
  229. InteropOutput(H245Logger,
  230. (BYTE FAR *)Asn1Buf.value,
  231. (int)Asn1Buf.length,
  232. H245LOG_RECEIVED_PDU);
  233. #endif // (PCS_COMPLIANCE)
  234. nRet = H245_Decode(pInstance->pWorld,
  235. (void **)&pPdu,
  236. pduNum,
  237. &Asn1Buf);
  238. if (ASN1_SUCCEEDED(nRet))
  239. {
  240. // Decode succeeded
  241. H245TRACE(h245Inst, 3, "H.245 Msg decode successful");
  242. // Pass on data to finite state machine
  243. FsmIncoming(pInstance, pPdu);
  244. }
  245. else
  246. {
  247. // Decode failed
  248. H245FunctionNotSupported(pInstance, syntaxError_chosen, savePdu, savePduLength);
  249. Asn1Buf.length = 0; // Terminate loop!
  250. }
  251. if (pPdu != NULL)
  252. {
  253. // Free the memory used by the ASN.1 library
  254. if (freePDU(pInstance->pWorld, pduNum, pPdu, H245ASN_Module))
  255. {
  256. H245TRACE(h245Inst, 1, "SR: FREE FAILURE");
  257. }
  258. }
  259. } // while (Asn1Buf.length > 0)
  260. if (pInstance->API.SystemState != APIST_Disconnected)
  261. {
  262. // Repost the buffer to the data link layer
  263. pInstance->SendReceive.hLinkReceiveReq(pInstance->SendReceive.hLinkLayerInstance,
  264. pbDataBuf,
  265. pInstance->SendReceive.dwPDUSize);
  266. }
  267. break; // case LINK_RECV_DATA
  268. case LINK_RECV_ABORT:
  269. // Receive buffer flush in process
  270. ASSERT(pbDataBuf != NULL);
  271. H245TRACE(h245Inst, 3, "SR: RX Flush Buffer");
  272. break;
  273. case LINK_FLUSH_COMPLETE:
  274. // Receive buffer flush done
  275. ASSERT(pbDataBuf == NULL);
  276. H245TRACE(h245Inst, 3, "SR: RX Flush Complete");
  277. pInstance->SendReceive.dwFlushMap &= ~DATALINK_RECEIVE;
  278. break;
  279. default:
  280. H245TRACE(h245Inst, 1, "SR: RX COMPLETE Error %d", dwMessage);
  281. break;
  282. } // switch
  283. InstanceUnlock(pInstance);
  284. }
  285.