Fri Jul 3 20:37:26 2009

Asterisk developer's documentation


chan_ss7.c File Reference

#include "asterisk.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/sched.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "astversion.h"
#include "config.h"
#include "lffifo.h"
#include "mtp.h"
#include "transport.h"
#include "isup.h"
#include "l4isup.h"
#include "cluster.h"
#include "mtp3io.h"

Include dependency graph for chan_ss7.c:

Go to the source code of this file.

Defines

#define AST_MODULE   "chan_ss7"
#define CHAN_SS7_VERSION   "1.0.93-beta"

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int cmd_dump_start (int fd, int argc, char *argv[])
static int cmd_dump_status (int fd, int argc, char *argv[])
static int cmd_dump_stop (int fd, int argc, char *argv[])
static int cmd_link_down (int fd, int argc, char *argv[])
static int cmd_link_status (int fd, int argc, char *argv[])
static int cmd_link_up (int fd, int argc, char *argv[])
static int cmd_link_up_down (int fd, int argc, char *argv[], int updown)
static int cmd_ss7_status (int fd, int argc, char *argv[])
static int cmd_version (int fd, int argc, char *argv[])
static char * complete_dump_start (const char *line, const char *word, int pos, int state)
static char * complete_dump_stop (const char *line, const char *word, int pos, int state)
static char * complete_generic (const char *word, int state, char **options, int entries)
static void dump_pcap (FILE *f, struct mtp_event *event)
static void init_pcap_file (FILE *f)
static void * monitor_main (void *data)
static void mtp_enqueue_control (struct mtp_req *req)
static void process_event (struct mtp_event *event)
static int ss7_load_module (void)
static int ss7_reload_module (void)
static int ss7_unload_module (void)
static int start_mtp_thread (void)
static void stop_monitor (void)
static void stop_mtp_thread (void)

Variables

static struct ast_module_info __mod_info = { .name = "chan_ss7" , .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = desc , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = ss7_load_module, .unload = ss7_unload_module, .reload = ss7_reload_module, }
static const struct
ast_module_info * 
ast_module_info = &__mod_info
static const char config [] = "ss7.conf"
static const char desc [] = "SS7 Protocol Support"
static char * dir_options [] = { "in", "out", "both", }
static int dump_do_fisu
static int dump_do_lssu
static int dump_do_msu
static FILE * dump_in_fh = NULL
static ast_mutex_t dump_mutex = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER )
static FILE * dump_out_fh = NULL
static char * filter_options [] = { "fisu", "lssu", "msu", }
static int monitor_running = 0
static pthread_t monitor_thread = AST_PTHREADT_NULL
static struct lffifo * mtp_control_fifo = NULL
static ast_mutex_t mtp_control_mutex = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER )
static pthread_t mtp_thread = AST_PTHREADT_NULL
static int mtp_thread_running = 0
static struct ast_cli_entry my_clis []


Define Documentation

#define AST_MODULE   "chan_ss7"

Definition at line 937 of file chan_ss7.c.

#define CHAN_SS7_VERSION   "1.0.93-beta"

Definition at line 1 of file chan_ss7.c.

Referenced by cmd_version().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 942 of file chan_ss7.c.

static void __unreg_module ( void   )  [static]

Definition at line 942 of file chan_ss7.c.

static int cmd_dump_start ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 402 of file chan_ss7.c.

References ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dump_do_fisu, dump_do_lssu, dump_do_msu, dump_in_fh, dump_mutex, dump_out_fh, errno, init_pcap_file(), RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00402                                                           {
00403   int in, out;
00404   int i;
00405   int fisu,lssu,msu;
00406   FILE *fh;
00407 
00408   if(argc < 4) {
00409     return RESULT_SHOWUSAGE;
00410   }
00411 
00412   if(argc == 4) {
00413     in = 1;
00414     out = 1;
00415   } else {
00416     if(0 == strcasecmp(argv[4], "in")) {
00417       in = 1;
00418       out = 0;
00419     } else if(0 == strcasecmp(argv[4], "out")) {
00420       in = 0;
00421       out = 1;
00422     } else if(0 == strcasecmp(argv[4], "both")) {
00423       in = 1;
00424       out = 1;
00425     } else {
00426       return RESULT_SHOWUSAGE;
00427     }
00428   }
00429 
00430   ast_mutex_lock(&dump_mutex);
00431   if((in && dump_in_fh != NULL) || (out && dump_out_fh != NULL)) {
00432     ast_cli(fd, "Dump already running, must be stopped (with 'ss7 stop dump') "
00433             "before new can be started.\n");
00434     ast_mutex_unlock(&dump_mutex);
00435     return RESULT_FAILURE;
00436   }
00437 
00438   if(argc <= 5) {
00439     fisu = 0;
00440     lssu = 0;
00441     msu = 1;
00442   } else {
00443     fisu = 0;
00444     lssu = 0;
00445     msu = 0;
00446     for(i = 5; i < argc; i++) {
00447       if(0 == strcasecmp(argv[i], "fisu")) {
00448         fisu = 1;
00449       } else if(0 == strcasecmp(argv[i], "lssu")) {
00450         lssu = 1;
00451       } else if(0 == strcasecmp(argv[i], "msu")) {
00452         msu = 1;
00453       } else {
00454         ast_mutex_unlock(&dump_mutex);
00455         return RESULT_SHOWUSAGE;
00456       }
00457     }
00458   }
00459 
00460   fh = fopen(argv[3], "w");
00461   if(fh == NULL) {
00462     ast_cli(fd, "Error opening file '%s': %s.\n", argv[3], strerror(errno));
00463     ast_mutex_unlock(&dump_mutex);
00464     return RESULT_FAILURE;
00465   }
00466 
00467   if(in) {
00468     dump_in_fh = fh;
00469   }
00470   if(out) {
00471     dump_out_fh = fh;
00472   }
00473   dump_do_fisu = fisu;
00474   dump_do_lssu = lssu;
00475   dump_do_msu = msu;
00476   init_pcap_file(fh);
00477 
00478   ast_mutex_unlock(&dump_mutex);
00479   return RESULT_SUCCESS;
00480 }

static int cmd_dump_status ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 532 of file chan_ss7.c.

References ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dump_do_fisu, dump_do_lssu, dump_do_msu, dump_in_fh, dump_mutex, dump_out_fh, and RESULT_SUCCESS.

00532                                                            {
00533   ast_mutex_lock(&dump_mutex);
00534 
00535   /* ToDo: This doesn't seem to work, the output is getting lost somehow.
00536      Not sure why, but could be related to ast_carefulwrite() called in
00537      ast_cli(). */
00538   ast_cli(fd, "Yuck! what is going on here?!?\n");
00539   if(dump_in_fh != NULL) {
00540     ast_cli(fd, "Dump of incoming frames is running.\n");
00541   }
00542   if(dump_out_fh != NULL) {
00543     ast_cli(fd, "Dump of outgoing frames is running.\n");
00544   }
00545   if(dump_in_fh != NULL || dump_out_fh != NULL) {
00546     ast_cli(fd, "Filter:%s%s%s.\n",
00547             (dump_do_fisu ? " fisu" : ""),
00548             (dump_do_lssu ? " lssu" : ""),
00549             (dump_do_msu ? " msu" : ""));
00550   }
00551 
00552   ast_mutex_unlock(&dump_mutex);
00553   return RESULT_SUCCESS;
00554 }

static int cmd_dump_stop ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 482 of file chan_ss7.c.

References ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dump_in_fh, dump_mutex, dump_out_fh, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00482                                                          {
00483   int in, out;
00484 
00485   if(argc == 3) {
00486     in = 1;
00487     out = 1;
00488   } else if(argc == 4) {
00489     if(0 == strcasecmp(argv[3], "in")) {
00490       in = 1;
00491       out = 0;
00492     } else if(0 == strcasecmp(argv[3], "out")) {
00493       in = 0;
00494       out = 1;
00495     } else if(0 == strcasecmp(argv[3], "both")) {
00496       in = 1;
00497       out = 1;
00498     } else {
00499       return RESULT_SHOWUSAGE;
00500     }
00501   } else {
00502     return RESULT_SHOWUSAGE;
00503   }
00504 
00505   ast_mutex_lock(&dump_mutex);
00506 
00507   if((in && !out && dump_in_fh == NULL) ||
00508      (out && !in && dump_out_fh == NULL) ||
00509      (in && out && dump_in_fh == NULL && dump_out_fh == NULL)) {
00510     ast_cli(fd, "No dump running.\n");
00511     ast_mutex_unlock(&dump_mutex);
00512     return RESULT_SUCCESS;
00513   }
00514 
00515   if(in && dump_in_fh != NULL) {
00516     if(dump_out_fh == dump_in_fh) {
00517       /* Avoid closing it twice. */
00518       dump_out_fh = NULL;
00519     }
00520     fclose(dump_in_fh);
00521     dump_in_fh = NULL;
00522   }
00523   if(out && dump_out_fh != NULL) {
00524     fclose(dump_out_fh);
00525     dump_out_fh = NULL;
00526   }
00527 
00528   ast_mutex_unlock(&dump_mutex);
00529   return RESULT_SUCCESS;
00530 }

static int cmd_link_down ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 339 of file chan_ss7.c.

References cmd_link_up_down().

00339                                                          {
00340   return cmd_link_up_down(fd, argc, argv, MTP_REQ_LINK_DOWN);
00341 }

static int cmd_link_status ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 349 of file chan_ss7.c.

References ast_cli(), and RESULT_SUCCESS.

00349                                                            {
00350   char buff[256];
00351   int i;
00352 
00353   for (i = 0; i < this_host->n_schannels; i++) {
00354     if (mtp_cmd_linkstatus(buff, i) == 0)
00355       ast_cli(fd, buff);
00356   }
00357   return RESULT_SUCCESS;
00358 }

static int cmd_link_up ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 344 of file chan_ss7.c.

References cmd_link_up_down().

00344                                                        {
00345   return cmd_link_up_down(fd, argc, argv, MTP_REQ_LINK_UP);
00346 }

static int cmd_link_up_down ( int  fd,
int  argc,
char *  argv[],
int  updown 
) [static]

Definition at line 309 of file chan_ss7.c.

References ast_log(), LOG_DEBUG, LOG_ERROR, mtp_enqueue_control(), RESULT_FAILURE, and RESULT_SUCCESS.

Referenced by cmd_link_down(), and cmd_link_up().

00309                                                                         {
00310   static unsigned char buf[sizeof(struct mtp_req)];
00311   struct mtp_req *req = (struct mtp_req *)buf;
00312   int i;
00313 
00314   req->typ = updown;
00315   req->len = sizeof(req->link);
00316   if(argc > 3) {
00317     for (i = 3; i < argc; i++) {
00318       int link_ix = atoi(argv[i]);
00319       ast_log(LOG_DEBUG, "MTP control link %s %d\n", updown == MTP_REQ_LINK_UP ? "up" : "down", link_ix);
00320       if (link_ix >= this_host->n_schannels) {
00321    ast_log(LOG_ERROR, "Link index out of range %d, max %d.\n", link_ix, this_host->n_schannels);
00322    return RESULT_FAILURE;
00323       }
00324       req->link.link_ix = link_ix;
00325       mtp_enqueue_control(req);
00326     }
00327   }
00328   else {
00329     for (i=0; i < this_host->n_schannels; i++) {
00330       ast_log(LOG_DEBUG, "MTP control link %s %d\n", updown == MTP_REQ_LINK_UP ? "up" : "down", i);
00331       req->link.link_ix = i;
00332       mtp_enqueue_control(req);
00333     }
00334   }
00335   return RESULT_SUCCESS;
00336 }

static int cmd_ss7_status ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 565 of file chan_ss7.c.

References RESULT_SUCCESS.

00566 {
00567   cmd_linkset_status(fd, argc, argv);
00568   return RESULT_SUCCESS;
00569 }

static int cmd_version ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 557 of file chan_ss7.c.

References ast_cli(), CHAN_SS7_VERSION, and RESULT_SUCCESS.

00558 {
00559   ast_cli(fd, "chan_ss7 version %s\n", CHAN_SS7_VERSION);
00560 
00561   return RESULT_SUCCESS;
00562 }

static char * complete_dump_start ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 378 of file chan_ss7.c.

References complete_generic(), dir_options, and filter_options.

00379 {
00380   if(pos == 4) {
00381     return complete_generic(word, state, dir_options,
00382                             sizeof(dir_options)/sizeof(dir_options[0]));
00383   } else if(pos > 4) {
00384     return complete_generic(word, state, filter_options,
00385                             sizeof(filter_options)/sizeof(filter_options[0]));
00386   } else {
00387     /* We won't attempt to complete file names, that's not worth it. */
00388     return NULL;
00389   }
00390 }

static char * complete_dump_stop ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 392 of file chan_ss7.c.

References complete_generic(), and dir_options.

00393 {
00394   if(pos == 3) {
00395     return complete_generic(word, state, dir_options,
00396                             sizeof(dir_options)/sizeof(dir_options[0]));
00397   } else {
00398     return NULL;
00399   }
00400 }

static char* complete_generic ( const char *  word,
int  state,
char **  options,
int  entries 
) [static]

Definition at line 361 of file chan_ss7.c.

References strdup.

Referenced by complete_dump_start(), and complete_dump_stop().

00361                                                                                         {
00362   int which = 0;
00363   int i;
00364 
00365   for(i = 0; i < entries; i++) {
00366     if(0 == strncasecmp(word, options[i], strlen(word))) {
00367       if(++which > state) {
00368         return strdup(options[i]);
00369       }
00370     }
00371   }
00372   return NULL;
00373 }

static void dump_pcap ( FILE *  f,
struct mtp_event *  event 
) [static]

Definition at line 251 of file chan_ss7.c.

Referenced by process_event().

00252 {
00253   unsigned int sec  = event->dump.stamp.tv_sec;
00254   unsigned int usec  = event->dump.stamp.tv_usec - (event->dump.stamp.tv_usec % 1000) +
00255     event->dump.slinkno*2 + /* encode link number in usecs */
00256     event->dump.out /* encode direction in/out */;
00257 
00258   fwrite(&sec, sizeof(sec), 1, f);
00259   fwrite(&usec, sizeof(usec), 1, f);
00260   fwrite(&event->len, sizeof(event->len), 1, f); /* number of bytes of packet in file */
00261   fwrite(&event->len, sizeof(event->len), 1, f); /* actual length of packet */
00262   fwrite(event->buf, 1, event->len, f);
00263   fflush(f);
00264 }

static void init_pcap_file ( FILE *  f  )  [static]

Definition at line 266 of file chan_ss7.c.

Referenced by cmd_dump_start().

00267 {
00268   unsigned int magic = 0xa1b2c3d4;  /* text2pcap does this */
00269   unsigned short version_major = 2;
00270   unsigned short version_minor = 4;
00271   unsigned int thiszone = 0;
00272   unsigned int sigfigs = 0;
00273   unsigned int snaplen = 102400;
00274   unsigned int linktype = 140;
00275 
00276   fwrite(&magic, sizeof(magic), 1, f);
00277   fwrite(&version_major, sizeof(version_major), 1, f);
00278   fwrite(&version_minor, sizeof(version_minor), 1, f);
00279   fwrite(&thiszone, sizeof(thiszone), 1, f);
00280   fwrite(&sigfigs, sizeof(sigfigs), 1, f);
00281   fwrite(&snaplen, sizeof(snaplen), 1, f);
00282   fwrite(&linktype, sizeof(linktype), 1, f);
00283 }

static void* monitor_main ( void *  data  )  [static]

Definition at line 645 of file chan_ss7.c.

References ast_log(), ast_verbose(), errno, pollfd::events, pollfd::fd, len(), LOG_ERROR, LOG_NOTICE, monitor_running, poll(), POLLERR, POLLHUP, POLLIN, POLLNVAL, process_event(), timeout, and VERBOSE_PREFIX_3.

Referenced by ss7_load_module().

00645                                       {
00646   int res, nres;
00647   struct pollfd fds[(MAX_LINKS+1)];
00648   int i, n_fds;
00649   int rebuild_fds = 1;
00650   struct lffifo *receive_fifo = mtp_get_receive_fifo();
00651 
00652   ast_verbose(VERBOSE_PREFIX_3 "Starting monitor thread, pid=%d.\n", getpid());
00653 
00654   fds[0].fd = get_receive_pipe();
00655   fds[0].events = POLLIN;
00656   while(monitor_running) {
00657     if (rebuild_fds) {
00658       if (rebuild_fds > 1)
00659    poll(fds, 0, 200); /* sleep */
00660       rebuild_fds = 0;
00661       n_fds = 1;
00662       for (i = 0; i < n_linksets; i++) {
00663    struct linkset* linkset = &linksets[i];
00664    int j;
00665    for (j = 0; j < linkset->n_links; j++) {
00666      int k;
00667      struct link* link = linkset->links[j];
00668      for (k = 0; k < this_host->n_spans; k++) {
00669        if (this_host->spans[k].link == link)
00670          break;
00671        if ((this_host->spans[k].link->linkset == link->linkset) ||
00672       (is_combined_linkset(this_host->spans[k].link->linkset, link->linkset)))
00673          break;
00674      }
00675      if (k < this_host->n_spans) {
00676        if (link->remote) {
00677          if (link->mtp3fd == -1) {
00678       link->mtp3fd = mtp3_connect_socket(link->mtp3server_host, link->mtp3server_port);
00679       if (link->mtp3fd != -1)
00680         res = mtp3_register_isup(link->mtp3fd, link->linkix);
00681       if ((link->mtp3fd == -1) || (res == -1))
00682         rebuild_fds += 2;
00683          }
00684          fds[n_fds].fd = link->mtp3fd;
00685          fds[n_fds++].events = POLLIN|POLLERR|POLLNVAL|POLLHUP;
00686        }
00687      }
00688    }
00689       }
00690     }
00691     int timeout = timers_wait();
00692 
00693     nres = poll(fds, n_fds, timeout);
00694     if(nres < 0) {
00695       if(errno == EINTR) {
00696         /* Just try again. */
00697       } else {
00698         ast_log(LOG_ERROR, "poll() failure, errno=%d: %s\n",
00699                 errno, strerror(errno));
00700       }
00701     } else if(nres > 0) {
00702       for (i = 0; (i < n_fds) && (nres > 0); i++) {
00703    unsigned char eventbuf[MTP_EVENT_MAX_SIZE];
00704    struct mtp_event *event = (struct mtp_event*) eventbuf;
00705    struct link* link = NULL;
00706    if(fds[i].revents) {
00707      int j;
00708      for (j = 0; j < n_links; j++) {
00709        if (links[j].remote && (links[j].mtp3fd == fds[i].fd)) {
00710          link = &links[j];
00711          break;
00712        }
00713      }
00714    }
00715    else
00716      continue;
00717    if(fds[i].revents & (POLLERR|POLLNVAL|POLLHUP)) {
00718      if (i == 0) { /* receivepipe */
00719        ast_log(LOG_ERROR, "poll() return bad revents for receivepipe, 0x%04x\n", fds[i].revents);
00720      }
00721      close(fds[i].fd);
00722      if (link)
00723        link->mtp3fd = -1;
00724      rebuild_fds++; rebuild_fds++; /* when > 1, use short sleep */
00725      nres--;
00726      continue;
00727    }
00728    if(!(fds[i].revents & POLLIN))
00729      continue;
00730    if (i == 0) {
00731      /* Events waiting in the receive buffer. */
00732      unsigned char dummy[512];
00733 
00734      /* Empty the pipe before pulling from fifo. This way the race
00735         condition between mtp and monitor threads may cause spurious
00736         wakeups, but not loss/delay of messages. */
00737      read(fds[i].fd, dummy, sizeof(dummy));
00738 
00739      /* Process all available events. */
00740      while((res = lffifo_get(receive_fifo, eventbuf, sizeof(eventbuf))) != 0) {
00741        if(res < 0) {
00742          ast_log(LOG_ERROR, "Yuck! oversized frame in receive fifo, bailing out.\n");
00743          return NULL;
00744        }
00745        process_event(event);
00746      }
00747    }
00748    else {
00749 #if MTP3_SOCKET == SOCK_STREAM
00750      res = read(fds[i].fd, eventbuf, sizeof(struct mtp_event));
00751      if ((res > 0) && (event->len > 0)) {
00752        int p = res;
00753        int len = event->len;
00754        if (sizeof(struct mtp_event) + event->len > MTP_EVENT_MAX_SIZE) {
00755          ast_log(LOG_NOTICE, "Got too large packet: len %d, max %d, discarded", sizeof(struct mtp_event) + event->len, MTP_EVENT_MAX_SIZE);
00756          len = 0;
00757          res = 0;
00758        }
00759        do {
00760          res = read(fds[i].fd, &eventbuf[p], len);
00761          if (res > 0) {
00762       p += res;
00763       len -= res;
00764          }
00765          else if ((res < 0) && (errno != EINTR)) {
00766       len = 0;
00767          }
00768          else {
00769       len = 0;
00770          }
00771        } while (len > 0);
00772      }
00773 #else
00774      res = read(fds[i].fd, eventbuf, sizeof(eventbuf)+MTP_MAX_PCK_SIZE);
00775 #endif
00776      if (res > 0) {
00777        if (event->typ == MTP_EVENT_ISUP) {
00778          event->isup.link = NULL;
00779          event->isup.slink = &links[event->isup.slinkix];
00780        }
00781        process_event(event);
00782      }
00783      else if (res == 0) {
00784        int j;
00785        for (j = 0; j < n_links; j++) {
00786          struct link* link = &links[j];
00787          if (link->remote && (link->mtp3fd == fds[i].fd)) {
00788       close(fds[i].fd);
00789       link->mtp3fd = -1;
00790       rebuild_fds++;
00791          }
00792        }
00793      }
00794    }
00795    nres--;
00796       }
00797     }
00798 
00799     /* We need to lock the global glock mutex around ast_sched_runq() so that
00800        we avoid a race with ss7_hangup. With the lock, invalidating the
00801        channel in ss7_hangup() and removing associated monitor_sched entries
00802        is an atomic operation, so that we avoid calling timer handlers with
00803        references to invalidated channels. */
00804     run_timers();
00805   }
00806   return NULL;
00807 }

static void mtp_enqueue_control ( struct mtp_req *  req  )  [static]

Definition at line 286 of file chan_ss7.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), LOG_WARNING, mtp_control_fifo, and mtp_control_mutex.

Referenced by cmd_link_up_down().

00286                                                      {
00287   int res;
00288 
00289   ast_mutex_lock(&mtp_control_mutex);
00290   res = lffifo_put(mtp_control_fifo, (unsigned char *)req, sizeof(struct mtp_req) + req->len);
00291   ast_mutex_unlock(&mtp_control_mutex);
00292   if(res != 0) {
00293     ast_log(LOG_WARNING, "MTP control fifo full (MTP thread hanging?).\n");
00294   }
00295 }

static void process_event ( struct mtp_event *  event  )  [static]

Definition at line 572 of file chan_ss7.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), dump_do_fisu, dump_do_lssu, dump_do_msu, dump_in_fh, dump_mutex, dump_out_fh, dump_pcap(), LOG_NOTICE, LOG_WARNING, and name.

Referenced by monitor_main().

00573 {
00574   FILE *dump_fh;
00575 
00576   switch(event->typ) {
00577   case MTP_EVENT_ISUP:
00578     l4isup_event(event);
00579     break;
00580   case MTP_EVENT_SCCP:
00581     break;
00582   case MTP_EVENT_REQ_REGISTER:
00583     if (event->regist.ss7_protocol == 5) {
00584       struct link* link = &links[event->regist.isup.slinkix];
00585       mtp3_register_isup(link->mtp3fd, link->linkix);
00586     }
00587     break;
00588   case MTP_EVENT_LOG:
00589     ast_log(event->log.level, event->log.file, event->log.line,
00590        event->log.function, "%s", event->buf);
00591     break;
00592 
00593   case MTP_EVENT_DUMP:
00594     ast_mutex_lock(&dump_mutex);
00595 
00596     if(event->dump.out) {
00597       dump_fh = dump_out_fh;
00598     } else {
00599       dump_fh = dump_in_fh;
00600     }
00601     if(dump_fh != NULL) {
00602       if(event->len < 3 ||
00603     ( !(event->buf[2] == 0 && !dump_do_fisu) &&
00604       !((event->buf[2] == 1 || event->buf[2] == 2) && !dump_do_lssu) &&
00605       !(event->buf[2] > 2 && !dump_do_msu)))
00606    dump_pcap(dump_fh, event);
00607     }
00608 
00609     ast_mutex_unlock(&dump_mutex);
00610     break;
00611 
00612   case MTP_EVENT_STATUS:
00613     {
00614       struct link* link = event->status.link;
00615       char* name = link ? link->name : "(peer)";
00616       switch(event->status.link_state) {
00617       case MTP_EVENT_STATUS_LINK_UP:
00618    l4isup_link_status_change(link, 1);
00619    ast_log(LOG_WARNING, "MTP is now UP on link '%s'.\n", name);
00620    break;
00621       case MTP_EVENT_STATUS_LINK_DOWN:
00622    l4isup_link_status_change(link, 0);
00623    ast_log(LOG_WARNING, "MTP is now DOWN on link '%s'.\n", name);
00624    break;
00625       case MTP_EVENT_STATUS_INSERVICE:
00626    ast_log(LOG_WARNING, "Signaling ready for linkset '%s'.\n", link->linkset->name);
00627    l4isup_inservice(link);
00628    break;
00629       default:
00630    ast_log(LOG_NOTICE, "Unknown event type STATUS (%d), "
00631       "not processed.\n", event->status.link_state);
00632       }
00633     }
00634     break;
00635 
00636   default:
00637     ast_log(LOG_NOTICE, "Unexpected mtp event type %d.\n", event->typ);
00638   }
00639 }

static int ss7_load_module ( void   )  [static]

Definition at line 832 of file chan_ss7.c.

References ast_cli_register_multiple(), ast_log(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_pthread_create, ast_verbose(), load_config(), LOG_ERROR, monitor_main(), monitor_running, monitor_thread, mtp_control_fifo, start_mtp_thread(), and VERBOSE_PREFIX_3.

00833 {
00834   if(load_config(0)) {
00835     return AST_MODULE_LOAD_FAILURE;
00836   }
00837 
00838   if (timers_init()) {
00839     ast_log(LOG_ERROR, "Unable to initialize timers.\n");
00840     return AST_MODULE_LOAD_FAILURE;
00841   }
00842   if (isup_init()) {
00843     ast_log(LOG_ERROR, "Unable to initialize ISUP.\n");
00844     return AST_MODULE_LOAD_FAILURE;
00845   }
00846 #ifdef SCCP
00847   if (sccp_init()) {
00848     ast_log(LOG_ERROR, "Unable to initialize SCCP.\n");
00849     return AST_MODULE_LOAD_FAILURE;
00850   }
00851 #endif
00852 
00853   if(mtp_init()) {
00854     ast_log(LOG_ERROR, "Unable to initialize MTP.\n");
00855     return AST_MODULE_LOAD_FAILURE;
00856   }
00857   if(start_mtp_thread()) {
00858     ast_log(LOG_ERROR, "Unable to start MTP thread.\n");
00859     return AST_MODULE_LOAD_FAILURE;
00860   }
00861   mtp_control_fifo = mtp_get_control_fifo();
00862 
00863   monitor_running = 1;          /* Otherwise there is a race, and
00864                                    monitor may exit immediately */
00865   if(ast_pthread_create(&monitor_thread, NULL, monitor_main, NULL) < 0) {
00866     ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
00867     monitor_running = 0;
00868     return AST_MODULE_LOAD_FAILURE;
00869   }
00870 
00871 
00872   ast_cli_register_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0]));
00873 
00874   ast_verbose(VERBOSE_PREFIX_3 "SS7 channel loaded successfully.\n");
00875   return AST_MODULE_LOAD_SUCCESS;
00876 }

static int ss7_reload_module ( void   )  [static]

Definition at line 826 of file chan_ss7.c.

References ast_log(), AST_MODULE_LOAD_SUCCESS, and LOG_NOTICE.

00826                                    {
00827   ast_log(LOG_NOTICE, "SS7 reload not implemented.\n");
00828   return AST_MODULE_LOAD_SUCCESS;
00829 }

static int ss7_unload_module ( void   )  [static]

Definition at line 879 of file chan_ss7.c.

References ast_cli_unregister_multiple(), AST_MODULE_LOAD_SUCCESS, ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), dump_in_fh, dump_mutex, dump_out_fh, monitor_running, stop_monitor(), stop_mtp_thread(), and VERBOSE_PREFIX_3.

00880 {
00881   ast_cli_unregister_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0]));
00882 
00883 #ifdef SCCP
00884   sccp_cleanup();
00885 #endif
00886   isup_cleanup();
00887 
00888   ast_mutex_lock(&dump_mutex);
00889   if(dump_in_fh != NULL) {
00890     if(dump_in_fh == dump_out_fh) {
00891       dump_out_fh = NULL;
00892     }
00893     fclose(dump_in_fh);
00894     dump_in_fh = NULL;
00895   }
00896   if(dump_out_fh != NULL) {
00897     fclose(dump_out_fh);
00898     dump_out_fh = NULL;
00899   }
00900   ast_mutex_unlock(&dump_mutex);
00901 
00902   if(monitor_running) {
00903     stop_monitor();
00904   }
00905   stop_mtp_thread();
00906   mtp_cleanup();
00907   timers_cleanup();
00908 
00909 
00910   destroy_config();
00911   ast_verbose(VERBOSE_PREFIX_3 "SS7 channel unloaded.\n");
00912   return AST_MODULE_LOAD_SUCCESS;
00913 }

static int start_mtp_thread ( void   )  [static]

Definition at line 298 of file chan_ss7.c.

References mtp_thread, and mtp_thread_running.

Referenced by ss7_load_module().

00299 {
00300   return start_thread(&mtp_thread, mtp_thread_main, &mtp_thread_running, 15);
00301 }

static void stop_monitor ( void   )  [static]

Definition at line 810 of file chan_ss7.c.

References monitor_running, and monitor_thread.

Referenced by ss7_unload_module().

00810                                {
00811   int i;
00812 
00813   if(monitor_running) {
00814     monitor_running = 0;
00815     /* Monitor wakes up every 1/2 sec, so no need to signal it explicitly. */
00816     pthread_join(monitor_thread, NULL);
00817   }
00818   for (i = 0; i < n_links; i++) {
00819     struct link* link = &links[i];
00820     if (link->remote && (link->mtp3fd > -1))
00821       close(link->mtp3fd);
00822   }
00823 }

static void stop_mtp_thread ( void   )  [static]

Definition at line 303 of file chan_ss7.c.

References mtp_thread, and mtp_thread_running.

Referenced by ss7_unload_module().

00304 {
00305     mtp_thread_signal_stop();
00306     stop_thread(&mtp_thread, &mtp_thread_running);
00307 }


Variable Documentation

struct ast_module_info __mod_info = { .name = "chan_ss7" , .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = desc , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = ss7_load_module, .unload = ss7_unload_module, .reload = ss7_reload_module, } [static]

Definition at line 942 of file chan_ss7.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 942 of file chan_ss7.c.

const char config[] = "ss7.conf" [static]

Definition at line 90 of file chan_ss7.c.

const char desc[] = "SS7 Protocol Support" [static]

Definition at line 89 of file chan_ss7.c.

char* dir_options[] = { "in", "out", "both", } [static]

Definition at line 375 of file chan_ss7.c.

Referenced by complete_dump_start(), and complete_dump_stop().

int dump_do_fisu [static]

Definition at line 86 of file chan_ss7.c.

Referenced by cmd_dump_start(), cmd_dump_status(), and process_event().

int dump_do_lssu [static]

Definition at line 86 of file chan_ss7.c.

Referenced by cmd_dump_start(), cmd_dump_status(), and process_event().

int dump_do_msu [static]

Definition at line 86 of file chan_ss7.c.

Referenced by cmd_dump_start(), cmd_dump_status(), and process_event().

FILE* dump_in_fh = NULL [static]

ast_mutex_t dump_mutex = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static]

FILE* dump_out_fh = NULL [static]

char* filter_options[] = { "fisu", "lssu", "msu", } [static]

Definition at line 376 of file chan_ss7.c.

Referenced by complete_dump_start().

int monitor_running = 0 [static]

Definition at line 78 of file chan_ss7.c.

Referenced by monitor_main(), ss7_load_module(), ss7_unload_module(), and stop_monitor().

pthread_t monitor_thread = AST_PTHREADT_NULL [static]

Definition at line 77 of file chan_ss7.c.

Referenced by ss7_load_module(), and stop_monitor().

struct lffifo* mtp_control_fifo = NULL [static]

Definition at line 67 of file chan_ss7.c.

Referenced by mtp_enqueue_control(), and ss7_load_module().

ast_mutex_t mtp_control_mutex = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static]

Definition at line 66 of file chan_ss7.c.

Referenced by mtp_enqueue_control().

pthread_t mtp_thread = AST_PTHREADT_NULL [static]

Definition at line 72 of file chan_ss7.c.

Referenced by start_mtp_thread(), and stop_mtp_thread().

int mtp_thread_running = 0 [static]

Definition at line 73 of file chan_ss7.c.

Referenced by start_mtp_thread(), and stop_mtp_thread().

struct ast_cli_entry my_clis[] [static]

Definition at line 106 of file chan_ss7.c.


Generated on Fri Jul 3 20:37:27 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9