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

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