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.

522 lines
16 KiB

  1. /***********************************************************************
  2. * *
  3. * Filename: muxentry.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: MUXENTRY.C $
  17. * $Revision: 1.5 $
  18. * $Modtime: 09 Dec 1996 13:34:24 $
  19. * $Log: S:/STURGEON/SRC/H245/SRC/VCS/MUXENTRY.C_v $
  20. *
  21. * Rev 1.5 09 Dec 1996 13:34:50 EHOWARDX
  22. * Updated copyright notice.
  23. *
  24. * Rev 1.4 19 Jul 1996 12:12:46 EHOWARDX
  25. *
  26. * Changed to use API events defined in H245API.H instead of FSM events
  27. * which are no longer defined in FSMEXPOR.H.
  28. *
  29. * Rev 1.3 14 Jun 1996 18:58:30 EHOWARDX
  30. * Geneva Update.
  31. *
  32. * Rev 1.2 04 Jun 1996 13:57:06 EHOWARDX
  33. * Fixed Release build warnings.
  34. *
  35. * Rev 1.1 30 May 1996 23:39:18 EHOWARDX
  36. * Cleanup.
  37. *
  38. * Rev 1.0 09 May 1996 21:06:34 EHOWARDX
  39. * Initial revision.
  40. *
  41. * Rev 1.14.1.3 09 May 1996 19:48:36 EHOWARDX
  42. * Change TimerExpiryF function arguements.
  43. *
  44. * Rev 1.14.1.2 15 Apr 1996 10:46:00 EHOWARDX
  45. * Update.
  46. *
  47. * Rev 1.14.1.1 10 Apr 1996 21:15:00 EHOWARDX
  48. * Check-in for safety in middle of re-design.
  49. *
  50. * Rev 1.14.1.0 05 Apr 1996 20:52:56 EHOWARDX
  51. * Branched.
  52. *
  53. * Rev 1.14 02 Apr 1996 12:01:58 helgebax
  54. * documented code
  55. *
  56. * Rev 1.13 28 Mar 1996 11:20:52 helgebax
  57. * removed mux release, fixed return values
  58. *
  59. * Rev 1.12 19 Mar 1996 18:09:46 helgebax
  60. *
  61. * removed include file: h245time.h
  62. *
  63. * Rev 1.11 19 Mar 1996 17:31:36 helgebax
  64. *
  65. * added new timers
  66. *
  67. * Rev 1.10 13 Mar 1996 11:49:14 helgebax
  68. * s can also access already deleted objects
  69. *
  70. * Rev 1.9 13 Mar 1996 08:58:46 helgebax
  71. * No change.
  72. *
  73. * Rev 1.8 11 Mar 1996 14:31:32 helgebax
  74. * removed prototype def for release function (moved to pdu.x)
  75. *
  76. * Rev 1.7 07 Mar 1996 13:23:12 helgebax
  77. * changed pObject->pdu_struct to NULL in timerExpiry function because the
  78. * pdu pointer has been deleted
  79. *
  80. * Rev 1.6 01 Mar 1996 13:22:46 unknown
  81. *
  82. * Changed to used pdu_id to save muxentry number so when timeout occurs
  83. * we can send the correct muxentry number in the MultiplexEntrySendRelease.
  84. *
  85. * Rev 1.5 01 Mar 1996 11:47:56 unknown
  86. * Since nSequence was removed from header, I have commented out
  87. * all references to it in the code. Also, state ASSERTs have been
  88. * changed to reflect the fact that state changes occur BEFORE
  89. * calling the state function, rather than AFTER.
  90. *
  91. * Rev 1.4 29 Feb 1996 20:57:20 helgebax
  92. * No change.
  93. *
  94. * Rev 1.3 29 Feb 1996 18:19:46 EHOWARDX
  95. * Made changes requested by Hani.
  96. *
  97. * Rev 1.2 28 Feb 1996 15:47:04 EHOWARDX
  98. *
  99. * First pass MTSE implementation complete.
  100. * *
  101. ***********************************************************************/
  102. #include "precomp.h"
  103. #include "h245api.h"
  104. #include "h245com.h"
  105. #include "h245fsm.h"
  106. #include "muxentry.h"
  107. // Out-going/In-coming MTSE states
  108. #define MTSE_IDLE 0 // IDLE
  109. #define MTSE_WAIT 1 // AWAITING_RESPONSE
  110. extern unsigned int uT104;
  111. /***********************************************************************
  112. *
  113. * LOCAL FUNCTIONS
  114. *
  115. ***********************************************************************/
  116. /*
  117. * NAME
  118. * T103ExpiryF - Callback function called by the timer
  119. *
  120. *
  121. * PARAMETERS
  122. * INPUT dwInst current instance of H245
  123. * INPUT id timer id
  124. * INPUT pObject pointer to a State Entity
  125. *
  126. *
  127. * RETURN VALUE
  128. * OK
  129. */
  130. int T104ExpiryF(struct InstanceStruct *pInstance, DWORD_PTR dwTimerId, void *pObject)
  131. {
  132. return FsmTimerEvent(pInstance, dwTimerId, pObject, T104Expiry);
  133. } // T104ExpiryF()
  134. /***********************************************************************
  135. *
  136. * OUT-GOING FINITE STATE MACHINE FUNCTIONS
  137. *
  138. ***********************************************************************/
  139. /*
  140. * NAME
  141. * MTSE0_TRANSFER_requestF - TRANSFER.request from API in IDLE state
  142. *
  143. *
  144. * PARAMETERS
  145. * INPUT pObject pointer to State Entity
  146. * INPUT pPdu pointer to PDU
  147. *
  148. * RETURN VALUE
  149. * Error return codes defined in h245com.h
  150. */
  151. HRESULT MTSE0_TRANSFER_requestF (Object_t *pObject, PDU_t *pPdu)
  152. {
  153. HRESULT lError;
  154. unsigned int uIndex;
  155. MultiplexEntryDescriptorLink pLink;
  156. ASSERT(pObject->Entity == MTSE_OUT);
  157. ASSERT(pObject->State == MTSE_IDLE);
  158. H245TRACE(pObject->dwInst, 2, "MTSE0_TRANSFER_request:%d", pObject->Key);
  159. pObject->pInstance->StateMachine.byMtseOutSequence++;
  160. pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.sequenceNumber =
  161. pObject->pInstance->StateMachine.byMtseOutSequence;
  162. // Save information for release
  163. uIndex = 0;
  164. pLink = pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.multiplexEntryDescriptors;
  165. while (pLink)
  166. {
  167. pObject->u.mtse.multiplexTableEntryNumber.value[uIndex++] =
  168. pLink->value.multiplexTableEntryNumber;
  169. pLink = pLink->next;
  170. }
  171. pObject->u.mtse.multiplexTableEntryNumber.count = (unsigned short)uIndex;
  172. // Send MultiplexEntrySend PDU to remote
  173. lError = sendPDU(pObject->pInstance, pPdu);
  174. // Set timer T104
  175. pObject->State = MTSE_WAIT;
  176. FsmStartTimer(pObject, T104ExpiryF, uT104);
  177. return lError;
  178. } // MTSE0_TRANSFER_request
  179. /*
  180. * NAME
  181. * MTSE1_TRANSFER_requestF - TRANSFER.request from API in AWAITING RESPONSE state
  182. *
  183. *
  184. * PARAMETERS
  185. * INPUT pObject pointer to State Entity
  186. * INPUT pPdu pointer to PDU
  187. *
  188. * RETURN VALUE
  189. * Error return codes defined in h245com.h
  190. */
  191. HRESULT MTSE1_TRANSFER_requestF (Object_t *pObject, PDU_t *pPdu)
  192. {
  193. HRESULT lError;
  194. unsigned int uIndex;
  195. MultiplexEntryDescriptorLink pLink;
  196. ASSERT(pObject->Entity == MTSE_OUT);
  197. ASSERT(pObject->State == MTSE_WAIT);
  198. H245TRACE(pObject->dwInst, 2, "MTSE1_TRANSFER_request:%d", pObject->Key);
  199. // Reset timer T104
  200. FsmStopTimer(pObject);
  201. pObject->pInstance->StateMachine.byMtseOutSequence++;
  202. pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.sequenceNumber =
  203. pObject->pInstance->StateMachine.byMtseOutSequence;
  204. // Save information for release
  205. uIndex = 0;
  206. pLink = pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.multiplexEntryDescriptors;
  207. while (pLink)
  208. {
  209. pObject->u.mtse.multiplexTableEntryNumber.value[uIndex++] =
  210. pLink->value.multiplexTableEntryNumber;
  211. pLink = pLink->next;
  212. }
  213. pObject->u.mtse.multiplexTableEntryNumber.count = (unsigned short)uIndex;
  214. // Send MultiplexEntrySend PDU to remote
  215. lError = sendPDU(pObject->pInstance, pPdu);
  216. // Set timer T104
  217. FsmStartTimer(pObject, T104ExpiryF, uT104);
  218. return lError;
  219. } // MTSE1_TRANSFER_request
  220. /*
  221. * NAME
  222. * MTSE1_MultiplexEntrySendAckF - MultiplexEntrySendAck in AWAITING RESPONSE state
  223. *
  224. *
  225. * PARAMETERS
  226. * INPUT pObject pointer to State Entity
  227. * INPUT pPdu pointer to PDU
  228. *
  229. * RETURN VALUE
  230. * Error return codes defined in h245com.h
  231. */
  232. HRESULT MTSE1_MultiplexEntrySendAckF (Object_t *pObject, PDU_t *pPdu)
  233. {
  234. ASSERT(pObject->Entity == MTSE_OUT);
  235. ASSERT(pObject->State == MTSE_WAIT);
  236. H245TRACE(pObject->dwInst, 2, "MTSE1_MultiplexEntrySendAck:%d", pObject->Key);
  237. if (pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.sequenceNumber ==
  238. pObject->pInstance->StateMachine.byMtseOutSequence)
  239. {
  240. // Reset timer T104
  241. FsmStopTimer(pObject);
  242. // Send TRANSFER.confirm to H.245 user
  243. pObject->State = MTSE_IDLE;
  244. H245FsmConfirm(pPdu, H245_CONF_MUXTBL_SND, pObject->pInstance, pObject->dwTransId, FSM_OK);
  245. }
  246. return 0;
  247. } // MTSE1_MultiplexEntrySendAck
  248. /*
  249. * NAME
  250. * MTSE1_MultiplexEntrySendRejF - MultiplexEntrySendReject in AWAITING RESPONSE state
  251. *
  252. *
  253. * PARAMETERS
  254. * INPUT pObject pointer to State Entity
  255. * INPUT pPdu pointer to PDU
  256. *
  257. * RETURN VALUE
  258. * Error return codes defined in h245com.h
  259. */
  260. HRESULT MTSE1_MultiplexEntrySendRejF (Object_t *pObject, PDU_t *pPdu)
  261. {
  262. ASSERT(pObject->Entity == MTSE_OUT);
  263. ASSERT(pObject->State == MTSE_WAIT);
  264. H245TRACE(pObject->dwInst, 2, "MTSE0_MultiplexEntrySendRej:%d", pObject->Key);
  265. if (pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.sequenceNumber ==
  266. pObject->pInstance->StateMachine.byMtseOutSequence)
  267. {
  268. // Reset timer T104
  269. FsmStopTimer(pObject);
  270. // Send REJECT.indication to H.245 user
  271. // CAUSE = MultiplexEntrySendReject.cause
  272. pObject->State = MTSE_IDLE;
  273. H245FsmConfirm(pPdu, H245_CONF_MUXTBL_SND, pObject->pInstance, pObject->dwTransId, REJECT);
  274. }
  275. return 0;
  276. } // MTSE1_MultiplexEntrySendRej
  277. /*
  278. * NAME
  279. * MTSE1_T104ExpiryF - timer T104 Expiry
  280. *
  281. *
  282. * PARAMETERS
  283. * INPUT pObject pointer to State Entity
  284. * INPUT pPdu pointer to PDU
  285. *
  286. * RETURN VALUE
  287. * Error return codes defined in h245com.h
  288. */
  289. HRESULT MTSE1_T104ExpiryF (Object_t *pObject, PDU_t *pPdu)
  290. {
  291. HRESULT lError;
  292. PDU_t * pOut;
  293. unsigned short wNumber = (unsigned short) pObject->Key;
  294. ASSERT(pObject->Entity == MTSE_OUT);
  295. ASSERT(pObject->State == MTSE_WAIT);
  296. ASSERT(pPdu == NULL);
  297. H245TRACE(pObject->dwInst, 2, "MTSE1_T104Expiry:%d", pObject->Key);
  298. // Send MultiplexEntrySendRelease PDU to remote peer
  299. pOut = MemAlloc(sizeof(*pOut));
  300. if (pOut == NULL)
  301. {
  302. H245TRACE(pObject->dwInst, 2,
  303. "MTSE1_T104ExpiryF: memory allocation failed");
  304. return H245_ERROR_NOMEM;
  305. }
  306. pOut->choice = indication_chosen;
  307. pOut->u.indication.choice = mltplxEntrySndRls_chosen;
  308. pOut->u.indication.u.mltplxEntrySndRls = pObject->u.mtse;
  309. lError = sendPDU(pObject->pInstance, pOut);
  310. MemFree(pOut);
  311. // Send REJECT.indication to H.245 user
  312. // SOURCE = PROTOCOL
  313. pObject->State = MTSE_IDLE;
  314. H245FsmConfirm(NULL, H245_CONF_MUXTBL_SND, pObject->pInstance, pObject->dwTransId, TIMER_EXPIRY);
  315. return lError;
  316. } // MTSE1_T104Expiry
  317. /***********************************************************************
  318. *
  319. * IN-COMING FINITE STATE MACHINE FUNCTIONS
  320. *
  321. ***********************************************************************/
  322. /*
  323. * NAME
  324. * MTSE0_MultiplexEntrySendF - MultiplexEntrySend received in IDLE state
  325. *
  326. *
  327. * PARAMETERS
  328. * INPUT pObject pointer to State Entity
  329. * INPUT pPdu pointer to PDU
  330. *
  331. * RETURN VALUE
  332. * Error return codes defined in h245com.h
  333. */
  334. HRESULT MTSE0_MultiplexEntrySendF (Object_t *pObject, PDU_t *pPdu)
  335. {
  336. ASSERT(pObject->Entity == MTSE_IN);
  337. ASSERT(pObject->State == MTSE_IDLE);
  338. H245TRACE(pObject->dwInst, 2, "MTSE0_MultiplexEntrySend:%d", pObject->Key);
  339. pObject->byInSequence = (unsigned char)
  340. pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.sequenceNumber;
  341. // Send TRANSFER.indication to H.245 user
  342. pObject->State = MTSE_WAIT;
  343. H245FsmIndication(pPdu, H245_IND_MUX_TBL, pObject->pInstance, pObject->dwTransId, FSM_OK);
  344. return 0;
  345. } // MTSE0_MultiplexEntrySend
  346. /*
  347. * NAME
  348. * MTSE1_MultiplexEntrySendF - MultiplexEntrySend received in AWAITING RESPONSE state
  349. *
  350. *
  351. * PARAMETERS
  352. * INPUT pObject pointer to State Entity
  353. * INPUT pPdu pointer to PDU
  354. *
  355. * RETURN VALUE
  356. * Error return codes defined in h245com.h
  357. */
  358. HRESULT MTSE1_MultiplexEntrySendF (Object_t *pObject, PDU_t *pPdu)
  359. {
  360. ASSERT(pObject->Entity == MTSE_IN);
  361. ASSERT(pObject->State == MTSE_WAIT);
  362. H245TRACE(pObject->dwInst, 2, "MTSE1_MultiplexEntrySend:%d", pObject->Key);
  363. pObject->byInSequence = (unsigned char)
  364. pPdu->u.MltmdSystmCntrlMssg_rqst.u.multiplexEntrySend.sequenceNumber;
  365. #if defined(SDL_COMPLIANT)
  366. // Send REJECT.indication to H.245 user
  367. H245FsmIndication(pPdu, H245_IND_MTSE_RELEASE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  368. #endif
  369. // Send TRANSFER.indication to H.245 user
  370. H245FsmIndication(pPdu, H245_IND_MUX_TBL, pObject->pInstance, pObject->dwTransId, FSM_OK);
  371. return 0;
  372. } // MTSE1_MultiplexEntrySend
  373. /*
  374. * NAME
  375. * MTSE1_MultiplexEntrySendReleaseF - MultiplexEntrySendRelease received in AWAITING RESPONSE state
  376. *
  377. *
  378. * PARAMETERS
  379. * INPUT pObject pointer to State Entity
  380. * INPUT pPdu pointer to PDU
  381. *
  382. * RETURN VALUE
  383. * Error return codes defined in h245com.h
  384. */
  385. HRESULT MTSE1_MultiplexEntrySendReleaseF (Object_t *pObject, PDU_t *pPdu)
  386. {
  387. ASSERT(pObject->Entity == MTSE_IN);
  388. ASSERT(pObject->State == MTSE_WAIT);
  389. H245TRACE(pObject->dwInst, 2, "MTSE1_MultiplexEntrySendRelease:%d", pObject->Key);
  390. // Send REJECT.indication to H.245 user
  391. // SOURCE:=PROTOCOL
  392. pObject->State = MTSE_IDLE;
  393. H245FsmIndication(pPdu, H245_IND_MTSE_RELEASE, pObject->pInstance, pObject->dwTransId, FSM_OK);
  394. return 0;
  395. } // MTSE1_MultiplexEntrySendRelease
  396. /*
  397. * NAME
  398. * MTSE1_TRANSFER_responseF - TRANSFER.response from API in AWAITING RESPONSE state
  399. *
  400. *
  401. * PARAMETERS
  402. * INPUT pObject pointer to State Entity
  403. * INPUT pPdu pointer to PDU
  404. *
  405. * RETURN VALUE
  406. * Error return codes defined in h245com.h
  407. */
  408. HRESULT MTSE1_TRANSFER_responseF (Object_t *pObject, PDU_t *pPdu)
  409. {
  410. ASSERT(pObject->Entity == MTSE_IN);
  411. ASSERT(pObject->State == MTSE_WAIT);
  412. H245TRACE(pObject->dwInst, 2, "MTSE1_TRANSFER_response:%d", pObject->Key);
  413. // Send MultiplexEntrySendAck PDU to remote peer
  414. pObject->State = MTSE_IDLE;
  415. return sendPDU(pObject->pInstance, pPdu);
  416. } // MTSE1_TRANSFER_response
  417. /*
  418. * NAME
  419. * MTSE1_REJECT_requestF - REJECT.request from API in AWAITING RESPONSE state
  420. *
  421. *
  422. * PARAMETERS
  423. * INPUT pObject pointer to State Entity
  424. * INPUT pPdu pointer to PDU
  425. *
  426. * RETURN VALUE
  427. * Error return codes defined in h245com.h
  428. */
  429. HRESULT MTSE1_REJECT_requestF (Object_t *pObject, PDU_t *pPdu)
  430. {
  431. ASSERT(pObject->Entity == MTSE_IN);
  432. ASSERT(pObject->State == MTSE_WAIT);
  433. H245TRACE(pObject->dwInst, 2, "MTSE1_REJECT_request:%d", pObject->Key);
  434. // Send MultiplexEntrySendReject PDU to remote
  435. pObject->State = MTSE_IDLE;
  436. return sendPDU(pObject->pInstance, pPdu);
  437. } // MTSE1_REJECT_request
  438.