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		Stimulus CC_EVENT_AVAILABLE {
8			/*
9			 * LibPRI will determine if CC will be offered based upon
10			 * if it is even possible.
11			 * Essentially:
12			 * 1) The call must not have been redirected in this link's
13			 * setup.
14			 * 2) Received an ALERTING or received a
15			 * DISCONNECT(busy/congestion).
16			 */
17			Action Pass_Up_CC_Available;
18			Next_State CC_STATE_AVAILABLE;
19		}
20		Stimulus CC_EVENT_CANCEL {
21			Action Set_Selfdestruct;
22		}
23	}
24	State CC_STATE_AVAILABLE {
25		/*
26		 * The upper layer is responsible for canceling the CC available
27		 * offering.
28		 */
29		Stimulus CC_EVENT_CC_REQUEST {
30			/*
31			 * Before event is posted:
32			 *   cc_record->is_ccnr is set.
33			 *   The signaling connection call record is created.
34			 */
35			Action Queue_CC_Request;
36			/* Start QSIG_CC_T1. */
37			Action Start_T_ACTIVATE;
38			Next_State CC_STATE_REQUESTED;
39		}
40		Stimulus CC_EVENT_CANCEL {
41			Action Set_Selfdestruct;
42			Next_State CC_STATE_IDLE;
43		}
44	}
45	State CC_STATE_REQUESTED {
46		Stimulus CC_EVENT_CC_REQUEST_ACCEPT {
47			/*
48			 * Received ccbsRequest/ccnrRequest response
49			 * Before event is posted:
50			 *   Negotiated CC retention setting saved
51			 *   Negotiated signaling link retention setting saved
52			 */
53			Action Stop_T_ACTIVATE;
54			Test = Get_msgtype;
55			Test == Q931_RELEASE {
56				Action Disassociate_Signaling_Link;
57				Test = Get_Retain_Signaling_Link;
58				Test == TRUE {
59					/*
60					 * The far end did not honor the
61					 * signaling link retention requirement.
62					 * ECMA-186 Section 6.5.2.2.1
63					 */
64					Action Pass_Up_CC_Req_Rsp_Timeout;
65					Action Pass_Up_CC_Cancel;
66					Action Send_CC_Cancel;
67					Action Set_Selfdestruct;
68					Next_State CC_STATE_IDLE;
69				}
70			}
71			Action Pass_Up_CC_Req_Rsp_Success;
72			/* Start QSIG_CCBS_T2/QSIG_CCNR_T2 depending upon CC mode. */
73			Action Start_T_SUPERVISION;
74			Action Reset_A_Status;
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			Action Set_Selfdestruct;
96			Next_State CC_STATE_IDLE;
97		}
98		Stimulus CC_EVENT_SIGNALING_GONE {
99			Action Stop_T_ACTIVATE;
100			/* Claim it was a timeout */
101			Action Pass_Up_CC_Req_Rsp_Timeout;
102			Action Pass_Up_CC_Cancel;
103			Action Set_Selfdestruct;
104			Next_State CC_STATE_IDLE;
105		}
106		Stimulus CC_EVENT_CANCEL {
107			Next_State CC_STATE_WAIT_DESTRUCTION;
108		}
109	}
110	State CC_STATE_WAIT_DESTRUCTION {
111		/*
112		 * Delayed disconnect of the signaling link to allow subcmd events
113		 * from the signaling link to be passed up.
114		 */
115		Stimulus CC_EVENT_CC_REQUEST_ACCEPT {
116			/*
117			 * Received ccbsRequest/ccnrRequest response
118			 * Before event is posted:
119			 *   Negotiated CC retention setting saved
120			 *   Negotiated signaling link retention setting saved
121			 */
122			Action Stop_T_ACTIVATE;
123			Test = Get_msgtype;
124			Test == Q931_RELEASE {
125				Action Disassociate_Signaling_Link;
126			}
127			Action Send_CC_Cancel;
128			Action Set_Selfdestruct;
129			Next_State CC_STATE_IDLE;
130		}
131		Stimulus CC_EVENT_CC_REQUEST_FAIL {
132			Action Stop_T_ACTIVATE;
133			/*
134			 * If this request fail comes in with the RELEASE message
135			 * then the post action will never get a chance to run.
136			 * It will be aborted because the CC_EVENT_SIGNALING_GONE
137			 * will be processed first.
138			 */
139			Action Post_HANGUP_SIGNALING;
140		}
141		Stimulus CC_EVENT_TIMEOUT_T_ACTIVATE {
142			Action Stop_T_ACTIVATE;
143			Action Hangup_Signaling_Link;
144			Action Set_Selfdestruct;
145			Next_State CC_STATE_IDLE;
146		}
147		Stimulus CC_EVENT_SIGNALING_GONE {
148			/* Signaling link cleared. */
149			Action Stop_T_ACTIVATE;
150			Action Set_Selfdestruct;
151			Next_State CC_STATE_IDLE;
152		}
153		Stimulus CC_EVENT_HANGUP_SIGNALING {
154			//Action Stop_T_ACTIVATE;
155			Action Hangup_Signaling_Link;
156			Action Set_Selfdestruct;
157			Next_State CC_STATE_IDLE;
158		}
159	}
160	State CC_STATE_ACTIVATED {
161		Stimulus CC_EVENT_REMOTE_USER_FREE {
162			/* Received ccExecPossible */
163			Action Pass_Up_Remote_User_Free;
164			/*
165			 * ECMA-186 Section 6.5.2.1.7
166			 * Implied switch to retain-signaling-link.
167			 */
168			Action Set_Retain_Signaling_Link;
169			Test = Get_msgtype;
170			Test == Q931_SETUP {
171				/* Send Q931_CALL_PROCEEDING message on signaling link. */
172				Action Send_Call_Proceeding;
173			}
174			Test = Get_A_Status;
175			Test == Busy {
176				/*
177				 * The ccSuspend will be sent in a FACILITY or CONNECT
178				 * message depending upon the CIS call state.
179				 */
180				Action Send_CC_Suspend;
181				Next_State CC_STATE_SUSPENDED;
182			}
183			/* Start QSIG_CC_T3 */
184			Action Start_T_RECALL;
185			Next_State CC_STATE_WAIT_CALLBACK;
186		}
187		Stimulus CC_EVENT_SUSPEND {
188			Action Set_A_Status_Busy;
189		}
190		Stimulus CC_EVENT_RESUME {
191			Action Reset_A_Status;
192		}
193		Stimulus CC_EVENT_TIMEOUT_T_SUPERVISION {
194			Action Pass_Up_CC_Cancel;
195			Action Send_CC_Cancel;
196			Action Stop_T_SUPERVISION;
197			Action Set_Selfdestruct;
198			Next_State CC_STATE_IDLE;
199		}
200		Stimulus CC_EVENT_SIGNALING_GONE {
201			/* Signaling link cleared. */
202			Action Disassociate_Signaling_Link;
203		}
204		Stimulus CC_EVENT_LINK_CANCEL {
205			/* Received ccCancel */
206			Action Pass_Up_CC_Cancel;
207			Action Post_HANGUP_SIGNALING;
208			Action Stop_T_SUPERVISION;
209			Next_State CC_STATE_WAIT_DESTRUCTION;
210		}
211		Stimulus CC_EVENT_CANCEL {
212			Action Send_CC_Cancel;
213			Action Stop_T_SUPERVISION;
214			Action Set_Selfdestruct;
215			Next_State CC_STATE_IDLE;
216		}
217	}
218	State CC_STATE_WAIT_CALLBACK {
219		Stimulus CC_EVENT_RECALL {
220			/* The original call parameters have already been set. */
221			Action Queue_SETUP_Recall;
222			Action Stop_T_RECALL;
223			Next_State CC_STATE_CALLBACK;
224		}
225		Stimulus CC_EVENT_SUSPEND {
226			Action Stop_T_RECALL;
227			/*
228			 * The ccSuspend will be sent in a FACILITY or CONNECT
229			 * message depending upon the CIS call state.
230			 */
231			Action Send_CC_Suspend;
232			Next_State CC_STATE_SUSPENDED;
233		}
234		Stimulus CC_EVENT_TIMEOUT_T_RECALL {
235			Action Pass_Up_CC_Cancel;
236			Action Send_CC_Cancel;
237			Action Stop_T_RECALL;
238			Action Stop_T_SUPERVISION;
239			Action Set_Selfdestruct;
240			Next_State CC_STATE_IDLE;
241		}
242		Stimulus CC_EVENT_TIMEOUT_T_SUPERVISION {
243			Action Pass_Up_CC_Cancel;
244			Action Send_CC_Cancel;
245			Action Stop_T_RECALL;
246			Action Stop_T_SUPERVISION;
247			Action Set_Selfdestruct;
248			Next_State CC_STATE_IDLE;
249		}
250		Stimulus CC_EVENT_SIGNALING_GONE {
251			/* Signaling link cleared. */
252			Action Disassociate_Signaling_Link;
253		}
254		Stimulus CC_EVENT_LINK_CANCEL {
255			/* Received ccCancel */
256			Action Pass_Up_CC_Cancel;
257			Action Post_HANGUP_SIGNALING;
258			Action Stop_T_RECALL;
259			Action Stop_T_SUPERVISION;
260			Next_State CC_STATE_WAIT_DESTRUCTION;
261		}
262		Stimulus CC_EVENT_CANCEL {
263			Action Send_CC_Cancel;
264			Action Stop_T_RECALL;
265			Action Stop_T_SUPERVISION;
266			Action Set_Selfdestruct;
267			Next_State CC_STATE_IDLE;
268		}
269	}
270	State CC_STATE_CALLBACK {
271		Stimulus CC_EVENT_TIMEOUT_T_SUPERVISION {
272			Action Pass_Up_CC_Cancel;
273			Action Send_CC_Cancel;
274			Action Stop_T_SUPERVISION;
275			Action Set_Selfdestruct;
276			Next_State CC_STATE_IDLE;
277		}
278		Stimulus CC_EVENT_SIGNALING_GONE {
279			/* Signaling link cleared. */
280			Action Disassociate_Signaling_Link;
281		}
282		Stimulus CC_EVENT_LINK_CANCEL {
283			/* Received ccCancel */
284			Action Pass_Up_CC_Cancel;
285			Action Post_HANGUP_SIGNALING;
286			Action Stop_T_SUPERVISION;
287			Next_State CC_STATE_WAIT_DESTRUCTION;
288		}
289		Stimulus CC_EVENT_CANCEL {
290			Action Send_CC_Cancel;
291			Action Stop_T_SUPERVISION;
292			Action Set_Selfdestruct;
293			Next_State CC_STATE_IDLE;
294		}
295	}
296	State CC_STATE_SUSPENDED {
297		Stimulus CC_EVENT_RESUME {
298			Action Send_CC_Resume;
299			Action Reset_A_Status;
300			Next_State CC_STATE_ACTIVATED;
301		}
302		Stimulus CC_EVENT_TIMEOUT_T_SUPERVISION {
303			Action Pass_Up_CC_Cancel;
304			Action Send_CC_Cancel;
305			Action Stop_T_SUPERVISION;
306			Action Set_Selfdestruct;
307			Next_State CC_STATE_IDLE;
308		}
309		Stimulus CC_EVENT_SIGNALING_GONE {
310			/* Signaling link cleared. */
311			Action Disassociate_Signaling_Link;
312		}
313		Stimulus CC_EVENT_LINK_CANCEL {
314			/* Received ccCancel */
315			Action Pass_Up_CC_Cancel;
316			Action Post_HANGUP_SIGNALING;
317			Action Stop_T_SUPERVISION;
318			Next_State CC_STATE_WAIT_DESTRUCTION;
319		}
320		Stimulus CC_EVENT_CANCEL {
321			Action Send_CC_Cancel;
322			Action Stop_T_SUPERVISION;
323			Action Set_Selfdestruct;
324			Next_State CC_STATE_IDLE;
325		}
326	}
327}
328