亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mtp.c

?? asterisk1.4.6版本下 7#信令驅動 源碼
?? C
?? 第 1 頁 / 共 5 頁
字號:
/* mtp.c - MTP2 and MTP3 functionality.
 *
 * Copyright (C) 2005-2006, Sifira A/S.
 *
 * Author: Kristian Nielsen <kn@sifira.dk>
 *         Anders Baekgaard <ab@sifira.dk>
 *         Anders Baekgaard <ab@dicea.dk>
 *
 * This file is part of chan_ss7.
 *
 * chan_ss7 is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * chan_ss7 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with chan_ss7; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <signal.h>
#include <sys/poll.h>
#include <sys/ioctl.h>
#include <sys/time.h>

#include "zaptel.h"
#define FAST_HDLC_NEED_TABLES
#include "fasthdlc.h"

#include "config.h"
#include "mtp.h"
#include "transport.h"
#include "lffifo.h"
#include "cluster.h"
#include "utils.h"

#ifdef MTP_STANDALONE
#include "aststubs.h"
#define cluster_mtp_received(link, event) {}
#define cluster_mtp_forward(req) {}
#define cluster_receivers_alive(linkset) (0)
#else
#include "asterisk/options.h"
#include "asterisk/logger.h"
#include "asterisk/sched.h"
#define mtp_sched_add ast_sched_add
#define mtp_sched_del ast_sched_del
#define mtp_sched_runq ast_sched_runq
#define mtp_sched_context_create sched_context_create
#define mtp_sched_context_destroy sched_context_destroy
#endif

/* NOTE: most of this code is run in the MTP thread, and has realtime
   constraints because of the need to constantly feed/read the
   signalling link with low latence and no frame drop.

   The thread runs with high realtime priority, and any kind of
   locking should generally be avoided. This includes ast_log() (use
   fifo_log() instead), and malloc()/free()!
*/


/* For testing failover mechanism */
int testfailover = 0;

/* #define DROP_PACKETS_PCT 66 */
/* #define DO_RAW_DUMPS */

/* Scheduling context for MTP2. */
/* This should ONLY be used by the MTP2 thread, otherwise the locking done
   by the sched operations may fatally delay the MTP2 thread because of
   priority inversion. */
static struct sched_context *mtp2_sched = NULL;

/* Set true to ask mtp thread to stop */
static int stop_mtp_thread;
static int receivepipe[2] = {-1, -1};
/* Lock-free FIFOs for communication with the MTP thread.
   The sendbuf is polled by the MTP thread whenever the link is ready to
   transmit data (every 2msec). It contains struct mtp_req entries for
   the higher level protocol layers (currently only ISUP).
   The receivebuf has an associated event pipe, and the MTP thread do
   non-blocking dummy writes to it whenever blocks are put in the buffer.
   The SS7 monitor thread can then wait for new data in poll(). The
   receivebuf contains struct mtp_event entries.
   The controlbuf is polled by the MTP thread, it contains struct mtp_req
   entries for control purposes only.
 */
struct lffifo *sendbuf[MAX_LINKSETS];
struct lffifo *receivebuf;
struct lffifo *controlbuf;


typedef struct mtp2_state {

  /* MTP2 stuff. */

  enum {
    /* Link is stopped by management command, will not go up until
       started explicitly. */
    MTP2_DOWN,
    /* Initial alignment has started, link is transmitting 'O', but no 'O',
       'N', or 'E' has been received. */
    MTP2_NOT_ALIGNED,
    /* 'O' has been received, 'N' or 'E' is transmitted. */
    MTP2_ALIGNED,
    /* 'N' or 'E' is transmitted and received. Runs for the duration of T4 to
       check that the link is of sufficient quality in terms of error rate. */
    MTP2_PROVING,
    /* Local T4 expired, and we are sending FISU, but remote is still
       proving. */
    MTP2_READY,
    /* The link is active sending and receiving FISU and MSU. */
    MTP2_INSERVICE,
  } state;

  /* Counts of raw bytes read and written, used to timestamp raw dumps.
     Make them double to avoid overflow for quite a while. */
  double readcount, writecount;

  /* Sequence numbers and indicator bits to be sent in signalling units. */
  int send_fib;
  int send_bsn, send_bib;

  /* Send initial SLTM? */
  int send_sltm;

  /* Timeslot for signalling channel */
  int schannel;
  int slinkno;
  struct link* link;
  int sls;
  int subservice;
  /* logical link name */
  char* name;
  /* Open fd for signalling link zaptel device. */
  int fd;

  /* Receive buffer. */
  unsigned char rx_buf[272 + 7];
  int rx_len;
  unsigned short rx_crc;

  /* Transmit buffer. */
  unsigned char tx_buffer[272 + 7 + 5];
  int tx_len;
  int tx_sofar;
  int tx_do_crc;                /* Flag used to handle writing CRC bytes */
  unsigned short tx_crc;

  /* Zaptel transmit buffer. */
  unsigned char zap_buf[ZAP_BUF_SIZE];
  int zap_buf_full;

  /* HDLC encoding and decoding state. */
  struct fasthdlc_state h_rx;
  struct fasthdlc_state h_tx;

  /* Last few raw bytes received, for debugging link errors. */
  unsigned char backbuf[36];
  int backbuf_idx;

  /* Retransmit buffer. */
  struct { int len; unsigned char buf[MTP_MAX_PCK_SIZE]; } retrans_buf[128];
  /* Retransmit counter; if this is != -1, it means that retransmission is
     taking place, with this being the next sequence number to retransmit. */
  int retrans_seq;
  /* Last sequence number ACK'ed by peer. */
  int retrans_last_acked;
  /* Last sequence number sent to peer. */
  int retrans_last_sent;
  /* Counter for signal unit/alignment error rate monitors (Q.703 (10)). */
  int error_rate_mon;
  /* Counters matching the D and N values of the error rate monitors. */
  int emon_ncount, emon_dcount;
  /* Counter for bad BSN */
  int bsn_errors;
  /* Q.703 timer T1 "alignment ready" (waiting for peer to end initial
     alignment after we are done). */
  int mtp2_t1;
  /* Q.703 timer T2 "not aligned" (waiting to receive O, E, or N after sending
     O). */
  int mtp2_t2;
  /* Q.703 timer T3 "aligned" (waiting to receive E or N after sending E or
     N). */
  int mtp2_t3;
  /* Q.703 timer T4 "proving period" - proving time before ending own initial
     alignment. */
  int mtp2_t4;
  /* Q.703 timer T7 "excessive delay of acknowledgement" . */
  int mtp2_t7;

  /* Set true when SLTA is received and User Parts (ie. ISUP) is notified that
     the link is now in service. */
  int level4_up;

  /* Hm, the rest is actually MTP3 state. Move to other structure, or
     rename this structure. */
  int sltm_t1;                  /* Timer T1 for SLTM (Q.707) */
  int sltm_t2;                  /* Timer T2 for SLTM (Q.707) */
  int sltm_tries;               /* For SLTM retry (Q.707 (2.2)) */

  /* Q.704 timer T17, "initial alignment restart delay". */
  int mtp3_t17;
} mtp2_t;

/* ToDo: Support more than one signalling link ... */
/* ToDo: Need real initialization, that doesn't depend on linker. */
mtp2_t mtp2_state[MAX_SCHANNELS];


/* Get the next sequence number, modulo 128. */
#define MTP_NEXT_SEQ(x) (((x) + 1) % 128)

/* Forward declaration, needed because of cyclic reference graph. */
static mtp2_t* find_alternative_slink(mtp2_t* m);
static void start_initial_alignment(mtp2_t *m, char* reason);
static void abort_initial_alignment(mtp2_t *m);
static void mtp2_cleanup(mtp2_t *m);
static void mtp2_queue_msu(mtp2_t *m, int sio, unsigned char *sif, int len);
static void deliver_l4(mtp2_t *m, unsigned char *sif, int len, int sio);
static void l4up(mtp2_t* m);
static void l4down(mtp2_t* m);
static void t7_stop(mtp2_t *m);
static void fifo_log(mtp2_t *m, int level, const char *file, int line,
		     const char *function, const char *format, ...)
     __attribute__ ((format (printf, 6, 7)));
static void process_msu(struct mtp2_state* m, unsigned char* buf, int len);

static inline ss7_variant variant(mtp2_t* m)   /* by lin.miao@openvox.cn */
{
  return m->link->linkset->variant;
}

int mtp2_slink_inservice(int ix) {
  struct mtp2_state* m = &mtp2_state[ix];
  return m->state == MTP2_INSERVICE;
}

int mtp_cmd_linkstatus(char* buff, int slinkno)
{
  char* format = "linkset %s, link %s, schannel %d, sls %d, %s, rx: %d, tx: %d/%d, sentseq/lastack: %d/%d, total %9llu, %9llu\n";

  char* s = "?";
  if (slinkno >= this_host->n_schannels)
    return -1;
  /* Todo: when more than one signalling link supported, check against that */
  struct mtp2_state* m = &mtp2_state[slinkno];
  switch (m->state) {
  case MTP2_DOWN: s = "DOWN"; break;
  case MTP2_NOT_ALIGNED: s = "NOT_ALIGNED"; break;
  case MTP2_ALIGNED: s = "ALIGNED"; break;
  case MTP2_PROVING: s = "PROVING"; break;
  case MTP2_READY: s = "READY"; break;
  case MTP2_INSERVICE: s = "INSERVICE"; break;
  default: s = "UNKNOWN";
  }
  sprintf(buff, format, m->link->linkset->name, m->link->name, m->schannel, m->sls, s, m->rx_len, m->tx_sofar, m->tx_len, m->retrans_last_sent, m->retrans_last_acked, (long long) m->readcount, (long long) m->writecount);
  return 0;
}

int mtp_cmd_data(int fd, int argc, char *argv[])
{
  unsigned char buf[MTP_EVENT_MAX_SIZE];
  int len = 0;
  int i;
  mtp2_t* m = &mtp2_state[0];

  for (i = 3; i < argc; i++) {
    char* p = argv[i];
    while (*p) {
      char b[3];
      unsigned int v;
      if (*p == ' ') {
	p++;
	continue;
      }
      b[0] = *p++;
      b[1] = *p++;
      b[2] = 0;
      sscanf(b, "%x", &v);
      buf[len++] = v;
    }
  }
  mtp2_queue_msu(m, 3, buf, len);
  deliver_l4(m, &buf[0], len, MTP_EVENT_SCCP);
  return 0;
}


static inline int peerpc(mtp2_t* m)
{
  return m->link->linkset->dpc;
}


static inline int linkpeerpc(mtp2_t* m)
{
  if (m->link->dpc)
    return m->link->dpc;
  return m->link->linkset->dpc;
}


static mtp2_t* findtargetslink(mtp2_t *originalm, int sls)
{
  int i;
  struct link* link = originalm->link;
  struct mtp2_state* bestm = NULL;

  for (i = 0; i < this_host->n_schannels; i++) {
    struct mtp2_state* m = &mtp2_state[i];
    struct link* slink = m->link;
    if (m->sls == sls) {
      if (link->linkset == slink->linkset) {
	fifo_log(m, LOG_DEBUG, "Target slink %s %d -> %s\n", originalm->name, sls, m->name);
        return m;
      }
      if (is_combined_linkset(link->linkset, slink->linkset))
        bestm = m;
    }
  }
  fifo_log(originalm, LOG_DEBUG, "Target slink %s %d -> %s\n", originalm->name, sls, bestm ? bestm->name : "(none)");
  return bestm;
}


static void mtp_put(mtp2_t *m, struct mtp_event *event) {
  static int log_safe_count = 0;
  int res;

  res = lffifo_put(receivebuf, (unsigned char *)event,
                   sizeof(*event) + event->len);
  if(res) {
    /* Can't fifo_log() here, or we would get an infinite loop. */
    /* Still, avoid excessive logging if the other thread gets long behind. */
    if(log_safe_count == 0) {
      ast_log(LOG_NOTICE, "Full MTP receivebuf, event lost, type=%d.\n", event->typ);
      log_safe_count = 2000;
    }
  } else {
    /* Wake up the other end. */
    write(receivepipe[1], "\0", 1);
  }
  if ((event->typ == MTP_EVENT_ISUP) || (event->typ == MTP_EVENT_STATUS)) {
    cluster_mtp_received(m ? m->link : NULL, event);
  }

  if(log_safe_count > 0) {
    log_safe_count--;
  }
}

/* Use this instead of ast_log() in the MTP thread, to avoid locking
   issues interupting the link timing.
   Note that LOG_WHATEVER includes all of (level, file, line, function), thanks
   to #define trickery in asterisk/logger.h! */

/* Grmble... stupid GCC allows the __attribute__ only in a
   declaration, not definition. */
static void fifo_log(mtp2_t *m, int level, const char *file, int line,
		     const char *function, const char *format, ...)
{
  va_list arg;
  unsigned char buf[MTP_EVENT_MAX_SIZE];
  struct mtp_event *event = (struct mtp_event *)buf;

  event->typ = MTP_EVENT_LOG;
  event->log.level = level;
  event->log.file = file;
  event->log.line = line;
  event->log.function = function;
  va_start(arg, format);
  vsnprintf((char*)event->buf, sizeof(buf) - sizeof(struct mtp_event), format, arg);
  va_end(arg);
  event->len = strlen((char*)event->buf) + 1;
  mtp_put(m, event);
}

static void log_frame(mtp2_t *m, int out, unsigned char *buf, int len) {
  unsigned char ebuf[MTP_EVENT_MAX_SIZE];

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品一区二区三区香蕉蜜桃 | 欧美日本韩国一区| 色视频成人在线观看免| 欧美亚洲国产怡红院影院| 欧美午夜理伦三级在线观看| 91精品国产综合久久久久| 日韩欧美在线1卡| 欧美精品一区二| 国产精品网站在线| 亚洲国产成人va在线观看天堂| 午夜国产精品影院在线观看| 老司机精品视频在线| 丁香天五香天堂综合| 欧美性做爰猛烈叫床潮| 精品伦理精品一区| 亚洲视频一区二区在线观看| 午夜激情综合网| 国产成人免费9x9x人网站视频| 国产精品88av| 欧美中文字幕一区| 久久欧美一区二区| 亚洲一区二区影院| 成人自拍视频在线观看| 欧美日韩精品欧美日韩精品一综合| 2017欧美狠狠色| 亚洲免费av网站| 国产毛片精品国产一区二区三区| 色视频一区二区| 久久精品视频一区| 麻豆精品一区二区| 欧美手机在线视频| 欧美激情一区二区三区| 另类人妖一区二区av| 91国偷自产一区二区三区成为亚洲经典| 在线不卡一区二区| 亚洲激情自拍偷拍| 懂色av中文字幕一区二区三区| 69久久夜色精品国产69蝌蚪网| 久久综合九色综合欧美亚洲| 亚洲成a人v欧美综合天堂| gogogo免费视频观看亚洲一| 中文文精品字幕一区二区| 亚洲综合精品久久| 91亚洲精华国产精华精华液| 久久精品视频免费| 免费精品视频最新在线| av在线一区二区三区| 国产亚洲欧美在线| 精品一区二区免费看| 欧美日韩精品高清| 亚洲成人免费av| 欧美日韩在线精品一区二区三区激情| 国产精品久久久久久久久动漫| 国产麻豆午夜三级精品| 欧美xxx久久| 久久国产日韩欧美精品| 欧美亚洲一区二区在线观看| 亚洲综合另类小说| 欧美日韩亚洲综合一区| 国产精品欧美久久久久无广告| 国产一区二区三区香蕉| 国产亚洲综合在线| 国产成人亚洲综合a∨婷婷图片| 欧美一区二区三区免费观看视频| 无吗不卡中文字幕| 日韩亚洲欧美在线| 精品亚洲国产成人av制服丝袜 | 亚洲电影一区二区| 欧美自拍丝袜亚洲| 天堂蜜桃91精品| 欧美一区二区三区啪啪| 免费人成网站在线观看欧美高清| 欧美一区二区美女| 天使萌一区二区三区免费观看| 精品国产99国产精品| 99r国产精品| 美国欧美日韩国产在线播放| 国产精品福利影院| 欧美大白屁股肥臀xxxxxx| 成人黄页在线观看| 麻豆久久久久久久| 亚洲天堂av一区| 久久久久久久综合色一本| 在线看国产日韩| 国产精品一二三区在线| 丝袜亚洲另类丝袜在线| 日本一区二区三区免费乱视频| 欧美日本在线观看| 97久久人人超碰| 国产精品一区二区不卡| 日韩精品免费视频人成| 中文字幕在线不卡视频| 久久综合色婷婷| 欧美精品一二三| 色婷婷一区二区| 成人黄色软件下载| 国产一区二区三区日韩| 视频一区二区中文字幕| 一区二区三区四区国产精品| 国产喷白浆一区二区三区| 欧美大片在线观看一区二区| 欧美日韩一级二级| 日本高清不卡视频| 99国产一区二区三精品乱码| 国产成人超碰人人澡人人澡| 久草中文综合在线| 蜜臀av性久久久久蜜臀aⅴ| 亚洲风情在线资源站| 亚洲一区在线观看视频| 亚洲欧美另类图片小说| 亚洲丝袜自拍清纯另类| 中文字幕欧美三区| 中文字幕av不卡| 国产三区在线成人av| 国产性色一区二区| 国产精品久久午夜| 欧美激情一区二区三区不卡| 久久久久88色偷偷免费| 久久精品一区蜜桃臀影院| 精品国产一区二区在线观看| 欧美大片在线观看一区| 久久综合狠狠综合| 国产亚洲综合色| 欧美激情中文字幕| 亚洲欧洲成人自拍| 亚洲三级在线播放| 一区二区三区中文字幕精品精品| 亚洲色图第一区| 亚洲国产综合在线| 五月综合激情日本mⅴ| 免费av成人在线| 极品少妇一区二区三区精品视频| 国模无码大尺度一区二区三区| 精品一区二区三区在线观看| 精品中文字幕一区二区| 国产在线播放一区三区四| 成人性色生活片免费看爆迷你毛片| 成人黄色av网站在线| 91在线你懂得| 欧美日韩久久不卡| 欧美精品一区二区三区在线播放 | 欧美一区二区三区喷汁尤物| 日韩一级二级三级精品视频| 26uuu久久综合| 国产精品天天摸av网| 一二三四社区欧美黄| 亚洲国产综合在线| 黄一区二区三区| 99精品热视频| 51精品秘密在线观看| 国产三级三级三级精品8ⅰ区| 中文字幕在线不卡国产视频| 亚洲福中文字幕伊人影院| 久久成人免费网| 91视频免费播放| 日韩一级欧美一级| 日韩毛片一二三区| 日本欧美一区二区在线观看| 国产福利一区在线| 欧美丝袜自拍制服另类| 精品国产电影一区二区| 亚洲天堂久久久久久久| 久久超碰97中文字幕| 一本一本大道香蕉久在线精品 | 亚洲色欲色欲www| 日韩国产在线一| av动漫一区二区| 亚洲精品一区二区三区四区高清| 亚洲欧美成aⅴ人在线观看| 久草中文综合在线| 日韩一级在线观看| 亚洲色图另类专区| 国产麻豆精品久久一二三| 在线观看亚洲一区| 国产日韩欧美综合一区| 日韩成人一级片| 色综合久久久网| 欧美激情在线看| 国产在线视频一区二区| 欧美日本韩国一区二区三区视频| 中文字幕av在线一区二区三区| 蜜桃一区二区三区在线| 色综合色综合色综合| 中日韩免费视频中文字幕| 久久99国产精品久久| 91.com视频| 亚洲国产欧美另类丝袜| 色悠久久久久综合欧美99| 国产精品卡一卡二| 国产麻豆精品在线观看| 欧美大片一区二区三区| 免费在线观看成人| 在线观看91av| 婷婷久久综合九色综合伊人色| 91蜜桃免费观看视频| 国产精品福利一区| 成人app软件下载大全免费| 九九**精品视频免费播放| 欧美日本视频在线| 夜夜操天天操亚洲|