1/*
2 * FSM pseudo code used in the design/implementation of the CC Q.SIG monitor.
3 */
4FSM CC_QSIG_Monitor
5{
6	State CC_STATE_IDLE {
7		Init {
8		}
9		Prolog {
10			Action Set_Selfdestruct;
11		}
12		Stimulus CC_EVENT_AVAILABLE {
13			/*
14			 * LibPRI will determine if CC will be offered based upon
15			 * if it is even possible.
16			 * Essentially:
17			 * 1) The call must not have been redirected in this link's
18			 * setup.
19			 * 2) Received an ALERTING or received a
20			 * DISCONNECT(busy/congestion).
21			 */
22			Action Pass_Up_CC_Available;
23			Next_State CC_STATE_AVAILABLE;
24		}
25		Stimulus CC_EVENT_CANCEL {
26			Action Set_Selfdestruct;
27		}
28	}
29	State CC_STATE_AVAILABLE {
30		/*
31		 * The upper layer is responsible for canceling the CC available
32		 * offering.
33		 */
34		Stimulus CC_EVENT_CC_REQUEST {
35			/*
36			 * Before event is posted:
37			 *   cc_record->is_ccnr is set.
38			 *   The signaling connection call record is created.
39			 */
40			Action Queue_CC_Request;
41			/* Start QSIG_CC_T1. */
42			Action Start_T_ACTIVATE;
43			Next_State CC_STATE_REQUESTED;
44		}
45		Stimulus CC_EVENT_CANCEL {
46			Next_State CC_STATE_IDLE;
47		}
48	}
49	State CC_STATE_REQUESTED {
50		Stimulus CC_EVENT_CC_REQUEST_ACCEPT {
51			/*
52			 * Received ccbsRequest/ccnrRequest response
53			 * Before event is posted:
54			 *   Negotiated CC retention setting saved
55			 *   Negotiated signaling link retention setting saved
56			 */
57			Action Stop_T_ACTIVATE;
58			Test = Get_msgtype;
59			Test == Q931_RELEASE {
60				Action Disassociate_Signaling_Link;
61				Test = Get_Retain_Signaling_Link;
62				Test == TRUE {
63					/*
64					 * The far end did not honor the
65					 * signaling link retention requirement.
66					 * ECMA-186 Section 6.5.2.2.1
67					 */
68					Action Pass_Up_CC_Req_Rsp_Timeout;
69					Action Pass_Up_CC_Cancel;
70					Action Send_CC_Cancel;
71					Next_State CC_STATE_IDLE;
72				}
73			}
74			Action Pass_Up_CC_Req_Rsp_Success;
75			Next_State CC_STATE_ACTIVATED;
76		}
77		Stimulus CC_EVENT_CC_REQUEST_FAIL {
78			Action Stop_T_ACTIVATE;
79			Action Pass_Up_CC_Req_Rsp_Fail(error/reject, code);
80			Action Pass_Up_CC_Cancel;
81			/*
82			 * If this request fail comes in with the RELEASE message
83			 * then the post action will never get a chance to run.
84			 * It will be aborted because the CC_EVENT_SIGNALING_GONE
85			 * will be processed first.
86			 */
87			Action Post_HANGUP_SIGNALING;
88			Next_State CC_STATE_WAIT_DESTRUCTION;
89		}
90		Stimulus CC_EVENT_TIMEOUT_T_ACTIVATE {
91			Action Stop_T_ACTIVATE;
92			Action Pass_Up_CC_Req_Rsp_Timeout;
93			Action Pass_Up_CC_Cancel;
94			Action Hangup_Signaling_Link;
95			Next_State CC_STATE_IDLE;
96		}
97		Stimulus CC_EVENT_SIGNALING_GONE {
98			Action Stop_T_ACTIVATE;
99			/* Claim it was a timeout */
100			Action Pass_Up_CC_Req_Rsp_Timeout;
101			Action Pass_Up_CC_Cancel;
102			Next_State CC_STATE_IDLE;
103		}
104		Stimulus CC_EVENT_CANCEL {
105			Next_State CC_STATE_WAIT_DESTRUCTION;
106		}
107	}
108	State CC_STATE_WAIT_DESTRUCTION {
109		/*
110		 * Delayed disconnect of the signaling link to allow subcmd events
111		 * from the signaling link to be passed up.
112		 */
113		Stimulus CC_EVENT_CC_REQUEST_ACCEPT {
114			/*
115			 * Received ccbsRequest/ccnrRequest response
116			 * Before event is posted:
117			 *   Negotiated CC retention setting saved
118			 *   Negotiated signaling link retention setting saved
119			 */
120			Action Stop_T_ACTIVATE;
121			Test = Get_msgtype;
122			Test == Q931_RELEASE {
123				Action Disassociate_Signaling_Link;
124			}
125			Action Send_CC_Cancel;
126			Next_State CC_STATE_IDLE;
127		}
128		Stimulus CC_EVENT_CC_REQUEST_FAIL {
129			Action Stop_T_ACTIVATE;
130			/*
131			 * If this request fail comes in with the RELEASE message
132			 * then the post action will never get a chance to run.
133			 * It will be aborted because the CC_EVENT_SIGNALING_GONE
134			 * will be processed first.
135			 */
136			Action Post_HANGUP_SIGNALING;
137		}
138		Stimulus CC_EVENT_TIMEOUT_T_ACTIVATE {
139			Action Stop_T_ACTIVATE;
140			Action Hangup_Signaling_Link;
141			Next_State CC_STATE_IDLE;
142		}
143		Stimulus CC_EVENT_SIGNALING_GONE {
144			/* Signaling link cleared. */
145			Action Stop_T_ACTIVATE;
146			Next_State CC_STATE_IDLE;
147		}
148		Stimulus CC_EVENT_HANGUP_SIGNALING {
149			//Action Stop_T_ACTIVATE;
150			Action Hangup_Signaling_Link;
151			Next_State CC_STATE_IDLE;
152		}
153	}
154	State CC_STATE_ACTIVATED {
155		Prolog {
156			Action Reset_A_Status;
157		}
158		Stimulus CC_EVENT_REMOTE_USER_FREE {
159			/* Received ccExecPossible */
160			Action Pass_Up_Remote_User_Free;
161			/*
162			 * ECMA-186 Section 6.5.2.1.7
163			 * Implied switch to retain-signaling-link.
164			 */
165			Action Set_Retain_Signaling_Link;
166			Test = Get_msgtype;
167			Test == Q931_SETUP {
168				/* Send Q931_CALL_PROCEEDING message on signaling link. */
169				Action Send_Call_Proceeding;
170			}
171			Test = Get_A_Status;
172			Test == Busy {
173				Next_State CC_STATE_SUSPENDED;
174			}
175			Next_State CC_STATE_WAIT_CALLBACK;
176		}
177		Stimulus CC_EVENT_SUSPEND {
178			Action Set_A_Status_Busy;
179		}
180		Stimulus CC_EVENT_RESUME {
181			Action Reset_A_Status;
182		}
183	}
184	State CC_STATE_WAIT_CALLBACK {
185		Prolog {
186			/* Start QSIG_CC_T3 */
187			Action Start_T_RECALL;
188		}
189		Epilog {
190			Action Stop_T_RECALL;
191		}
192		Stimulus CC_EVENT_RECALL {
193			/* The original call parameters have already been set. */
194			Action Queue_SETUP_Recall;
195			Next_State CC_STATE_CALLBACK;
196		}
197		Stimulus CC_EVENT_SUSPEND {
198			Next_State CC_STATE_SUSPENDED;
199		}
200		Stimulus CC_EVENT_TIMEOUT_T_RECALL {
201			Action Pass_Up_CC_Cancel;
202			Action Send_CC_Cancel;
203			Next_State CC_STATE_IDLE;
204		}
205	}
206	State CC_STATE_CALLBACK {
207	}
208	State CC_STATE_SUSPENDED {
209		Prolog {
210			/*
211			 * The ccSuspend will be sent in a FACILITY or CONNECT
212			 * message depending upon the CIS call state.
213			 */
214			Action Send_CC_Suspend;
215		}
216		Stimulus CC_EVENT_RESUME {
217			Action Send_CC_Resume;
218			Next_State CC_STATE_ACTIVATED;
219		}
220	}
221	Superstate CC_ACTIVE(CC_STATE_ACTIVATED, CC_STATE_WAIT_CALLBACK, CC_STATE_CALLBACK, CC_STATE_SUSPENDED) {
222		Prolog {
223			/* Start QSIG_CCBS_T2/QSIG_CCNR_T2 depending upon CC mode. */
224			Action Start_T_SUPERVISION;
225		}
226		Epilog {
227			Action Stop_T_SUPERVISION;
228		}
229		Stimulus CC_EVENT_TIMEOUT_T_SUPERVISION {
230			Action Pass_Up_CC_Cancel;
231			Action Send_CC_Cancel;
232			Next_State CC_STATE_IDLE;
233		}
234		Stimulus CC_EVENT_SIGNALING_GONE {
235			/* Signaling link cleared. */
236			Action Disassociate_Signaling_Link;
237		}
238		Stimulus CC_EVENT_LINK_CANCEL {
239			/* Received ccCancel */
240			Action Pass_Up_CC_Cancel;
241			Action Post_HANGUP_SIGNALING;
242			Next_State CC_STATE_WAIT_DESTRUCTION;
243		}
244		Stimulus CC_EVENT_CANCEL {
245			Action Send_CC_Cancel;
246			Next_State CC_STATE_IDLE;
247		}
248	}
249}
250