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.

824 lines
40 KiB

  1. /***********************************************************************
  2. * *
  3. * Filename: fsm.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: FSM.C $
  17. * $Revision: 1.5 $
  18. * $Modtime: 09 Dec 1996 13:34:24 $
  19. * $Log: S:/STURGEON/SRC/H245/SRC/VCS/FSM.C_v $
  20. *
  21. * Rev 1.5 09 Dec 1996 13:34:28 EHOWARDX
  22. * Updated copyright notice.
  23. *
  24. * Rev 1.4 02 Jul 1996 00:09:24 EHOWARDX
  25. *
  26. * Added trace of state after state machine function called.
  27. *
  28. * Rev 1.3 30 May 1996 23:39:04 EHOWARDX
  29. * Cleanup.
  30. *
  31. * Rev 1.2 29 May 1996 15:20:12 EHOWARDX
  32. * Change to use HRESULT.
  33. *
  34. * Rev 1.1 28 May 1996 14:25:48 EHOWARDX
  35. * Tel Aviv update.
  36. *
  37. * Rev 1.0 09 May 1996 21:06:12 EHOWARDX
  38. * Initial revision.
  39. *
  40. * Rev 1.16.1.4 09 May 1996 19:48:34 EHOWARDX
  41. * Change TimerExpiryF function arguements.
  42. *
  43. * Rev 1.16.1.3 25 Apr 1996 17:00:18 EHOWARDX
  44. * Minor fixes.
  45. *
  46. * Rev 1.16.1.2 15 Apr 1996 10:45:38 EHOWARDX
  47. * Update.
  48. *
  49. * Rev 1.16.1.1 10 Apr 1996 21:16:06 EHOWARDX
  50. * Check-in for safety in middle of re-design.
  51. *
  52. * Rev 1.16.1.0 05 Apr 1996 12:21:16 EHOWARDX
  53. * Branched.
  54. * *
  55. ***********************************************************************/
  56. #include "precomp.h"
  57. #include "h245api.h"
  58. #include "h245com.h"
  59. #include "h245fsm.h"
  60. #include "openu.h"
  61. #include "openb.h"
  62. #include "rqstcls.h"
  63. #include "termcap.h"
  64. #include "muxentry.h"
  65. #include "rmese.h"
  66. #include "mrse.h"
  67. #include "mlse.h"
  68. #include "mstrslv.h"
  69. #include "rtdse.h"
  70. #if defined(_DEBUG)
  71. // Signalling Entity definitions
  72. char * EntityName[NUM_ENTITYS] =
  73. {
  74. // Per-channel Signalling Entities
  75. "LCSE_OUT", // 0 Uni-directional Logical Channel signalling Signalling Entity - Outbound
  76. "LCSE_IN", // 1 Uni-directional Logical Channel signalling Signalling Entity - Inbound
  77. "BLCSE_OUT", // 2 Bi-directional Logical Channel signalling Signalling Entity - Outbound
  78. "BLCSE_IN", // 3 Bi-directional Logical Channel signalling Signalling Entity - Inbound
  79. "CLCSE_OUT", // 4 Close Logical Channel signalling Signalling Entity - Outbound
  80. "CLCSE_IN", // 5 Close Logical Channel signalling Signalling Entity - Inbound
  81. // Per H.245 Instance Signalling Entities
  82. "CESE_OUT", // 6 Capability Exchange Signalling Entity - Out-going
  83. "CESE_IN", // 7 Capability Exchange Signalling Entity - In-coming
  84. "MTSE_OUT", // 8 Multiplex Table Signalling Entity - Out-going
  85. "MTSE_IN", // 9 Multiplex Table Signalling Entity - In-coming
  86. "RMESE_OUT", // 10 Request Multiplex Entry Signalling Entity - Out-going
  87. "RMESE_IN", // 11 Request Multiplex Entry Signalling Entity - In-coming
  88. "MRSE_OUT", // 12 Mode Request Signalling Entity - Out-going
  89. "MRSE_IN", // 13 Mode Request Signalling Entity - In-coming
  90. "MLSE_OUT", // 14 Maintenance Loop Signalling Entity - Out-going
  91. "MLSE_IN", // 15 Maintenance Loop Signalling Entity - In-coming
  92. "MSDSE", // 16 Master Slave Determination Signalling Entity
  93. "RTDSE", // 17 Round Trip Delay Signalling Entity
  94. "STATELESS", // 18 No state machine associated with PDU
  95. };
  96. // Event definitions
  97. char * EventName[NUM_EVENTS] =
  98. {
  99. // Out-going Uni-directional Logical Channel (LCSE_OUT) events
  100. "ReqUEstablish", // 0
  101. "OpenUChAckPDU", // 1
  102. "OpenUChRejectPDU", // 2
  103. "CloseUChAckPDU", // 3
  104. "ReqURelease", // 4
  105. "T103Expiry", // 5
  106. // In-coming Uni-directional Logical Channel (LCSE_IN) events
  107. "OpenUChPDU", // 6
  108. "CloseUChPDU", // 7
  109. "ResponseUEstablish", // 8
  110. "EstablishUReject", // 9
  111. // Out-going Bi-directional Logical Channel (BLCSE_OUT) events
  112. "ReqBEstablish", // 10
  113. "OpenBChAckPDU", // 11
  114. "OpenBChRejectPDU", // 12
  115. "CloseBChAckPDU", // 13
  116. "ReqClsBLCSE", // 14
  117. "RspConfirmBLCSE", // 15
  118. "T103OutExpiry", // 16
  119. // In-coming Bi-directional Logical Channel (BLCSE_IN) events
  120. "OpenBChPDU", // 17
  121. "CloseBChPDU", // 18
  122. "ResponseBEstablish", // 19
  123. "OpenBChConfirmPDU", // 20
  124. "OpenRejectBLCSE", // 21
  125. "T103InExpiry", // 22
  126. // Out-going Request Close Logical Channel (CLCSE_OUT) events
  127. "ReqClose", // 23
  128. "ReqChCloseAckPDU", // 24
  129. "ReqChCloseRejectPDU", // 25
  130. "T108Expiry", // 26
  131. // In-coming Request Close Logical Channel (CLCSE_IN) events
  132. "ReqChClosePDU", // 27
  133. "ReqChCloseReleasePDU", // 28
  134. "CLCSE_CLOSE_response", // 29
  135. "CLCSE_REJECT_request", // 30
  136. // Out-going Terminal Capablity Exchange (CESE_OUT) events
  137. "TransferCapRequest", // 31
  138. "TermCapSetAckPDU", // 32
  139. "TermCapSetRejectPDU", // 33
  140. "T101Expiry", // 34
  141. // In-coming Terminal Capablity Exchange (CESE_IN) events
  142. "TermCapSetPDU", // 35
  143. "TermCapSetReleasePDU", // 36
  144. "CESE_TRANSFER_response", // 37
  145. "CESE_REJECT_request", // 38
  146. // Out-going Multiplex Table (MTSE_OUT) events
  147. "MTSE_TRANSFER_request", // 39
  148. "MultiplexEntrySendAckPDU", // 40
  149. "MultiplexEntrySendRejectPDU", // 41
  150. "T104Expiry", // 42
  151. // In-coming Multiplex Table (MTSE_IN) events
  152. "MultiplexEntrySendPDU", // 43
  153. "MultiplexEntrySendReleasePDU", // 44
  154. "MTSE_TRANSFER_response", // 45
  155. "MTSE_REJECT_request", // 46
  156. // Out-going Request Multiplex Entry (RMESE_OUT) events
  157. "RMESE_SEND_request", // 47
  158. "RequestMultiplexEntryAckPDU", // 48
  159. "RequestMultiplexEntryRejectPDU",// 49
  160. "T107Expiry", // 50
  161. // In-coming Request Multiplex Entry (RMESE_IN) events
  162. "RequestMultiplexEntryPDU", // 51
  163. "RequestMultiplexEntryReleasePDU",// 52
  164. "RMESE_SEND_response", // 53
  165. "RMESE_REJECT_request", // 54
  166. // Out-going Mode Request (MRSE_OUT) events
  167. "MRSE_TRANSFER_request", // 55
  168. "RequestModeAckPDU", // 56
  169. "RequestModeRejectPDU", // 57
  170. "T109Expiry", // 58
  171. // In-coming Mode Request (MRSE_IN) events
  172. "RequestModePDU", // 59
  173. "RequestModeReleasePDU", // 60
  174. "MRSE_TRANSFER_response", // 61
  175. "MRSE_REJECT_request", // 62
  176. // Out-going Maintenance Loop (MLSE_OUT) events
  177. "MLSE_LOOP_request", // 63
  178. "MLSE_OUT_RELEASE_request", // 64
  179. "MaintenanceLoopAckPDU", // 65
  180. "MaintenanceLoopRejectPDU", // 66
  181. "T102Expiry", // 67
  182. // In-coming Maintenance Loop (MLSE_IN) events
  183. "MaintenanceLoopRequestPDU", // 68
  184. "MaintenanceLoopOffCommandPDU", // 69
  185. "MLSE_LOOP_response", // 70
  186. "MLSE_IN_RELEASE_request", // 71
  187. // Master Slave Determination (MSDSE) events
  188. "MSDetReq", // 72
  189. "MSDetPDU", // 73
  190. "MSDetAckPDU", // 74
  191. "MSDetRejectPDU", // 75
  192. "MSDetReleasePDU", // 76
  193. "T106Expiry", // 77
  194. // Round Trip Delay Delay (RTDSE) events
  195. "RTDSE_TRANSFER_request", // 78
  196. "RoundTripDelayRequestPDU", // 79
  197. "RoundTripDelayResponsePDU", // 80
  198. "T105Expiry", // 81
  199. // Events with no associated state entity
  200. "NonStandardRequestPDU", // 82
  201. "NonStandardResponsePDU", // 83
  202. "NonStandardCommandPDU", // 84
  203. "NonStandardIndicationPDU", // 85
  204. "MiscellaneousRequestPDU", // 86
  205. "MiscellaneousResponsePDU", // 87
  206. "MiscellaneousCommandPDU", // 88
  207. "MiscellaneousIndicationPDU", // 89
  208. "CommunicationModeRequestPDU", // 90
  209. "CommunicationModeResponsePDU", // 91
  210. "CommunicationModeCommandPDU", // 92
  211. "SendTerminalCapabilitySetPDU", // 93
  212. "EncryptionCommandPDU", // 94
  213. "FlowControlCommandPDU", // 95
  214. "EndSessionCommandPDU", // 96
  215. "FunctionNotSupportedIndicationPDU",// 97
  216. "JitterIndicationPDU", // 98
  217. "H223SkewIndicationPDU", // 99
  218. "NewATMVCIndicationPDU", // 100
  219. "UserInputIndicationPDU", // 101
  220. "H2250MaximumSkewIndicationPDU", // 102
  221. "MCLocationIndicationPDU", // 103
  222. };
  223. // Output function definitions
  224. char * OutputName[NUM_OUTPUTS] =
  225. {
  226. // Out-going Open Uni-directional Logical Channel (LCSE_OUT) state functions
  227. "EstablishReleased", // 0
  228. "OpenAckAwaitingE", // 1
  229. "OpenRejAwaitingE", // 2
  230. "ReleaseAwaitingE", // 3
  231. "T103AwaitingE", // 4
  232. "ReleaseEstablished", // 5
  233. "OpenRejEstablished", // 6
  234. "CloseAckEstablished", // 7
  235. "CloseAckAwaitingR", // 8
  236. "OpenRejAwaitingR", // 9
  237. "T103AwaitingR", // 10
  238. "EstablishAwaitingR", // 11
  239. // In-coming Open Uni-directional Logical Channel (LCSE_IN) state functions
  240. "OpenReleased", // 12
  241. "CloseReleased", // 13
  242. "ResponseAwaiting", // 14
  243. "ReleaseAwaiting", // 15
  244. "CloseAwaiting", // 16
  245. "OpenAwaiting", // 17
  246. "CloseEstablished", // 18
  247. "OpenEstablished", // 19
  248. // Out-going Open Bi-directional Logical Channel (BLCSE_OUT) state functions
  249. "EstablishReqBReleased", // 20
  250. "OpenChannelAckBAwaitingE", // 21
  251. "OpenChannelRejBAwaitingE", // 22
  252. "ReleaseReqBOutAwaitingE", // 23
  253. "T103ExpiryBAwaitingE", // 24
  254. "ReleaseReqBEstablished", // 25
  255. "OpenChannelRejBEstablished", // 26
  256. "CloseChannelAckBEstablished", // 27
  257. "CloseChannelAckAwaitingR", // 28
  258. "OpenChannelRejBAwaitingR", // 29
  259. "T103ExpiryBAwaitingR", // 30
  260. "EstablishReqAwaitingR", // 31
  261. // In-coming Open Bi-directional Logical Channel (BLCSE_IN) state functions
  262. "OpenChannelBReleased", // 32
  263. "CloseChannelBReleased", // 33
  264. "EstablishResBAwaitingE", // 34
  265. "ReleaseReqBInAwaitingE", // 35
  266. "CloseChannelBAwaitingE", // 36
  267. "OpenChannelBAwaitingE", // 37
  268. "OpenChannelConfirmBAwaitingE", // 38
  269. "T103ExpiryBAwaitingC", // 39
  270. "OpenChannelConfirmBAwaitingC", // 40
  271. "CloseChannelBAwaitingC", // 41
  272. "OpenChannelBAwaitingC", // 42
  273. "CloseChannelBEstablished", // 43
  274. "OpenChannelBEstablished", // 44
  275. // Out-going Request Close Logical Channel (CLCSE_OUT) state functions
  276. "CloseRequestIdle", // 45
  277. "RequestCloseAckAwaitingR", // 46
  278. "RequestCloseRejAwaitingR", // 47
  279. "T108ExpiryAwaitingR", // 48
  280. // In-coming Request Close Logical Channel (CLCSE_IN) state functions
  281. "RequestCloseIdle", // 49
  282. "CloseResponseAwaitingR", // 50
  283. "RejectRequestAwaitingR", // 51
  284. "RequestCloseReleaseAwaitingR", // 52
  285. "RequestCloseAwaitingR", // 53
  286. // Out-going Terminal Capability Exchange (CESE_OUT) state functions
  287. "RequestCapIdle", // 54
  288. "TermCapAckAwaiting", // 55
  289. "TermCapRejAwaiting", // 56
  290. "T101ExpiryAwaiting", // 57
  291. // In-coming Terminal Capability Exchange (CESE_IN) state functions
  292. "TermCapSetIdle", // 58
  293. "ResponseCapAwaiting", // 59
  294. "RejectCapAwaiting", // 60
  295. "TermCapReleaseAwaiting", // 61
  296. "TermCapSetAwaiting", // 62
  297. // Out-going Multiplex Table (MTSE_OUT) state functions
  298. "MTSE0_TRANSFER_request", // 63
  299. "MTSE1_TRANSFER_request", // 64
  300. "MTSE1_MultiplexEntrySendAck", // 65
  301. "MTSE1_MultiplexEntrySendRej", // 66
  302. "MTSE1_T104Expiry", // 67
  303. // In-coming Multiplex Table (MTSE_IN) state functions
  304. "MTSE0_MultiplexEntrySend", // 68
  305. "MTSE1_MultiplexEntrySend", // 69
  306. "MTSE1_MultiplexEntrySendRelease",// 70
  307. "MTSE1_TRANSFER_response", // 71
  308. "MTSE1_REJECT_request", // 72
  309. // Out-going Request Multiplex Entry (RMESE_OUT) state functions
  310. "RMESE0_SEND_request", // 73
  311. "RMESE1_SEND_request", // 74
  312. "RMESE1_RequestMuxEntryAck", // 75
  313. "RMESE1_RequestMuxEntryRej", // 76
  314. "RMESE1_T107Expiry", // 77
  315. // In-coming Request Multiplex Entry (RMESE_IN) state functions
  316. "RMESE0_RequestMuxEntry", // 78
  317. "RMESE1_RequestMuxEntry", // 79
  318. "RMESE1_RequestMuxEntryRelease", // 80
  319. "RMESE1_SEND_response", // 81
  320. "RMESE1_REJECT_request", // 82
  321. // Out-going Request Mode (MRSE_OUT) state functions
  322. "MRSE0_TRANSFER_request", // 83
  323. "MRSE1_TRANSFER_request", // 84
  324. "MRSE1_RequestModeAck", // 85
  325. "MRSE1_RequestModeRej", // 86
  326. "MRSE1_T109Expiry", // 87
  327. // In-coming Request Mode (MRSE_IN) state functions
  328. "MRSE0_RequestMode", // 88
  329. "MRSE1_RequestMode", // 89
  330. "MRSE1_RequestModeRelease", // 90
  331. "MRSE1_TRANSFER_response", // 91
  332. "MRSE1_REJECT_request", // 92
  333. // Out-going Request Mode (MLSE_OUT) state functions
  334. "MLSE0_LOOP_request", // 93
  335. "MLSE1_MaintenanceLoopAck", // 94
  336. "MLSE1_MaintenanceLoopRej", // 95
  337. "MLSE1_OUT_RELEASE_request", // 96
  338. "MLSE1_T102Expiry", // 97
  339. "MLSE2_MaintenanceLoopRej", // 98
  340. "MLSE2_OUT_RELEASE_request", // 99
  341. // In-coming Request Mode (MLSE_IN) state functions
  342. "MLSE0_MaintenanceLoopRequest", // 100
  343. "MLSE1_MaintenanceLoopRequest", // 101
  344. "MLSE1_MaintenanceLoopOffCommand",// 102
  345. "MLSE1_LOOP_response", // 103
  346. "MLSE1_IN_RELEASE_request", // 104
  347. "MLSE2_MaintenanceLoopRequest", // 105
  348. "MLSE2_MaintenanceLoopOffCommand",// 106
  349. // Master Slave Determination (MSDSE) state functions
  350. "DetRequestIdle", // 107
  351. "MSDetIdle", // 108
  352. "MSDetAckOutgoing", // 109
  353. "MSDetOutgoing", // 110
  354. "MSDetRejOutgoing", // 111
  355. "MSDetReleaseOutgoing", // 112
  356. "T106ExpiryOutgoing", // 113
  357. "MSDetAckIncoming", // 114
  358. "MSDetIncoming", // 115
  359. "MSDetRejIncoming", // 116
  360. "MSDetReleaseIncoming", // 117
  361. "T106ExpiryIncoming", // 118
  362. // Round Trip Delay (RTDSE) state functions
  363. "RTDSE0_TRANSFER_request", // 119
  364. "RTDSE0_RoundTripDelayRequest", // 120
  365. "RTDSE1_TRANSFER_request", // 121
  366. "RTDSE1_RoundTripDelayRequest", // 122
  367. "RTDSE1_RoundTripDelayResponse", // 123
  368. "RTDSE1_T105Expiry", // 124
  369. };
  370. #endif // (_DEBUG)
  371. typedef HRESULT (*STATE_FUNCTION)(Object_t *pObject, PDU_t *pPdu);
  372. // Output function defintions
  373. static STATE_FUNCTION StateFun[] =
  374. {
  375. // Out-going Open Uni-directional Logical Channel (LCSE_OUT) state functions
  376. establishReleased, // 0
  377. openAckAwaitingE, // 1
  378. openRejAwaitingE, // 2
  379. releaseAwaitingE, // 3
  380. t103AwaitingE, // 4
  381. releaseEstablished, // 5
  382. openRejEstablished, // 6
  383. closeAckEstablished, // 7
  384. closeAckAwaitingR, // 8
  385. openRejAwaitingR, // 9
  386. t103AwaitingR, // 10
  387. establishAwaitingR, // 11
  388. // In-coming Open Uni-directional Logical Channel (LCSE_IN) state functions
  389. openReleased, // 12
  390. closeReleased, // 13
  391. responseAwaiting, // 14
  392. releaseAwaiting, // 15
  393. closeAwaiting, // 16
  394. openAwaiting, // 17
  395. closeEstablished, // 18
  396. openEstablished, // 19
  397. // Out-going Open Bi-directional Logical Channel (BLCSE_OUT) state functions
  398. establishReqBReleased, // 20
  399. openChannelAckBAwaitingE, // 21
  400. openChannelRejBAwaitingE, // 22
  401. releaseReqBOutAwaitingE, // 23
  402. t103ExpiryBAwaitingE, // 24
  403. releaseReqBEstablished, // 25
  404. openChannelRejBEstablished, // 26
  405. closeChannelAckBEstablished, // 27
  406. closeChannelAckAwaitingR, // 28
  407. openChannelRejBAwaitingR, // 29
  408. t103ExpiryBAwaitingR, // 30
  409. establishReqAwaitingR, // 31
  410. // In-coming Open Bi-directional Logical Channel (BLCSE_IN) state functions
  411. openChannelBReleased, // 32
  412. closeChannelBReleased, // 33
  413. establishResBAwaitingE, // 34
  414. releaseReqBInAwaitingE, // 35
  415. closeChannelBAwaitingE, // 36
  416. openChannelBAwaitingE, // 37
  417. openChannelConfirmBAwaitingE, // 38
  418. t103ExpiryBAwaitingC, // 39
  419. openChannelConfirmBAwaitingC, // 40
  420. closeChannelBAwaitingC, // 41
  421. openChannelBAwaitingC, // 42
  422. closeChannelBEstablished, // 43
  423. openChannelBEstablished, // 44
  424. // Out-going Request Close Logical Channel (CLCSE_OUT) state functions
  425. closeRequestIdle, // 45
  426. requestCloseAckAwaitingR, // 46
  427. requestCloseRejAwaitingR, // 47
  428. t108ExpiryAwaitingR, // 48
  429. // In-coming Request Close Logical Channel (CLCSE_IN) state functions
  430. requestCloseIdle, // 49
  431. closeResponseAwaitingR, // 50
  432. rejectRequestAwaitingR, // 51
  433. requestCloseReleaseAwaitingR, // 52
  434. requestCloseAwaitingR, // 53
  435. // Out-going Terminal Capability Exchange (CESE_OUT) state functions
  436. requestCapIdle, // 54
  437. termCapAckAwaiting, // 55
  438. termCapRejAwaiting, // 56
  439. t101ExpiryAwaiting, // 57
  440. // In-coming Terminal Capability Exchange (CESE_IN) state functions
  441. termCapSetIdle, // 58
  442. responseCapAwaiting, // 59
  443. rejectCapAwaiting, // 60
  444. termCapReleaseAwaiting, // 61
  445. termCapSetAwaiting, // 62
  446. // Out-going Multiplex Table (MTSE_OUT) state functions
  447. MTSE0_TRANSFER_requestF, // 63
  448. MTSE1_TRANSFER_requestF, // 64
  449. MTSE1_MultiplexEntrySendAckF, // 65
  450. MTSE1_MultiplexEntrySendRejF, // 66
  451. MTSE1_T104ExpiryF, // 67
  452. // In-coming Multiplex Table (MTSE_IN) state functions
  453. MTSE0_MultiplexEntrySendF, // 68
  454. MTSE1_MultiplexEntrySendF, // 69
  455. MTSE1_MultiplexEntrySendReleaseF,// 70
  456. MTSE1_TRANSFER_responseF, // 71
  457. MTSE1_REJECT_requestF, // 72
  458. // Out-going Request Multiplex Entry (RMESE_OUT) state functions
  459. RMESE0_SEND_requestF, // 73
  460. RMESE1_SEND_requestF, // 74
  461. RMESE1_RequestMuxEntryAckF, // 75
  462. RMESE1_RequestMuxEntryRejF, // 76
  463. RMESE1_T107ExpiryF, // 77
  464. // In-coming Request Multiplex Entry (RMESE_IN) state functions
  465. RMESE0_RequestMuxEntryF, // 78
  466. RMESE1_RequestMuxEntryF, // 79
  467. RMESE1_RequestMuxEntryReleaseF, // 80
  468. RMESE1_SEND_responseF, // 81
  469. RMESE1_REJECT_requestF, // 82
  470. // Out-going Request Mode (MRSE_OUT) state functions
  471. MRSE0_TRANSFER_requestF, // 83
  472. MRSE1_TRANSFER_requestF, // 84
  473. MRSE1_RequestModeAckF, // 85
  474. MRSE1_RequestModeRejF, // 86
  475. MRSE1_T109ExpiryF, // 87
  476. // In-coming Request Mode (MRSE_OUT) state functions
  477. MRSE0_RequestModeF, // 88
  478. MRSE1_RequestModeF, // 89
  479. MRSE1_RequestModeReleaseF, // 90
  480. MRSE1_TRANSFER_responseF, // 91
  481. MRSE1_REJECT_requestF, // 92
  482. // Out-going Request Mode (MLSE_OUT) state functions
  483. MLSE0_LOOP_requestF, // 93
  484. MLSE1_MaintenanceLoopAckF, // 94
  485. MLSE1_MaintenanceLoopRejF, // 95
  486. MLSE1_OUT_RELEASE_requestF, // 96
  487. MLSE1_T102ExpiryF, // 97
  488. MLSE2_MaintenanceLoopRejF, // 98
  489. MLSE2_OUT_RELEASE_requestF, // 99
  490. // In-coming Request Mode (MLSE_IN) state functions
  491. MLSE0_MaintenanceLoopRequestF, // 100
  492. MLSE1_MaintenanceLoopRequestF, // 101
  493. MLSE1_MaintenanceLoopOffCommandF,// 102
  494. MLSE1_LOOP_responseF, // 103
  495. MLSE1_IN_RELEASE_requestF, // 104
  496. MLSE2_MaintenanceLoopRequestF, // 105
  497. MLSE2_MaintenanceLoopOffCommandF,// 106
  498. // Master Slave Determination (MSDSE) state functions
  499. detRequestIdle, // 107
  500. msDetIdle, // 108
  501. msDetAckOutgoing, // 109
  502. msDetOutgoing, // 110
  503. msDetRejOutgoing, // 111
  504. msDetReleaseOutgoing, // 112
  505. t106ExpiryOutgoing, // 113
  506. msDetAckIncoming, // 114
  507. msDetIncoming, // 115
  508. msDetRejIncoming, // 116
  509. msDetReleaseIncoming, // 117
  510. t106ExpiryIncoming, // 118
  511. // Round Trip Delay (RTDSE) state functions
  512. RTDSE0_TRANSFER_requestF, // 119
  513. RTDSE0_RoundTripDelayRequestF, // 120
  514. RTDSE1_TRANSFER_requestF, // 121
  515. RTDSE1_RoundTripDelayRequestF, // 122
  516. RTDSE1_RoundTripDelayResponseF, // 123
  517. RTDSE1_T105ExpiryF, // 124
  518. };
  519. /*********************************************
  520. *
  521. * State table for the finite state machine
  522. *
  523. *********************************************/
  524. Output_t StateTable[NUM_STATE_EVENTS][MAXSTATES] =
  525. {
  526. // Out-going Uni-directional Logical Channel (LCSE_OUT) events
  527. {EstablishReleased,IGNORE, IGNORE, EstablishAwaitingR}, // ReqUEstablish
  528. {IGNORE, OpenAckAwaitingE, IGNORE, IGNORE }, // OpenUChAckPDU
  529. {IGNORE, OpenRejAwaitingE, OpenRejEstablished, OpenRejAwaitingR }, // OpenUChRejectPDU
  530. {IGNORE, IGNORE, CloseAckEstablished,CloseAckAwaitingR }, // CloseUChAckPDU
  531. {IGNORE, ReleaseAwaitingE, ReleaseEstablished, IGNORE }, // ReqURelease
  532. {BAD, T103AwaitingE, BAD, T103AwaitingR }, // T103Expiry
  533. // In-coming Uni-directional Logical Channel (LCSE_IN) events
  534. {OpenReleased, OpenAwaiting, OpenEstablished, BAD }, // OpenUChPDU
  535. {CloseReleased, CloseAwaiting, CloseEstablished, BAD }, // CloseUChPDU
  536. {IGNORE, ResponseAwaiting, IGNORE, BAD }, // ResponseUEstablish
  537. {IGNORE, ReleaseAwaiting, IGNORE, BAD }, // EstablishUReject
  538. // Out-going Bi-directional Logical Channel (BLCSE_OUT) events
  539. {EstablishReqBReleased,IGNORE, IGNORE, EstablishReqAwaitingR },// ReqBEstablish
  540. {IGNORE, OpenChannelAckBAwaitingE, IGNORE, IGNORE },// OpenBChAckPDU
  541. {IGNORE, OpenChannelRejBAwaitingE, OpenChannelRejBEstablished, OpenChannelRejBAwaitingR},// OpenBChRejectPDU
  542. {IGNORE, IGNORE, CloseChannelAckBEstablished, CloseChannelAckAwaitingR},// CloseBChAckPDU
  543. {IGNORE, ReleaseReqBOutAwaitingE, ReleaseReqBEstablished, IGNORE },// ReqClsBLCSE
  544. {IGNORE, IGNORE, IGNORE, IGNORE },// RspConfirmBLCSE
  545. {BAD, T103ExpiryBAwaitingE, BAD, T103ExpiryBAwaitingR },// T103OutExpiry
  546. // In-coming Bi-directional Logical Channel (BLCSE_IN) events
  547. {OpenChannelBReleased, OpenChannelBAwaitingE, OpenChannelBAwaitingC, OpenChannelBEstablished },// OpenBChPDU
  548. {CloseChannelBReleased,CloseChannelBAwaitingE, CloseChannelBAwaitingC, CloseChannelBEstablished},// CloseBChPDU
  549. {IGNORE, EstablishResBAwaitingE, IGNORE, IGNORE },// ResponseBEstablish
  550. {IGNORE, OpenChannelConfirmBAwaitingE,OpenChannelConfirmBAwaitingC,IGNORE },// OpenBChConfirmPDU
  551. {IGNORE, ReleaseReqBInAwaitingE, IGNORE, IGNORE },// OpenRejectBLCSE
  552. {BAD, BAD, T103ExpiryBAwaitingC, BAD },// T103InExpiry
  553. // Out-going Request Close Logical Channel (CLCSE_OUT) events
  554. {CloseRequestIdle, IGNORE, BAD,BAD}, // ReqClose
  555. {IGNORE, RequestCloseAckAwaitingR, BAD,BAD}, // ReqChCloseAckPDU
  556. {IGNORE, RequestCloseRejAwaitingR, BAD,BAD}, // ReqChCloseRejectPDU
  557. {BAD, T108ExpiryAwaitingR, BAD,BAD}, // T108Expiry
  558. // In-coming Request Close Logical Channel (CLCSE_IN) events
  559. {RequestCloseIdle, RequestCloseAwaitingR, BAD,BAD}, // ReqChClosePDU
  560. {IGNORE, RequestCloseReleaseAwaitingR, BAD,BAD}, // ReqChCloseReleasePDU
  561. {IGNORE, CloseResponseAwaitingR, BAD,BAD}, // CLCSE_CLOSE_response
  562. {IGNORE, RejectRequestAwaitingR, BAD,BAD}, // CLCSE_REJECT_request
  563. // Out-going Terminal Capablity Exchange (CESE_OUT) events
  564. {RequestCapIdle, IGNORE, BAD,BAD}, // TransferCapRequest
  565. {IGNORE, TermCapAckAwaiting, BAD,BAD}, // TermCapSetAckPDU
  566. {IGNORE, TermCapRejAwaiting, BAD,BAD}, // TermCapSetRejectPDU
  567. {BAD, T101ExpiryAwaiting, BAD,BAD}, // T101Expiry
  568. // In-coming Terminal Capablity Exchange (CESE_IN) events
  569. {TermCapSetIdle, TermCapSetAwaiting, BAD,BAD}, // TermCapSetPDU
  570. {IGNORE, TermCapReleaseAwaiting, BAD,BAD}, // TermCapSetRelPDU
  571. {IGNORE, ResponseCapAwaiting, BAD,BAD}, // CESE_TRANSFER_response
  572. {IGNORE, RejectCapAwaiting, BAD,BAD}, // CESE_REJECT_request
  573. // Out-going Multiplex Table (MTSE_OUT) events
  574. {MTSE0_TRANSFER_request, MTSE1_TRANSFER_request, BAD,BAD}, // TRANSFER_request
  575. {IGNORE, MTSE1_MultiplexEntrySendAck, BAD,BAD}, // MultiplexEntrySendAck
  576. {IGNORE, MTSE1_MultiplexEntrySendRej, BAD,BAD}, // MultiplexEntrySendReject
  577. {BAD, MTSE1_T104Expiry, BAD,BAD}, // T104Expiry
  578. // In-coming Multiplex Table (MTSE_IN) events
  579. {MTSE0_MultiplexEntrySend, MTSE1_MultiplexEntrySend, BAD,BAD}, // MultiplexEntrySend
  580. {IGNORE, MTSE1_MultiplexEntrySendRelease,BAD,BAD}, // MultiplexEntrySendRelease
  581. {IGNORE, MTSE1_TRANSFER_response, BAD,BAD}, // MTSE_TRANSFER_response
  582. {IGNORE, MTSE1_REJECT_request, BAD,BAD}, // MTSE_REJECT_request
  583. // Out-going Request Multiplex Entry (RMESE_OUT) events
  584. {RMESE0_SEND_request, RMESE1_SEND_request, BAD,BAD}, // RMESE_SEND_request
  585. {IGNORE, RMESE1_RequestMuxEntryAck, BAD,BAD}, // RequestMultiplexEntryAck
  586. {IGNORE, RMESE1_RequestMuxEntryRej, BAD,BAD}, // RequestMultiplexEntryReject
  587. {BAD, RMESE1_T107Expiry, BAD,BAD}, // T107Expiry
  588. // In-coming Request Multiplex Entry (RMESE_IN) events
  589. {RMESE0_RequestMuxEntry, RMESE1_RequestMuxEntry, BAD,BAD}, // RequestMultiplexEntry
  590. {IGNORE, RMESE1_RequestMuxEntryRelease, BAD,BAD}, // RequestMultiplexEntryRelease
  591. {BAD, RMESE1_SEND_response, BAD,BAD}, // RMESE_SEND_response
  592. {BAD, RMESE1_REJECT_request, BAD,BAD}, // RMESE_REJECT_request
  593. // Out-going Mode Request (MRSE_OUT) events
  594. {MRSE0_TRANSFER_request, MRSE1_TRANSFER_request, BAD,BAD}, // MRSE_TRANSFER_request
  595. {IGNORE, MRSE1_RequestModeAck, BAD,BAD}, // RequestModeAck
  596. {IGNORE, MRSE1_RequestModeRej, BAD,BAD}, // RequestModeReject
  597. {BAD, MRSE1_T109Expiry, BAD,BAD}, // T109Expiry
  598. // In-coming Mode Request (MRSE_IN) events
  599. {MRSE0_RequestMode, MRSE1_RequestMode, BAD,BAD}, // RequestMode
  600. {IGNORE, MRSE1_RequestModeRelease, BAD,BAD}, // RequestModeRelease
  601. {BAD, MRSE1_TRANSFER_response, BAD,BAD}, // MRSE_TRANSFER_response
  602. {BAD, MRSE1_REJECT_request, BAD,BAD}, // MRSE_REJECT_request
  603. // Out-going Maintenance Loop (MLSE_OUT) events
  604. {MLSE0_LOOP_request, BAD, BAD, BAD}, // MLSE_LOOP_request
  605. {BAD, MLSE1_OUT_RELEASE_request, MLSE2_OUT_RELEASE_request, BAD}, // MLSE_OUT_RELEASE_request
  606. {IGNORE, MLSE1_MaintenanceLoopAck, IGNORE, BAD}, // MaintenanceLoopAck
  607. {IGNORE, MLSE1_MaintenanceLoopRej, MLSE2_MaintenanceLoopRej, BAD}, // MaintenanceLoopReject
  608. {BAD, MLSE1_T102Expiry, BAD, BAD}, // T102Expiry
  609. // In-coming Maintenance Loop (MLSE_IN) events
  610. {MLSE0_MaintenanceLoopRequest, MLSE1_MaintenanceLoopRequest, MLSE2_MaintenanceLoopRequest, BAD}, // MaintenanceLoopRequest
  611. {IGNORE, MLSE1_MaintenanceLoopOffCommand,MLSE2_MaintenanceLoopOffCommand,BAD}, // MaintenanceLoopOffCommand
  612. {BAD, MLSE1_LOOP_response, BAD, BAD}, // MLSE_LOOP_response
  613. {BAD, MLSE1_IN_RELEASE_request, BAD, BAD}, // MLSE_IN_RELEASE_request
  614. // Master Slave Determination (MSDSE) events
  615. {DetRequestIdle, IGNORE, IGNORE, BAD}, // MSDetReq
  616. {MSDetIdle, MSDetOutgoing, MSDetIncoming, BAD}, // MSDetPDU
  617. {IGNORE, MSDetAckOutgoing, MSDetAckIncoming, BAD}, // MSDetAckPDU
  618. {IGNORE, MSDetRejOutgoing, MSDetRejIncoming, BAD}, // MSDetRejectPDU
  619. {IGNORE, MSDetReleaseOutgoing, MSDetReleaseIncoming,BAD}, // MSDetReleasePDU
  620. {BAD, T106ExpiryOutgoing, T106ExpiryIncoming, BAD}, // T106Expiry
  621. // Round Trip Delay Delay (RTDSE) events
  622. {RTDSE0_TRANSFER_request, RTDSE1_TRANSFER_request, BAD,BAD}, // RTDSE_TRANSFER_request
  623. {RTDSE0_RoundTripDelayRequest, RTDSE0_RoundTripDelayRequest, BAD,BAD}, // RoundTripDelayRequest
  624. {IGNORE, RTDSE1_RoundTripDelayResponse, BAD,BAD}, // RoundTripDelayResponse
  625. {BAD, RTDSE1_T105Expiry, BAD,BAD}, // T105Expiry
  626. };
  627. /*
  628. * NAME
  629. * StateMachine() - engine for finite state machine
  630. *
  631. *
  632. * PARAMETERS
  633. * INPUT pObject pointer to an FSM object structure
  634. * INTPUT event input to the finite state machine
  635. *
  636. * RETURN VALUE
  637. * error codes defined in h245api.h
  638. */
  639. HRESULT
  640. StateMachine(Object_t *pObject, PDU_t *pPdu, Event_t Event)
  641. {
  642. UINT uFunction;
  643. HRESULT lError;
  644. ASSERT(pObject != NULL);
  645. if (Event > NUM_EVENTS)
  646. {
  647. H245TRACE(pObject->dwInst, 1, "StateMachine: Invalid Event %d", Event);
  648. return H245_ERROR_PARAM;
  649. }
  650. if (pObject->State > MAXSTATES)
  651. {
  652. H245TRACE(pObject->dwInst, 1, "StateMachine: Invalid State %d", pObject->State);
  653. return H245_ERROR_INVALID_STATE;
  654. }
  655. ++(pObject->uNestLevel);
  656. #if defined(_DEBUG)
  657. H245TRACE(pObject->dwInst, 2, "StateMachine: Entity=%s(%d) State=%d Event=%s(%d)",
  658. EntityName[pObject->Entity], pObject->Entity,
  659. pObject->State,
  660. EventName[Event], Event);
  661. #else
  662. H245TRACE(pObject->dwInst, 2, "StateMachine: Entity=%d State=%d Event=%d",
  663. pObject->Entity, pObject->State, Event);
  664. #endif
  665. uFunction = StateTable[Event][pObject->State];
  666. if (uFunction < (sizeof (StateFun) / sizeof(StateFun[0])))
  667. {
  668. /* indicating a valid transition */
  669. #if defined(_DEBUG)
  670. H245TRACE(pObject->dwInst, 2, "StateMachine: Function=%s(%d)",
  671. OutputName[uFunction], uFunction);
  672. #else // (_DEBUG)
  673. H245TRACE(pObject->dwInst, 2, "StateMachine: Function=%d", uFunction);
  674. #endif // (_DEBUG)
  675. lError = (*StateFun[uFunction])(pObject, pPdu);
  676. #if defined(_DEBUG)
  677. H245TRACE(pObject->dwInst, 2, "StateMachine: Entity=%s(%d) New State=%d",
  678. EntityName[pObject->Entity], pObject->Entity, pObject->State);
  679. #else
  680. H245TRACE(pObject->dwInst, 2, "StateMachine: Entity=%d New State=%d",
  681. pObject->Entity, pObject->State);
  682. #endif
  683. }
  684. else if (uFunction == IGNORE)
  685. {
  686. H245TRACE(pObject->dwInst, 2, "StateMachine: Event ignored");
  687. #if defined(_DEBUG)
  688. H245TRACE(pObject->dwInst, 2, "StateMachine: Event Ignored; Entity=%s(%d) State=%d Event=%s(%d)",
  689. EntityName[pObject->Entity], pObject->Entity,
  690. pObject->State,
  691. EventName[Event], Event);
  692. #else
  693. H245TRACE(pObject->dwInst, 2, "StateMachine: Entity=%d State=%d Event=%d",
  694. pObject->Entity, pObject->State, Event);
  695. #endif
  696. lError = H245_ERROR_OK;
  697. }
  698. else
  699. {
  700. #if defined(_DEBUG)
  701. H245TRACE(pObject->dwInst, 2, "StateMachine: Event Invalid; Entity=%s(%d) State=%d Event=%s(%d)",
  702. EntityName[pObject->Entity], pObject->Entity,
  703. pObject->State,
  704. EventName[Event], Event);
  705. #else
  706. H245TRACE(pObject->dwInst, 2, "StateMachine: Event Invalid; Entity=%d State=%d Event=%d",
  707. pObject->Entity, pObject->State, Event);
  708. #endif
  709. lError = H245_ERROR_INVALID_STATE;
  710. }
  711. if (--(pObject->uNestLevel) == 0 && pObject->State == 0)
  712. {
  713. ObjectDestroy(pObject);
  714. }
  715. return lError;
  716. } // StateMachine()