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.

335 lines
10 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. HRESULT status = H245_ERROR_OK;
  165. MltmdSystmCntrlMssg *pPdu = NULL;
  166. pPdu = (MltmdSystmCntrlMssg *) MemAlloc(sizeof(MltmdSystmCntrlMssg));
  167. if(NULL != pPdu)
  168. {
  169. memset(pPdu, 0, sizeof(MltmdSystmCntrlMssg));
  170. pPdu->choice = indication_chosen;
  171. pPdu->u.indication.choice = IndicationMessage_functionNotSupported_chosen;
  172. pPdu->u.indication.u.functionNotSupported.cause.choice = wChoice;
  173. if (pBuf != NULL && uLength != 0)
  174. {
  175. pPdu->u.indication.u.functionNotSupported.bit_mask = returnedFunction_present;
  176. pPdu->u.indication.u.functionNotSupported.returnedFunction.length = (WORD)uLength;
  177. pPdu->u.indication.u.functionNotSupported.returnedFunction.value = pBuf;
  178. }
  179. else
  180. {
  181. pPdu->u.indication.u.functionNotSupported.bit_mask = 0;
  182. }
  183. status = sendPDU(pInstance, pPdu);
  184. MemFree(pPdu);
  185. pPdu = NULL;
  186. }
  187. else
  188. {
  189. status = H245_ERROR_NOMEM;
  190. }
  191. return status;
  192. } // H245FunctionNotSupported()
  193. void h245ReceiveComplete(DWORD_PTR h245Inst,
  194. HRESULT dwMessage,
  195. PBYTE pbDataBuf,
  196. DWORD dwLength)
  197. {
  198. struct InstanceStruct *pInstance;
  199. int pduNum = MltmdSystmCntrlMssg_PDU;
  200. ASN1_BUF Asn1Buf;
  201. MltmdSystmCntrlMssg *pPdu;
  202. int nRet;
  203. // Validate the instance handle
  204. pInstance = InstanceLock(h245Inst);
  205. if (pInstance == NULL) {
  206. H245TRACE(h245Inst, 1, "h245ReceiveComplete: Instance not found");
  207. return;
  208. }
  209. // ONLY submit buffers to the decoder if it's for data received,
  210. // skip for flushes
  211. switch (dwMessage) {
  212. case LINK_RECV_CLOSED:
  213. H245TRACE(h245Inst, 3, "h245ReceiveComplete: Link Layer closed");
  214. pInstance->API.SystemState = APIST_Disconnected;
  215. InstanceUnlock(pInstance);
  216. return;
  217. case LINK_RECV_DATA:
  218. if (pInstance->pWorld == NULL) {
  219. H245TRACE(h245Inst, 1, "h245ReceiveComplete: ASN.1 Decoder not initialized");
  220. InstanceUnlock(pInstance);
  221. return;
  222. }
  223. switch (pInstance->Configuration) {
  224. case H245_CONF_H324:
  225. Asn1Buf.value = &pbDataBuf[2];
  226. Asn1Buf.length = dwLength;
  227. break;
  228. default:
  229. Asn1Buf.value = pbDataBuf;
  230. Asn1Buf.length = dwLength;
  231. } // switch
  232. // Loop around as long as the length field is positive.
  233. // ASN.1 decoder will update the length for each PDU it decodes until
  234. // a 0 length is achieved.
  235. while (Asn1Buf.length > 0)
  236. {
  237. int savePduLength = Asn1Buf.length;
  238. PBYTE savePdu = Asn1Buf.value;
  239. pPdu = NULL;
  240. #if defined(_DEBUG) || defined(PCS_COMPLIANCE)
  241. if (H245Logger)
  242. InteropOutput(H245Logger,
  243. (BYTE FAR *)Asn1Buf.value,
  244. (int)Asn1Buf.length,
  245. H245LOG_RECEIVED_PDU);
  246. #endif // (PCS_COMPLIANCE)
  247. nRet = H245_Decode(pInstance->pWorld,
  248. (void **)&pPdu,
  249. pduNum,
  250. &Asn1Buf);
  251. if (ASN1_SUCCEEDED(nRet))
  252. {
  253. // Decode succeeded
  254. H245TRACE(h245Inst, 3, "H.245 Msg decode successful");
  255. // Pass on data to finite state machine
  256. FsmIncoming(pInstance, pPdu);
  257. }
  258. else
  259. {
  260. // Decode failed
  261. H245FunctionNotSupported(pInstance, syntaxError_chosen, savePdu, savePduLength);
  262. Asn1Buf.length = 0; // Terminate loop!
  263. }
  264. if (pPdu != NULL)
  265. {
  266. // Free the memory used by the ASN.1 library
  267. if (freePDU(pInstance->pWorld, pduNum, pPdu, H245ASN_Module))
  268. {
  269. H245TRACE(h245Inst, 1, "SR: FREE FAILURE");
  270. }
  271. }
  272. } // while (Asn1Buf.length > 0)
  273. if (pInstance->API.SystemState != APIST_Disconnected)
  274. {
  275. // Repost the buffer to the data link layer
  276. pInstance->SendReceive.hLinkReceiveReq(pInstance->SendReceive.hLinkLayerInstance,
  277. pbDataBuf,
  278. pInstance->SendReceive.dwPDUSize);
  279. }
  280. break; // case LINK_RECV_DATA
  281. case LINK_RECV_ABORT:
  282. // Receive buffer flush in process
  283. ASSERT(pbDataBuf != NULL);
  284. H245TRACE(h245Inst, 3, "SR: RX Flush Buffer");
  285. break;
  286. case LINK_FLUSH_COMPLETE:
  287. // Receive buffer flush done
  288. ASSERT(pbDataBuf == NULL);
  289. H245TRACE(h245Inst, 3, "SR: RX Flush Complete");
  290. pInstance->SendReceive.dwFlushMap &= ~DATALINK_RECEIVE;
  291. break;
  292. default:
  293. H245TRACE(h245Inst, 1, "SR: RX COMPLETE Error %d", dwMessage);
  294. break;
  295. } // switch
  296. InstanceUnlock(pInstance);
  297. }