1 /*****************************************************************************
2 
3   FileName:		q931StateTE.c
4 
5   Contents:		Q.931 State Engine for TE (User Mode).
6 
7 			The controlling state engine for Q.931 is the state engine
8 			on the NT side. The state engine on the TE side is a slave
9 			of this. The TE side maintain it's own states as described in
10 			ITU-T Q931, but will in	raise conditions be overridden by
11 			the NT side.
12 
13 			This reference implementation uses a process per message,
14 			meaning that each message must check call states. This
15 			is easier for dialect maintenance as each message proc
16 			can be replaced individually. A new TE variant only
17 			need to copy the Q931CreateTE and replace those procs or
18 			need to override.
19 
20   License/Copyright:
21 
22   Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
23   email:janvb@caselaboratories.com
24 
25   Redistribution and use in source and binary forms, with or without
26   modification, are permitted provided that the following conditions are
27   met:
28 
29 	* Redistributions of source code must retain the above copyright notice,
30 	  this list of conditions and the following disclaimer.
31 	* Redistributions in binary form must reproduce the above copyright notice,
32 	  this list of conditions and the following disclaimer in the documentation
33 	  and/or other materials provided with the distribution.
34 	* Neither the name of the Case Labs, Ltd nor the names of its contributors
35 	  may be used to endorse or promote products derived from this software
36 	  without specific prior written permission.
37 
38   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
42   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
44   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
46   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48   POSSIBILITY OF SUCH DAMAGE.
49 *****************************************************************************/
50 
51 #include "Q931.h"
52 
53 extern L3INT Q931L4HeaderSpace;
54 
55 /*****************************************************************************
56   Function:		Q931CreateTE
57 
58   Description:	Will create the Q931 TE as a Dialect in the stack. The first
59 				bulk set up the message handlers, the second bulk the IE
60 				encoders/coders, and the last bulk set up the state table.
61 
62   Parameters:	i		Dialect index
63 *****************************************************************************/
Q931CreateTE(L3UCHAR i)64 void Q931CreateTE(L3UCHAR i)
65 {
66 	Q931SetMesProc(Q931mes_ALERTING,             i, Q931ProcAlertingTE,          Q931Umes_Alerting,          Q931Pmes_Alerting);
67 	Q931SetMesProc(Q931mes_CALL_PROCEEDING,      i, Q931ProcCallProceedingTE,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);
68 	Q931SetMesProc(Q931mes_CONNECT,              i, Q931ProcConnectTE,           Q931Umes_Connect,           Q931Pmes_Connect);
69 	Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE,  i, Q931ProcConnectAckTE,        Q931Umes_ConnectAck,        Q931Pmes_ConnectAck);
70 	Q931SetMesProc(Q931mes_PROGRESS,             i, Q931ProcProgressTE,          Q931Umes_Progress,          Q931Pmes_Progress);
71 	Q931SetMesProc(Q931mes_SETUP,                i, Q931ProcSetupTE,             Q931Umes_Setup,             Q931Pmes_Setup);
72 	Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,    i, Q931ProcSetupAckTE,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);
73 	Q931SetMesProc(Q931mes_RESUME,               i, Q931ProcResumeTE,            Q931Umes_Resume,            Q931Pmes_Resume);
74 	Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,   i, Q931ProcResumeAckTE,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);
75 	Q931SetMesProc(Q931mes_RESUME_REJECT,        i, Q931ProcResumeRejectTE,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);
76 	Q931SetMesProc(Q931mes_SUSPEND,              i, Q931ProcSuspendTE,           Q931Umes_Suspend,           Q931Pmes_Suspend);
77 	Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE,  i, Q931ProcSuspendAckTE,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);
78 	Q931SetMesProc(Q931mes_SUSPEND_REJECT,       i, Q931ProcSuspendRejectTE,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);
79 	Q931SetMesProc(Q931mes_USER_INFORMATION,     i, Q931ProcUserInformationTE,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);
80 	Q931SetMesProc(Q931mes_DISCONNECT,           i, Q931ProcDisconnectTE,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);
81 	Q931SetMesProc(Q931mes_RELEASE,              i, Q931ProcReleaseTE,           Q931Umes_Release,           Q931Pmes_Release);
82 	Q931SetMesProc(Q931mes_RELEASE_COMPLETE,     i, Q931ProcReleaseCompleteTE,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);
83 	Q931SetMesProc(Q931mes_RESTART,              i, Q931ProcRestartTE,           Q931Umes_Restart,           Q931Pmes_Restart);
84 	Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE,  i, Q931ProcRestartAckTE,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);
85 	Q931SetMesProc(Q931mes_CONGESTION_CONTROL,   i, Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
86 	Q931SetMesProc(Q931mes_INFORMATION,          i, Q931ProcInformationTE,       Q931Umes_Information,       Q931Pmes_Information);
87 	Q931SetMesProc(Q931mes_NOTIFY,               i, Q931ProcNotifyTE,            Q931Umes_Notify,            Q931Pmes_Notify);
88 	Q931SetMesProc(Q931mes_STATUS,               i, Q931ProcStatusTE,            Q931Umes_Status,            Q931Pmes_Status);
89 	Q931SetMesProc(Q931mes_STATUS_ENQUIRY,       i, Q931ProcStatusEnquiryTE,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);
90 	Q931SetMesProc(Q931mes_SEGMENT,              i, Q931ProcSegmentTE,           Q931Umes_Segment,           Q931Pmes_Segment);
91 
92 	Q931SetMesProc(Q932mes_FACILITY,             i, Q932ProcFacilityTE,          Q932Umes_Facility,          Q932Pmes_Facility);
93 	Q931SetMesProc(Q932mes_HOLD,                 i, Q932ProcHoldTE,              Q932Umes_Hold,              Q932Pmes_Hold);
94 	Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,     i, Q932ProcHoldAckTE,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);
95 	Q931SetMesProc(Q932mes_HOLD_REJECT,          i, Q932ProcHoldRejectTE,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);
96 	Q931SetMesProc(Q932mes_REGISTER,             i, Q932ProcRegisterTE,          Q932Umes_Register,          Q932Pmes_Register);
97 	Q931SetMesProc(Q932mes_RETRIEVE,             i, Q932ProcRetrieveTE,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);
98 	Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckTE,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);
99 	Q931SetMesProc(Q932mes_RETRIEVE_REJECT,      i, Q932ProcRetrieveRejectTE,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);
100 
101 	/* Set up the IE encoder/decoder handle table.*/
102 	Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i, Q931Pie_Segment,     Q931Uie_Segment);
103 	Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i, Q931Pie_BearerCap,   Q931Uie_BearerCap);
104 	Q931SetIEProc(Q931ie_CAUSE,                            i, Q931Pie_Cause,       Q931Uie_Cause);
105 	Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i, Q931Pie_CallID,      Q931Uie_CallID);
106 	Q931SetIEProc(Q931ie_CALL_STATE,                       i, Q931Pie_CallState,   Q931Uie_CallState);
107 	Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i, Q931Pie_ChanID,      Q931Uie_ChanID);
108 	Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i, Q931Pie_ProgInd,     Q931Uie_ProgInd);
109 	Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i, Q931Pie_NetFac,      Q931Uie_NetFac);
110 	Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i, Q931Pie_NotifInd,    Q931Uie_NotifInd);
111 	Q931SetIEProc(Q931ie_DISPLAY,                          i, Q931Pie_Display,     Q931Uie_Display);
112 	Q931SetIEProc(Q931ie_DATETIME,                         i, Q931Pie_DateTime,    Q931Uie_DateTime);
113 	Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i, Q931Pie_KeypadFac,   Q931Uie_KeypadFac);
114 	Q931SetIEProc(Q931ie_SIGNAL,                           i, Q931Pie_Signal,      Q931Uie_Signal);
115 	Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
116 	Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i, Q931Pie_CallingNum,  Q931Uie_CallingNum);
117 	Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i, Q931Pie_CallingSub,  Q931Uie_CallingSub);
118 	Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i, Q931Pie_CalledNum,   Q931Uie_CalledNum);
119 	Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i, Q931Pie_CalledSub,   Q931Uie_CalledSub);
120 	Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
121 	Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i, Q931Pie_RestartInd,  Q931Uie_RestartInd);
122 	Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i, Q931Pie_LLComp,      Q931Uie_LLComp);
123 	Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i, Q931Pie_HLComp,      Q931Uie_HLComp);
124 	Q931SetIEProc(Q931ie_USER_USER,                        i, Q931Pie_UserUser,    Q931Uie_UserUser);
125 
126 	Q931SetIEProc(Q931ie_CONNECTED_NUMBER,   i, Q931Pie_Generic, Q931Uie_Generic);
127 	Q931SetIEProc(Q931ie_FACILITY,           i, Q931Pie_Generic, Q931Uie_Generic);
128 	Q931SetIEProc(Q931ie_REDIRECTING_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
129 
130 	/* The following define a state machine. The point is that the Message
131 	 * procs can when search this to find out if the message/state
132 	 * combination is legale. If not, the proc for unexpected message apply.
133 	 */
134 
135 	/* State 0 Idle */
136 	Q931AddStateEntry(i, Q931_U0, Q931mes_RESUME,           2);
137 	Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP,            4);
138 	Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP,            2);
139 	Q931AddStateEntry(i, Q931_U0, Q931mes_STATUS,           4);
140 	Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE,          4);
141 	Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE_COMPLETE, 4);
142 
143 	/* State 1 Call Initiating */
144 	Q931AddStateEntry(i, Q931_U1, Q931mes_DISCONNECT,        2);
145 	Q931AddStateEntry(i, Q931_U1, Q931mes_SETUP_ACKNOWLEDGE, 4);
146 	Q931AddStateEntry(i, Q931_U1, Q931mes_RELEASE_COMPLETE,  4);
147 	Q931AddStateEntry(i, Q931_U1, Q931mes_CALL_PROCEEDING,   4);
148 	Q931AddStateEntry(i, Q931_U1, Q931mes_ALERTING,          4);
149 	Q931AddStateEntry(i, Q931_U1, Q931mes_CONNECT,           4);
150 
151 	/* State 2 Overlap Sending */
152 	Q931AddStateEntry(i, Q931_U2, Q931mes_INFORMATION,     2);
153 	Q931AddStateEntry(i, Q931_U2, Q931mes_CALL_PROCEEDING, 4);
154 	Q931AddStateEntry(i, Q931_U2, Q931mes_ALERTING,        4);
155 	Q931AddStateEntry(i, Q931_U2, Q931mes_PROGRESS,        4);
156 	Q931AddStateEntry(i, Q931_U2, Q931mes_CONNECT,         4);
157 	Q931AddStateEntry(i, Q931_U2, Q931mes_RELEASE,         2);
158 
159 	/* State 3 Outgoing Call Proceeding */
160 	Q931AddStateEntry(i, Q931_U3, Q931mes_PROGRESS, 4);
161 	Q931AddStateEntry(i, Q931_U3, Q931mes_ALERTING, 4);
162 	Q931AddStateEntry(i, Q931_U3, Q931mes_CONNECT,  4);
163 	Q931AddStateEntry(i, Q931_U3, Q931mes_RELEASE,  2);
164 
165 	/* State 4 Call Delivered */
166 	Q931AddStateEntry(i, Q931_U4, Q931mes_CONNECT, 4);
167 
168 	/* State 6 Call Precent */
169 	Q931AddStateEntry(i, Q931_U6, Q931mes_INFORMATION,      2);
170 	Q931AddStateEntry(i, Q931_U6, Q931mes_ALERTING,         2);
171 	Q931AddStateEntry(i, Q931_U6, Q931mes_CALL_PROCEEDING,  2);
172 	Q931AddStateEntry(i, Q931_U6, Q931mes_CONNECT,          2);
173 	Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE_COMPLETE, 2);
174 	Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE,          4);
175 	Q931AddStateEntry(i, Q931_U6, Q931mes_DISCONNECT,       4);
176 
177 	/* State 7 Call Received */
178 	Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2);
179 
180 	/* State 8 Connect request */
181 	Q931AddStateEntry(i, Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4);
182 
183 	/* State 9 Incoming Call Proceeding */
184 	Q931AddStateEntry(i, Q931_U9, Q931mes_CONNECT,  2);
185 	Q931AddStateEntry(i, Q931_U9, Q931mes_ALERTING, 2);
186 	Q931AddStateEntry(i, Q931_U9, Q931mes_PROGRESS, 2);
187 
188 	/* State 10 Active */
189 	Q931AddStateEntry(i, Q931_U10, Q931mes_SUSPEND, 2);
190 	Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY,  4);
191 	Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY,  2);
192 
193 	/* State 11 Disconnect Request */
194 	Q931AddStateEntry(i, Q931_U11, Q931mes_RELEASE,    4);
195 	Q931AddStateEntry(i, Q931_U11, Q931mes_DISCONNECT, 4);
196 	Q931AddStateEntry(i, Q931_U11, Q931mes_NOTIFY,     4);
197 
198 	/* State 12 Disconnect Ind */
199 	Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 4);
200 	Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 2);
201 
202 	/* State 15 Suspend Request */
203 	Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_ACKNOWLEDGE, 4);
204 	Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_REJECT,      4);
205 	Q931AddStateEntry(i, Q931_U15, Q931mes_DISCONNECT,          4);
206 	Q931AddStateEntry(i, Q931_U15, Q931mes_RELEASE,             4);
207 
208 /* TODO
209 	Q931AddStateEntry(i, Q931_U17,
210 	Q931AddStateEntry(i, Q931_U19,
211 	Q931AddStateEntry(i, Q931_U25,
212 */
213 
214 	/* Timer default values */
215 	Q931SetTimerDefault(i, Q931_TIMER_T301, 180000);	/* T301: 180s */
216 	Q931SetTimerDefault(i, Q931_TIMER_T302,  15000);	/* T302:  15s */
217 	Q931SetTimerDefault(i, Q931_TIMER_T303,   4000);	/* T303:   4s */
218 	Q931SetTimerDefault(i, Q931_TIMER_T304,  30000);	/* T304:  30s */
219 	Q931SetTimerDefault(i, Q931_TIMER_T305,  30000);	/* T305:  30s */
220 	Q931SetTimerDefault(i, Q931_TIMER_T308,   4000);	/* T308:   4s */
221 	Q931SetTimerDefault(i, Q931_TIMER_T309,  60000);	/* T309:  60s */
222 	Q931SetTimerDefault(i, Q931_TIMER_T310,  60000);	/* T310:  60s */
223 	Q931SetTimerDefault(i, Q931_TIMER_T313,   4000);	/* T313:   4s */
224 	Q931SetTimerDefault(i, Q931_TIMER_T314,   4000);	/* T314:   4s */
225 	Q931SetTimerDefault(i, Q931_TIMER_T316, 120000);	/* T316: 120s */
226 	Q931SetTimerDefault(i, Q931_TIMER_T317,  90000);	/* T317:  90s */
227 	Q931SetTimerDefault(i, Q931_TIMER_T318,   4000);	/* T318:   4s */
228 	Q931SetTimerDefault(i, Q931_TIMER_T319,   4000);	/* T319:   4s */
229 	Q931SetTimerDefault(i, Q931_TIMER_T321,  30000);	/* T321:  30s */
230 	Q931SetTimerDefault(i, Q931_TIMER_T322,   4000);	/* T322:   4s */
231 }
232 
233 /*****************************************************************************
234 
235   Function:		Q931ProcAlertingTE
236 
237 *****************************************************************************/
Q931ProcAlertingTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)238 L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
239 {
240 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
241 	L3INT callIndex;
242 	L3INT ret = Q931E_NO_ERROR;
243 
244 	/* Find the call using CRV */
245 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
246 	if (ret != Q931E_NO_ERROR)
247 		return ret;
248 
249 	/* Reset 4 sec timer. */
250 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
251 	if (iFrom == 4) {
252 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
253 	}
254 	else if (iFrom == 2) {
255 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
256 	}
257 	return ret;
258 }
259 
260 /*****************************************************************************
261 
262   Function:		Q931ProcCallProceedingTE
263 
264 *****************************************************************************/
Q931ProcCallProceedingTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)265 L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
266 {
267 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
268 	L3INT callIndex;
269 	L3INT ret = Q931E_NO_ERROR;
270 
271 	/* Find the call using CRV */
272 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
273 	if (ret != Q931E_NO_ERROR)
274 		return ret;
275 
276 	/* TODO chack against state table for illegal or unexpected message here */
277 
278 	/* TODO - Set correct timer here */
279 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
280 	if (iFrom == 4) {
281 		/* TODO Add proc here */
282 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
283 	}
284 	else if (iFrom == 2) {
285 		/* TODO Add proc here */
286 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
287 	}
288 	return ret;
289 }
290 
291 /*****************************************************************************
292 
293   Function:		Q931ProcConnectTE
294 
295 *****************************************************************************/
Q931ProcConnectTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)296 L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
297 {
298 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
299 	L3INT callIndex;
300 	L3INT ret = Q931E_NO_ERROR;
301 
302 	/* Find the call using CRV */
303 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
304 	if (ret != Q931E_NO_ERROR)
305 		return ret;
306 
307 	/* TODO chack against state table for illegal or unexpected message here */
308 
309 	/* TODO - Set correct timer here */
310 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
311 	if (iFrom ==4) {
312 		/* TODO Add proc here */
313 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
314 	}
315 	else if (iFrom == 2) {
316 		/* TODO Add proc here */
317 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
318 		if (pTrunk->autoConnectAck) {
319 			Q931AckConnect(pTrunk, buf);
320 		}
321 	}
322 	return ret;
323 }
324 
325 /*****************************************************************************
326 
327   Function:		Q931ProcConnectAckTE
328 
329 *****************************************************************************/
Q931ProcConnectAckTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)330 L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
331 {
332 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
333 	L3INT callIndex;
334 	L3INT ret = Q931E_NO_ERROR;
335 
336 	/* Find the call using CRV */
337 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
338 	if (ret != Q931E_NO_ERROR)
339 		return ret;
340 
341 	/* TODO chack against state table for illegal or unexpected message here */
342 
343 	/* TODO - Set correct timer here */
344 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
345 	if (iFrom ==4) {
346 		/* TODO Add proc here */
347 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
348 	}
349 	else if (iFrom == 2) {
350 		/* TODO Add proc here */
351 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
352 	}
353 	return ret;
354 }
355 
356 /*****************************************************************************
357 
358   Function:		Q931ProcProgressTE
359 
360 *****************************************************************************/
Q931ProcProgressTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)361 L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
362 {
363 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
364 	L3INT callIndex;
365 	L3INT ret = Q931E_NO_ERROR;
366 
367 	/* Find the call using CRV */
368 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
369 	if (ret != Q931E_NO_ERROR)
370 		return ret;
371 
372 	/* TODO chack against state table for illegal or unexpected message here */
373 
374 	/* TODO - Set correct timer here */
375 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
376 	if (iFrom ==4) {
377 		/* TODO Add proc here */
378 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
379 	}
380 	else if (iFrom == 2) {
381 		/* TODO Add proc here */
382 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
383 	}
384 	return ret;
385 }
386 
387 /*****************************************************************************
388 
389   Function:		Q931ProcSetupTE
390 
391 *****************************************************************************/
Q931ProcSetupTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)392 L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
393 {
394 	Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
395 	L3INT rc = 0;
396 	L3INT callIndex;
397 	L3INT ret = Q931E_NO_ERROR;
398 
399 	/* Reject SETUP on existing calls */
400 	if (Q931GetCallState(pTrunk, pMes->CRV) != Q931_U0) {
401 		Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
402 		return Q931E_UNEXPECTED_MESSAGE;
403 	}
404 
405 	/* outgoing call */
406 	if (iFrom == 4) {
407 		ret = Q931CreateCRV(pTrunk, &callIndex);
408 		if (ret)
409 			return ret;
410 		pMes->CRV = pTrunk->call[callIndex].CRV;
411 
412 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
413 		if (ret)
414 			return ret;
415 
416 		Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
417 
418 		/* TODO: Add this back when we get the state stuff more filled out */
419 		/*Q931SetState(pTrunk, callIndex, Q931_U1);*/
420 	}
421 	/* incoming call */
422 	else {
423 		/* Locate free CRV entry and store info */
424 		ret = Q931AllocateCRV(pTrunk, pMes->CRV, &callIndex);
425 		if (ret != Q931E_NO_ERROR) {
426 			/* Not possible to allocate CRV entry, so must reject call */
427 			Q931Disconnect(pTrunk, iFrom, pMes->CRV, 42);
428 			return ret;
429 		}
430 
431 		/* Send setup indication to user */
432 		ret = Q931Tx34(pTrunk, (L3UCHAR*)pMes, pMes->Size);
433 		if (ret != Q931E_NO_ERROR) {
434 			if (pTrunk->autoSetupAck) {
435 				Q931AckSetup(pTrunk, buf);
436 			}
437 			return ret;
438 		} else {
439 			/* Must be full queue, meaning we can't process the call */
440 			/* so we must disconnect */
441 			Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
442 			 return ret;
443 		}
444 #if 0
445 		/* TODO: Unreachable code??? */
446 		/* Set state U6 */
447 		Q931SetState(pTrunk, callIndex, Q931_U6);
448 
449 		Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
450 #endif
451 	}
452 	return rc;
453 }
454 
455 /*****************************************************************************
456 
457   Function:		Q931ProcSetupAckTE
458 
459   Description:	Used to acknowedge a SETUP. Usually the first initial
460 				response recevide back used to buy some time. L4 sending this
461 				should only be passed on. L2 sending this means that we set
462 				a new timer (and pass it to L4).
463 
464 				Note that ChanID (B Channel Assignment) might come here from
465 				NT side.
466 
467 *****************************************************************************/
Q931ProcSetupAckTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)468 L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
469 {
470 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
471 	L3INT callIndex;
472 	L3INT ret = Q931E_NO_ERROR;
473 
474 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
475 	if (ret != Q931E_NO_ERROR)
476 		return ret;
477 
478 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
479 	if (iFrom ==4) {
480 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
481 	}
482 	else if (iFrom == 2) {
483 		Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
484 	}
485 	return ret;
486 }
487 
488 /*****************************************************************************
489 
490   Function:		Q931ProcResumeTE
491 
492 *****************************************************************************/
Q931ProcResumeTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)493 L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
494 {
495 	Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
496 	L3INT callIndex;
497 	L3INT ret = Q931E_NO_ERROR;
498 
499 	if (Q931GetCallState(pTrunk, pMes->CRV) == Q931_U0 && iFrom ==4) {
500 		/* Call reference selection */
501 		ret = Q931CreateCRV(pTrunk, &callIndex);
502 		if (ret != Q931E_NO_ERROR)
503 			return ret;
504 		pMes->CRV = pTrunk->call[callIndex].CRV;
505 
506 		/* Send RESUME to network */
507 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
508 		if (ret != Q931E_NO_ERROR)
509 			return ret;
510 
511 		/* Start timer T318 */
512 		Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T318);
513 
514 		/* set state U17 */
515 		Q931SetState(pTrunk, callIndex, Q931_U17);
516 	} else {
517 		return Q931E_ILLEGAL_MESSAGE;
518 	}
519 	return ret;
520 }
521 
522 /*****************************************************************************
523 
524   Function:		Q931ProcResumeAckTE
525 
526 *****************************************************************************/
Q931ProcResumeAckTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)527 L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
528 {
529 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
530 	L3INT callIndex;
531 	L3INT ret = Q931E_NO_ERROR;
532 
533 	/* Find the call using CRV */
534 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
535 	if (ret != Q931E_NO_ERROR)
536 		return ret;
537 
538 	/* TODO chack against state table for illegal or unexpected message here */
539 
540 	/* TODO - Set correct timer here */
541 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
542 	if (iFrom ==4) {
543 		/* TODO Add proc here */
544 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
545 	}
546 	else if (iFrom == 2) {
547 		/* TODO Add proc here */
548 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
549 	}
550 	return ret;
551 }
552 
553 /*****************************************************************************
554 
555   Function:		Q931ProcResumeRejectTE
556 
557 *****************************************************************************/
Q931ProcResumeRejectTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)558 L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
559 {
560 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
561 	L3INT callIndex;
562 	L3INT ret = Q931E_NO_ERROR;
563 
564 	/* Find the call using CRV */
565 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
566 	if (ret != Q931E_NO_ERROR)
567 		return ret;
568 
569 	/* TODO chack against state table for illegal or unexpected message here */
570 
571 	/* TODO - Set correct timer here */
572 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
573 	if (iFrom ==4) {
574 		/* TODO Add proc here */
575 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
576 	}
577 	else if (iFrom == 2) {
578 		/* TODO Add proc here */
579 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
580 	}
581 	return ret;
582 }
583 
584 /*****************************************************************************
585 
586   Function:		Q931ProcSuspendTE
587 
588 *****************************************************************************/
Q931ProcSuspendTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)589 L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
590 {
591 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
592 	L3INT callIndex;
593 	L3INT ret = Q931E_NO_ERROR;
594 
595 	/* Find the call using CRV */
596 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
597 	if (ret != Q931E_NO_ERROR)
598 		return ret;
599 
600 	/* TODO chack against state table for illegal or unexpected message here */
601 
602 	/* TODO - Set correct timer here */
603 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
604 	if (iFrom ==4) {
605 		/* TODO Add proc here */
606 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
607 	}
608 	else if (iFrom == 2) {
609 		/* TODO Add proc here */
610 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
611 	}
612 	return ret;
613 }
614 
615 /*****************************************************************************
616 
617   Function:		Q931ProcSuspendAckTE
618 
619 *****************************************************************************/
Q931ProcSuspendAckTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)620 L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
621 {
622 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
623 	L3INT callIndex;
624 	L3INT ret = Q931E_NO_ERROR;
625 
626 	/* Find the call using CRV */
627 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
628 	if (ret != Q931E_NO_ERROR)
629 		return ret;
630 
631 	/* TODO chack against state table for illegal or unexpected message here */
632 
633 	/* TODO - Set correct timer here */
634 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
635 	if (iFrom ==4) {
636 		/* TODO Add proc here */
637 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
638 	}
639 	else if (iFrom == 2) {
640 		/* TODO Add proc here */
641 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
642 	}
643 	return ret;
644 }
645 
646 /*****************************************************************************
647 
648   Function:		Q931ProcSuspendRejectTE
649 
650 *****************************************************************************/
Q931ProcSuspendRejectTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)651 L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
652 {
653 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
654 	L3INT callIndex;
655 	L3INT ret = Q931E_NO_ERROR;
656 
657 	/* Find the call using CRV */
658 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
659 	if (ret != Q931E_NO_ERROR)
660 		return ret;
661 
662 	/* TODO chack against state table for illegal or unexpected message here */
663 
664 	/* TODO - Set correct timer here */
665 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
666 	if (iFrom ==4) {
667 		/* TODO Add proc here */
668 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
669 	}
670 	else if (iFrom == 2) {
671 		/* TODO Add proc here */
672 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
673 	}
674 	return ret;
675 }
676 
677 /*****************************************************************************
678 
679   Function:		Q931ProcInformationTE
680 
681 *****************************************************************************/
Q931ProcUserInformationTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)682 L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
683 {
684 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
685 	L3INT callIndex;
686 	L3INT ret = Q931E_NO_ERROR;
687 
688 	/* Find the call using CRV */
689 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
690 	if (ret != Q931E_NO_ERROR)
691 		return ret;
692 
693 	/* TODO chack against state table for illegal or unexpected message here */
694 
695 	/* TODO - Set correct timer here */
696 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
697 	if (iFrom ==4) {
698 		/* TODO Add proc here */
699 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
700 	}
701 	else if (iFrom == 2) {
702 		/* TODO Add proc here */
703 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
704 	}
705 	return ret;
706 }
707 
708 /*****************************************************************************
709 
710   Function:		Q931ProcDisconnectTE
711 
712 *****************************************************************************/
Q931ProcDisconnectTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)713 L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
714 {
715 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
716 	L3INT callIndex;
717 	L3INT ret = Q931E_NO_ERROR;
718 
719 	Q931Log(pTrunk, Q931_LOG_DEBUG, "Processing DISCONNECT message from %s for CRV: %d (%#hx)\n",
720 						 iFrom == 4 ? "Local" : "Remote", pMes->CRV, pMes->CRV);
721 
722 	/* Find the call using CRV */
723 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
724 	if (ret != Q931E_NO_ERROR)
725 		return ret;
726 
727 	/* TODO chack against state table for illegal or unexpected message here */
728 
729 	/* TODO - Set correct timer here */
730 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
731 	if (iFrom ==4) {
732 		/* TODO Add proc here */
733 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
734 	}
735 	else if (iFrom == 2) {
736 		/* TODO Add proc here */
737 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
738 	}
739 	return ret;
740 }
741 
742 /*****************************************************************************
743 
744   Function:		Q931ProcReleaseTE
745 
746 *****************************************************************************/
Q931ProcReleaseTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)747 L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
748 {
749 	Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
750 	L3INT callIndex;
751 	L3INT state = Q931GetCallState(pTrunk, pMes->CRV);
752 	L3INT ret = Q931E_NO_ERROR;
753 
754 	if (iFrom == 4) {
755 		/* TODO Add proc here */
756 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
757 	}
758 	else if (state == Q931_U0 && iFrom == 2) {
759 		Q931Tx34(pTrunk, buf, pMes->Size);
760 		ret = Q931ReleaseComplete(pTrunk, buf);
761 	} else {
762 		ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom);
763 	}
764 	if (pMes->CRV && iFrom == 2) {
765 		/* Find the call using CRV */
766 		if ((Q931FindCRV(pTrunk, pMes->CRV, &callIndex)) != Q931E_NO_ERROR)
767 			return ret;
768 		pTrunk->call[callIndex].InUse = 0;
769 	}
770 
771 	return ret;
772 }
773 
774 /*****************************************************************************
775 
776   Function:		Q931ProcReleaseCompleteTE
777 
778 *****************************************************************************/
Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)779 L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
780 {
781 	Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
782 	L3INT callIndex;
783 	L3INT ret = Q931E_NO_ERROR;
784 
785 	if (iFrom == 2) {
786 		/* TODO Add proc here */
787 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
788 	} else {
789 		if (pMes->CRV) {
790 			/* Find the call using CRV */
791 			ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
792 			if (ret != Q931E_NO_ERROR)
793 				return ret;
794 			pTrunk->call[callIndex].InUse = 0;
795 
796 			/* TODO: experimental, send RELEASE_COMPLETE message */
797 		        ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
798 		}
799 	}
800 	return ret;
801 }
802 
803 /*****************************************************************************
804 
805   Function:		Q931ProcRestartTE
806 
807 *****************************************************************************/
Q931ProcRestartTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)808 L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
809 {
810 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
811 	L3INT callIndex;
812 	L3INT ret = Q931E_NO_ERROR;
813 
814 	if (pMes->CRV) {
815 		/* Find the call using CRV */
816 		ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
817 		if (ret != Q931E_NO_ERROR)
818 			return ret;
819 
820 		/* TODO - Set correct timer here */
821 		Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
822 	}
823 
824 	/* TODO chack against state table for illegal or unexpected message here */
825 
826 	if (iFrom ==4) {
827 		/* TODO Add proc here */
828 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
829 	}
830 	else if (iFrom == 2) {
831 		/* TODO Add proc here */
832 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
833 
834 		if (pTrunk->autoRestartAck) {
835 			Q931AckRestart(pTrunk, buf);
836 		}
837 	}
838 	return ret;
839 }
840 
841 /*****************************************************************************
842 
843   Function:		Q931ProcRestartAckTE
844 
845 *****************************************************************************/
Q931ProcRestartAckTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)846 L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
847 {
848 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
849 	L3INT callIndex;
850 	L3INT ret = Q931E_NO_ERROR;
851 
852 	if (pMes->CRV) {
853 		/* Find the call using CRV */
854 		ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
855 		if (ret != Q931E_NO_ERROR)
856 			return ret;
857 		/* TODO - Set correct timer here */
858 		Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
859 	}
860 
861 	/* TODO chack against state table for illegal or unexpected message here */
862 
863 	if (iFrom ==4) {
864 		/* TODO Add proc here */
865 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
866 	}
867 	else if (iFrom == 2) {
868 		/* TODO Add proc here */
869 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
870 	}
871 	return ret;
872 }
873 
874 /*****************************************************************************
875 
876   Function:		Q931ProcCongestionControlTE
877 
878 *****************************************************************************/
Q931ProcCongestionControlTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)879 L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
880 {
881 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
882 	L3INT callIndex;
883 	L3INT ret = Q931E_NO_ERROR;
884 
885 	/* Find the call using CRV */
886 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
887 	if (ret != Q931E_NO_ERROR)
888 		return ret;
889 
890 	/* TODO chack against state table for illegal or unexpected message here */
891 
892 	/* TODO - Set correct timer here */
893 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
894 	if (iFrom ==4) {
895 		/* TODO Add proc here */
896 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
897 	}
898 	else if (iFrom == 2) {
899 		/* TODO Add proc here */
900 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
901 	}
902 	return ret;
903 }
904 
905 /*****************************************************************************
906 
907   Function:		Q931ProcInformationTE
908 
909 *****************************************************************************/
Q931ProcInformationTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)910 L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
911 {
912 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
913 	L3INT callIndex;
914 	L3INT ret = Q931E_NO_ERROR;
915 
916 	/* Find the call using CRV */
917 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
918 	if (ret != Q931E_NO_ERROR)
919 		return ret;
920 
921 	/* TODO chack against state table for illegal or unexpected message here */
922 
923 	/* TODO - Set correct timer here */
924 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
925 	if (iFrom ==4) {
926 		/* TODO Add proc here */
927 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
928 	}
929 	else if (iFrom == 2) {
930 		/* TODO Add proc here */
931 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
932 	}
933 	return ret;
934 }
935 
936 /*****************************************************************************
937 
938   Function:		Q931ProcNotifyTE
939 
940 *****************************************************************************/
Q931ProcNotifyTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)941 L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
942 {
943 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
944 	L3INT callIndex;
945 	L3INT ret = Q931E_NO_ERROR;
946 
947 	/* Find the call using CRV */
948 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
949 	if (ret != Q931E_NO_ERROR)
950 		return ret;
951 
952 	/* TODO chack against state table for illegal or unexpected message here */
953 
954 	/* TODO - Set correct timer here */
955 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
956 	if (iFrom ==4) {
957 		/* TODO Add proc here */
958 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
959 	}
960 	else if (iFrom == 2) {
961 		/* TODO Add proc here */
962 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
963 	}
964 	return ret;
965 }
966 
967 /*****************************************************************************
968 
969   Function:		Q931ProcStatusTE
970 
971 *****************************************************************************/
Q931ProcStatusTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)972 L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
973 {
974 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
975 	L3INT callIndex;
976 	L3INT ret = Q931E_NO_ERROR;
977 
978 	/* Find the call using CRV */
979 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
980 	if (ret != Q931E_NO_ERROR)
981 		return ret;
982 
983 	/* TODO chack against state table for illegal or unexpected message here */
984 
985 	/* TODO - Set correct timer here */
986 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
987 	if (iFrom ==4) {
988 		/* TODO Add proc here */
989 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
990 	}
991 	else if (iFrom == 2) {
992 		/* TODO Add proc here */
993 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
994 	}
995 	return ret;
996 }
997 
998 /*****************************************************************************
999 
1000   Function:		Q931ProcStatusEnquiryTE
1001 
1002 *****************************************************************************/
Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1003 L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1004 {
1005 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1006 	L3INT callIndex;
1007 	L3INT ret = Q931E_NO_ERROR;
1008 
1009 	/* Find the call using CRV */
1010 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1011 	if (ret != Q931E_NO_ERROR)
1012 		return ret;
1013 
1014 	/* TODO chack against state table for illegal or unexpected message here */
1015 
1016 	/* TODO - Set correct timer here */
1017 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1018 	if (iFrom ==4) {
1019 		/* TODO Add proc here */
1020 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1021 	}
1022 	else if (iFrom == 2) {
1023 		/* TODO Add proc here */
1024 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1025 	}
1026 	return ret;
1027 }
1028 
1029 /*****************************************************************************
1030 
1031   Function:		Q931ProcSegmentTE
1032 
1033 *****************************************************************************/
Q931ProcSegmentTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1034 L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1035 {
1036 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1037 	L3INT callIndex;
1038 	L3INT ret = Q931E_NO_ERROR;
1039 
1040 	/* Find the call using CRV */
1041 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1042 	if (ret != Q931E_NO_ERROR)
1043 		return ret;
1044 
1045 	/* TODO chack against state table for illegal or unexpected message here */
1046 
1047 	/* TODO - Set correct timer here */
1048 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1049 	if (iFrom ==4) {
1050 		/* TODO Add proc here */
1051 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1052 	}
1053 	else if (iFrom == 2) {
1054 		/* TODO Add proc here */
1055 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1056 	}
1057 	return ret;
1058 }
1059 
1060 /****************************************************************************/
1061 /******************* Q.932 - Supplementary Services *************************/
1062 /****************************************************************************/
1063 
1064 /*****************************************************************************
1065 
1066   Function:		Q932ProcRetrieveTE
1067 
1068 *****************************************************************************/
Q932ProcFacilityTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1069 L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1070 {
1071 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1072 	L3INT callIndex;
1073 	L3INT ret = Q931E_NO_ERROR;
1074 
1075 	/* Find the call using CRV */
1076 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1077 	if (ret != Q931E_NO_ERROR)
1078 		return ret;
1079 
1080 	/* TODO chack against state table for illegal or unexpected message here */
1081 
1082 	/* TODO - Set correct timer here */
1083 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1084 	if (iFrom ==4) {
1085 		/* TODO Add proc here */
1086 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1087 	}
1088 	else if (iFrom == 2) {
1089 		/* TODO Add proc here */
1090 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1091 	}
1092 	return ret;
1093 }
1094 
1095 /*****************************************************************************
1096 
1097   Function:		Q932ProcRetrieveTE
1098 
1099 *****************************************************************************/
Q932ProcHoldTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1100 L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1101 {
1102 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1103 	L3INT callIndex;
1104 	L3INT ret = Q931E_NO_ERROR;
1105 
1106 	/* Find the call using CRV */
1107 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1108 	if (ret != Q931E_NO_ERROR)
1109 		return ret;
1110 
1111 	/* TODO chack against state table for illegal or unexpected message here */
1112 
1113 	/* TODO - Set correct timer here */
1114 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1115 	if (iFrom ==4) {
1116 		/* TODO Add proc here */
1117 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1118 	}
1119 	else if (iFrom == 2) {
1120 		/* TODO Add proc here */
1121 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1122 	}
1123 	return ret;
1124 }
1125 
1126 /*****************************************************************************
1127 
1128   Function:		Q932ProcRetrieveTE
1129 
1130 *****************************************************************************/
Q932ProcHoldAckTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1131 L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1132 {
1133 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1134 	L3INT callIndex;
1135 	L3INT ret = Q931E_NO_ERROR;
1136 
1137 	/* Find the call using CRV */
1138 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1139 	if (ret != Q931E_NO_ERROR)
1140 		return ret;
1141 
1142 	/* TODO chack against state table for illegal or unexpected message here */
1143 
1144 	/* TODO - Set correct timer here */
1145 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1146 	if (iFrom ==4) {
1147 		/* TODO Add proc here */
1148 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1149 	}
1150 	else if (iFrom == 2) {
1151 		/* TODO Add proc here */
1152 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1153 	}
1154 	return ret;
1155 }
1156 
1157 /*****************************************************************************
1158 
1159   Function:		Q932ProcRetrieveTE
1160 
1161 *****************************************************************************/
Q932ProcHoldRejectTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1162 L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1163 {
1164 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1165 	L3INT callIndex;
1166 	L3INT ret = Q931E_NO_ERROR;
1167 
1168 	/* Find the call using CRV */
1169 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1170 	if (ret != Q931E_NO_ERROR)
1171 		return ret;
1172 
1173 	/* TODO chack against state table for illegal or unexpected message here */
1174 
1175 	/* TODO - Set correct timer here */
1176 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1177 	if (iFrom ==4) {
1178 		/* TODO Add proc here */
1179 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1180 	}
1181 	else if (iFrom == 2) {
1182 		/* TODO Add proc here */
1183 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1184 	}
1185 	return ret;
1186 }
1187 
1188 /*****************************************************************************
1189 
1190   Function:		Q932ProcRegisterTE
1191 
1192 *****************************************************************************/
Q932ProcRegisterTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1193 L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1194 {
1195 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1196 	L3INT callIndex;
1197 	L3INT ret = Q931E_NO_ERROR;
1198 
1199 	/* Find the call using CRV */
1200 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1201 	if (ret != Q931E_NO_ERROR)
1202 		return ret;
1203 
1204 	/* TODO chack against state table for illegal or unexpected message here */
1205 
1206 	/* TODO - Set correct timer here */
1207 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1208 	if (iFrom ==4) {
1209 		/* TODO Add proc here */
1210 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1211 	}
1212 	else if (iFrom == 2) {
1213 		/* TODO Add proc here */
1214 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1215 	}
1216 	return ret;
1217 }
1218 
1219 /*****************************************************************************
1220 
1221   Function:		Q932ProcRetrieveTE
1222 
1223 *****************************************************************************/
Q932ProcRetrieveTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1224 L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1225 {
1226 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1227 	L3INT callIndex;
1228 	L3INT ret = Q931E_NO_ERROR;
1229 
1230 	/* Find the call using CRV */
1231 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1232 	if (ret != Q931E_NO_ERROR)
1233 		return ret;
1234 
1235 	/* TODO chack against state table for illegal or unexpected message here */
1236 
1237 	/* TODO - Set correct timer here */
1238 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1239 	if (iFrom ==4) {
1240 		/* TODO Add proc here */
1241 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1242 	}
1243 	else if (iFrom == 2) {
1244 		/* TODO Add proc here */
1245 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1246 	}
1247 	return ret;
1248 }
1249 
1250 /*****************************************************************************
1251 
1252   Function:		Q931ProcRetrieveAckTE
1253 
1254 *****************************************************************************/
Q932ProcRetrieveAckTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1255 L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1256 {
1257 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1258 	L3INT callIndex;
1259 	L3INT ret = Q931E_NO_ERROR;
1260 
1261 	/* Find the call using CRV */
1262 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1263 	if (ret != Q931E_NO_ERROR)
1264 		return ret;
1265 
1266 	/* TODO chack against state table for illegal or unexpected message here */
1267 
1268 	/* TODO - Set correct timer here */
1269 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1270 	if (iFrom ==4) {
1271 		/* TODO Add proc here */
1272 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1273 	}
1274 	else if (iFrom == 2) {
1275 		/* TODO Add proc here */
1276 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1277 	}
1278 	return ret;
1279 }
1280 
1281 /*****************************************************************************
1282 
1283   Function:		Q931ProcRetrieveRejectTE
1284 
1285 *****************************************************************************/
Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t * pTrunk,L3UCHAR * buf,L3INT iFrom)1286 L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
1287 {
1288 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
1289 	L3INT callIndex;
1290 	L3INT ret = Q931E_NO_ERROR;
1291 
1292 	/* Find the call using CRV */
1293 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
1294 	if (ret != Q931E_NO_ERROR)
1295 		return ret;
1296 
1297 	/* TODO chack against state table for illegal or unexpected message here */
1298 
1299 	/* TODO - Set correct timer here */
1300 	Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
1301 	if (iFrom ==4) {
1302 		/* TODO Add proc here */
1303 		ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
1304 	}
1305 	else if (iFrom == 2) {
1306 		/* TODO Add proc here */
1307 		ret = Q931Tx34(pTrunk, buf, pMes->Size);
1308 	}
1309 	return ret;
1310 }
1311