1 /*
2  * Copyright (c) 2009, Konrad Hammel <konrad@sangoma.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the original author; nor the names of any contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /* INCLUDE ********************************************************************/
35 #include "ftmod_sangoma_ss7_main.h"
36 /******************************************************************************/
37 
38 /* DEFINES ********************************************************************/
39 /******************************************************************************/
40 
41 /* GLOBALS ********************************************************************/
42 /******************************************************************************/
43 
44 /* PROTOTYPES *****************************************************************/
45 void sngss7_sta_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
46 void sngss7_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt);
47 void sngss7_con_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt);
48 void sngss7_con_sta(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiCnStEvnt *siCnStEvnt, uint8_t evntType);
49 void sngss7_rel_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt);
50 void sngss7_rel_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt);
51 void sngss7_dat_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiInfoEvnt *siInfoEvnt);
52 void sngss7_fac_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt);
53 void sngss7_fac_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt);
54 void sngss7_umsg_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit);
55 void sngss7_resm_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiResmEvnt *siResmEvnt);
56 void sngss7_susp_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiSuspEvnt *siSuspEvnt);
57 void sngss7_ssp_sta_cfm(uint32_t infId);
58 /******************************************************************************/
59 
60 /* FUNCTIONS ******************************************************************/
sngss7_con_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiConEvnt * siConEvnt)61 void sngss7_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt)
62 {
63 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
64 
65 	sngss7_chan_data_t	*sngss7_info = NULL;
66 	ftdm_channel_t		*ftdmchan = NULL;
67 	sngss7_event_data_t	*sngss7_event = NULL;
68 
69 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
70 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
71 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
72 		return;
73 	}
74 
75 	/* get the ftdmchan and ss7_chan_data from the circuit */
76 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
77 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
78 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
79 		return;
80 	}
81 
82 	/* initalize the sngss7_event */
83 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
84 
85 	if (sngss7_event == NULL) {
86 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
87 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
88 		return;
89 	}
90 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
91 
92 	/* fill in the sngss7_event struct */
93 	sngss7_event->spInstId	= spInstId;
94 	sngss7_event->suInstId	= suInstId;
95 	sngss7_event->circuit	= circuit;
96 	sngss7_event->event_id	= SNGSS7_CON_IND_EVENT;
97 	memcpy(&sngss7_event->event.siConEvnt, siConEvnt, sizeof(*siConEvnt));
98 
99 	/* enqueue this event */
100 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
101 
102 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
103 }
104 
105 /******************************************************************************/
sngss7_con_cfm(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiConEvnt * siConEvnt)106 void sngss7_con_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt)
107 {
108 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
109 
110 	sngss7_chan_data_t	*sngss7_info = NULL;
111 	ftdm_channel_t		*ftdmchan = NULL;
112 	sngss7_event_data_t	*sngss7_event = NULL;
113 
114 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
115 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
116 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
117 		return;
118 	}
119 
120 	/* get the ftdmchan and ss7_chan_data from the circuit */
121 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
122 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
123 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
124 		return;
125 	}
126 
127 	/* initalize the sngss7_event */
128 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
129 	if (sngss7_event == NULL) {
130 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
131 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
132 		return;
133 	}
134 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
135 
136 	/* fill in the sngss7_event struct */
137 	sngss7_event->spInstId	= spInstId;
138 	sngss7_event->suInstId	= suInstId;
139 	sngss7_event->circuit	= circuit;
140 	sngss7_event->event_id	= SNGSS7_CON_CFM_EVENT;
141 	memcpy(&sngss7_event->event.siConEvnt, siConEvnt, sizeof(*siConEvnt));
142 
143 	/* enqueue this event */
144 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
145 
146 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
147 }
148 
149 /******************************************************************************/
sngss7_con_sta(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiCnStEvnt * siCnStEvnt,uint8_t evntType)150 void sngss7_con_sta(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiCnStEvnt *siCnStEvnt, uint8_t evntType)
151 {
152 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
153 
154 	sngss7_chan_data_t	*sngss7_info = NULL;
155 	ftdm_channel_t		*ftdmchan = NULL;
156 	sngss7_event_data_t	*sngss7_event = NULL;
157 
158 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
159 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
160 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
161 		return;
162 	}
163 
164 	/* get the ftdmchan and ss7_chan_data from the circuit */
165 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
166 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
167 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
168 		return;
169 	}
170 
171 	/* initalize the sngss7_event */
172 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
173 	if (sngss7_event == NULL) {
174 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
175 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
176 		return;
177 	}
178 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
179 
180 	/* fill in the sngss7_event struct */
181 	sngss7_event->spInstId	= spInstId;
182 	sngss7_event->suInstId	= suInstId;
183 	sngss7_event->circuit	= circuit;
184 	sngss7_event->evntType	= evntType;
185 	sngss7_event->event_id	= SNGSS7_CON_STA_EVENT;
186 	memcpy(&sngss7_event->event.siCnStEvnt, siCnStEvnt, sizeof(*siCnStEvnt));
187 
188 	/* enqueue this event */
189 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
190 
191 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
192 }
193 
194 /******************************************************************************/
sngss7_rel_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiRelEvnt * siRelEvnt)195 void sngss7_rel_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt)
196 {
197 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
198 
199 	sngss7_chan_data_t	*sngss7_info = NULL;
200 	ftdm_channel_t		*ftdmchan = NULL;
201 	sngss7_event_data_t	*sngss7_event = NULL;
202 
203 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
204 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
205 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
206 		return;
207 	}
208 
209 	/* get the ftdmchan and ss7_chan_data from the circuit */
210 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
211 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
212 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
213 		return;
214 	}
215 
216 	/* initalize the sngss7_event */
217 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
218 	if (sngss7_event == NULL) {
219 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
220 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
221 		return;
222 	}
223 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
224 
225 	/* fill in the sngss7_event struct */
226 	sngss7_event->spInstId	= spInstId;
227 	sngss7_event->suInstId	= suInstId;
228 	sngss7_event->circuit	= circuit;
229 	sngss7_event->event_id	= SNGSS7_REL_IND_EVENT;
230 	memcpy(&sngss7_event->event.siRelEvnt, siRelEvnt, sizeof(*siRelEvnt));
231 
232 	/* enqueue this event */
233 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
234 
235 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
236 }
237 
238 /******************************************************************************/
sngss7_rel_cfm(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiRelEvnt * siRelEvnt)239 void sngss7_rel_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt)
240 {
241 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
242 
243 	sngss7_chan_data_t	*sngss7_info = NULL;
244 	ftdm_channel_t		*ftdmchan = NULL;
245 	sngss7_event_data_t	*sngss7_event = NULL;
246 
247 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
248 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
249 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
250 		return;
251 	}
252 
253 	/* get the ftdmchan and ss7_chan_data from the circuit */
254 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
255 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
256 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
257 		return;
258 	}
259 
260 	/* initalize the sngss7_event */
261 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
262 	if (sngss7_event == NULL) {
263 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
264 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
265 		return;
266 	}
267 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
268 
269 	/* fill in the sngss7_event struct */
270 	sngss7_event->spInstId	= spInstId;
271 	sngss7_event->suInstId	= suInstId;
272 	sngss7_event->circuit	= circuit;
273 	sngss7_event->event_id	= SNGSS7_REL_CFM_EVENT;
274 	memcpy(&sngss7_event->event.siRelEvnt, siRelEvnt, sizeof(*siRelEvnt));
275 
276 	/* enqueue this event */
277 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
278 
279 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
280 }
281 
282 /******************************************************************************/
sngss7_dat_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiInfoEvnt * siInfoEvnt)283 void sngss7_dat_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiInfoEvnt *siInfoEvnt)
284 {
285 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
286 
287 	sngss7_chan_data_t	*sngss7_info = NULL;
288 	ftdm_channel_t		*ftdmchan = NULL;
289 	sngss7_event_data_t	*sngss7_event = NULL;
290 
291 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
292 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
293 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
294 		return;
295 	}
296 
297 	/* get the ftdmchan and ss7_chan_data from the circuit */
298 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
299 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
300 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
301 		return;
302 	}
303 
304 	/* initalize the sngss7_event */
305 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
306 	if (sngss7_event == NULL) {
307 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
308 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
309 		return;
310 	}
311 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
312 
313 	/* fill in the sngss7_event struct */
314 	sngss7_event->spInstId	= spInstId;
315 	sngss7_event->suInstId	= suInstId;
316 	sngss7_event->circuit	= circuit;
317 	sngss7_event->event_id	= SNGSS7_DAT_IND_EVENT;
318 	memcpy(&sngss7_event->event.siInfoEvnt, siInfoEvnt, sizeof(*siInfoEvnt));
319 
320 	/* enqueue this event */
321 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
322 
323 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
324 }
325 
326 /******************************************************************************/
sngss7_fac_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,uint8_t evntType,SiFacEvnt * siFacEvnt)327 void sngss7_fac_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt)
328 {
329 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
330 
331 	sngss7_chan_data_t	*sngss7_info = NULL;
332 	ftdm_channel_t		*ftdmchan = NULL;
333 	sngss7_event_data_t	*sngss7_event = NULL;
334 
335 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
336 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
337 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
338 		return;
339 	}
340 
341 	/* get the ftdmchan and ss7_chan_data from the circuit */
342 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
343 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
344 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
345 		return;
346 	}
347 
348 	/* initalize the sngss7_event */
349 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
350 	if (sngss7_event == NULL) {
351 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
352 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
353 		return;
354 	}
355 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
356 
357 	/* fill in the sngss7_event struct */
358 	sngss7_event->spInstId	= spInstId;
359 	sngss7_event->suInstId	= suInstId;
360 	sngss7_event->circuit	= circuit;
361 	sngss7_event->evntType	= evntType;
362 	sngss7_event->event_id	= SNGSS7_FAC_IND_EVENT;
363 	memcpy(&sngss7_event->event.siFacEvnt, siFacEvnt, sizeof(*siFacEvnt));
364 
365 	/* enqueue this event */
366 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
367 
368 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
369 }
370 
371 /******************************************************************************/
sngss7_fac_cfm(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,uint8_t evntType,SiFacEvnt * siFacEvnt)372 void sngss7_fac_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt)
373 {
374 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
375 
376 	sngss7_chan_data_t	*sngss7_info = NULL;
377 	ftdm_channel_t		*ftdmchan = NULL;
378 	sngss7_event_data_t	*sngss7_event = NULL;
379 
380 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
381 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
382 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
383 		return;
384 	}
385 
386 	/* get the ftdmchan and ss7_chan_data from the circuit */
387 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
388 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
389 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
390 		return;
391 	}
392 
393 	/* initalize the sngss7_event */
394 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
395 	if (sngss7_event == NULL) {
396 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
397 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
398 		return;
399 	}
400 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
401 
402 	/* fill in the sngss7_event struct */
403 	sngss7_event->spInstId	= spInstId;
404 	sngss7_event->suInstId	= suInstId;
405 	sngss7_event->circuit	= circuit;
406 	sngss7_event->evntType	= evntType;
407 	sngss7_event->event_id	= SNGSS7_FAC_CFM_EVENT;
408 	memcpy(&sngss7_event->event.siFacEvnt, siFacEvnt, sizeof(*siFacEvnt));
409 
410 	/* enqueue this event */
411 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
412 
413 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
414 }
415 
416 /******************************************************************************/
sngss7_umsg_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit)417 void sngss7_umsg_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit)
418 {
419 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
420 
421 	sngss7_chan_data_t	*sngss7_info = NULL;
422 	ftdm_channel_t		*ftdmchan = NULL;
423 	sngss7_event_data_t	*sngss7_event = NULL;
424 
425 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
426 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
427 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
428 		return;
429 	}
430 
431 	/* get the ftdmchan and ss7_chan_data from the circuit */
432 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
433 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
434 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
435 		return;
436 	}
437 
438 	/* initalize the sngss7_event */
439 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
440 	if (sngss7_event == NULL) {
441 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
442 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
443 		return;
444 	}
445 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
446 
447 	/* fill in the sngss7_event struct */
448 	sngss7_event->spInstId	= spInstId;
449 	sngss7_event->suInstId	= suInstId;
450 	sngss7_event->circuit	= circuit;
451 	sngss7_event->event_id	= SNGSS7_UMSG_IND_EVENT;
452 
453 	/* enqueue this event */
454 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
455 
456 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
457 
458 }
459 /* GENERAL STATUS *************************************************************/
sngss7_sta_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,uint8_t globalFlg,uint8_t evntType,SiStaEvnt * siStaEvnt)460 void sngss7_sta_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
461 {
462 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
463 
464 	sngss7_chan_data_t	*sngss7_info = NULL;
465 	ftdm_channel_t		*ftdmchan = NULL;
466 	sngss7_event_data_t	*sngss7_event = NULL;
467 	uint32_t			intfId;
468 	int 				x;
469 
470 
471 
472 	/* check if the eventType is a pause/resume */
473 	switch (evntType) {
474 	/**************************************************************************/
475 	case (SIT_STA_PAUSEIND):
476 	case (SIT_STA_RESUMEIND):
477 		/* the circuit may or may not be on the local system so we have to find
478 		 * circuit with the same intfId.  The circuit specified might also be
479 		 * a non-voice cic so we also need to find the first voice cic on this
480 		 * system with the same intfId.
481 		 */
482 		intfId = g_ftdm_sngss7_data.cfg.isupCkt[circuit].infId;
483 
484 		if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
485 			SS7_DEBUG("Rx %s on circuit that is not a voice CIC (%d) finding a new circuit\n",
486 						DECODE_LCC_EVENT(evntType),
487 						g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic);
488 		}
489 
490 		x = (g_ftdm_sngss7_data.cfg.procId * MAX_CIC_MAP_LENGTH) + 1;
491 		while ((g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) &&
492 			   (g_ftdm_sngss7_data.cfg.isupCkt[x].id < ((g_ftdm_sngss7_data.cfg.procId + 1) * MAX_CIC_MAP_LENGTH))) {
493 			/**********************************************************************/
494 			/* confirm this is a voice channel and not a gap/sig (no ftdmchan there) */
495 			if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == SNG_CKT_VOICE) {
496 				/* compare the intfIds */
497 				if (g_ftdm_sngss7_data.cfg.isupCkt[x].infId == intfId) {
498 					/* we have a match, setup the pointers to the correct values */
499 					circuit = x;
500 
501 					/* confirm that the circuit is active on our side otherwise move to the next circuit */
502 					if (!sngss7_test_flag(&g_ftdm_sngss7_data.cfg.isupCkt[circuit], SNGSS7_ACTIVE)) {
503 						SS7_DEBUG("[CIC:%d]Rx %s but circuit is not active yet, skipping!\n",
504 									g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic,
505 									DECODE_LCC_EVENT(evntType));
506 						x++;
507 						continue;
508 					}
509 
510 					if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
511 						SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
512 						SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
513 						return;
514 					}
515 
516 					/* bounce out of the loop */
517 					break;
518 				}
519 			}
520 
521 			x++;
522 			/**********************************************************************/
523 		}
524 
525 		/* check if we found any circuits that are on the intfId, drop the message
526 		 * if none are found */
527 		if (!ftdmchan) {
528 			SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
529 			return;
530 		}
531 
532 		break;
533 	/**************************************************************************/
534 	default:
535 		if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
536 			ftdm_log(FTDM_LOG_DEBUG, "Rx %s on circuit that is not a voice CIC (%d) (circuit:%d)\n",
537 						DECODE_LCC_EVENT(evntType), g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic, circuit);
538 			SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
539 			return;
540 		}
541 
542 		/* get the ftdmchan and ss7_chan_data from the circuit */
543 		if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
544 			SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
545 			SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
546 			return;
547 		}
548 		break;
549 	/**************************************************************************/
550 	} /* switch (evntType) */
551 
552 	/* initalize the sngss7_event */
553 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
554 	if (sngss7_event == NULL) {
555 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
556 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
557 		return;
558 	}
559 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
560 
561 	/* fill in the sngss7_event struct */
562 	sngss7_event->spInstId	= spInstId;
563 	sngss7_event->suInstId	= suInstId;
564 	sngss7_event->circuit	= circuit;
565 	sngss7_event->globalFlg	= globalFlg;
566 	sngss7_event->evntType	= evntType;
567 	sngss7_event->event_id	= SNGSS7_STA_IND_EVENT;
568 	if (siStaEvnt != NULL) {
569 		memcpy(&sngss7_event->event.siStaEvnt, siStaEvnt, sizeof(*siStaEvnt));
570 	}
571 
572 	/* enqueue this event */
573 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
574 }
575 
576 /******************************************************************************/
sngss7_susp_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiSuspEvnt * siSuspEvnt)577 void sngss7_susp_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiSuspEvnt *siSuspEvnt)
578 {
579 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
580 
581 	sngss7_chan_data_t	*sngss7_info = NULL;
582 	ftdm_channel_t		*ftdmchan = NULL;
583 	sngss7_event_data_t	*sngss7_event = NULL;
584 
585 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
586 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
587 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
588 		return;
589 	}
590 
591 	/* get the ftdmchan and ss7_chan_data from the circuit */
592 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
593 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
594 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
595 		return;
596 	}
597 
598 	/* initalize the sngss7_event */
599 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
600 	if (sngss7_event == NULL) {
601 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
602 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
603 		return;
604 	}
605 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
606 
607 	/* fill in the sngss7_event struct */
608 	sngss7_event->spInstId	= spInstId;
609 	sngss7_event->suInstId	= suInstId;
610 	sngss7_event->circuit	= circuit;
611 	sngss7_event->event_id	= SNGSS7_SUSP_IND_EVENT;
612 	if (siSuspEvnt != NULL) {
613 		memcpy(&sngss7_event->event.siSuspEvnt, siSuspEvnt, sizeof(*siSuspEvnt));
614 	}
615 
616 	/* enqueue this event */
617 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
618 
619 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
620 
621 }
622 
623 /******************************************************************************/
sngss7_resm_ind(uint32_t suInstId,uint32_t spInstId,uint32_t circuit,SiResmEvnt * siResmEvnt)624 void sngss7_resm_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiResmEvnt *siResmEvnt)
625 {
626 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
627 
628 	sngss7_chan_data_t	*sngss7_info = NULL;
629 	ftdm_channel_t		*ftdmchan = NULL;
630 	sngss7_event_data_t	*sngss7_event = NULL;
631 
632 	if (g_ftdm_sngss7_data.cfg.isupCkt[circuit].type != SNG_CKT_VOICE) {
633 		SS7_ERROR("Rx sig event on circuit that is not a voice CIC (%d)\n", circuit);
634 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
635 		return;
636 	}
637 
638 	/* get the ftdmchan and ss7_chan_data from the circuit */
639 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
640 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
641 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
642 		return;
643 	}
644 
645 	/* initalize the sngss7_event */
646 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
647 	if (sngss7_event == NULL) {
648 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
649 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
650 		return;
651 	}
652 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
653 
654 	/* fill in the sngss7_event struct */
655 	sngss7_event->spInstId	= spInstId;
656 	sngss7_event->suInstId	= suInstId;
657 	sngss7_event->circuit	= circuit;
658 	sngss7_event->event_id	= SNGSS7_RESM_IND_EVENT;
659 	if (siResmEvnt != NULL) {
660 		memcpy(&sngss7_event->event.siResmEvnt, siResmEvnt, sizeof(*siResmEvnt));
661 	}
662 
663 	/* enqueue this event */
664 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
665 
666 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
667 
668 }
669 
670 /******************************************************************************/
sngss7_ssp_sta_cfm(uint32_t infId)671 void sngss7_ssp_sta_cfm(uint32_t infId)
672 {
673 	SS7_FUNC_TRACE_ENTER(__FTDM_FUNC__);
674 #if 0
675 	sngss7_chan_data_t	*sngss7_info = NULL;
676 	ftdm_channel_t		*ftdmchan = NULL;
677 	sngss7_event_data_t	*sngss7_event = NULL;
678 
679 	/* get the ftdmchan and ss7_chan_data from the circuit */
680 	if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
681 		SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
682 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
683 		return;
684 	}
685 
686 	/* initalize the sngss7_event */
687 	sngss7_event = ftdm_malloc(sizeof(*sngss7_event));
688 	if (sngss7_event == NULL) {
689 		SS7_ERROR("Failed to allocate memory for sngss7_event!\n");
690 		SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
691 		return;
692 	}
693 	memset(sngss7_event, 0x0, sizeof(*sngss7_event));
694 
695 	/* fill in the sngss7_event struct */
696 	sngss7_event->spInstId	= spInstId;
697 	sngss7_event->suInstId	= suInstId;
698 	sngss7_event->circuit	= circuit;
699 	sngss7_event->event_id	= SNGSS7_RESM_IND_EVENT;
700 	if (siSuspEvnt != NULL) {
701 		memcpy(&sngss7_event->event.siResmEvnt, siResmEvnt, sizeof(*siResmEvnt));
702 	}
703 
704 	/* enqueue this event */
705 	ftdm_queue_enqueue(((sngss7_span_data_t*)sngss7_info->ftdmchan->span->signal_data)->event_queue, sngss7_event);
706 #endif
707 	SS7_FUNC_TRACE_EXIT(__FTDM_FUNC__);
708 
709 }
710 /******************************************************************************/
711 /* For Emacs:
712  * Local Variables:
713  * mode:c
714  * indent-tabs-mode:t
715  * tab-width:4
716  * c-basic-offset:4
717  * End:
718  * For VIM:
719  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
720  */
721 /******************************************************************************/
722 
723