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.

442 lines
13 KiB

  1. /***********************************************************************
  2. * *
  3. * Filename: mrse.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: mrse.c $
  17. * $Revision: 1.5 $
  18. * $Modtime: 13 Feb 1997 19:25:48 $
  19. * $Log: S:/STURGEON/SRC/H245/SRC/VCS/mrse.c_v $
  20. *
  21. * Rev 1.5 13 Feb 1997 19:31:20 MANDREWS
  22. * Fixed bug in generation of request mode ack and request mode reject;
  23. * the sequence number was not being copied into the pdu.
  24. *
  25. * Rev 1.4 09 Dec 1996 13:34:46 EHOWARDX
  26. * Updated copyright notice.
  27. *
  28. * Rev 1.3 04 Jun 1996 14:01:06 EHOWARDX
  29. * Fixed Release build warnings.
  30. *
  31. * Rev 1.2 30 May 1996 23:39:16 EHOWARDX
  32. * Cleanup.
  33. *
  34. * Rev 1.1 28 May 1996 14:25:44 EHOWARDX
  35. * Tel Aviv update.
  36. *
  37. * Rev 1.0 09 May 1996 21:06:32 EHOWARDX
  38. * Initial revision.
  39. *
  40. * Rev 1.1 09 May 1996 19:48:08 EHOWARDX
  41. * Change TimerExpiryF function arguements.
  42. *
  43. * Rev 1.0 15 Apr 1996 10:44:52 EHOWARDX
  44. * Initial revision.
  45. * *
  46. ***********************************************************************/
  47. #include "precomp.h"
  48. #include "h245api.h"
  49. #include "h245com.h"
  50. #include "h245fsm.h"
  51. #include "mrse.h"
  52. // Out-going/In-coming MRSE states
  53. #define MRSE_IDLE 0 // IDLE
  54. #define MRSE_WAIT 1 // AWAITING_RESPONSE
  55. extern unsigned int uT109;
  56. /***********************************************************************
  57. *
  58. * LOCAL FUNCTIONS
  59. *
  60. ***********************************************************************/
  61. /*
  62. * NAME
  63. * T109ExpiryF - Callback function called by the timer
  64. *
  65. *
  66. * PARAMETERS
  67. * INPUT dwInst current instance of H245
  68. * INPUT id timer id
  69. * INPUT pObject pointer to a State Entity
  70. *
  71. *
  72. * RETURN VALUE
  73. * OK
  74. */
  75. int T109ExpiryF(struct InstanceStruct *pInstance, DWORD_PTR dwTimerId, void *pObject)
  76. {
  77. return FsmTimerEvent(pInstance, dwTimerId, pObject, T109Expiry);
  78. } // T109ExpiryF()
  79. /***********************************************************************
  80. *
  81. * OUT-GOING FINITE STATE MACHINE FUNCTIONS
  82. *
  83. ***********************************************************************/
  84. /*
  85. * NAME
  86. * MRSE0_TRANSFER_requestF - TRANSFER.request from API in IDLE state
  87. *
  88. *
  89. * PARAMETERS
  90. * INPUT pObject pointer to State Entity
  91. * INPUT pPdu pointer to PDU
  92. *
  93. * RETURN VALUE
  94. * Error return codes defined in h245com.h
  95. */
  96. HRESULT MRSE0_TRANSFER_requestF (Object_t *pObject, PDU_t *pPdu)
  97. {
  98. HRESULT lError;
  99. ASSERT(pObject->Entity == MRSE_OUT);
  100. ASSERT(pObject->State == MRSE_IDLE);
  101. H245TRACE(pObject->dwInst, 2, "MRSE0_TRANSFER_request:%d", pObject->Key);
  102. pObject->pInstance->StateMachine.byMrseOutSequence++;
  103. pPdu->u.MltmdSystmCntrlMssg_rqst.u.requestMode.sequenceNumber =
  104. pObject->pInstance->StateMachine.byMrseOutSequence;
  105. // Send Request Mode PDU to remote
  106. lError = sendPDU(pObject->pInstance, pPdu);
  107. // Set timer T109
  108. pObject->State = MRSE_WAIT;
  109. FsmStartTimer(pObject, T109ExpiryF, uT109);
  110. return lError;
  111. } // MRSE0_TRANSFER_request
  112. /*
  113. * NAME
  114. * MRSE1_TRANSFER_requestF - TRANSFER.request from API in AWAITING RESPONSE state
  115. *
  116. *
  117. * PARAMETERS
  118. * INPUT pObject pointer to State Entity
  119. * INPUT pPdu pointer to PDU
  120. *
  121. * RETURN VALUE
  122. * Error return codes defined in h245com.h
  123. */
  124. HRESULT MRSE1_TRANSFER_requestF (Object_t *pObject, PDU_t *pPdu)
  125. {
  126. HRESULT lError;
  127. ASSERT(pObject->Entity == MRSE_OUT);
  128. ASSERT(pObject->State == MRSE_WAIT);
  129. H245TRACE(pObject->dwInst, 2, "MRSE1_TRANSFER_request:%d", pObject->Key);
  130. // Reset timer T109
  131. FsmStopTimer(pObject);
  132. pObject->pInstance->StateMachine.byMrseOutSequence++;
  133. pPdu->u.MltmdSystmCntrlMssg_rqst.u.requestMode.sequenceNumber =
  134. pObject->pInstance->StateMachine.byMrseOutSequence;
  135. // Send Request Mode PDU to remote
  136. lError = sendPDU(pObject->pInstance, pPdu);
  137. // Set timer T109
  138. FsmStartTimer(pObject, T109ExpiryF, uT109);
  139. return lError;
  140. } // MRSE1_TRANSFER_request
  141. /*
  142. * NAME
  143. * MRSE1_RequestModeAckF - RequestModeAck in AWAITING RESPONSE state
  144. *
  145. *
  146. * PARAMETERS
  147. * INPUT pObject pointer to State Entity
  148. * INPUT pPdu pointer to PDU
  149. *
  150. * RETURN VALUE
  151. * Error return codes defined in h245com.h
  152. */
  153. HRESULT MRSE1_RequestModeAckF (Object_t *pObject, PDU_t *pPdu)
  154. {
  155. ASSERT(pObject->Entity == MRSE_OUT);
  156. ASSERT(pObject->State == MRSE_WAIT);
  157. H245TRACE(pObject->dwInst, 2, "MRSE1_RequestModeAck:%d", pObject->Key);
  158. if (pPdu->u.MSCMg_rspns.u.requestModeAck.sequenceNumber ==
  159. pObject->pInstance->StateMachine.byMrseOutSequence)
  160. {
  161. // Reset timer T109
  162. FsmStopTimer(pObject);
  163. // Send TRANSFER.confirm to H.245 user
  164. pObject->State = MRSE_IDLE;
  165. H245FsmConfirm(pPdu, H245_CONF_MRSE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  166. }
  167. return 0;
  168. } // MRSE1_RequestModeAck
  169. /*
  170. * NAME
  171. * MRSE1_RequestModeRejF - RequestModeReject in AWAITING RESPONSE state
  172. *
  173. *
  174. * PARAMETERS
  175. * INPUT pObject pointer to State Entity
  176. * INPUT pPdu pointer to PDU
  177. *
  178. * RETURN VALUE
  179. * Error return codes defined in h245com.h
  180. */
  181. HRESULT MRSE1_RequestModeRejF (Object_t *pObject, PDU_t *pPdu)
  182. {
  183. ASSERT(pObject->Entity == MRSE_OUT);
  184. ASSERT(pObject->State == MRSE_WAIT);
  185. H245TRACE(pObject->dwInst, 2, "MRSE0_RequestModeRej:%d", pObject->Key);
  186. if (pPdu->u.MSCMg_rspns.u.requestModeReject.sequenceNumber ==
  187. pObject->pInstance->StateMachine.byMrseOutSequence)
  188. {
  189. // Reset timer T109
  190. FsmStopTimer(pObject);
  191. // Send REJECT.indication to H.245 user
  192. // CAUSE = RequestModeReject.cause
  193. pObject->State = MRSE_IDLE;
  194. H245FsmConfirm(pPdu, H245_CONF_MRSE_REJECT, pObject->pInstance, pObject->dwTransId, FSM_OK);
  195. }
  196. return 0;
  197. } // MRSE1_RequestModeRej
  198. /*
  199. * NAME
  200. * MRSE1_T109ExpiryF - timer T109 Expiry
  201. *
  202. *
  203. * PARAMETERS
  204. * INPUT pObject pointer to State Entity
  205. * INPUT pPdu pointer to PDU
  206. *
  207. * RETURN VALUE
  208. * Error return codes defined in h245com.h
  209. */
  210. HRESULT MRSE1_T109ExpiryF (Object_t *pObject, PDU_t *pPdu)
  211. {
  212. HRESULT lError;
  213. PDU_t * pOut;
  214. unsigned short wNumber = (unsigned short) pObject->Key;
  215. ASSERT(pObject->Entity == MRSE_OUT);
  216. ASSERT(pObject->State == MRSE_WAIT);
  217. ASSERT(pPdu == NULL);
  218. H245TRACE(pObject->dwInst, 2, "MRSE1_T109Expiry:%d", pObject->Key);
  219. // Send RequestModeRelease PDU to remote peer
  220. pOut = MemAlloc(sizeof(*pOut));
  221. if (pOut == NULL)
  222. {
  223. H245TRACE(pObject->dwInst, 2,
  224. "MRSE1_T109ExpiryF: memory allocation failed");
  225. return H245_ERROR_NOMEM;
  226. }
  227. pOut->choice = indication_chosen;
  228. pOut->u.indication.choice = requestModeRelease_chosen;
  229. lError = sendPDU(pObject->pInstance, pOut);
  230. MemFree(pOut);
  231. // Send REJECT.indication to H.245 user
  232. // SOURCE := PROTOCOL
  233. pObject->State = MRSE_IDLE;
  234. H245FsmConfirm(NULL, H245_CONF_MRSE_EXPIRED, pObject->pInstance, pObject->dwTransId, FSM_OK);
  235. return lError;
  236. } // MRSE1_T109Expiry
  237. /***********************************************************************
  238. *
  239. * IN-COMING FINITE STATE MACHINE FUNCTIONS
  240. *
  241. ***********************************************************************/
  242. /*
  243. * NAME
  244. * MRSE0_RequestModeF - RequestMode received in IDLE state
  245. *
  246. *
  247. * PARAMETERS
  248. * INPUT pObject pointer to State Entity
  249. * INPUT pPdu pointer to PDU
  250. *
  251. * RETURN VALUE
  252. * Error return codes defined in h245com.h
  253. */
  254. HRESULT MRSE0_RequestModeF (Object_t *pObject, PDU_t *pPdu)
  255. {
  256. ASSERT(pObject->Entity == MRSE_IN);
  257. ASSERT(pObject->State == MRSE_IDLE);
  258. H245TRACE(pObject->dwInst, 2, "MRSE0_RequestMode:%d", pObject->Key);
  259. pObject->byInSequence = (unsigned char)
  260. pPdu->u.MltmdSystmCntrlMssg_rqst.u.requestMode.sequenceNumber;
  261. // Send TRANSFER.indication to H.245 user
  262. pObject->State = MRSE_WAIT;
  263. H245FsmIndication(pPdu, H245_IND_MRSE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  264. return 0;
  265. } // MRSE0_RequestMode
  266. /*
  267. * NAME
  268. * MRSE1_RequestModeF - RequestMode received in AWAITING RESPONSE state
  269. *
  270. *
  271. * PARAMETERS
  272. * INPUT pObject pointer to State Entity
  273. * INPUT pPdu pointer to PDU
  274. *
  275. * RETURN VALUE
  276. * Error return codes defined in h245com.h
  277. */
  278. HRESULT MRSE1_RequestModeF (Object_t *pObject, PDU_t *pPdu)
  279. {
  280. ASSERT(pObject->Entity == MRSE_IN);
  281. ASSERT(pObject->State == MRSE_WAIT);
  282. H245TRACE(pObject->dwInst, 2, "MRSE1_RequestMode:%d", pObject->Key);
  283. pObject->byInSequence = (unsigned char)
  284. pPdu->u.MltmdSystmCntrlMssg_rqst.u.requestMode.sequenceNumber;
  285. #if defined(SDL_COMPLIANT)
  286. // Send REJECT.indication to H.245 user
  287. H245FsmIndication(pPdu, H245_IND_MRSE_RELEASE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  288. #endif
  289. // Send TRANSFER.indication to H.245 user
  290. H245FsmIndication(pPdu, H245_IND_MRSE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  291. return 0;
  292. } // MRSE1_RequestMode
  293. /*
  294. * NAME
  295. * MRSE1_RequestModeReleaseF - RequestModeRelease received in AWAITING RESPONSE state
  296. *
  297. *
  298. * PARAMETERS
  299. * INPUT pObject pointer to State Entity
  300. * INPUT pPdu pointer to PDU
  301. *
  302. * RETURN VALUE
  303. * Error return codes defined in h245com.h
  304. */
  305. HRESULT MRSE1_RequestModeReleaseF (Object_t *pObject, PDU_t *pPdu)
  306. {
  307. ASSERT(pObject->Entity == MRSE_IN);
  308. ASSERT(pObject->State == MRSE_WAIT);
  309. H245TRACE(pObject->dwInst, 2, "MRSE1_RequestModeRelease:%d", pObject->Key);
  310. // Send REJECT.indication to H.245 user
  311. // SOURCE:=PROTOCOL
  312. pObject->State = MRSE_IDLE;
  313. H245FsmIndication(pPdu, H245_IND_MRSE_RELEASE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  314. return 0;
  315. } // MRSE1_RequestModeRelease
  316. /*
  317. * NAME
  318. * MRSE1_TRANSFER_responseF - TRANSFER.response from API in AWAITING RESPONSE state
  319. *
  320. *
  321. * PARAMETERS
  322. * INPUT pObject pointer to State Entity
  323. * INPUT pPdu pointer to PDU
  324. *
  325. * RETURN VALUE
  326. * Error return codes defined in h245com.h
  327. */
  328. HRESULT MRSE1_TRANSFER_responseF (Object_t *pObject, PDU_t *pPdu)
  329. {
  330. ASSERT(pObject->Entity == MRSE_IN);
  331. ASSERT(pObject->State == MRSE_WAIT);
  332. H245TRACE(pObject->dwInst, 2, "MRSE1_TRANSFER_response:%d", pObject->Key);
  333. // Send RequestModeAck PDU to remote peer
  334. pObject->State = MRSE_IDLE;
  335. pPdu->u.MSCMg_rspns.u.requestModeAck.sequenceNumber = pObject->byInSequence;
  336. return sendPDU(pObject->pInstance, pPdu);
  337. } // MRSE1_TRANSFER_response
  338. /*
  339. * NAME
  340. * MRSE1_REJECT_requestF - REJECT.request from API in AWAITING RESPONSE state
  341. *
  342. *
  343. * PARAMETERS
  344. * INPUT pObject pointer to State Entity
  345. * INPUT pPdu pointer to PDU
  346. *
  347. * RETURN VALUE
  348. * Error return codes defined in h245com.h
  349. */
  350. HRESULT MRSE1_REJECT_requestF (Object_t *pObject, PDU_t *pPdu)
  351. {
  352. ASSERT(pObject->Entity == MRSE_IN);
  353. ASSERT(pObject->State == MRSE_WAIT);
  354. H245TRACE(pObject->dwInst, 2, "MRSE1_REJECT_request:%d", pObject->Key);
  355. // Send RequestModeReject PDU to remote
  356. pObject->State = MRSE_IDLE;
  357. pPdu->u.MSCMg_rspns.u.requestModeReject.sequenceNumber = pObject->byInSequence;
  358. return sendPDU(pObject->pInstance, pPdu);
  359. } // MRSE1_REJECT_request
  360.