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.

292 lines
8.9 KiB

  1. /******************************************************************************
  2. *
  3. * File: h245send.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: h245send.c $
  16. * $Revision: 1.8 $
  17. * $Modtime: 22 Jul 1996 17:24:18 $
  18. * $Log: S:/STURGEON/SRC/H245/SRC/VCS/h245send.c_v $
  19. *
  20. * Rev 1.8 22 Jul 1996 17:33:28 EHOWARDX
  21. * Updated to latest Interop API.
  22. *
  23. * Rev 1.7 05 Jun 1996 17:14:30 EHOWARDX
  24. * Further work on converting to HRESULT; added PrintOssError to eliminate
  25. * pErrorString from instance structure.
  26. *
  27. * Rev 1.6 04 Jun 1996 18:18:18 EHOWARDX
  28. * Interop Logging changes inside #if defined(PCS_COMPLIANCE) conditionals.
  29. *
  30. * Rev 1.5 30 May 1996 23:39:12 EHOWARDX
  31. * Cleanup.
  32. *
  33. * Rev 1.4 28 May 1996 14:25:18 EHOWARDX
  34. * Tel Aviv update.
  35. *
  36. * Rev 1.3 21 May 1996 13:40:48 EHOWARDX
  37. * Added LOGGING switch to log PDUs to the file H245.OUT.
  38. * Add /D "LOGGING" to project options to enable this feature.
  39. *
  40. * Rev 1.2 20 May 1996 14:35:14 EHOWARDX
  41. * Got rid of asynchronous H245EndConnection/H245ShutDown stuff...
  42. *
  43. * Rev 1.1 17 May 1996 16:19:46 EHOWARDX
  44. * Changed sendPDU to return an error if link layer send fails.
  45. * (Probably should define a new error code for this...)
  46. *
  47. * Rev 1.0 09 May 1996 21:06:26 EHOWARDX
  48. * Initial revision.
  49. *
  50. * Rev 1.11.1.4 09 May 1996 19:34:46 EHOWARDX
  51. * Redesigned locking logic.
  52. * Simplified link API.
  53. *
  54. * Rev 1.11.1.3 25 Apr 1996 21:27:14 EHOWARDX
  55. * Changed to use pInstance->p_ossWorld instead of bAsnInitialized.
  56. *
  57. * Rev 1.11.1.2 23 Apr 1996 14:44:34 EHOWARDX
  58. * Updated.
  59. *
  60. * Rev 1.11.1.1 15 Apr 1996 15:12:04 EHOWARDX
  61. * Updated.
  62. *
  63. * Rev 1.11.1.0 26 Mar 1996 19:14:46 EHOWARDX
  64. *
  65. * Commented out hTraceFile for H.323
  66. *
  67. * Rev 1.11 21 Mar 1996 17:20:40 dabrown1
  68. * - put in test1/2 trace fdwrite
  69. * .
  70. *
  71. * .
  72. *
  73. *
  74. *
  75. *
  76. * Rev 1.10 13 Mar 1996 11:31:14 DABROWN1
  77. *
  78. * Enable logging for ring0
  79. *
  80. * Rev 1.9 11 Mar 1996 15:32:06 DABROWN1
  81. *
  82. * Defined/Undefined _DLL for _IA_SPOX_ environment
  83. *
  84. * Rev 1.8 06 Mar 1996 13:11:44 DABROWN1
  85. *
  86. * enable flush buffers
  87. *
  88. * Rev 1.7 02 Mar 1996 22:10:26 DABROWN1
  89. * updated to new MemFree
  90. *
  91. * Rev 1.6 01 Mar 1996 17:25:14 DABROWN1
  92. *
  93. * moved oss 'world' context to h245instance
  94. * delete buffer returned in sendcomplete instead of what was held in context
  95. *
  96. * Rev 1.5 28 Feb 1996 14:52:18 DABROWN1
  97. * Put oss errors in range of SR (10000)
  98. *
  99. * Rev 1.4 23 Feb 1996 13:56:30 DABROWN1
  100. *
  101. * added H245TRACE / ASSERT calls
  102. *
  103. * Rev 1.3 21 Feb 1996 16:52:52 DABROWN1
  104. *
  105. * correct pointer passed to SRP for transmits
  106. *
  107. * Rev 1.2 21 Feb 1996 10:50:42 EHOWARDX
  108. * Got rid of unreferenced local variable.
  109. *
  110. * Rev 1.1 21 Feb 1996 08:24:20 DABROWN1
  111. * allocate/deallocate send buffers per message. Enable sendComplete functiot
  112. *
  113. * Rev 1.0 09 Feb 1996 17:37:42 cjutzi
  114. * Initial revision.
  115. *
  116. *****************************************************************************/
  117. #ifndef STRICT
  118. #define STRICT
  119. #endif
  120. /***********************/
  121. /* SYSTEM INCLUDES */
  122. /***********************/
  123. #include <stdio.h>
  124. #include <stdlib.h>
  125. #include <stddef.h>
  126. #include <limits.h>
  127. #include "precomp.h"
  128. /***********************/
  129. /* H245 INCLUDES */
  130. /***********************/
  131. #ifdef _IA_SPOX_
  132. #define _DLL
  133. #endif //_IA_SPOX_
  134. #include "h245com.h"
  135. #include "sr_api.h"
  136. #if defined(_DEBUG) || defined(PCS_COMPLIANCE)
  137. #include "interop.h"
  138. #include "h245plog.h"
  139. extern LPInteropLogger H245Logger;
  140. #endif // (PCS_COMPLIANCE)
  141. #ifdef _IA_SPOX_
  142. #undef _DLL
  143. #endif //_IA_SPOX_
  144. /**************************************************************************
  145. ** Function : sendPDU
  146. ** Description : Convert struct to ASN.1 PDU and forward to datalink layer
  147. ***************************************************************************/
  148. HRESULT sendPDU(struct InstanceStruct *pInstance,
  149. MltmdSystmCntrlMssg *lp245MsgStruct)
  150. {
  151. HRESULT lError;
  152. ASN1_BUF Asn1Buf;
  153. PBYTE pEncoded_pdu;
  154. int nRet;
  155. // Set up the oss struct for passing a pre-allocated buffer
  156. switch (pInstance->Configuration) {
  157. case H245_CONF_H324:
  158. // Allocate a buffer to transmit
  159. pEncoded_pdu = MemAlloc(pInstance->SendReceive.dwPDUSize);
  160. if (pEncoded_pdu == NULL) {
  161. H245TRACE(pInstance->dwInst, 1, "H245Send: No memory");
  162. return H245_ERROR_NOMEM;
  163. }
  164. Asn1Buf.value = &pEncoded_pdu[2];
  165. Asn1Buf.length = pInstance->SendReceive.dwPDUSize - 4;
  166. break;
  167. case H245_CONF_H323:
  168. // Allocate a buffer to transmit
  169. pEncoded_pdu = MemAlloc(pInstance->SendReceive.dwPDUSize);
  170. if (pEncoded_pdu == NULL) {
  171. H245TRACE(pInstance->dwInst, 1, "H245Send: No memory");
  172. return H245_ERROR_NOMEM;
  173. }
  174. Asn1Buf.value = pEncoded_pdu;
  175. Asn1Buf.length = pInstance->SendReceive.dwPDUSize;
  176. break;
  177. default:
  178. H245TRACE(pInstance->dwInst,
  179. 1,
  180. "SR: Unknown Configuration %d",
  181. pInstance->Configuration);
  182. return H245_ERROR_SUBSYS;
  183. }
  184. nRet = H245_Encode(pInstance->pWorld,
  185. (void *)lp245MsgStruct,
  186. MltmdSystmCntrlMssg_PDU,
  187. &Asn1Buf);
  188. if (ASN1_SUCCEEDED(nRet))
  189. {
  190. H245TRACE(pInstance->dwInst, 3, "H245: Msg Encode Successful");
  191. #if defined(_DEBUG) || defined(PCS_COMPLIANCE)
  192. if (H245Logger)
  193. InteropOutput(H245Logger,
  194. (BYTE FAR*)(pEncoded_pdu),
  195. (int)Asn1Buf.length,
  196. H245LOG_SENT_PDU);
  197. #endif // (PCS_COMPLIANCE)
  198. lError = pInstance->SendReceive.hLinkSendReq(pInstance->SendReceive.hLinkLayerInstance,
  199. pEncoded_pdu,
  200. Asn1Buf.length);
  201. }
  202. else
  203. {
  204. MemFree(pEncoded_pdu);
  205. lError = H245_ERROR_ASN1;
  206. }
  207. return lError;
  208. }
  209. /**************************************************************************
  210. ** Function : h245SendComplete
  211. ** Description : Send Completion Callback routine from link layer
  212. ***************************************************************************/
  213. void h245SendComplete( DWORD_PTR h245Inst,
  214. HRESULT dwMessage,
  215. PBYTE pbDataBuf,
  216. DWORD dwLength)
  217. {
  218. struct InstanceStruct *pInstance;
  219. pInstance = InstanceLock(h245Inst);
  220. if (pInstance == NULL) {
  221. H245TRACE(h245Inst, 1, "SR: h245SendComplete - invalid instance");
  222. return;
  223. }
  224. // Return the buffer
  225. if (pbDataBuf) {
  226. MemFree(pbDataBuf);
  227. }
  228. switch (dwMessage) {
  229. case LINK_SEND_COMPLETE:
  230. if (pInstance->SendReceive.dwFlushMap & SHUTDOWN_PENDING) {
  231. H245TRACE(h245Inst, 10, "SR: Shutdown Complete");
  232. }
  233. break;
  234. case LINK_SEND_ABORT:
  235. H245TRACE(h245Inst, 10, "SR: TX Abort Buffer");
  236. break;
  237. case LINK_FLUSH_COMPLETE:
  238. // If we are in the process of abort, then the next and
  239. // last mesage out will be the endSession
  240. H245TRACE(h245Inst, 10, "SR: TX Flush Complete");
  241. // Indicate Transmit buffer flush is complete
  242. pInstance->SendReceive.dwFlushMap ^= DATALINK_TRANSMIT;
  243. // If all requested queues have been flushed, call the
  244. // appropriate callback routing
  245. switch (pInstance->SendReceive.dwFlushMap & SHUTDOWN_MASK) {
  246. case 0:
  247. // TBD: Who is interested in callback if not in connection
  248. // with shutdown?
  249. break;
  250. case SHUTDOWN_PENDING:
  251. // Flush buffers completed, and shutdown in progress
  252. // notify the API
  253. H245TRACE(h245Inst, 20, "SR: SHUTDOWN CALLBACK");
  254. break;
  255. default:
  256. // Still waiting for buffers to be flushed. No action now
  257. break;
  258. } // switch (pInstance->SendReceive.dwFlushMap & SHUTDOWN_MASK) {
  259. break;
  260. default:
  261. H245TRACE(h245Inst, 10, "SR: SendComplete");
  262. break;
  263. }
  264. InstanceUnlock(pInstance);
  265. }
  266.