1/*
2 * FSM pseudo code used in the design/implementation of the CC PTP agent.
3 */
4FSM CC_PTP_Agent
5{
6	State CC_STATE_IDLE {
7		Init {
8		}
9		Prolog {
10			Action Set_Selfdestruct;
11		}
12		Stimulus CC_EVENT_AVAILABLE {
13			Next_State CC_STATE_PENDING_AVAILABLE;
14		}
15		Stimulus CC_EVENT_CANCEL {
16			Action Set_Selfdestruct;
17		}
18	}
19	State CC_STATE_PENDING_AVAILABLE {
20		Stimulus CC_EVENT_MSG_ALERTING {
21			Action Send_CC_Available(Q931_ALERTING);
22			Next_State CC_STATE_AVAILABLE;
23		}
24		Stimulus CC_EVENT_MSG_DISCONNECT {
25			Action Send_CC_Available(Q931_DISCONNECT);
26			Next_State CC_STATE_AVAILABLE;
27		}
28		Stimulus CC_EVENT_INTERNAL_CLEARING {
29			Action Pass_Up_CC_Cancel;
30			Next_State CC_STATE_IDLE;
31		}
32		Stimulus CC_EVENT_CANCEL {
33			Next_State CC_STATE_IDLE;
34		}
35	}
36	State CC_STATE_AVAILABLE {
37		/*
38		 * For PTP mode the T_RETENTION timer is not defined.  However,
39		 * we will use it anyway in this state to protect our resources
40		 * from leaks caused by user A not requesting CC.  This timer
41		 * should be set much longer than the PTMP network link to
42		 * allow for variations in user A's CC offer timer.
43		 */
44		Epilog {
45			Action Stop_T_RETENTION;
46		}
47		Stimulus CC_EVENT_MSG_RELEASE {
48			Action Stop_T_RETENTION;
49			Action Start_T_RETENTION;
50		}
51		Stimulus CC_EVENT_MSG_RELEASE_COMPLETE {
52			Action Stop_T_RETENTION;
53			Action Start_T_RETENTION;
54		}
55		Stimulus CC_EVENT_CC_REQUEST {
56			Action Pass_Up_CC_Request;
57			Action Stop_T_RETENTION;
58			Next_State CC_STATE_REQUESTED;
59		}
60		Stimulus CC_EVENT_INTERNAL_CLEARING {
61			Action Stop_T_RETENTION;
62			Action Start_T_RETENTION;
63		}
64		Stimulus CC_EVENT_TIMEOUT_T_RETENTION {
65			Action Pass_Up_CC_Cancel;
66			Next_State CC_STATE_IDLE;
67		}
68		Stimulus CC_EVENT_CANCEL {
69			Next_State CC_STATE_IDLE;
70		}
71	}
72	State CC_STATE_REQUESTED {
73		Stimulus CC_EVENT_CC_REQUEST_ACCEPT {
74			Next_State CC_STATE_ACTIVATED;
75		}
76		Stimulus CC_EVENT_SIGNALING_GONE {
77			/* Signaling link cleared. */
78			Action Pass_Up_CC_Cancel;
79			Next_State CC_STATE_IDLE;
80		}
81		Stimulus CC_EVENT_CANCEL {
82			Action Hangup_Signaling_Link;
83			Next_State CC_STATE_IDLE;
84		}
85	}
86	State CC_STATE_ACTIVATED {
87		Prolog {
88			Action Reset_A_Status;
89		}
90		Stimulus CC_EVENT_REMOTE_USER_FREE {
91			Action Pass_Up_A_Status_Indirect;
92			Test = Get_A_Status;
93			Test == Busy {
94				Next_State CC_STATE_SUSPENDED;
95			}
96			Action Send_RemoteUserFree;
97			Next_State CC_STATE_WAIT_CALLBACK;
98		}
99		Stimulus CC_EVENT_SUSPEND {
100			/* Received CCBS_T_Suspend */
101			Action Set_A_Status_Busy;
102		}
103		Stimulus CC_EVENT_RESUME {
104			/* Received CCBS_T_Resume */
105			Action Reset_A_Status;
106		}
107	}
108	State CC_STATE_WAIT_CALLBACK {
109		Stimulus CC_EVENT_SUSPEND {
110			/* Received CCBS_T_Suspend */
111			Action Set_A_Status_Busy;
112			Action Pass_Up_A_Status;
113			Next_State CC_STATE_SUSPENDED;
114		}
115	}
116	State CC_STATE_SUSPENDED {
117		Stimulus CC_EVENT_RESUME {
118			/* Received CCBS_T_Resume */
119			Action Set_A_Status_Free;
120			Action Pass_Up_A_Status;
121			Next_State CC_STATE_ACTIVATED;
122		}
123	}
124	Superstate CC_ACTIVE(CC_STATE_ACTIVATED, CC_STATE_WAIT_CALLBACK, CC_STATE_SUSPENDED) {
125		Prolog {
126			/* Start T_CCBS5/T_CCNR5 depending upon CC mode. */
127			Action Start_T_SUPERVISION;
128		}
129		Epilog {
130			Action Stop_T_SUPERVISION;
131		}
132		Stimulus CC_EVENT_RECALL {
133			/* Received CCBS_T_Call */
134			Action Pass_Up_CC_Call;
135			Action Set_Original_Call_Parameters;
136		}
137		Stimulus CC_EVENT_TIMEOUT_T_SUPERVISION {
138			Action Pass_Up_CC_Cancel;
139			Action Hangup_Signaling_Link;
140			Next_State CC_STATE_IDLE;
141		}
142		Stimulus CC_EVENT_SIGNALING_GONE {
143			/* Signaling link cleared. */
144			Action Pass_Up_CC_Cancel;
145			Next_State CC_STATE_IDLE;
146		}
147		Stimulus CC_EVENT_CANCEL {
148			Action Hangup_Signaling_Link;
149			Next_State CC_STATE_IDLE;
150		}
151	}
152}
153