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.

391 lines
11 KiB

  1. /***********************************************************************
  2. * *
  3. * Filename: termcap.c *
  4. * Module: H245 Finite State Machine Subsystem *
  5. * *
  6. ***********************************************************************
  7. * INTEL Corporation Proprietary Information *
  8. * *
  9. * This listing is supplied under the terms of a license agreement *
  10. * with INTEL Corporation and may not be copied nor disclosed except *
  11. * in accordance with the terms of that agreement. *
  12. * *
  13. * Copyright (c) 1996 Intel Corporation. All rights reserved. *
  14. ***********************************************************************
  15. * *
  16. * $Workfile: TERMCAP.C $
  17. * $Revision: 1.6 $
  18. * $Modtime: 09 Dec 1996 13:36:34 $
  19. * $Log L:\mphone\h245\h245env\comm\h245_3\h245_fsm\vcs\src\termcap.c_v $
  20. * *
  21. ***********************************************************************/
  22. #include "precomp.h"
  23. #include "h245api.h"
  24. #include "h245com.h"
  25. #include "h245fsm.h"
  26. #include "termcap.h"
  27. #include "pdu.x"
  28. // Terminal Capability Exchange Out-going/In-coming states
  29. #define CapIDLE 0
  30. #define CapAwaitingResponse 1
  31. extern unsigned int uT101;
  32. /***********************************************************************
  33. *
  34. * LOCAL FUNCTIONS
  35. *
  36. ***********************************************************************/
  37. /*
  38. * NAME
  39. * T101ExpiryF - Callback function called by the timer.
  40. *
  41. *
  42. * PARAMETERS
  43. * INPUT dwInst current instance of H245
  44. * INPUT id timer id
  45. * INPUT pObject pointer to a State Entity
  46. *
  47. *
  48. * RETURN VALUE
  49. * OK
  50. */
  51. int T101ExpiryF(struct InstanceStruct *pInstance, DWORD_PTR dwTimerId, void *pObject)
  52. {
  53. return FsmTimerEvent(pInstance, dwTimerId, pObject, T101Expiry);
  54. } // T101ExpiryF()
  55. /***********************************************************************
  56. *
  57. * OUT-GOING FINITE STATE MACHINE FUNCTIONS
  58. *
  59. ***********************************************************************/
  60. /*
  61. * NAME
  62. * requestCapIdle - received TRANSFER.request in idle state
  63. *
  64. *
  65. * PARAMETERS
  66. * INPUT pObject pointer to a FSM object
  67. *
  68. * RETURN VALUE
  69. * error return codes defined in h245com.h
  70. */
  71. HRESULT requestCapIdle(Object_t *pObject, PDU_t *pPdu)
  72. {
  73. HRESULT lError;
  74. ASSERT(pObject->Entity == CESE_OUT);
  75. ASSERT(pObject->State == CapIDLE);
  76. /* Increment sequence number */
  77. pObject->pInstance->StateMachine.byCeseOutSequence++;
  78. pPdu->u.MltmdSystmCntrlMssg_rqst.u.terminalCapabilitySet.sequenceNumber =
  79. pObject->pInstance->StateMachine.byCeseOutSequence;
  80. H245TRACE( pObject->dwInst, 2, "TerminalCapabilitySet to ASN; Sequence=%d",
  81. pObject->pInstance->StateMachine.byCeseOutSequence);
  82. /* Send Terminal Capability Set to remote */
  83. lError = sendPDU(pObject->pInstance, pPdu);
  84. /* set timer T101 */
  85. pObject->State = CapAwaitingResponse;
  86. FsmStartTimer(pObject, T101ExpiryF, uT101);
  87. return lError;
  88. }
  89. /*
  90. * NAME
  91. * termCapAckAwaiting - received termCap Ack in Awaiting state
  92. *
  93. *
  94. * PARAMETERS
  95. * INPUT pObject pointer to a FSM object
  96. *
  97. * RETURN VALUE
  98. * error return codes defined in h245com.h
  99. */
  100. HRESULT termCapAckAwaiting(Object_t *pObject, PDU_t *pPdu)
  101. {
  102. ASSERT(pObject->Entity == CESE_OUT);
  103. ASSERT(pObject->State == CapAwaitingResponse);
  104. /* reset timer T101 */
  105. FsmStopTimer(pObject);
  106. if (pPdu->u.MSCMg_rspns.u.terminalCapabilitySetAck.sequenceNumber ==
  107. pObject->pInstance->StateMachine.byCeseOutSequence)
  108. {
  109. H245TRACE(pObject->dwInst, 2, "H245_CONF_SEND_TERMCAP with no error to API; Sequence=%d",
  110. pObject->pInstance->StateMachine.byCeseOutSequence);
  111. pObject->State = CapIDLE;
  112. H245FsmConfirm(pPdu, H245_CONF_SEND_TERMCAP, pObject->pInstance, pObject->dwTransId, FSM_OK);
  113. }
  114. else
  115. {
  116. H245TRACE(pObject->dwInst, 2, "termCapAckAwaiting: Sequence %d != %d",
  117. pPdu->u.MSCMg_rspns.u.terminalCapabilitySetAck.sequenceNumber,
  118. pObject->pInstance->StateMachine.byCeseOutSequence);
  119. }
  120. return 0;
  121. }
  122. /*
  123. * NAME
  124. * termCapRejAwaiting - received termCap Ack in Awaiting state
  125. *
  126. *
  127. * PARAMETERS
  128. * INPUT pObject pointer to a FSM object
  129. *
  130. * RETURN VALUE
  131. * error return codes defined in h245com.h
  132. */
  133. HRESULT termCapRejAwaiting(Object_t *pObject, PDU_t *pPdu)
  134. {
  135. ASSERT(pObject->Entity == CESE_OUT);
  136. ASSERT(pObject->State == CapAwaitingResponse);
  137. /* reset timer T101 */
  138. FsmStopTimer(pObject);
  139. if (pPdu->u.MSCMg_rspns.u.trmnlCpbltyStRjct.sequenceNumber ==
  140. pObject->pInstance->StateMachine.byCeseOutSequence)
  141. {
  142. H245TRACE(pObject->dwInst, 2, "H245_CONF_SEND_TERMCAP with Reject to API; Sequence=%d",
  143. pObject->pInstance->StateMachine.byCeseOutSequence);
  144. pObject->State = CapIDLE;
  145. H245FsmConfirm(pPdu, H245_CONF_SEND_TERMCAP, pObject->pInstance, pObject->dwTransId, REJECT);
  146. }
  147. else
  148. {
  149. H245TRACE(pObject->dwInst, 2, "termCapRejAwaiting: Sequence %d != %d",
  150. pPdu->u.MSCMg_rspns.u.trmnlCpbltyStRjct.sequenceNumber,
  151. pObject->pInstance->StateMachine.byCeseOutSequence);
  152. }
  153. return 0;
  154. }
  155. /*
  156. * NAME
  157. * t101ExpiryAwaiting - handle timer expiry for an outstanding termcap
  158. *
  159. *
  160. * PARAMETERS
  161. * INPUT pObject pointer to a FSM object
  162. *
  163. * RETURN VALUE
  164. * error return codes defined in h245com.h
  165. */
  166. HRESULT t101ExpiryAwaiting(Object_t *pObject, PDU_t *pPdu)
  167. {
  168. PDU_t * pOut;
  169. HRESULT lError;
  170. ASSERT(pObject->Entity == CESE_OUT);
  171. ASSERT(pObject->State == CapAwaitingResponse);
  172. ASSERT(pPdu == NULL);
  173. pOut = (PDU_t *) MemAlloc(sizeof(*pOut));
  174. if (pOut == NULL)
  175. {
  176. return H245_ERROR_NOMEM;
  177. }
  178. /* Send Terminal Capability Set Release to remote */
  179. pOut->choice = indication_chosen;
  180. pOut->u.indication.choice = trmnlCpbltyStRls_chosen;
  181. lError = sendPDU(pObject->pInstance, pOut);
  182. MemFree(pOut);
  183. /* Send REJECT.indication (SOURCE=PROTOCOL) to client */
  184. H245TRACE(pObject->dwInst, 2, "H245_CONF_SEND_TERMCAP with Timer Expiry to API; Sequence=%d",
  185. pObject->pInstance->StateMachine.byCeseOutSequence);
  186. pObject->State = CapIDLE;
  187. H245FsmConfirm(NULL, H245_CONF_SEND_TERMCAP, pObject->pInstance, pObject->dwTransId, TIMER_EXPIRY);
  188. return lError;
  189. }
  190. /***********************************************************************
  191. *
  192. * IN-COMING FINITE STATE MACHINE FUNCTIONS
  193. *
  194. ***********************************************************************/
  195. /*
  196. * NAME
  197. * termCapSetIdle - received termcap set in idle state
  198. *
  199. *
  200. * PARAMETERS
  201. * INPUT pObject pointer to a FSM object
  202. *
  203. * RETURN VALUE
  204. * error return codes defined in h245com.h
  205. */
  206. HRESULT termCapSetIdle(Object_t *pObject, PDU_t *pPdu)
  207. {
  208. ASSERT(pObject->Entity == CESE_IN);
  209. ASSERT(pObject->State == CapIDLE);
  210. /* Save sequence number from PDU */
  211. pObject->byInSequence = (unsigned char)
  212. pPdu->u.MltmdSystmCntrlMssg_rqst.u.terminalCapabilitySet.sequenceNumber;
  213. H245TRACE(pObject->dwInst, 2, "H245_IND_CAP with no error to API; Sequence=%d",
  214. pObject->byInSequence);
  215. /* Send TRANSFER.indication to client */
  216. pObject->State = CapAwaitingResponse;
  217. H245FsmIndication(pPdu, H245_IND_CAP, pObject->pInstance, pObject->dwTransId, FSM_OK);
  218. return 0;
  219. }
  220. /*
  221. * NAME
  222. * responseCapAwaiting - respond to a termcap with ack
  223. *
  224. *
  225. * PARAMETERS
  226. * INPUT pObject pointer to a FSM object
  227. *
  228. * RETURN VALUE
  229. * error return codes defined in h245com.h
  230. */
  231. HRESULT responseCapAwaiting(Object_t *pObject, PDU_t *pPdu)
  232. {
  233. ASSERT(pObject->Entity == CESE_IN);
  234. ASSERT(pObject->State == CapAwaitingResponse);
  235. H245TRACE(pObject->dwInst, 2, "Send Term Cap Ack to ASN; Sequence=%d",
  236. pObject->byInSequence);
  237. pPdu->u.MSCMg_rspns.u.terminalCapabilitySetAck.sequenceNumber =
  238. pObject->byInSequence;
  239. /* Send Terminal Capability Set Ack to remote */
  240. pObject->State = CapIDLE;
  241. return sendPDU(pObject->pInstance, pPdu);
  242. }
  243. /*
  244. * NAME
  245. * rejectCapAwaiting - respond to a termcap with reject
  246. *
  247. *
  248. * PARAMETERS
  249. * INPUT pObject pointer to a FSM object
  250. *
  251. * RETURN VALUE
  252. * error return codes defined in h245com.h
  253. */
  254. HRESULT rejectCapAwaiting(Object_t *pObject, PDU_t *pPdu)
  255. {
  256. ASSERT(pObject->Entity == CESE_IN);
  257. ASSERT(pObject->State == CapAwaitingResponse);
  258. H245TRACE(pObject->dwInst, 2, "Send Term Cap Reject to ASN; Sequence=%d",
  259. pObject->byInSequence);
  260. pPdu->u.MSCMg_rspns.u.trmnlCpbltyStRjct.sequenceNumber =
  261. pObject->byInSequence;
  262. /* Send Terminal Capability Set Reject to remote */
  263. pObject->State = CapIDLE;
  264. return sendPDU(pObject->pInstance, pPdu);
  265. }
  266. /*
  267. * NAME
  268. * termCapReleaseAwaiting - received termcap release in Awaiting state
  269. *
  270. *
  271. * PARAMETERS
  272. * INPUT pObject pointer to a FSM object
  273. *
  274. * RETURN VALUE
  275. * error return codes defined in h245com.h
  276. */
  277. HRESULT termCapReleaseAwaiting(Object_t *pObject, PDU_t *pPdu)
  278. {
  279. ASSERT(pObject->Entity == CESE_IN);
  280. ASSERT(pObject->State == CapAwaitingResponse);
  281. H245TRACE(pObject->dwInst, 2, "H245_IND_CAP with Reject to API; Sequence=%d",
  282. pObject->byInSequence);
  283. /* Send REJECT.indication (SOURCE = PROTOCOL) to client */
  284. pObject->State = CapIDLE;
  285. H245FsmIndication(pPdu, H245_IND_CESE_RELEASE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  286. return 0;
  287. }
  288. /*
  289. * NAME
  290. * termCapSetAwaiting - received overriding termcap set in Awaiting state
  291. *
  292. *
  293. * PARAMETERS
  294. * INPUT pObject pointer to a FSM object
  295. *
  296. * RETURN VALUE
  297. * error return codes defined in h245com.h
  298. */
  299. HRESULT termCapSetAwaiting(Object_t *pObject, PDU_t *pPdu)
  300. {
  301. ASSERT(pObject->Entity == CESE_IN);
  302. ASSERT(pObject->State == CapAwaitingResponse);
  303. /* Save sequence number from PDU */
  304. pObject->byInSequence = (unsigned char)
  305. pPdu->u.MltmdSystmCntrlMssg_rqst.u.terminalCapabilitySet.sequenceNumber;
  306. H245TRACE( pObject->dwInst, 2, "termCapSetAwaiting: Sequence=%d",
  307. pObject->byInSequence);
  308. #if defined(SDL_COMPLIANT)
  309. /* Send REJECT.indication to client - not necessary */
  310. H245FsmIndication(NULL, H245_IND_CAP, pObject->pInstance, pObject->dwTransId, REJECT);
  311. #endif
  312. /* Send TRANSFER.indication to client */
  313. H245FsmIndication(pPdu, H245_IND_CAP, pObject->pInstance, 0, FSM_OK);
  314. return 0;
  315. }
  316.