1/*
2 * FSM pseudo code used in the design/implementation of the CC PTMP monitor.
3 *
4 * The CCBSStatusRequest messages are handled independently from this FSM.
5 *
6 * The CCBSInterrogate/CCNRInterrogate messages are initiated by a dialplan
7 * application/AMI/CLI (future) and are handled outside of this FSM.
8 */
9FSM CC_PTMP_Monitor
10{
11	State CC_STATE_IDLE {
12		Init {
13		}
14		Prolog {
15			Action Set_Selfdestruct;
16		}
17		Stimulus CC_EVENT_AVAILABLE {
18			/*
19			 * Before event is posted:
20			 *   Received CallInfoRetain
21			 *   Created cc_record
22			 *   Saved CallLinkageID
23			 */
24			Action Pass_Up_CC_Available;
25			Next_State CC_STATE_AVAILABLE;
26		}
27		Stimulus CC_EVENT_CANCEL {
28			Action Set_Selfdestruct;
29		}
30	}
31	State CC_STATE_AVAILABLE {
32		/*
33		 * The upper layer is responsible for canceling the CC available
34		 * offering as a safeguard in case the network cable is disconnected.
35		 * The timer should be set much longer than the network T_RETENTION
36		 * timer so normally the CC records will be cleaned up by network
37		 * activity.
38		 */
39		Stimulus CC_EVENT_CC_REQUEST {
40			/* cc_record->is_ccnr is set before event posted. */
41			Action Queue_CC_Request;
42			Action Start_T_ACTIVATE;
43			Next_State CC_STATE_REQUESTED;
44		}
45		Stimulus CC_EVENT_TIMEOUT_T_RETENTION {
46			/*
47			 * Received EraseCallLinkageID
48			 * T_RETENTION expired on the network side so we will pretend
49			 * that it expired on our side.
50			 */
51			Action Pass_Up_CC_Cancel;
52			Next_State CC_STATE_IDLE;
53		}
54		Stimulus CC_EVENT_CANCEL {
55			Next_State CC_STATE_IDLE;
56		}
57	}
58	State CC_STATE_REQUESTED {
59		Stimulus CC_EVENT_CC_REQUEST_ACCEPT {
60			/*
61			 * Before event is posted:
62			 *   Received CCBSRequest/CCNRRequest response
63			 *   Saved CCBSReference
64			 */
65			Action Relese_LinkID;
66			Action Pass_Up_CC_Req_Rsp_Success;
67			Action Stop_T_ACTIVATE;
68			Next_State CC_STATE_ACTIVATED;
69		}
70		Stimulus CC_EVENT_CC_REQUEST_FAIL {
71			Action Pass_Up_CC_Req_Rsp_Fail(error/reject, code);
72			Action Pass_Up_CC_Cancel;
73			Action Stop_T_ACTIVATE;
74			Next_State CC_STATE_IDLE;
75		}
76		Stimulus CC_EVENT_TIMEOUT_T_ACTIVATE {
77			Action Pass_Up_CC_Req_Rsp_Timeout;
78			Action Pass_Up_CC_Cancel;
79			Action Stop_T_ACTIVATE;
80			Next_State CC_STATE_IDLE;
81		}
82		Stimulus CC_EVENT_LINK_CANCEL {
83			/* Received CCBSErase */
84			/* Claim it was a timeout */
85			Action Pass_Up_CC_Req_Rsp_Timeout;
86			Action Pass_Up_CC_Cancel;
87			Action Stop_T_ACTIVATE;
88			Next_State CC_STATE_IDLE;
89		}
90		Stimulus CC_EVENT_CANCEL {
91			Next_State CC_STATE_WAIT_DESTRUCTION;
92		}
93	}
94	State CC_STATE_WAIT_DESTRUCTION {
95		/* We were in the middle of a cc-request when we were asked to cancel. */
96		Epilog {
97			Action Stop_T_ACTIVATE;
98		}
99		Stimulus CC_EVENT_CC_REQUEST_ACCEPT {
100			/*
101			 * Before event is posted:
102			 *   Received CCBSRequest/CCNRRequest response
103			 *   Saved CCBSReference
104			 */
105			Action Send_CC_Deactivate_Req;
106			Next_State CC_STATE_IDLE;
107		}
108		Stimulus CC_EVENT_CC_REQUEST_FAIL {
109			Next_State CC_STATE_IDLE;
110		}
111		Stimulus CC_EVENT_TIMEOUT_T_ACTIVATE {
112			Next_State CC_STATE_IDLE;
113		}
114		Stimulus CC_EVENT_LINK_CANCEL {
115			/* Received CCBSErase */
116			Next_State CC_STATE_IDLE;
117		}
118	}
119	State CC_STATE_ACTIVATED {
120		Stimulus CC_EVENT_B_FREE {
121			/* Received CCBSBFree */
122			Action Pass_Up_B_Free;
123		}
124		Stimulus CC_EVENT_REMOTE_USER_FREE {
125			/* Received CCBSRemoteUserFree */
126			Action Pass_Up_Remote_User_Free;
127			Next_State CC_STATE_WAIT_CALLBACK;
128		}
129	}
130	State CC_STATE_WAIT_CALLBACK {
131		Stimulus CC_EVENT_STOP_ALERTING {
132			Action Pass_Up_Stop_Alerting;
133			Next_State CC_STATE_ACTIVATED;
134		}
135		Stimulus CC_EVENT_RECALL {
136			/* The original call parameters have already been set. */
137			Action Queue_SETUP_Recall;
138			Next_State CC_STATE_CALLBACK;
139		}
140	}
141	State CC_STATE_CALLBACK {
142		/*
143		 * We are waiting for the CC records to be torn down because
144		 * CC is complete.
145		 * This state is mainly to block CC_EVENT_STOP_ALERTING since
146		 * we are the one doing the CC recall so we do not need to stop
147		 * alerting.
148		 */
149	}
150	Superstate CC_ACTIVE(CC_STATE_ACTIVATED, CC_STATE_WAIT_CALLBACK, CC_STATE_CALLBACK) {
151		Prolog {
152			/*
153			 * Start T_CCBS2 or T_CCNR2 depending upon CC mode.
154			 * For PTMP TE mode these timers are not defined.  However,
155			 * we will use them anyway to protect our resources from leaks
156			 * caused by the network cable being disconnected.  These
157			 * timers should be set much longer than the network
158			 * so normally the CC records will be cleaned up by network
159			 * activity.
160			 */
161			Action Start_T_SUPERVISION;
162		}
163		Epilog {
164			Action Stop_T_SUPERVISION;
165		}
166		Stimulus CC_EVENT_TIMEOUT_T_SUPERVISION {
167			Action Send_CC_Deactivate_Req;
168			Action Pass_Up_CC_Cancel;
169			Next_State CC_STATE_IDLE;
170		}
171		Stimulus CC_EVENT_LINK_CANCEL {
172			/* Received CCBSErase */
173			Action Pass_Up_CC_Cancel;
174			Next_State CC_STATE_IDLE;
175		}
176		Stimulus CC_EVENT_CANCEL {
177			Action Send_CC_Deactivate_Req;
178			Next_State CC_STATE_IDLE;
179		}
180	}
181}
182