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 int ft_to_sngss7_activate_all(void);
46 
47 static int ftmod_ss7_enable_isap(int suId);
48 static int ftmod_ss7_enable_nsap(int suId);
49 static int ftmod_ss7_enable_mtpLinkSet(int lnkSetId);
50 
51 
52 /******************************************************************************/
53 
54 /* FUNCTIONS ******************************************************************/
ft_to_sngss7_activate_all(void)55 int ft_to_sngss7_activate_all(void)
56 {
57 	int x;
58 
59 	x = 1;
60 	while (x < (MAX_ISAPS)) {
61 		/* check if this link has already been actived */
62 		if ((g_ftdm_sngss7_data.cfg.isap[x].id != 0) &&
63 				(!(g_ftdm_sngss7_data.cfg.isap[x].flags & SNGSS7_ACTIVE))) {
64 
65 			if (ftmod_ss7_enable_isap(x)) {
66 				SS7_CRITICAL("ISAP %d Enable: NOT OK\n", x);
67 				return 1;
68 			} else {
69 				SS7_INFO("ISAP %d Enable: OK\n", x);
70 			}
71 
72 			/* set the SNGSS7_ACTIVE flag */
73 			g_ftdm_sngss7_data.cfg.isap[x].flags |= SNGSS7_ACTIVE;
74 		} /* if !SNGSS7_ACTIVE */
75 
76 		x++;
77 	} /* while (x < (MAX_ISAPS)) */
78 
79 	if(SNG_SS7_OPR_MODE_M2UA_SG != g_ftdm_operating_mode){
80 	x = 1;
81 	while (x < (MAX_NSAPS)) {
82 		/* check if this link has already been actived */
83 		if ((g_ftdm_sngss7_data.cfg.nsap[x].id != 0) &&
84 				(!(g_ftdm_sngss7_data.cfg.nsap[x].flags & SNGSS7_ACTIVE))) {
85 
86 			if (ftmod_ss7_enable_nsap(x)) {
87 				SS7_CRITICAL("NSAP %d Enable: NOT OK\n", x);
88 				return 1;
89 			} else {
90 				SS7_INFO("NSAP %d Enable: OK\n", x);
91 			}
92 
93 			/* set the SNGSS7_ACTIVE flag */
94 			g_ftdm_sngss7_data.cfg.nsap[x].flags |= SNGSS7_ACTIVE;
95 		} /* if !SNGSS7_ACTIVE */
96 
97 		x++;
98 	} /* while (x < (MAX_NSAPS)) */
99 
100 		if (g_ftdm_sngss7_data.cfg.mtpRoute[1].id != 0) {
101 			x = 1;
102 			while (x < (MAX_MTP_LINKSETS+1)) {
103 				/* check if this link has already been actived */
104 				if ((g_ftdm_sngss7_data.cfg.mtpLinkSet[x].id != 0) &&
105 						(!(g_ftdm_sngss7_data.cfg.mtpLinkSet[x].flags & SNGSS7_ACTIVE))) {
106 
107 					if (ftmod_ss7_enable_mtpLinkSet(x)) {
108 						SS7_CRITICAL("LinkSet \"%s\" Enable: NOT OK\n", g_ftdm_sngss7_data.cfg.mtpLinkSet[x].name);
109 						return 1;
110 					} else {
111 						SS7_INFO("LinkSet \"%s\" Enable: OK\n", g_ftdm_sngss7_data.cfg.mtpLinkSet[x].name);
112 					}
113 
114 					/* set the SNGSS7_ACTIVE flag */
115 					g_ftdm_sngss7_data.cfg.mtpLinkSet[x].flags |= SNGSS7_ACTIVE;
116 				} /* if !SNGSS7_ACTIVE */
117 
118 				x++;
119 			} /* while (x < (MAX_MTP_LINKSETS+1)) */
120 		}
121 	}
122 
123 	if(SNG_SS7_OPR_MODE_M2UA_SG == g_ftdm_operating_mode){
124 		return ftmod_ss7_m2ua_start();
125 	}
126 
127 	return 0;
128 }
129 
130 /******************************************************************************/
ftmod_ss7_enable_isap(int suId)131 static int ftmod_ss7_enable_isap(int suId)
132 {
133 	CcMngmt cntrl;
134 	Pst pst;
135 
136 	/* initalize the post structure */
137 	smPstInit(&pst);
138 
139 	/* insert the destination Entity */
140 	pst.dstEnt = ENTCC;
141 
142 	/* initalize the control structure */
143 	memset(&cntrl, 0x0, sizeof(CcMngmt));
144 
145 	/* initalize the control header */
146 	smHdrInit(&cntrl.hdr);
147 
148 	cntrl.hdr.msgType			= TCNTRL;		/* this is a control request */
149 	cntrl.hdr.entId.ent			= ENTCC;
150 	cntrl.hdr.entId.inst		= S_INST;
151 	cntrl.hdr.elmId.elmnt		= STISAP;
152 
153 	cntrl.hdr.elmId.elmntInst1	= suId;			/* this is the SAP to bind */
154 
155 	cntrl.t.cntrl.action		= ABND_ENA;		/* bind and activate */
156 	cntrl.t.cntrl.subAction		= SAELMNT;		/* specificed element */
157 
158 	return (sng_cntrl_cc(&pst, &cntrl));
159 }
160 
161 /******************************************************************************/
ftmod_ss7_enable_nsap(int suId)162 static int ftmod_ss7_enable_nsap(int suId)
163 {
164 	SiMngmt cntrl;
165 	Pst pst;
166 
167 	/* initalize the post structure */
168 	smPstInit(&pst);
169 
170 	/* insert the destination Entity */
171 	pst.dstEnt = ENTSI;
172 
173 	/* initalize the control structure */
174 	memset(&cntrl, 0x0, sizeof(SiMngmt));
175 
176 	/* initalize the control header */
177 	smHdrInit(&cntrl.hdr);
178 
179 	cntrl.hdr.msgType			= TCNTRL;	   /* this is a control request */
180 	cntrl.hdr.entId.ent			= ENTSI;
181 	cntrl.hdr.entId.inst		= S_INST;
182 	cntrl.hdr.elmId.elmnt		= STNSAP;
183 
184 	cntrl.t.cntrl.s.siElmnt.elmntId.sapId				= suId;
185 	cntrl.t.cntrl.s.siElmnt.elmntParam.nsap.nsapType	= SAP_MTP;
186 
187 
188 	cntrl.t.cntrl.action		= ABND_ENA;		/* bind and activate */
189 	cntrl.t.cntrl.subAction		= SAELMNT;		/* specificed element */
190 
191 	return (sng_cntrl_isup(&pst, &cntrl));
192 }
193 
194 /******************************************************************************/
ftmod_ss7_enable_mtpLinkSet(int lnkSetId)195 static int ftmod_ss7_enable_mtpLinkSet(int lnkSetId)
196 {
197 	SnMngmt cntrl;
198 	Pst pst;
199 
200 	/* initalize the post structure */
201 	smPstInit(&pst);
202 
203 	/* insert the destination Entity */
204 	pst.dstEnt = ENTSN;
205 
206 	/* initalize the control structure */
207 	memset(&cntrl, 0x0, sizeof(SnMngmt));
208 
209 	/* initalize the control header */
210 	smHdrInit(&cntrl.hdr);
211 
212 	cntrl.hdr.msgType			= TCNTRL;		/* this is a control request */
213 	cntrl.hdr.entId.ent			= ENTSN;
214 	cntrl.hdr.entId.inst		= S_INST;
215 	cntrl.hdr.elmId.elmnt		= STLNKSET;
216 	cntrl.hdr.elmId.elmntInst1	= lnkSetId;		/* this is the linkset to bind */
217 
218 	cntrl.t.cntrl.action		= ABND_ENA;		/* bind and activate */
219 	cntrl.t.cntrl.subAction		= SAELMNT;		/* specificed element */
220 
221 	return (sng_cntrl_mtp3(&pst, &cntrl));
222 }
223 
224 /******************************************************************************/
ftmod_ss7_inhibit_mtp3link(uint32_t id)225 int ftmod_ss7_inhibit_mtp3link(uint32_t id)
226 {
227 	SnMngmt cntrl;
228 	Pst pst;
229 
230 	/* initalize the post structure */
231 	smPstInit(&pst);
232 
233 	/* insert the destination Entity */
234 	pst.dstEnt = ENTSN;
235 
236 	/* initalize the control structure */
237 	memset(&cntrl, 0x0, sizeof(SnMngmt));
238 
239 	/* initalize the control header */
240 	smHdrInit(&cntrl.hdr);
241 
242 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
243 	cntrl.hdr.entId.ent			= ENTSN;
244 	cntrl.hdr.entId.inst		= S_INST;
245 	cntrl.hdr.elmId.elmnt		= STDLSAP;
246 	cntrl.hdr.elmId.elmntInst1	= id;		/* the DSLAP to inhibit  */
247 
248 	cntrl.t.cntrl.action		= AINH;		/* Inhibit */
249 	cntrl.t.cntrl.subAction		= SAELMNT;	/* specificed element */
250 
251 	return (sng_cntrl_mtp3(&pst, &cntrl));
252 }
253 
254 /******************************************************************************/
ftmod_ss7_uninhibit_mtp3link(uint32_t id)255 int ftmod_ss7_uninhibit_mtp3link(uint32_t id)
256 {
257 	SnMngmt cntrl;
258 	Pst pst;
259 
260 	/* initalize the post structure */
261 	smPstInit(&pst);
262 
263 	/* insert the destination Entity */
264 	pst.dstEnt = ENTSN;
265 
266 	/* initalize the control structure */
267 	memset(&cntrl, 0x0, sizeof(SnMngmt));
268 
269 	/* initalize the control header */
270 	smHdrInit(&cntrl.hdr);
271 
272 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
273 	cntrl.hdr.entId.ent			= ENTSN;
274 	cntrl.hdr.entId.inst		= S_INST;
275 	cntrl.hdr.elmId.elmnt		= STDLSAP;
276 	cntrl.hdr.elmId.elmntInst1	= id;		/* the DSLAP to inhibit  */
277 
278 	cntrl.t.cntrl.action		= AUNINH;		/* Inhibit */
279 	cntrl.t.cntrl.subAction		= SAELMNT;	/* specificed element */
280 
281 	return (sng_cntrl_mtp3(&pst, &cntrl));
282 }
283 
284 /******************************************************************************/
ftmod_ss7_bind_mtp3link(uint32_t id)285 int ftmod_ss7_bind_mtp3link(uint32_t id)
286 {
287 	SnMngmt cntrl;
288 	Pst pst;
289 
290 	/* initalize the post structure */
291 	smPstInit(&pst);
292 
293 	/* insert the destination Entity */
294 	pst.dstEnt = ENTSN;
295 
296 	/* initalize the control structure */
297 	memset(&cntrl, 0x0, sizeof(SnMngmt));
298 
299 	/* initalize the control header */
300 	smHdrInit(&cntrl.hdr);
301 
302 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
303 	cntrl.hdr.entId.ent			= ENTSN;
304 	cntrl.hdr.entId.inst		= S_INST;
305 	cntrl.hdr.elmId.elmnt		= STDLSAP;
306 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtp3Link[id].id;
307 
308 	cntrl.t.cntrl.action		= ABND;		/* Activate */
309 	cntrl.t.cntrl.subAction		= SAELMNT;	/* specificed element */
310 
311 	return (sng_cntrl_mtp3(&pst, &cntrl));
312 }
313 
314 /******************************************************************************/
ftmod_ss7_unbind_mtp3link(uint32_t id)315 int ftmod_ss7_unbind_mtp3link(uint32_t id)
316 {
317 	SnMngmt cntrl;
318 	Pst pst;
319 
320 	/* initalize the post structure */
321 	smPstInit(&pst);
322 
323 	/* insert the destination Entity */
324 	pst.dstEnt = ENTSN;
325 
326 	/* initalize the control structure */
327 	memset(&cntrl, 0x0, sizeof(SnMngmt));
328 
329 	/* initalize the control header */
330 	smHdrInit(&cntrl.hdr);
331 
332 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
333 	cntrl.hdr.entId.ent			= ENTSN;
334 	cntrl.hdr.entId.inst		= S_INST;
335 	cntrl.hdr.elmId.elmnt		= STDLSAP;
336 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtp3Link[id].id;
337 
338 	cntrl.t.cntrl.action		= AUBND_DIS;		/* unbind and disable */
339 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
340 
341 	return (sng_cntrl_mtp3(&pst, &cntrl));
342 }
343 
344 /******************************************************************************/
ftmod_ss7_activate_mtp3link(uint32_t id)345 int ftmod_ss7_activate_mtp3link(uint32_t id)
346 {
347 	SnMngmt cntrl;
348 	Pst pst;
349 
350 	/* initalize the post structure */
351 	smPstInit(&pst);
352 
353 	/* insert the destination Entity */
354 	pst.dstEnt = ENTSN;
355 
356 	/* initalize the control structure */
357 	memset(&cntrl, 0x0, sizeof(SnMngmt));
358 
359 	/* initalize the control header */
360 	smHdrInit(&cntrl.hdr);
361 
362 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
363 	cntrl.hdr.entId.ent			= ENTSN;
364 	cntrl.hdr.entId.inst		= S_INST;
365 	cntrl.hdr.elmId.elmnt		= STDLSAP;
366 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtp3Link[id].id;
367 
368 	cntrl.t.cntrl.action		= AENA;		/* Activate */
369 	cntrl.t.cntrl.subAction		= SAELMNT;	/* specificed element */
370 
371 	return (sng_cntrl_mtp3(&pst, &cntrl));
372 }
373 
374 /******************************************************************************/
ftmod_ss7_deactivate_mtp3link(uint32_t id)375 int ftmod_ss7_deactivate_mtp3link(uint32_t id)
376 {
377 	SnMngmt cntrl;
378 	Pst pst;
379 
380 	/* initalize the post structure */
381 	smPstInit(&pst);
382 
383 	/* insert the destination Entity */
384 	pst.dstEnt = ENTSN;
385 
386 	/* initalize the control structure */
387 	memset(&cntrl, 0x0, sizeof(SnMngmt));
388 
389 	/* initalize the control header */
390 	smHdrInit(&cntrl.hdr);
391 
392 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
393 	cntrl.hdr.entId.ent			= ENTSN;
394 	cntrl.hdr.entId.inst		= S_INST;
395 	cntrl.hdr.elmId.elmnt		= STDLSAP;
396 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtp3Link[id].id;
397 
398 	cntrl.t.cntrl.action		= ADISIMM;	/* Deactivate */
399 	cntrl.t.cntrl.subAction		= SAELMNT;	/* specificed element */
400 
401 	return (sng_cntrl_mtp3(&pst, &cntrl));
402 }
403 
404 /******************************************************************************/
ftmod_ss7_deactivate2_mtp3link(uint32_t id)405 int ftmod_ss7_deactivate2_mtp3link(uint32_t id)
406 {
407 	SnMngmt cntrl;
408 	Pst pst;
409 
410 	/* initalize the post structure */
411 	smPstInit(&pst);
412 
413 	/* insert the destination Entity */
414 	pst.dstEnt = ENTSN;
415 
416 	/* initalize the control structure */
417 	memset(&cntrl, 0x0, sizeof(SnMngmt));
418 
419 	/* initalize the control header */
420 	smHdrInit(&cntrl.hdr);
421 
422 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
423 	cntrl.hdr.entId.ent			= ENTSN;
424 	cntrl.hdr.entId.inst		= S_INST;
425 	cntrl.hdr.elmId.elmnt		= STDLSAP;
426 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtp3Link[id].id;
427 
428 	cntrl.t.cntrl.action		= ADISIMM_L2;	/* Deactivate...layer 2 only */
429 	cntrl.t.cntrl.subAction		= SAELMNT;		/* specificed element */
430 
431 	return (sng_cntrl_mtp3(&pst, &cntrl));
432 }
433 
434 /******************************************************************************/
ftmod_ss7_activate_mtplinkSet(uint32_t id)435 int ftmod_ss7_activate_mtplinkSet(uint32_t id)
436 {
437 	SnMngmt cntrl;
438 	Pst pst;
439 
440 	/* initalize the post structure */
441 	smPstInit(&pst);
442 
443 	/* insert the destination Entity */
444 	pst.dstEnt = ENTSN;
445 
446 	/* initalize the control structure */
447 	memset(&cntrl, 0x0, sizeof(SnMngmt));
448 
449 	/* initalize the control header */
450 	smHdrInit(&cntrl.hdr);
451 
452 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
453 	cntrl.hdr.entId.ent			= ENTSN;
454 	cntrl.hdr.entId.inst		= S_INST;
455 	cntrl.hdr.elmId.elmnt		= STLNKSET;
456 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtpLinkSet[id].id;
457 
458 	cntrl.t.cntrl.action		= AACTLNKSET;	/* Activate */
459 	cntrl.t.cntrl.subAction		= SAELMNT;		/* specificed element */
460 
461 	return (sng_cntrl_mtp3(&pst, &cntrl));
462 }
463 
464 /******************************************************************************/
ftmod_ss7_deactivate_mtplinkSet(uint32_t id)465 int ftmod_ss7_deactivate_mtplinkSet(uint32_t id)
466 {
467 	SnMngmt cntrl;
468 	Pst pst;
469 
470 	/* initalize the post structure */
471 	smPstInit(&pst);
472 
473 	/* insert the destination Entity */
474 	pst.dstEnt = ENTSN;
475 
476 	/* initalize the control structure */
477 	memset(&cntrl, 0x0, sizeof(SnMngmt));
478 
479 	/* initalize the control header */
480 	smHdrInit(&cntrl.hdr);
481 
482 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
483 	cntrl.hdr.entId.ent			= ENTSN;
484 	cntrl.hdr.entId.inst		= S_INST;
485 	cntrl.hdr.elmId.elmnt		= STLNKSET;
486 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtpLinkSet[id].id;
487 
488 	cntrl.t.cntrl.action		= ADEACTLNKSET;	/* Activate */
489 	cntrl.t.cntrl.subAction		= SAELMNT;		/* specificed element */
490 
491 	return (sng_cntrl_mtp3(&pst, &cntrl));
492 }
493 
494 /******************************************************************************/
ftmod_ss7_deactivate2_mtplinkSet(uint32_t id)495 int ftmod_ss7_deactivate2_mtplinkSet(uint32_t id)
496 {
497 	SnMngmt cntrl;
498 	Pst pst;
499 
500 	/* initalize the post structure */
501 	smPstInit(&pst);
502 
503 	/* insert the destination Entity */
504 	pst.dstEnt = ENTSN;
505 
506 	/* initalize the control structure */
507 	memset(&cntrl, 0x0, sizeof(SnMngmt));
508 
509 	/* initalize the control header */
510 	smHdrInit(&cntrl.hdr);
511 
512 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
513 	cntrl.hdr.entId.ent			= ENTSN;
514 	cntrl.hdr.entId.inst		= S_INST;
515 	cntrl.hdr.elmId.elmnt		= STLNKSET;
516 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtpLinkSet[id].id;
517 
518 	cntrl.t.cntrl.action		= ADEACTLNKSET_L2;	/* Activate */
519 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
520 
521 	return (sng_cntrl_mtp3(&pst, &cntrl));
522 }
523 
524 /******************************************************************************/
ftmod_ss7_lpo_mtp3link(uint32_t id)525 int ftmod_ss7_lpo_mtp3link(uint32_t id)
526 {
527 	SnMngmt cntrl;
528 	Pst pst;
529 
530 	/* initalize the post structure */
531 	smPstInit(&pst);
532 
533 	/* insert the destination Entity */
534 	pst.dstEnt = ENTSN;
535 
536 	/* initalize the control structure */
537 	memset(&cntrl, 0x0, sizeof(SnMngmt));
538 
539 	/* initalize the control header */
540 	smHdrInit(&cntrl.hdr);
541 
542 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
543 	cntrl.hdr.entId.ent			= ENTSN;
544 	cntrl.hdr.entId.inst		= S_INST;
545 	cntrl.hdr.elmId.elmnt		= STDLSAP;
546 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtp3Link[id].id;
547 
548 	cntrl.t.cntrl.action		= ACTION_LPO;	/* Activate */
549 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
550 
551 	return (sng_cntrl_mtp3(&pst, &cntrl));
552 }
553 
554 /******************************************************************************/
ftmod_ss7_lpr_mtp3link(uint32_t id)555 int ftmod_ss7_lpr_mtp3link(uint32_t id)
556 {
557 	SnMngmt cntrl;
558 	Pst pst;
559 
560 	/* initalize the post structure */
561 	smPstInit(&pst);
562 
563 	/* insert the destination Entity */
564 	pst.dstEnt = ENTSN;
565 
566 	/* initalize the control structure */
567 	memset(&cntrl, 0x0, sizeof(SnMngmt));
568 
569 	/* initalize the control header */
570 	smHdrInit(&cntrl.hdr);
571 
572 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
573 	cntrl.hdr.entId.ent			= ENTSN;
574 	cntrl.hdr.entId.inst		= S_INST;
575 	cntrl.hdr.elmId.elmnt		= STDLSAP;
576 	cntrl.hdr.elmId.elmntInst1	= g_ftdm_sngss7_data.cfg.mtp3Link[id].id;
577 
578 	cntrl.t.cntrl.action		= ACTION_LPR;	/* Activate */
579 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
580 
581 	return (sng_cntrl_mtp3(&pst, &cntrl));
582 }
583 
584 /******************************************************************************/
ftmod_ss7_shutdown_isup(void)585 int ftmod_ss7_shutdown_isup(void)
586 {
587 	SiMngmt cntrl;
588 	Pst pst;
589 
590 	/* initalize the post structure */
591 	smPstInit(&pst);
592 
593 	/* insert the destination Entity */
594 	pst.dstEnt = ENTSI;
595 
596 	/* initalize the control structure */
597 	memset(&cntrl, 0x0, sizeof(SiMngmt));
598 
599 	/* initalize the control header */
600 	smHdrInit(&cntrl.hdr);
601 
602 	cntrl.hdr.msgType			= TCNTRL;	   /* this is a control request */
603 	cntrl.hdr.entId.ent			= ENTSI;
604 	cntrl.hdr.entId.inst		= S_INST;
605 	cntrl.hdr.elmId.elmnt		= STGEN;
606 
607 	cntrl.t.cntrl.action		= ASHUTDOWN;	/* shutdown */
608 	cntrl.t.cntrl.subAction		= SAELMNT;		/* specificed element */
609 
610 	return (sng_cntrl_isup(&pst, &cntrl));
611 }
612 
613 /******************************************************************************/
ftmod_ss7_shutdown_mtp3(void)614 int ftmod_ss7_shutdown_mtp3(void)
615 {
616 	SnMngmt cntrl;
617 	Pst pst;
618 
619 	/* initalize the post structure */
620 	smPstInit(&pst);
621 
622 	/* insert the destination Entity */
623 	pst.dstEnt = ENTSN;
624 
625 	/* initalize the control structure */
626 	memset(&cntrl, 0x0, sizeof(SnMngmt));
627 
628 	/* initalize the control header */
629 	smHdrInit(&cntrl.hdr);
630 
631 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
632 	cntrl.hdr.entId.ent			= ENTSN;
633 	cntrl.hdr.entId.inst		= S_INST;
634 	cntrl.hdr.elmId.elmnt		= STGEN;
635 
636 	cntrl.t.cntrl.action		= ASHUTDOWN;	/* Activate */
637 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
638 
639 	return (sng_cntrl_mtp3(&pst, &cntrl));
640 }
641 
642 /******************************************************************************/
ftmod_ss7_shutdown_mtp2(void)643 int ftmod_ss7_shutdown_mtp2(void)
644 {
645 	SdMngmt cntrl;
646 	Pst pst;
647 
648 	/* initalize the post structure */
649 	smPstInit(&pst);
650 
651 	/* insert the destination Entity */
652 	pst.dstEnt = ENTSD;
653 
654 	/* initalize the control structure */
655 	memset(&cntrl, 0x0, sizeof(SdMngmt));
656 
657 	/* initalize the control header */
658 	smHdrInit(&cntrl.hdr);
659 
660 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
661 	cntrl.hdr.entId.ent			= ENTSD;
662 	cntrl.hdr.entId.inst		= S_INST;
663 	cntrl.hdr.elmId.elmnt		= STGEN;
664 
665 	cntrl.t.cntrl.action		= ASHUTDOWN;	/* Activate */
666 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
667 
668 	return (sng_cntrl_mtp2(&pst, &cntrl));
669 }
670 
671 /******************************************************************************/
ftmod_ss7_shutdown_relay(void)672 int ftmod_ss7_shutdown_relay(void)
673 {
674 	RyMngmt cntrl;
675 	Pst pst;
676 
677 	/* initalize the post structure */
678 	smPstInit(&pst);
679 
680 	/* insert the destination Entity */
681 	pst.dstEnt = ENTRY;
682 
683 	/* initalize the control structure */
684 	memset(&cntrl, 0x0, sizeof(RyMngmt));
685 
686 	/* initalize the control header */
687 	smHdrInit(&cntrl.hdr);
688 
689 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
690 	cntrl.hdr.entId.ent			= ENTRY;
691 	cntrl.hdr.entId.inst		= S_INST;
692 	cntrl.hdr.elmId.elmnt		= STGEN;
693 
694 	cntrl.t.cntrl.action		= ASHUTDOWN;	/* Activate */
695 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
696 
697 	return (sng_cntrl_relay(&pst, &cntrl));
698 }
699 
700 /******************************************************************************/
ftmod_ss7_disable_relay_channel(uint32_t chanId)701 int ftmod_ss7_disable_relay_channel(uint32_t chanId)
702 {
703 	RyMngmt cntrl;
704 	Pst pst;
705 
706 	/* initalize the post structure */
707 	smPstInit(&pst);
708 
709 	/* insert the destination Entity */
710 	pst.dstEnt = ENTRY;
711 
712 	/* initalize the control structure */
713 	memset(&cntrl, 0x0, sizeof(RyMngmt));
714 
715 	/* initalize the control header */
716 	smHdrInit(&cntrl.hdr);
717 
718 	cntrl.hdr.msgType			= TCNTRL;	/* this is a control request */
719 	cntrl.hdr.entId.ent			= ENTRY;
720 	cntrl.hdr.entId.inst		= S_INST;
721 	cntrl.hdr.elmId.elmnt		= STGEN;
722 
723 
724 	cntrl.hdr.elmId.elmntInst1	= chanId;
725 
726 	cntrl.t.cntrl.action		= ADISIMM;			/* Deactivate */
727 	cntrl.t.cntrl.subAction		= SAELMNT;			/* specificed element */
728 
729 	return (sng_cntrl_relay(&pst, &cntrl));
730 }
731 
732 /******************************************************************************/
ftmod_ss7_disable_grp_mtp3Link(uint32_t procId)733 int ftmod_ss7_disable_grp_mtp3Link(uint32_t procId)
734 {
735 	SnMngmt cntrl;
736 	Pst pst;
737 
738 	/* initalize the post structure */
739 	smPstInit(&pst);
740 
741 	/* insert the destination Entity */
742 	pst.dstEnt = ENTSN;
743 
744 	/* initalize the control structure */
745 	memset(&cntrl, 0x0, sizeof(SnMngmt));
746 
747 	/* initalize the control header */
748 	smHdrInit(&cntrl.hdr);
749 
750 	cntrl.hdr.msgType			= TCNTRL;			/* this is a control request */
751 	cntrl.hdr.entId.ent			= ENTSN;
752 	cntrl.hdr.entId.inst		= S_INST;
753 	cntrl.hdr.elmId.elmnt		= STGRDLSAP;		/* group DLSAP */
754 
755 	cntrl.t.cntrl.ctlType.groupKey.dstProcId = procId;	/* all SAPS to this ProcId */
756 
757 	cntrl.t.cntrl.action		= AUBND_DIS;		/* disable and unbind */
758 	cntrl.t.cntrl.subAction		= SAGR_DSTPROCID;			/* specificed element */
759 
760 	if (g_ftdm_sngss7_data.cfg.procId == procId) {
761 		SS7_DEBUG("Executing MTP3 cntrl command local pid =%i\n",procId);
762 		return (sng_cntrl_mtp3(&pst, &cntrl));
763 	} else {
764 		SS7_WARN("Executing MTP3 cntrl command different local=%i target=%i\n",
765 				g_ftdm_sngss7_data.cfg.procId,procId);
766 		return (sng_cntrl_mtp3_nowait(&pst, &cntrl));
767 	}
768 
769 }
770 
771 /******************************************************************************/
ftmod_ss7_enable_grp_mtp3Link(uint32_t procId)772 int ftmod_ss7_enable_grp_mtp3Link(uint32_t procId)
773 {
774 	SnMngmt cntrl;
775 	Pst pst;
776 
777 	/* initalize the post structure */
778 	smPstInit(&pst);
779 
780 	/* insert the destination Entity */
781 	pst.dstEnt = ENTSN;
782 
783 	/* initalize the control structure */
784 	memset(&cntrl, 0x0, sizeof(SnMngmt));
785 
786 	/* initalize the control header */
787 	smHdrInit(&cntrl.hdr);
788 
789 	cntrl.hdr.msgType			= TCNTRL;			/* this is a control request */
790 	cntrl.hdr.entId.ent			= ENTSN;
791 	cntrl.hdr.entId.inst		= S_INST;
792 	cntrl.hdr.elmId.elmnt		= STGRDLSAP;		/* group DLSAP */
793 
794 	cntrl.t.cntrl.ctlType.groupKey.dstProcId = procId;	/* all SAPS to this ProcId */
795 
796 	cntrl.t.cntrl.action		= ABND_ENA;			/* bind and enable */
797 	cntrl.t.cntrl.subAction		= SAGR_DSTPROCID;			/* specificed element */
798 
799 	if (g_ftdm_sngss7_data.cfg.procId == procId) {
800 		SS7_DEBUG("Executing MTP3 cntrl command local pid =%i\n",procId);
801 		return (sng_cntrl_mtp3(&pst, &cntrl));
802 	} else {
803 		SS7_WARN("Executing MTP3 cntrl command different local=%i target=%i\n",
804 				g_ftdm_sngss7_data.cfg.procId,procId);
805 		return (sng_cntrl_mtp3_nowait(&pst, &cntrl));
806 	}
807 
808 }
809 
810 /******************************************************************************/
ftmod_ss7_disable_grp_mtp2Link(uint32_t procId)811 int ftmod_ss7_disable_grp_mtp2Link(uint32_t procId)
812 {
813 	SdMngmt cntrl;
814 	Pst pst;
815 
816 	/* initalize the post structure */
817 	smPstInit(&pst);
818 
819 	/* insert the destination Entity */
820 	pst.dstEnt = ENTSD;
821 
822 	/* initalize the control structure */
823 	memset(&cntrl, 0x0, sizeof(cntrl));
824 
825 	/* initalize the control header */
826 	smHdrInit(&cntrl.hdr);
827 
828 	cntrl.hdr.msgType			= TCNTRL;			/* this is a control request */
829 	cntrl.hdr.entId.ent			= ENTSD;
830 	cntrl.hdr.entId.inst		= S_INST;
831 	cntrl.hdr.elmId.elmnt		= STGRNSAP;			/* group NSAP */
832 
833 	cntrl.t.cntrl.par.dstProcId = procId;			/* all SAPS to this ProcId */
834 
835 	cntrl.t.cntrl.action		= AUBND_DIS;		/* disable and unbind */
836 	cntrl.t.cntrl.subAction		= SAGR_DSTPROCID;			/* specificed element */
837 
838 	return (sng_cntrl_mtp2(&pst, &cntrl));
839 
840 }
841 
842 /******************************************************************************/
__ftmod_ss7_block_isup_ckt(uint32_t cktId,ftdm_bool_t wait)843 int __ftmod_ss7_block_isup_ckt(uint32_t cktId, ftdm_bool_t wait)
844 {
845 	SiMngmt cntrl;
846 	Pst pst;
847 
848 	/* initalize the post structure */
849 	smPstInit(&pst);
850 
851 	/* insert the destination Entity */
852 	pst.dstEnt = ENTSI;
853 
854 	/* initalize the control structure */
855 	memset(&cntrl, 0x0, sizeof(SiMngmt));
856 
857 	/* initalize the control header */
858 	smHdrInit(&cntrl.hdr);
859 
860 	cntrl.hdr.msgType						= TCNTRL;		/* this is a control request */
861 	cntrl.hdr.entId.ent						= ENTSI;
862 	cntrl.hdr.entId.inst					= S_INST;
863 	cntrl.hdr.elmId.elmnt					= STICIR;
864 
865 	cntrl.t.cntrl.s.siElmnt.elmntId.circuit	= cktId;
866 	cntrl.t.cntrl.s.siElmnt.elmntParam.cir.flag = LSI_CNTRL_CIR_FORCE;
867 
868 	cntrl.t.cntrl.action					= ADISIMM;		/* block via BLO */
869 	cntrl.t.cntrl.subAction					= SAELMNT;		/* specificed element */
870 
871 	if (wait == FTDM_TRUE) {
872 		return (sng_cntrl_isup(&pst, &cntrl));
873 	} else {
874 		return (sng_cntrl_isup_nowait(&pst, &cntrl));
875 	}
876 }
877 
878 /******************************************************************************/
ftmod_ss7_unblock_isup_ckt(uint32_t cktId)879 int ftmod_ss7_unblock_isup_ckt(uint32_t cktId)
880 {
881 	SiMngmt cntrl;
882 	Pst pst;
883 
884 	/* initalize the post structure */
885 	smPstInit(&pst);
886 
887 	/* insert the destination Entity */
888 	pst.dstEnt = ENTSI;
889 
890 	/* initalize the control structure */
891 	memset(&cntrl, 0x0, sizeof(SiMngmt));
892 
893 	/* initalize the control header */
894 	smHdrInit(&cntrl.hdr);
895 
896 	cntrl.hdr.msgType						= TCNTRL;		/* this is a control request */
897 	cntrl.hdr.entId.ent						= ENTSI;
898 	cntrl.hdr.entId.inst					= S_INST;
899 	cntrl.hdr.elmId.elmnt					= STICIR;
900 
901 	cntrl.t.cntrl.s.siElmnt.elmntId.circuit		= cktId;
902 	cntrl.t.cntrl.s.siElmnt.elmntParam.cir.flag = LSI_CNTRL_CIR_FORCE;
903 
904 	cntrl.t.cntrl.action					= AENA;			/* unblock via UBL */
905 	cntrl.t.cntrl.subAction					= SAELMNT;		/* specificed element */
906 
907 	return (sng_cntrl_isup(&pst, &cntrl));
908 }
909 /******************************************************************************/
910 /* For Emacs:
911  * Local Variables:
912  * mode:c
913  * indent-tabs-mode:t
914  * tab-width:4
915  * c-basic-offset:4
916  * End:
917  * For VIM:
918  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
919  */
920 /******************************************************************************/
921 
922