root/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ftdm_sngss7_handle_cli_cmd
  2. handle_print_usuage
  3. handle_set_function_trace
  4. handle_set_message_trace
  5. handle_show_free
  6. handle_show_inuse
  7. handle_show_inreset
  8. handle_show_flags
  9. handle_show_blocks
  10. handle_show_status
  11. handle_tx_blo
  12. handle_tx_ubl
  13. handle_status_link
  14. handle_status_linkset
  15. handle_set_inhibit
  16. handle_set_uninhibit
  17. handle_tx_rsc
  18. handle_tx_grs
  19. handle_tx_cgb
  20. handle_tx_cgu
  21. handle_activate_link
  22. handle_deactivate_link
  23. handle_activate_linkset
  24. handle_deactivate_linkset
  25. handle_tx_lpo
  26. handle_tx_lpr
  27. extract_span_chan
  28. check_arg_count

   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 ftdm_status_t ftdm_sngss7_handle_cli_cmd(ftdm_stream_handle_t *stream, const char *data);
  46 
  47 static ftdm_status_t handle_print_usuage(ftdm_stream_handle_t *stream);
  48 
  49 static ftdm_status_t handle_set_function_trace(ftdm_stream_handle_t *stream, int on, int level);
  50 static ftdm_status_t handle_set_message_trace(ftdm_stream_handle_t *stream, int on, int level);
  51 static ftdm_status_t handle_set_inhibit(ftdm_stream_handle_t *stream, char *name);
  52 static ftdm_status_t handle_set_uninhibit(ftdm_stream_handle_t *stream, char *name);
  53 
  54 static ftdm_status_t handle_show_free(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  55 static ftdm_status_t handle_show_inuse(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  56 static ftdm_status_t handle_show_inreset(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  57 static ftdm_status_t handle_show_flags(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  58 static ftdm_status_t handle_show_blocks(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  59 static ftdm_status_t handle_show_status(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  60 
  61 static ftdm_status_t handle_tx_rsc(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  62 static ftdm_status_t handle_tx_grs(ftdm_stream_handle_t *stream, int span, int chan, int range, int verbose);
  63 
  64 static ftdm_status_t handle_tx_blo(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  65 static ftdm_status_t handle_tx_ubl(ftdm_stream_handle_t *stream, int span, int chan, int verbose);
  66 
  67 static ftdm_status_t handle_tx_cgb(ftdm_stream_handle_t *stream, int span, int chan, int range, int verbose);
  68 static ftdm_status_t handle_tx_cgu(ftdm_stream_handle_t *stream, int span, int chan, int range, int verbose);
  69 
  70 static ftdm_status_t handle_activate_link(ftdm_stream_handle_t *stream, char *name);
  71 static ftdm_status_t handle_deactivate_link(ftdm_stream_handle_t *stream, char *name);
  72 
  73 static ftdm_status_t handle_activate_linkset(ftdm_stream_handle_t *stream, char *name);
  74 static ftdm_status_t handle_deactivate_linkset(ftdm_stream_handle_t *stream, char *name);
  75 
  76 static ftdm_status_t handle_tx_lpo(ftdm_stream_handle_t *stream, char *name);
  77 static ftdm_status_t handle_tx_lpr(ftdm_stream_handle_t *stream, char *name);
  78 
  79 static ftdm_status_t handle_status_link(ftdm_stream_handle_t *stream, char *name);
  80 static ftdm_status_t handle_status_linkset(ftdm_stream_handle_t *stream, char *name);
  81 
  82 static ftdm_status_t extract_span_chan(char *argv[10], int pos, int *span, int *chan);
  83 static ftdm_status_t check_arg_count(int args, int min);
  84 /******************************************************************************/
  85 
  86 /* FUNCTIONS ******************************************************************/
  87 ftdm_status_t ftdm_sngss7_handle_cli_cmd(ftdm_stream_handle_t *stream, const char *data)
  88 {
  89         char    *mycmd = NULL;
  90         char    *argv[10] = { 0 };
  91         int             argc = 0;
  92         int             span = 0;
  93         int             chan = 0;
  94         int             range = 0;
  95         int             trace = 0;
  96         int             trace_level = 7;
  97         int             verbose = 1;
  98         int             c = 0;
  99 
 100         if (data) {
 101                 mycmd = ftdm_strdup(data);
 102                 argc = ftdm_separate_string(mycmd,' ',argv,(sizeof(argv) / sizeof(argv[0])));
 103         }
 104 
 105         if (check_arg_count(argc, 1)) goto handle_cli_error_argc;
 106         
 107         if (!strcasecmp(argv[c], "show")) {
 108         /**************************************************************************/   
 109                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 110                 c++;
 111 
 112                 if (!strcasecmp(argv[c], "status")) {
 113                 /**********************************************************************/
 114                         c++;
 115 
 116                         if (!strcasecmp(argv[c], "link")) {
 117                         /******************************************************************/
 118                                 c++;
 119                                 handle_status_link(stream, argv[c]);
 120                         /******************************************************************/
 121                         } else if (!strcasecmp(argv[c], "linkset")) {
 122                         /******************************************************************/
 123                                 c++;
 124                                 handle_status_linkset(stream, argv[c]);
 125                         /******************************************************************/
 126                         } else if (!strcasecmp(argv[c], "span")) {
 127                         /******************************************************************/
 128                                 if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 129 
 130                                 if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 131 
 132                                 handle_show_status(stream, span, chan, verbose);
 133                         /******************************************************************/
 134                         } else {
 135                         /******************************************************************/
 136                                 stream->write_function(stream, "Unknown \"status\" command\n");
 137                                 goto handle_cli_error;
 138                         /******************************************************************/
 139                         }
 140                 /**********************************************************************/
 141                 } else if (!strcasecmp(argv[c], "inuse")) {
 142                 /**********************************************************************/
 143                         if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 144                         c++;
 145 
 146                         if (!strcasecmp(argv[c], "span")) {
 147                         /******************************************************************/
 148                                 if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 149 
 150                                 if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 151 
 152                                 handle_show_inuse(stream, span, chan, verbose);
 153                         /******************************************************************/
 154                         } else {
 155                         /******************************************************************/
 156                                 stream->write_function(stream, "Unknown \"inuse\" command\n");
 157                                 goto handle_cli_error;
 158                         /******************************************************************/
 159                         }
 160                 /**********************************************************************/
 161                 } else if (!strcasecmp(argv[c], "inreset")) {
 162                 /**********************************************************************/
 163                         if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 164                         c++;
 165 
 166                         if (!strcasecmp(argv[c], "span")) {
 167                         /******************************************************************/
 168                                 if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 169 
 170                                 if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 171 
 172                                 handle_show_inreset(stream, span, chan, verbose);
 173                         /******************************************************************/
 174                         } else {
 175                         /******************************************************************/
 176                                 stream->write_function(stream, "Unknown \"inreset\" command\n");
 177                                 goto handle_cli_error;
 178                         /******************************************************************/
 179                         }   
 180                 /**********************************************************************/
 181                 } else if (!strcasecmp(argv[c], "free")) {
 182                 /**********************************************************************/
 183                         if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 184                         c++;
 185 
 186                         if (!strcasecmp(argv[c], "span")) {
 187                         /******************************************************************/
 188                                 if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 189 
 190                                 if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 191 
 192                                 handle_show_free(stream, span, chan, verbose);
 193                         /******************************************************************/
 194                         } else {
 195                         /******************************************************************/
 196                                 stream->write_function(stream, "Unknown \"free\" command\n");
 197                                 goto handle_cli_error;
 198                         /******************************************************************/
 199                         }   
 200                 /**********************************************************************/
 201                 } else if (!strcasecmp(argv[c], "blocks")) {
 202                 /**********************************************************************/
 203                         if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 204                         c++;
 205 
 206                         if (!strcasecmp(argv[c], "span")) {
 207                         /******************************************************************/
 208                                 if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 209 
 210                                 if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 211 
 212                                 handle_show_blocks(stream, span, chan, verbose);
 213                         /******************************************************************/
 214                         } else {
 215                         /******************************************************************/
 216                                 stream->write_function(stream, "Unknown \"blocks\" command\n");
 217                                 goto handle_cli_error;
 218                         /******************************************************************/
 219                         }   
 220                 /**********************************************************************/
 221                 } else if (!strcasecmp(argv[c], "flags")) {
 222                 /**********************************************************************/
 223                         if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 224                         c++;
 225 
 226                         if (!strcasecmp(argv[c], "span")) {
 227                         /******************************************************************/
 228                                 if (check_arg_count(argc, 6)) goto handle_cli_error_argc;
 229 
 230                                 if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 231 
 232                                 handle_show_flags(stream, span, chan, verbose);
 233                         /******************************************************************/
 234                         } else {
 235                         /******************************************************************/
 236                                 stream->write_function(stream, "Unknown \"flags\" command\n");
 237                                 goto handle_cli_error;
 238                         /******************************************************************/
 239                         }
 240                 /**********************************************************************/
 241                 } else if (!strcasecmp(argv[c], "mem")) {
 242                 /**********************************************************************/
 243                         sng_isup_reg_info_show();
 244                 /**********************************************************************/
 245                 } else if (!strcasecmp(argv[c], "stats")) {
 246                 /**********************************************************************/
 247 /*                      sng_mtp1_sts_t sts;
 248 
 249                         memset(&sts, 0x0, sizeof(sng_mtp1_sts_t));
 250 
 251                         sng_mtp1_sts(1, &sts);
 252 
 253                         stream->write_function(stream,"MTP1 tx stats:|tx_frm=%d|tx_err=%d|tx_fisu=%d|tx_lssu=%d|tx_msu=%d|\n",
 254                                                                                         sts.tx_frm, sts.tx_err, sts.tx_fisu, sts.tx_lssu, sts.tx_msu);
 255                         stream->write_function(stream,"MTP1 rx stats:|rx_frm=%d|rx_err=%d|rx_fisu=%d|rx_lssu=%d|rx_msu=%d|\n",
 256                                                                                         sts.rx_frm, sts.rx_err, sts.rx_fisu, sts.rx_lssu, sts.rx_msu);
 257 */
 258                 /**********************************************************************/
 259                 } else {
 260                 /**********************************************************************/
 261                         stream->write_function(stream, "Unknown \"show\" command\n");
 262                         goto handle_cli_error;
 263                 /**********************************************************************/
 264                 }
 265         /**************************************************************************/
 266         } else if (!strcasecmp(argv[c], "set")) {
 267         /**************************************************************************/
 268                 if (check_arg_count(argc, 4)) goto handle_cli_error_argc;
 269                 c++;
 270 
 271                 if (!strcasecmp(argv[c], "ftrace")) {
 272                 /**********************************************************************/
 273                         c++;
 274                         trace = atoi(argv[c]);
 275                         c++;
 276                         trace_level = atoi(argv[c]);
 277                         c++;
 278                         handle_set_function_trace(stream, trace, trace_level);
 279                 /**********************************************************************/
 280                 } else if (!strcasecmp(argv[c], "mtrace")) {
 281                 /**********************************************************************/
 282                         c++;
 283                         trace = atoi(argv[c]);
 284                         c++;
 285                         trace_level = atoi(argv[c]);
 286                         c++;
 287                         handle_set_message_trace(stream, trace, trace_level);
 288                 /**********************************************************************/
 289                 } else {
 290                 /**********************************************************************/
 291                         stream->write_function(stream, "Unknown \"set\" command\n");
 292                         goto handle_cli_error;
 293                 /**********************************************************************/
 294                 }  
 295         /**************************************************************************/
 296         } else if (!strcasecmp(argv[c], "inhibit")) {
 297         /**************************************************************************/
 298                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 299                 c++;
 300 
 301                 if (!strcasecmp(argv[c], "link")) {
 302                 /**********************************************************************/
 303                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 304                         c++;
 305                         
 306                         handle_set_inhibit(stream, argv[c]);
 307                 /**********************************************************************/
 308                 } else {
 309                 /**********************************************************************/
 310                         stream->write_function(stream, "Unknown \"block\" command\n");
 311                         goto handle_cli_error;
 312                 /**********************************************************************/
 313                 }   
 314         /**************************************************************************/
 315         } else if (!strcasecmp(argv[c], "uninhibit")) {
 316         /**************************************************************************/
 317                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 318                 c++;
 319 
 320                 if (!strcasecmp(argv[c], "link")) {
 321                 /**********************************************************************/
 322                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 323                         c++;
 324                         
 325                         handle_set_uninhibit(stream, argv[c]);
 326                 /**********************************************************************/
 327                 } else {
 328                 /**********************************************************************/
 329                         stream->write_function(stream, "Unknown \"unblock\" command\n");
 330                         goto handle_cli_error;
 331                 /**********************************************************************/
 332                 } 
 333         /**************************************************************************/
 334         } else if (!strcasecmp(argv[c], "blo")) {
 335         /**************************************************************************/
 336                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 337                 c++;
 338 
 339                 if (!strcasecmp(argv[c], "span")) {
 340                 /**********************************************************************/
 341                         if (check_arg_count(argc, 5)) goto handle_cli_error_argc;
 342 
 343                         if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 344 
 345                         handle_tx_blo(stream, span, chan, verbose);
 346                 /**********************************************************************/
 347                 } else {
 348                 /**********************************************************************/
 349                         stream->write_function(stream, "Unknown \"block\" command\n");
 350                         goto handle_cli_error;
 351                 /**********************************************************************/
 352                 }
 353         /**************************************************************************/
 354         } else if (!strcasecmp(argv[c], "ubl")) {
 355         /**************************************************************************/
 356                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 357                 c++;
 358 
 359                 if (!strcasecmp(argv[c], "span")) {
 360                 /**********************************************************************/
 361                         if (check_arg_count(argc, 5)) goto handle_cli_error_argc;
 362 
 363                         if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 364 
 365                         handle_tx_ubl(stream, span, chan, verbose);
 366                 /**********************************************************************/
 367                 } else {
 368                 /**********************************************************************/
 369                         stream->write_function(stream, "Unknown \"ubl\" command\n");
 370                         goto handle_cli_error;
 371                 /**********************************************************************/
 372                 } 
 373         /**************************************************************************/
 374         } else if (!strcasecmp(argv[c], "cgb")) {
 375         /**************************************************************************/
 376                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 377                 c++;
 378 
 379                 if (!strcasecmp(argv[c], "span")) {
 380                 /**********************************************************************/
 381                         if (check_arg_count(argc, 5)) goto handle_cli_error_argc;
 382 
 383                         if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 384                         c = c + 4;
 385 
 386                         if (check_arg_count(argc, 7)) goto handle_cli_error_argc;
 387 
 388                         if (!strcasecmp(argv[c], "range")) {
 389                         /******************************************************************/
 390                                 c++;
 391                                 range =  atoi(argv[c]);
 392                         /******************************************************************/
 393                         } else {
 394                         /******************************************************************/
 395                                 stream->write_function(stream, "Unknown \"cgb range\" command\n");
 396                                 goto handle_cli_error;
 397                         /******************************************************************/
 398                         }
 399 
 400                         handle_tx_cgb(stream, span, chan, range, verbose);
 401                 /**********************************************************************/
 402                 } else {
 403                 /**********************************************************************/
 404                         stream->write_function(stream, "Unknown \"cgb\" command\n");
 405                         goto handle_cli_error;
 406                 /**********************************************************************/
 407                 } 
 408         /**************************************************************************/
 409         } else if (!strcasecmp(argv[c], "cgu")) {
 410         /**************************************************************************/
 411                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 412                 c++;
 413 
 414                 if (!strcasecmp(argv[c], "span")) {
 415                 /**********************************************************************/
 416                         if (check_arg_count(argc, 5)) goto handle_cli_error_argc;
 417 
 418                         if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 419                         c = c + 4;
 420 
 421                         if (check_arg_count(argc, 7)) goto handle_cli_error_argc;
 422 
 423                         if (!strcasecmp(argv[c], "range")) {
 424                         /******************************************************************/
 425                                 c++;
 426                                 range =  atoi(argv[c]);
 427                         /******************************************************************/
 428                         } else {
 429                         /******************************************************************/
 430                                 stream->write_function(stream, "Unknown \"cgu range\" command\n");
 431                                 goto handle_cli_error;
 432                         /******************************************************************/
 433                         }
 434 
 435                         handle_tx_cgu(stream, span, chan, range, verbose);
 436                 /**********************************************************************/
 437                 } else {
 438                 /**********************************************************************/
 439                         stream->write_function(stream, "Unknown \"cgu\" command\n");
 440                         goto handle_cli_error;
 441                 /**********************************************************************/
 442                 } 
 443         /**************************************************************************/
 444         } else if (!strcasecmp(argv[c], "rsc")) {
 445         /**************************************************************************/
 446                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 447                 c++;
 448 
 449                 if (!strcasecmp(argv[c], "span")) {
 450                 /**********************************************************************/
 451                         if (check_arg_count(argc, 5)) goto handle_cli_error_argc;
 452 
 453                         if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 454 
 455                         handle_tx_rsc(stream, span, chan, verbose);
 456                 /**********************************************************************/
 457                 } else {
 458                 /**********************************************************************/
 459                         stream->write_function(stream, "Unknown \"rsc\" command\n");
 460                         goto handle_cli_error;
 461                 /**********************************************************************/
 462                 } 
 463         /**************************************************************************/
 464         } else if (!strcasecmp(argv[c], "grs")) {
 465         /**************************************************************************/
 466                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 467                 c++;
 468 
 469                 if (!strcasecmp(argv[c], "span")) {
 470                 /**********************************************************************/
 471                         if (check_arg_count(argc, 5)) goto handle_cli_error_argc;
 472 
 473                         if (extract_span_chan(argv, c, &span, &chan)) goto handle_cli_error_span_chan;
 474                         c = c + 4;
 475 
 476                         if (check_arg_count(argc, 7)) goto handle_cli_error_argc;
 477 
 478                         if (!strcasecmp(argv[c], "range")) {
 479                         /******************************************************************/
 480                                 c++;
 481                                 range =  atoi(argv[c]);
 482                         /******************************************************************/
 483                         } else {
 484                         /******************************************************************/
 485                                 stream->write_function(stream, "Unknown \"grs range\" command\n");
 486                                 goto handle_cli_error;
 487                         /******************************************************************/
 488                         }
 489 
 490                         handle_tx_grs(stream, span, chan, range, verbose);
 491                 /**********************************************************************/
 492                 } else {
 493                 /**********************************************************************/
 494                         stream->write_function(stream, "Unknown \"grs\" command\n");
 495                         goto handle_cli_error;
 496                 /**********************************************************************/
 497                 }
 498         /**************************************************************************/
 499         } else if (!strcasecmp(argv[c], "lpo")) {
 500         /**************************************************************************/
 501                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 502                 c++;
 503 
 504                 if (!strcasecmp(argv[c], "link")) {
 505                 /**********************************************************************/
 506                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 507                         c++;
 508                         
 509                         handle_tx_lpo(stream, argv[c]);
 510                 /**********************************************************************/
 511                 } else {
 512                 /**********************************************************************/
 513                         stream->write_function(stream, "Unknown \"lpo\" command\n");
 514                         goto handle_cli_error;
 515                 /**********************************************************************/
 516                 }
 517         /**************************************************************************/
 518         } else if (!strcasecmp(argv[c], "lpr")) {
 519         /**************************************************************************/
 520                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 521                 c++;
 522 
 523                 if (!strcasecmp(argv[c], "link")) {
 524                 /**********************************************************************/
 525                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 526                         c++;
 527                         
 528                         handle_tx_lpr(stream, argv[c]);
 529                 /**********************************************************************/
 530                 } else {
 531                 /**********************************************************************/
 532                         stream->write_function(stream, "Unknown \"lpr\" command\n");
 533                         goto handle_cli_error;
 534                 /**********************************************************************/
 535                 }
 536         /**************************************************************************/
 537         } else if (!strcasecmp(argv[c], "activate")) {
 538         /**************************************************************************/
 539                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 540                 c++;
 541 
 542                 if (!strcasecmp(argv[c], "link")) {
 543                 /**********************************************************************/
 544                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 545                         c++;
 546                         
 547                         handle_activate_link(stream, argv[c]);
 548                 /**********************************************************************/
 549                 }else if (!strcasecmp(argv[c], "linkset")) {
 550                 /**********************************************************************/
 551                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 552                         c++;
 553                         
 554                         handle_activate_linkset(stream, argv[c]);
 555                 /**********************************************************************/
 556                 } else {
 557                 /**********************************************************************/
 558                         stream->write_function(stream, "Unknown \"activate\" command\n");
 559                         goto handle_cli_error;
 560                 /**********************************************************************/
 561                 }
 562         /**************************************************************************/
 563         } else if (!strcasecmp(argv[c], "deactivate")) {
 564         /**************************************************************************/
 565                 if (check_arg_count(argc, 2)) goto handle_cli_error_argc;
 566                 c++;
 567 
 568                 if (!strcasecmp(argv[c], "link")) {
 569                 /**********************************************************************/
 570                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 571                         c++;
 572                         
 573                         handle_deactivate_link(stream, argv[c]);
 574                 /**********************************************************************/
 575                 }else if (!strcasecmp(argv[c], "linkset")) {
 576                 /**********************************************************************/
 577                         if (check_arg_count(argc, 3)) goto handle_cli_error_argc;
 578                         c++;
 579                         
 580                         handle_deactivate_linkset(stream, argv[c]);
 581                 /**********************************************************************/
 582                 } else {
 583                 /**********************************************************************/
 584                         stream->write_function(stream, "Unknown \"deactivate\" command\n");
 585                         goto handle_cli_error;
 586                 /**********************************************************************/
 587                 }
 588         /**************************************************************************/    
 589         } else {
 590         /**************************************************************************/
 591                 goto handle_cli_error;
 592         /**************************************************************************/
 593         }
 594 
 595         return FTDM_SUCCESS;
 596 
 597 handle_cli_error_argc:
 598         stream->write_function(stream, "Invalid # of arguments in command\n");
 599         handle_print_usuage(stream);
 600         return FTDM_SUCCESS;
 601 
 602 handle_cli_error_span_chan:
 603         stream->write_function(stream, "Unknown \"span\\chan\" command\n");
 604         handle_print_usuage(stream);
 605         return FTDM_SUCCESS;
 606 
 607 handle_cli_error:
 608         stream->write_function(stream, "Unknown command requested\n");
 609         handle_print_usuage(stream);
 610         return FTDM_SUCCESS;
 611 }
 612 
 613 /******************************************************************************/
 614 static ftdm_status_t handle_print_usuage(ftdm_stream_handle_t *stream)
 615 {
 616         stream->write_function(stream, "Sangoma SS7 CLI usuage:\n\n");
 617 
 618         stream->write_function(stream, "Ftmod_sangoma_ss7 general control:\n");
 619         stream->write_function(stream, "ftdm ss7 set ftrace X Y\n");
 620         stream->write_function(stream, "ftdm ss7 set mtrace X Y\n");
 621         stream->write_function(stream, "\n");
 622         stream->write_function(stream, "Ftmod_sangoma_ss7 information:\n");
 623         stream->write_function(stream, "ftdm ss7 show status link X\n");
 624         stream->write_function(stream, "ftdm ss7 show status linkset X\n");
 625         stream->write_function(stream, "ftdm ss7 show status span X chan Y\n");
 626         stream->write_function(stream, "ftdm ss7 show free span X chan Y\n");
 627         stream->write_function(stream, "ftdm ss7 show inuse span X chan Y\n");
 628         stream->write_function(stream, "ftdm ss7 show inreset span X chan Y\n");
 629         stream->write_function(stream, "\n");
 630         stream->write_function(stream, "Ftmod_sangoma_ss7 circuit control:\n");
 631         stream->write_function(stream, "ftdm ss7 blo span X chan Y\n");
 632         stream->write_function(stream, "ftdm ss7 ubl span X chan Y\n");
 633         stream->write_function(stream, "ftdm ss7 rsc span X chan Y\n");
 634         stream->write_function(stream, "ftdm ss7 grs span X chan Y range Z\n");
 635         stream->write_function(stream, "ftdm ss7 cgb span X chan Y range Z\n");
 636         stream->write_function(stream, "ftdm ss7 cgu span X chan Y range Z\n");
 637         stream->write_function(stream, "\n");
 638         stream->write_function(stream, "Ftmod_sangoma_ss7 link control:\n");
 639         stream->write_function(stream, "ftdm ss7 inhibit link X\n");
 640         stream->write_function(stream, "ftdm ss7 uninhibit link X\n");
 641         stream->write_function(stream, "ftdm ss7 activate link X\n");
 642         stream->write_function(stream, "ftdm ss7 deactivate link X\n");
 643         stream->write_function(stream, "ftdm ss7 activate linkset X\n");
 644         stream->write_function(stream, "ftdm ss7 deactivate linkset X\n");
 645         stream->write_function(stream, "ftdm ss7 lpo link X\n");
 646         stream->write_function(stream, "ftdm ss7 lpr link X\n");
 647         stream->write_function(stream, "\n");
 648 
 649         return FTDM_SUCCESS;
 650 }
 651 
 652 /******************************************************************************/
 653 static ftdm_status_t handle_set_function_trace(ftdm_stream_handle_t *stream, int on, int level)
 654 {
 655         stream->write_function(stream, "ftmod_sangoma_ss7 Function Trace was %s, level = %d\n",
 656                                                         (g_ftdm_sngss7_data.function_trace == 1) ? "ON" : "OFF",
 657                                                         g_ftdm_sngss7_data.function_trace_level);
 658 
 659         g_ftdm_sngss7_data.function_trace = on;
 660         g_ftdm_sngss7_data.function_trace_level = level;
 661 
 662         stream->write_function(stream, "ftmod_sangoma_ss7 Function Trace now is %s, level = %d\n",
 663                                                         (g_ftdm_sngss7_data.function_trace == 1) ? "ON" : "OFF",
 664                                                         g_ftdm_sngss7_data.function_trace_level);
 665 
 666         return FTDM_SUCCESS;
 667 }
 668 
 669 /******************************************************************************/
 670 static ftdm_status_t handle_set_message_trace(ftdm_stream_handle_t *stream, int on, int level)
 671 {
 672         stream->write_function(stream, "ftmod_sangoma_ss7 Message Trace was %s, level = %d\n",
 673                                                         (g_ftdm_sngss7_data.message_trace == 1) ? "ON" : "OFF",
 674                                                         g_ftdm_sngss7_data.message_trace_level);
 675 
 676         g_ftdm_sngss7_data.message_trace = on;
 677         g_ftdm_sngss7_data.message_trace_level = level;
 678 
 679         stream->write_function(stream, "ftmod_sangoma_ss7 Message Trace now is %s, level = %d\n",
 680                                                         (g_ftdm_sngss7_data.message_trace == 1) ? "ON" : "OFF",
 681                                                         g_ftdm_sngss7_data.message_trace_level);
 682 
 683         return FTDM_SUCCESS;
 684 }
 685 
 686 /******************************************************************************/
 687 static ftdm_status_t handle_show_free(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
 688 {
 689         int                              x;
 690         int                              free;
 691         sngss7_chan_data_t  *ss7_info;
 692         ftdm_channel_t    *ftdmchan;
 693         int                              lspan;
 694         int                              lchan;
 695 
 696         x=1;
 697         free = 0;
 698         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
 699                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
 700                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
 701                         ftdmchan = ss7_info->ftdmchan;
 702 
 703                         /* if span == 0 then all spans should be printed */
 704                         if (span == 0) {
 705                                 lspan = ftdmchan->physical_span_id;
 706                         } else {
 707                                 lspan = span;
 708                         }
 709 
 710                         /* if chan == 0 then all chans should be printed */
 711                         if (chan == 0) {
 712                                 lchan = ftdmchan->physical_chan_id;
 713                         } else {
 714                                 lchan = chan;
 715                         }
 716 
 717                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
 718                                 switch (ftdmchan->state) {
 719                                 /******************************************************************/
 720                                 case (FTDM_CHANNEL_STATE_DOWN):
 721                                         if (verbose) {
 722                                                 stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d|state=%s\n",
 723                                                                         ftdmchan->physical_span_id,
 724                                                                         ftdmchan->physical_chan_id,
 725                                                                         ss7_info->circuit->cic,
 726                                                                         ftdm_channel_state2str(ftdmchan->state));
 727                                         } /* if (verbose) */
 728 
 729                                         /*increment the count of circuits in reset */
 730                                         free++;
 731                                         break;
 732                                 /******************************************************************/
 733                                 default:
 734                                         break;
 735                                 /******************************************************************/
 736                                 } /* switch (ftdmchan->state) */
 737                         } /* if ( span and chan) */
 738                 } /* if ( cic != 0) */
 739 
 740                 /* go the next circuit */
 741                 x++;
 742         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
 743 
 744         stream->write_function(stream, "\nTotal # of CICs free = %d\n",free);
 745 
 746         return FTDM_SUCCESS;
 747 }
 748 
 749 /******************************************************************************/
 750 static ftdm_status_t handle_show_inuse(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
 751 {
 752         int                              x;
 753         int                              in_use;
 754         sngss7_chan_data_t  *ss7_info;
 755         ftdm_channel_t    *ftdmchan;
 756         int                              lspan;
 757         int                              lchan;
 758 
 759         x=1;
 760         in_use = 0;
 761         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
 762                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
 763                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
 764                         ftdmchan = ss7_info->ftdmchan;
 765 
 766                         /* if span == 0 then all spans should be printed */
 767                         if (span == 0) {
 768                                 lspan = ftdmchan->physical_span_id;
 769                         } else {
 770                                 lspan = span;
 771                         }
 772 
 773                         /* if chan == 0 then all chans should be printed */
 774                         if (chan == 0) {
 775                                 lchan = ftdmchan->physical_chan_id;
 776                         } else {
 777                                 lchan = chan;
 778                         }
 779 
 780                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
 781                                 switch (ftdmchan->state) {
 782                                 /******************************************************************/
 783                                 case (FTDM_CHANNEL_STATE_COLLECT):
 784                                 case (FTDM_CHANNEL_STATE_RING):
 785                                 case (FTDM_CHANNEL_STATE_DIALING):
 786                                 case (FTDM_CHANNEL_STATE_PROGRESS):
 787                                 case (FTDM_CHANNEL_STATE_PROGRESS_MEDIA):
 788                                 case (FTDM_CHANNEL_STATE_UP):
 789                                 case (FTDM_CHANNEL_STATE_TERMINATING):
 790                                 case (FTDM_CHANNEL_STATE_HANGUP):
 791                                         if (verbose) {
 792                                                 stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d|state=%s\n",
 793                                                                         ftdmchan->physical_span_id,
 794                                                                         ftdmchan->physical_chan_id,
 795                                                                         ss7_info->circuit->cic,
 796                                                                         ftdm_channel_state2str(ftdmchan->state));
 797                                         } /* if (verbose) */
 798 
 799                                         /*increment the count of circuits in reset */
 800                                         in_use++;
 801                                         break;
 802                                 /******************************************************************/
 803                                 default:
 804                                         break;
 805                                 /******************************************************************/
 806                                 } /* switch (ftdmchan->state) */
 807                         } /* if ( span and chan) */
 808                 } /* if ( cic != 0) */
 809 
 810                 /* go the next circuit */
 811                 x++;
 812         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
 813 
 814         stream->write_function(stream, "\nTotal # of CICs in use = %d\n",in_use);
 815 
 816         return FTDM_SUCCESS;
 817 }
 818 
 819 /******************************************************************************/
 820 static ftdm_status_t handle_show_inreset(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
 821 {
 822         int                              x;
 823         int                              in_reset;
 824         sngss7_chan_data_t  *ss7_info;
 825         ftdm_channel_t    *ftdmchan;
 826         int                              lspan;
 827         int                              lchan;
 828 
 829         x=1;
 830         in_reset = 0;
 831         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
 832                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
 833                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
 834                         ftdmchan = ss7_info->ftdmchan;
 835 
 836                         /* if span == 0 then all spans should be printed */
 837                         if (span == 0) {
 838                                 lspan = ftdmchan->physical_span_id;
 839                         } else {
 840                                 lspan = span;
 841                         }
 842 
 843                         /* if chan == 0 then all chans should be printed */
 844                         if (chan == 0) {
 845                                 lchan = ftdmchan->physical_chan_id;
 846                         } else {
 847                                 lchan = chan;
 848                         }
 849 
 850                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
 851                                 if ((sngss7_test_flag(ss7_info, FLAG_RESET_RX)) ||
 852                                         (sngss7_test_flag(ss7_info, FLAG_RESET_TX)) ||
 853                                         (sngss7_test_flag(ss7_info, FLAG_GRP_RESET_RX)) ||
 854                                         (sngss7_test_flag(ss7_info, FLAG_GRP_RESET_TX))) {
 855                                         
 856                                         if (verbose) {
 857                                                 stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d|in_reset=Y\n",
 858                                                                         ftdmchan->physical_span_id,
 859                                                                         ftdmchan->physical_chan_id,
 860                                                                         ss7_info->circuit->cic);
 861                                         } /* if (verbose) */
 862                 
 863                                         /*increment the count of circuits in reset */
 864                                         in_reset++;
 865                                 } /* if ((sngss7_test_flag(ss7_info, FLAG_RESET_RX) ... */
 866                         } /* if ( span and chan) */
 867                 } /* if ( cic != 0) */
 868 
 869                 /* go the next circuit */
 870                 x++;
 871         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
 872 
 873         stream->write_function(stream, "\nTotal # of CICs in reset = %d\n",in_reset);
 874 
 875         return FTDM_SUCCESS;
 876 }
 877 
 878 /******************************************************************************/
 879 static ftdm_status_t handle_show_flags(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
 880 {
 881         int                              x;
 882         int                              bit;
 883         sngss7_chan_data_t  *ss7_info;
 884         ftdm_channel_t    *ftdmchan;
 885         int                              lspan;
 886         int                              lchan;
 887 
 888         x=1;
 889         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
 890                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
 891                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
 892                         ftdmchan = ss7_info->ftdmchan;
 893 
 894                         /* if span == 0 then all spans should be printed */
 895                         if (span == 0) {
 896                                 lspan = ftdmchan->physical_span_id;
 897                         } else {
 898                                 lspan = span;
 899                         }
 900 
 901                         /* if chan == 0 then all chans should be printed */
 902                         if (chan == 0) {
 903                                 lchan = ftdmchan->physical_chan_id;
 904                         } else {
 905                                 lchan = chan;
 906                         }
 907 
 908                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
 909                                 stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d",
 910                                                         ftdmchan->physical_span_id,
 911                                                         ftdmchan->physical_chan_id,
 912                                                         ss7_info->circuit->cic);
 913         
 914                                 for (bit = 0; bit < 33; bit++) {
 915                                         stream->write_function(stream, "|");
 916                                         if (ss7_info->flags & ( 0x1 << bit)) {
 917                                                 stream->write_function(stream, "%2d=1", bit);
 918                                         } else {
 919                                                 stream->write_function(stream, "%2d=0", bit);
 920                                         }
 921                                 }
 922 
 923                                 stream->write_function(stream, "\n");
 924                         } /* if ( span and chan) */
 925 
 926                 } /* if ( cic != 0) */
 927 
 928                 /* go the next circuit */
 929                 x++;
 930         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
 931 
 932         return FTDM_SUCCESS;
 933 }
 934 
 935 /******************************************************************************/
 936 static ftdm_status_t handle_show_blocks(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
 937 {
 938         int                              x;
 939         sngss7_chan_data_t  *ss7_info;
 940         ftdm_channel_t    *ftdmchan;
 941         int                              lspan;
 942         int                              lchan;
 943 
 944         x=1;
 945         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
 946                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
 947                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
 948                         ftdmchan = ss7_info->ftdmchan;
 949 
 950                         /* if span == 0 then all spans should be printed */
 951                         if (span == 0) {
 952                                 lspan = ftdmchan->physical_span_id;
 953                         } else {
 954                                 lspan = span;
 955                         }
 956 
 957                         /* if chan == 0 then all chans should be printed */
 958                         if (chan == 0) {
 959                                 lchan = ftdmchan->physical_chan_id;
 960                         } else {
 961                                 lchan = chan;
 962                         }
 963 
 964                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
 965                                 stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d|",
 966                                                         ftdmchan->physical_span_id,
 967                                                         ftdmchan->physical_chan_id,
 968                                                         ss7_info->circuit->cic);
 969 
 970                                 if((sngss7_test_flag(ss7_info, FLAG_CKT_MN_BLOCK_TX)) || (sngss7_test_flag(ss7_info, FLAG_GRP_MN_BLOCK_TX))) {
 971                                         stream->write_function(stream, "l_mn=Y|");
 972                                 }else {
 973                                         stream->write_function(stream, "l_mn=N|");
 974                                 }
 975 
 976                                 if((sngss7_test_flag(ss7_info, FLAG_CKT_MN_BLOCK_RX)) || (sngss7_test_flag(ss7_info, FLAG_GRP_MN_BLOCK_RX))) {
 977                                         stream->write_function(stream, "r_mn=Y|");
 978                                 }else {
 979                                         stream->write_function(stream, "r_mn=N|");
 980                                 }
 981 
 982                                 if(sngss7_test_flag(ss7_info, FLAG_GRP_HW_BLOCK_TX)) {
 983                                         stream->write_function(stream, "l_hw=Y|");
 984                                 }else {
 985                                         stream->write_function(stream, "l_hw=N|");
 986                                 }
 987 
 988                                 if(sngss7_test_flag(ss7_info, FLAG_GRP_HW_BLOCK_RX)) {
 989                                         stream->write_function(stream, "r_hw=Y|");
 990                                 }else {
 991                                         stream->write_function(stream, "r_hw=N|");
 992                                 }
 993 
 994                                 if(sngss7_test_flag(ss7_info, FLAG_CKT_LC_BLOCK_RX)) {
 995                                         stream->write_function(stream, "l_mngmt=Y|");
 996                                 }else {
 997                                         stream->write_function(stream, "l_mngmt=N|");
 998                                 }
 999 
1000                                 if(sngss7_test_flag(ss7_info, FLAG_CKT_UCIC_BLOCK)) {
1001                                         stream->write_function(stream, "l_ucic=Y|");
1002                                 }else {
1003                                         stream->write_function(stream, "l_ucic=N|");
1004                                 } 
1005 
1006                                 stream->write_function(stream, "\n");                           
1007                         } /* if ( span and chan) */
1008 
1009                 } /* if ( cic != 0) */
1010 
1011                 /* go the next circuit */
1012                 x++;
1013         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1014 
1015         return FTDM_SUCCESS;
1016 }
1017 
1018 /******************************************************************************/
1019 static ftdm_status_t handle_show_status(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
1020 {
1021         int                                                     x;
1022         sngss7_chan_data_t              *ss7_info;
1023         ftdm_channel_t                          *ftdmchan;
1024         int                                                     lspan;
1025         int                                                     lchan;
1026         ftdm_signaling_status_t         sigstatus = FTDM_SIG_STATE_DOWN;
1027         sng_isup_ckt_t                          *ckt;
1028 
1029         x=1;
1030         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1031                         /* extract the circuit to make it easier to work with */
1032                         ckt = &g_ftdm_sngss7_data.cfg.isupCkt[x];
1033 
1034                         /* if span == 0 then all spans should be printed */
1035                         if (span == 0) {
1036                                 lspan = ckt->span;
1037                         } else {
1038                                 lspan = span;
1039                         }
1040 
1041                         /* if chan == 0 then all chans should be printed */
1042                         if (chan == 0) {
1043                                 lchan = ckt->chan;
1044                         } else {
1045                                 lchan = chan;
1046                         }
1047 
1048                         /* check if this circuit is one of the circuits we're interested in */
1049                         if ((ckt->span == lspan) && (ckt->chan == lchan)) {
1050                                 if (ckt->type == HOLE) {
1051                                         stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d|NOT USED\n",
1052                                                         ckt->span,
1053                                                         ckt->chan,
1054                                                         ckt->cic);
1055                                 } else if (ckt->type == SIG) {
1056                                         stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d|SIGNALING LINK\n",
1057                                                         ckt->span,
1058                                                         ckt->chan,
1059                                                         ckt->cic);
1060                                 } else {
1061                                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1062                                         ftdmchan = ss7_info->ftdmchan;
1063 
1064                                         /* grab the signaling_status */
1065                                         ftdm_channel_get_sig_status(ftdmchan, &sigstatus);
1066         
1067                                         stream->write_function(stream, "span=%2d|chan=%2d|cic=%4d|sig_status=%4s|state=%s|",
1068                                                                                                         ckt->span,
1069                                                                                                         ckt->chan,
1070                                                                                                         ckt->cic,
1071                                                                                                         ftdm_signaling_status2str(sigstatus),
1072                                                                                                         ftdm_channel_state2str(ftdmchan->state));
1073         
1074                                         if((sngss7_test_flag(ss7_info, FLAG_CKT_MN_BLOCK_TX)) || (sngss7_test_flag(ss7_info, FLAG_GRP_MN_BLOCK_TX))) {
1075                                                 stream->write_function(stream, "l_mn=Y|");
1076                                         }else {
1077                                                 stream->write_function(stream, "l_mn=N|");
1078                                         }
1079         
1080                                         if((sngss7_test_flag(ss7_info, FLAG_CKT_MN_BLOCK_RX)) || (sngss7_test_flag(ss7_info, FLAG_GRP_MN_BLOCK_RX))) {
1081                                                 stream->write_function(stream, "r_mn=Y|");
1082                                         }else {
1083                                                 stream->write_function(stream, "r_mn=N|");
1084                                         }
1085         
1086                                         if(sngss7_test_flag(ss7_info, FLAG_GRP_HW_BLOCK_TX)) {
1087                                                 stream->write_function(stream, "l_hw=Y|");
1088                                         }else {
1089                                                 stream->write_function(stream, "l_hw=N|");
1090                                         }
1091         
1092                                         if(sngss7_test_flag(ss7_info, FLAG_GRP_HW_BLOCK_RX)) {
1093                                                 stream->write_function(stream, "r_hw=Y|");
1094                                         }else {
1095                                                 stream->write_function(stream, "r_hw=N|");
1096                                         }
1097         
1098                                         if(sngss7_test_flag(ss7_info, FLAG_CKT_LC_BLOCK_RX)) {
1099                                                 stream->write_function(stream, "l_mngmt=Y|");
1100                                         }else {
1101                                                 stream->write_function(stream, "l_mngmt=N|");
1102                                         }
1103         
1104                                         if(sngss7_test_flag(ss7_info, FLAG_CKT_UCIC_BLOCK)) {
1105                                                 stream->write_function(stream, "l_ucic=Y|");
1106                                         }else {
1107                                                 stream->write_function(stream, "l_ucic=N|");
1108                                         }                               
1109         
1110                                         stream->write_function(stream, "flags=0x%X",ss7_info->flags);
1111         
1112                                         stream->write_function(stream, "\n");
1113                                 } /* if ( hole, sig, voice) */
1114                         } /* if ( span and chan) */
1115                 /* go the next circuit */
1116                 x++;
1117         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1118 
1119         return FTDM_SUCCESS;
1120 }
1121 /******************************************************************************/
1122 static ftdm_status_t handle_tx_blo(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
1123 {
1124         int                              x;
1125         sngss7_chan_data_t  *ss7_info;
1126         ftdm_channel_t    *ftdmchan;
1127         int                              lspan;
1128         int                              lchan;
1129 
1130         x=1;
1131         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1132                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1133                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1134                         ftdmchan = ss7_info->ftdmchan;
1135 
1136                         /* if span == 0 then all spans should be printed */
1137                         if (span == 0) {
1138                                 lspan = ftdmchan->physical_span_id;
1139                         } else {
1140                                 lspan = span;
1141                         }
1142 
1143                         /* if chan == 0 then all chans should be printed */
1144                         if (chan == 0) {
1145                                 lchan = ftdmchan->physical_chan_id;
1146                         } else {
1147                                 lchan = chan;
1148                         }
1149 
1150                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
1151                                 /* now that we have the right channel...put a lock on it so no-one else can use it */
1152                                 ftdm_mutex_lock(ftdmchan->mutex);
1153 
1154                                 /* check if there is a pending state change|give it a bit to clear */
1155                                 if (check_for_state_change(ftdmchan)) {
1156                                         SS7_ERROR("Failed to wait for pending state change on CIC = %d\n", ss7_info->circuit->cic);
1157                                         /* check if we need to die */
1158                                         SS7_ASSERT;
1159                                         /* unlock the channel again before we exit */
1160                                         ftdm_mutex_unlock(ftdmchan->mutex);
1161                                         /* move to the next channel */
1162                                         continue;
1163                                 } else {
1164                                         /* throw the ckt block flag */
1165                                         sngss7_set_flag(ss7_info, FLAG_CKT_MN_BLOCK_TX);
1166 
1167                                         /* set the channel to suspended state */
1168                                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED);
1169                                 }
1170 
1171                                 /* unlock the channel again before we exit */
1172                                 ftdm_mutex_unlock(ftdmchan->mutex);
1173 
1174                         } /* if ( span and chan) */
1175 
1176                 } /* if ( cic != 0) */
1177 
1178                 /* go the next circuit */
1179                 x++;
1180         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1181 
1182         handle_show_blocks(stream, span, chan, verbose);
1183 
1184         return FTDM_SUCCESS;
1185 }
1186 
1187 /******************************************************************************/
1188 static ftdm_status_t handle_tx_ubl(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
1189 {
1190         int                              x;
1191         sngss7_chan_data_t  *ss7_info;
1192         ftdm_channel_t    *ftdmchan;
1193         int                              lspan;
1194         int                              lchan;
1195 
1196         x=1;
1197         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1198                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1199                         ss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1200                         ftdmchan = ss7_info->ftdmchan;
1201 
1202                         /* if span == 0 then all spans should be printed */
1203                         if (span == 0) {
1204                                 lspan = ftdmchan->physical_span_id;
1205                         } else {
1206                                 lspan = span;
1207                         }
1208 
1209                         /* if chan == 0 then all chans should be printed */
1210                         if (chan == 0) {
1211                                 lchan = ftdmchan->physical_chan_id;
1212                         } else {
1213                                 lchan = chan;
1214                         }
1215 
1216                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
1217                                 /* now that we have the right channel...put a lock on it so no-one else can use it */
1218                                 ftdm_mutex_lock(ftdmchan->mutex);
1219 
1220                                 /* check if there is a pending state change|give it a bit to clear */
1221                                 if (check_for_state_change(ftdmchan)) {
1222                                         SS7_ERROR("Failed to wait for pending state change on CIC = %d\n", ss7_info->circuit->cic);
1223                                         /* check if we need to die */
1224                                         SS7_ASSERT;
1225                                         /* unlock the channel again before we exit */
1226                                         ftdm_mutex_unlock(ftdmchan->mutex);
1227                                         /* move to the next channel */
1228                                         continue;
1229                                 } else {
1230                                         /* throw the ckt block flag */
1231                                         sngss7_set_flag(ss7_info, FLAG_CKT_MN_UNBLK_TX);
1232 
1233                                         /* clear the block flag */
1234                                         sngss7_clear_flag(ss7_info, FLAG_CKT_MN_BLOCK_TX);
1235 
1236                                         /* set the channel to suspended state */
1237                                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED);
1238                                 }
1239 
1240                                 /* unlock the channel again before we exit */
1241                                 ftdm_mutex_unlock(ftdmchan->mutex);
1242 
1243                         } /* if ( span and chan) */
1244 
1245                 } /* if ( cic != 0) */
1246 
1247                 /* go the next circuit */
1248                 x++;
1249         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1250 
1251         handle_show_blocks(stream, span, chan, verbose);
1252 
1253         return FTDM_SUCCESS;
1254 }
1255 
1256 /******************************************************************************/
1257 static ftdm_status_t handle_status_link(ftdm_stream_handle_t *stream, char *name)
1258 {
1259         int             x = 0;
1260         SnMngmt         sta;
1261         
1262         /* find the link request by it's name */
1263         x = 1;
1264         while(g_ftdm_sngss7_data.cfg.mtpLink[x].id != 0) {
1265                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLink[x].name, name)) {
1266 
1267                         /* send the status request */
1268                         if (ftmod_ss7_mtplink_sta(x, &sta)) {
1269                                 stream->write_function(stream, "Failed to read link=%s status\n", name);
1270                                 return FTDM_FAIL;
1271                         }
1272 
1273                         /* print the results */
1274                         stream->write_function(stream, "%s|span=%d|chan=%d|sap=%d|state=%s|l_blk=%s|r_blk=%s|l_inhbt=%s|r_inhbt=%s\n",
1275                                                 name,
1276                                                 g_ftdm_sngss7_data.cfg.mtpLink[x].mtp1.span,
1277                                                 g_ftdm_sngss7_data.cfg.mtpLink[x].mtp1.chan,
1278                                                 g_ftdm_sngss7_data.cfg.mtpLink[x].id,
1279                                                 DECODE_LSN_LINK_STATUS(sta.t.ssta.s.snDLSAP.state),
1280                                                 (sta.t.ssta.s.snDLSAP.locBlkd) ? "Y":"N",
1281                                                 (sta.t.ssta.s.snDLSAP.remBlkd) ? "Y":"N",
1282                                                 (sta.t.ssta.s.snDLSAP.locInhbt) ? "Y":"N",
1283                                                 (sta.t.ssta.s.snDLSAP.rmtInhbt) ? "Y":"N");
1284 
1285                         goto success;
1286                 }
1287                 
1288                 /* move to the next link */
1289                 x++;
1290         } /* while (id != 0) */
1291 
1292         stream->write_function(stream, "Failed to find link=\"%s\"\n", name);
1293 
1294 success:
1295         return FTDM_SUCCESS;
1296 }
1297 
1298 /******************************************************************************/
1299 static ftdm_status_t handle_status_linkset(ftdm_stream_handle_t *stream, char *name)
1300 {
1301         int             x = 0;
1302         SnMngmt         sta;
1303 
1304         /* find the linkset request by it's name */
1305         x = 1;
1306         while(g_ftdm_sngss7_data.cfg.mtpLinkSet[x].id != 0) {
1307                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLinkSet[x].name, name)) {
1308 
1309                         /* send the status request */
1310                         if (ftmod_ss7_mtplinkSet_sta(x, &sta)) {
1311                                 stream->write_function(stream, "Failed to read linkset=%s status\n", name);
1312                                 return FTDM_FAIL;
1313                         }
1314 
1315                         /* print the results */
1316                         stream->write_function(stream, "%s|state=%s|nmbActLnk=%d\n",
1317                                                 name,
1318                                                 DECODE_LSN_LINKSET_STATUS(sta.t.ssta.s.snLnkSet.state),
1319                                                 sta.t.ssta.s.snLnkSet.nmbActLnks);
1320                         
1321                         goto success;
1322                 }
1323  
1324                 /* move to the next linkset */
1325                 x++;
1326         } /* while (id != 0) */
1327 
1328         stream->write_function(stream, "Failed to find link=\"%s\"\n", name);
1329 
1330 success:
1331         return FTDM_SUCCESS;
1332 }
1333 
1334 /******************************************************************************/
1335 static ftdm_status_t handle_set_inhibit(ftdm_stream_handle_t *stream, char *name)
1336 {
1337         int             x = 0;
1338 
1339         /* find the link request by it's name */
1340         x = 1;
1341         while(g_ftdm_sngss7_data.cfg.mtpLink[x].id != 0) {
1342                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLink[x].name, name)) {
1343 
1344                         /* send the inhibit request */
1345                         if (ftmod_ss7_inhibit_mtplink(x)) {
1346                                 stream->write_function(stream, "Failed to inhibit link=%s\n", name);
1347                                 return FTDM_FAIL;
1348                         }
1349 
1350                         /* print the new status of the link */
1351                         handle_status_link(stream, &name[0]);
1352 
1353                         goto success;
1354                 }
1355  
1356                 /* move to the next linkset */
1357                 x++;
1358         } /* while (id != 0) */
1359 
1360         stream->write_function(stream, "Failed to find link=\"%s\"\n", name);
1361 
1362 success:
1363         return FTDM_SUCCESS;
1364 }
1365 
1366 /******************************************************************************/
1367 static ftdm_status_t handle_set_uninhibit(ftdm_stream_handle_t *stream, char *name)
1368 {
1369         int             x = 0;
1370 
1371         /* find the link request by it's name */
1372         x = 1;
1373         while(g_ftdm_sngss7_data.cfg.mtpLink[x].id != 0) {
1374                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLink[x].name, name)) {
1375 
1376                         /* send the uninhibit request */
1377                         if (ftmod_ss7_uninhibit_mtplink(x)) {
1378                                 stream->write_function(stream, "Failed to uninhibit link=%s\n", name);
1379                                 return FTDM_FAIL;
1380                         }
1381 
1382                         /* print the new status of the link */
1383                         handle_status_link(stream, &name[0]);
1384 
1385                         goto success;
1386                 }
1387  
1388                 /* move to the next linkset */
1389                 x++;
1390         } /* while (id != 0) */
1391 
1392         stream->write_function(stream, "Failed to find link=\"%s\"\n", name);
1393 
1394 success:
1395         return FTDM_SUCCESS;
1396 }
1397 
1398 /******************************************************************************/
1399 static ftdm_status_t handle_tx_rsc(ftdm_stream_handle_t *stream, int span, int chan, int verbose)
1400 {
1401         int                                     x;
1402         sngss7_chan_data_t  *sngss7_info;
1403         ftdm_channel_t          *ftdmchan;
1404         int                                     lspan;
1405         int                                     lchan;
1406 
1407         x=1;
1408         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1409                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1410                         sngss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1411                         ftdmchan = sngss7_info->ftdmchan;
1412 
1413                         /* if span == 0 then all spans should be printed */
1414                         if (span == 0) {
1415                                 lspan = ftdmchan->physical_span_id;
1416                         } else {
1417                                 lspan = span;
1418                         }
1419 
1420                         /* if chan == 0 then all chans should be printed */
1421                         if (chan == 0) {
1422                                 lchan = ftdmchan->physical_chan_id;
1423                         } else {
1424                                 lchan = chan;
1425                         }
1426 
1427                         if ((ftdmchan->physical_span_id == lspan) && (ftdmchan->physical_chan_id == lchan)) {
1428                                 /* lock the channel */
1429                                 ftdm_mutex_lock(ftdmchan->mutex);
1430 
1431                                 /* throw the reset flag */
1432                                 sngss7_set_flag(sngss7_info, FLAG_RESET_TX);
1433 
1434                                 switch (ftdmchan->state) {
1435                                 /**************************************************************************/
1436                                 case FTDM_CHANNEL_STATE_RESTART:
1437                                         /* go to idle so that we can redo the restart state*/
1438                                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE);
1439                                         break;
1440                                 /**************************************************************************/
1441                                 default:
1442                                         /* set the state of the channel to restart...the rest is done by the chan monitor */
1443                                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
1444                                         break;
1445                                 /**************************************************************************/
1446                                 }
1447                         
1448                                 /* unlock the channel again before we exit */
1449                                 ftdm_mutex_unlock(ftdmchan->mutex);
1450                         } /* if ( span and chan) */
1451 
1452                 } /* if ( cic == voice) */
1453 
1454                 /* go the next circuit */
1455                 x++;
1456         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1457 
1458         /* print the status of channels */
1459         handle_show_status(stream, span, chan, verbose);
1460         
1461         
1462 
1463         return FTDM_SUCCESS;
1464 }
1465 
1466 /******************************************************************************/
1467 static ftdm_status_t handle_tx_grs(ftdm_stream_handle_t *stream, int span, int chan, int range, int verbose)
1468 {
1469         int                                     x;
1470         sngss7_chan_data_t      *sngss7_info;
1471         ftdm_channel_t          *ftdmchan;
1472         sngss7_span_data_t      *sngss7_span;
1473 
1474         if (range > 31) {
1475                 stream->write_function(stream, "Invalid range value %d", range);
1476                 return FTDM_SUCCESS;
1477         }
1478 
1479         x=1;
1480         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1481                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1482 
1483                         sngss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1484                         ftdmchan = sngss7_info->ftdmchan;
1485                         sngss7_span = ftdmchan->span->signal_data;
1486 
1487                         if ((ftdmchan->physical_span_id == span) && 
1488                                 ((ftdmchan->physical_chan_id >= chan) && (ftdmchan->physical_chan_id < (chan+range)))) {
1489                                 /* now that we have the right channel...put a lock on it so no-one else can use it */
1490                                 ftdm_mutex_lock(ftdmchan->mutex);
1491 
1492                                 /* check if there is a pending state change|give it a bit to clear */
1493                                 if (check_for_state_change(ftdmchan)) {
1494                                         SS7_ERROR("Failed to wait for pending state change on CIC = %d\n", sngss7_info->circuit->cic);
1495                                         /* check if we need to die */
1496                                         SS7_ASSERT;
1497                                         /* unlock the channel again before we exit */
1498                                         ftdm_mutex_unlock(ftdmchan->mutex);
1499                                         /* move to the next channel */
1500                                         continue;
1501                                 } else {
1502                                         /* throw the grp reset flag */
1503                                         sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX);
1504                                         if (ftdmchan->physical_chan_id == chan) {
1505                                                 sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_BASE);
1506                                                 sngss7_span->tx_grs.circuit = sngss7_info->circuit->id;
1507                                                 sngss7_span->tx_grs.range = range-1;
1508                                         }
1509 
1510                                         /* set the channel to suspended state */
1511                                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
1512 
1513                                 }
1514 
1515                                 /* unlock the channel again before we exit */
1516                                 ftdm_mutex_unlock(ftdmchan->mutex);
1517 
1518                         } /* if ( span and chan) */
1519 
1520                 } /* if ( cic != 0) */
1521 
1522                 /* go the next circuit */
1523                 x++;
1524         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1525         
1526         x=1;
1527         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1528                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1529 
1530                         sngss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1531                         ftdmchan = sngss7_info->ftdmchan;
1532                         sngss7_span = ftdmchan->span->signal_data;
1533 
1534                         if ((ftdmchan->physical_span_id == span) && 
1535                                 ((ftdmchan->physical_chan_id >= chan) && (ftdmchan->physical_chan_id < (chan+range)))) {
1536 
1537                                 handle_show_status(stream, span, chan, verbose);
1538                         }
1539                 } /* if ( cic == voice) */
1540 
1541                 /* go the next circuit */
1542                 x++;
1543         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1544 
1545         return FTDM_SUCCESS;
1546 }
1547 
1548 /******************************************************************************/
1549 static ftdm_status_t handle_tx_cgb(ftdm_stream_handle_t *stream, int span, int chan, int range, int verbose)
1550 {
1551         int                                     x;
1552         sngss7_chan_data_t      *sngss7_info;
1553         ftdm_channel_t          *ftdmchan;
1554         ftdm_channel_t          *main_chan = NULL;
1555         sngss7_span_data_t      *sngss7_span;
1556         int                                     byte = 0;
1557         int                                     bit = 0;
1558         ftdm_sigmsg_t           sigev;
1559 
1560         memset (&sigev, 0, sizeof (sigev));
1561 
1562 
1563         if (range > 31) {
1564                 stream->write_function(stream, "Invalid range value %d", range);
1565                 return FTDM_SUCCESS;
1566         }
1567 
1568         x=1;
1569         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1570                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1571 
1572                         /* extract the channel and span info for this circuit */
1573                         sngss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1574                         ftdmchan = sngss7_info->ftdmchan;
1575                         sngss7_span = ftdmchan->span->signal_data;
1576 
1577                         /* check if this circuit is part of the block */
1578                         if ((ftdmchan->physical_span_id == span) && 
1579                                 ((ftdmchan->physical_chan_id >= chan) && (ftdmchan->physical_chan_id < (chan+range)))) {
1580 
1581                                 /* now that we have the right channel...put a lock on it so no-one else can use it */
1582                                 ftdm_mutex_lock(ftdmchan->mutex);
1583 
1584                                 /* throw the grp maint. block flag */
1585                                 sngss7_set_flag(sngss7_info, FLAG_GRP_MN_BLOCK_TX);
1586 
1587                                 /* bring the sig status down */
1588                                 sigev.chan_id = ftdmchan->chan_id;
1589                                 sigev.span_id = ftdmchan->span_id;
1590                                 sigev.channel = ftdmchan;
1591                                 sigev.event_id = FTDM_SIGEVENT_SIGSTATUS_CHANGED;
1592                                 sigev.ev_data.sigstatus.status = FTDM_SIG_STATE_DOWN;
1593                                 ftdm_span_send_signal(ftdmchan->span, &sigev); 
1594 
1595                                 /* if this is the first channel in the range */
1596                                 if (ftdmchan->physical_chan_id == chan) {
1597                                         /* attach the cgb information */
1598                                         main_chan = ftdmchan;
1599                                         sngss7_span->tx_cgb.circuit = sngss7_info->circuit->id;
1600                                         sngss7_span->tx_cgb.range = range-1;
1601                                         sngss7_span->tx_cgb.type = 0; /* maintenace block */
1602                                 } /* if (ftdmchan->physical_chan_id == chan) */
1603                                 
1604                                 /* update the status field */
1605                                 sngss7_span->tx_cgb.status[byte] = (sngss7_span->tx_cgb.status[byte] | (1 << bit));
1606 
1607                                 /* update the bit and byte counter*/
1608                                 bit ++;
1609                                 if (bit == 8) {
1610                                         byte++;
1611                                         bit = 0;
1612                                 }
1613 
1614                                 /* unlock the channel again before we exit */
1615                                 ftdm_mutex_unlock(ftdmchan->mutex);
1616                         } /* if ( span and chan) */
1617                 } /* if ( cic == voice) */
1618                 /* go the next circuit */
1619                 x++;
1620         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1621 
1622         /* send the circuit group block */
1623         ft_to_sngss7_cgb(main_chan);
1624 
1625         x=1;
1626         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1627                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1628 
1629                         sngss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1630                         ftdmchan = sngss7_info->ftdmchan;
1631                         sngss7_span = ftdmchan->span->signal_data;
1632 
1633                         if ((ftdmchan->physical_span_id == span) && 
1634                                 ((ftdmchan->physical_chan_id >= chan) && (ftdmchan->physical_chan_id < (chan+range)))) {
1635 
1636                                 handle_show_status(stream, span, chan, verbose);
1637                         }
1638                 } /* if ( cic == voice) */
1639 
1640                 /* go the next circuit */
1641                 x++;
1642         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1643         
1644 
1645         return FTDM_SUCCESS;
1646 }
1647 
1648 /******************************************************************************/
1649 static ftdm_status_t handle_tx_cgu(ftdm_stream_handle_t *stream, int span, int chan, int range, int verbose)
1650 {
1651         int                                     x;
1652         sngss7_chan_data_t      *sngss7_info;
1653         ftdm_channel_t          *ftdmchan;
1654         ftdm_channel_t          *main_chan = NULL;
1655         sngss7_span_data_t      *sngss7_span;
1656         int                                     byte = 0;
1657         int                                     bit = 0;
1658         ftdm_sigmsg_t           sigev;
1659 
1660         memset (&sigev, 0, sizeof (sigev));
1661 
1662 
1663         if (range > 31) {
1664                 stream->write_function(stream, "Invalid range value %d", range);
1665                 return FTDM_SUCCESS;
1666         }
1667 
1668         x=1;
1669         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1670                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1671 
1672                         /* extract the channel and span info for this circuit */
1673                         sngss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1674                         ftdmchan = sngss7_info->ftdmchan;
1675                         sngss7_span = ftdmchan->span->signal_data;
1676 
1677                         /* check if this circuit is part of the block */
1678                         if ((ftdmchan->physical_span_id == span) && 
1679                                 ((ftdmchan->physical_chan_id >= chan) && (ftdmchan->physical_chan_id < (chan+range)))) {
1680 
1681                                 /* now that we have the right channel...put a lock on it so no-one else can use it */
1682                                 ftdm_mutex_lock(ftdmchan->mutex);
1683 
1684                                 /* throw the grp maint. block flag */
1685                                 sngss7_clear_flag(sngss7_info, FLAG_GRP_MN_BLOCK_TX);
1686 
1687                                 /* bring the sig status up */
1688                                 sigev.chan_id = ftdmchan->chan_id;
1689                                 sigev.span_id = ftdmchan->span_id;
1690                                 sigev.channel = ftdmchan;
1691                                 sigev.event_id = FTDM_SIGEVENT_SIGSTATUS_CHANGED;
1692                                 sigev.ev_data.sigstatus.status = FTDM_SIG_STATE_UP;
1693                                 ftdm_span_send_signal(ftdmchan->span, &sigev); 
1694 
1695                                 /* if this is the first channel in the range */
1696                                 if (ftdmchan->physical_chan_id == chan) {
1697                                         /* attach the cgb information */
1698                                         main_chan = ftdmchan;
1699                                         sngss7_span->tx_cgu.circuit = sngss7_info->circuit->id;
1700                                         sngss7_span->tx_cgu.range = range-1;
1701                                         sngss7_span->tx_cgu.type = 0; /* maintenace block */
1702                                 } /* if (ftdmchan->physical_chan_id == chan) */
1703                                 
1704                                 /* update the status field */
1705                                 sngss7_span->tx_cgu.status[byte] = (sngss7_span->tx_cgu.status[byte] | (1 << bit));
1706 
1707                                 /* update the bit and byte counter*/
1708                                 bit ++;
1709                                 if (bit == 8) {
1710                                         byte++;
1711                                         bit = 0;
1712                                 }
1713 
1714                                 /* unlock the channel again before we exit */
1715                                 ftdm_mutex_unlock(ftdmchan->mutex);
1716                         } /* if ( span and chan) */
1717                 } /* if ( cic == voice) */
1718                 /* go the next circuit */
1719                 x++;
1720         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1721 
1722         /* send the circuit group block */
1723         ft_to_sngss7_cgu(main_chan);
1724 
1725         x=1;
1726         while (g_ftdm_sngss7_data.cfg.isupCkt[x].id != 0) {
1727                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type == VOICE) {
1728 
1729                         sngss7_info = (sngss7_chan_data_t *)g_ftdm_sngss7_data.cfg.isupCkt[x].obj;
1730                         ftdmchan = sngss7_info->ftdmchan;
1731                         sngss7_span = ftdmchan->span->signal_data;
1732 
1733                         if ((ftdmchan->physical_span_id == span) && 
1734                                 ((ftdmchan->physical_chan_id >= chan) && (ftdmchan->physical_chan_id < (chan+range)))) {
1735 
1736                                 handle_show_status(stream, span, chan, verbose);
1737                         }
1738                 } /* if ( cic == voice) */
1739 
1740                 /* go the next circuit */
1741                 x++;
1742         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[x]id != 0) */
1743         
1744 
1745         return FTDM_SUCCESS;
1746 }
1747 
1748 /******************************************************************************/
1749 static ftdm_status_t handle_activate_link(ftdm_stream_handle_t *stream, char *name)
1750 {
1751         int             x = 0;
1752 
1753         /* find the link request by it's name */
1754         x = 1;
1755         while(g_ftdm_sngss7_data.cfg.mtpLink[x].id != 0) {
1756                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLink[x].name, name)) {
1757 
1758                         /* send the uninhibit request */
1759                         if (ftmod_ss7_activate_mtplink(x)) {
1760                                 stream->write_function(stream, "Failed to activate link=%s\n", name);
1761                                 return FTDM_FAIL;
1762                         }
1763 
1764                         /* print the new status of the link */
1765                         handle_status_link(stream, &name[0]);
1766                         goto success;
1767                 }
1768  
1769                 /* move to the next link */
1770                 x++;
1771         } /* while (id != 0) */
1772 
1773         stream->write_function(stream, "Could not find link=%s\n", name);
1774 
1775 success:
1776         return FTDM_SUCCESS;
1777 }
1778 
1779 /******************************************************************************/
1780 static ftdm_status_t handle_deactivate_link(ftdm_stream_handle_t *stream, char *name)
1781 {
1782         int             x = 0;
1783 
1784         /* find the link request by it's name */
1785         x = 1;
1786         while(g_ftdm_sngss7_data.cfg.mtpLink[x].id != 0) {
1787                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLink[x].name, name)) {
1788 
1789                         /* send the deactivate request */
1790                         if (ftmod_ss7_deactivate2_mtplink(x)) {
1791                                 stream->write_function(stream, "Failed to deactivate link=%s\n", name);
1792                                 return FTDM_FAIL;
1793                         }
1794 
1795                         /* print the new status of the link */
1796                         handle_status_link(stream, &name[0]);
1797                         goto success;
1798                 }
1799  
1800                 /* move to the next link */
1801                 x++;
1802         } /* while (id != 0) */
1803 
1804         stream->write_function(stream, "Could not find link=%s\n", name);
1805 
1806 success:
1807         return FTDM_SUCCESS;
1808 }
1809 
1810 /******************************************************************************/
1811 static ftdm_status_t handle_activate_linkset(ftdm_stream_handle_t *stream, char *name)
1812 {
1813         int             x = 0;
1814 
1815         /* find the linkset request by it's name */
1816         x = 1;
1817         while(g_ftdm_sngss7_data.cfg.mtpLinkSet[x].id != 0) {
1818                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLinkSet[x].name, name)) {
1819 
1820                         /* send the activate request */
1821                         if (ftmod_ss7_activate_mtplinkSet(x)) {
1822                                 stream->write_function(stream, "Failed to activate linkset=%s\n", name);
1823                                 return FTDM_FAIL;
1824                         }
1825 
1826                         /* print the new status of the linkset */
1827                         handle_status_linkset(stream, &name[0]);
1828                         goto success;
1829                 }
1830  
1831                 /* move to the next linkset */
1832                 x++;
1833         } /* while (id != 0) */
1834 
1835         stream->write_function(stream, "Could not find linkset=%s\n", name);
1836 
1837 success:
1838         return FTDM_SUCCESS;
1839 }
1840 
1841 /******************************************************************************/
1842 static ftdm_status_t handle_deactivate_linkset(ftdm_stream_handle_t *stream, char *name)
1843 {
1844         int             x = 0;
1845 
1846         /* find the linkset request by it's name */
1847         x = 1;
1848         while(g_ftdm_sngss7_data.cfg.mtpLinkSet[x].id != 0) {
1849                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLinkSet[x].name, name)) {
1850 
1851                         /* send the deactivate request */
1852                         if (ftmod_ss7_deactivate2_mtplinkSet(x)) {
1853                                 stream->write_function(stream, "Failed to deactivate linkset=%s\n", name);
1854                                 return FTDM_FAIL;
1855                         }
1856 
1857                         /* print the new status of the linkset */
1858                         handle_status_linkset(stream, &name[0]);
1859                         goto success;
1860                 }
1861  
1862                 /* move to the next linkset */
1863                 x++;
1864         } /* while (id != 0) */
1865 
1866         stream->write_function(stream, "Could not find linkset=%s\n", name);
1867 
1868 success:
1869         return FTDM_SUCCESS;
1870 }
1871 
1872 /******************************************************************************/
1873 
1874 static ftdm_status_t handle_tx_lpo(ftdm_stream_handle_t *stream, char *name)
1875 {
1876         int             x = 0;
1877 
1878         /* find the link request by it's name */
1879         x = 1;
1880         while(g_ftdm_sngss7_data.cfg.mtpLink[x].id != 0) {
1881                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLink[x].name, name)) {
1882 
1883                         /* send the uninhibit request */
1884                         if (ftmod_ss7_lpo_mtplink(x)) {
1885                                 stream->write_function(stream, "Failed set LPO link=%s\n", name);
1886                                 return FTDM_FAIL;
1887                         }
1888 
1889                         /* print the new status of the link */
1890                         handle_status_link(stream, &name[0]);
1891                         goto success;
1892                 }
1893  
1894                 /* move to the next link */
1895                 x++;
1896         } /* while (id != 0) */
1897 
1898         stream->write_function(stream, "Could not find link=%s\n", name);
1899 
1900 success:
1901         return FTDM_SUCCESS;
1902 }
1903 
1904 /******************************************************************************/
1905 static ftdm_status_t handle_tx_lpr(ftdm_stream_handle_t *stream, char *name)
1906 {
1907         int             x = 0;
1908 
1909         /* find the link request by it's name */
1910         x = 1;
1911         while(g_ftdm_sngss7_data.cfg.mtpLink[x].id != 0) {
1912                 if (!strcasecmp(g_ftdm_sngss7_data.cfg.mtpLink[x].name, name)) {
1913 
1914                         /* send the uninhibit request */
1915                         if (ftmod_ss7_lpr_mtplink(x)) {
1916                                 stream->write_function(stream, "Failed set LPR link=%s\n", name);
1917                                 return FTDM_FAIL;
1918                         }
1919 
1920                         /* print the new status of the link */
1921                         handle_status_link(stream, &name[0]);
1922                         goto success;
1923                 }
1924  
1925                 /* move to the next link */
1926                 x++;
1927         } /* while (id != 0) */
1928 
1929         stream->write_function(stream, "Could not find link=%s\n", name);
1930 
1931 success:
1932         return FTDM_SUCCESS;
1933 }
1934 
1935 /******************************************************************************/
1936 static ftdm_status_t extract_span_chan(char *argv[10], int pos, int *span, int *chan)
1937 {
1938 
1939         if (!strcasecmp(argv[pos], "span")) {
1940         /**************************************************************************/
1941                 pos++;
1942                 *span = atoi(argv[pos]);
1943 
1944                 pos++;
1945                 if (!strcasecmp(argv[pos], "chan")) {
1946                 /**********************************************************************/
1947                         pos++;
1948                         *chan = atoi(argv[pos]);
1949                 /**********************************************************************/
1950                 } else {
1951                 /**********************************************************************/
1952                         return FTDM_FAIL;
1953                 /**********************************************************************/
1954                 }
1955         /**************************************************************************/
1956         } else {
1957         /**************************************************************************/
1958                 *span = atoi(argv[pos]);
1959 
1960                 pos++;
1961                 if (!strcasecmp(argv[pos], "chan")) {
1962                 /**********************************************************************/
1963                         pos++;
1964                         *chan = atoi(argv[pos]);
1965                 /**********************************************************************/
1966                 } else {
1967                 /**********************************************************************/
1968                         return FTDM_FAIL;
1969                 /**********************************************************************/
1970                 }
1971         /**************************************************************************/
1972         }
1973 
1974         return FTDM_SUCCESS;
1975 }
1976 
1977 /******************************************************************************/
1978 static ftdm_status_t check_arg_count(int args, int min)
1979 {
1980         if ( args < min ) {
1981                 return FTDM_FAIL;
1982         } else {
1983                 return FTDM_SUCCESS;
1984         }
1985 }               
1986 
1987 /******************************************************************************/
1988 /* For Emacs:
1989  * Local Variables:
1990  * mode:c
1991  * indent-tabs-mode:t
1992  * tab-width:4
1993  * c-basic-offset:4
1994  * End:
1995  * For VIM:
1996  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
1997  */
1998 /******************************************************************************/

/* [<][>][^][v][top][bottom][index][help] */