From e6f778ebffbb5b6431b211e6003056f54ab79ff4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 19 Apr 2007 15:34:30 +0000 Subject: [PATCH] update wanpipe git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4971 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_wanpipe/Makefile | 2 +- .../mod_wanpipe/libsangoma/libsangoma.c | 65 +++++++++++++------ .../mod_wanpipe/libsangoma/libsangoma.h | 30 ++++----- .../mod_wanpipe/libsangoma/sangoma_pri.c | 28 ++++---- .../mod_wanpipe/libsangoma/sangoma_pri.h | 4 ++ src/mod/endpoints/mod_wanpipe/mod_wanpipe.c | 15 +++++ 6 files changed, 91 insertions(+), 53 deletions(-) diff --git a/src/mod/endpoints/mod_wanpipe/Makefile b/src/mod/endpoints/mod_wanpipe/Makefile index 15c3dc8f05..d394407511 100644 --- a/src/mod/endpoints/mod_wanpipe/Makefile +++ b/src/mod/endpoints/mod_wanpipe/Makefile @@ -3,7 +3,7 @@ LIBPRI_HOST=http://ftp.digium.com/pub/libpri LIBPRI=libpri-1.2.4 LIBPRI_FILE=$(LIBPRI).tar.gz LIBPRI_DIR=$(BASE)/libs/$(LIBPRI) -WANPIPE=wanpipe-3.1.0.p15 +WANPIPE=wanpipe-3.1.0.p18 WANPIPE_HOST=ftp://ftp.sangoma.com/linux/custom/3.1 WANPIPE_FILE=$(WANPIPE).tgz WANPIPE_DIR=$(BASE)/libs/$(WANPIPE) diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c index 4e5c09e8c5..282bd3c2a3 100644 --- a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c +++ b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c @@ -1,25 +1,6 @@ -/***************************************************************************** - * libsangoma.c AFT T1/E1: HDLC API Code Library - * - * Author(s): Anthony Minessale II - * Nenad Corbic - * David Rokhvarg - * Michael Jerris - * - * Copyright: (c) 2005 Anthony Minessale II - * - * This program 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. - * ============================================================================ - * - * Aug 15, 2006 David Rokhvarg Ported to MS Windows 2000/XP - * Sep 24, 2006 Michael Jerris Windows port, standardize api, cleanup - * - */ - #include "libsangoma.h" +#include + #define DFT_CARD "wanpipe1" #if defined(WIN32) @@ -265,6 +246,48 @@ sng_fd_t sangoma_open_tdmapi_span(int span) return fd; } +static char *cut_path(char *in) +{ + char *p, *ret = in; + char delims[] = "/\\"; + char *i; + + for (i = delims; *i; i++) { + p = in; + while ((p = strchr(p, *i)) != 0) { + ret = ++p; + } + } + return ret; +} + + +static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + char *fp; + char data[1024]; + + va_list ap; + + fp = cut_path(file); + + va_start(ap, fmt); + + vsnprintf(data, sizeof(data), fmt, ap); + + fprintf(stderr, "%s:%d %s() %s", file, line, func, data); + + va_end(ap); + +} + +sangoma_logger_t global_logger = default_logger; + +void sangoma_set_logger(sangoma_logger_t logger) +{ + global_logger = logger; +} + int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag) { int rx_len=0; diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h index 0577165de0..14a5d99785 100644 --- a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h +++ b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h @@ -1,18 +1,3 @@ -/***************************************************************************** - * libsangoma.c AFT T1/E1: HDLC API Code Library - * - * Author(s): Anthony Minessale II - * Nenad Corbic - * - * Copyright: (c) 2005 Anthony Minessale II - * - * This program 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. - * ============================================================================ - */ - #ifndef _LIBSNAGOMA_H #define _LIBSNAGOMA_H #include @@ -161,6 +146,21 @@ int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api); int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api); int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api); +#define WP_PRE __FILE__, __FUNCTION__, __LINE__ +#define WP_LOG_DEBUG WP_PRE, 7 +#define WP_LOG_INFO WP_PRE, 6 +#define WP_LOG_NOTICE WP_PRE, 5 +#define WP_LOG_WARNING WP_PRE, 4 +#define WP_LOG_ERROR WP_PRE, 3 +#define WP_LOG_CRIT WP_PRE, 2 +#define WP_LOG_ALERT WP_PRE, 1 +#define WP_LOG_EMERG WP_PRE, 0 + +typedef void (*sangoma_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); +void sangoma_set_logger(sangoma_logger_t logger); + +extern sangoma_logger_t global_logger; + #ifndef LIBSANGOMA_GET_HWCODING #define LIBSANGOMA_GET_HWCODING 1 #endif diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c b/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c index b459edd65a..c5dcb2cd63 100644 --- a/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c +++ b/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c @@ -1,18 +1,3 @@ -/***************************************************************************** - * sangoma_pri.c libpri Sangoma integration - * - * Author(s): Anthony Minessale II - * Nenad Corbic - * - * Copyright: (c) 2005 Anthony Minessale II - * - * This program 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. - * ============================================================================ - */ - #include #include #ifndef HAVE_GETTIMEOFDAY @@ -158,6 +143,10 @@ int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, } else { if ((spri->pri = pri_new_cb((int) dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))) { spri->span = span; + spri->dchan = dchan; + spri->swtype = swtype; + spri->node = node; + spri->debug = debug; pri_set_debug(spri->pri, debug); ret = 0; } else { @@ -183,7 +172,7 @@ int sangoma_one_loop(struct sangoma_pri *spri) FD_ZERO(&efds); #ifdef _MSC_VER -//Windows macro for FD_SET includes a warning C4127: conditional expression is constant +//Windows macro for FD_SET includes a warning C4127: conditional expression is constant #pragma warning(push) #pragma warning(disable:4127) #endif @@ -211,6 +200,13 @@ int sangoma_one_loop(struct sangoma_pri *spri) sel = select(spri->pri->fd + 1, &rfds, NULL, &efds, next ? &now : NULL); event = NULL; + + if (FD_ISSET(spri->pri->fd, &efds)) { + wanpipe_tdm_api_t tdm_api = {0}; + + sangoma_tdm_read_event(spri->pri->fd, &tdm_api); + global_logger(WP_LOG_ERROR, "DCHANNEL ERROR! [span %d]\n", spri->span); + } if (!sel) { event = pri_schedule_run(spri->pri); diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h b/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h index 7aed00b07e..5c3512aa12 100644 --- a/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h +++ b/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h @@ -79,6 +79,10 @@ struct sangoma_pri { void *private_info; event_handler eventmap[MAX_EVENT + 1]; loop_handler on_loop; + int dfd; + int swtype; + int node; + int debug; }; struct sangoma_pri_event_list { diff --git a/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c b/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c index 3d51d7b815..fe19e89301 100644 --- a/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c +++ b/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c @@ -211,6 +211,19 @@ typedef struct private_object private_object_t; +static void wp_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + va_list ap; + char *data = NULL; + int ret; + + va_start(ap, fmt); + if ((ret = switch_vasprintf(&data, fmt, ap)) != -1) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level, "%s", data); + } + va_end(ap); +} + static int local_sangoma_tdm_read_event(sng_fd_t fd, wp_tdm_api_rx_hdr_t *rx_event) { wanpipe_tdm_api_t tdm_api[1]; @@ -1299,6 +1312,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod { switch_status_t status = SWITCH_STATUS_SUCCESS; + sangoma_set_logger(wp_logger); + memset(SPANS, 0, sizeof(SPANS)); pri_set_error(s_pri_error);