mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-16 08:49:01 +00:00
Linux renaming from openzap to freetdm
git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@967 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
0346bc76cc
commit
900f1ed2ef
@ -36,11 +36,11 @@ moddir = @modinstdir@
|
||||
libdir = @libdir@
|
||||
library_includedir = $(PREFIX)/include
|
||||
|
||||
INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include
|
||||
INCS = -I$(FT_SRCDIR)/$(SRC)/include -I$(FT_SRCDIR)/$(SRC)/isdn/include
|
||||
if HAVE_SCTP
|
||||
INCS += -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost
|
||||
INCS += -I$(FT_SRCDIR)/$(SRC)/ftmod/ftmod_sangoma_boost
|
||||
endif
|
||||
MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@
|
||||
MY_CFLAGS = $(INCS) $(FTDM_CFLAGS) -DFTDM_CONFIG_DIR=\"@confdir@\" -DFTDM_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@
|
||||
COMPILE = $(CC) $(MY_CFLAGS) $(INCS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE)
|
||||
LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@
|
||||
@ -49,30 +49,30 @@ LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@
|
||||
#
|
||||
# GNU pkgconfig file
|
||||
#
|
||||
EXTRA_DIST = openzap.pc.in
|
||||
EXTRA_DIST = freetdm.pc.in
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = openzap.pc
|
||||
pkgconfig_DATA = freetdm.pc
|
||||
|
||||
|
||||
#
|
||||
# libopenzap
|
||||
# libfreetdm
|
||||
#
|
||||
libopenzap_la_SOURCES = \
|
||||
libfreetdm_la_SOURCES = \
|
||||
$(SRC)/hashtable.c \
|
||||
$(SRC)/hashtable_itr.c \
|
||||
$(SRC)/zap_io.c \
|
||||
$(SRC)/zap_queue.c \
|
||||
$(SRC)/zap_config.c \
|
||||
$(SRC)/zap_callerid.c \
|
||||
$(SRC)/ftdm_io.c \
|
||||
$(SRC)/ftdm_queue.c \
|
||||
$(SRC)/ftdm_config.c \
|
||||
$(SRC)/ftdm_callerid.c \
|
||||
$(SRC)/fsk.c \
|
||||
$(SRC)/uart.c \
|
||||
$(SRC)/g711.c \
|
||||
$(SRC)/libteletone_detect.c \
|
||||
$(SRC)/libteletone_generate.c \
|
||||
$(SRC)/zap_buffer.c \
|
||||
$(SRC)/zap_threadmutex.c \
|
||||
$(SRC)/zap_dso.c
|
||||
$(SRC)/ftdm_buffer.c \
|
||||
$(SRC)/ftdm_threadmutex.c \
|
||||
$(SRC)/ftdm_dso.c
|
||||
|
||||
library_include_HEADERS = \
|
||||
$(SRC)/include/fsk.h \
|
||||
@ -83,23 +83,23 @@ $(SRC)/include/hashtable_private.h \
|
||||
$(SRC)/include/libteletone_detect.h \
|
||||
$(SRC)/include/libteletone_generate.h \
|
||||
$(SRC)/include/libteletone.h \
|
||||
$(SRC)/include/openzap.h \
|
||||
$(SRC)/include/freetdm.h \
|
||||
$(SRC)/include/sangoma_tdm_api.h \
|
||||
$(SRC)/include/uart.h \
|
||||
$(SRC)/include/zap_buffer.h \
|
||||
$(SRC)/include/zap_config.h \
|
||||
$(SRC)/include/zap_threadmutex.h \
|
||||
$(SRC)/include/zap_dso.h \
|
||||
$(SRC)/include/zap_types.h
|
||||
$(SRC)/include/ftdm_buffer.h \
|
||||
$(SRC)/include/ftdm_config.h \
|
||||
$(SRC)/include/ftdm_threadmutex.h \
|
||||
$(SRC)/include/ftdm_dso.h \
|
||||
$(SRC)/include/ftdm_types.h
|
||||
|
||||
lib_LTLIBRARIES = libopenzap.la
|
||||
libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS)
|
||||
libopenzap_la_LIBADD = $(LIBS)
|
||||
lib_LTLIBRARIES = libfreetdm.la
|
||||
libfreetdm_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
libfreetdm_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS)
|
||||
libfreetdm_la_LIBADD = $(LIBS)
|
||||
|
||||
MYLIB = libopenzap.la
|
||||
MYLIB = libfreetdm.la
|
||||
|
||||
core: libopenzap.la
|
||||
core: libfreetdm.la
|
||||
core-install: install-libLTLIBRARIES
|
||||
|
||||
#
|
||||
@ -112,91 +112,91 @@ endif
|
||||
noinst_PROGRAMS += testsangomaboost
|
||||
|
||||
testapp_SOURCES = $(SRC)/testapp.c
|
||||
testapp_LDADD = libopenzap.la
|
||||
testapp_LDADD = libfreetdm.la
|
||||
testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
testcid_SOURCES = $(SRC)/testcid.c
|
||||
testcid_LDADD = libopenzap.la
|
||||
testcid_LDADD = libfreetdm.la
|
||||
testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
testtones_SOURCES = $(SRC)/testtones.c
|
||||
testtones_LDADD = libopenzap.la
|
||||
testtones_LDADD = libfreetdm.la
|
||||
testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
detect_tones_SOURCES = $(SRC)/detect_tones.c
|
||||
detect_tones_LDADD = libopenzap.la
|
||||
detect_tones_LDADD = libfreetdm.la
|
||||
detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
detect_dtmf_SOURCES = $(SRC)/detect_dtmf.c
|
||||
detect_dtmf_LDADD = libopenzap.la
|
||||
detect_dtmf_LDADD = libfreetdm.la
|
||||
detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
testisdn_SOURCES = $(SRC)/testisdn.c
|
||||
testisdn_LDADD = libopenzap.la
|
||||
testisdn_LDADD = libfreetdm.la
|
||||
testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
testpri_SOURCES = $(SRC)/testpri.c
|
||||
testpri_LDADD = libopenzap.la
|
||||
testpri_LDADD = libfreetdm.la
|
||||
testpri_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
testr2_SOURCES = $(SRC)/testr2.c
|
||||
testr2_LDADD = libopenzap.la
|
||||
testr2_LDADD = libfreetdm.la
|
||||
testr2_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
if HAVE_SCTP
|
||||
testboost_SOURCES = $(SRC)/testboost.c
|
||||
testboost_LDADD = libopenzap.la
|
||||
testboost_LDADD = libfreetdm.la
|
||||
testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
endif
|
||||
|
||||
testsangomaboost_SOURCES = $(SRC)/testsangomaboost.c
|
||||
testsangomaboost_LDADD = libopenzap.la
|
||||
testsangomaboost_LDADD = libfreetdm.la
|
||||
testsangomaboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
testanalog_SOURCES = $(SRC)/testanalog.c
|
||||
testanalog_LDADD = libopenzap.la
|
||||
testanalog_LDADD = libfreetdm.la
|
||||
testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
||||
#
|
||||
# ozmod modules
|
||||
# ftmod modules
|
||||
#
|
||||
mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la
|
||||
mod_LTLIBRARIES = ftmod_zt.la ftmod_skel.la ftmod_isdn.la ftmod_analog.la ftmod_analog_em.la
|
||||
|
||||
|
||||
if HAVE_SCTP
|
||||
mod_LTLIBRARIES += ozmod_sangoma_boost.la
|
||||
mod_LTLIBRARIES += ftmod_sangoma_boost.la
|
||||
endif
|
||||
|
||||
if LIBSANGOMA
|
||||
mod_LTLIBRARIES += ozmod_wanpipe.la
|
||||
mod_LTLIBRARIES += ftmod_wanpipe.la
|
||||
endif
|
||||
|
||||
if LIBPRI
|
||||
mod_LTLIBRARIES += ozmod_libpri.la
|
||||
mod_LTLIBRARIES += ftmod_libpri.la
|
||||
endif
|
||||
|
||||
if OPENR2
|
||||
mod_LTLIBRARIES += ozmod_r2.la
|
||||
mod_LTLIBRARIES += ftmod_r2.la
|
||||
endif
|
||||
|
||||
ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c
|
||||
ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ozmod_zt_la_LDFLAGS = -module -avoid-version
|
||||
ozmod_zt_la_LIBADD = $(MYLIB)
|
||||
ftmod_zt_la_SOURCES = $(SRC)/ftmod/ftmod_zt/ftmod_zt.c
|
||||
ftmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ftmod_zt_la_LDFLAGS = -module -avoid-version
|
||||
ftmod_zt_la_LIBADD = $(MYLIB)
|
||||
|
||||
ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c
|
||||
ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ozmod_skel_la_LDFLAGS = -module -avoid-version
|
||||
ozmod_skel_la_LIBADD = $(MYLIB)
|
||||
ftmod_skel_la_SOURCES = $(SRC)/ftmod/ftmod_skel/ftmod_skel.c
|
||||
ftmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ftmod_skel_la_LDFLAGS = -module -avoid-version
|
||||
ftmod_skel_la_LIBADD = $(MYLIB)
|
||||
|
||||
if LIBSANGOMA
|
||||
ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c
|
||||
ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe
|
||||
ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma
|
||||
ozmod_wanpipe_la_LIBADD = $(MYLIB)
|
||||
ftmod_wanpipe_la_SOURCES = $(SRC)/ftmod/ftmod_wanpipe/ftmod_wanpipe.c
|
||||
ftmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe
|
||||
ftmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma
|
||||
ftmod_wanpipe_la_LIBADD = $(MYLIB)
|
||||
endif
|
||||
|
||||
ozmod_isdn_la_SOURCES = \
|
||||
ftmod_isdn_la_SOURCES = \
|
||||
$(SRC)/isdn/EuroISDNStateNT.c \
|
||||
$(SRC)/isdn/EuroISDNStateTE.c \
|
||||
$(SRC)/isdn/mfifo.c \
|
||||
@ -217,60 +217,60 @@ $(SRC)/isdn/5ESSmes.c \
|
||||
$(SRC)/isdn/5ESSStateNT.c \
|
||||
$(SRC)/isdn/5ESSStateTE.c \
|
||||
$(SRC)/isdn/Q932mes.c \
|
||||
$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c
|
||||
$(SRC)/ftmod/ftmod_isdn/ftmod_isdn.c
|
||||
|
||||
ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE
|
||||
ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -avoid-version
|
||||
ozmod_isdn_la_LIBADD = $(MYLIB)
|
||||
ftmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE
|
||||
ftmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -avoid-version
|
||||
ftmod_isdn_la_LIBADD = $(MYLIB)
|
||||
|
||||
ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c
|
||||
ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ozmod_analog_la_LDFLAGS = -module -avoid-version
|
||||
ozmod_analog_la_LIBADD = $(MYLIB)
|
||||
ftmod_analog_la_SOURCES = $(SRC)/ftmod/ftmod_analog/ftmod_analog.c
|
||||
ftmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ftmod_analog_la_LDFLAGS = -module -avoid-version
|
||||
ftmod_analog_la_LIBADD = $(MYLIB)
|
||||
|
||||
ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c
|
||||
ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ozmod_analog_em_la_LDFLAGS = -module -avoid-version
|
||||
ozmod_analog_em_la_LIBADD = $(MYLIB)
|
||||
ftmod_analog_em_la_SOURCES = $(SRC)/ftmod/ftmod_analog_em/ftmod_analog_em.c
|
||||
ftmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ftmod_analog_em_la_LDFLAGS = -module -avoid-version
|
||||
ftmod_analog_em_la_LIBADD = $(MYLIB)
|
||||
|
||||
if HAVE_SCTP
|
||||
ozmod_sangoma_boost_la_SOURCES = $(SRC)/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c
|
||||
ozmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ozmod_sangoma_boost_la_LDFLAGS = -module -avoid-version
|
||||
ozmod_sangoma_boost_la_LIBADD = $(MYLIB)
|
||||
ftmod_sangoma_boost_la_SOURCES = $(SRC)/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c
|
||||
ftmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ftmod_sangoma_boost_la_LDFLAGS = -module -avoid-version
|
||||
ftmod_sangoma_boost_la_LIBADD = $(MYLIB)
|
||||
endif
|
||||
|
||||
if LIBPRI
|
||||
ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c
|
||||
ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ozmod_libpri_la_LDFLAGS = -module -avoid-version -lpri
|
||||
ozmod_libpri_la_LIBADD = $(MYLIB)
|
||||
ftmod_libpri_la_SOURCES = $(SRC)/ftmod/ftmod_libpri/ftmod_libpri.c $(SRC)/ftmod/ftmod_libpri/lpwrap_pri.c
|
||||
ftmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ftmod_libpri_la_LDFLAGS = -module -avoid-version -lpri
|
||||
ftmod_libpri_la_LIBADD = $(MYLIB)
|
||||
endif
|
||||
|
||||
if OPENR2
|
||||
ozmod_r2_la_SOURCES = $(SRC)/ozmod/ozmod_r2/ozmod_r2.c
|
||||
ozmod_r2_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ozmod_r2_la_LDFLAGS = -module -avoid-version -lopenr2
|
||||
ozmod_r2_la_LIBADD = $(MYLIB)
|
||||
ftmod_r2_la_SOURCES = $(SRC)/ftmod/ftmod_r2/ftmod_r2.c
|
||||
ftmod_r2_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
ftmod_r2_la_LDFLAGS = -module -avoid-version -lopenr2
|
||||
ftmod_r2_la_LIBADD = $(MYLIB)
|
||||
endif
|
||||
|
||||
|
||||
dox doxygen:
|
||||
cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf
|
||||
cd docs && doxygen $(FT_SRCDIR)/docs/Doxygen.conf
|
||||
|
||||
mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c
|
||||
cd mod_openzap && make
|
||||
mod_freetdm/mod_freetdm.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_freetdm/mod_freetdm.c
|
||||
cd mod_freetdm && make
|
||||
|
||||
mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN)
|
||||
mod_freetdm: mod_freetdm/mod_freetdm.$(DYNAMIC_LIB_EXTEN)
|
||||
|
||||
mod_openzap-install: mod_openzap
|
||||
cd mod_openzap && make install
|
||||
mod_freetdm-install: mod_freetdm
|
||||
cd mod_freetdm && make install
|
||||
|
||||
mod_openzap-clean:
|
||||
@if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi
|
||||
mod_freetdm-clean:
|
||||
@if [ -f mod_freetdm/mod_freetdm.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_freetdm && make clean ; fi
|
||||
|
||||
install-data-local:
|
||||
$(mkinstalldirs) $(DESTDIR)$(PREFIX)
|
||||
$(mkinstalldirs) $(DESTDIR)@confdir@
|
||||
@[ -f "$(DESTDIR)@confdir@/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)@confdir@)
|
||||
@echo OpenZAP Installed
|
||||
@[ -f "$(DESTDIR)@confdir@/freetdm.conf" ] || ( cp conf/*.conf $(DESTDIR)@confdir@)
|
||||
@echo OpenFTDM Installed
|
||||
|
@ -2,28 +2,28 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.59)
|
||||
AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org])
|
||||
AC_CONFIG_SRCDIR([src/zap_io.c])
|
||||
AC_INIT([freetdm],[pre-alpha],[bugs@freeswitch.org])
|
||||
AC_CONFIG_SRCDIR([src/ftdm_io.c])
|
||||
|
||||
AC_CONFIG_AUX_DIR(build)
|
||||
AM_INIT_AUTOMAKE(libopenzap,0.1)
|
||||
AM_INIT_AUTOMAKE(libfreetdm,0.1)
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_MAKE_SET
|
||||
AM_PROG_CC_C_O
|
||||
|
||||
AC_PREFIX_DEFAULT(/usr/local/openzap)
|
||||
AC_PREFIX_DEFAULT(/usr/local/freetdm)
|
||||
# AC_PREFIX_DEFAULT does not get expanded until too late so we need to do this to use prefix in this script
|
||||
if test "x$prefix" = "xNONE" ; then
|
||||
prefix='/usr/local/openzap'
|
||||
prefix='/usr/local/freetdm'
|
||||
fi
|
||||
|
||||
# Absolute source/build directory
|
||||
OZ_SRCDIR=`(cd $srcdir && pwd)`
|
||||
oz_builddir=`pwd`
|
||||
AC_SUBST(OZ_SRCDIR)
|
||||
AC_SUBST(oz_builddir)
|
||||
FT_SRCDIR=`(cd $srcdir && pwd)`
|
||||
ft_builddir=`pwd`
|
||||
AC_SUBST(FT_SRCDIR)
|
||||
AC_SUBST(ft_builddir)
|
||||
|
||||
if test "$sysconfdir" = "\${prefix}/etc" ; then
|
||||
confdir="$prefix/conf"
|
||||
@ -162,7 +162,7 @@ AC_SUBST(modinstdir)
|
||||
|
||||
# libpri?
|
||||
AC_ARG_WITH([libpri],
|
||||
[AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"])
|
||||
[AS_HELP_STRING([--with-libpri], [Install ftmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"])
|
||||
AC_SUBST(enable_libpri)
|
||||
|
||||
AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"])
|
||||
@ -176,6 +176,6 @@ AM_CONDITIONAL([OPENR2],[test "${have_openr2}" = "yes"])
|
||||
COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS"
|
||||
AC_SUBST(COMP_VENDOR_CFLAGS)
|
||||
AC_CONFIG_FILES([Makefile
|
||||
openzap.pc
|
||||
mod_openzap/Makefile])
|
||||
freetdm.pc
|
||||
mod_freetdm/Makefile])
|
||||
AC_OUTPUT
|
||||
|
23
libs/freetdm/mod_freetdm/Makefile.in
Normal file
23
libs/freetdm/mod_freetdm/Makefile.in
Normal file
@ -0,0 +1,23 @@
|
||||
FT_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@
|
||||
|
||||
BASE=../../..
|
||||
FT_DIR=..
|
||||
VERBOSE=1
|
||||
FTLA=$(FT_DIR)/libfreetdm.la
|
||||
LOCAL_CFLAGS=-I$(FT_DIR)/src/include -I$(FT_DIR)/src/isdn/include $(FT_CFLAGS)
|
||||
LOCAL_LDFLAGS=-L$(FT_DIR) -lfreetdm
|
||||
include $(BASE)/build/modmake.rules
|
||||
|
||||
local_depend: $(FTLA)
|
||||
|
||||
$(FTLA): $(FT_DIR)/.update
|
||||
cd $(FT_DIR) && $(MAKE)
|
||||
|
||||
local_install:
|
||||
cd $(FT_DIR) && $(MAKE) install
|
||||
[ -f $(DESTDIR)@confdir@/autoload_configs/freetdm.conf.xml ] || cp -f $(FT_DIR)/conf/freetdm.conf.xml $(DESTDIR)@confdir@/autoload_configs
|
||||
|
||||
local_clean:
|
||||
cd $(FT_DIR) && $(MAKE) clean
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,23 +0,0 @@
|
||||
OZ_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@
|
||||
|
||||
BASE=../../..
|
||||
OZ_DIR=..
|
||||
VERBOSE=1
|
||||
OZLA=$(OZ_DIR)/libopenzap.la
|
||||
LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include $(OZ_CFLAGS)
|
||||
LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap
|
||||
include $(BASE)/build/modmake.rules
|
||||
|
||||
local_depend: $(OZLA)
|
||||
|
||||
$(OZLA): $(OZ_DIR)/.update
|
||||
cd $(OZ_DIR) && $(MAKE)
|
||||
|
||||
local_install:
|
||||
cd $(OZ_DIR) && $(MAKE) install
|
||||
[ -f $(DESTDIR)@confdir@/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)@confdir@/autoload_configs
|
||||
|
||||
local_clean:
|
||||
cd $(OZ_DIR) && $(MAKE) clean
|
||||
|
||||
|
@ -1,40 +1,57 @@
|
||||
# renaming main header and build file
|
||||
move="mv"
|
||||
$move src/include/openzap.h src/include/freetdm.h
|
||||
$move openzap.pc.in freetdm.pc.in
|
||||
$move mod_openzap/mod_openzap.c mod_openzap/mod_freetdm.c
|
||||
$move mod_openzap mod_freetdm
|
||||
copy="cp -r"
|
||||
|
||||
$copy src/include/openzap.h src/include/freetdm.h
|
||||
svn delete src/include/openzap.h
|
||||
$copy openzap.pc.in freetdm.pc.in
|
||||
svn delete openzap.pc.in
|
||||
|
||||
# create mod_freetdm
|
||||
mkdir mod_freetdm
|
||||
cp mod_openzap/* mod_freetdm/
|
||||
mv mod_freetdm/mod_openzap.c mod_freetdm/mod_freetdm.c
|
||||
svn delete --force mod_openzap
|
||||
|
||||
|
||||
##### ozmod stuff ####
|
||||
# rename anything ozmod to ftmod, including directories first
|
||||
$move src/ozmod src/ftmod
|
||||
for file in `find ./ -name *ozmod_* -type d`
|
||||
mkdir ./src/ftmod
|
||||
for file in `find ./src/ozmod -name *ozmod_* -type d`
|
||||
do
|
||||
$move $file ${file//ozmod/ftmod}
|
||||
$copy ${file} ${file//ozmod/ftmod}
|
||||
done
|
||||
|
||||
# move ozmod c files
|
||||
for file in `find ./ -name *ozmod_*.c`
|
||||
#remove .svn directories in the copied ozmod dirs
|
||||
find ./src/ftmod -name *.svn -exec rm -rf {} \;
|
||||
|
||||
# copy ozmod c files
|
||||
for file in `find ./src/ftmod -name *ozmod_*.c`
|
||||
do
|
||||
$move $file ${file//ozmod/ftmod}
|
||||
mv $file ${file//ozmod/ftmod}
|
||||
done
|
||||
|
||||
# move ozmod h files
|
||||
for file in `find ./ -name *ozmod_*.h`
|
||||
# copy ozmod h files
|
||||
for file in `find ./src/ftmod -name *ozmod_*.h`
|
||||
do
|
||||
$move $file ${file//ozmod/ftmod}
|
||||
mv $file ${file//ozmod/ftmod}
|
||||
done
|
||||
|
||||
# renaming other files
|
||||
#### end ozmod stuff ####
|
||||
|
||||
# renaming other zap files
|
||||
for file in `find ./ -name *zap_*.c`
|
||||
do
|
||||
$move $file ${file//zap_/ftdm_}
|
||||
mv $file ${file//zap_/ftdm_}
|
||||
done
|
||||
|
||||
for file in `find ./ -name *zap_*.h`
|
||||
do
|
||||
$move $file ${file//zap_/ftdm_}
|
||||
mv $file ${file//zap_/ftdm_}
|
||||
done
|
||||
|
||||
svn revert -R src/ozmod
|
||||
svn delete --force src/ozmod
|
||||
|
||||
# replace full openzap occurences first (handles openzap.h, libopenzap etc)
|
||||
find ./ -name *.c -exec sed -i 's,openzap,freetdm,g' {} \;
|
||||
|
||||
@ -77,3 +94,6 @@ sed -i 's,zap,ftdm,g' mod_freetdm/Makefile.in
|
||||
sed -i 's,ZAP,FTDM,g' mod_freetdm/Makefile.in
|
||||
sed -i 's,zchan,ftdmchan,g' mod_freetdm/Makefile.in
|
||||
|
||||
svn add src/ftmod/
|
||||
svn add mod_freetdm/
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//#include "openzap.h"
|
||||
//#include "freetdm.h"
|
||||
#include "libteletone_detect.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -1,4 +1,4 @@
|
||||
//#include "openzap.h"
|
||||
//#include "freetdm.h"
|
||||
#include "libteletone_detect.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -32,7 +32,7 @@
|
||||
*
|
||||
* 2005 03 20 R. Krten created
|
||||
*/
|
||||
#include <openzap.h>
|
||||
#include <freetdm.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -134,7 +134,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr)
|
||||
double phi_mark, phi_space;
|
||||
dsp_fsk_handle_t *handle;
|
||||
|
||||
handle = zap_malloc(sizeof(*handle));
|
||||
handle = ftdm_malloc(sizeof(*handle));
|
||||
if (!handle) {
|
||||
return NULL;
|
||||
}
|
||||
@ -157,7 +157,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr)
|
||||
|
||||
/* allocate the correlation sin/cos arrays and initialize */
|
||||
for (i = 0; i < 4; i++) {
|
||||
handle->correlates[i] = zap_malloc(sizeof(double) * handle->corrsize);
|
||||
handle->correlates[i] = ftdm_malloc(sizeof(double) * handle->corrsize);
|
||||
if (handle->correlates[i] == NULL) {
|
||||
/* some failed, back out memory allocations */
|
||||
dsp_fsk_destroy(&handle);
|
||||
@ -177,7 +177,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr)
|
||||
}
|
||||
|
||||
/* initialize the ring buffer */
|
||||
handle->buffer = zap_malloc(sizeof(double) * handle->corrsize);
|
||||
handle->buffer = ftdm_malloc(sizeof(double) * handle->corrsize);
|
||||
if (!handle->buffer) { /* failed; back out memory allocations */
|
||||
dsp_fsk_destroy(&handle);
|
||||
return NULL;
|
||||
@ -226,13 +226,13 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle)
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
if ((*handle)->correlates[i] != NULL) {
|
||||
zap_safe_free((*handle)->correlates[i]);
|
||||
ftdm_safe_free((*handle)->correlates[i]);
|
||||
(*handle)->correlates[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*handle)->buffer != NULL) {
|
||||
zap_safe_free((*handle)->buffer);
|
||||
ftdm_safe_free((*handle)->buffer);
|
||||
(*handle)->buffer = NULL;
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle)
|
||||
dsp_uart_destroy(dhandle);
|
||||
}
|
||||
|
||||
zap_safe_free(*handle);
|
||||
ftdm_safe_free(*handle);
|
||||
*handle = NULL;
|
||||
}
|
||||
|
||||
|
@ -31,37 +31,37 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "zap_buffer.h"
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_buffer.h"
|
||||
|
||||
static unsigned buffer_id = 0;
|
||||
|
||||
struct zap_buffer {
|
||||
struct ftdm_buffer {
|
||||
unsigned char *data;
|
||||
unsigned char *head;
|
||||
zap_size_t used;
|
||||
zap_size_t actually_used;
|
||||
zap_size_t datalen;
|
||||
zap_size_t max_len;
|
||||
zap_size_t blocksize;
|
||||
ftdm_size_t used;
|
||||
ftdm_size_t actually_used;
|
||||
ftdm_size_t datalen;
|
||||
ftdm_size_t max_len;
|
||||
ftdm_size_t blocksize;
|
||||
unsigned id;
|
||||
int loops;
|
||||
};
|
||||
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_buffer_create(ftdm_buffer_t **buffer, ftdm_size_t blocksize, ftdm_size_t start_len, ftdm_size_t max_len)
|
||||
{
|
||||
zap_buffer_t *new_buffer;
|
||||
ftdm_buffer_t *new_buffer;
|
||||
|
||||
new_buffer = zap_malloc(sizeof(*new_buffer));
|
||||
new_buffer = ftdm_malloc(sizeof(*new_buffer));
|
||||
if (new_buffer) {
|
||||
memset(new_buffer, 0, sizeof(*new_buffer));
|
||||
|
||||
if (start_len) {
|
||||
new_buffer->data = zap_malloc(start_len);
|
||||
new_buffer->data = ftdm_malloc(start_len);
|
||||
if (!new_buffer->data) {
|
||||
zap_safe_free(new_buffer);
|
||||
return ZAP_MEMERR;
|
||||
ftdm_safe_free(new_buffer);
|
||||
return FTDM_MEMERR;
|
||||
}
|
||||
memset(new_buffer->data, 0, start_len);
|
||||
}
|
||||
@ -73,13 +73,13 @@ OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blo
|
||||
new_buffer->head = new_buffer->data;
|
||||
|
||||
*buffer = new_buffer;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
return ZAP_MEMERR;
|
||||
return FTDM_MEMERR;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_len(ftdm_buffer_t *buffer)
|
||||
{
|
||||
|
||||
assert(buffer != NULL);
|
||||
@ -89,28 +89,28 @@ OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_freespace(ftdm_buffer_t *buffer)
|
||||
{
|
||||
assert(buffer != NULL);
|
||||
|
||||
|
||||
if (buffer->max_len) {
|
||||
return (zap_size_t) (buffer->max_len - buffer->used);
|
||||
return (ftdm_size_t) (buffer->max_len - buffer->used);
|
||||
}
|
||||
return 1000000;
|
||||
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_inuse(ftdm_buffer_t *buffer)
|
||||
{
|
||||
assert(buffer != NULL);
|
||||
|
||||
return buffer->used;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_seek(ftdm_buffer_t *buffer, ftdm_size_t datalen)
|
||||
{
|
||||
zap_size_t reading = 0;
|
||||
ftdm_size_t reading = 0;
|
||||
|
||||
assert(buffer != NULL);
|
||||
|
||||
@ -129,9 +129,9 @@ OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen)
|
||||
return reading;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_toss(ftdm_buffer_t *buffer, ftdm_size_t datalen)
|
||||
{
|
||||
zap_size_t reading = 0;
|
||||
ftdm_size_t reading = 0;
|
||||
|
||||
assert(buffer != NULL);
|
||||
|
||||
@ -150,29 +150,29 @@ OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen)
|
||||
return buffer->used;
|
||||
}
|
||||
|
||||
OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int loops)
|
||||
FT_DECLARE(void) ftdm_buffer_set_loops(ftdm_buffer_t *buffer, int loops)
|
||||
{
|
||||
buffer->loops = loops;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_read_loop(ftdm_buffer_t *buffer, void *data, ftdm_size_t datalen)
|
||||
{
|
||||
zap_size_t len;
|
||||
if ((len = zap_buffer_read(buffer, data, datalen)) < datalen) {
|
||||
ftdm_size_t len;
|
||||
if ((len = ftdm_buffer_read(buffer, data, datalen)) < datalen) {
|
||||
if (buffer->loops == 0) {
|
||||
return len;
|
||||
}
|
||||
buffer->head = buffer->data;
|
||||
buffer->used = buffer->actually_used;
|
||||
len = zap_buffer_read(buffer, (char*)data + len, datalen - len);
|
||||
len = ftdm_buffer_read(buffer, (char*)data + len, datalen - len);
|
||||
buffer->loops--;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_read(ftdm_buffer_t *buffer, void *data, ftdm_size_t datalen)
|
||||
{
|
||||
zap_size_t reading = 0;
|
||||
ftdm_size_t reading = 0;
|
||||
|
||||
assert(buffer != NULL);
|
||||
assert(data != NULL);
|
||||
@ -195,9 +195,9 @@ OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_siz
|
||||
return reading;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_write(ftdm_buffer_t *buffer, const void *data, ftdm_size_t datalen)
|
||||
{
|
||||
zap_size_t freespace, actual_freespace;
|
||||
ftdm_size_t freespace, actual_freespace;
|
||||
|
||||
assert(buffer != NULL);
|
||||
assert(data != NULL);
|
||||
@ -224,7 +224,7 @@ OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data,
|
||||
*/
|
||||
|
||||
if (freespace < datalen) {
|
||||
zap_size_t new_size, new_block_size;
|
||||
ftdm_size_t new_size, new_block_size;
|
||||
void *data;
|
||||
|
||||
new_size = buffer->datalen + datalen;
|
||||
@ -258,7 +258,7 @@ OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data,
|
||||
return buffer->used;
|
||||
}
|
||||
|
||||
OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer)
|
||||
FT_DECLARE(void) ftdm_buffer_zero(ftdm_buffer_t *buffer)
|
||||
{
|
||||
assert(buffer != NULL);
|
||||
assert(buffer->data != NULL);
|
||||
@ -268,23 +268,23 @@ OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer)
|
||||
buffer->head = buffer->data;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_buffer_zwrite(ftdm_buffer_t *buffer, const void *data, ftdm_size_t datalen)
|
||||
{
|
||||
zap_size_t w;
|
||||
ftdm_size_t w;
|
||||
|
||||
if (!(w = zap_buffer_write(buffer, data, datalen))) {
|
||||
zap_buffer_zero(buffer);
|
||||
return zap_buffer_write(buffer, data, datalen);
|
||||
if (!(w = ftdm_buffer_write(buffer, data, datalen))) {
|
||||
ftdm_buffer_zero(buffer);
|
||||
return ftdm_buffer_write(buffer, data, datalen);
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer)
|
||||
FT_DECLARE(void) ftdm_buffer_destroy(ftdm_buffer_t **buffer)
|
||||
{
|
||||
if (*buffer) {
|
||||
zap_safe_free((*buffer)->data);
|
||||
zap_safe_free(*buffer);
|
||||
ftdm_safe_free((*buffer)->data);
|
||||
ftdm_safe_free(*buffer);
|
||||
}
|
||||
|
||||
*buffer = NULL;
|
@ -1,4 +1,4 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include "fsk.h"
|
||||
#include "uart.h"
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
static void fsk_byte_handler (void *x, int data)
|
||||
{
|
||||
zap_fsk_data_state_t *state = (zap_fsk_data_state_t *) x;
|
||||
ftdm_fsk_data_state_t *state = (ftdm_fsk_data_state_t *) x;
|
||||
uint8_t byte = (uint8_t)data;
|
||||
|
||||
top:
|
||||
@ -37,42 +37,42 @@ static void fsk_byte_handler (void *x, int data)
|
||||
}
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_init(ftdm_fsk_data_state_t *state, uint8_t *data, uint32_t datalen)
|
||||
{
|
||||
memset(state, 0, sizeof(*state));
|
||||
state->buf = data;
|
||||
state->bufsize = datalen;
|
||||
state->bpos = 2;
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_sdmf(ftdm_fsk_data_state_t *state, const char *date, char *number)
|
||||
{
|
||||
size_t dlen = strlen(date);
|
||||
size_t nlen = strlen(number);
|
||||
|
||||
state->buf[0] = ZAP_CID_TYPE_SDMF;
|
||||
state->buf[0] = FTDM_CID_TYPE_SDMF;
|
||||
memcpy(&state->buf[state->bpos], date, dlen);
|
||||
state->bpos += dlen;
|
||||
memcpy(&state->buf[state->bpos], number, nlen);
|
||||
state->bpos += nlen;
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_mdmf(ftdm_fsk_data_state_t *state, ftdm_mdmf_type_t type, const uint8_t *data, uint32_t datalen)
|
||||
{
|
||||
state->buf[0] = ZAP_CID_TYPE_MDMF;
|
||||
state->buf[0] = FTDM_CID_TYPE_MDMF;
|
||||
state->buf[state->bpos++] = type;
|
||||
state->buf[state->bpos++] = (uint8_t)datalen;
|
||||
memcpy(&state->buf[state->bpos], data, datalen);
|
||||
state->bpos += datalen;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_checksum(ftdm_fsk_data_state_t *state)
|
||||
{
|
||||
uint32_t i;
|
||||
uint8_t check = 0;
|
||||
@ -89,20 +89,20 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state)
|
||||
state->dlen = state->bpos;
|
||||
state->blen = state->buf[1];
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_parse(ftdm_fsk_data_state_t *state, ftdm_size_t *type, char **data, ftdm_size_t *len)
|
||||
{
|
||||
|
||||
zap_size_t i;
|
||||
ftdm_size_t i;
|
||||
int sum = 0;
|
||||
|
||||
top:
|
||||
|
||||
if (state->checksum != 0 || state->ppos >= state->dlen - 1) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
if (!state->ppos) {
|
||||
@ -112,13 +112,13 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_siz
|
||||
state->checksum = sum % 256;
|
||||
state->ppos = 2;
|
||||
|
||||
if (state->buf[0] != ZAP_CID_TYPE_MDMF && state->buf[0] != ZAP_CID_TYPE_SDMF) {
|
||||
if (state->buf[0] != FTDM_CID_TYPE_MDMF && state->buf[0] != FTDM_CID_TYPE_SDMF) {
|
||||
state->checksum = -1;
|
||||
}
|
||||
goto top;
|
||||
}
|
||||
|
||||
if (state->buf[0] == ZAP_CID_TYPE_SDMF) {
|
||||
if (state->buf[0] == FTDM_CID_TYPE_SDMF) {
|
||||
/* convert sdmf to mdmf so we don't need 2 parsers */
|
||||
if (state->ppos == 2) {
|
||||
*type = MDMF_DATETIME;
|
||||
@ -134,46 +134,46 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_siz
|
||||
}
|
||||
*data = (char *)&state->buf[state->ppos];
|
||||
state->ppos += *len;
|
||||
return ZAP_SUCCESS;
|
||||
} else if (state->buf[0] == ZAP_CID_TYPE_MDMF) {
|
||||
return FTDM_SUCCESS;
|
||||
} else if (state->buf[0] == FTDM_CID_TYPE_MDMF) {
|
||||
*type = state->buf[state->ppos++];
|
||||
*len = state->buf[state->ppos++];
|
||||
*data = (char *)&state->buf[state->ppos];
|
||||
state->ppos += *len;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, zap_size_t samples)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_feed(ftdm_fsk_data_state_t *state, int16_t *data, ftdm_size_t samples)
|
||||
{
|
||||
uint32_t x;
|
||||
int16_t *sp = data;
|
||||
|
||||
if (state->init == 3) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
for (x = 0; x < samples; x++) {
|
||||
dsp_fsk_sample (state->fsk1200_handle, (double) *sp++ / 32767.0);
|
||||
if (state->dlen && state->bpos >= state->dlen) {
|
||||
state->init = 3;
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_demod_destroy(zap_fsk_data_state_t *state)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_destroy(ftdm_fsk_data_state_t *state)
|
||||
{
|
||||
dsp_fsk_destroy(&state->fsk1200_handle);
|
||||
memset(state, 0, sizeof(*state));
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_size_t bufsize)
|
||||
FT_DECLARE(int) ftdm_fsk_demod_init(ftdm_fsk_data_state_t *state, int rate, uint8_t *buf, ftdm_size_t bufsize)
|
||||
{
|
||||
|
||||
dsp_fsk_attr_t fsk1200_attr;
|
||||
@ -193,20 +193,20 @@ OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_
|
||||
state->fsk1200_handle = dsp_fsk_create (&fsk1200_attr);
|
||||
|
||||
if (state->fsk1200_handle == NULL) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen)
|
||||
FT_DECLARE(ftdm_size_t) ftdm_fsk_modulator_generate_bit(ftdm_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, ftdm_size_t buflen)
|
||||
{
|
||||
zap_size_t i;
|
||||
ftdm_size_t i;
|
||||
|
||||
for(i = 0 ; i < buflen; i++) {
|
||||
fsk_trans->bit_accum += fsk_trans->bit_factor;
|
||||
if (fsk_trans->bit_accum >= ZAP_FSK_MOD_FACTOR) {
|
||||
fsk_trans->bit_accum -= (ZAP_FSK_MOD_FACTOR + fsk_trans->bit_factor);
|
||||
if (fsk_trans->bit_accum >= FTDM_FSK_MOD_FACTOR) {
|
||||
fsk_trans->bit_accum -= (FTDM_FSK_MOD_FACTOR + fsk_trans->bit_factor);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -217,15 +217,15 @@ OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_t
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits)
|
||||
FT_DECLARE(int32_t) ftdm_fsk_modulator_generate_carrier_bits(ftdm_fsk_modulator_t *fsk_trans, uint32_t bits)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
zap_size_t r = 0;
|
||||
ftdm_size_t r = 0;
|
||||
int8_t bit = 1;
|
||||
|
||||
for (i = 0; i < bits; i++) {
|
||||
if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
|
||||
if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) {
|
||||
if ((r = ftdm_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
|
||||
if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != FTDM_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -237,15 +237,15 @@ OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans)
|
||||
FT_DECLARE(void) ftdm_fsk_modulator_generate_chan_sieze(ftdm_fsk_modulator_t *fsk_trans)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
zap_size_t r = 0;
|
||||
ftdm_size_t r = 0;
|
||||
int8_t bit = 0;
|
||||
|
||||
for (i = 0; i < fsk_trans->chan_sieze_bits; i++) {
|
||||
if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
|
||||
if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) {
|
||||
if ((r = ftdm_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
|
||||
if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != FTDM_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -258,14 +258,14 @@ OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans)
|
||||
FT_DECLARE(void) ftdm_fsk_modulator_send_data(ftdm_fsk_modulator_t *fsk_trans)
|
||||
{
|
||||
zap_size_t r = 0;
|
||||
ftdm_size_t r = 0;
|
||||
int8_t bit = 0;
|
||||
|
||||
while((bit = zap_bitstream_get_bit(&fsk_trans->bs)) > -1) {
|
||||
if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
|
||||
if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) {
|
||||
while((bit = ftdm_bitstream_get_bit(&fsk_trans->bs)) > -1) {
|
||||
if ((r = ftdm_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
|
||||
if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != FTDM_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -275,33 +275,33 @@ OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans)
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans,
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_modulator_init(ftdm_fsk_modulator_t *fsk_trans,
|
||||
fsk_modem_types_t modem_type,
|
||||
uint32_t sample_rate,
|
||||
zap_fsk_data_state_t *fsk_data,
|
||||
ftdm_fsk_data_state_t *fsk_data,
|
||||
float db_level,
|
||||
uint32_t carrier_bits_start,
|
||||
uint32_t carrier_bits_stop,
|
||||
uint32_t chan_sieze_bits,
|
||||
zap_fsk_write_sample_t write_sample_callback,
|
||||
ftdm_fsk_write_sample_t write_sample_callback,
|
||||
void *user_data)
|
||||
{
|
||||
memset(fsk_trans, 0, sizeof(*fsk_trans));
|
||||
fsk_trans->modem_type = modem_type;
|
||||
teletone_dds_state_set_tone(&fsk_trans->dds, fsk_modem_definitions[fsk_trans->modem_type].freq_space, sample_rate, 0);
|
||||
teletone_dds_state_set_tone(&fsk_trans->dds, fsk_modem_definitions[fsk_trans->modem_type].freq_mark, sample_rate, 1);
|
||||
fsk_trans->bit_factor = (uint32_t)((fsk_modem_definitions[fsk_trans->modem_type].baud_rate * ZAP_FSK_MOD_FACTOR) / (float)sample_rate);
|
||||
fsk_trans->bit_factor = (uint32_t)((fsk_modem_definitions[fsk_trans->modem_type].baud_rate * FTDM_FSK_MOD_FACTOR) / (float)sample_rate);
|
||||
fsk_trans->samples_per_bit = (uint32_t) (sample_rate / fsk_modem_definitions[fsk_trans->modem_type].baud_rate);
|
||||
fsk_trans->est_bytes = (int32_t)(((fsk_data->dlen * 10) + carrier_bits_start + carrier_bits_stop + chan_sieze_bits) * ((fsk_trans->samples_per_bit + 1) * 2));
|
||||
fsk_trans->bit_accum = 0;
|
||||
fsk_trans->fsk_data = fsk_data;
|
||||
teletone_dds_state_set_tx_level(&fsk_trans->dds, db_level);
|
||||
zap_bitstream_init(&fsk_trans->bs, fsk_trans->fsk_data->buf, (uint32_t)fsk_trans->fsk_data->dlen, ZAP_ENDIAN_BIG, 1);
|
||||
ftdm_bitstream_init(&fsk_trans->bs, fsk_trans->fsk_data->buf, (uint32_t)fsk_trans->fsk_data->dlen, FTDM_ENDIAN_BIG, 1);
|
||||
fsk_trans->carrier_bits_start = carrier_bits_start;
|
||||
fsk_trans->carrier_bits_stop = carrier_bits_stop;
|
||||
fsk_trans->chan_sieze_bits = chan_sieze_bits;
|
||||
fsk_trans->write_sample_callback = write_sample_callback;
|
||||
fsk_trans->user_data = user_data;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
@ -31,10 +31,10 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "zap_config.h"
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_config.h"
|
||||
|
||||
int zap_config_open_file(zap_config_t *cfg, const char *file_path)
|
||||
int ftdm_config_open_file(ftdm_config_t *cfg, const char *file_path)
|
||||
{
|
||||
FILE *f;
|
||||
const char *path = NULL;
|
||||
@ -43,7 +43,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path)
|
||||
if (file_path[0] == '/') {
|
||||
path = file_path;
|
||||
} else {
|
||||
snprintf(path_buf, sizeof(path_buf), "%s%s%s", ZAP_CONFIG_DIR, ZAP_PATH_SEPARATOR, file_path);
|
||||
snprintf(path_buf, sizeof(path_buf), "%s%s%s", FTDM_CONFIG_DIR, FTDM_PATH_SEPARATOR, file_path);
|
||||
path = path_buf;
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path)
|
||||
|
||||
memset(cfg, 0, sizeof(*cfg));
|
||||
cfg->lockto = -1;
|
||||
zap_log(ZAP_LOG_DEBUG, "Configuration file is %s.\n", path);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Configuration file is %s.\n", path);
|
||||
f = fopen(path, "r");
|
||||
|
||||
if (!f) {
|
||||
@ -61,7 +61,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path)
|
||||
int last = -1;
|
||||
char *var, *val;
|
||||
|
||||
snprintf(path_buf, sizeof(path_buf), "%s%sopenzap.conf", ZAP_CONFIG_DIR, ZAP_PATH_SEPARATOR);
|
||||
snprintf(path_buf, sizeof(path_buf), "%s%sfreetdm.conf", FTDM_CONFIG_DIR, FTDM_PATH_SEPARATOR);
|
||||
path = path_buf;
|
||||
|
||||
if ((f = fopen(path, "r")) == 0) {
|
||||
@ -69,16 +69,16 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path)
|
||||
}
|
||||
|
||||
cfg->file = f;
|
||||
zap_set_string(cfg->path, path);
|
||||
ftdm_set_string(cfg->path, path);
|
||||
|
||||
while (zap_config_next_pair(cfg, &var, &val)) {
|
||||
while (ftdm_config_next_pair(cfg, &var, &val)) {
|
||||
if ((cfg->sectno != last) && !strcmp(cfg->section, file_path)) {
|
||||
cfg->lockto = cfg->sectno;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
zap_config_close_file(cfg);
|
||||
ftdm_config_close_file(cfg);
|
||||
memset(cfg, 0, sizeof(*cfg));
|
||||
return 0;
|
||||
}
|
||||
@ -86,12 +86,12 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path)
|
||||
return 0;
|
||||
} else {
|
||||
cfg->file = f;
|
||||
zap_set_string(cfg->path, path);
|
||||
ftdm_set_string(cfg->path, path);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void zap_config_close_file(zap_config_t *cfg)
|
||||
void ftdm_config_close_file(ftdm_config_t *cfg)
|
||||
{
|
||||
|
||||
if (cfg->file) {
|
||||
@ -103,7 +103,7 @@ void zap_config_close_file(zap_config_t *cfg)
|
||||
|
||||
|
||||
|
||||
int zap_config_next_pair(zap_config_t *cfg, char **var, char **val)
|
||||
int ftdm_config_next_pair(ftdm_config_t *cfg, char **var, char **val)
|
||||
{
|
||||
int ret = 0;
|
||||
char *p, *end;
|
||||
@ -128,7 +128,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val)
|
||||
(*var)++;
|
||||
if (**var == '+') {
|
||||
(*var)++;
|
||||
zap_copy_string(cfg->section, *var, sizeof(cfg->section));
|
||||
ftdm_copy_string(cfg->section, *var, sizeof(cfg->section));
|
||||
cfg->sectno++;
|
||||
|
||||
if (cfg->lockto > -1 && cfg->sectno != cfg->lockto) {
|
||||
@ -140,7 +140,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val)
|
||||
*val = (char *) "";
|
||||
return 1;
|
||||
} else {
|
||||
zap_copy_string(cfg->category, *var, sizeof(cfg->category));
|
||||
ftdm_copy_string(cfg->category, *var, sizeof(cfg->category));
|
||||
cfg->catno++;
|
||||
}
|
||||
continue;
|
||||
@ -209,29 +209,29 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val)
|
||||
|
||||
}
|
||||
|
||||
OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits)
|
||||
FT_DECLARE (int) ftdm_config_get_cas_bits(char *strvalue, unsigned char *outbits)
|
||||
{
|
||||
char cas_bits[5];
|
||||
unsigned char bit = 0x8;
|
||||
int x = 0;
|
||||
char *double_colon = strchr(strvalue, ':');
|
||||
if (!double_colon) {
|
||||
zap_log(ZAP_LOG_ERROR, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", strvalue);
|
||||
ftdm_log(FTDM_LOG_ERROR, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", strvalue);
|
||||
return -1;
|
||||
}
|
||||
double_colon++;
|
||||
*outbits = 0;
|
||||
cas_bits[4] = 0;
|
||||
if (sscanf(double_colon, "%c%c%c%c", &cas_bits[0], &cas_bits[1], &cas_bits[2], &cas_bits[3]) != 4) {
|
||||
zap_log(ZAP_LOG_ERROR, "Invalid CAS bits specified: '%s', :xxxx definition expected, where x is 1 or 0\n", double_colon);
|
||||
ftdm_log(FTDM_LOG_ERROR, "Invalid CAS bits specified: '%s', :xxxx definition expected, where x is 1 or 0\n", double_colon);
|
||||
return -1;
|
||||
}
|
||||
zap_log(ZAP_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits);
|
||||
for (; cas_bits[x]; x++) {
|
||||
if ('1' == cas_bits[x]) {
|
||||
*outbits |= bit;
|
||||
} else if ('0' != cas_bits[x]) {
|
||||
zap_log(ZAP_LOG_ERROR, "Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n");
|
||||
ftdm_log(FTDM_LOG_ERROR, "Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n");
|
||||
return -1;
|
||||
}
|
||||
bit >>= 1;
|
@ -17,8 +17,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "zap_dso.h"
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_dso.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -27,14 +27,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib) {
|
||||
FT_DECLARE(void) ftdm_dso_destroy(ftdm_dso_lib_t *lib) {
|
||||
if (lib && *lib) {
|
||||
FreeLibrary(*lib);
|
||||
*lib = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) {
|
||||
FT_DECLARE(ftdm_dso_lib_t) ftdm_dso_open(const char *path, char **err) {
|
||||
HINSTANCE lib;
|
||||
|
||||
lib = LoadLibraryEx(path, NULL, 0);
|
||||
@ -47,21 +47,21 @@ OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) {
|
||||
DWORD error = GetLastError();
|
||||
char tmp[80];
|
||||
sprintf(tmp, "dll open error [%ul]\n", error);
|
||||
*err = zap_strdup(tmp);
|
||||
*err = ftdm_strdup(tmp);
|
||||
}
|
||||
|
||||
return lib;
|
||||
}
|
||||
|
||||
OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) {
|
||||
FT_DECLARE(void*) ftdm_dso_func_sym(ftdm_dso_lib_t lib, const char *sym, char **err) {
|
||||
FARPROC func = GetProcAddress(lib, sym);
|
||||
if (!func) {
|
||||
DWORD error = GetLastError();
|
||||
char tmp[80];
|
||||
sprintf(tmp, "dll sym error [%ul]\n", error);
|
||||
*err = zap_strdup(tmp);
|
||||
*err = ftdm_strdup(tmp);
|
||||
}
|
||||
return (void *)(intptr_t)func; // this should really be addr - zap_dso_func_data
|
||||
return (void *)(intptr_t)func; // this should really be addr - ftdm_dso_func_data
|
||||
}
|
||||
|
||||
#else
|
||||
@ -78,25 +78,25 @@ OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **er
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib) {
|
||||
FT_DECLARE(void) ftdm_dso_destroy(ftdm_dso_lib_t *lib) {
|
||||
if (lib && *lib) {
|
||||
dlclose(*lib);
|
||||
*lib = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) {
|
||||
FT_DECLARE(ftdm_dso_lib_t) ftdm_dso_open(const char *path, char **err) {
|
||||
void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
|
||||
if (lib == NULL) {
|
||||
*err = zap_strdup(dlerror());
|
||||
*err = ftdm_strdup(dlerror());
|
||||
}
|
||||
return lib;
|
||||
}
|
||||
|
||||
OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) {
|
||||
FT_DECLARE(void*) ftdm_dso_func_sym(ftdm_dso_lib_t lib, const char *sym, char **err) {
|
||||
void *func = dlsym(lib, sym);
|
||||
if (!func) {
|
||||
*err = zap_strdup(dlerror());
|
||||
*err = ftdm_strdup(dlerror());
|
||||
}
|
||||
return func;
|
||||
}
|
3754
libs/freetdm/src/ftdm_io.c
Normal file
3754
libs/freetdm/src/ftdm_io.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* zap_m3ua.c
|
||||
* openzap
|
||||
* ftdm_m3ua.c
|
||||
* freetdm
|
||||
*
|
||||
* Created by Shane Burrell on 4/3/08.
|
||||
* Copyright 2008 Shane Burrell. All rights reserved.
|
||||
@ -38,9 +38,9 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include "m3ua_client.h"
|
||||
#include "zap_m3ua.h"
|
||||
#include "ftdm_m3ua.h"
|
||||
|
||||
#define MAX_REQ_ID MAX_PENDING_CALLS
|
||||
typedef uint16_t m3ua_request_id_t;
|
||||
@ -55,8 +55,8 @@ typedef enum {
|
||||
typedef struct {
|
||||
m3ua_request_status_t status;
|
||||
m3uac_event_t event;
|
||||
zap_span_t *span;
|
||||
zap_channel_t *zchan;
|
||||
ftdm_span_t *span;
|
||||
ftdm_channel_t *ftdmchan;
|
||||
} m3ua_request_t;
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ struct m3ua_channel_profile {
|
||||
typedef struct m3ua_channel_profile m3ua_channel_profile_t;
|
||||
|
||||
static struct {
|
||||
zap_hash_t *profile_hash;
|
||||
ftdm_hash_t *profile_hash;
|
||||
general_config_t general_config;
|
||||
} globals;
|
||||
|
||||
@ -91,24 +91,24 @@ struct m3ua_span_data {
|
||||
typedef struct m3ua_span_data m3ua_span_data_t;
|
||||
|
||||
struct m3ua_chan_data {
|
||||
zap_buffer_t *digit_buffer;
|
||||
zap_mutex_t *digit_mutex;
|
||||
zap_size_t dtmf_len;
|
||||
ftdm_buffer_t *digit_buffer;
|
||||
ftdm_mutex_t *digit_mutex;
|
||||
ftdm_size_t dtmf_len;
|
||||
uint32_t flags;
|
||||
uint32_t hdlc_bytes;
|
||||
};
|
||||
typedef struct m3ua_chan_data m3ua_chan_data_t;
|
||||
|
||||
static zap_mutex_t *request_mutex = NULL;
|
||||
static zap_mutex_t *signal_mutex = NULL;
|
||||
static ftdm_mutex_t *request_mutex = NULL;
|
||||
static ftdm_mutex_t *signal_mutex = NULL;
|
||||
|
||||
static uint8_t req_map[MAX_REQ_ID+1] = { 0 };
|
||||
|
||||
static void release_request_id(m3ua_request_id_t r)
|
||||
{
|
||||
zap_mutex_lock(request_mutex);
|
||||
ftdm_mutex_lock(request_mutex);
|
||||
req_map[r] = 0;
|
||||
zap_mutex_unlock(request_mutex);
|
||||
ftdm_mutex_unlock(request_mutex);
|
||||
}
|
||||
|
||||
/*static m3ua_request_id_t next_request_id(void)
|
||||
@ -117,7 +117,7 @@ static void release_request_id(m3ua_request_id_t r)
|
||||
int ok = 0;
|
||||
|
||||
while(!ok) {
|
||||
zap_mutex_lock(request_mutex);
|
||||
ftdm_mutex_lock(request_mutex);
|
||||
for (r = 1; r <= MAX_REQ_ID; r++) {
|
||||
if (!req_map[r]) {
|
||||
ok = 1;
|
||||
@ -125,153 +125,153 @@ static void release_request_id(m3ua_request_id_t r)
|
||||
break;
|
||||
}
|
||||
}
|
||||
zap_mutex_unlock(request_mutex);
|
||||
ftdm_mutex_unlock(request_mutex);
|
||||
if (!ok) {
|
||||
zap_sleep(5);
|
||||
ftdm_sleep(5);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
*/
|
||||
|
||||
static __inline__ void state_advance(zap_channel_t *zchan)
|
||||
static __inline__ void state_advance(ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
|
||||
m3ua_data_t *m3ua_data = zchan->span->signal_data;
|
||||
m3ua_data_t *m3ua_data = ftdmchan->span->signal_data;
|
||||
m3uac_connection_t *mcon = &m3ua_data->mcon;
|
||||
zap_sigmsg_t sig;
|
||||
zap_status_t status;
|
||||
ftdm_sigmsg_t sig;
|
||||
ftdm_status_t status;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n", zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state));
|
||||
ftdm_log(FTDM_LOG_DEBUG, "%d:%d STATE [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state));
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = zchan->chan_id;
|
||||
sig.span_id = zchan->span_id;
|
||||
sig.channel = zchan;
|
||||
sig.chan_id = ftdmchan->chan_id;
|
||||
sig.span_id = ftdmchan->span_id;
|
||||
sig.channel = ftdmchan;
|
||||
|
||||
switch (zchan->state) {
|
||||
case ZAP_CHANNEL_STATE_DOWN:
|
||||
switch (ftdmchan->state) {
|
||||
case FTDM_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
if (zchan->extra_id) {
|
||||
release_request_id((m3ua_request_id_t)zchan->extra_id);
|
||||
zchan->extra_id = 0;
|
||||
if (ftdmchan->extra_id) {
|
||||
release_request_id((m3ua_request_id_t)ftdmchan->extra_id);
|
||||
ftdmchan->extra_id = 0;
|
||||
}
|
||||
zap_channel_done(zchan);
|
||||
ftdm_channel_done(ftdmchan);
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_PROGRESS_MEDIA:
|
||||
case ZAP_CHANNEL_STATE_PROGRESS:
|
||||
case FTDM_CHANNEL_STATE_PROGRESS_MEDIA:
|
||||
case FTDM_CHANNEL_STATE_PROGRESS:
|
||||
{
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA;
|
||||
if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA;
|
||||
if ((status = m3ua_data->signal_cb(&sig) != FTDM_SUCCESS)) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
|
||||
}
|
||||
} else {
|
||||
m3uac_exec_command(mcon,
|
||||
zchan->physical_span_id-1,
|
||||
zchan->physical_chan_id-1,
|
||||
ftdmchan->physical_span_id-1,
|
||||
ftdmchan->physical_chan_id-1,
|
||||
0,
|
||||
SIGBOOST_EVENT_CALL_START_ACK,
|
||||
0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_RING:
|
||||
case FTDM_CHANNEL_STATE_RING:
|
||||
{
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
sig.event_id = ZAP_SIGEVENT_START;
|
||||
if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
sig.event_id = FTDM_SIGEVENT_START;
|
||||
if ((status = m3ua_data->signal_cb(&sig) != FTDM_SUCCESS)) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_RESTART:
|
||||
case FTDM_CHANNEL_STATE_RESTART:
|
||||
{
|
||||
if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||
if (ftdmchan->last_state != FTDM_CHANNEL_STATE_HANGUP && ftdmchan->last_state != FTDM_CHANNEL_STATE_DOWN) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_UP:
|
||||
case FTDM_CHANNEL_STATE_UP:
|
||||
{
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
sig.event_id = ZAP_SIGEVENT_UP;
|
||||
if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
sig.event_id = FTDM_SIGEVENT_UP;
|
||||
if ((status = m3ua_data->signal_cb(&sig) != FTDM_SUCCESS)) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
|
||||
}
|
||||
} else {
|
||||
if (!(zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA))) {
|
||||
if (!(ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA))) {
|
||||
m3uac_exec_command(mcon,
|
||||
zchan->physical_span_id-1,
|
||||
zchan->physical_chan_id-1,
|
||||
ftdmchan->physical_span_id-1,
|
||||
ftdmchan->physical_chan_id-1,
|
||||
0,
|
||||
SIGBOOST_EVENT_CALL_START_ACK,
|
||||
0);
|
||||
}
|
||||
|
||||
m3uac_exec_command(mcon,
|
||||
zchan->physical_span_id-1,
|
||||
zchan->physical_chan_id-1,
|
||||
ftdmchan->physical_span_id-1,
|
||||
ftdmchan->physical_chan_id-1,
|
||||
0,
|
||||
SIGBOOST_EVENT_CALL_ANSWERED,
|
||||
0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALING:
|
||||
case FTDM_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_HANGUP_COMPLETE:
|
||||
case FTDM_CHANNEL_STATE_HANGUP_COMPLETE:
|
||||
{
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_HANGUP:
|
||||
case FTDM_CHANNEL_STATE_HANGUP:
|
||||
{
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) {
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_ANSWERED) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA)) {
|
||||
m3uac_exec_command(mcon,
|
||||
zchan->physical_span_id-1,
|
||||
zchan->physical_chan_id-1,
|
||||
ftdmchan->physical_span_id-1,
|
||||
ftdmchan->physical_chan_id-1,
|
||||
0,
|
||||
SIGBOOST_EVENT_CALL_STOPPED,
|
||||
zchan->caller_data.hangup_cause);
|
||||
ftdmchan->caller_data.hangup_cause);
|
||||
} else {
|
||||
m3uac_exec_command(mcon,
|
||||
zchan->physical_span_id-1,
|
||||
zchan->physical_chan_id-1,
|
||||
ftdmchan->physical_span_id-1,
|
||||
ftdmchan->physical_chan_id-1,
|
||||
0,
|
||||
SIGBOOST_EVENT_CALL_START_NACK,
|
||||
zchan->caller_data.hangup_cause);
|
||||
ftdmchan->caller_data.hangup_cause);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_CANCEL:
|
||||
case FTDM_CHANNEL_STATE_CANCEL:
|
||||
{
|
||||
sig.event_id = ZAP_SIGEVENT_STOP;
|
||||
sig.event_id = FTDM_SIGEVENT_STOP;
|
||||
status = m3ua_data->signal_cb(&sig);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
m3uac_exec_command(mcon,
|
||||
zchan->physical_span_id-1,
|
||||
zchan->physical_chan_id-1,
|
||||
ftdmchan->physical_span_id-1,
|
||||
ftdmchan->physical_chan_id-1,
|
||||
0,
|
||||
SIGBOOST_EVENT_CALL_START_NACK_ACK,
|
||||
0);
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_TERMINATING:
|
||||
case FTDM_CHANNEL_STATE_TERMINATING:
|
||||
{
|
||||
sig.event_id = ZAP_SIGEVENT_STOP;
|
||||
sig.event_id = FTDM_SIGEVENT_STOP;
|
||||
status = m3ua_data->signal_cb(&sig);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
m3uac_exec_command(mcon,
|
||||
zchan->physical_span_id-1,
|
||||
zchan->physical_chan_id-1,
|
||||
ftdmchan->physical_span_id-1,
|
||||
ftdmchan->physical_chan_id-1,
|
||||
0,
|
||||
SIGBOOST_EVENT_CALL_STOPPED_ACK,
|
||||
0);
|
||||
@ -283,36 +283,36 @@ static __inline__ void state_advance(zap_channel_t *zchan)
|
||||
}
|
||||
|
||||
|
||||
static __inline__ void check_state(zap_span_t *span)
|
||||
static __inline__ void check_state(ftdm_span_t *span)
|
||||
{
|
||||
if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) {
|
||||
if (ftdm_test_flag(span, FTDM_SPAN_STATE_CHANGE)) {
|
||||
uint32_t j;
|
||||
zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE);
|
||||
ftdm_clear_flag_locked(span, FTDM_SPAN_STATE_CHANGE);
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) {
|
||||
zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE);
|
||||
if (ftdm_test_flag((&span->channels[j]), FTDM_CHANNEL_STATE_CHANGE)) {
|
||||
ftdm_clear_flag_locked((&span->channels[j]), FTDM_CHANNEL_STATE_CHANGE);
|
||||
state_advance(&span->channels[j]);
|
||||
zap_channel_complete_state(&span->channels[j]);
|
||||
ftdm_channel_complete_state(&span->channels[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_event_t *event)
|
||||
static int parse_ss7_event(ftdm_span_t *span, m3uac_connection_t *mcon, m3uac_event_t *event)
|
||||
{
|
||||
zap_mutex_lock(signal_mutex);
|
||||
ftdm_mutex_lock(signal_mutex);
|
||||
|
||||
if (!zap_running()) {
|
||||
zap_log(ZAP_LOG_WARNING, "System is shutting down.\n");
|
||||
if (!ftdm_running()) {
|
||||
ftdm_log(FTDM_LOG_WARNING, "System is shutting down.\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) &&
|
||||
if (ftdm_test_flag(span, FTDM_SPAN_SUSPENDED) &&
|
||||
event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) {
|
||||
|
||||
zap_log(ZAP_LOG_WARNING,
|
||||
ftdm_log(FTDM_LOG_WARNING,
|
||||
"INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n",
|
||||
m3uac_event_id_name(event->event_id),
|
||||
event->event_id,
|
||||
@ -329,7 +329,7 @@ static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_eve
|
||||
}
|
||||
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG,
|
||||
ftdm_log(FTDM_LOG_DEBUG,
|
||||
"RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n",
|
||||
m3uac_event_id_name(event->event_id),
|
||||
event->event_id,
|
||||
@ -381,13 +381,13 @@ static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_eve
|
||||
//handle_gap_abate(event);
|
||||
break;
|
||||
default:
|
||||
zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", m3uac_event_id_name(event->event_id));
|
||||
ftdm_log(FTDM_LOG_WARNING, "No handler implemented for [%s]\n", m3uac_event_id_name(event->event_id));
|
||||
break;
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
zap_mutex_unlock(signal_mutex);
|
||||
ftdm_mutex_unlock(signal_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -399,14 +399,14 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure)
|
||||
int ok = 1;
|
||||
|
||||
if (!(profile = (m3ua_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) {
|
||||
profile = zap_malloc(sizeof(*profile));
|
||||
profile = ftdm_malloc(sizeof(*profile));
|
||||
memset(profile, 0, sizeof(*profile));
|
||||
zap_set_string(profile->name, category);
|
||||
ftdm_set_string(profile->name, category);
|
||||
hashtable_insert(globals.profile_hash, (void *)profile->name, profile);
|
||||
zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category);
|
||||
ftdm_log(FTDM_LOG_INFO, "creating profile [%s]\n", category);
|
||||
}
|
||||
|
||||
// zap_set_string(m3ua_data->mcon. cfg.local_ip, local_ip);
|
||||
// ftdm_set_string(m3ua_data->mcon. cfg.local_ip, local_ip);
|
||||
if (!strcasecmp(var, "local_sctp_port")) {
|
||||
profile->local_port = 30000 ;
|
||||
profile->remote_port = 30000;
|
||||
@ -416,30 +416,30 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure)
|
||||
|
||||
|
||||
if (ok) {
|
||||
zap_log(ZAP_LOG_INFO, "setting param [%s]=[%s] for profile [%s]\n", var, val, category);
|
||||
ftdm_log(FTDM_LOG_INFO, "setting param [%s]=[%s] for profile [%s]\n", var, val, category);
|
||||
} else {
|
||||
zap_log(ZAP_LOG_ERROR, "unknown param [%s]\n", var);
|
||||
ftdm_log(FTDM_LOG_ERROR, "unknown param [%s]\n", var);
|
||||
}
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
static ZIO_CONFIGURE_SPAN_FUNCTION(m3ua_configure_span)
|
||||
{
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_OPEN_FUNCTION(m3ua_open)
|
||||
{
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_CLOSE_FUNCTION(m3ua_close)
|
||||
{
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
/*static ZIO_SET_INTERVAL_FUNCTION(m3ua_set_interval)
|
||||
@ -451,34 +451,34 @@ static ZIO_CLOSE_FUNCTION(m3ua_close)
|
||||
static ZIO_WAIT_FUNCTION(m3ua_wait)
|
||||
{
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_READ_FUNCTION(m3ua_read)
|
||||
{
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_WRITE_FUNCTION(m3ua_write)
|
||||
{
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_COMMAND_FUNCTION(m3ua_command)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_SPAN_POLL_EVENT_FUNCTION(m3ua_poll_event)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_SPAN_NEXT_EVENT_FUNCTION(m3ua_next_event)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@ -487,18 +487,18 @@ static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy)
|
||||
m3ua_span_data_t *span_data = (m3ua_span_data_t *) span->mod_data;
|
||||
|
||||
if (span_data) {
|
||||
zap_safe_free(span_data);
|
||||
ftdm_safe_free(span_data);
|
||||
}
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy)
|
||||
{
|
||||
m3ua_chan_data_t *chan_data = (m3ua_chan_data_t *) zchan->mod_data;
|
||||
m3ua_span_data_t *span_data = (m3ua_span_data_t *) zchan->span->mod_data;
|
||||
m3ua_chan_data_t *chan_data = (m3ua_chan_data_t *) ftdmchan->mod_data;
|
||||
m3ua_span_data_t *span_data = (m3ua_span_data_t *) ftdmchan->span->mod_data;
|
||||
|
||||
if (!chan_data) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@ -506,30 +506,30 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy)
|
||||
|
||||
|
||||
|
||||
zap_mutex_destroy(&chan_data->digit_mutex);
|
||||
zap_buffer_destroy(&chan_data->digit_buffer);
|
||||
ftdm_mutex_destroy(&chan_data->digit_mutex);
|
||||
ftdm_buffer_destroy(&chan_data->digit_buffer);
|
||||
|
||||
|
||||
zap_safe_free(chan_data);
|
||||
ftdm_safe_free(chan_data);
|
||||
|
||||
if (span_data) {
|
||||
zap_safe_free(span_data);
|
||||
ftdm_safe_free(span_data);
|
||||
}
|
||||
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ZIO_GET_ALARMS_FUNCTION(m3ua_get_alarms)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static zap_io_interface_t m3ua_interface;
|
||||
static ftdm_io_interface_t m3ua_interface;
|
||||
|
||||
zap_status_t m3ua_init(zap_io_interface_t **zint)
|
||||
ftdm_status_t m3ua_init(ftdm_io_interface_t **zint)
|
||||
{
|
||||
assert(zint != NULL);
|
||||
memset(&m3ua_interface, 0, sizeof(m3ua_interface));
|
||||
@ -550,18 +550,18 @@ zap_status_t m3ua_init(zap_io_interface_t **zint)
|
||||
m3ua_interface.get_alarms = m3ua_get_alarms;
|
||||
*zint = &m3ua_interface;
|
||||
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
zap_status_t m3ua_destroy(void)
|
||||
ftdm_status_t m3ua_destroy(void)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
|
||||
static void *m3ua_run(zap_thread_t *me, void *obj)
|
||||
static void *m3ua_run(ftdm_thread_t *me, void *obj)
|
||||
{
|
||||
zap_span_t *span = (zap_span_t *) obj;
|
||||
ftdm_span_t *span = (ftdm_span_t *) obj;
|
||||
m3ua_data_t *m3ua_data = span->signal_data;
|
||||
m3uac_connection_t *mcon, *pcon;
|
||||
uint32_t ms = 10, too_long = 60000;
|
||||
@ -574,7 +574,7 @@ static void *m3ua_run(zap_thread_t *me, void *obj)
|
||||
m3ua_data->mcon.cfg.local_port,
|
||||
m3ua_data->mcon.cfg.remote_ip,
|
||||
m3ua_data->mcon.cfg.remote_port) < 0) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", m3ua_data->mcon.socket, strerror(errno));
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", m3ua_data->mcon.socket, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
|
||||
@ -583,7 +583,7 @@ static void *m3ua_run(zap_thread_t *me, void *obj)
|
||||
++m3ua_data->pcon.cfg.local_port,
|
||||
m3ua_data->pcon.cfg.remote_ip,
|
||||
m3ua_data->pcon.cfg.remote_port) < 0) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", m3ua_data->pcon.socket, strerror(errno));
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", m3ua_data->pcon.socket, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
|
||||
@ -601,13 +601,13 @@ static void *m3ua_run(zap_thread_t *me, void *obj)
|
||||
SIGBOOST_EVENT_SYSTEM_RESTART,
|
||||
0);
|
||||
|
||||
while (zap_test_flag(m3ua_data, ZAP_M3UA_RUNNING)) {
|
||||
while (ftdm_test_flag(m3ua_data, FTDM_M3UA_RUNNING)) {
|
||||
fd_set rfds, efds;
|
||||
struct timeval tv = { 0, ms * 1000 };
|
||||
int max, activity, i = 0;
|
||||
m3uac_event_t *event = NULL;
|
||||
|
||||
if (!zap_running()) {
|
||||
if (!ftdm_running()) {
|
||||
m3uac_exec_command(mcon,
|
||||
0,
|
||||
0,
|
||||
@ -651,11 +651,11 @@ static void *m3ua_run(zap_thread_t *me, void *obj)
|
||||
check_state(span);
|
||||
mcon->hb_elapsed += ms;
|
||||
|
||||
if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) {
|
||||
zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART);
|
||||
zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED);
|
||||
if (mcon->hb_elapsed >= too_long && (mcon->up || !ftdm_test_flag(span, FTDM_SPAN_SUSPENDED))) {
|
||||
ftdm_set_state_all(span, FTDM_CHANNEL_STATE_RESTART);
|
||||
ftdm_set_flag_locked(span, FTDM_SPAN_SUSPENDED);
|
||||
mcon->up = 0;
|
||||
zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n");
|
||||
ftdm_log(FTDM_LOG_CRIT, "Lost Heartbeat!\n");
|
||||
}
|
||||
|
||||
}
|
||||
@ -663,23 +663,23 @@ static void *m3ua_run(zap_thread_t *me, void *obj)
|
||||
goto end;
|
||||
|
||||
error:
|
||||
zap_log(ZAP_LOG_CRIT, "Socket Error!\n");
|
||||
ftdm_log(FTDM_LOG_CRIT, "Socket Error!\n");
|
||||
|
||||
end:
|
||||
|
||||
m3uac_connection_close(&m3ua_data->mcon);
|
||||
m3uac_connection_close(&m3ua_data->pcon);
|
||||
|
||||
zap_clear_flag(m3ua_data, ZAP_M3UA_RUNNING);
|
||||
ftdm_clear_flag(m3ua_data, FTDM_M3UA_RUNNING);
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "M3UA thread ended.\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "M3UA thread ended.\n");
|
||||
return NULL;
|
||||
}
|
||||
zap_status_t m3ua_start(zap_span_t *span)
|
||||
ftdm_status_t m3ua_start(ftdm_span_t *span)
|
||||
{
|
||||
m3ua_data_t *m3ua_data = span->signal_data;
|
||||
zap_set_flag(m3ua_data, ZAP_M3UA_RUNNING);
|
||||
return zap_thread_create_detached(m3ua_run, span);
|
||||
ftdm_set_flag(m3ua_data, FTDM_M3UA_RUNNING);
|
||||
return ftdm_thread_create_detached(m3ua_run, span);
|
||||
}
|
||||
|
||||
/* For Emacs:
|
@ -32,34 +32,34 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity);
|
||||
static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj);
|
||||
static void *zap_std_queue_dequeue(zap_queue_t *queue);
|
||||
static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms);
|
||||
static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue);
|
||||
static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t capacity);
|
||||
static ftdm_status_t ftdm_std_queue_enqueue(ftdm_queue_t *queue, void *obj);
|
||||
static void *ftdm_std_queue_dequeue(ftdm_queue_t *queue);
|
||||
static ftdm_status_t ftdm_std_queue_wait(ftdm_queue_t *queue, int ms);
|
||||
static ftdm_status_t ftdm_std_queue_destroy(ftdm_queue_t **inqueue);
|
||||
|
||||
struct zap_queue {
|
||||
zap_mutex_t *mutex;
|
||||
zap_condition_t *condition;
|
||||
zap_size_t capacity;
|
||||
zap_size_t size;
|
||||
struct ftdm_queue {
|
||||
ftdm_mutex_t *mutex;
|
||||
ftdm_condition_t *condition;
|
||||
ftdm_size_t capacity;
|
||||
ftdm_size_t size;
|
||||
unsigned rindex;
|
||||
unsigned windex;
|
||||
void **elements;
|
||||
};
|
||||
|
||||
OZ_DECLARE_DATA zap_queue_handler_t g_zap_queue_handler =
|
||||
FT_DECLARE_DATA ftdm_queue_handler_t g_ftdm_queue_handler =
|
||||
{
|
||||
/*.create = */ zap_std_queue_create,
|
||||
/*.enqueue = */ zap_std_queue_enqueue,
|
||||
/*.dequeue = */ zap_std_queue_dequeue,
|
||||
/*.wait = */ zap_std_queue_wait,
|
||||
/*.destroy = */ zap_std_queue_destroy
|
||||
/*.create = */ ftdm_std_queue_create,
|
||||
/*.enqueue = */ ftdm_std_queue_enqueue,
|
||||
/*.dequeue = */ ftdm_std_queue_dequeue,
|
||||
/*.wait = */ ftdm_std_queue_wait,
|
||||
/*.destroy = */ ftdm_std_queue_destroy
|
||||
};
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handler)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_global_set_queue_handler(ftdm_queue_handler_t *handler)
|
||||
{
|
||||
if (!handler ||
|
||||
!handler->create ||
|
||||
@ -67,62 +67,62 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl
|
||||
!handler->dequeue ||
|
||||
!handler->wait ||
|
||||
!handler->destroy) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
memcpy(&g_zap_queue_handler, handler, sizeof(*handler));
|
||||
return ZAP_SUCCESS;
|
||||
memcpy(&g_ftdm_queue_handler, handler, sizeof(*handler));
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity)
|
||||
static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t capacity)
|
||||
{
|
||||
zap_queue_t *queue = NULL;
|
||||
zap_assert_return(outqueue, ZAP_FAIL, "Queue double pointer is null\n");
|
||||
zap_assert_return(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n");
|
||||
ftdm_queue_t *queue = NULL;
|
||||
ftdm_assert_return(outqueue, FTDM_FAIL, "Queue double pointer is null\n");
|
||||
ftdm_assert_return(capacity > 0, FTDM_FAIL, "Queue capacity is not bigger than 0\n");
|
||||
|
||||
*outqueue = NULL;
|
||||
queue = zap_calloc(1, sizeof(*queue));
|
||||
queue = ftdm_calloc(1, sizeof(*queue));
|
||||
if (!queue) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
queue->elements = zap_calloc(1, (sizeof(void*)*capacity));
|
||||
queue->elements = ftdm_calloc(1, (sizeof(void*)*capacity));
|
||||
if (!queue->elements) {
|
||||
goto failed;
|
||||
}
|
||||
queue->capacity = capacity;
|
||||
|
||||
if (zap_mutex_create(&queue->mutex) != ZAP_SUCCESS) {
|
||||
if (ftdm_mutex_create(&queue->mutex) != FTDM_SUCCESS) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (zap_condition_create(&queue->condition, queue->mutex) != ZAP_SUCCESS) {
|
||||
if (ftdm_condition_create(&queue->condition, queue->mutex) != FTDM_SUCCESS) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
*outqueue = queue;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
|
||||
failed:
|
||||
if (queue) {
|
||||
if (queue->condition) {
|
||||
zap_condition_destroy(&queue->condition);
|
||||
ftdm_condition_destroy(&queue->condition);
|
||||
}
|
||||
if (queue->mutex) {
|
||||
zap_mutex_destroy(&queue->mutex);
|
||||
ftdm_mutex_destroy(&queue->mutex);
|
||||
}
|
||||
zap_safe_free(queue->elements);
|
||||
zap_safe_free(queue);
|
||||
ftdm_safe_free(queue->elements);
|
||||
ftdm_safe_free(queue);
|
||||
}
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj)
|
||||
static ftdm_status_t ftdm_std_queue_enqueue(ftdm_queue_t *queue, void *obj)
|
||||
{
|
||||
zap_status_t status = ZAP_FAIL;
|
||||
ftdm_status_t status = FTDM_FAIL;
|
||||
|
||||
zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!");
|
||||
ftdm_assert_return(queue != NULL, FTDM_FAIL, "Queue is null!");
|
||||
|
||||
zap_mutex_lock(queue->mutex);
|
||||
ftdm_mutex_lock(queue->mutex);
|
||||
|
||||
if (queue->windex == queue->capacity) {
|
||||
/* try to see if we can wrap around */
|
||||
@ -130,31 +130,31 @@ static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj)
|
||||
}
|
||||
|
||||
if (queue->size != 0 && queue->windex == queue->rindex) {
|
||||
zap_log(ZAP_LOG_ERROR, "Failed to enqueue obj %p in queue %p, no more room! windex == rindex == %d!\n", obj, queue, queue->windex);
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failed to enqueue obj %p in queue %p, no more room! windex == rindex == %d!\n", obj, queue, queue->windex);
|
||||
goto done;
|
||||
}
|
||||
|
||||
queue->elements[queue->windex++] = obj;
|
||||
queue->size++;
|
||||
status = ZAP_SUCCESS;
|
||||
status = FTDM_SUCCESS;
|
||||
|
||||
/* wake up queue reader */
|
||||
zap_condition_signal(queue->condition);
|
||||
ftdm_condition_signal(queue->condition);
|
||||
|
||||
done:
|
||||
|
||||
zap_mutex_unlock(queue->mutex);
|
||||
ftdm_mutex_unlock(queue->mutex);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static void *zap_std_queue_dequeue(zap_queue_t *queue)
|
||||
static void *ftdm_std_queue_dequeue(ftdm_queue_t *queue)
|
||||
{
|
||||
void *obj = NULL;
|
||||
|
||||
zap_assert_return(queue != NULL, NULL, "Queue is null!");
|
||||
ftdm_assert_return(queue != NULL, NULL, "Queue is null!");
|
||||
|
||||
zap_mutex_lock(queue->mutex);
|
||||
ftdm_mutex_lock(queue->mutex);
|
||||
|
||||
if (queue->size == 0) {
|
||||
goto done;
|
||||
@ -169,46 +169,46 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue)
|
||||
|
||||
done:
|
||||
|
||||
zap_mutex_unlock(queue->mutex);
|
||||
ftdm_mutex_unlock(queue->mutex);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms)
|
||||
static ftdm_status_t ftdm_std_queue_wait(ftdm_queue_t *queue, int ms)
|
||||
{
|
||||
zap_status_t ret;
|
||||
zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!");
|
||||
ftdm_status_t ret;
|
||||
ftdm_assert_return(queue != NULL, FTDM_FAIL, "Queue is null!");
|
||||
|
||||
zap_mutex_lock(queue->mutex);
|
||||
ftdm_mutex_lock(queue->mutex);
|
||||
|
||||
/* if there is elements in the queue, no need to wait */
|
||||
if (queue->size != 0) {
|
||||
zap_mutex_unlock(queue->mutex);
|
||||
return ZAP_SUCCESS;
|
||||
ftdm_mutex_unlock(queue->mutex);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/* no elements on the queue, wait for someone to write an element */
|
||||
ret = zap_condition_wait(queue->condition, ms);
|
||||
ret = ftdm_condition_wait(queue->condition, ms);
|
||||
|
||||
/* got an element or timeout, bail out */
|
||||
zap_mutex_unlock(queue->mutex);
|
||||
ftdm_mutex_unlock(queue->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue)
|
||||
static ftdm_status_t ftdm_std_queue_destroy(ftdm_queue_t **inqueue)
|
||||
{
|
||||
zap_queue_t *queue = NULL;
|
||||
zap_assert_return(inqueue != NULL, ZAP_FAIL, "Queue is null!");
|
||||
zap_assert_return(*inqueue != NULL, ZAP_FAIL, "Queue is null!");
|
||||
ftdm_queue_t *queue = NULL;
|
||||
ftdm_assert_return(inqueue != NULL, FTDM_FAIL, "Queue is null!");
|
||||
ftdm_assert_return(*inqueue != NULL, FTDM_FAIL, "Queue is null!");
|
||||
|
||||
queue = *inqueue;
|
||||
zap_condition_destroy(&queue->condition);
|
||||
zap_mutex_destroy(&queue->mutex);
|
||||
zap_safe_free(queue->elements);
|
||||
zap_safe_free(queue);
|
||||
ftdm_condition_destroy(&queue->condition);
|
||||
ftdm_mutex_destroy(&queue->mutex);
|
||||
ftdm_safe_free(queue->elements);
|
||||
ftdm_safe_free(queue);
|
||||
*inqueue = NULL;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
@ -26,84 +26,84 @@
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#endif
|
||||
|
||||
#include "openzap.h"
|
||||
#include "zap_threadmutex.h"
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_threadmutex.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <process.h>
|
||||
|
||||
#define ZAP_THREAD_CALLING_CONVENTION __stdcall
|
||||
#define FTDM_THREAD_CALLING_CONVENTION __stdcall
|
||||
|
||||
struct zap_mutex {
|
||||
struct ftdm_mutex {
|
||||
CRITICAL_SECTION mutex;
|
||||
};
|
||||
|
||||
#else
|
||||
#include <pthread.h>
|
||||
|
||||
#define ZAP_THREAD_CALLING_CONVENTION
|
||||
#define FTDM_THREAD_CALLING_CONVENTION
|
||||
|
||||
struct zap_mutex {
|
||||
struct ftdm_mutex {
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct zap_condition {
|
||||
struct ftdm_condition {
|
||||
#ifdef WIN32
|
||||
HANDLE condition;
|
||||
#else
|
||||
pthread_cond_t condition;
|
||||
#endif
|
||||
zap_mutex_t *mutex;
|
||||
ftdm_mutex_t *mutex;
|
||||
};
|
||||
|
||||
|
||||
struct zap_thread {
|
||||
struct ftdm_thread {
|
||||
#ifdef WIN32
|
||||
void *handle;
|
||||
#else
|
||||
pthread_t handle;
|
||||
#endif
|
||||
void *private_data;
|
||||
zap_thread_function_t function;
|
||||
zap_size_t stack_size;
|
||||
ftdm_thread_function_t function;
|
||||
ftdm_size_t stack_size;
|
||||
#ifndef WIN32
|
||||
pthread_attr_t attribute;
|
||||
#endif
|
||||
};
|
||||
|
||||
zap_size_t thread_default_stacksize = 0;
|
||||
ftdm_size_t thread_default_stacksize = 0;
|
||||
|
||||
OZ_DECLARE(void) zap_thread_override_default_stacksize(zap_size_t size)
|
||||
FT_DECLARE(void) ftdm_thread_override_default_stacksize(ftdm_size_t size)
|
||||
{
|
||||
thread_default_stacksize = size;
|
||||
}
|
||||
|
||||
static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args)
|
||||
static void * FTDM_THREAD_CALLING_CONVENTION thread_launch(void *args)
|
||||
{
|
||||
void *exit_val;
|
||||
zap_thread_t *thread = (zap_thread_t *)args;
|
||||
ftdm_thread_t *thread = (ftdm_thread_t *)args;
|
||||
exit_val = thread->function(thread, thread->private_data);
|
||||
#ifndef WIN32
|
||||
pthread_attr_destroy(&thread->attribute);
|
||||
#endif
|
||||
zap_safe_free(thread);
|
||||
ftdm_safe_free(thread);
|
||||
|
||||
return exit_val;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached(ftdm_thread_function_t func, void *data)
|
||||
{
|
||||
return zap_thread_create_detached_ex(func, data, thread_default_stacksize);
|
||||
return ftdm_thread_create_detached_ex(func, data, thread_default_stacksize);
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached_ex(ftdm_thread_function_t func, void *data, ftdm_size_t stack_size)
|
||||
{
|
||||
zap_thread_t *thread = NULL;
|
||||
zap_status_t status = ZAP_FAIL;
|
||||
ftdm_thread_t *thread = NULL;
|
||||
ftdm_status_t status = FTDM_FAIL;
|
||||
|
||||
if (!func || !(thread = (zap_thread_t *)zap_malloc(sizeof(zap_thread_t)))) {
|
||||
if (!func || !(thread = (ftdm_thread_t *)ftdm_malloc(sizeof(ftdm_thread_t)))) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun
|
||||
}
|
||||
CloseHandle(thread->handle);
|
||||
|
||||
status = ZAP_SUCCESS;
|
||||
status = FTDM_SUCCESS;
|
||||
goto done;
|
||||
#else
|
||||
|
||||
@ -130,7 +130,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun
|
||||
|
||||
if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto failpthread;
|
||||
|
||||
status = ZAP_SUCCESS;
|
||||
status = FTDM_SUCCESS;
|
||||
goto done;
|
||||
failpthread:
|
||||
pthread_attr_destroy(&thread->attribute);
|
||||
@ -138,22 +138,22 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun
|
||||
|
||||
fail:
|
||||
if (thread) {
|
||||
zap_safe_free(thread);
|
||||
ftdm_safe_free(thread);
|
||||
}
|
||||
done:
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_mutex_create(ftdm_mutex_t **mutex)
|
||||
{
|
||||
zap_status_t status = ZAP_FAIL;
|
||||
ftdm_status_t status = FTDM_FAIL;
|
||||
#ifndef WIN32
|
||||
pthread_mutexattr_t attr;
|
||||
#endif
|
||||
zap_mutex_t *check = NULL;
|
||||
ftdm_mutex_t *check = NULL;
|
||||
|
||||
check = (zap_mutex_t *)zap_malloc(sizeof(**mutex));
|
||||
check = (ftdm_mutex_t *)ftdm_malloc(sizeof(**mutex));
|
||||
if (!check)
|
||||
goto done;
|
||||
#ifdef WIN32
|
||||
@ -177,77 +177,77 @@ OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex)
|
||||
success:
|
||||
#endif
|
||||
*mutex = check;
|
||||
status = ZAP_SUCCESS;
|
||||
status = FTDM_SUCCESS;
|
||||
|
||||
done:
|
||||
return status;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_mutex_destroy(ftdm_mutex_t **mutex)
|
||||
{
|
||||
zap_mutex_t *mp = *mutex;
|
||||
ftdm_mutex_t *mp = *mutex;
|
||||
*mutex = NULL;
|
||||
if (!mp) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
#ifdef WIN32
|
||||
DeleteCriticalSection(&mp->mutex);
|
||||
#else
|
||||
if (pthread_mutex_destroy(&mp->mutex))
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
#endif
|
||||
zap_safe_free(mp);
|
||||
return ZAP_SUCCESS;
|
||||
ftdm_safe_free(mp);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex)
|
||||
FT_DECLARE(ftdm_status_t) _ftdm_mutex_lock(ftdm_mutex_t *mutex)
|
||||
{
|
||||
#ifdef WIN32
|
||||
EnterCriticalSection(&mutex->mutex);
|
||||
#else
|
||||
int err;
|
||||
if ((err = pthread_mutex_lock(&mutex->mutex))) {
|
||||
zap_log(ZAP_LOG_ERROR, "Failed to lock mutex %d:%s\n", err, strerror(err));
|
||||
return ZAP_FAIL;
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failed to lock mutex %d:%s\n", err, strerror(err));
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
#endif
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex)
|
||||
FT_DECLARE(ftdm_status_t) _ftdm_mutex_trylock(ftdm_mutex_t *mutex)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (!TryEnterCriticalSection(&mutex->mutex))
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
#else
|
||||
if (pthread_mutex_trylock(&mutex->mutex))
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
#endif
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex)
|
||||
FT_DECLARE(ftdm_status_t) _ftdm_mutex_unlock(ftdm_mutex_t *mutex)
|
||||
{
|
||||
#ifdef WIN32
|
||||
LeaveCriticalSection(&mutex->mutex);
|
||||
#else
|
||||
if (pthread_mutex_unlock(&mutex->mutex))
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
#endif
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap_mutex_t *mutex)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_condition_create(ftdm_condition_t **incondition, ftdm_mutex_t *mutex)
|
||||
{
|
||||
zap_condition_t *condition = NULL;
|
||||
ftdm_condition_t *condition = NULL;
|
||||
|
||||
zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n");
|
||||
zap_assert_return(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n");
|
||||
ftdm_assert_return(incondition != NULL, FTDM_FAIL, "Condition double pointer is null!\n");
|
||||
ftdm_assert_return(mutex != NULL, FTDM_FAIL, "Mutex for condition must not be null!\n");
|
||||
|
||||
condition = zap_calloc(1, sizeof(*condition));
|
||||
condition = ftdm_calloc(1, sizeof(*condition));
|
||||
if (!condition) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
condition->mutex = mutex;
|
||||
@ -263,38 +263,38 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap
|
||||
#endif
|
||||
|
||||
*incondition = condition;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
|
||||
failed:
|
||||
if (condition) {
|
||||
zap_safe_free(condition);
|
||||
ftdm_safe_free(condition);
|
||||
}
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
#define ONE_BILLION 1000000000
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_condition_wait(ftdm_condition_t *condition, int ms)
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD res = 0;
|
||||
#endif
|
||||
zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n");
|
||||
ftdm_assert_return(condition != NULL, FTDM_FAIL, "Condition is null!\n");
|
||||
#ifdef WIN32
|
||||
zap_mutex_unlock(condition->mutex);
|
||||
ftdm_mutex_unlock(condition->mutex);
|
||||
res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE);
|
||||
zap_mutex_lock(condition->mutex);
|
||||
ftdm_mutex_lock(condition->mutex);
|
||||
switch (res) {
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_TIMEOUT:
|
||||
return ZAP_TIMEOUT;
|
||||
return FTDM_TIMEOUT;
|
||||
case WAIT_FAILED:
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
case WAIT_OBJECT_0:
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
default:
|
||||
zap_log(ZAP_LOG_ERROR, "Error waiting for openzap condition event (WaitForSingleObject returned %d)\n", res);
|
||||
return ZAP_FAIL;
|
||||
ftdm_log(FTDM_LOG_ERROR, "Error waiting for freetdm condition event (WaitForSingleObject returned %d)\n", res);
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
#else
|
||||
int res = 0;
|
||||
@ -314,48 +314,48 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
|
||||
}
|
||||
if (res != 0) {
|
||||
if (res == ETIMEDOUT) {
|
||||
return ZAP_TIMEOUT;
|
||||
return FTDM_TIMEOUT;
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res);
|
||||
return ZAP_FAIL;
|
||||
ftdm_log(FTDM_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res);
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_condition_signal(ftdm_condition_t *condition)
|
||||
{
|
||||
zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n");
|
||||
ftdm_assert_return(condition != NULL, FTDM_FAIL, "Condition is null!\n");
|
||||
#ifdef WIN32
|
||||
if (!SetEvent(condition->condition)) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
#else
|
||||
int err;
|
||||
if ((err = pthread_cond_signal(&condition->condition))) {
|
||||
zap_log(ZAP_LOG_ERROR, "Failed to signal condition %d:%s\n", err, strerror(err));
|
||||
return ZAP_FAIL;
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failed to signal condition %d:%s\n", err, strerror(err));
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
#endif
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_condition_destroy(ftdm_condition_t **incondition)
|
||||
{
|
||||
zap_condition_t *condition = NULL;
|
||||
zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n");
|
||||
ftdm_condition_t *condition = NULL;
|
||||
ftdm_assert_return(incondition != NULL, FTDM_FAIL, "Condition null when destroying!\n");
|
||||
condition = *incondition;
|
||||
#ifdef WIN32
|
||||
CloseHandle(condition->condition);
|
||||
#else
|
||||
if (pthread_cond_destroy(&condition->condition)) {
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
#endif
|
||||
zap_safe_free(condition);
|
||||
ftdm_safe_free(condition);
|
||||
*incondition = NULL;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
@ -31,30 +31,30 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ZAP_ANALOG_H
|
||||
#define ZAP_ANALOG_H
|
||||
#include "openzap.h"
|
||||
#ifndef FTDM_ANALOG_H
|
||||
#define FTDM_ANALOG_H
|
||||
#include "freetdm.h"
|
||||
|
||||
typedef enum {
|
||||
ZAP_ANALOG_RUNNING = (1 << 0),
|
||||
ZAP_ANALOG_CALLERID = (1 << 1)
|
||||
} zap_analog_flag_t;
|
||||
FTDM_ANALOG_RUNNING = (1 << 0),
|
||||
FTDM_ANALOG_CALLERID = (1 << 1)
|
||||
} ftdm_analog_flag_t;
|
||||
|
||||
#define ZAP_MAX_HOTLINE_STR 20
|
||||
#define FTDM_MAX_HOTLINE_STR 20
|
||||
#define MAX_DTMF 256
|
||||
|
||||
struct zap_analog_data {
|
||||
struct ftdm_analog_data {
|
||||
uint32_t flags;
|
||||
uint32_t max_dialstr;
|
||||
uint32_t digit_timeout;
|
||||
char hotline[ZAP_MAX_HOTLINE_STR];
|
||||
char hotline[FTDM_MAX_HOTLINE_STR];
|
||||
zio_signal_cb_t sig_cb;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void *zap_analog_run(zap_thread_t *me, void *obj);
|
||||
typedef struct zap_analog_data zap_analog_data_t;
|
||||
static void *ftdm_analog_run(ftdm_thread_t *me, void *obj);
|
||||
typedef struct ftdm_analog_data ftdm_analog_data_t;
|
||||
|
||||
#endif
|
||||
|
977
libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c
Normal file
977
libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c
Normal file
@ -0,0 +1,977 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_analog.h"
|
||||
|
||||
#ifndef localtime_r
|
||||
struct tm * localtime_r(const time_t *clock, struct tm *result);
|
||||
#endif
|
||||
|
||||
static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj);
|
||||
|
||||
/**
|
||||
* \brief Starts an FXO channel thread (outgoing call)
|
||||
* \param ftdmchan Channel to initiate call on
|
||||
* \return Success or failure
|
||||
*
|
||||
* Initialises state, starts tone progress detection and runs the channel in a new a thread.
|
||||
*/
|
||||
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call)
|
||||
{
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) {
|
||||
ftdm_channel_clear_needed_tones(ftdmchan);
|
||||
ftdm_channel_clear_detected_tones(ftdmchan);
|
||||
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL);
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_PROGRESS_DETECT, NULL);
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_DIAL] = 1;
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALING);
|
||||
ftdm_thread_create_detached(ftdm_analog_channel_run, ftdmchan);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Starts an FXS channel thread (outgoing call)
|
||||
* \param ftdmchan Channel to initiate call on
|
||||
* \return Success or failure
|
||||
*
|
||||
* Indicates call waiting if channel is already in use, otherwise runs the channel in a new thread.
|
||||
*/
|
||||
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call)
|
||||
{
|
||||
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_CALLWAITING);
|
||||
} else {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_GENRING);
|
||||
ftdm_thread_create_detached(ftdm_analog_channel_run, ftdmchan);
|
||||
}
|
||||
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Starts an analog span thread (monitor)
|
||||
* \param span Span to monitor
|
||||
* \return Success or failure
|
||||
*/
|
||||
static ftdm_status_t ftdm_analog_start(ftdm_span_t *span)
|
||||
{
|
||||
ftdm_analog_data_t *analog_data = span->signal_data;
|
||||
ftdm_set_flag(analog_data, FTDM_ANALOG_RUNNING);
|
||||
return ftdm_thread_create_detached(ftdm_analog_run, span);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialises an analog span from configuration variables
|
||||
* \param span Span to configure
|
||||
* \param sig_cb Callback function for event signals
|
||||
* \param ap List of configuration variables
|
||||
* \return Success or failure
|
||||
*/
|
||||
static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_configure_span)
|
||||
//ftdm_status_t ftdm_analog_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
|
||||
{
|
||||
ftdm_analog_data_t *analog_data;
|
||||
const char *tonemap = "us";
|
||||
const char *hotline = "";
|
||||
uint32_t digit_timeout = 10;
|
||||
uint32_t max_dialstr = MAX_DTMF;
|
||||
const char *var, *val;
|
||||
int *intval;
|
||||
uint32_t flags = FTDM_ANALOG_CALLERID;
|
||||
|
||||
assert(sig_cb != NULL);
|
||||
|
||||
if (span->signal_type) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling.");
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
analog_data = ftdm_malloc(sizeof(*analog_data));
|
||||
assert(analog_data != NULL);
|
||||
memset(analog_data, 0, sizeof(*analog_data));
|
||||
|
||||
while ((var = va_arg(ap, char *))) {
|
||||
if (!strcasecmp(var, "tonemap")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
tonemap = val;
|
||||
} else if (!strcasecmp(var, "digit_timeout")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
digit_timeout = *intval;
|
||||
} else if (!strcasecmp(var, "enable_callerid")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ftdm_true(val)) {
|
||||
flags |= FTDM_ANALOG_CALLERID;
|
||||
} else {
|
||||
flags &= ~FTDM_ANALOG_CALLERID;
|
||||
}
|
||||
} else if (!strcasecmp(var, "max_dialstr")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
max_dialstr = *intval;
|
||||
} else if (!strcasecmp(var, "hotline")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
hotline = val;
|
||||
} else {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (digit_timeout < 2000 || digit_timeout > 10000) {
|
||||
digit_timeout = 2000;
|
||||
}
|
||||
|
||||
if ((max_dialstr < 1 && !strlen(hotline)) || max_dialstr > MAX_DTMF) {
|
||||
max_dialstr = MAX_DTMF;
|
||||
}
|
||||
|
||||
span->start = ftdm_analog_start;
|
||||
analog_data->flags = flags;
|
||||
analog_data->digit_timeout = digit_timeout;
|
||||
analog_data->max_dialstr = max_dialstr;
|
||||
analog_data->sig_cb = sig_cb;
|
||||
strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline));
|
||||
span->signal_type = FTDM_SIGTYPE_ANALOG;
|
||||
span->signal_data = analog_data;
|
||||
span->outgoing_call = span->trunk_type == FTDM_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call;
|
||||
ftdm_span_load_tones(span, tonemap);
|
||||
|
||||
return FTDM_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieves tone generation output to be sent
|
||||
* \param ts Teletone generator
|
||||
* \param map Tone map
|
||||
* \return -1 on error, 0 on success
|
||||
*/
|
||||
static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
|
||||
{
|
||||
ftdm_buffer_t *dt_buffer = ts->user_data;
|
||||
int wrote;
|
||||
|
||||
if (!dt_buffer) {
|
||||
return -1;
|
||||
}
|
||||
wrote = teletone_mux_tones(ts, map);
|
||||
ftdm_buffer_write(dt_buffer, ts->buffer, wrote * 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends caller id on an analog channel (FSK coded)
|
||||
* \param ftdmchan Channel to send caller id on
|
||||
*/
|
||||
static void send_caller_id(ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
ftdm_fsk_data_state_t fsk_data;
|
||||
uint8_t databuf[1024] = "";
|
||||
char time_str[9];
|
||||
struct tm tm;
|
||||
time_t now;
|
||||
ftdm_mdmf_type_t mt = MDMF_INVALID;
|
||||
|
||||
time(&now);
|
||||
#ifdef WIN32
|
||||
_tzset();
|
||||
_localtime64_s(&tm, &now);
|
||||
#else
|
||||
localtime_r(&now, &tm);
|
||||
#endif
|
||||
strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm);
|
||||
|
||||
ftdm_fsk_data_init(&fsk_data, databuf, sizeof(databuf));
|
||||
ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *) time_str, 8);
|
||||
|
||||
if (ftdm_strlen_zero(ftdmchan->caller_data.cid_num.digits)) {
|
||||
mt = MDMF_NO_NUM;
|
||||
ftdm_set_string(ftdmchan->caller_data.cid_num.digits, "O");
|
||||
} else if (!strcasecmp(ftdmchan->caller_data.cid_num.digits, "P") || !strcasecmp(ftdmchan->caller_data.cid_num.digits, "O")) {
|
||||
mt = MDMF_NO_NUM;
|
||||
} else {
|
||||
mt = MDMF_PHONE_NUM;
|
||||
}
|
||||
ftdm_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) ftdmchan->caller_data.cid_num.digits, (uint8_t)strlen(ftdmchan->caller_data.cid_num.digits));
|
||||
|
||||
if (ftdm_strlen_zero(ftdmchan->caller_data.cid_name)) {
|
||||
mt = MDMF_NO_NAME;
|
||||
ftdm_set_string(ftdmchan->caller_data.cid_name, "O");
|
||||
} else if (!strcasecmp(ftdmchan->caller_data.cid_name, "P") || !strcasecmp(ftdmchan->caller_data.cid_name, "O")) {
|
||||
mt = MDMF_NO_NAME;
|
||||
} else {
|
||||
mt = MDMF_PHONE_NAME;
|
||||
}
|
||||
ftdm_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) ftdmchan->caller_data.cid_name, (uint8_t)strlen(ftdmchan->caller_data.cid_name));
|
||||
|
||||
ftdm_fsk_data_add_checksum(&fsk_data);
|
||||
ftdm_channel_send_fsk_data(ftdmchan, &fsk_data, -14);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for analog channel (outgoing call)
|
||||
* \param me Current thread
|
||||
* \param obj Channel to run in this thread
|
||||
*/
|
||||
static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj)
|
||||
{
|
||||
ftdm_channel_t *ftdmchan = (ftdm_channel_t *) obj;
|
||||
ftdm_buffer_t *dt_buffer = NULL;
|
||||
teletone_generation_session_t ts;
|
||||
uint8_t frame[1024];
|
||||
ftdm_size_t len, rlen;
|
||||
ftdm_tone_type_t tt = FTDM_TONE_DTMF;
|
||||
char dtmf[MAX_DTMF+1] = "";
|
||||
ftdm_size_t dtmf_offset = 0;
|
||||
ftdm_analog_data_t *analog_data = ftdmchan->span->signal_data;
|
||||
ftdm_channel_t *closed_chan;
|
||||
uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000;
|
||||
ftdm_sigmsg_t sig;
|
||||
ftdm_status_t status;
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n");
|
||||
|
||||
ts.buffer = NULL;
|
||||
|
||||
if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ftdm_buffer_create(&dt_buffer, 1024, 3192, 0) != FTDM_SUCCESS) {
|
||||
snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "memory error!");
|
||||
ftdm_log(FTDM_LOG_ERROR, "MEM ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) {
|
||||
snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "error initilizing tone detector!");
|
||||
ftdm_log(FTDM_LOG_ERROR, "TONE ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INTHREAD);
|
||||
teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
|
||||
ts.rate = 8000;
|
||||
#if 0
|
||||
ts.debug = 1;
|
||||
ts.debug_stream = stdout;
|
||||
#endif
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_GET_INTERVAL, &interval);
|
||||
ftdm_buffer_set_loops(dt_buffer, -1);
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = ftdmchan->chan_id;
|
||||
sig.span_id = ftdmchan->span_id;
|
||||
sig.channel = ftdmchan;
|
||||
|
||||
assert(interval != 0);
|
||||
|
||||
while (ftdm_running() && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) {
|
||||
ftdm_wait_flag_t flags = FTDM_READ;
|
||||
ftdm_size_t dlen = 0;
|
||||
|
||||
len = sizeof(frame);
|
||||
|
||||
elapsed += interval;
|
||||
state_counter += interval;
|
||||
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) {
|
||||
switch(ftdmchan->state) {
|
||||
case FTDM_CHANNEL_STATE_GET_CALLERID:
|
||||
{
|
||||
if (state_counter > 5000 || !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_CALLERID_DETECT)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_DISABLE_CALLERID_DETECT, NULL);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
if (state_counter > dial_timeout) {
|
||||
if (ftdmchan->needed_tones[FTDM_TONEMAP_DIAL]) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_GENRING:
|
||||
{
|
||||
if (state_counter > 60000) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
} else if (!ftdmchan->fsk_buffer || !ftdm_buffer_inuse(ftdmchan->fsk_buffer)) {
|
||||
ftdm_sleep(interval);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_HOLD) && state_counter > 10000) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_ATTN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_HANGUP:
|
||||
{
|
||||
if (state_counter > 500) {
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) &&
|
||||
(ftdmchan->last_state == FTDM_CHANNEL_STATE_RING || ftdmchan->last_state == FTDM_CHANNEL_STATE_DIALTONE
|
||||
|| ftdmchan->last_state >= FTDM_CHANNEL_STATE_IDLE)) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CLEARING;
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_CALLWAITING:
|
||||
{
|
||||
int done = 0;
|
||||
|
||||
if (ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] == 1) {
|
||||
send_caller_id(ftdmchan);
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]++;
|
||||
} else if (state_counter > 600 && !ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]) {
|
||||
send_caller_id(ftdmchan);
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]++;
|
||||
} else if (state_counter > 1000 && !ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]) {
|
||||
done = 1;
|
||||
} else if (state_counter > 10000) {
|
||||
if (ftdmchan->fsk_buffer) {
|
||||
ftdm_buffer_zero(ftdmchan->fsk_buffer);
|
||||
} else {
|
||||
ftdm_buffer_create(&ftdmchan->fsk_buffer, 128, 128, 0);
|
||||
}
|
||||
|
||||
ts.user_data = ftdmchan->fsk_buffer;
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_CALLWAITING_SAS]);
|
||||
ts.user_data = dt_buffer;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE);
|
||||
ftdm_clear_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE);
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] = 0;
|
||||
}
|
||||
}
|
||||
case FTDM_CHANNEL_STATE_UP:
|
||||
case FTDM_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
ftdm_sleep(interval);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE);
|
||||
ftdm_clear_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE);
|
||||
ftdm_channel_complete_state(ftdmchan);
|
||||
indicate = 0;
|
||||
state_counter = 0;
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Executing state handler on %d:%d for %s\n",
|
||||
ftdmchan->span_id, ftdmchan->chan_id,
|
||||
ftdm_channel_state2str(ftdmchan->state));
|
||||
switch(ftdmchan->state) {
|
||||
case FTDM_CHANNEL_STATE_UP:
|
||||
{
|
||||
ftdm_channel_use(ftdmchan);
|
||||
ftdm_channel_clear_needed_tones(ftdmchan);
|
||||
ftdm_channel_flush_dtmf(ftdmchan);
|
||||
|
||||
if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL);
|
||||
}
|
||||
|
||||
if (ftdmchan->fsk_buffer && ftdm_buffer_inuse(ftdmchan->fsk_buffer)) {
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Cancel FSK transmit due to early answer.\n");
|
||||
ftdm_buffer_zero(ftdmchan->fsk_buffer);
|
||||
}
|
||||
|
||||
if (ftdmchan->type == FTDM_CHAN_TYPE_FXS && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
if (ftdmchan->token_count == 1) {
|
||||
ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_HOLD);
|
||||
}
|
||||
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_HOLD)) {
|
||||
ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_HOLD);
|
||||
sig.event_id = FTDM_SIGEVENT_ADD_CALL;
|
||||
} else {
|
||||
sig.event_id = FTDM_SIGEVENT_UP;
|
||||
}
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
ftdm_channel_use(ftdmchan);
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
ftdm_channel_use(ftdmchan);
|
||||
sig.event_id = FTDM_SIGEVENT_START;
|
||||
|
||||
if (ftdmchan->type == FTDM_CHAN_TYPE_FXO) {
|
||||
ftdm_set_string(ftdmchan->caller_data.dnis.digits, ftdmchan->chan_number);
|
||||
} else {
|
||||
ftdm_set_string(ftdmchan->caller_data.dnis.digits, dtmf);
|
||||
}
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
sig.event_id = FTDM_SIGEVENT_STOP;
|
||||
analog_data->sig_cb(&sig);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data));
|
||||
*dtmf = '\0';
|
||||
dtmf_offset = 0;
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_DIAL]);
|
||||
indicate = 1;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_CALLWAITING:
|
||||
{
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] = 0;
|
||||
if (ftdmchan->fsk_buffer) {
|
||||
ftdm_buffer_zero(ftdmchan->fsk_buffer);
|
||||
} else {
|
||||
ftdm_buffer_create(&ftdmchan->fsk_buffer, 128, 128, 0);
|
||||
}
|
||||
|
||||
ts.user_data = ftdmchan->fsk_buffer;
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_CALLWAITING_SAS]);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_CALLWAITING_CAS]);
|
||||
ts.user_data = dt_buffer;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_GENRING:
|
||||
{
|
||||
ftdm_sigmsg_t sig;
|
||||
|
||||
send_caller_id(ftdmchan);
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_ON, NULL);
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = ftdmchan->chan_id;
|
||||
sig.span_id = ftdmchan->span_id;
|
||||
sig.channel = ftdmchan;
|
||||
sig.event_id = FTDM_SIGEVENT_PROGRESS;
|
||||
analog_data->sig_cb(&sig);
|
||||
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_GET_CALLERID:
|
||||
{
|
||||
memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data));
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_CALLERID_DETECT, NULL);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_RING:
|
||||
{
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_RING]);
|
||||
indicate = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CIRCUIT_CONGESTION;
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_BUSY]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_ATTN]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE || ftdmchan->state == FTDM_CHANNEL_STATE_COLLECT) {
|
||||
if ((dlen = ftdm_channel_dequeue_dtmf(ftdmchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {
|
||||
|
||||
if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_COLLECT);
|
||||
collecting = 1;
|
||||
}
|
||||
dtmf_offset = strlen(dtmf);
|
||||
last_digit = elapsed;
|
||||
sig.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT;
|
||||
sig.raw_data = dtmf;
|
||||
if (analog_data->sig_cb(&sig) == FTDM_BREAK) {
|
||||
collecting = 0;
|
||||
}
|
||||
}
|
||||
else if(!analog_data->max_dialstr)
|
||||
{
|
||||
last_digit = elapsed;
|
||||
collecting = 0;
|
||||
strcpy(dtmf, analog_data->hotline);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) >= analog_data->max_dialstr))) {
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Number obtained [%s]\n", dtmf);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE);
|
||||
last_digit = 0;
|
||||
collecting = 0;
|
||||
}
|
||||
|
||||
if (ftdm_channel_wait(ftdmchan, &flags, interval * 2) != FTDM_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(flags & FTDM_READ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ftdm_channel_read(ftdmchan, frame, &len) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "READ ERROR [%s]\n", ftdmchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && ftdmchan->detected_tones[0]) {
|
||||
ftdm_sigmsg_t sig;
|
||||
int i;
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = ftdmchan->chan_id;
|
||||
sig.span_id = ftdmchan->span_id;
|
||||
sig.channel = ftdmchan;
|
||||
sig.event_id = FTDM_SIGEVENT_TONE_DETECTED;
|
||||
|
||||
for (i = 1; i < FTDM_TONEMAP_INVALID; i++) {
|
||||
if (ftdmchan->detected_tones[i]) {
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Detected tone %s on %d:%d\n", ftdm_tonemap2str(i), ftdmchan->span_id, ftdmchan->chan_id);
|
||||
sig.raw_data = &i;
|
||||
if (analog_data->sig_cb) {
|
||||
analog_data->sig_cb(&sig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ftdmchan->detected_tones[FTDM_TONEMAP_BUSY] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_FAIL1] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_FAIL2] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_FAIL3] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_ATTN]
|
||||
) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failure indication detected!\n");
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else if (ftdmchan->detected_tones[FTDM_TONEMAP_DIAL]) {
|
||||
if (ftdm_strlen_zero(ftdmchan->caller_data.ani.digits)) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "No Digits to send!\n");
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.ani.digits) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Send Digits Failed [%s]\n", ftdmchan->last_error);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
state_counter = 0;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_RING] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_BUSY] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_FAIL1] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_FAIL2] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_FAIL3] = 1;
|
||||
dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.ani.digits)) + 2000;
|
||||
}
|
||||
}
|
||||
} else if (ftdmchan->detected_tones[FTDM_TONEMAP_RING]) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
}
|
||||
|
||||
ftdm_channel_clear_detected_tones(ftdmchan);
|
||||
}
|
||||
|
||||
if ((ftdmchan->dtmf_buffer && ftdm_buffer_inuse(ftdmchan->dtmf_buffer)) || (ftdmchan->fsk_buffer && ftdm_buffer_inuse(ftdmchan->fsk_buffer))) {
|
||||
//rlen = len;
|
||||
//memset(frame, 0, len);
|
||||
//ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!indicate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL);
|
||||
}
|
||||
|
||||
if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) {
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
rlen = ftdm_buffer_read_loop(dt_buffer, frame, len);
|
||||
|
||||
if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) {
|
||||
zio_codec_t codec_func = NULL;
|
||||
|
||||
if (ftdmchan->native_codec == FTDM_CODEC_ULAW) {
|
||||
codec_func = zio_slin2ulaw;
|
||||
} else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) {
|
||||
codec_func = zio_slin2alaw;
|
||||
}
|
||||
|
||||
if (codec_func) {
|
||||
status = codec_func(frame, sizeof(frame), &rlen);
|
||||
} else {
|
||||
snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
|
||||
if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_ONHOOK, NULL);
|
||||
}
|
||||
|
||||
if (ftdmchan->type == FTDM_CHAN_TYPE_FXS && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
|
||||
closed_chan = ftdmchan;
|
||||
ftdm_channel_close(&ftdmchan);
|
||||
|
||||
ftdm_channel_command(closed_chan, FTDM_COMMAND_SET_NATIVE_CODEC, NULL);
|
||||
|
||||
if (ts.buffer) {
|
||||
teletone_destroy_session(&ts);
|
||||
}
|
||||
|
||||
if (dt_buffer) {
|
||||
ftdm_buffer_destroy(&dt_buffer);
|
||||
}
|
||||
|
||||
if (closed_chan->state != FTDM_CHANNEL_STATE_DOWN) {
|
||||
ftdm_set_state_locked(closed_chan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG CHANNEL %d:%d thread ended.\n", closed_chan->span_id, closed_chan->chan_id);
|
||||
ftdm_clear_flag(closed_chan, FTDM_CHANNEL_INTHREAD);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Processes freetdm event
|
||||
* \param span Span on which the event was fired
|
||||
* \param event Event to be treated
|
||||
* \return Success or failure
|
||||
*/
|
||||
static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event)
|
||||
{
|
||||
ftdm_sigmsg_t sig;
|
||||
ftdm_analog_data_t *analog_data = event->channel->span->signal_data;
|
||||
int locked = 0;
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = event->channel->chan_id;
|
||||
sig.span_id = event->channel->span_id;
|
||||
sig.channel = event->channel;
|
||||
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n",
|
||||
ftdm_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state));
|
||||
|
||||
ftdm_mutex_lock(event->channel->mutex);
|
||||
locked++;
|
||||
|
||||
switch(event->enum_id) {
|
||||
case FTDM_OOB_RING_START:
|
||||
{
|
||||
if (event->channel->type != FTDM_CHAN_TYPE_FXO) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Cannot get a RING_START event on a non-fxo channel, please check your config.\n");
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN);
|
||||
goto end;
|
||||
}
|
||||
if (!event->channel->ring_count && (event->channel->state == FTDM_CHANNEL_STATE_DOWN && !ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD))) {
|
||||
if (ftdm_test_flag(analog_data, FTDM_ANALOG_CALLERID)) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_GET_CALLERID);
|
||||
} else {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_IDLE);
|
||||
}
|
||||
event->channel->ring_count = 1;
|
||||
ftdm_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
ftdm_thread_create_detached(ftdm_analog_channel_run, event->channel);
|
||||
} else {
|
||||
event->channel->ring_count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_OOB_ONHOOK:
|
||||
{
|
||||
if (ftdm_test_flag(event->channel, FTDM_CHANNEL_RINGING)) {
|
||||
ftdm_channel_command(event->channel, FTDM_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case FTDM_OOB_FLASH:
|
||||
{
|
||||
if (event->channel->state == FTDM_CHANNEL_STATE_CALLWAITING) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP);
|
||||
ftdm_clear_flag_locked(event->channel, FTDM_CHANNEL_STATE_CHANGE);
|
||||
ftdm_clear_flag_locked(event->channel->span, FTDM_SPAN_STATE_CHANGE);
|
||||
event->channel->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] = 0;
|
||||
}
|
||||
|
||||
ftdm_channel_rotate_tokens(event->channel);
|
||||
|
||||
if (ftdm_test_flag(event->channel, FTDM_CHANNEL_HOLD) && event->channel->token_count != 1) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP);
|
||||
} else {
|
||||
sig.event_id = FTDM_SIGEVENT_FLASH;
|
||||
analog_data->sig_cb(&sig);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_OOB_OFFHOOK:
|
||||
{
|
||||
if (event->channel->type == FTDM_CHAN_TYPE_FXS) {
|
||||
if (ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD)) {
|
||||
if (ftdm_test_flag(event->channel, FTDM_CHANNEL_RINGING)) {
|
||||
ftdm_channel_command(event->channel, FTDM_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP);
|
||||
} else {
|
||||
if(!analog_data->max_dialstr) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_COLLECT);
|
||||
} else {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DIALTONE);
|
||||
}
|
||||
ftdm_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
ftdm_thread_create_detached(ftdm_analog_channel_run, event->channel);
|
||||
}
|
||||
} else {
|
||||
if (!ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD)) {
|
||||
if (ftdm_test_flag(event->channel, FTDM_CHANNEL_OFFHOOK)) {
|
||||
ftdm_channel_command(event->channel, FTDM_COMMAND_ONHOOK, NULL);
|
||||
}
|
||||
}
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
if (locked) {
|
||||
ftdm_mutex_unlock(event->channel->mutex);
|
||||
}
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for analog span (monitor)
|
||||
* \param me Current thread
|
||||
* \param obj Span to run in this thread
|
||||
*/
|
||||
static void *ftdm_analog_run(ftdm_thread_t *me, void *obj)
|
||||
{
|
||||
ftdm_span_t *span = (ftdm_span_t *) obj;
|
||||
ftdm_analog_data_t *analog_data = span->signal_data;
|
||||
int errs = 0;
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG thread starting.\n");
|
||||
|
||||
while(ftdm_running() && ftdm_test_flag(analog_data, FTDM_ANALOG_RUNNING)) {
|
||||
int waitms = 1000;
|
||||
ftdm_status_t status;
|
||||
|
||||
if ((status = ftdm_span_poll_event(span, waitms)) != FTDM_FAIL) {
|
||||
errs = 0;
|
||||
}
|
||||
|
||||
switch(status) {
|
||||
case FTDM_SUCCESS:
|
||||
{
|
||||
ftdm_event_t *event;
|
||||
while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) {
|
||||
if (event->enum_id == FTDM_OOB_NOOP) {
|
||||
continue;
|
||||
}
|
||||
if (process_event(span, event) != FTDM_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_FAIL:
|
||||
{
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error);
|
||||
if (++errs > 300) {
|
||||
ftdm_log(FTDM_LOG_CRIT, "Too Many Errors!\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
ftdm_clear_flag(analog_data, FTDM_ANALOG_RUNNING);
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG thread ending.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openftdm analog signaling module initialisation
|
||||
* \return Success
|
||||
*/
|
||||
static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_init)
|
||||
{
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openftdm analog signaling module definition
|
||||
*/
|
||||
EX_DECLARE_DATA ftdm_module_t ftdm_module = {
|
||||
"analog",
|
||||
NULL,
|
||||
NULL,
|
||||
ftdm_analog_init,
|
||||
ftdm_analog_configure_span,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
@ -36,26 +36,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ZAP_ANALOG_EM_H
|
||||
#define ZAP_ANALOG_EM_H
|
||||
#include "openzap.h"
|
||||
#ifndef FTDM_ANALOG_EM_H
|
||||
#define FTDM_ANALOG_EM_H
|
||||
#include "freetdm.h"
|
||||
|
||||
#define MAX_DIALSTRING 256
|
||||
|
||||
typedef enum {
|
||||
ZAP_ANALOG_EM_RUNNING = (1 << 0)
|
||||
} zap_analog_em_flag_t;
|
||||
FTDM_ANALOG_EM_RUNNING = (1 << 0)
|
||||
} ftdm_analog_em_flag_t;
|
||||
|
||||
|
||||
struct zap_analog_data {
|
||||
struct ftdm_analog_data {
|
||||
uint32_t flags;
|
||||
uint32_t max_dialstr;
|
||||
uint32_t digit_timeout;
|
||||
zio_signal_cb_t sig_cb;
|
||||
};
|
||||
|
||||
static void *zap_analog_em_run(zap_thread_t *me, void *obj);
|
||||
typedef struct zap_analog_data zap_analog_em_data_t;
|
||||
static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj);
|
||||
typedef struct ftdm_analog_data ftdm_analog_em_data_t;
|
||||
|
||||
#endif
|
||||
|
709
libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c
Normal file
709
libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c
Normal file
@ -0,0 +1,709 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* John Wehle (john@feith.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_analog_em.h"
|
||||
|
||||
#ifndef localtime_r
|
||||
struct tm * localtime_r(const time_t *clock, struct tm *result);
|
||||
#endif
|
||||
|
||||
static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj);
|
||||
|
||||
/**
|
||||
* \brief Starts an EM channel thread (outgoing call)
|
||||
* \param ftdmchan Channel to initiate call on
|
||||
* \return Success or failure
|
||||
*
|
||||
* Initialises state, starts tone progress detection and runs the channel in a new a thread.
|
||||
*/
|
||||
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call)
|
||||
{
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) {
|
||||
ftdm_channel_clear_needed_tones(ftdmchan);
|
||||
ftdm_channel_clear_detected_tones(ftdmchan);
|
||||
|
||||
ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND);
|
||||
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL);
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_PROGRESS_DETECT, NULL);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALING);
|
||||
ftdm_thread_create_detached(ftdm_analog_em_channel_run, ftdmchan);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Starts an EM span thread (monitor)
|
||||
* \param span Span to monitor
|
||||
* \return Success or failure
|
||||
*/
|
||||
static ftdm_status_t ftdm_analog_em_start(ftdm_span_t *span)
|
||||
{
|
||||
ftdm_analog_em_data_t *analog_data = span->signal_data;
|
||||
ftdm_set_flag(analog_data, FTDM_ANALOG_EM_RUNNING);
|
||||
return ftdm_thread_create_detached(ftdm_analog_em_run, span);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialises an EM span from configuration variables
|
||||
* \param span Span to configure
|
||||
* \param sig_cb Callback function for event signals
|
||||
* \param ap List of configuration variables
|
||||
* \return Success or failure
|
||||
*/
|
||||
static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_em_configure_span)
|
||||
//ftdm_status_t ftdm_analog_em_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
|
||||
{
|
||||
ftdm_analog_em_data_t *analog_data;
|
||||
const char *tonemap = "us";
|
||||
uint32_t digit_timeout = 10;
|
||||
uint32_t max_dialstr = 11;
|
||||
const char *var, *val;
|
||||
int *intval;
|
||||
|
||||
assert(sig_cb != NULL);
|
||||
|
||||
if (span->signal_type) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling.");
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
analog_data = ftdm_malloc(sizeof(*analog_data));
|
||||
assert(analog_data != NULL);
|
||||
memset(analog_data, 0, sizeof(*analog_data));
|
||||
|
||||
while((var = va_arg(ap, char *))) {
|
||||
if (!strcasecmp(var, "tonemap")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
tonemap = val;
|
||||
} else if (!strcasecmp(var, "digit_timeout")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
digit_timeout = *intval;
|
||||
} else if (!strcasecmp(var, "max_dialstr")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
max_dialstr = *intval;
|
||||
} else {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (digit_timeout < 2000 || digit_timeout > 10000) {
|
||||
digit_timeout = 2000;
|
||||
}
|
||||
|
||||
if (max_dialstr < 2 || max_dialstr > MAX_DIALSTRING) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Invalid max_dialstr, setting to %d\n", MAX_DIALSTRING);
|
||||
max_dialstr = MAX_DIALSTRING;
|
||||
}
|
||||
|
||||
span->start = ftdm_analog_em_start;
|
||||
analog_data->digit_timeout = digit_timeout;
|
||||
analog_data->max_dialstr = max_dialstr;
|
||||
analog_data->sig_cb = sig_cb;
|
||||
span->signal_type = FTDM_SIGTYPE_ANALOG;
|
||||
span->signal_data = analog_data;
|
||||
span->outgoing_call = analog_em_outgoing_call;
|
||||
ftdm_span_load_tones(span, tonemap);
|
||||
|
||||
return FTDM_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieves tone generation output to be sent
|
||||
* \param ts Teletone generator
|
||||
* \param map Tone map
|
||||
* \return -1 on error, 0 on success
|
||||
*/
|
||||
static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
|
||||
{
|
||||
ftdm_buffer_t *dt_buffer = ts->user_data;
|
||||
int wrote;
|
||||
|
||||
if (!dt_buffer) {
|
||||
return -1;
|
||||
}
|
||||
wrote = teletone_mux_tones(ts, map);
|
||||
ftdm_buffer_write(dt_buffer, ts->buffer, wrote * 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for EM channel (outgoing call)
|
||||
* \param me Current thread
|
||||
* \param obj Channel to run in this thread
|
||||
*/
|
||||
static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj)
|
||||
{
|
||||
ftdm_channel_t *ftdmchan = (ftdm_channel_t *) obj;
|
||||
ftdm_buffer_t *dt_buffer = NULL;
|
||||
teletone_generation_session_t ts;
|
||||
uint8_t frame[1024];
|
||||
ftdm_size_t len, rlen;
|
||||
ftdm_tone_type_t tt = FTDM_TONE_DTMF;
|
||||
char dtmf[128] = "";
|
||||
ftdm_size_t dtmf_offset = 0;
|
||||
ftdm_analog_em_data_t *analog_data = ftdmchan->span->signal_data;
|
||||
ftdm_channel_t *closed_chan;
|
||||
uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000;
|
||||
ftdm_sigmsg_t sig;
|
||||
ftdm_status_t status;
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM CHANNEL thread starting.\n");
|
||||
|
||||
ts.buffer = NULL;
|
||||
|
||||
if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ftdm_buffer_create(&dt_buffer, 1024, 3192, 0) != FTDM_SUCCESS) {
|
||||
snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "memory error!");
|
||||
ftdm_log(FTDM_LOG_ERROR, "MEM ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) {
|
||||
snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "error initilizing tone detector!");
|
||||
ftdm_log(FTDM_LOG_ERROR, "TONE ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INTHREAD);
|
||||
teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
|
||||
ts.rate = 8000;
|
||||
#if 0
|
||||
ts.debug = 1;
|
||||
ts.debug_stream = stdout;
|
||||
#endif
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_GET_INTERVAL, &interval);
|
||||
ftdm_buffer_set_loops(dt_buffer, -1);
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = ftdmchan->chan_id;
|
||||
sig.span_id = ftdmchan->span_id;
|
||||
sig.channel = ftdmchan;
|
||||
|
||||
assert(interval != 0);
|
||||
|
||||
while (ftdm_running() && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) {
|
||||
ftdm_wait_flag_t flags = FTDM_READ;
|
||||
ftdm_size_t dlen = 0;
|
||||
|
||||
len = sizeof(frame);
|
||||
|
||||
elapsed += interval;
|
||||
state_counter += interval;
|
||||
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) {
|
||||
switch(ftdmchan->state) {
|
||||
case FTDM_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
if (! ftdmchan->needed_tones[FTDM_TONEMAP_RING]
|
||||
&& ftdm_test_flag(ftdmchan, FTDM_CHANNEL_WINK)) {
|
||||
if (ftdm_strlen_zero(ftdmchan->caller_data.ani.digits)) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "No Digits to send!\n");
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.ani.digits) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Send Digits Failed [%s]\n", ftdmchan->last_error);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
state_counter = 0;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_RING] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_BUSY] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_FAIL1] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_FAIL2] = 1;
|
||||
ftdmchan->needed_tones[FTDM_TONEMAP_FAIL3] = 1;
|
||||
dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.ani.digits)) + 2000;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (state_counter > dial_timeout) {
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_WINK)) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
if (state_counter > 10000) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_ATTN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_HANGUP:
|
||||
{
|
||||
if (state_counter > 500) {
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) &&
|
||||
(ftdmchan->last_state == FTDM_CHANNEL_STATE_RING || ftdmchan->last_state == FTDM_CHANNEL_STATE_DIALTONE
|
||||
|| ftdmchan->last_state >= FTDM_CHANNEL_STATE_IDLE)) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CLEARING;
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_UP:
|
||||
case FTDM_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
ftdm_sleep(interval);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE);
|
||||
ftdm_clear_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE);
|
||||
ftdm_channel_complete_state(ftdmchan);
|
||||
indicate = 0;
|
||||
state_counter = 0;
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Executing state handler on %d:%d for %s\n",
|
||||
ftdmchan->span_id, ftdmchan->chan_id,
|
||||
ftdm_channel_state2str(ftdmchan->state));
|
||||
switch(ftdmchan->state) {
|
||||
case FTDM_CHANNEL_STATE_UP:
|
||||
{
|
||||
ftdm_channel_use(ftdmchan);
|
||||
ftdm_channel_clear_needed_tones(ftdmchan);
|
||||
ftdm_channel_flush_dtmf(ftdmchan);
|
||||
|
||||
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) {
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL);
|
||||
}
|
||||
|
||||
sig.event_id = FTDM_SIGEVENT_UP;
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
ftdm_channel_use(ftdmchan);
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
ftdm_channel_use(ftdmchan);
|
||||
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
ftdm_set_string(ftdmchan->caller_data.dnis.digits, ftdmchan->chan_number);
|
||||
} else {
|
||||
ftdm_set_string(ftdmchan->caller_data.dnis.digits, dtmf);
|
||||
}
|
||||
|
||||
sig.event_id = FTDM_SIGEVENT_START;
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
sig.event_id = FTDM_SIGEVENT_STOP;
|
||||
analog_data->sig_cb(&sig);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data));
|
||||
*dtmf = '\0';
|
||||
dtmf_offset = 0;
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_DIAL]);
|
||||
indicate = 1;
|
||||
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_WINK, NULL);
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_RING:
|
||||
{
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_RING]);
|
||||
indicate = 1;
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CIRCUIT_CONGESTION;
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_BUSY]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
|
||||
ftdm_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_ATTN]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE || ftdmchan->state == FTDM_CHANNEL_STATE_COLLECT) {
|
||||
if ((dlen = ftdm_channel_dequeue_dtmf(ftdmchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {
|
||||
|
||||
if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_COLLECT);
|
||||
collecting = 1;
|
||||
}
|
||||
dtmf_offset = strlen(dtmf);
|
||||
last_digit = elapsed;
|
||||
sig.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT;
|
||||
sig.raw_data = dtmf;
|
||||
if (analog_data->sig_cb(&sig) == FTDM_BREAK) {
|
||||
collecting = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) {
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Number obtained [%s]\n", dtmf);
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE);
|
||||
last_digit = 0;
|
||||
collecting = 0;
|
||||
}
|
||||
|
||||
if (ftdm_channel_wait(ftdmchan, &flags, interval * 2) != FTDM_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(flags & FTDM_READ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ftdm_channel_read(ftdmchan, frame, &len) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "READ ERROR [%s]\n", ftdmchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ftdmchan->detected_tones[0]) {
|
||||
ftdm_sigmsg_t sig;
|
||||
int i;
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = ftdmchan->chan_id;
|
||||
sig.span_id = ftdmchan->span_id;
|
||||
sig.channel = ftdmchan;
|
||||
sig.event_id = FTDM_SIGEVENT_TONE_DETECTED;
|
||||
|
||||
for (i = 1; i < FTDM_TONEMAP_INVALID; i++) {
|
||||
if (ftdmchan->detected_tones[i]) {
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Detected tone %s on %d:%d\n", ftdm_tonemap2str(i), ftdmchan->span_id, ftdmchan->chan_id);
|
||||
sig.raw_data = &i;
|
||||
if (analog_data->sig_cb) {
|
||||
analog_data->sig_cb(&sig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ftdmchan->detected_tones[FTDM_TONEMAP_BUSY] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_FAIL1] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_FAIL2] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_FAIL3] ||
|
||||
ftdmchan->detected_tones[FTDM_TONEMAP_ATTN]
|
||||
) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failure indication detected!\n");
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY);
|
||||
} else if (ftdmchan->detected_tones[FTDM_TONEMAP_RING]) {
|
||||
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
}
|
||||
|
||||
ftdm_channel_clear_detected_tones(ftdmchan);
|
||||
}
|
||||
|
||||
if ((ftdmchan->dtmf_buffer && ftdm_buffer_inuse(ftdmchan->dtmf_buffer))) {
|
||||
rlen = len;
|
||||
memset(frame, 0, len);
|
||||
ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!indicate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) {
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
rlen = ftdm_buffer_read_loop(dt_buffer, frame, len);
|
||||
|
||||
if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) {
|
||||
zio_codec_t codec_func = NULL;
|
||||
|
||||
if (ftdmchan->native_codec == FTDM_CODEC_ULAW) {
|
||||
codec_func = zio_slin2ulaw;
|
||||
} else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) {
|
||||
codec_func = zio_slin2alaw;
|
||||
}
|
||||
|
||||
if (codec_func) {
|
||||
status = codec_func(frame, sizeof(frame), &rlen);
|
||||
} else {
|
||||
snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
ftdm_channel_command(ftdmchan, FTDM_COMMAND_ONHOOK, NULL);
|
||||
|
||||
closed_chan = ftdmchan;
|
||||
ftdm_channel_close(&ftdmchan);
|
||||
|
||||
ftdm_channel_command(closed_chan, FTDM_COMMAND_SET_NATIVE_CODEC, NULL);
|
||||
|
||||
if (ts.buffer) {
|
||||
teletone_destroy_session(&ts);
|
||||
}
|
||||
|
||||
if (dt_buffer) {
|
||||
ftdm_buffer_destroy(&dt_buffer);
|
||||
}
|
||||
|
||||
ftdm_clear_flag(closed_chan, FTDM_CHANNEL_INTHREAD);
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM CHANNEL thread ended.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Processes EM events coming from ftdmtel/dahdi
|
||||
* \param span Span on which the event was fired
|
||||
* \param event Event to be treated
|
||||
* \return Success or failure
|
||||
*/
|
||||
static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event)
|
||||
{
|
||||
ftdm_sigmsg_t sig;
|
||||
int locked = 0;
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = event->channel->chan_id;
|
||||
sig.span_id = event->channel->span_id;
|
||||
sig.channel = event->channel;
|
||||
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n",
|
||||
ftdm_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state));
|
||||
|
||||
ftdm_mutex_lock(event->channel->mutex);
|
||||
locked++;
|
||||
|
||||
switch(event->enum_id) {
|
||||
case FTDM_OOB_ONHOOK:
|
||||
{
|
||||
if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case FTDM_OOB_OFFHOOK:
|
||||
{
|
||||
if (ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD)) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP);
|
||||
} else {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DIALTONE);
|
||||
ftdm_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
ftdm_thread_create_detached(ftdm_analog_em_channel_run, event->channel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FTDM_OOB_WINK:
|
||||
{
|
||||
if (event->channel->state != FTDM_CHANNEL_STATE_DIALING) {
|
||||
ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN);
|
||||
} else {
|
||||
ftdm_set_flag_locked(event->channel, FTDM_CHANNEL_WINK);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (locked) {
|
||||
ftdm_mutex_unlock(event->channel->mutex);
|
||||
}
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for EM span (monitor)
|
||||
* \param me Current thread
|
||||
* \param obj Span to run in this thread
|
||||
*/
|
||||
static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj)
|
||||
{
|
||||
ftdm_span_t *span = (ftdm_span_t *) obj;
|
||||
ftdm_analog_em_data_t *analog_data = span->signal_data;
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM thread starting.\n");
|
||||
|
||||
while(ftdm_running() && ftdm_test_flag(analog_data, FTDM_ANALOG_EM_RUNNING)) {
|
||||
int waitms = 10;
|
||||
ftdm_status_t status;
|
||||
|
||||
status = ftdm_span_poll_event(span, waitms);
|
||||
|
||||
switch(status) {
|
||||
case FTDM_SUCCESS:
|
||||
{
|
||||
ftdm_event_t *event;
|
||||
while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) {
|
||||
if (event->enum_id == FTDM_OOB_NOOP) {
|
||||
continue;
|
||||
}
|
||||
if (process_event(span, event) != FTDM_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FTDM_FAIL:
|
||||
{
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
ftdm_clear_flag(analog_data, FTDM_ANALOG_EM_RUNNING);
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM thread ending.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openftdm analog EM module initialisation
|
||||
* \return Success
|
||||
*/
|
||||
static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_em_init)
|
||||
{
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openftdm analog EM module definition
|
||||
*/
|
||||
EX_DECLARE_DATA ftdm_module_t ftdm_module = {
|
||||
"analog_em",
|
||||
NULL,
|
||||
NULL,
|
||||
ftdm_analog_em_init,
|
||||
ftdm_analog_em_configure_span,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
@ -31,55 +31,55 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ZAP_ISDN_H
|
||||
#define ZAP_ISDN_H
|
||||
#include "openzap.h"
|
||||
#ifndef FTDM_ISDN_H
|
||||
#define FTDM_ISDN_H
|
||||
#include "freetdm.h"
|
||||
|
||||
#define DEFAULT_DIGIT_TIMEOUT 10000 /* default overlap timeout: 10 seconds */
|
||||
|
||||
|
||||
typedef enum {
|
||||
ZAP_ISDN_OPT_NONE = 0,
|
||||
ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0),
|
||||
ZAP_ISDN_OPT_OMIT_DISPLAY_IE = (1 << 1), /*!< Do not send Caller name in outgoing SETUP message (= Display IE) */
|
||||
ZAP_ISDN_OPT_DISABLE_TONES = (1 << 2), /*!< Disable tone generating thread (NT mode) */
|
||||
FTDM_ISDN_OPT_NONE = 0,
|
||||
FTDM_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0),
|
||||
FTDM_ISDN_OPT_OMIT_DISPLAY_IE = (1 << 1), /*!< Do not send Caller name in outgoing SETUP message (= Display IE) */
|
||||
FTDM_ISDN_OPT_DISABLE_TONES = (1 << 2), /*!< Disable tone generating thread (NT mode) */
|
||||
|
||||
ZAP_ISDN_OPT_MAX = (2 << 0)
|
||||
} zap_isdn_opts_t;
|
||||
FTDM_ISDN_OPT_MAX = (2 << 0)
|
||||
} ftdm_isdn_opts_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_ISDN_RUNNING = (1 << 0),
|
||||
ZAP_ISDN_TONES_RUNNING = (1 << 1),
|
||||
ZAP_ISDN_STOP = (1 << 2)
|
||||
} zap_isdn_flag_t;
|
||||
FTDM_ISDN_RUNNING = (1 << 0),
|
||||
FTDM_ISDN_TONES_RUNNING = (1 << 1),
|
||||
FTDM_ISDN_STOP = (1 << 2)
|
||||
} ftdm_isdn_flag_t;
|
||||
|
||||
|
||||
struct zap_isdn_data {
|
||||
struct ftdm_isdn_data {
|
||||
Q921Data_t q921;
|
||||
Q931_TrunkInfo_t q931;
|
||||
zap_channel_t *dchan;
|
||||
zap_channel_t *dchans[2];
|
||||
struct zap_sigmsg sigmsg;
|
||||
ftdm_channel_t *dchan;
|
||||
ftdm_channel_t *dchans[2];
|
||||
struct ftdm_sigmsg sigmsg;
|
||||
zio_signal_cb_t sig_cb;
|
||||
uint32_t flags;
|
||||
int32_t mode;
|
||||
int32_t digit_timeout;
|
||||
zap_isdn_opts_t opts;
|
||||
zap_caller_data_t *outbound_crv[32768];
|
||||
zap_channel_t *channels_local_crv[32768];
|
||||
zap_channel_t *channels_remote_crv[32768];
|
||||
ftdm_isdn_opts_t opts;
|
||||
ftdm_caller_data_t *outbound_crv[32768];
|
||||
ftdm_channel_t *channels_local_crv[32768];
|
||||
ftdm_channel_t *channels_remote_crv[32768];
|
||||
};
|
||||
|
||||
typedef struct zap_isdn_data zap_isdn_data_t;
|
||||
typedef struct ftdm_isdn_data ftdm_isdn_data_t;
|
||||
|
||||
|
||||
/* b-channel private data */
|
||||
struct zap_isdn_bchan_data
|
||||
struct ftdm_isdn_bchan_data
|
||||
{
|
||||
L2ULONG digit_timeout;
|
||||
};
|
||||
|
||||
typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t;
|
||||
typedef struct ftdm_isdn_bchan_data ftdm_isdn_bchan_data_t;
|
||||
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -32,33 +32,33 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OZMOD_LIBPRI_H
|
||||
#define OZMOD_LIBPRI_H
|
||||
#include "openzap.h"
|
||||
#ifndef FTMOD_LIBPRI_H
|
||||
#define FTMOD_LIBPRI_H
|
||||
#include "freetdm.h"
|
||||
#include "lpwrap_pri.h"
|
||||
|
||||
typedef enum {
|
||||
OZMOD_LIBPRI_OPT_NONE = 0,
|
||||
OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0),
|
||||
OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1),
|
||||
OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2),
|
||||
FTMOD_LIBPRI_OPT_NONE = 0,
|
||||
FTMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0),
|
||||
FTMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1),
|
||||
FTMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2),
|
||||
|
||||
OZMOD_LIBPRI_OPT_MAX = (1 << 3)
|
||||
} zap_isdn_opts_t;
|
||||
FTMOD_LIBPRI_OPT_MAX = (1 << 3)
|
||||
} ftdm_isdn_opts_t;
|
||||
|
||||
typedef enum {
|
||||
OZMOD_LIBPRI_RUNNING = (1 << 0)
|
||||
} zap_isdn_flag_t;
|
||||
FTMOD_LIBPRI_RUNNING = (1 << 0)
|
||||
} ftdm_isdn_flag_t;
|
||||
|
||||
|
||||
struct zap_libpri_data {
|
||||
zap_channel_t *dchan;
|
||||
zap_channel_t *dchans[2];
|
||||
struct zap_sigmsg sigmsg;
|
||||
struct ftdm_libpri_data {
|
||||
ftdm_channel_t *dchan;
|
||||
ftdm_channel_t *dchans[2];
|
||||
struct ftdm_sigmsg sigmsg;
|
||||
zio_signal_cb_t sig_cb;
|
||||
uint32_t flags;
|
||||
int32_t mode;
|
||||
zap_isdn_opts_t opts;
|
||||
ftdm_isdn_opts_t opts;
|
||||
|
||||
int node;
|
||||
int pswitch;
|
||||
@ -71,16 +71,16 @@ struct zap_libpri_data {
|
||||
lpwrap_pri_t spri;
|
||||
};
|
||||
|
||||
typedef struct zap_libpri_data zap_libpri_data_t;
|
||||
typedef struct ftdm_libpri_data ftdm_libpri_data_t;
|
||||
|
||||
|
||||
/* b-channel private data */
|
||||
struct zap_isdn_bchan_data
|
||||
struct ftdm_isdn_bchan_data
|
||||
{
|
||||
int32_t digit_timeout;
|
||||
};
|
||||
|
||||
typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t;
|
||||
typedef struct ftdm_isdn_bchan_data ftdm_isdn_bchan_data_t;
|
||||
|
||||
|
||||
#endif
|
@ -33,7 +33,7 @@
|
||||
|
||||
//#define IODEBUG
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include "lpwrap_pri.h"
|
||||
#ifndef HAVE_GETTIMEOFDAY
|
||||
|
||||
@ -113,19 +113,19 @@ const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id)
|
||||
static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
|
||||
{
|
||||
struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri);
|
||||
zap_size_t len = buflen;
|
||||
ftdm_size_t len = buflen;
|
||||
int res;
|
||||
zap_status_t zst;
|
||||
ftdm_status_t zst;
|
||||
|
||||
if ((zst = zap_channel_read(spri->dchan, buf, &len)) != ZAP_SUCCESS) {
|
||||
if (zst == ZAP_FAIL) {
|
||||
zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
|
||||
if ((zst = ftdm_channel_read(spri->dchan, buf, &len)) != FTDM_SUCCESS) {
|
||||
if (zst == FTDM_FAIL) {
|
||||
ftdm_log(FTDM_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
|
||||
spri->errs++;
|
||||
} else {
|
||||
zap_log(ZAP_LOG_CRIT, "span %d D-READ TIMEOUT\n", spri->span->span_id);
|
||||
ftdm_log(FTDM_LOG_CRIT, "span %d D-READ TIMEOUT\n", spri->span->span_id);
|
||||
}
|
||||
|
||||
zap_clear_flag(spri, LPWRAP_PRI_READY);
|
||||
ftdm_clear_flag(spri, LPWRAP_PRI_READY);
|
||||
return -1;
|
||||
}
|
||||
spri->errs = 0;
|
||||
@ -138,7 +138,7 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
|
||||
char bb[2048] = { 0 };
|
||||
|
||||
print_hex_bytes(buf, res - 2, bb, sizeof(bb));
|
||||
zap_log(ZAP_LOG_DEBUG, "READ %d\n", res-2);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "READ %d\n", res-2);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -148,11 +148,11 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
|
||||
static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
|
||||
{
|
||||
struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri);
|
||||
zap_size_t len = buflen -2;
|
||||
ftdm_size_t len = buflen -2;
|
||||
|
||||
if (zap_channel_write(spri->dchan, buf, buflen, &len) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
|
||||
zap_clear_flag(spri, LPWRAP_PRI_READY);
|
||||
if (ftdm_channel_write(spri->dchan, buf, buflen, &len) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
|
||||
ftdm_clear_flag(spri, LPWRAP_PRI_READY);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -161,14 +161,14 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
|
||||
char bb[2048] = { 0 };
|
||||
|
||||
print_hex_bytes(buf, buflen - 2, bb, sizeof(bb));
|
||||
zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", (int)buflen-2);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n", (int)buflen-2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (int) buflen;
|
||||
}
|
||||
|
||||
int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug)
|
||||
int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int debug)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
@ -182,8 +182,8 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dc
|
||||
size_t buflen = sizeof(buf), len = 0;
|
||||
pri_set_debug(spri->pri, debug);
|
||||
ret = 0;
|
||||
zap_set_flag(spri, LPWRAP_PRI_READY);
|
||||
zap_channel_write(spri->dchan, buf, buflen, &len);
|
||||
ftdm_set_flag(spri, LPWRAP_PRI_READY);
|
||||
ftdm_channel_write(spri->dchan, buf, buflen, &len);
|
||||
} else {
|
||||
fprintf(stderr, "Unable to create PRI\n");
|
||||
}
|
||||
@ -238,7 +238,7 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
|
||||
if ((next = pri_schedule_next(spri->pri))) {
|
||||
gettimeofday(&now, NULL);
|
||||
if (now.tv_sec >= next->tv_sec && (now.tv_usec >= next->tv_usec || next->tv_usec <= 100000)) {
|
||||
//zap_log(ZAP_LOG_DEBUG, "Check event\n");
|
||||
//ftdm_log(FTDM_LOG_DEBUG, "Check event\n");
|
||||
event = pri_schedule_run(spri->pri);
|
||||
}
|
||||
}
|
||||
@ -251,7 +251,7 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
|
||||
if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
|
||||
handler(spri, event->e, event);
|
||||
} else {
|
||||
zap_log(ZAP_LOG_CRIT, "No event handler found for event %d.\n", event->e);
|
||||
ftdm_log(FTDM_LOG_CRIT, "No event handler found for event %d.\n", event->e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ int lpwrap_run_pri(struct lpwrap_pri *spri)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
zap_log(ZAP_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno));
|
||||
ftdm_log(FTDM_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@
|
||||
#ifndef _LPWRAP_PRI_H
|
||||
#define _LPWRAP_PRI_H
|
||||
#include <libpri.h>
|
||||
#include <openzap.h>
|
||||
#include <freetdm.h>
|
||||
|
||||
|
||||
#define LPWRAP_MAX_CHAN_PER_SPAN 32
|
||||
@ -97,8 +97,8 @@ typedef int (*loop_handler)(struct lpwrap_pri *);
|
||||
|
||||
struct lpwrap_pri {
|
||||
struct pri *pri;
|
||||
zap_span_t *span;
|
||||
zap_channel_t *dchan;
|
||||
ftdm_span_t *span;
|
||||
ftdm_channel_t *dchan;
|
||||
unsigned int flags;
|
||||
void *private_info;
|
||||
event_handler eventmap[LPWRAP_PRI_EVENT_MAX];
|
||||
@ -120,7 +120,7 @@ struct lpwrap_pri_event_list {
|
||||
|
||||
const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id);
|
||||
int lpwrap_one_loop(struct lpwrap_pri *spri);
|
||||
int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug);
|
||||
int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int debug);
|
||||
int lpwrap_run_pri(struct lpwrap_pri *spri);
|
||||
|
||||
#endif
|
@ -31,9 +31,9 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ZAP_PIKA_H
|
||||
#define ZAP_PIKA_H
|
||||
#include "openzap.h"
|
||||
#ifndef FTDM_PIKA_H
|
||||
#define FTDM_PIKA_H
|
||||
#include "freetdm.h"
|
||||
#include "pikahmpapi.h"
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
1367
libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c
Normal file
1367
libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -31,19 +31,19 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ZAP_SANGOMA_BOOST_H
|
||||
#define ZAP_SANGOMA_BOOST_H
|
||||
#ifndef FTDM_SANGOMA_BOOST_H
|
||||
#define FTDM_SANGOMA_BOOST_H
|
||||
#include "sangoma_boost_client.h"
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
#define MAX_CHANS_PER_TRUNKGROUP 1024
|
||||
|
||||
typedef enum {
|
||||
ZAP_SANGOMA_BOOST_RUNNING = (1 << 0),
|
||||
ZAP_SANGOMA_BOOST_RESTARTING = (1 << 1)
|
||||
} zap_sangoma_boost_flag_t;
|
||||
FTDM_SANGOMA_BOOST_RUNNING = (1 << 0),
|
||||
FTDM_SANGOMA_BOOST_RESTARTING = (1 << 1)
|
||||
} ftdm_sangoma_boost_flag_t;
|
||||
|
||||
typedef struct zap_sangoma_boost_data {
|
||||
typedef struct ftdm_sangoma_boost_data {
|
||||
sangomabc_connection_t mcon;
|
||||
sangomabc_connection_t pcon;
|
||||
fd_set rfds;
|
||||
@ -52,16 +52,16 @@ typedef struct zap_sangoma_boost_data {
|
||||
zio_signal_cb_t signal_cb;
|
||||
uint32_t flags;
|
||||
boost_sigmod_interface_t *sigmod;
|
||||
zap_queue_t *boost_queue;
|
||||
} zap_sangoma_boost_data_t;
|
||||
ftdm_queue_t *boost_queue;
|
||||
} ftdm_sangoma_boost_data_t;
|
||||
|
||||
typedef struct zap_sangoma_boost_trunkgroup {
|
||||
zap_mutex_t *mutex;
|
||||
zap_size_t size; /* Number of b-channels in group */
|
||||
typedef struct ftdm_sangoma_boost_trunkgroup {
|
||||
ftdm_mutex_t *mutex;
|
||||
ftdm_size_t size; /* Number of b-channels in group */
|
||||
unsigned int last_used_index; /* index of last b-channel used */
|
||||
zap_channel_t* zchans[MAX_CHANS_PER_TRUNKGROUP];
|
||||
ftdm_channel_t* ftdmchans[MAX_CHANS_PER_TRUNKGROUP];
|
||||
//DAVIDY need to merge congestion timeouts to this struct
|
||||
} zap_sangoma_boost_trunkgroup_t;
|
||||
} ftdm_sangoma_boost_trunkgroup_t;
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
File diff suppressed because it is too large
Load Diff
@ -35,7 +35,7 @@
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include "sangoma_boost_client.h"
|
||||
|
||||
#ifndef HAVE_GETHOSTBYNAME_R
|
||||
@ -77,7 +77,7 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e
|
||||
if (event->event_id == SIGBOOST_EVENT_HEARTBEAT)
|
||||
return;
|
||||
|
||||
zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n",
|
||||
ftdm_log(file, func, line, FTDM_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n",
|
||||
dir ? "TX":"RX",
|
||||
priority ? "P":"N",
|
||||
sangomabc_event_id_name(event->event_id),
|
||||
@ -96,7 +96,7 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_
|
||||
{
|
||||
if (event->event_id == SIGBOOST_EVENT_HEARTBEAT)
|
||||
return;
|
||||
zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n",
|
||||
ftdm_log(file, func, line, FTDM_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n",
|
||||
dir ? "TX":"RX",
|
||||
priority ? "P":"N",
|
||||
sangomabc_event_id_name(event->event_id),
|
||||
@ -118,18 +118,18 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int
|
||||
int err = 0, local_err = 0;
|
||||
|
||||
if (mcon->sigmod) {
|
||||
zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n");
|
||||
ftdm_log(FTDM_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp));
|
||||
memset(&mcon->local_hp, 0, sizeof(mcon->local_hp));
|
||||
#ifdef HAVE_NETINET_SCTP_H
|
||||
zap_log(ZAP_LOG_DEBUG, "Creating SCTP socket L=%s:%d R=%s:%d\n",
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Creating SCTP socket L=%s:%d R=%s:%d\n",
|
||||
local_ip, local_port, ip, port);
|
||||
mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
|
||||
#else
|
||||
zap_log(ZAP_LOG_DEBUG, "Creating UDP socket L=%s:%d R=%s:%d\n",
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Creating UDP socket L=%s:%d R=%s:%d\n",
|
||||
local_ip, local_port, ip, port);
|
||||
mcon->socket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
#endif
|
||||
@ -187,7 +187,7 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon)
|
||||
{
|
||||
#ifndef WIN32
|
||||
if (mcon->sigmod) {
|
||||
zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n");
|
||||
ftdm_log(FTDM_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n");
|
||||
return 0;
|
||||
}
|
||||
if (mcon->socket > -1) {
|
||||
@ -195,9 +195,9 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon)
|
||||
}
|
||||
|
||||
if (mcon->mutex) {
|
||||
zap_mutex_lock(mcon->mutex);
|
||||
zap_mutex_unlock(mcon->mutex);
|
||||
zap_mutex_destroy(&mcon->mutex);
|
||||
ftdm_mutex_lock(mcon->mutex);
|
||||
ftdm_mutex_unlock(mcon->mutex);
|
||||
ftdm_mutex_destroy(&mcon->mutex);
|
||||
}
|
||||
memset(mcon, 0, sizeof(*mcon));
|
||||
mcon->socket = -1;
|
||||
@ -207,7 +207,7 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon)
|
||||
|
||||
int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
|
||||
{
|
||||
zap_mutex_create(&mcon->mutex);
|
||||
ftdm_mutex_create(&mcon->mutex);
|
||||
if (mcon->sigmod) {
|
||||
/*value of mcon->socket will be ignored in sigmod mode */
|
||||
return 0;
|
||||
@ -242,11 +242,11 @@ int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int
|
||||
|
||||
while (sangomabc_connection_write(mcon, (sangomabc_event_t*)&oevent) <= 0) {
|
||||
if (--retry <= 0) {
|
||||
zap_log(ZAP_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno));
|
||||
ftdm_log(FTDM_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
zap_log(ZAP_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry);
|
||||
zap_sleep(1);
|
||||
ftdm_log(FTDM_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry);
|
||||
ftdm_sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,11 +268,11 @@ int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, in
|
||||
|
||||
while (sangomabc_connection_writep(pcon, (sangomabc_event_t*)&oevent) <= 0) {
|
||||
if (--retry <= 0) {
|
||||
zap_log(ZAP_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno));
|
||||
ftdm_log(FTDM_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
zap_log(ZAP_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry);
|
||||
zap_sleep(1);
|
||||
ftdm_log(FTDM_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry);
|
||||
ftdm_sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,11 +289,11 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int
|
||||
sangomabc_queue_element_t *e = NULL;
|
||||
|
||||
if (mcon->sigmod) {
|
||||
e = zap_queue_dequeue(mcon->boost_queue);
|
||||
e = ftdm_queue_dequeue(mcon->boost_queue);
|
||||
if (e) {
|
||||
bytes = e->size;
|
||||
memcpy(&mcon->event, e->boostmsg, bytes);
|
||||
zap_safe_free(e);
|
||||
ftdm_safe_free(e);
|
||||
}
|
||||
}
|
||||
#ifndef WIN32
|
||||
@ -307,7 +307,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int
|
||||
}
|
||||
|
||||
if (mcon->event.version != SIGBOOST_VERSION) {
|
||||
zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION);
|
||||
ftdm_log(FTDM_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION);
|
||||
}
|
||||
|
||||
/* Must check for < 0 cannot rely on bytes > MIN_SIZE_... compiler issue */
|
||||
@ -329,7 +329,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int
|
||||
if (mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART &&
|
||||
mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK &&
|
||||
mcon->event.event_id != SIGBOOST_EVENT_HEARTBEAT) {
|
||||
zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "Not reading packets when connection is down. [%s]\n",
|
||||
ftdm_log(file, func, line, FTDM_LOG_LEVEL_WARNING, "Not reading packets when connection is down. [%s]\n",
|
||||
sangomabc_event_id_name(mcon->event.event_id));
|
||||
return NULL;
|
||||
}
|
||||
@ -345,12 +345,12 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int
|
||||
/* NC: NOT USED ANY MORE */
|
||||
if (mcon->rxseq_reset) {
|
||||
//if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Rx sync ok\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Rx sync ok\n");
|
||||
mcon->rxseq = mcon->event.fseqno;
|
||||
return &mcon->event;
|
||||
//}
|
||||
errno=EAGAIN;
|
||||
zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Waiting for rx sync...\n");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@ -360,7 +360,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int
|
||||
|
||||
#if 0
|
||||
if (mcon->rxseq != mcon->event.fseqno) {
|
||||
zap_log(ZAP_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno);
|
||||
ftdm_log(FTDM_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@ -368,7 +368,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int
|
||||
return &mcon->event;
|
||||
} else {
|
||||
if (iteration == 0) {
|
||||
zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
ftdm_log(FTDM_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -397,7 +397,7 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in
|
||||
}
|
||||
|
||||
if (mcon->event.version != SIGBOOST_VERSION) {
|
||||
zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION);
|
||||
ftdm_log(FTDM_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION);
|
||||
}
|
||||
|
||||
if (bytes == sizeof(sangomabc_short_event_t)) {
|
||||
@ -411,7 +411,7 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in
|
||||
return &mcon->event;
|
||||
} else {
|
||||
if (iteration == 0) {
|
||||
zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
ftdm_log(FTDM_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -425,12 +425,12 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t
|
||||
int err = 0;
|
||||
int event_size=MIN_SIZE_CALLSTART_MSG+event->isup_in_rdnis_size;
|
||||
|
||||
zap_assert_return(event != NULL, -1, "No event!");
|
||||
zap_assert_return(mcon->socket >= 0, -1, "No mcon->socket!");
|
||||
zap_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!");
|
||||
ftdm_assert_return(event != NULL, -1, "No event!");
|
||||
ftdm_assert_return(mcon->socket >= 0, -1, "No mcon->socket!");
|
||||
ftdm_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!");
|
||||
|
||||
if (event->span >= ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN || event->chan >= ZAP_MAX_CHANNELS_PHYSICAL_SPAN ) {
|
||||
zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", sangomabc_event_id_name(event->event_id), event->span, event->chan);
|
||||
if (event->span >= FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN || event->chan >= FTDM_MAX_CHANNELS_PHYSICAL_SPAN ) {
|
||||
ftdm_log(file, func, line, FTDM_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", sangomabc_event_id_name(event->event_id), event->span, event->chan);
|
||||
abort();
|
||||
return -1;
|
||||
}
|
||||
@ -443,13 +443,13 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t
|
||||
if (event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART &&
|
||||
event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK &&
|
||||
event->event_id != SIGBOOST_EVENT_HEARTBEAT) {
|
||||
zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "Not writing packets when connection is down. [%s]\n",
|
||||
ftdm_log(file, func, line, FTDM_LOG_LEVEL_WARNING, "Not writing packets when connection is down. [%s]\n",
|
||||
sangomabc_event_id_name(event->event_id));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
zap_mutex_lock(mcon->mutex);
|
||||
ftdm_mutex_lock(mcon->mutex);
|
||||
if (event->event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) {
|
||||
mcon->txseq=0;
|
||||
mcon->rxseq=0;
|
||||
@ -476,9 +476,9 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t
|
||||
}
|
||||
#endif
|
||||
|
||||
zap_mutex_unlock(mcon->mutex);
|
||||
ftdm_mutex_unlock(mcon->mutex);
|
||||
|
||||
zap_assert_return(err == event_size, -1, "Failed to send the boost message completely!");
|
||||
ftdm_assert_return(err == event_size, -1, "Failed to send the boost message completely!");
|
||||
|
||||
return err;
|
||||
}
|
||||
@ -490,16 +490,16 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_
|
||||
int event_size=sizeof(sangomabc_event_t);
|
||||
|
||||
if (!mcon->sigmod) {
|
||||
zap_assert_return(event != NULL, -1, "No event!");
|
||||
zap_assert_return(mcon->socket >= 0, -1, "No mcon->socket!");
|
||||
zap_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!");
|
||||
ftdm_assert_return(event != NULL, -1, "No event!");
|
||||
ftdm_assert_return(mcon->socket >= 0, -1, "No mcon->socket!");
|
||||
ftdm_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!");
|
||||
}
|
||||
|
||||
if (!boost_full_event(event->event_id)) {
|
||||
event_size=sizeof(sangomabc_short_event_t);
|
||||
}
|
||||
|
||||
zap_mutex_lock(mcon->mutex);
|
||||
ftdm_mutex_lock(mcon->mutex);
|
||||
event->version = SIGBOOST_VERSION;
|
||||
if (mcon->sigmod) {
|
||||
mcon->sigmod->write_msg(mcon->span, event, event_size);
|
||||
@ -511,9 +511,9 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_
|
||||
err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr));
|
||||
}
|
||||
#endif
|
||||
zap_mutex_unlock(mcon->mutex);
|
||||
ftdm_mutex_unlock(mcon->mutex);
|
||||
|
||||
zap_assert_return(err == event_size, -1, "Failed to send boost message completely!");
|
||||
ftdm_assert_return(err == event_size, -1, "Failed to send boost message completely!");
|
||||
|
||||
if (boost_full_event(event->event_id)) {
|
||||
sangomabc_print_event_call(mcon, event, 1, 1, file, func, line);
|
@ -91,14 +91,14 @@ typedef enum {
|
||||
|
||||
|
||||
struct sangomabc_connection {
|
||||
zap_socket_t socket;
|
||||
ftdm_socket_t socket;
|
||||
struct sockaddr_in local_addr;
|
||||
struct sockaddr_in remote_addr;
|
||||
sangomabc_event_t event;
|
||||
struct hostent remote_hp;
|
||||
struct hostent local_hp;
|
||||
unsigned int flags;
|
||||
zap_mutex_t *mutex;
|
||||
ftdm_mutex_t *mutex;
|
||||
FILE *log;
|
||||
unsigned int txseq;
|
||||
unsigned int rxseq;
|
||||
@ -108,15 +108,15 @@ struct sangomabc_connection {
|
||||
uint32_t hb_elapsed;
|
||||
/* boost signaling mod interface pointer (if not working in TCP mode) */
|
||||
boost_sigmod_interface_t *sigmod;
|
||||
zap_queue_t *boost_queue;
|
||||
zap_span_t *span;
|
||||
ftdm_queue_t *boost_queue;
|
||||
ftdm_span_t *span;
|
||||
};
|
||||
|
||||
typedef struct sangomabc_connection sangomabc_connection_t;
|
||||
|
||||
typedef struct sangomabc_queue_element {
|
||||
unsigned char boostmsg[sizeof(sangomabc_event_t)];
|
||||
zap_size_t size;
|
||||
ftdm_size_t size;
|
||||
} sangomabc_queue_element_t;
|
||||
|
||||
/* disable nagle's algorythm */
|
@ -35,7 +35,7 @@
|
||||
#ifndef SANGOMA_BOOST_INTERFACE_H
|
||||
#define SANGOMA_BOOST_INTERFACE_H
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -44,28 +44,28 @@ extern "C" {
|
||||
|
||||
/*!
|
||||
\brief Callback used to notify signaling status changes on a channel
|
||||
\param zchan The openzap channel where the signaling status just changed
|
||||
\param ftdmchan The freetdm channel where the signaling status just changed
|
||||
\param status The new signaling status
|
||||
*/
|
||||
#define BOOST_SIG_STATUS_CB_ARGS (zap_channel_t *zchan, zap_signaling_status_t status)
|
||||
#define BOOST_SIG_STATUS_CB_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status)
|
||||
typedef void (*boost_sig_status_cb_func_t) BOOST_SIG_STATUS_CB_ARGS;
|
||||
#define BOOST_SIG_STATUS_CB_FUNCTION(name) void name BOOST_SIG_STATUS_CB_ARGS
|
||||
|
||||
/*!
|
||||
\brief Write a boost msg to a boost endpoint
|
||||
\param span The openzap span where this msg was generated
|
||||
\param span The freetdm span where this msg was generated
|
||||
\param msg The generic message pointer, owned by the caller
|
||||
\param msglen The length of the provided structure pointed by msg
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
|
||||
The msg buffer is owned by the caller and it should
|
||||
be either t_sigboost_callstart or t_sigboost_short
|
||||
the endpoint receiving the msg will first cast to
|
||||
t_sigboost_short, check the event type, and if needed.
|
||||
*/
|
||||
#define BOOST_WRITE_MSG_ARGS (zap_span_t *span, void *msg, zap_size_t msglen)
|
||||
typedef zap_status_t (*boost_write_msg_func_t) BOOST_WRITE_MSG_ARGS;
|
||||
#define BOOST_WRITE_MSG_FUNCTION(name) zap_status_t name BOOST_WRITE_MSG_ARGS
|
||||
#define BOOST_WRITE_MSG_ARGS (ftdm_span_t *span, void *msg, ftdm_size_t msglen)
|
||||
typedef ftdm_status_t (*boost_write_msg_func_t) BOOST_WRITE_MSG_ARGS;
|
||||
#define BOOST_WRITE_MSG_FUNCTION(name) ftdm_status_t name BOOST_WRITE_MSG_ARGS
|
||||
|
||||
/*!
|
||||
\brief Set the callback to be used by a signaling module to write boost messages
|
||||
@ -80,11 +80,11 @@ typedef void (*boost_set_write_msg_cb_func_t) BOOST_SET_WRITE_MSG_CB_ARGS;
|
||||
|
||||
/*!
|
||||
\brief Notify hardware status change
|
||||
\param zchan The openzap channel
|
||||
\param ftdmchan The freetdm channel
|
||||
\param status The hw status
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
*/
|
||||
#define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status)
|
||||
#define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (ftdm_channel_t *ftdmchan, ftdm_channel_hw_link_status_t status)
|
||||
typedef void (*boost_on_hw_link_status_change_func_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS;
|
||||
#define BOOST_ON_HW_LINK_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS
|
||||
|
||||
@ -101,84 +101,84 @@ typedef void (*boost_set_sig_status_cb_func_t) BOOST_SET_SIG_STATUS_CB_ARGS;
|
||||
|
||||
/*!
|
||||
\brief Get the signaling status on the given channel.
|
||||
\param zchan The openzap channel
|
||||
\param ftdmchan The freetdm channel
|
||||
\param status The status pointer where the current signaling status will be set
|
||||
*/
|
||||
#define BOOST_GET_CHANNEL_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t *status)
|
||||
typedef zap_status_t (*boost_get_channel_sig_status_func_t) BOOST_GET_CHANNEL_SIG_STATUS_ARGS;
|
||||
#define BOOST_GET_CHANNEL_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_CHANNEL_SIG_STATUS_ARGS
|
||||
#define BOOST_GET_CHANNEL_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status)
|
||||
typedef ftdm_status_t (*boost_get_channel_sig_status_func_t) BOOST_GET_CHANNEL_SIG_STATUS_ARGS;
|
||||
#define BOOST_GET_CHANNEL_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_GET_CHANNEL_SIG_STATUS_ARGS
|
||||
|
||||
/*!
|
||||
\brief Set the signaling status on the given channel.
|
||||
\param zchan The openzap channel
|
||||
\param ftdmchan The freetdm channel
|
||||
\param status The new status for the channel
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
*/
|
||||
#define BOOST_SET_CHANNEL_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t status)
|
||||
typedef zap_status_t (*boost_set_channel_sig_status_func_t) BOOST_SET_CHANNEL_SIG_STATUS_ARGS;
|
||||
#define BOOST_SET_CHANNEL_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_CHANNEL_SIG_STATUS_ARGS
|
||||
#define BOOST_SET_CHANNEL_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status)
|
||||
typedef ftdm_status_t (*boost_set_channel_sig_status_func_t) BOOST_SET_CHANNEL_SIG_STATUS_ARGS;
|
||||
#define BOOST_SET_CHANNEL_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_SET_CHANNEL_SIG_STATUS_ARGS
|
||||
|
||||
/*!
|
||||
\brief Get the signaling status on the given span.
|
||||
\param span The openzap span
|
||||
\param span The freetdm span
|
||||
\param status The status pointer where the current signaling status will be set
|
||||
*/
|
||||
#define BOOST_GET_SPAN_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t *status)
|
||||
typedef zap_status_t (*boost_get_span_sig_status_func_t) BOOST_GET_SPAN_SIG_STATUS_ARGS;
|
||||
#define BOOST_GET_SPAN_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_SPAN_SIG_STATUS_ARGS
|
||||
#define BOOST_GET_SPAN_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t *status)
|
||||
typedef ftdm_status_t (*boost_get_span_sig_status_func_t) BOOST_GET_SPAN_SIG_STATUS_ARGS;
|
||||
#define BOOST_GET_SPAN_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_GET_SPAN_SIG_STATUS_ARGS
|
||||
|
||||
/*!
|
||||
\brief Set the signaling status on the given span.
|
||||
\param zchan The openzap span
|
||||
\param ftdmchan The freetdm span
|
||||
\param status The new status for the span
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
*/
|
||||
#define BOOST_SET_SPAN_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t status)
|
||||
typedef zap_status_t (*boost_set_span_sig_status_func_t) BOOST_SET_SPAN_SIG_STATUS_ARGS;
|
||||
#define BOOST_SET_SPAN_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_SPAN_SIG_STATUS_ARGS
|
||||
#define BOOST_SET_SPAN_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t status)
|
||||
typedef ftdm_status_t (*boost_set_span_sig_status_func_t) BOOST_SET_SPAN_SIG_STATUS_ARGS;
|
||||
#define BOOST_SET_SPAN_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_SET_SPAN_SIG_STATUS_ARGS
|
||||
|
||||
/*!
|
||||
\brief Configure the given span signaling
|
||||
\param span The openzap span
|
||||
\param span The freetdm span
|
||||
\param parameters The array of configuration key,value pairs (must be null terminated)
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
*/
|
||||
#define BOOST_CONFIGURE_SPAN_ARGS (zap_span_t *span, zap_conf_parameter_t *parameters)
|
||||
typedef zap_status_t (*boost_configure_span_func_t) BOOST_CONFIGURE_SPAN_ARGS;
|
||||
#define BOOST_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name BOOST_CONFIGURE_SPAN_ARGS
|
||||
#define BOOST_CONFIGURE_SPAN_ARGS (ftdm_span_t *span, ftdm_conf_parameter_t *parameters)
|
||||
typedef ftdm_status_t (*boost_configure_span_func_t) BOOST_CONFIGURE_SPAN_ARGS;
|
||||
#define BOOST_CONFIGURE_SPAN_FUNCTION(name) ftdm_status_t name BOOST_CONFIGURE_SPAN_ARGS
|
||||
|
||||
/*!
|
||||
\brief Start the given span
|
||||
\param span The openzap span
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\param span The freetdm span
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
*/
|
||||
#define BOOST_START_SPAN_ARGS (zap_span_t *span)
|
||||
typedef zap_status_t (*boost_start_span_func_t) BOOST_START_SPAN_ARGS;
|
||||
#define BOOST_START_SPAN_FUNCTION(name) zap_status_t name BOOST_START_SPAN_ARGS
|
||||
#define BOOST_START_SPAN_ARGS (ftdm_span_t *span)
|
||||
typedef ftdm_status_t (*boost_start_span_func_t) BOOST_START_SPAN_ARGS;
|
||||
#define BOOST_START_SPAN_FUNCTION(name) ftdm_status_t name BOOST_START_SPAN_ARGS
|
||||
|
||||
/*!
|
||||
\brief Stop the given span
|
||||
\param span The openzap span
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\param span The freetdm span
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
*/
|
||||
#define BOOST_STOP_SPAN_ARGS (zap_span_t *span)
|
||||
typedef zap_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS;
|
||||
#define BOOST_STOP_SPAN_FUNCTION(name) zap_status_t name BOOST_STOP_SPAN_ARGS
|
||||
#define BOOST_STOP_SPAN_ARGS (ftdm_span_t *span)
|
||||
typedef ftdm_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS;
|
||||
#define BOOST_STOP_SPAN_FUNCTION(name) ftdm_status_t name BOOST_STOP_SPAN_ARGS
|
||||
|
||||
/*!
|
||||
\brief Called when the module is being loaded BEFORE calling anything else
|
||||
\return ZAP_SUCCESS or ZAP_FAIL
|
||||
\return FTDM_SUCCESS or FTDM_FAIL
|
||||
*/
|
||||
#define BOOST_ON_LOAD_ARGS (void)
|
||||
typedef zap_status_t (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS;
|
||||
#define BOOST_ON_LOAD_FUNCTION(name) zap_status_t name BOOST_ON_LOAD_ARGS
|
||||
typedef ftdm_status_t (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS;
|
||||
#define BOOST_ON_LOAD_FUNCTION(name) ftdm_status_t name BOOST_ON_LOAD_ARGS
|
||||
|
||||
/*!
|
||||
\brief Called when the module is being unloaded, last chance to stop everything!
|
||||
*/
|
||||
#define BOOST_ON_UNLOAD_ARGS (void)
|
||||
typedef zap_status_t (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS;
|
||||
#define BOOST_ON_UNLOAD_FUNCTION(name) zap_status_t name BOOST_ON_UNLOAD_ARGS
|
||||
typedef ftdm_status_t (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS;
|
||||
#define BOOST_ON_UNLOAD_FUNCTION(name) ftdm_status_t name BOOST_ON_UNLOAD_ARGS
|
||||
|
||||
/*!
|
||||
\brief The boost signaling module interface
|
||||
@ -204,9 +204,9 @@ typedef struct boost_sigmod_interface_s {
|
||||
boost_on_hw_link_status_change_func_t on_hw_link_status_change;
|
||||
/*! \brief configure span signaling */
|
||||
boost_configure_span_func_t configure_span;
|
||||
/*! \brief start openzap span */
|
||||
/*! \brief start freetdm span */
|
||||
boost_start_span_func_t start_span;
|
||||
/*! \brief stop openzap span */
|
||||
/*! \brief stop freetdm span */
|
||||
boost_stop_span_func_t stop_span;
|
||||
/*! \brief the module was just loaded */
|
||||
boost_on_load_func_t on_load;
|
@ -17,7 +17,7 @@
|
||||
#define SIGBOOST_VERSION 100
|
||||
|
||||
// handy to define integer types that actually work on both Lin and Win
|
||||
#include <openzap.h>
|
||||
#include <freetdm.h>
|
||||
|
||||
enum e_sigboost_event_id_values
|
||||
{
|
||||
@ -30,11 +30,11 @@ enum e_sigboost_event_id_values
|
||||
SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/
|
||||
/* CALL_RELEASED is aimed to fix a race condition that became obvious
|
||||
* when the boost socket was replaced by direct function calls
|
||||
* and the channel hunting was moved to openzap, the problem is
|
||||
* and the channel hunting was moved to freetdm, the problem is
|
||||
* we can get CALL_STOPPED msg and reply with CALL_STOPPED_ACK
|
||||
* but the signaling module will still (in PRI) send RELEASE and
|
||||
* wait for RELEASE_COMPLETE from the isdn network before
|
||||
* marking the channel as available, therefore openzap should
|
||||
* marking the channel as available, therefore freetdm should
|
||||
* also not mark the channel as available until CALL_RELEASED
|
||||
* is received, for socket mode we can continue working as usual
|
||||
* with CALL_STOPPED being the last step because the hunting is
|
@ -32,75 +32,75 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "openzap.h"
|
||||
//#include "zap_skel.h"
|
||||
#include "freetdm.h"
|
||||
//#include "ftdm_skel.h"
|
||||
|
||||
static ZIO_CONFIGURE_FUNCTION(skel_configure)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_OPEN_FUNCTION(skel_open)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_CLOSE_FUNCTION(skel_close)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_WAIT_FUNCTION(skel_wait)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_READ_FUNCTION(skel_read)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_WRITE_FUNCTION(skel_write)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_COMMAND_FUNCTION(skel_command)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_SPAN_POLL_EVENT_FUNCTION(skel_poll_event)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_SPAN_NEXT_EVENT_FUNCTION(skel_next_event)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_SPAN_DESTROY_FUNCTION(skel_span_destroy)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static zap_io_interface_t skel_interface;
|
||||
static ftdm_io_interface_t skel_interface;
|
||||
|
||||
static ZIO_IO_LOAD_FUNCTION(skel_init)
|
||||
{
|
||||
@ -123,16 +123,16 @@ static ZIO_IO_LOAD_FUNCTION(skel_init)
|
||||
skel_interface.get_alarms = skel_get_alarms;
|
||||
*zio = &skel_interface;
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
static ZIO_IO_UNLOAD_FUNCTION(skel_destroy)
|
||||
{
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
zap_module_t zap_module = {
|
||||
ftdm_module_t ftdm_module = {
|
||||
"skel",
|
||||
skel_init,
|
||||
skel_destroy,
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -31,9 +31,9 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ZAP_ZT_H
|
||||
#define ZAP_ZT_H
|
||||
#include "openzap.h"
|
||||
#ifndef FTDM_ZT_H
|
||||
#define FTDM_ZT_H
|
||||
#include "freetdm.h"
|
||||
#include <sys/ioctl.h>
|
||||
#include <poll.h>
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
|
||||
/* Hardware interface structures and defines */
|
||||
/* Based on documentation of the structures required for the hardware interface */
|
||||
/* from http://wiki.freeswitch.org/wiki/Zapata_zaptel_interface */
|
||||
/* from http://wiki.freeswitch.org/wiki/Zapata_ftdmtel_interface */
|
||||
|
||||
/* Structures */
|
||||
|
||||
@ -111,9 +111,9 @@ struct zt_spaninfo {
|
||||
int sync_src; /* Span # of sync source (0 = free run) */
|
||||
int configured_chan_count; /* Count of channels configured on the span */
|
||||
int channel_count; /* Total count of channels on the span */
|
||||
int span_count; /* Total count of zaptel spans on the system*/
|
||||
int span_count; /* Total count of ftdmtel spans on the system*/
|
||||
/* end v1 of the struct */
|
||||
/* as long as we don't use the fields below we should be ok regardless of the zaptel/dahdi version */
|
||||
/* as long as we don't use the fields below we should be ok regardless of the ftdmtel/dahdi version */
|
||||
int lbo; /* Line Build Out */
|
||||
int lineconfig; /* framing/coding */
|
||||
/* end of v2 of the struct */
|
||||
@ -290,7 +290,7 @@ ZT_ABIT = 8
|
||||
#define ZT_HDLCRAWMODE _IOW (ZT_CODE, 36, int) /* Set a clear channel into HDLC w/out FCS checking/calculation mode */
|
||||
#define ZT_HDLCFCSMODE _IOW (ZT_CODE, 37, int) /* Set a clear channel into HDLC w/ FCS mode */
|
||||
|
||||
/* Specify a channel on /dev/zap/chan -- must be done before any other ioctl's and is only valid on /dev/zap/chan */
|
||||
/* Specify a channel on /dev/ftdm/chan -- must be done before any other ioctl's and is only valid on /dev/ftdm/chan */
|
||||
#define ZT_SPECIFY _IOW (ZT_CODE, 38, int)
|
||||
|
||||
/* Temporarily set the law on a channel to ZT_LAW_DEFAULT, ZT_LAW_ALAW, or ZT_LAW_MULAW. Is reset on close. */
|
@ -31,7 +31,7 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include "hashtable.h"
|
||||
#include "hashtable_private.h"
|
||||
#include <stdlib.h>
|
||||
@ -57,7 +57,7 @@ const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
|
||||
const float max_load_factor = 0.65f;
|
||||
|
||||
/*****************************************************************************/
|
||||
OZ_DECLARE(struct hashtable *)
|
||||
FT_DECLARE(struct hashtable *)
|
||||
create_hashtable(unsigned int minsize,
|
||||
unsigned int (*hashf) (void*),
|
||||
int (*eqf) (void*,void*))
|
||||
@ -70,10 +70,10 @@ create_hashtable(unsigned int minsize,
|
||||
for (pindex=0; pindex < prime_table_length; pindex++) {
|
||||
if (primes[pindex] > minsize) { size = primes[pindex]; break; }
|
||||
}
|
||||
h = (struct hashtable *)zap_malloc(sizeof(struct hashtable));
|
||||
h = (struct hashtable *)ftdm_malloc(sizeof(struct hashtable));
|
||||
if (NULL == h) return NULL; /*oom*/
|
||||
h->table = (struct entry **)zap_malloc(sizeof(struct entry*) * size);
|
||||
if (NULL == h->table) { zap_safe_free(h); return NULL; } /*oom*/
|
||||
h->table = (struct entry **)ftdm_malloc(sizeof(struct entry*) * size);
|
||||
if (NULL == h->table) { ftdm_safe_free(h); return NULL; } /*oom*/
|
||||
memset(h->table, 0, size * sizeof(struct entry *));
|
||||
h->tablelength = size;
|
||||
h->primeindex = pindex;
|
||||
@ -111,7 +111,7 @@ hashtable_expand(struct hashtable *h)
|
||||
if (h->primeindex == (prime_table_length - 1)) return 0;
|
||||
newsize = primes[++(h->primeindex)];
|
||||
|
||||
newtable = (struct entry **)zap_malloc(sizeof(struct entry*) * newsize);
|
||||
newtable = (struct entry **)ftdm_malloc(sizeof(struct entry*) * newsize);
|
||||
if (NULL != newtable)
|
||||
{
|
||||
memset(newtable, 0, newsize * sizeof(struct entry *));
|
||||
@ -125,7 +125,7 @@ hashtable_expand(struct hashtable *h)
|
||||
newtable[index] = e;
|
||||
}
|
||||
}
|
||||
zap_safe_free(h->table);
|
||||
ftdm_safe_free(h->table);
|
||||
h->table = newtable;
|
||||
}
|
||||
/* Plan B: realloc instead */
|
||||
@ -158,14 +158,14 @@ hashtable_expand(struct hashtable *h)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
OZ_DECLARE(unsigned int)
|
||||
FT_DECLARE(unsigned int)
|
||||
hashtable_count(struct hashtable *h)
|
||||
{
|
||||
return h->entrycount;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
OZ_DECLARE(int)
|
||||
FT_DECLARE(int)
|
||||
hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags)
|
||||
{
|
||||
/* This method allows duplicate keys - but they shouldn't be used */
|
||||
@ -179,7 +179,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags)
|
||||
* element may be ok. Next time we insert, we'll try expanding again.*/
|
||||
hashtable_expand(h);
|
||||
}
|
||||
e = (struct entry *)zap_malloc(sizeof(struct entry));
|
||||
e = (struct entry *)ftdm_malloc(sizeof(struct entry));
|
||||
if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
|
||||
e->h = hash(h,k);
|
||||
index = indexFor(h->tablelength,e->h);
|
||||
@ -192,7 +192,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
OZ_DECLARE(void *) /* returns value associated with key */
|
||||
FT_DECLARE(void *) /* returns value associated with key */
|
||||
hashtable_search(struct hashtable *h, void *k)
|
||||
{
|
||||
struct entry *e;
|
||||
@ -210,7 +210,7 @@ hashtable_search(struct hashtable *h, void *k)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
OZ_DECLARE(void *) /* returns value associated with key */
|
||||
FT_DECLARE(void *) /* returns value associated with key */
|
||||
hashtable_remove(struct hashtable *h, void *k)
|
||||
{
|
||||
/* TODO: consider compacting the table when the load factor drops enough,
|
||||
@ -236,7 +236,7 @@ hashtable_remove(struct hashtable *h, void *k)
|
||||
if (e->flags & HASHTABLE_FLAG_FREE_KEY) {
|
||||
freekey(e->k);
|
||||
}
|
||||
zap_safe_free(e);
|
||||
ftdm_safe_free(e);
|
||||
return v;
|
||||
}
|
||||
pE = &(e->next);
|
||||
@ -247,7 +247,7 @@ hashtable_remove(struct hashtable *h, void *k)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* destroy */
|
||||
OZ_DECLARE(void)
|
||||
FT_DECLARE(void)
|
||||
hashtable_destroy(struct hashtable *h)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -258,14 +258,14 @@ hashtable_destroy(struct hashtable *h)
|
||||
{
|
||||
e = table[i];
|
||||
while (NULL != e)
|
||||
{ f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) zap_safe_free(f->v); zap_safe_free(f); }
|
||||
{ f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) ftdm_safe_free(f->v); ftdm_safe_free(f); }
|
||||
}
|
||||
|
||||
zap_safe_free(h->table);
|
||||
zap_safe_free(h);
|
||||
ftdm_safe_free(h->table);
|
||||
ftdm_safe_free(h);
|
||||
}
|
||||
|
||||
OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i)
|
||||
FT_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i)
|
||||
{
|
||||
|
||||
if (i->e) {
|
||||
@ -291,7 +291,7 @@ OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OZ_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h)
|
||||
FT_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h)
|
||||
{
|
||||
h->iterator.pos = 0;
|
||||
h->iterator.e = NULL;
|
||||
@ -301,7 +301,7 @@ OZ_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h)
|
||||
|
||||
|
||||
|
||||
OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val)
|
||||
FT_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val)
|
||||
{
|
||||
if (i->e) {
|
||||
if (key) {
|
||||
|
@ -31,7 +31,7 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include "hashtable.h"
|
||||
#include "hashtable_private.h"
|
||||
#include "hashtable_itr.h"
|
||||
@ -44,7 +44,7 @@ struct hashtable_itr *
|
||||
hashtable_iterator(struct hashtable *h)
|
||||
{
|
||||
unsigned int i, tablelength;
|
||||
struct hashtable_itr *itr = zap_malloc(sizeof(struct hashtable_itr));
|
||||
struct hashtable_itr *itr = ftdm_malloc(sizeof(struct hashtable_itr));
|
||||
if (NULL == itr) return NULL;
|
||||
itr->h = h;
|
||||
itr->e = NULL;
|
||||
@ -138,7 +138,7 @@ hashtable_iterator_remove(struct hashtable_itr *itr)
|
||||
remember_parent = itr->parent;
|
||||
ret = hashtable_iterator_advance(itr);
|
||||
if (itr->parent == remember_e) { itr->parent = remember_parent; }
|
||||
zap_safe_free(remember_e);
|
||||
ftdm_safe_free(remember_e);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#endif
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -81,7 +81,7 @@ struct hashtable_iterator;
|
||||
* @return newly created hashtable or NULL on failure
|
||||
*/
|
||||
|
||||
OZ_DECLARE(struct hashtable *)
|
||||
FT_DECLARE(struct hashtable *)
|
||||
create_hashtable(unsigned int minsize,
|
||||
unsigned int (*hashfunction) (void*),
|
||||
int (*key_eq_fn) (void*,void*));
|
||||
@ -112,7 +112,7 @@ typedef enum {
|
||||
HASHTABLE_FLAG_FREE_VALUE = (1 << 1)
|
||||
} hashtable_flag_t;
|
||||
|
||||
OZ_DECLARE(int)
|
||||
FT_DECLARE(int)
|
||||
hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags);
|
||||
|
||||
#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \
|
||||
@ -130,7 +130,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags);
|
||||
* @return the value associated with the key, or NULL if none found
|
||||
*/
|
||||
|
||||
OZ_DECLARE(void *)
|
||||
FT_DECLARE(void *)
|
||||
hashtable_search(struct hashtable *h, void *k);
|
||||
|
||||
#define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \
|
||||
@ -148,7 +148,7 @@ hashtable_search(struct hashtable *h, void *k);
|
||||
* @return the value associated with the key, or NULL if none found
|
||||
*/
|
||||
|
||||
OZ_DECLARE(void *) /* returns value */
|
||||
FT_DECLARE(void *) /* returns value */
|
||||
hashtable_remove(struct hashtable *h, void *k);
|
||||
|
||||
#define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \
|
||||
@ -165,7 +165,7 @@ hashtable_remove(struct hashtable *h, void *k);
|
||||
* @param h the hashtable
|
||||
* @return the number of items stored in the hashtable
|
||||
*/
|
||||
OZ_DECLARE(unsigned int)
|
||||
FT_DECLARE(unsigned int)
|
||||
hashtable_count(struct hashtable *h);
|
||||
|
||||
|
||||
@ -177,12 +177,12 @@ hashtable_count(struct hashtable *h);
|
||||
* @param free_values whether to call 'free' on the remaining values
|
||||
*/
|
||||
|
||||
OZ_DECLARE(void)
|
||||
FT_DECLARE(void)
|
||||
hashtable_destroy(struct hashtable *h);
|
||||
|
||||
OZ_DECLARE(struct hashtable_iterator*) hashtable_first(struct hashtable *h);
|
||||
OZ_DECLARE(struct hashtable_iterator*) hashtable_next(struct hashtable_iterator *i);
|
||||
OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val);
|
||||
FT_DECLARE(struct hashtable_iterator*) hashtable_first(struct hashtable *h);
|
||||
FT_DECLARE(struct hashtable_iterator*) hashtable_next(struct hashtable_iterator *i);
|
||||
FT_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern C */
|
||||
|
@ -4,10 +4,10 @@
|
||||
*
|
||||
* Version: MPL 1.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* The contents of this file are subject to the Mftilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
* http://www.mftilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
@ -33,8 +33,8 @@
|
||||
* Exception:
|
||||
* The author hereby grants the use of this source code under the
|
||||
* following license if and only if the source code is distributed
|
||||
* as part of the openzap library. Any use or distribution of this
|
||||
* source code outside the scope of the openzap library will nullify the
|
||||
* as part of the freetdm library. Any use or distribution of this
|
||||
* source code outside the scope of the freetdm library will nullify the
|
||||
* following license and reinact the MPL 1.1 as stated above.
|
||||
*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
|
@ -7,8 +7,8 @@
|
||||
* Exception:
|
||||
* The author hereby grants the use of this source code under the
|
||||
* following license if and only if the source code is distributed
|
||||
* as part of the openzap library. Any use or distribution of this
|
||||
* source code outside the scope of the openzap library will nullify the
|
||||
* as part of the freetdm library. Any use or distribution of this
|
||||
* source code outside the scope of the freetdm library will nullify the
|
||||
* following license and reinact the MPL 1.1 as stated above.
|
||||
*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
|
@ -1,932 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Contributors:
|
||||
*
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef OPENZAP_H
|
||||
#define OPENZAP_H
|
||||
|
||||
|
||||
#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__)
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRINGS_H
|
||||
#define HAVE_STRINGS_H 1
|
||||
#endif
|
||||
#ifndef HAVE_SYS_SOCKET_H
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
#endif
|
||||
|
||||
#ifndef __WINDOWS__
|
||||
#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if defined(OZ_DECLARE_STATIC)
|
||||
#define OZ_DECLARE(type) type __stdcall
|
||||
#define OZ_DECLARE_NONSTD(type) type __cdecl
|
||||
#define OZ_DECLARE_DATA
|
||||
#elif defined(OPENZAP_EXPORTS)
|
||||
#define OZ_DECLARE(type) __declspec(dllexport) type __stdcall
|
||||
#define OZ_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
|
||||
#define OZ_DECLARE_DATA __declspec(dllexport)
|
||||
#else
|
||||
#define OZ_DECLARE(type) __declspec(dllimport) type __stdcall
|
||||
#define OZ_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl
|
||||
#define OZ_DECLARE_DATA __declspec(dllimport)
|
||||
#endif
|
||||
#define EX_DECLARE_DATA __declspec(dllexport)
|
||||
#else
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY)
|
||||
#define OZ_DECLARE(type) __attribute__((visibility("default"))) type
|
||||
#define OZ_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type
|
||||
#define OZ_DECLARE_DATA __attribute__((visibility("default")))
|
||||
#else
|
||||
#define OZ_DECLARE(type) type
|
||||
#define OZ_DECLARE_NONSTD(type) type
|
||||
#define OZ_DECLARE_DATA
|
||||
#endif
|
||||
#define EX_DECLARE_DATA
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#if (_MSC_VER >= 1400) /* VC8+ */
|
||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
#endif
|
||||
#endif
|
||||
#ifndef strcasecmp
|
||||
#define strcasecmp(s1, s2) _stricmp(s1, s2)
|
||||
#endif
|
||||
#ifndef strncasecmp
|
||||
#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
|
||||
#endif
|
||||
#ifndef snprintf
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#ifndef S_IRUSR
|
||||
#define S_IRUSR _S_IREAD
|
||||
#endif
|
||||
#ifndef S_IWUSR
|
||||
#define S_IWUSR _S_IWRITE
|
||||
#endif
|
||||
#undef HAVE_STRINGS_H
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
/* disable warning for zero length array in a struct */
|
||||
/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */
|
||||
#pragma warning(disable:4706)
|
||||
#pragma comment(lib, "Winmm")
|
||||
#endif
|
||||
|
||||
#define ZAP_THREAD_STACKSIZE 240 * 1024
|
||||
#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL };
|
||||
#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) OZ_DECLARE(_TYPE) _FUNC1 (const char *name); OZ_DECLARE(const char *) _FUNC2 (_TYPE type);
|
||||
#define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \
|
||||
OZ_DECLARE(_TYPE) _FUNC1 (const char *name) \
|
||||
{ \
|
||||
int i; \
|
||||
_TYPE t = _MAX ; \
|
||||
\
|
||||
for (i = 0; i < _MAX ; i++) { \
|
||||
if (!strcasecmp(name, _STRINGS[i])) { \
|
||||
t = (_TYPE) i; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return t; \
|
||||
} \
|
||||
OZ_DECLARE(const char *) _FUNC2 (_TYPE type) \
|
||||
{ \
|
||||
if (type > _MAX) { \
|
||||
type = _MAX; \
|
||||
} \
|
||||
return _STRINGS[(int)type]; \
|
||||
} \
|
||||
|
||||
#define zap_true(expr) \
|
||||
(expr && ( !strcasecmp(expr, "yes") || \
|
||||
!strcasecmp(expr, "on") || \
|
||||
!strcasecmp(expr, "true") || \
|
||||
!strcasecmp(expr, "enabled") || \
|
||||
!strcasecmp(expr, "active") || \
|
||||
atoi(expr))) ? 1 : 0
|
||||
|
||||
|
||||
#include <time.h>
|
||||
#ifndef __WINDOWS__
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include "zap_types.h"
|
||||
#include "hashtable.h"
|
||||
#include "zap_config.h"
|
||||
#include "g711.h"
|
||||
#include "libteletone.h"
|
||||
#include "zap_buffer.h"
|
||||
#include "zap_threadmutex.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#define zap_sleep(x) Sleep(x)
|
||||
#else
|
||||
#define zap_sleep(x) usleep(x * 1000)
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#undef assert
|
||||
#define assert(_Expression) ((void)(_Expression))
|
||||
#endif
|
||||
|
||||
#define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32
|
||||
#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 32
|
||||
#define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN
|
||||
#define ZAP_MAX_SPANS_INTERFACE 128
|
||||
|
||||
#define ZAP_MAX_CHANNELS_GROUP 1024
|
||||
#define ZAP_MAX_GROUPS_INTERFACE ZAP_MAX_SPANS_INTERFACE
|
||||
|
||||
#define GOTO_STATUS(label,st) status = st; goto label ;
|
||||
|
||||
#define zap_copy_string(x,y,z) strncpy(x, y, z - 1)
|
||||
#define zap_set_string(x,y) strncpy(x, y, sizeof(x)-1)
|
||||
#define zap_strlen_zero(s) (!s || *s == '\0')
|
||||
#define zap_strlen_zero_buf(s) (*s == '\0')
|
||||
|
||||
|
||||
#define zap_channel_test_feature(obj, flag) ((obj)->features & flag)
|
||||
#define zap_channel_set_feature(obj, flag) (obj)->features |= (flag)
|
||||
#define zap_channel_clear_feature(obj, flag) (obj)->features &= ~(flag)
|
||||
#define zap_channel_set_member_locked(obj, _m, _v) zap_mutex_lock(obj->mutex); obj->_m = _v; zap_mutex_unlock(obj->mutex)
|
||||
|
||||
/*!
|
||||
\brief Test for the existance of a flag on an arbitary object
|
||||
\command obj the object to test
|
||||
\command flag the or'd list of flags to test
|
||||
\return true value if the object has the flags defined
|
||||
*/
|
||||
#define zap_test_flag(obj, flag) ((obj)->flags & flag)
|
||||
#define zap_test_pflag(obj, flag) ((obj)->pflags & flag)
|
||||
#define zap_test_sflag(obj, flag) ((obj)->sflags & flag)
|
||||
|
||||
|
||||
#define zap_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag)
|
||||
#define zap_clear_alarm_flag(obj, flag) (obj)->alarm_flags &= ~(flag)
|
||||
#define zap_test_alarm_flag(obj, flag) ((obj)->alarm_flags & flag)
|
||||
|
||||
/*!
|
||||
\brief Set a flag on an arbitrary object
|
||||
\command obj the object to set the flags on
|
||||
\command flag the or'd list of flags to set
|
||||
*/
|
||||
#define zap_set_flag(obj, flag) (obj)->flags |= (flag)
|
||||
#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \
|
||||
zap_mutex_lock(obj->mutex); \
|
||||
(obj)->flags |= (flag); \
|
||||
zap_mutex_unlock(obj->mutex);
|
||||
|
||||
#define zap_set_pflag(obj, flag) (obj)->pflags |= (flag)
|
||||
#define zap_set_pflag_locked(obj, flag) assert(obj->mutex != NULL); \
|
||||
zap_mutex_lock(obj->mutex); \
|
||||
(obj)->pflags |= (flag); \
|
||||
zap_mutex_unlock(obj->mutex);
|
||||
|
||||
#define zap_set_sflag(obj, flag) (obj)->sflags |= (flag)
|
||||
#define zap_set_sflag_locked(obj, flag) assert(obj->mutex != NULL); \
|
||||
zap_mutex_lock(obj->mutex); \
|
||||
(obj)->sflags |= (flag); \
|
||||
zap_mutex_unlock(obj->mutex);
|
||||
|
||||
/*!
|
||||
\brief Clear a flag on an arbitrary object while locked
|
||||
\command obj the object to test
|
||||
\command flag the or'd list of flags to clear
|
||||
*/
|
||||
#define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag)
|
||||
|
||||
#define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex);
|
||||
|
||||
#define zap_clear_pflag(obj, flag) (obj)->pflags &= ~(flag)
|
||||
|
||||
#define zap_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); zap_mutex_unlock(obj->mutex);
|
||||
|
||||
#define zap_clear_sflag(obj, flag) (obj)->sflags &= ~(flag)
|
||||
|
||||
#define zap_clear_sflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->sflags &= ~(flag); zap_mutex_unlock(obj->mutex);
|
||||
|
||||
|
||||
#define zap_set_state_locked(obj, s) if ( obj->state == s ) { \
|
||||
zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \
|
||||
} else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \
|
||||
zap_channel_state_t st = obj->state; \
|
||||
zap_channel_set_state(obj, s, 1); \
|
||||
if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \
|
||||
else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* The while(0) below throws a conditional expression is constant warning */
|
||||
#pragma warning(disable:4127)
|
||||
#endif
|
||||
|
||||
#define zap_set_state_locked_wait(obj, s) \
|
||||
do { \
|
||||
int __safety = 100; \
|
||||
zap_set_state_locked(obj, s); \
|
||||
while(__safety-- && zap_test_flag(obj, ZAP_CHANNEL_STATE_CHANGE)) { \
|
||||
zap_sleep(10); \
|
||||
} \
|
||||
if(!__safety) { \
|
||||
zap_log(ZAP_LOG_CRIT, "State change not completed\n"); \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#define zap_wait_for_flag_cleared(obj, flag, time) \
|
||||
do { \
|
||||
int __safety = time; \
|
||||
while(__safety-- && zap_test_flag(obj, flag)) { \
|
||||
zap_mutex_unlock(obj->mutex); \
|
||||
zap_sleep(10); \
|
||||
zap_mutex_lock(obj->mutex); \
|
||||
} \
|
||||
if(!__safety) { \
|
||||
zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#define zap_set_state_wait(obj, s) \
|
||||
do { \
|
||||
zap_channel_set_state(obj, s, 0); \
|
||||
zap_wait_for_flag_cleared(obj, ZAP_CHANNEL_STATE_CHANGE, 100); \
|
||||
} while(0);
|
||||
|
||||
|
||||
typedef enum {
|
||||
ZAP_STATE_CHANGE_FAIL,
|
||||
ZAP_STATE_CHANGE_SUCCESS,
|
||||
ZAP_STATE_CHANGE_SAME,
|
||||
} zap_state_change_result_t;
|
||||
|
||||
#define zap_set_state_r(obj, s, l, r) if ( obj->state == s ) { \
|
||||
zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \
|
||||
} else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \
|
||||
int st = obj->state; \
|
||||
r = (zap_channel_set_state(obj, s, l) == ZAP_SUCCESS) ? ZAP_STATE_CHANGE_SUCCESS : ZAP_STATE_CHANGE_FAIL; \
|
||||
if (obj->state == s) {zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s));} \
|
||||
else {zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); } \
|
||||
}
|
||||
|
||||
|
||||
#define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119)
|
||||
|
||||
/*!
|
||||
\brief Copy flags from one arbitrary object to another
|
||||
\command dest the object to copy the flags to
|
||||
\command src the object to copy the flags from
|
||||
\command flags the flags to copy
|
||||
*/
|
||||
#define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags))
|
||||
|
||||
struct zap_stream_handle {
|
||||
zap_stream_handle_write_function_t write_function;
|
||||
zap_stream_handle_raw_write_function_t raw_write_function;
|
||||
void *data;
|
||||
void *end;
|
||||
zap_size_t data_size;
|
||||
zap_size_t data_len;
|
||||
zap_size_t alloc_len;
|
||||
zap_size_t alloc_chunk;
|
||||
};
|
||||
|
||||
|
||||
OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen);
|
||||
OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...);
|
||||
|
||||
#define ZAP_CMD_CHUNK_LEN 1024
|
||||
#define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \
|
||||
assert(s.data); \
|
||||
memset(s.data, 0, ZAP_CMD_CHUNK_LEN); \
|
||||
s.end = s.data; \
|
||||
s.data_size = ZAP_CMD_CHUNK_LEN; \
|
||||
s.write_function = zap_console_stream_write; \
|
||||
s.raw_write_function = zap_console_stream_raw_write; \
|
||||
s.alloc_len = ZAP_CMD_CHUNK_LEN; \
|
||||
s.alloc_chunk = ZAP_CMD_CHUNK_LEN
|
||||
|
||||
struct zap_event {
|
||||
zap_event_type_t e_type;
|
||||
uint32_t enum_id;
|
||||
zap_channel_t *channel;
|
||||
void *data;
|
||||
};
|
||||
|
||||
#define ZAP_TOKEN_STRLEN 128
|
||||
#define ZAP_MAX_TOKENS 10
|
||||
|
||||
static __inline__ char *zap_clean_string(char *s)
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = s; p && *p; p++) {
|
||||
uint8_t x = (uint8_t) *p;
|
||||
if (x < 32 || x > 127) {
|
||||
*p = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
struct zap_bitstream {
|
||||
uint8_t *data;
|
||||
uint32_t datalen;
|
||||
uint32_t byte_index;
|
||||
uint8_t bit_index;
|
||||
int8_t endian;
|
||||
uint8_t top;
|
||||
uint8_t bot;
|
||||
uint8_t ss;
|
||||
uint8_t ssv;
|
||||
};
|
||||
|
||||
struct zap_fsk_data_state {
|
||||
dsp_fsk_handle_t *fsk1200_handle;
|
||||
uint8_t init;
|
||||
uint8_t *buf;
|
||||
size_t bufsize;
|
||||
zap_size_t blen;
|
||||
zap_size_t bpos;
|
||||
zap_size_t dlen;
|
||||
zap_size_t ppos;
|
||||
int checksum;
|
||||
};
|
||||
|
||||
struct zap_fsk_modulator {
|
||||
teletone_dds_state_t dds;
|
||||
zap_bitstream_t bs;
|
||||
uint32_t carrier_bits_start;
|
||||
uint32_t carrier_bits_stop;
|
||||
uint32_t chan_sieze_bits;
|
||||
uint32_t bit_factor;
|
||||
uint32_t bit_accum;
|
||||
uint32_t sample_counter;
|
||||
int32_t samples_per_bit;
|
||||
int32_t est_bytes;
|
||||
fsk_modem_types_t modem_type;
|
||||
zap_fsk_data_state_t *fsk_data;
|
||||
zap_fsk_write_sample_t write_sample_callback;
|
||||
void *user_data;
|
||||
int16_t sample_buffer[64];
|
||||
};
|
||||
|
||||
/**
|
||||
* Type Of Number (TON)
|
||||
*/
|
||||
typedef enum {
|
||||
ZAP_TON_UNKNOWN = 0,
|
||||
ZAP_TON_INTERNATIONAL,
|
||||
ZAP_TON_NATIONAL,
|
||||
ZAP_TON_NETWORK_SPECIFIC,
|
||||
ZAP_TON_SUBSCRIBER_NUMBER,
|
||||
ZAP_TON_ABBREVIATED_NUMBER,
|
||||
ZAP_TON_RESERVED
|
||||
} zap_ton_t;
|
||||
|
||||
typedef struct {
|
||||
char digits[25];
|
||||
uint8_t type;
|
||||
uint8_t plan;
|
||||
} zap_number_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CALLER_STATE_DIALING,
|
||||
ZAP_CALLER_STATE_SUCCESS,
|
||||
ZAP_CALLER_STATE_FAIL
|
||||
} zap_caller_state_t;
|
||||
|
||||
struct zap_caller_data {
|
||||
char cid_date[8];
|
||||
char cid_name[80];
|
||||
zap_number_t cid_num;
|
||||
zap_number_t ani;
|
||||
zap_number_t dnis;
|
||||
zap_number_t rdnis;
|
||||
char aniII[25];
|
||||
uint8_t screen;
|
||||
uint8_t pres;
|
||||
char collected[25];
|
||||
int CRV;
|
||||
int hangup_cause;
|
||||
uint8_t raw_data[1024];
|
||||
uint32_t raw_data_len;
|
||||
uint32_t flags;
|
||||
zap_caller_state_t call_state;
|
||||
uint32_t chan_id;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ZAP_TYPE_NONE,
|
||||
ZAP_TYPE_SPAN = 0xFF,
|
||||
ZAP_TYPE_CHANNEL
|
||||
} zap_data_type_t;
|
||||
|
||||
/* 2^8 table size, one for each byte value */
|
||||
#define ZAP_GAINS_TABLE_SIZE 256
|
||||
struct zap_channel {
|
||||
zap_data_type_t data_type;
|
||||
uint32_t span_id;
|
||||
uint32_t chan_id;
|
||||
uint32_t physical_span_id;
|
||||
uint32_t physical_chan_id;
|
||||
uint32_t rate;
|
||||
uint32_t extra_id;
|
||||
zap_chan_type_t type;
|
||||
zap_socket_t sockfd;
|
||||
zap_channel_flag_t flags;
|
||||
uint32_t pflags;
|
||||
uint32_t sflags;
|
||||
zap_alarm_flag_t alarm_flags;
|
||||
zap_channel_feature_t features;
|
||||
zap_codec_t effective_codec;
|
||||
zap_codec_t native_codec;
|
||||
uint32_t effective_interval;
|
||||
uint32_t native_interval;
|
||||
uint32_t packet_len;
|
||||
zap_channel_state_t state;
|
||||
zap_channel_state_t last_state;
|
||||
zap_channel_state_t init_state;
|
||||
zap_mutex_t *mutex;
|
||||
teletone_dtmf_detect_state_t dtmf_detect;
|
||||
uint32_t buffer_delay;
|
||||
zap_event_t event_header;
|
||||
char last_error[256];
|
||||
zio_event_cb_t event_callback;
|
||||
uint32_t skip_read_frames;
|
||||
zap_buffer_t *dtmf_buffer;
|
||||
zap_buffer_t *gen_dtmf_buffer;
|
||||
zap_buffer_t *pre_buffer;
|
||||
zap_buffer_t *digit_buffer;
|
||||
zap_buffer_t *fsk_buffer;
|
||||
zap_mutex_t *pre_buffer_mutex;
|
||||
uint32_t dtmf_on;
|
||||
uint32_t dtmf_off;
|
||||
char *dtmf_hangup_buf;
|
||||
teletone_generation_session_t tone_session;
|
||||
zap_time_t last_event_time;
|
||||
zap_time_t ring_time;
|
||||
char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN];
|
||||
uint8_t needed_tones[ZAP_TONEMAP_INVALID];
|
||||
uint8_t detected_tones[ZAP_TONEMAP_INVALID];
|
||||
zap_tonemap_t last_detected_tone;
|
||||
uint32_t token_count;
|
||||
char chan_name[128];
|
||||
char chan_number[32];
|
||||
zap_filehandle_t fds[2];
|
||||
zap_fsk_data_state_t fsk;
|
||||
uint8_t fsk_buf[80];
|
||||
uint32_t ring_count;
|
||||
void *mod_data;
|
||||
void *call_data;
|
||||
struct zap_caller_data caller_data;
|
||||
struct zap_span *span;
|
||||
struct zap_io_interface *zio;
|
||||
zap_hash_t *variable_hash;
|
||||
unsigned char rx_cas_bits;
|
||||
uint32_t pre_buffer_size;
|
||||
unsigned char rxgain_table[ZAP_GAINS_TABLE_SIZE];
|
||||
unsigned char txgain_table[ZAP_GAINS_TABLE_SIZE];
|
||||
float rxgain;
|
||||
float txgain;
|
||||
};
|
||||
|
||||
|
||||
struct zap_sigmsg {
|
||||
zap_signal_event_t event_id;
|
||||
uint32_t chan_id;
|
||||
uint32_t span_id;
|
||||
zap_channel_t *channel;
|
||||
void *raw_data;
|
||||
uint32_t raw_data_len;
|
||||
};
|
||||
|
||||
|
||||
struct zap_span {
|
||||
zap_data_type_t data_type;
|
||||
char *name;
|
||||
uint32_t span_id;
|
||||
uint32_t chan_count;
|
||||
zap_span_flag_t flags;
|
||||
struct zap_io_interface *zio;
|
||||
zio_event_cb_t event_callback;
|
||||
zap_mutex_t *mutex;
|
||||
zap_trunk_type_t trunk_type;
|
||||
zap_analog_start_type_t start_type;
|
||||
zap_signal_type_t signal_type;
|
||||
void *signal_data;
|
||||
zap_event_t event_header;
|
||||
char last_error[256];
|
||||
char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN];
|
||||
teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1];
|
||||
teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1];
|
||||
zap_channel_t *channels[ZAP_MAX_CHANNELS_SPAN+1];
|
||||
zio_channel_outgoing_call_t outgoing_call;
|
||||
zio_channel_set_sig_status_t set_channel_sig_status;
|
||||
zio_channel_get_sig_status_t get_channel_sig_status;
|
||||
zio_span_set_sig_status_t set_span_sig_status;
|
||||
zio_span_get_sig_status_t get_span_sig_status;
|
||||
zio_channel_request_t channel_request;
|
||||
zap_span_start_t start;
|
||||
zap_span_stop_t stop;
|
||||
void *mod_data;
|
||||
char *type;
|
||||
char *dtmf_hangup;
|
||||
size_t dtmf_hangup_len;
|
||||
int suggest_chan_id;
|
||||
zap_state_map_t *state_map;
|
||||
struct zap_span *next;
|
||||
};
|
||||
|
||||
struct zap_group {
|
||||
char *name;
|
||||
uint32_t group_id;
|
||||
uint32_t chan_count;
|
||||
zap_channel_t *channels[ZAP_MAX_CHANNELS_GROUP];
|
||||
uint32_t last_used_index;
|
||||
zap_mutex_t *mutex;
|
||||
struct zap_group *next;
|
||||
};
|
||||
|
||||
OZ_DECLARE_DATA extern zap_logger_t zap_log;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CRASH_NEVER = 0,
|
||||
ZAP_CRASH_ON_ASSERT
|
||||
} zap_crash_policy_t;
|
||||
|
||||
OZ_DECLARE_DATA extern zap_crash_policy_t g_zap_crash_policy;
|
||||
|
||||
typedef void *(*zap_malloc_func_t)(void *pool, zap_size_t len);
|
||||
typedef void *(*zap_calloc_func_t)(void *pool, zap_size_t elements, zap_size_t len);
|
||||
typedef void (*zap_free_func_t)(void *pool, void *ptr);
|
||||
typedef struct zap_memory_handler {
|
||||
void *pool;
|
||||
zap_malloc_func_t malloc;
|
||||
zap_calloc_func_t calloc;
|
||||
zap_free_func_t free;
|
||||
} zap_memory_handler_t;
|
||||
|
||||
OZ_DECLARE_DATA extern zap_memory_handler_t g_zap_mem_handler;
|
||||
|
||||
struct zap_io_interface {
|
||||
const char *name;
|
||||
zio_configure_span_t configure_span;
|
||||
zio_configure_t configure;
|
||||
zio_open_t open;
|
||||
zio_close_t close;
|
||||
zio_channel_destroy_t channel_destroy;
|
||||
zio_span_destroy_t span_destroy;
|
||||
zio_get_alarms_t get_alarms;
|
||||
zio_command_t command;
|
||||
zio_wait_t wait;
|
||||
zio_read_t read;
|
||||
zio_write_t write;
|
||||
zio_span_poll_event_t poll_event;
|
||||
zio_span_next_event_t next_event;
|
||||
zio_api_t api;
|
||||
};
|
||||
|
||||
typedef struct zap_queue zap_queue_t;
|
||||
typedef zap_status_t (*zap_queue_create_func_t)(zap_queue_t **queue, zap_size_t capacity);
|
||||
typedef zap_status_t (*zap_queue_enqueue_func_t)(zap_queue_t *queue, void *obj);
|
||||
typedef void *(*zap_queue_dequeue_func_t)(zap_queue_t *queue);
|
||||
typedef zap_status_t (*zap_queue_wait_func_t)(zap_queue_t *queue, int ms);
|
||||
typedef zap_status_t (*zap_queue_destroy_func_t)(zap_queue_t **queue);
|
||||
typedef struct zap_queue_handler {
|
||||
zap_queue_create_func_t create;
|
||||
zap_queue_enqueue_func_t enqueue;
|
||||
zap_queue_dequeue_func_t dequeue;
|
||||
zap_queue_wait_func_t wait;
|
||||
zap_queue_destroy_func_t destroy;
|
||||
} zap_queue_handler_t;
|
||||
OZ_DECLARE_DATA extern zap_queue_handler_t g_zap_queue_handler;
|
||||
|
||||
/*! brief create a new queue */
|
||||
#define zap_queue_create(queue, capacity) g_zap_queue_handler.create(queue, capacity)
|
||||
|
||||
/*! Enqueue an object */
|
||||
#define zap_queue_enqueue(queue, obj) g_zap_queue_handler.enqueue(queue, obj)
|
||||
|
||||
/*! dequeue an object from the queue */
|
||||
#define zap_queue_dequeue(queue) g_zap_queue_handler.dequeue(queue)
|
||||
|
||||
/*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */
|
||||
#define zap_queue_wait(queue, ms) g_zap_queue_handler.wait(queue, ms)
|
||||
|
||||
/*! destroy the queue */
|
||||
#define zap_queue_destroy(queue) g_zap_queue_handler.destroy(queue)
|
||||
|
||||
/*! \brief Override the default queue handler */
|
||||
OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handler);
|
||||
|
||||
/*! \brief Duplicate string */
|
||||
OZ_DECLARE(char *) zap_strdup(const char *str);
|
||||
OZ_DECLARE(char *) zap_strndup(const char *str, zap_size_t inlen);
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen);
|
||||
OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits);
|
||||
OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans);
|
||||
OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans);
|
||||
#define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \
|
||||
zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \
|
||||
zap_fsk_modulator_send_data(_it); \
|
||||
zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop)
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans,
|
||||
fsk_modem_types_t modem_type,
|
||||
uint32_t sample_rate,
|
||||
zap_fsk_data_state_t *fsk_data,
|
||||
float db_level,
|
||||
uint32_t carrier_bits_start,
|
||||
uint32_t carrier_bits_stop,
|
||||
uint32_t chan_sieze_bits,
|
||||
zap_fsk_write_sample_t write_sample_callback,
|
||||
void *user_data);
|
||||
OZ_DECLARE(int8_t) zap_bitstream_get_bit(zap_bitstream_t *bsp);
|
||||
OZ_DECLARE(void) zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss);
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len);
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples);
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_demod_destroy(zap_fsk_data_state_t *state);
|
||||
OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize);
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen);
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen);
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state);
|
||||
OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_set_sig_status(zap_channel_t *zchan, zap_signaling_status_t status);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_signaling_status_t *status);
|
||||
OZ_DECLARE(zap_status_t) zap_span_set_sig_status(zap_span_t *span, zap_signaling_status_t status);
|
||||
OZ_DECLARE(zap_status_t) zap_span_get_sig_status(zap_span_t *span, zap_signaling_status_t *status);
|
||||
OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan);
|
||||
OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan);
|
||||
OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token);
|
||||
OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock);
|
||||
OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname);
|
||||
OZ_DECLARE(zap_size_t) zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf);
|
||||
OZ_DECLARE(void) zap_channel_flush_dtmf(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void);
|
||||
OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms);
|
||||
OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event);
|
||||
OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span);
|
||||
OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span, const char *name);
|
||||
OZ_DECLARE(zap_status_t) zap_span_close_all(void);
|
||||
OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan);
|
||||
OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_add_to_group(const char* name, zap_channel_t* zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* span, const char* val);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_remove_from_group(zap_group_t* group, zap_channel_t* zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group);
|
||||
OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group);
|
||||
OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count);
|
||||
OZ_DECLARE(zap_status_t) zap_group_channel_use_count(zap_group_t *group, uint32_t *count);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_open_by_span(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_open_by_group(uint32_t group_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen);
|
||||
OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value);
|
||||
OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_global_init(void);
|
||||
OZ_DECLARE(zap_status_t) zap_global_configuration(void);
|
||||
OZ_DECLARE(zap_status_t) zap_global_destroy(void);
|
||||
OZ_DECLARE(zap_status_t) zap_global_set_memory_handler(zap_memory_handler_t *handler);
|
||||
OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy);
|
||||
OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger);
|
||||
OZ_DECLARE(void) zap_global_set_default_logger(int level);
|
||||
OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen);
|
||||
OZ_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss);
|
||||
OZ_DECLARE(void) print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen);
|
||||
OZ_DECLARE_NONSTD(int) zap_hash_equalkeys(void *k1, void *k2);
|
||||
OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky);
|
||||
OZ_DECLARE(uint32_t) zap_running(void);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_complete_state(zap_channel_t *zchan);
|
||||
OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan);
|
||||
OZ_DECLARE(int) zap_load_modules(void);
|
||||
OZ_DECLARE(zap_status_t) zap_unload_modules(void);
|
||||
OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...);
|
||||
OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *parameters);
|
||||
OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span);
|
||||
OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span);
|
||||
OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t len);
|
||||
OZ_DECLARE(zap_status_t) zap_global_add_io_interface(zap_io_interface_t *io_interface);
|
||||
OZ_DECLARE(int) zap_load_module(const char *name);
|
||||
OZ_DECLARE(int) zap_load_module_assume(const char *name);
|
||||
OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span);
|
||||
OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd);
|
||||
OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap);
|
||||
|
||||
ZIO_CODEC_FUNCTION(zio_slin2ulaw);
|
||||
ZIO_CODEC_FUNCTION(zio_ulaw2slin);
|
||||
ZIO_CODEC_FUNCTION(zio_slin2alaw);
|
||||
ZIO_CODEC_FUNCTION(zio_alaw2slin);
|
||||
ZIO_CODEC_FUNCTION(zio_ulaw2alaw);
|
||||
ZIO_CODEC_FUNCTION(zio_alaw2ulaw);
|
||||
|
||||
#ifdef DEBUG_LOCKS
|
||||
#define zap_mutex_lock(_x) printf("++++++lock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_lock(_x)
|
||||
#define zap_mutex_trylock(_x) printf("++++++try %s:%d\n", __FILE__, __LINE__) && _zap_mutex_trylock(_x)
|
||||
#define zap_mutex_unlock(_x) printf("------unlock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_unlock(_x)
|
||||
#else
|
||||
#define zap_mutex_lock(_x) _zap_mutex_lock(_x)
|
||||
#define zap_mutex_trylock(_x) _zap_mutex_trylock(_x)
|
||||
#define zap_mutex_unlock(_x) _zap_mutex_unlock(_x)
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Assert condition
|
||||
*/
|
||||
#define zap_assert(assertion, msg) \
|
||||
if (!(assertion)) { \
|
||||
zap_log(ZAP_LOG_CRIT, msg); \
|
||||
if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \
|
||||
zap_abort(); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Assert condition and return
|
||||
*/
|
||||
#define zap_assert_return(assertion, retval, msg) \
|
||||
if (!(assertion)) { \
|
||||
zap_log(ZAP_LOG_CRIT, msg); \
|
||||
if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \
|
||||
zap_abort(); \
|
||||
} else { \
|
||||
return retval; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Allocate uninitialized memory
|
||||
\command chunksize the chunk size
|
||||
*/
|
||||
#define zap_malloc(chunksize) g_zap_mem_handler.malloc(g_zap_mem_handler.pool, chunksize)
|
||||
|
||||
/*!
|
||||
\brief Allocate initialized memory
|
||||
\command chunksize the chunk size
|
||||
*/
|
||||
#define zap_calloc(elements, chunksize) g_zap_mem_handler.calloc(g_zap_mem_handler.pool, elements, chunksize)
|
||||
|
||||
/*!
|
||||
\brief Free chunk of memory
|
||||
\command chunksize the chunk size
|
||||
*/
|
||||
#define zap_free(chunk) g_zap_mem_handler.free(g_zap_mem_handler.pool, chunk)
|
||||
|
||||
/*!
|
||||
\brief Free a pointer and set it to NULL unless it already is NULL
|
||||
\command it the pointer
|
||||
*/
|
||||
#define zap_safe_free(it) if (it) { zap_free(it); it = NULL; }
|
||||
|
||||
/*!
|
||||
\brief Socket the given socket
|
||||
\command it the socket
|
||||
*/
|
||||
#define zap_socket_close(it) if (it > -1) { close(it); it = -1;}
|
||||
|
||||
static __inline__ void zap_abort(void)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
::abort();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t state)
|
||||
{
|
||||
uint32_t j;
|
||||
zap_mutex_lock(span->mutex);
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
zap_set_state_locked((span->channels[j]), state);
|
||||
}
|
||||
zap_mutex_unlock(span->mutex);
|
||||
}
|
||||
|
||||
static __inline__ int zap_check_state_all(zap_span_t *span, zap_channel_state_t state)
|
||||
{
|
||||
uint32_t j;
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
if (span->channels[j]->state != state || zap_test_flag(span->channels[j], ZAP_CHANNEL_STATE_CHANGE)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag)
|
||||
{
|
||||
uint32_t j;
|
||||
zap_mutex_lock(span->mutex);
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
zap_set_flag_locked((span->channels[j]), flag);
|
||||
}
|
||||
zap_mutex_unlock(span->mutex);
|
||||
}
|
||||
|
||||
static __inline__ void zap_clear_flag_all(zap_span_t *span, uint32_t flag)
|
||||
{
|
||||
uint32_t j;
|
||||
zap_mutex_lock(span->mutex);
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
zap_clear_flag_locked((span->channels[j]), flag);
|
||||
}
|
||||
zap_mutex_unlock(span->mutex);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern C */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ZAP_BUFFER_H
|
||||
#define ZAP_BUFFER_H
|
||||
|
||||
#include "openzap.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup zap_buffer Buffer Routines
|
||||
* @ingroup buffer
|
||||
* The purpose of this module is to make a plain buffering interface that can be used for read/write buffers
|
||||
* throughout the application.
|
||||
* @{
|
||||
*/
|
||||
struct zap_buffer;
|
||||
typedef struct zap_buffer zap_buffer_t;
|
||||
|
||||
/*! \brief Allocate a new dynamic zap_buffer
|
||||
* \param buffer returned pointer to the new buffer
|
||||
* \param blocksize length to realloc by as data is added
|
||||
* \param start_len ammount of memory to reserve initially
|
||||
* \param max_len length the buffer is allowed to grow to
|
||||
* \return status
|
||||
*/
|
||||
OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len);
|
||||
|
||||
/*! \brief Get the length of a zap_buffer_t
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \return int size of the buffer.
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer);
|
||||
|
||||
/*! \brief Get the freespace of a zap_buffer_t
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \return int freespace in the buffer.
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer);
|
||||
|
||||
/*! \brief Get the in use amount of a zap_buffer_t
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \return int ammount of buffer curently in use
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer);
|
||||
|
||||
/*! \brief Read data from a zap_buffer_t up to the ammount of datalen if it is available. Remove read data from buffer.
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \param data pointer to the read data to be returned
|
||||
* \param datalen amount of data to be returned
|
||||
* \return int ammount of data actually read
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen);
|
||||
|
||||
/*! \brief Read data endlessly from a zap_buffer_t
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \param data pointer to the read data to be returned
|
||||
* \param datalen amount of data to be returned
|
||||
* \return int ammount of data actually read
|
||||
* \note Once you have read all the data from the buffer it will loop around.
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen);
|
||||
|
||||
/*! \brief Assign a number of loops to read
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \param loops the number of loops (-1 for infinite)
|
||||
*/
|
||||
OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int32_t loops);
|
||||
|
||||
/*! \brief Write data into a zap_buffer_t up to the length of datalen
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \param data pointer to the data to be written
|
||||
* \param datalen amount of data to be written
|
||||
* \return int amount of buffer used after the write, or 0 if no space available
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen);
|
||||
|
||||
/*! \brief Remove data from the buffer
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
* \param datalen amount of data to be removed
|
||||
* \return int size of buffer, or 0 if unable to toss that much data
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen);
|
||||
|
||||
/*! \brief Remove all data from the buffer
|
||||
* \param buffer any buffer of type zap_buffer_t
|
||||
*/
|
||||
OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer);
|
||||
|
||||
/*! \brief Destroy the buffer
|
||||
* \param buffer buffer to destroy
|
||||
* \note only neccessary on dynamic buffers (noop on pooled ones)
|
||||
*/
|
||||
OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer);
|
||||
|
||||
/*! \brief Seek to offset from the beginning of the buffer
|
||||
* \param buffer buffer to seek
|
||||
* \param datalen offset in bytes
|
||||
* \return new position
|
||||
*/
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen);
|
||||
|
||||
/** @} */
|
||||
|
||||
OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup config Config File Parser
|
||||
* @ingroup config
|
||||
* This module implements a basic interface and file format parser
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* EXAMPLE
|
||||
*
|
||||
* [category1]
|
||||
* var1 => val1
|
||||
* var2 => val2
|
||||
* \# lines that begin with \# are comments
|
||||
* \#var3 => val3
|
||||
* </pre>
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef ZAP_CONFIG_H
|
||||
#define ZAP_CONFIG_H
|
||||
|
||||
#include "openzap.h"
|
||||
#define ZAP_URL_SEPARATOR "://"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define ZAP_PATH_SEPARATOR "\\"
|
||||
#ifndef ZAP_CONFIG_DIR
|
||||
#define ZAP_CONFIG_DIR "c:\\openzap"
|
||||
#endif
|
||||
#define zap_is_file_path(file) (*(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR))
|
||||
#else
|
||||
#define ZAP_PATH_SEPARATOR "/"
|
||||
#ifndef ZAP_CONFIG_DIR
|
||||
#define ZAP_CONFIG_DIR "/etc/openzap"
|
||||
#endif
|
||||
#define zap_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct zap_config zap_config_t;
|
||||
|
||||
/*! \brief A simple file handle representing an open configuration file **/
|
||||
struct zap_config {
|
||||
/*! FILE stream buffer to the opened file */
|
||||
FILE *file;
|
||||
/*! path to the file */
|
||||
char path[512];
|
||||
/*! current category */
|
||||
char category[256];
|
||||
/*! current section */
|
||||
char section[256];
|
||||
/*! buffer of current line being read */
|
||||
char buf[1024];
|
||||
/*! current line number in file */
|
||||
int lineno;
|
||||
/*! current category number in file */
|
||||
int catno;
|
||||
/*! current section number in file */
|
||||
int sectno;
|
||||
|
||||
int lockto;
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief Open a configuration file
|
||||
\param cfg (zap_config_t *) config handle to use
|
||||
\param file_path path to the file
|
||||
\return 1 (true) on success 0 (false) on failure
|
||||
*/
|
||||
int zap_config_open_file(zap_config_t * cfg, const char *file_path);
|
||||
|
||||
/*!
|
||||
\brief Close a previously opened configuration file
|
||||
\param cfg (zap_config_t *) config handle to use
|
||||
*/
|
||||
void zap_config_close_file(zap_config_t * cfg);
|
||||
|
||||
/*!
|
||||
\brief Retrieve next name/value pair from configuration file
|
||||
\param cfg (zap_config_t *) config handle to use
|
||||
\param var pointer to aim at the new variable name
|
||||
\param val pointer to aim at the new value
|
||||
*/
|
||||
int zap_config_next_pair(zap_config_t * cfg, char **var, char **val);
|
||||
|
||||
/*!
|
||||
\brief Retrieve the CAS bits from a configuration string value
|
||||
\param strvalue pointer to the configuration string value (expected to be in format whatever:xxxx)
|
||||
\param outbits pointer to aim at the CAS bits
|
||||
*/
|
||||
OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Cross Platform dso/dll load abstraction
|
||||
* Copyright(C) 2008 Michael Jerris
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so.
|
||||
*
|
||||
* This work is provided under this license on an "as is" basis, without warranty of any kind,
|
||||
* either expressed or implied, including, without limitation, warranties that the covered code
|
||||
* is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
|
||||
* risk as to the quality and performance of the covered code is with you. Should any covered
|
||||
* code prove defective in any respect, you (not the initial developer or any other contributor)
|
||||
* assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
|
||||
* constitutes an essential part of this license. No use of any covered code is authorized hereunder
|
||||
* except under this disclaimer.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ZAP_DSO_H
|
||||
#define _ZAP_DSO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*zap_func_ptr_t) (void);
|
||||
typedef void * zap_dso_lib_t;
|
||||
|
||||
OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib);
|
||||
OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err);
|
||||
OZ_DECLARE(void *) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4
|
||||
*/
|
||||
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* zap_m3ua.h
|
||||
* openzap
|
||||
*
|
||||
* Created by Shane Burrell on 4/3/08.
|
||||
* Copyright 2008 Shane Burrell. All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2007, Anthony Minessale II, Nenad Corbic
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
//#include "m3ua_client.h"
|
||||
#include "openzap.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
enum e_sigboost_event_id_values
|
||||
{
|
||||
SIGBOOST_EVENT_CALL_START = 0x80, /*128*/
|
||||
SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129*/
|
||||
SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130*/
|
||||
SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131*/
|
||||
SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/
|
||||
SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/
|
||||
SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/
|
||||
SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/
|
||||
SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/
|
||||
/* Following IDs are ss7boost to sangoma_mgd only. */
|
||||
SIGBOOST_EVENT_HEARTBEAT = 0x89, /*137*/
|
||||
SIGBOOST_EVENT_INSERT_CHECK_LOOP = 0x8a, /*138*/
|
||||
SIGBOOST_EVENT_REMOVE_CHECK_LOOP = 0x8b, /*139*/
|
||||
SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE = 0x8c, /*140*/
|
||||
};
|
||||
enum e_sigboost_release_cause_values
|
||||
{
|
||||
SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0,
|
||||
SIGBOOST_RELEASE_CAUSE_NORMAL = 16,
|
||||
SIGBOOST_RELEASE_CAUSE_BUSY = 17,
|
||||
/* probable elimination */
|
||||
//SIGBOOST_RELEASE_CAUSE_BUSY = 0x91, /* 145 */
|
||||
//SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92, /* 146 */
|
||||
//SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93, /* 147 */
|
||||
//SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94, /* 148 */
|
||||
};
|
||||
|
||||
enum e_sigboost_call_setup_ack_nack_cause_values
|
||||
{
|
||||
SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 117, /* unused Q.850 value */
|
||||
SIGBOOST_CALL_SETUP_NACK_TEST_CKT_BUSY = 118, /* unused Q.850 value */
|
||||
SIGBOOST_CALL_SETUP_NACK_INVALID_NUMBER = 28,
|
||||
/* probable elimination */
|
||||
//SIGBOOST_CALL_SETUP_RESERVED = 0x00,
|
||||
//SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
|
||||
//SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
|
||||
//SIGBOOST_CALL_SETUP_NACK_AUTO_CALL_GAP = 0x17,
|
||||
};
|
||||
typedef enum {
|
||||
M3UA_SPAN_SIGNALING_M3UA,
|
||||
M3UA_SPAN_SIGNALING_SS7BOX,
|
||||
|
||||
} M3UA_TSpanSignaling;
|
||||
#define M3UA_SPAN_STRINGS "M3UA", "SS7BOX"
|
||||
ZAP_STR2ENUM_P(m3ua_str2span, m3ua_span2str, M3UA_TSpanSignaling)
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
ZAP_M3UA_RUNNING = (1 << 0)
|
||||
} zap_m3uat_flag_t;
|
||||
|
||||
/*typedef struct m3ua_data {
|
||||
m3uac_connection_t mcon;
|
||||
m3uac_connection_t pcon;
|
||||
zio_signal_cb_t signal_cb;
|
||||
uint32_t flags;
|
||||
} m3ua_data_t;
|
||||
|
||||
*/
|
||||
/*typedef struct mu3a_link {
|
||||
ss7bc_connection_t mcon;
|
||||
ss7bc_connection_t pcon;
|
||||
zio_signal_cb_t signal_cb;
|
||||
uint32_t flags;
|
||||
} zap_m3ua_data_t;
|
||||
*/
|
||||
|
||||
zap_status_t m3ua_init(zap_io_interface_t **zint);
|
||||
zap_status_t m3ua_destroy(void);
|
||||
zap_status_t m3ua_start(zap_span_t *span);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
||||
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Cross Platform Thread/Mutex abstraction
|
||||
* Copyright(C) 2007 Michael Jerris
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so.
|
||||
*
|
||||
* This work is provided under this license on an "as is" basis, without warranty of any kind,
|
||||
* either expressed or implied, including, without limitation, warranties that the covered code
|
||||
* is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
|
||||
* risk as to the quality and performance of the covered code is with you. Should any covered
|
||||
* code prove defective in any respect, you (not the initial developer or any other contributor)
|
||||
* assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
|
||||
* constitutes an essential part of this license. No use of any covered code is authorized hereunder
|
||||
* except under this disclaimer.
|
||||
*
|
||||
* Contributors:
|
||||
*
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ZAP_THREADMUTEX_H
|
||||
#define _ZAP_THREADMUTEX_H
|
||||
|
||||
#include "openzap.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef struct zap_mutex zap_mutex_t;
|
||||
typedef struct zap_thread zap_thread_t;
|
||||
typedef struct zap_condition zap_condition_t;
|
||||
typedef void *(*zap_thread_function_t) (zap_thread_t *, void *);
|
||||
|
||||
OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data);
|
||||
OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size);
|
||||
OZ_DECLARE(void) zap_thread_override_default_stacksize(zap_size_t size);
|
||||
OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex);
|
||||
OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex);
|
||||
OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex);
|
||||
OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex);
|
||||
OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex);
|
||||
OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **cond, zap_mutex_t *mutex);
|
||||
OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **cond);
|
||||
OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *cond);
|
||||
OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *cond, int ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
||||
|
@ -1,703 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Contributors:
|
||||
*
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ZAP_TYPES_H
|
||||
#define ZAP_TYPES_H
|
||||
#include "fsk.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
typedef HANDLE zap_socket_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef __int8 int8_t;
|
||||
typedef intptr_t zap_ssize_t;
|
||||
typedef int zap_filehandle_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdarg.h>
|
||||
typedef int zap_socket_t;
|
||||
typedef ssize_t zap_ssize_t;
|
||||
typedef int zap_filehandle_t;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define TAG_END NULL
|
||||
|
||||
typedef size_t zap_size_t;
|
||||
struct zap_io_interface;
|
||||
|
||||
#define ZAP_COMMAND_OBJ_INT *((int *)obj)
|
||||
#define ZAP_COMMAND_OBJ_CHAR_P (char *)obj
|
||||
#define ZAP_COMMAND_OBJ_FLOAT *(float *)obj
|
||||
#define ZAP_FSK_MOD_FACTOR 0x10000
|
||||
#define ZAP_DEFAULT_DTMF_ON 250
|
||||
#define ZAP_DEFAULT_DTMF_OFF 50
|
||||
|
||||
#define ZAP_END -1
|
||||
#define ZAP_ANY_STATE -1
|
||||
|
||||
typedef uint64_t zap_time_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_ENDIAN_BIG = 1,
|
||||
ZAP_ENDIAN_LITTLE = -1
|
||||
} zap_endian_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CID_TYPE_SDMF = 0x04,
|
||||
ZAP_CID_TYPE_MDMF = 0x80
|
||||
} zap_cid_type_t;
|
||||
|
||||
typedef enum {
|
||||
MDMF_DATETIME = 1,
|
||||
MDMF_PHONE_NUM = 2,
|
||||
MDMF_DDN = 3,
|
||||
MDMF_NO_NUM = 4,
|
||||
MDMF_PHONE_NAME = 7,
|
||||
MDMF_NO_NAME = 8,
|
||||
MDMF_ALT_ROUTE = 9,
|
||||
MDMF_INVALID = 10
|
||||
} zap_mdmf_type_t;
|
||||
#define MDMF_STRINGS "X", "DATETIME", "PHONE_NUM", "DDN", "NO_NUM", "X", "X", "PHONE_NAME", "NO_NAME", "ALT_ROUTE", "INVALID"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t)
|
||||
|
||||
#define ZAP_TONEMAP_LEN 128
|
||||
typedef enum {
|
||||
ZAP_TONEMAP_NONE,
|
||||
ZAP_TONEMAP_DIAL,
|
||||
ZAP_TONEMAP_RING,
|
||||
ZAP_TONEMAP_BUSY,
|
||||
ZAP_TONEMAP_FAIL1,
|
||||
ZAP_TONEMAP_FAIL2,
|
||||
ZAP_TONEMAP_FAIL3,
|
||||
ZAP_TONEMAP_ATTN,
|
||||
ZAP_TONEMAP_CALLWAITING_CAS,
|
||||
ZAP_TONEMAP_CALLWAITING_SAS,
|
||||
ZAP_TONEMAP_CALLWAITING_ACK,
|
||||
ZAP_TONEMAP_INVALID
|
||||
} zap_tonemap_t;
|
||||
#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "FAIL1", "FAIL2", "FAIL3", "ATTN", "CALLWAITING-CAS", "CALLWAITING-SAS", "CALLWAITING-ACK", "INVALID"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_TRUNK_E1,
|
||||
ZAP_TRUNK_T1,
|
||||
ZAP_TRUNK_J1,
|
||||
ZAP_TRUNK_BRI,
|
||||
ZAP_TRUNK_BRI_PTMP,
|
||||
ZAP_TRUNK_FXO,
|
||||
ZAP_TRUNK_FXS,
|
||||
ZAP_TRUNK_EM,
|
||||
ZAP_TRUNK_NONE
|
||||
} zap_trunk_type_t;
|
||||
#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "EM", "NONE"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_ANALOG_START_KEWL,
|
||||
ZAP_ANALOG_START_LOOP,
|
||||
ZAP_ANALOG_START_GROUND,
|
||||
ZAP_ANALOG_START_WINK,
|
||||
ZAP_ANALOG_START_NA
|
||||
} zap_analog_start_type_t;
|
||||
#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "WINK", "NA"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_OOB_ONHOOK,
|
||||
ZAP_OOB_OFFHOOK,
|
||||
ZAP_OOB_WINK,
|
||||
ZAP_OOB_FLASH,
|
||||
ZAP_OOB_RING_START,
|
||||
ZAP_OOB_RING_STOP,
|
||||
ZAP_OOB_ALARM_TRAP,
|
||||
ZAP_OOB_ALARM_CLEAR,
|
||||
ZAP_OOB_NOOP,
|
||||
ZAP_OOB_CAS_BITS_CHANGE,
|
||||
ZAP_OOB_INVALID
|
||||
} zap_oob_event_t;
|
||||
#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "NOOP", "CAS_BITS_CHANGE", "INVALID"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_ALARM_NONE = 0,
|
||||
ZAP_ALARM_RECOVER = (1 << 0),
|
||||
ZAP_ALARM_LOOPBACK = (1 << 2),
|
||||
ZAP_ALARM_YELLOW = (1 << 3),
|
||||
ZAP_ALARM_RED = (1 << 4),
|
||||
ZAP_ALARM_BLUE = (1 << 5),
|
||||
ZAP_ALARM_NOTOPEN = ( 1 << 6),
|
||||
ZAP_ALARM_AIS = ( 1 << 7),
|
||||
ZAP_ALARM_RAI = ( 1 << 8),
|
||||
ZAP_ALARM_GENERAL = ( 1 << 30)
|
||||
} zap_alarm_flag_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_SIGTYPE_NONE,
|
||||
ZAP_SIGTYPE_ISDN,
|
||||
ZAP_SIGTYPE_RBS,
|
||||
ZAP_SIGTYPE_ANALOG,
|
||||
ZAP_SIGTYPE_SANGOMABOOST,
|
||||
ZAP_SIGTYPE_M3UA,
|
||||
ZAP_SIGTYPE_R2
|
||||
} zap_signal_type_t;
|
||||
|
||||
/*!
|
||||
\brief Signaling status on a given span or specific channel on protocols that support it
|
||||
*/
|
||||
typedef enum {
|
||||
/* The signaling link is down (no d-chans up in the span/group, MFC-R2 bit pattern unidentified) */
|
||||
ZAP_SIG_STATE_DOWN,
|
||||
/* The signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */
|
||||
ZAP_SIG_STATE_SUSPENDED,
|
||||
/* The signaling link is ready and calls can be placed */
|
||||
ZAP_SIG_STATE_UP,
|
||||
/* Invalid status */
|
||||
ZAP_SIG_STATE_INVALID
|
||||
} zap_signaling_status_t;
|
||||
#define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP", "INVALID"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_signaling_status, zap_signaling_status2str, zap_signaling_status_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_SIGEVENT_START,
|
||||
ZAP_SIGEVENT_STOP,
|
||||
ZAP_SIGEVENT_TRANSFER,
|
||||
ZAP_SIGEVENT_ANSWER,
|
||||
ZAP_SIGEVENT_UP,
|
||||
ZAP_SIGEVENT_FLASH,
|
||||
ZAP_SIGEVENT_PROGRESS,
|
||||
ZAP_SIGEVENT_PROGRESS_MEDIA,
|
||||
ZAP_SIGEVENT_NOTIFY,
|
||||
ZAP_SIGEVENT_TONE_DETECTED,
|
||||
ZAP_SIGEVENT_ALARM_TRAP,
|
||||
ZAP_SIGEVENT_ALARM_CLEAR,
|
||||
ZAP_SIGEVENT_MISC,
|
||||
ZAP_SIGEVENT_COLLECTED_DIGIT,
|
||||
ZAP_SIGEVENT_ADD_CALL,
|
||||
ZAP_SIGEVENT_RESTART,
|
||||
/* Signaling link status changed (D-chan up, down, R2 blocked etc) */
|
||||
ZAP_SIGEVENT_SIGSTATUS_CHANGED,
|
||||
/* Hardware link status changed (Line connected, disconnected) */
|
||||
ZAP_SIGEVENT_HWSTATUS_CHANGED,
|
||||
ZAP_SIGEVENT_INVALID
|
||||
} zap_signal_event_t;
|
||||
#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \
|
||||
"PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", \
|
||||
"COLLECTED_DIGIT", "ADD_CALL", "RESTART", "SIGLINK_CHANGED", "HWSTATUS_CHANGED", "INVALID"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_EVENT_NONE,
|
||||
ZAP_EVENT_DTMF,
|
||||
ZAP_EVENT_OOB,
|
||||
ZAP_EVENT_COUNT
|
||||
} zap_event_type_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_TOP_DOWN,
|
||||
ZAP_BOTTOM_UP
|
||||
} zap_direction_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_SUCCESS,
|
||||
ZAP_FAIL,
|
||||
ZAP_MEMERR,
|
||||
ZAP_TIMEOUT,
|
||||
ZAP_NOTIMPL,
|
||||
ZAP_CHECKSUM_ERROR,
|
||||
ZAP_STATUS_COUNT,
|
||||
ZAP_BREAK
|
||||
} zap_status_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_NO_FLAGS = 0,
|
||||
ZAP_READ = (1 << 0),
|
||||
ZAP_WRITE = (1 << 1),
|
||||
ZAP_EVENTS = (1 << 2)
|
||||
} zap_wait_flag_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CODEC_ULAW = 0,
|
||||
ZAP_CODEC_ALAW = 8,
|
||||
ZAP_CODEC_SLIN = 10,
|
||||
ZAP_CODEC_NONE = (1 << 30)
|
||||
} zap_codec_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_TONE_DTMF = (1 << 0)
|
||||
} zap_tone_type_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_COMMAND_NOOP,
|
||||
ZAP_COMMAND_SET_INTERVAL,
|
||||
ZAP_COMMAND_GET_INTERVAL,
|
||||
ZAP_COMMAND_SET_CODEC,
|
||||
ZAP_COMMAND_GET_CODEC,
|
||||
ZAP_COMMAND_SET_NATIVE_CODEC,
|
||||
ZAP_COMMAND_GET_NATIVE_CODEC,
|
||||
ZAP_COMMAND_ENABLE_DTMF_DETECT,
|
||||
ZAP_COMMAND_DISABLE_DTMF_DETECT,
|
||||
ZAP_COMMAND_SEND_DTMF,
|
||||
ZAP_COMMAND_SET_DTMF_ON_PERIOD,
|
||||
ZAP_COMMAND_GET_DTMF_ON_PERIOD,
|
||||
ZAP_COMMAND_SET_DTMF_OFF_PERIOD,
|
||||
ZAP_COMMAND_GET_DTMF_OFF_PERIOD,
|
||||
ZAP_COMMAND_GENERATE_RING_ON,
|
||||
ZAP_COMMAND_GENERATE_RING_OFF,
|
||||
ZAP_COMMAND_OFFHOOK,
|
||||
ZAP_COMMAND_ONHOOK,
|
||||
ZAP_COMMAND_FLASH,
|
||||
ZAP_COMMAND_WINK,
|
||||
ZAP_COMMAND_ENABLE_PROGRESS_DETECT,
|
||||
ZAP_COMMAND_DISABLE_PROGRESS_DETECT,
|
||||
ZAP_COMMAND_TRACE_INPUT,
|
||||
ZAP_COMMAND_TRACE_OUTPUT,
|
||||
ZAP_COMMAND_ENABLE_CALLERID_DETECT,
|
||||
ZAP_COMMAND_DISABLE_CALLERID_DETECT,
|
||||
ZAP_COMMAND_ENABLE_ECHOCANCEL,
|
||||
ZAP_COMMAND_DISABLE_ECHOCANCEL,
|
||||
ZAP_COMMAND_ENABLE_ECHOTRAIN,
|
||||
ZAP_COMMAND_DISABLE_ECHOTRAIN,
|
||||
ZAP_COMMAND_SET_CAS_BITS,
|
||||
ZAP_COMMAND_GET_CAS_BITS,
|
||||
ZAP_COMMAND_SET_RX_GAIN,
|
||||
ZAP_COMMAND_GET_RX_GAIN,
|
||||
ZAP_COMMAND_SET_TX_GAIN,
|
||||
ZAP_COMMAND_GET_TX_GAIN,
|
||||
ZAP_COMMAND_FLUSH_TX_BUFFERS,
|
||||
ZAP_COMMAND_FLUSH_RX_BUFFERS,
|
||||
ZAP_COMMAND_FLUSH_BUFFERS,
|
||||
ZAP_COMMAND_SET_PRE_BUFFER_SIZE,
|
||||
ZAP_COMMAND_SET_LINK_STATUS,
|
||||
ZAP_COMMAND_GET_LINK_STATUS,
|
||||
ZAP_COMMAND_COUNT
|
||||
} zap_command_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_SPAN_CONFIGURED = (1 << 0),
|
||||
ZAP_SPAN_READY = (1 << 1),
|
||||
ZAP_SPAN_STATE_CHANGE = (1 << 2),
|
||||
ZAP_SPAN_SUSPENDED = (1 << 3),
|
||||
ZAP_SPAN_IN_THREAD = (1 << 4),
|
||||
ZAP_SPAN_STOP_THREAD = (1 << 5)
|
||||
} zap_span_flag_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CHAN_TYPE_B,
|
||||
ZAP_CHAN_TYPE_DQ921,
|
||||
ZAP_CHAN_TYPE_DQ931,
|
||||
ZAP_CHAN_TYPE_FXS,
|
||||
ZAP_CHAN_TYPE_FXO,
|
||||
ZAP_CHAN_TYPE_EM,
|
||||
ZAP_CHAN_TYPE_CAS,
|
||||
ZAP_CHAN_TYPE_COUNT
|
||||
} zap_chan_type_t;
|
||||
|
||||
#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0),
|
||||
ZAP_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1),
|
||||
ZAP_CHANNEL_FEATURE_CODECS = (1 << 2),
|
||||
ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 3),
|
||||
ZAP_CHANNEL_FEATURE_CALLERID = (1 << 4),
|
||||
ZAP_CHANNEL_FEATURE_PROGRESS = (1 << 5)
|
||||
} zap_channel_feature_t;
|
||||
|
||||
typedef enum {
|
||||
ZAP_CHANNEL_STATE_DOWN,
|
||||
ZAP_CHANNEL_STATE_HOLD,
|
||||
ZAP_CHANNEL_STATE_SUSPENDED,
|
||||
ZAP_CHANNEL_STATE_DIALTONE,
|
||||
ZAP_CHANNEL_STATE_COLLECT,
|
||||
ZAP_CHANNEL_STATE_RING,
|
||||
ZAP_CHANNEL_STATE_BUSY,
|
||||
ZAP_CHANNEL_STATE_ATTN,
|
||||
ZAP_CHANNEL_STATE_GENRING,
|
||||
ZAP_CHANNEL_STATE_DIALING,
|
||||
ZAP_CHANNEL_STATE_GET_CALLERID,
|
||||
ZAP_CHANNEL_STATE_CALLWAITING,
|
||||
ZAP_CHANNEL_STATE_RESTART,
|
||||
ZAP_CHANNEL_STATE_PROGRESS,
|
||||
ZAP_CHANNEL_STATE_PROGRESS_MEDIA,
|
||||
ZAP_CHANNEL_STATE_UP,
|
||||
ZAP_CHANNEL_STATE_IDLE,
|
||||
ZAP_CHANNEL_STATE_TERMINATING,
|
||||
ZAP_CHANNEL_STATE_CANCEL,
|
||||
ZAP_CHANNEL_STATE_HANGUP,
|
||||
ZAP_CHANNEL_STATE_HANGUP_COMPLETE,
|
||||
ZAP_CHANNEL_STATE_INVALID
|
||||
} zap_channel_state_t;
|
||||
#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \
|
||||
"RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \
|
||||
"RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", "HANGUP", "HANGUP_COMPLETE", "INVALID"
|
||||
ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t)
|
||||
|
||||
typedef enum {
|
||||
ZAP_CHANNEL_CONFIGURED = (1 << 0),
|
||||
ZAP_CHANNEL_READY = (1 << 1),
|
||||
ZAP_CHANNEL_OPEN = (1 << 2),
|
||||
ZAP_CHANNEL_DTMF_DETECT = (1 << 3),
|
||||
ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4),
|
||||
ZAP_CHANNEL_TRANSCODE = (1 << 5),
|
||||
ZAP_CHANNEL_BUFFER = (1 << 6),
|
||||
ZAP_CHANNEL_EVENT = (1 << 7),
|
||||
ZAP_CHANNEL_INTHREAD = (1 << 8),
|
||||
ZAP_CHANNEL_WINK = (1 << 9),
|
||||
ZAP_CHANNEL_FLASH = (1 << 10),
|
||||
ZAP_CHANNEL_STATE_CHANGE = (1 << 11),
|
||||
ZAP_CHANNEL_HOLD = (1 << 12),
|
||||
ZAP_CHANNEL_INUSE = (1 << 13),
|
||||
ZAP_CHANNEL_OFFHOOK = (1 << 14),
|
||||
ZAP_CHANNEL_RINGING = (1 << 15),
|
||||
ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16),
|
||||
ZAP_CHANNEL_CALLERID_DETECT = (1 << 17),
|
||||
ZAP_CHANNEL_OUTBOUND = (1 << 18),
|
||||
ZAP_CHANNEL_SUSPENDED = (1 << 19),
|
||||
ZAP_CHANNEL_3WAY = (1 << 20),
|
||||
ZAP_CHANNEL_PROGRESS = (1 << 21),
|
||||
ZAP_CHANNEL_MEDIA = (1 << 22),
|
||||
ZAP_CHANNEL_ANSWERED = (1 << 23),
|
||||
ZAP_CHANNEL_MUTE = (1 << 24),
|
||||
ZAP_CHANNEL_USE_RX_GAIN = (1 << 25),
|
||||
ZAP_CHANNEL_USE_TX_GAIN = (1 << 26),
|
||||
} zap_channel_flag_t;
|
||||
#if defined(__cplusplus) && defined(WIN32)
|
||||
// fix C2676
|
||||
__inline__ zap_channel_flag_t operator|=(zap_channel_flag_t a, int32_t b) {
|
||||
a = (zap_channel_flag_t)(a | b);
|
||||
return a;
|
||||
}
|
||||
__inline__ zap_channel_flag_t operator&=(zap_channel_flag_t a, int32_t b) {
|
||||
a = (zap_channel_flag_t)(a & b);
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ZSM_NONE,
|
||||
ZSM_UNACCEPTABLE,
|
||||
ZSM_ACCEPTABLE
|
||||
} zap_state_map_type_t;
|
||||
|
||||
typedef enum {
|
||||
ZSD_INBOUND,
|
||||
ZSD_OUTBOUND,
|
||||
} zap_state_direction_t;
|
||||
|
||||
#define ZAP_MAP_NODE_SIZE 512
|
||||
#define ZAP_MAP_MAX ZAP_CHANNEL_STATE_INVALID+2
|
||||
|
||||
struct zap_state_map_node {
|
||||
zap_state_direction_t direction;
|
||||
zap_state_map_type_t type;
|
||||
zap_channel_state_t check_states[ZAP_MAP_MAX];
|
||||
zap_channel_state_t states[ZAP_MAP_MAX];
|
||||
};
|
||||
typedef struct zap_state_map_node zap_state_map_node_t;
|
||||
|
||||
struct zap_state_map {
|
||||
zap_state_map_node_t nodes[ZAP_MAP_NODE_SIZE];
|
||||
};
|
||||
typedef struct zap_state_map zap_state_map_t;
|
||||
|
||||
typedef enum zap_channel_hw_link_status {
|
||||
ZAP_HW_LINK_DISCONNECTED = 0,
|
||||
ZAP_HW_LINK_CONNECTED
|
||||
} zap_channel_hw_link_status_t;
|
||||
|
||||
typedef struct zap_conf_parameter_s {
|
||||
const char *var;
|
||||
const char *val;
|
||||
} zap_conf_parameter_t;
|
||||
|
||||
typedef struct zap_channel zap_channel_t;
|
||||
typedef struct zap_event zap_event_t;
|
||||
typedef struct zap_sigmsg zap_sigmsg_t;
|
||||
typedef struct zap_span zap_span_t;
|
||||
typedef struct zap_group zap_group_t;
|
||||
typedef struct zap_caller_data zap_caller_data_t;
|
||||
typedef struct zap_io_interface zap_io_interface_t;
|
||||
|
||||
struct zap_stream_handle;
|
||||
typedef struct zap_stream_handle zap_stream_handle_t;
|
||||
|
||||
typedef zap_status_t (*zap_stream_handle_raw_write_function_t) (zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen);
|
||||
typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t *handle, const char *fmt, ...);
|
||||
|
||||
#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, uint32_t chan_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan)
|
||||
#define ZIO_CHANNEL_OUTGOING_CALL_ARGS (zap_channel_t *zchan)
|
||||
#define ZIO_CHANNEL_SET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t status)
|
||||
#define ZIO_CHANNEL_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t *status)
|
||||
#define ZIO_SPAN_SET_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t status)
|
||||
#define ZIO_SPAN_GET_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t *status)
|
||||
#define ZIO_SPAN_POLL_EVENT_ARGS (zap_span_t *span, uint32_t ms)
|
||||
#define ZIO_SPAN_NEXT_EVENT_ARGS (zap_span_t *span, zap_event_t **event)
|
||||
#define ZIO_SIGNAL_CB_ARGS (zap_sigmsg_t *sigmsg)
|
||||
#define ZIO_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event)
|
||||
#define ZIO_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen)
|
||||
#define ZIO_CONFIGURE_SPAN_ARGS (zap_span_t *span, const char *str, zap_chan_type_t type, char *name, char *number)
|
||||
#define ZIO_CONFIGURE_ARGS (const char *category, const char *var, const char *val, int lineno)
|
||||
#define ZIO_OPEN_ARGS (zap_channel_t *zchan)
|
||||
#define ZIO_CLOSE_ARGS (zap_channel_t *zchan)
|
||||
#define ZIO_CHANNEL_DESTROY_ARGS (zap_channel_t *zchan)
|
||||
#define ZIO_SPAN_DESTROY_ARGS (zap_span_t *span)
|
||||
#define ZIO_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj)
|
||||
#define ZIO_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to)
|
||||
#define ZIO_GET_ALARMS_ARGS (zap_channel_t *zchan)
|
||||
#define ZIO_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
|
||||
#define ZIO_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
|
||||
#define ZIO_IO_LOAD_ARGS (zap_io_interface_t **zio)
|
||||
#define ZIO_IO_UNLOAD_ARGS (void)
|
||||
#define ZIO_SIG_LOAD_ARGS (void)
|
||||
#define ZIO_SIG_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap)
|
||||
#define ZIO_CONFIGURE_SPAN_SIGNALING_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *zap_parameters)
|
||||
#define ZIO_SIG_UNLOAD_ARGS (void)
|
||||
#define ZIO_API_ARGS (zap_stream_handle_t *stream, const char *data)
|
||||
|
||||
typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ;
|
||||
typedef zap_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ;
|
||||
typedef zap_status_t (*zio_channel_set_sig_status_t) ZIO_CHANNEL_SET_SIG_STATUS_ARGS;
|
||||
typedef zap_status_t (*zio_channel_get_sig_status_t) ZIO_CHANNEL_GET_SIG_STATUS_ARGS;
|
||||
typedef zap_status_t (*zio_span_set_sig_status_t) ZIO_SPAN_SET_SIG_STATUS_ARGS;
|
||||
typedef zap_status_t (*zio_span_get_sig_status_t) ZIO_SPAN_GET_SIG_STATUS_ARGS;
|
||||
typedef zap_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ;
|
||||
typedef zap_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ;
|
||||
typedef zap_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ;
|
||||
typedef zap_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ;
|
||||
typedef zap_status_t (*zio_codec_t) ZIO_CODEC_ARGS ;
|
||||
typedef zap_status_t (*zio_configure_span_t) ZIO_CONFIGURE_SPAN_ARGS ;
|
||||
typedef zap_status_t (*zio_configure_t) ZIO_CONFIGURE_ARGS ;
|
||||
typedef zap_status_t (*zio_open_t) ZIO_OPEN_ARGS ;
|
||||
typedef zap_status_t (*zio_close_t) ZIO_CLOSE_ARGS ;
|
||||
typedef zap_status_t (*zio_channel_destroy_t) ZIO_CHANNEL_DESTROY_ARGS ;
|
||||
typedef zap_status_t (*zio_span_destroy_t) ZIO_SPAN_DESTROY_ARGS ;
|
||||
typedef zap_status_t (*zio_get_alarms_t) ZIO_GET_ALARMS_ARGS ;
|
||||
typedef zap_status_t (*zio_command_t) ZIO_COMMAND_ARGS ;
|
||||
typedef zap_status_t (*zio_wait_t) ZIO_WAIT_ARGS ;
|
||||
typedef zap_status_t (*zio_read_t) ZIO_READ_ARGS ;
|
||||
typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ;
|
||||
typedef zap_status_t (*zio_io_load_t) ZIO_IO_LOAD_ARGS ;
|
||||
typedef zap_status_t (*zio_sig_load_t) ZIO_SIG_LOAD_ARGS ;
|
||||
typedef zap_status_t (*zio_sig_configure_t) ZIO_SIG_CONFIGURE_ARGS ;
|
||||
typedef zap_status_t (*zio_configure_span_signaling_t) ZIO_CONFIGURE_SPAN_SIGNALING_ARGS ;
|
||||
typedef zap_status_t (*zio_io_unload_t) ZIO_IO_UNLOAD_ARGS ;
|
||||
typedef zap_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_ARGS ;
|
||||
typedef zap_status_t (*zio_api_t) ZIO_API_ARGS ;
|
||||
|
||||
|
||||
#define ZIO_CHANNEL_REQUEST_FUNCTION(name) zap_status_t name ZIO_CHANNEL_REQUEST_ARGS
|
||||
#define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) zap_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS
|
||||
#define ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_CHANNEL_SET_SIG_STATUS_ARGS
|
||||
#define ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_CHANNEL_GET_SIG_STATUS_ARGS
|
||||
#define ZIO_SPAN_SET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_SPAN_SET_SIG_STATUS_ARGS
|
||||
#define ZIO_SPAN_GET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_SPAN_GET_SIG_STATUS_ARGS
|
||||
#define ZIO_SPAN_POLL_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_POLL_EVENT_ARGS
|
||||
#define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_NEXT_EVENT_ARGS
|
||||
#define ZIO_SIGNAL_CB_FUNCTION(name) zap_status_t name ZIO_SIGNAL_CB_ARGS
|
||||
#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS
|
||||
#define ZIO_CODEC_FUNCTION(name) OZ_DECLARE_NONSTD(zap_status_t) name ZIO_CODEC_ARGS
|
||||
#define ZIO_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_SPAN_ARGS
|
||||
#define ZIO_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_ARGS
|
||||
#define ZIO_OPEN_FUNCTION(name) zap_status_t name ZIO_OPEN_ARGS
|
||||
#define ZIO_CLOSE_FUNCTION(name) zap_status_t name ZIO_CLOSE_ARGS
|
||||
#define ZIO_CHANNEL_DESTROY_FUNCTION(name) zap_status_t name ZIO_CHANNEL_DESTROY_ARGS
|
||||
#define ZIO_SPAN_DESTROY_FUNCTION(name) zap_status_t name ZIO_SPAN_DESTROY_ARGS
|
||||
#define ZIO_GET_ALARMS_FUNCTION(name) zap_status_t name ZIO_GET_ALARMS_ARGS
|
||||
#define ZIO_COMMAND_FUNCTION(name) zap_status_t name ZIO_COMMAND_ARGS
|
||||
#define ZIO_WAIT_FUNCTION(name) zap_status_t name ZIO_WAIT_ARGS
|
||||
#define ZIO_READ_FUNCTION(name) zap_status_t name ZIO_READ_ARGS
|
||||
#define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS
|
||||
#define ZIO_IO_LOAD_FUNCTION(name) zap_status_t name ZIO_IO_LOAD_ARGS
|
||||
#define ZIO_SIG_LOAD_FUNCTION(name) zap_status_t name ZIO_SIG_LOAD_ARGS
|
||||
#define ZIO_SIG_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_SIG_CONFIGURE_ARGS
|
||||
#define ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_SPAN_SIGNALING_ARGS
|
||||
#define ZIO_IO_UNLOAD_FUNCTION(name) zap_status_t name ZIO_IO_UNLOAD_ARGS
|
||||
#define ZIO_SIG_UNLOAD_FUNCTION(name) zap_status_t name ZIO_SIG_UNLOAD_ARGS
|
||||
#define ZIO_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS
|
||||
|
||||
#include "zap_dso.h"
|
||||
|
||||
typedef struct {
|
||||
char name[256];
|
||||
zio_io_load_t io_load;
|
||||
zio_io_unload_t io_unload;
|
||||
zio_sig_load_t sig_load;
|
||||
zio_sig_configure_t sig_configure;
|
||||
zio_sig_unload_t sig_unload;
|
||||
/*!
|
||||
\brief configure a given span signaling
|
||||
\see sig_configure
|
||||
This is just like sig_configure but receives
|
||||
an array of paramters instead of va_list
|
||||
I'd like to deprecate sig_configure and move
|
||||
all modules to use sigparam_configure
|
||||
*/
|
||||
zio_configure_span_signaling_t configure_span_signaling;
|
||||
zap_dso_lib_t lib;
|
||||
char path[256];
|
||||
} zap_module_t;
|
||||
|
||||
#ifndef __FUNCTION__
|
||||
#define __FUNCTION__ (const char *)__func__
|
||||
#endif
|
||||
|
||||
#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__
|
||||
#define ZAP_LOG_LEVEL_DEBUG 7
|
||||
#define ZAP_LOG_LEVEL_INFO 6
|
||||
#define ZAP_LOG_LEVEL_NOTICE 5
|
||||
#define ZAP_LOG_LEVEL_WARNING 4
|
||||
#define ZAP_LOG_LEVEL_ERROR 3
|
||||
#define ZAP_LOG_LEVEL_CRIT 2
|
||||
#define ZAP_LOG_LEVEL_ALERT 1
|
||||
#define ZAP_LOG_LEVEL_EMERG 0
|
||||
|
||||
#define ZAP_LOG_DEBUG ZAP_PRE, ZAP_LOG_LEVEL_DEBUG
|
||||
#define ZAP_LOG_INFO ZAP_PRE, ZAP_LOG_LEVEL_INFO
|
||||
#define ZAP_LOG_NOTICE ZAP_PRE, ZAP_LOG_LEVEL_NOTICE
|
||||
#define ZAP_LOG_WARNING ZAP_PRE, ZAP_LOG_LEVEL_WARNING
|
||||
#define ZAP_LOG_ERROR ZAP_PRE, ZAP_LOG_LEVEL_ERROR
|
||||
#define ZAP_LOG_CRIT ZAP_PRE, ZAP_LOG_LEVEL_CRIT
|
||||
#define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT
|
||||
#define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG
|
||||
|
||||
typedef struct zap_fsk_data_state zap_fsk_data_state_t;
|
||||
typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state);
|
||||
typedef zap_status_t (*zap_fsk_write_sample_t)(int16_t *buf, zap_size_t buflen, void *user_data);
|
||||
typedef void (*zap_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...);
|
||||
typedef struct hashtable zap_hash_t;
|
||||
typedef struct hashtable_iterator zap_hash_iterator_t;
|
||||
typedef struct key zap_hash_key_t;
|
||||
typedef struct value zap_hash_val_t;
|
||||
typedef struct zap_bitstream zap_bitstream_t;
|
||||
typedef struct zap_fsk_modulator zap_fsk_modulator_t;
|
||||
typedef zap_status_t (*zap_span_start_t)(zap_span_t *span);
|
||||
typedef zap_status_t (*zap_span_stop_t)(zap_span_t *span);
|
||||
|
||||
typedef enum {
|
||||
ZAP_CAUSE_NONE = 0,
|
||||
ZAP_CAUSE_UNALLOCATED = 1,
|
||||
ZAP_CAUSE_NO_ROUTE_TRANSIT_NET = 2,
|
||||
ZAP_CAUSE_NO_ROUTE_DESTINATION = 3,
|
||||
ZAP_CAUSE_CHANNEL_UNACCEPTABLE = 6,
|
||||
ZAP_CAUSE_CALL_AWARDED_DELIVERED = 7,
|
||||
ZAP_CAUSE_NORMAL_CLEARING = 16,
|
||||
ZAP_CAUSE_USER_BUSY = 17,
|
||||
ZAP_CAUSE_NO_USER_RESPONSE = 18,
|
||||
ZAP_CAUSE_NO_ANSWER = 19,
|
||||
ZAP_CAUSE_SUBSCRIBER_ABSENT = 20,
|
||||
ZAP_CAUSE_CALL_REJECTED = 21,
|
||||
ZAP_CAUSE_NUMBER_CHANGED = 22,
|
||||
ZAP_CAUSE_REDIRECTION_TO_NEW_DESTINATION = 23,
|
||||
ZAP_CAUSE_EXCHANGE_ROUTING_ERROR = 25,
|
||||
ZAP_CAUSE_DESTINATION_OUT_OF_ORDER = 27,
|
||||
ZAP_CAUSE_INVALID_NUMBER_FORMAT = 28,
|
||||
ZAP_CAUSE_FACILITY_REJECTED = 29,
|
||||
ZAP_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30,
|
||||
ZAP_CAUSE_NORMAL_UNSPECIFIED = 31,
|
||||
ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34,
|
||||
ZAP_CAUSE_NETWORK_OUT_OF_ORDER = 38,
|
||||
ZAP_CAUSE_NORMAL_TEMPORARY_FAILURE = 41,
|
||||
ZAP_CAUSE_SWITCH_CONGESTION = 42,
|
||||
ZAP_CAUSE_ACCESS_INFO_DISCARDED = 43,
|
||||
ZAP_CAUSE_REQUESTED_CHAN_UNAVAIL = 44,
|
||||
ZAP_CAUSE_PRE_EMPTED = 45,
|
||||
ZAP_CAUSE_FACILITY_NOT_SUBSCRIBED = 50,
|
||||
ZAP_CAUSE_OUTGOING_CALL_BARRED = 52,
|
||||
ZAP_CAUSE_INCOMING_CALL_BARRED = 54,
|
||||
ZAP_CAUSE_BEARERCAPABILITY_NOTAUTH = 57,
|
||||
ZAP_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58,
|
||||
ZAP_CAUSE_SERVICE_UNAVAILABLE = 63,
|
||||
ZAP_CAUSE_BEARERCAPABILITY_NOTIMPL = 65,
|
||||
ZAP_CAUSE_CHAN_NOT_IMPLEMENTED = 66,
|
||||
ZAP_CAUSE_FACILITY_NOT_IMPLEMENTED = 69,
|
||||
ZAP_CAUSE_SERVICE_NOT_IMPLEMENTED = 79,
|
||||
ZAP_CAUSE_INVALID_CALL_REFERENCE = 81,
|
||||
ZAP_CAUSE_INCOMPATIBLE_DESTINATION = 88,
|
||||
ZAP_CAUSE_INVALID_MSG_UNSPECIFIED = 95,
|
||||
ZAP_CAUSE_MANDATORY_IE_MISSING = 96,
|
||||
ZAP_CAUSE_MESSAGE_TYPE_NONEXIST = 97,
|
||||
ZAP_CAUSE_WRONG_MESSAGE = 98,
|
||||
ZAP_CAUSE_IE_NONEXIST = 99,
|
||||
ZAP_CAUSE_INVALID_IE_CONTENTS = 100,
|
||||
ZAP_CAUSE_WRONG_CALL_STATE = 101,
|
||||
ZAP_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102,
|
||||
ZAP_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103,
|
||||
ZAP_CAUSE_PROTOCOL_ERROR = 111,
|
||||
ZAP_CAUSE_INTERWORKING = 127,
|
||||
ZAP_CAUSE_SUCCESS = 142,
|
||||
ZAP_CAUSE_ORIGINATOR_CANCEL = 487,
|
||||
ZAP_CAUSE_CRASH = 500,
|
||||
ZAP_CAUSE_SYSTEM_SHUTDOWN = 501,
|
||||
ZAP_CAUSE_LOSE_RACE = 502,
|
||||
ZAP_CAUSE_MANAGER_REQUEST = 503,
|
||||
ZAP_CAUSE_BLIND_TRANSFER = 600,
|
||||
ZAP_CAUSE_ATTENDED_TRANSFER = 601,
|
||||
ZAP_CAUSE_ALLOTTED_TIMEOUT = 602,
|
||||
ZAP_CAUSE_USER_CHALLENGE = 603,
|
||||
ZAP_CAUSE_MEDIA_TIMEOUT = 604
|
||||
} zap_call_cause_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
||||
|
@ -79,7 +79,7 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include "Q921.h"
|
||||
#include "Q921priv.h"
|
||||
#include "mfifo.h"
|
||||
@ -398,7 +398,7 @@ int Q921_InitTrunk(L2TRUNK trunk,
|
||||
/*
|
||||
* Allocate space for per-link context(s)
|
||||
*/
|
||||
trunk->context = zap_malloc(numlinks * sizeof(struct Q921_Link));
|
||||
trunk->context = ftdm_malloc(numlinks * sizeof(struct Q921_Link));
|
||||
if(!trunk->context)
|
||||
return -1;
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
*/
|
||||
|
||||
#include <libteletone.h>
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
#define SMAX 32767
|
||||
#define SMIN -32768
|
||||
@ -111,7 +111,7 @@ TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int b
|
||||
ts->decay_step = 0;
|
||||
ts->decay_factor = 1;
|
||||
if (buflen) {
|
||||
if ((ts->buffer = zap_calloc(buflen, sizeof(teletone_audio_t))) == 0) {
|
||||
if ((ts->buffer = ftdm_calloc(buflen, sizeof(teletone_audio_t))) == 0) {
|
||||
return -1;
|
||||
}
|
||||
ts->datalen = buflen;
|
||||
@ -142,7 +142,7 @@ TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int b
|
||||
TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts)
|
||||
{
|
||||
if (ts->buffer) {
|
||||
zap_safe_free(ts->buffer);
|
||||
ftdm_safe_free(ts->buffer);
|
||||
ts->buffer = NULL;
|
||||
ts->samples = 0;
|
||||
}
|
||||
@ -280,7 +280,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm
|
||||
}
|
||||
|
||||
do {
|
||||
if (!(data = zap_strdup(cmd))) {
|
||||
if (!(data = ftdm_strdup(cmd))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -429,7 +429,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm
|
||||
}
|
||||
}
|
||||
bottom:
|
||||
zap_safe_free(data);
|
||||
ftdm_safe_free(data);
|
||||
data = NULL;
|
||||
if (ts->LOOPS > 0) {
|
||||
ts->LOOPS--;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* m3ua_client.c
|
||||
* openzap
|
||||
* freetdm
|
||||
*
|
||||
* Created by Shane Burrell on 4/3/08.
|
||||
* Copyright 2008 Shane Burrell. All rights reserved.
|
||||
@ -40,7 +40,7 @@
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include <m3ua_client.h>
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ static int create_conn_socket(m3uac_connection_t *mcon, char *local_ip, int loca
|
||||
memset(&mcon->local_hp, 0, sizeof(mcon->local_hp));
|
||||
mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "Creating L=%s:%d R=%s:%d\n",
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Creating L=%s:%d R=%s:%d\n",
|
||||
local_ip,local_port,ip,port);
|
||||
|
||||
if (mcon->socket >= 0) {
|
||||
@ -115,7 +115,7 @@ static int create_conn_socket(m3uac_connection_t *mcon, char *local_ip, int loca
|
||||
}
|
||||
}
|
||||
|
||||
zap_mutex_create(&mcon->mutex);
|
||||
ftdm_mutex_create(&mcon->mutex);
|
||||
|
||||
return mcon->socket;
|
||||
}
|
||||
@ -126,9 +126,9 @@ int m3uac_connection_close(m3uac_connection_t *mcon)
|
||||
close(mcon->socket);
|
||||
}
|
||||
|
||||
zap_mutex_lock(mcon->mutex);
|
||||
zap_mutex_unlock(mcon->mutex);
|
||||
zap_mutex_destroy(&mcon->mutex);
|
||||
ftdm_mutex_lock(mcon->mutex);
|
||||
ftdm_mutex_unlock(mcon->mutex);
|
||||
ftdm_mutex_destroy(&mcon->mutex);
|
||||
memset(mcon, 0, sizeof(*mcon));
|
||||
mcon->socket = -1;
|
||||
|
||||
@ -163,11 +163,11 @@ int m3uac_exec_command(m3uac_connection_t *mcon, int span, int chan, int id, int
|
||||
|
||||
while (m3uac_connection_write(mcon, &oevent) <= 0) {
|
||||
if (--retry <= 0) {
|
||||
zap_log(ZAP_LOG_CRIT, "Failed to tx on M3UA socket: %s\n", strerror(errno));
|
||||
ftdm_log(FTDM_LOG_CRIT, "Failed to tx on M3UA socket: %s\n", strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
zap_log(ZAP_LOG_WARNING, "Failed to tx on M3UA socket: %s :retry %i\n", strerror(errno), retry);
|
||||
zap_sleep(1);
|
||||
ftdm_log(FTDM_LOG_WARNING, "Failed to tx on M3UA socket: %s :retry %i\n", strerror(errno), retry);
|
||||
ftdm_sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,12 +188,12 @@ m3uac_event_t *m3uac_connection_read(m3uac_connection_t *mcon, int iteration)
|
||||
|
||||
if (mcon->rxseq_reset) {
|
||||
if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Rx sync ok\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Rx sync ok\n");
|
||||
mcon->rxseq = mcon->event.fseqno;
|
||||
return &mcon->event;
|
||||
}
|
||||
errno=EAGAIN;
|
||||
zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Waiting for rx sync...\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -201,14 +201,14 @@ m3uac_event_t *m3uac_connection_read(m3uac_connection_t *mcon, int iteration)
|
||||
mcon->rxseq++;
|
||||
|
||||
if (mcon->rxseq != mcon->event.fseqno) {
|
||||
zap_log(ZAP_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno);
|
||||
ftdm_log(FTDM_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &mcon->event;
|
||||
} else {
|
||||
if (iteration == 0) {
|
||||
zap_log(ZAP_LOG_CRIT, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
ftdm_log(FTDM_LOG_CRIT, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,7 @@ m3uac_event_t *m3uac_connection_readp(m3uac_connection_t *mcon, int iteration)
|
||||
return &mcon->event;
|
||||
} else {
|
||||
if (iteration == 0) {
|
||||
zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
ftdm_log(FTDM_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -241,28 +241,28 @@ int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_event_t *event)
|
||||
int err;
|
||||
|
||||
if (!event || mcon->socket < 0 || !mcon->mutex) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Critical Error: No Event Device\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (event->span > 16 || event->chan > 31) {
|
||||
zap_log(ZAP_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", m3uac_event_id_name(event->event_id), event->span,event->chan);
|
||||
ftdm_log(FTDM_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", m3uac_event_id_name(event->event_id), event->span,event->chan);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gettimeofday(&event->tv,NULL);
|
||||
|
||||
zap_mutex_lock(mcon->mutex);
|
||||
ftdm_mutex_lock(mcon->mutex);
|
||||
event->fseqno = mcon->txseq++;
|
||||
event->bseqno = mcon->rxseq;
|
||||
err = sendto(mcon->socket, event, sizeof(m3uac_event_t), 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr));
|
||||
zap_mutex_unlock(mcon->mutex);
|
||||
ftdm_mutex_unlock(mcon->mutex);
|
||||
|
||||
if (err != sizeof(m3uac_event_t)) {
|
||||
err = -1;
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n",
|
||||
ftdm_log(FTDM_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n",
|
||||
m3uac_event_id_name(event->event_id),
|
||||
event->event_id,
|
||||
event->span+1,
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* m3ua_client.h
|
||||
* openzap
|
||||
* freetdm
|
||||
*
|
||||
* Created by Shane Burrell on 4/3/08.
|
||||
* Copyright 2008 Shane Burrell. All rights reserved.
|
||||
@ -109,14 +109,14 @@ typedef struct m3uac_ip_cfg
|
||||
}m3uac_ip_cfg_t;
|
||||
|
||||
struct m3uac_connection {
|
||||
zap_socket_t socket;
|
||||
ftdm_socket_t socket;
|
||||
struct sockaddr_in local_addr;
|
||||
struct sockaddr_in remote_addr;
|
||||
m3uac_event_t event;
|
||||
struct hostent remote_hp;
|
||||
struct hostent local_hp;
|
||||
unsigned int flags;
|
||||
zap_mutex_t *mutex;
|
||||
ftdm_mutex_t *mutex;
|
||||
FILE *log;
|
||||
unsigned int txseq;
|
||||
unsigned int rxseq;
|
||||
|
@ -1,977 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "zap_analog.h"
|
||||
|
||||
#ifndef localtime_r
|
||||
struct tm * localtime_r(const time_t *clock, struct tm *result);
|
||||
#endif
|
||||
|
||||
static void *zap_analog_channel_run(zap_thread_t *me, void *obj);
|
||||
|
||||
/**
|
||||
* \brief Starts an FXO channel thread (outgoing call)
|
||||
* \param zchan Channel to initiate call on
|
||||
* \return Success or failure
|
||||
*
|
||||
* Initialises state, starts tone progress detection and runs the channel in a new a thread.
|
||||
*/
|
||||
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call)
|
||||
{
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
|
||||
zap_channel_clear_needed_tones(zchan);
|
||||
zap_channel_clear_detected_tones(zchan);
|
||||
|
||||
zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
|
||||
zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL);
|
||||
zchan->needed_tones[ZAP_TONEMAP_DIAL] = 1;
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING);
|
||||
zap_thread_create_detached(zap_analog_channel_run, zchan);
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Starts an FXS channel thread (outgoing call)
|
||||
* \param zchan Channel to initiate call on
|
||||
* \return Success or failure
|
||||
*
|
||||
* Indicates call waiting if channel is already in use, otherwise runs the channel in a new thread.
|
||||
*/
|
||||
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call)
|
||||
{
|
||||
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CALLWAITING);
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_GENRING);
|
||||
zap_thread_create_detached(zap_analog_channel_run, zchan);
|
||||
}
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Starts an analog span thread (monitor)
|
||||
* \param span Span to monitor
|
||||
* \return Success or failure
|
||||
*/
|
||||
static zap_status_t zap_analog_start(zap_span_t *span)
|
||||
{
|
||||
zap_analog_data_t *analog_data = span->signal_data;
|
||||
zap_set_flag(analog_data, ZAP_ANALOG_RUNNING);
|
||||
return zap_thread_create_detached(zap_analog_run, span);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialises an analog span from configuration variables
|
||||
* \param span Span to configure
|
||||
* \param sig_cb Callback function for event signals
|
||||
* \param ap List of configuration variables
|
||||
* \return Success or failure
|
||||
*/
|
||||
static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span)
|
||||
//zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
|
||||
{
|
||||
zap_analog_data_t *analog_data;
|
||||
const char *tonemap = "us";
|
||||
const char *hotline = "";
|
||||
uint32_t digit_timeout = 10;
|
||||
uint32_t max_dialstr = MAX_DTMF;
|
||||
const char *var, *val;
|
||||
int *intval;
|
||||
uint32_t flags = ZAP_ANALOG_CALLERID;
|
||||
|
||||
assert(sig_cb != NULL);
|
||||
|
||||
if (span->signal_type) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling.");
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
analog_data = zap_malloc(sizeof(*analog_data));
|
||||
assert(analog_data != NULL);
|
||||
memset(analog_data, 0, sizeof(*analog_data));
|
||||
|
||||
while ((var = va_arg(ap, char *))) {
|
||||
if (!strcasecmp(var, "tonemap")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
tonemap = val;
|
||||
} else if (!strcasecmp(var, "digit_timeout")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
digit_timeout = *intval;
|
||||
} else if (!strcasecmp(var, "enable_callerid")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (zap_true(val)) {
|
||||
flags |= ZAP_ANALOG_CALLERID;
|
||||
} else {
|
||||
flags &= ~ZAP_ANALOG_CALLERID;
|
||||
}
|
||||
} else if (!strcasecmp(var, "max_dialstr")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
max_dialstr = *intval;
|
||||
} else if (!strcasecmp(var, "hotline")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
hotline = val;
|
||||
} else {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (digit_timeout < 2000 || digit_timeout > 10000) {
|
||||
digit_timeout = 2000;
|
||||
}
|
||||
|
||||
if ((max_dialstr < 1 && !strlen(hotline)) || max_dialstr > MAX_DTMF) {
|
||||
max_dialstr = MAX_DTMF;
|
||||
}
|
||||
|
||||
span->start = zap_analog_start;
|
||||
analog_data->flags = flags;
|
||||
analog_data->digit_timeout = digit_timeout;
|
||||
analog_data->max_dialstr = max_dialstr;
|
||||
analog_data->sig_cb = sig_cb;
|
||||
strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline));
|
||||
span->signal_type = ZAP_SIGTYPE_ANALOG;
|
||||
span->signal_data = analog_data;
|
||||
span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call;
|
||||
zap_span_load_tones(span, tonemap);
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieves tone generation output to be sent
|
||||
* \param ts Teletone generator
|
||||
* \param map Tone map
|
||||
* \return -1 on error, 0 on success
|
||||
*/
|
||||
static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
|
||||
{
|
||||
zap_buffer_t *dt_buffer = ts->user_data;
|
||||
int wrote;
|
||||
|
||||
if (!dt_buffer) {
|
||||
return -1;
|
||||
}
|
||||
wrote = teletone_mux_tones(ts, map);
|
||||
zap_buffer_write(dt_buffer, ts->buffer, wrote * 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends caller id on an analog channel (FSK coded)
|
||||
* \param zchan Channel to send caller id on
|
||||
*/
|
||||
static void send_caller_id(zap_channel_t *zchan)
|
||||
{
|
||||
zap_fsk_data_state_t fsk_data;
|
||||
uint8_t databuf[1024] = "";
|
||||
char time_str[9];
|
||||
struct tm tm;
|
||||
time_t now;
|
||||
zap_mdmf_type_t mt = MDMF_INVALID;
|
||||
|
||||
time(&now);
|
||||
#ifdef WIN32
|
||||
_tzset();
|
||||
_localtime64_s(&tm, &now);
|
||||
#else
|
||||
localtime_r(&now, &tm);
|
||||
#endif
|
||||
strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm);
|
||||
|
||||
zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf));
|
||||
zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *) time_str, 8);
|
||||
|
||||
if (zap_strlen_zero(zchan->caller_data.cid_num.digits)) {
|
||||
mt = MDMF_NO_NUM;
|
||||
zap_set_string(zchan->caller_data.cid_num.digits, "O");
|
||||
} else if (!strcasecmp(zchan->caller_data.cid_num.digits, "P") || !strcasecmp(zchan->caller_data.cid_num.digits, "O")) {
|
||||
mt = MDMF_NO_NUM;
|
||||
} else {
|
||||
mt = MDMF_PHONE_NUM;
|
||||
}
|
||||
zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_num.digits, (uint8_t)strlen(zchan->caller_data.cid_num.digits));
|
||||
|
||||
if (zap_strlen_zero(zchan->caller_data.cid_name)) {
|
||||
mt = MDMF_NO_NAME;
|
||||
zap_set_string(zchan->caller_data.cid_name, "O");
|
||||
} else if (!strcasecmp(zchan->caller_data.cid_name, "P") || !strcasecmp(zchan->caller_data.cid_name, "O")) {
|
||||
mt = MDMF_NO_NAME;
|
||||
} else {
|
||||
mt = MDMF_PHONE_NAME;
|
||||
}
|
||||
zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_name, (uint8_t)strlen(zchan->caller_data.cid_name));
|
||||
|
||||
zap_fsk_data_add_checksum(&fsk_data);
|
||||
zap_channel_send_fsk_data(zchan, &fsk_data, -14);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for analog channel (outgoing call)
|
||||
* \param me Current thread
|
||||
* \param obj Channel to run in this thread
|
||||
*/
|
||||
static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
|
||||
{
|
||||
zap_channel_t *zchan = (zap_channel_t *) obj;
|
||||
zap_buffer_t *dt_buffer = NULL;
|
||||
teletone_generation_session_t ts;
|
||||
uint8_t frame[1024];
|
||||
zap_size_t len, rlen;
|
||||
zap_tone_type_t tt = ZAP_TONE_DTMF;
|
||||
char dtmf[MAX_DTMF+1] = "";
|
||||
zap_size_t dtmf_offset = 0;
|
||||
zap_analog_data_t *analog_data = zchan->span->signal_data;
|
||||
zap_channel_t *closed_chan;
|
||||
uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000;
|
||||
zap_sigmsg_t sig;
|
||||
zap_status_t status;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n");
|
||||
|
||||
ts.buffer = NULL;
|
||||
|
||||
if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!");
|
||||
zap_log(ZAP_LOG_ERROR, "MEM ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!");
|
||||
zap_log(ZAP_LOG_ERROR, "TONE ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD);
|
||||
teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
|
||||
ts.rate = 8000;
|
||||
#if 0
|
||||
ts.debug = 1;
|
||||
ts.debug_stream = stdout;
|
||||
#endif
|
||||
zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval);
|
||||
zap_buffer_set_loops(dt_buffer, -1);
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = zchan->chan_id;
|
||||
sig.span_id = zchan->span_id;
|
||||
sig.channel = zchan;
|
||||
|
||||
assert(interval != 0);
|
||||
|
||||
while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
|
||||
zap_wait_flag_t flags = ZAP_READ;
|
||||
zap_size_t dlen = 0;
|
||||
|
||||
len = sizeof(frame);
|
||||
|
||||
elapsed += interval;
|
||||
state_counter += interval;
|
||||
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) {
|
||||
switch(zchan->state) {
|
||||
case ZAP_CHANNEL_STATE_GET_CALLERID:
|
||||
{
|
||||
if (state_counter > 5000 || !zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_DISABLE_CALLERID_DETECT, NULL);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
if (state_counter > dial_timeout) {
|
||||
if (zchan->needed_tones[ZAP_TONEMAP_DIAL]) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_GENRING:
|
||||
{
|
||||
if (state_counter > 60000) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
} else if (!zchan->fsk_buffer || !zap_buffer_inuse(zchan->fsk_buffer)) {
|
||||
zap_sleep(interval);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_HOLD) && state_counter > 10000) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_HANGUP:
|
||||
{
|
||||
if (state_counter > 500) {
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) &&
|
||||
(zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE
|
||||
|| zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING;
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_CALLWAITING:
|
||||
{
|
||||
int done = 0;
|
||||
|
||||
if (zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] == 1) {
|
||||
send_caller_id(zchan);
|
||||
zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++;
|
||||
} else if (state_counter > 600 && !zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) {
|
||||
send_caller_id(zchan);
|
||||
zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++;
|
||||
} else if (state_counter > 1000 && !zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) {
|
||||
done = 1;
|
||||
} else if (state_counter > 10000) {
|
||||
if (zchan->fsk_buffer) {
|
||||
zap_buffer_zero(zchan->fsk_buffer);
|
||||
} else {
|
||||
zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0);
|
||||
}
|
||||
|
||||
ts.user_data = zchan->fsk_buffer;
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]);
|
||||
ts.user_data = dt_buffer;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
|
||||
zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
|
||||
zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
|
||||
zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0;
|
||||
}
|
||||
}
|
||||
case ZAP_CHANNEL_STATE_UP:
|
||||
case ZAP_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
zap_sleep(interval);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
|
||||
zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
|
||||
zap_channel_complete_state(zchan);
|
||||
indicate = 0;
|
||||
state_counter = 0;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n",
|
||||
zchan->span_id, zchan->chan_id,
|
||||
zap_channel_state2str(zchan->state));
|
||||
switch(zchan->state) {
|
||||
case ZAP_CHANNEL_STATE_UP:
|
||||
{
|
||||
zap_channel_use(zchan);
|
||||
zap_channel_clear_needed_tones(zchan);
|
||||
zap_channel_flush_dtmf(zchan);
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
|
||||
}
|
||||
|
||||
if (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer)) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Cancel FSK transmit due to early answer.\n");
|
||||
zap_buffer_zero(zchan->fsk_buffer);
|
||||
}
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
if (zchan->token_count == 1) {
|
||||
zap_clear_flag(zchan, ZAP_CHANNEL_HOLD);
|
||||
}
|
||||
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_HOLD)) {
|
||||
zap_clear_flag(zchan, ZAP_CHANNEL_HOLD);
|
||||
sig.event_id = ZAP_SIGEVENT_ADD_CALL;
|
||||
} else {
|
||||
sig.event_id = ZAP_SIGEVENT_UP;
|
||||
}
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
zap_channel_use(zchan);
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
zap_channel_use(zchan);
|
||||
sig.event_id = ZAP_SIGEVENT_START;
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXO) {
|
||||
zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number);
|
||||
} else {
|
||||
zap_set_string(zchan->caller_data.dnis.digits, dtmf);
|
||||
}
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
sig.event_id = ZAP_SIGEVENT_STOP;
|
||||
analog_data->sig_cb(&sig);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
|
||||
*dtmf = '\0';
|
||||
dtmf_offset = 0;
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]);
|
||||
indicate = 1;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_CALLWAITING:
|
||||
{
|
||||
zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0;
|
||||
if (zchan->fsk_buffer) {
|
||||
zap_buffer_zero(zchan->fsk_buffer);
|
||||
} else {
|
||||
zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0);
|
||||
}
|
||||
|
||||
ts.user_data = zchan->fsk_buffer;
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_CAS]);
|
||||
ts.user_data = dt_buffer;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_GENRING:
|
||||
{
|
||||
zap_sigmsg_t sig;
|
||||
|
||||
send_caller_id(zchan);
|
||||
zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_ON, NULL);
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = zchan->chan_id;
|
||||
sig.span_id = zchan->span_id;
|
||||
sig.channel = zchan;
|
||||
sig.event_id = ZAP_SIGEVENT_PROGRESS;
|
||||
analog_data->sig_cb(&sig);
|
||||
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_GET_CALLERID:
|
||||
{
|
||||
memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
|
||||
zap_channel_command(zchan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_RING:
|
||||
{
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]);
|
||||
indicate = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION;
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) {
|
||||
if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {
|
||||
|
||||
if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT);
|
||||
collecting = 1;
|
||||
}
|
||||
dtmf_offset = strlen(dtmf);
|
||||
last_digit = elapsed;
|
||||
sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT;
|
||||
sig.raw_data = dtmf;
|
||||
if (analog_data->sig_cb(&sig) == ZAP_BREAK) {
|
||||
collecting = 0;
|
||||
}
|
||||
}
|
||||
else if(!analog_data->max_dialstr)
|
||||
{
|
||||
last_digit = elapsed;
|
||||
collecting = 0;
|
||||
strcpy(dtmf, analog_data->hotline);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) >= analog_data->max_dialstr))) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
|
||||
last_digit = 0;
|
||||
collecting = 0;
|
||||
}
|
||||
|
||||
if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(flags & ZAP_READ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXO && zchan->detected_tones[0]) {
|
||||
zap_sigmsg_t sig;
|
||||
int i;
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = zchan->chan_id;
|
||||
sig.span_id = zchan->span_id;
|
||||
sig.channel = zchan;
|
||||
sig.event_id = ZAP_SIGEVENT_TONE_DETECTED;
|
||||
|
||||
for (i = 1; i < ZAP_TONEMAP_INVALID; i++) {
|
||||
if (zchan->detected_tones[i]) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id);
|
||||
sig.raw_data = &i;
|
||||
if (analog_data->sig_cb) {
|
||||
analog_data->sig_cb(&sig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zchan->detected_tones[ZAP_TONEMAP_BUSY] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_FAIL1] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_FAIL2] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_FAIL3] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_ATTN]
|
||||
) {
|
||||
zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n");
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else if (zchan->detected_tones[ZAP_TONEMAP_DIAL]) {
|
||||
if (zap_strlen_zero(zchan->caller_data.ani.digits)) {
|
||||
zap_log(ZAP_LOG_ERROR, "No Digits to send!\n");
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
state_counter = 0;
|
||||
zchan->needed_tones[ZAP_TONEMAP_RING] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1;
|
||||
dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000;
|
||||
}
|
||||
}
|
||||
} else if (zchan->detected_tones[ZAP_TONEMAP_RING]) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
|
||||
}
|
||||
|
||||
zap_channel_clear_detected_tones(zchan);
|
||||
}
|
||||
|
||||
if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer)) || (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer))) {
|
||||
//rlen = len;
|
||||
//memset(frame, 0, len);
|
||||
//zap_channel_write(zchan, frame, sizeof(frame), &rlen);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!indicate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
|
||||
}
|
||||
|
||||
if (zchan->effective_codec != ZAP_CODEC_SLIN) {
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
rlen = zap_buffer_read_loop(dt_buffer, frame, len);
|
||||
|
||||
if (zchan->effective_codec != ZAP_CODEC_SLIN) {
|
||||
zio_codec_t codec_func = NULL;
|
||||
|
||||
if (zchan->native_codec == ZAP_CODEC_ULAW) {
|
||||
codec_func = zio_slin2ulaw;
|
||||
} else if (zchan->native_codec == ZAP_CODEC_ALAW) {
|
||||
codec_func = zio_slin2alaw;
|
||||
}
|
||||
|
||||
if (codec_func) {
|
||||
status = codec_func(frame, sizeof(frame), &rlen);
|
||||
} else {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
zap_channel_write(zchan, frame, sizeof(frame), &rlen);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL);
|
||||
}
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
|
||||
closed_chan = zchan;
|
||||
zap_channel_close(&zchan);
|
||||
|
||||
zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL);
|
||||
|
||||
if (ts.buffer) {
|
||||
teletone_destroy_session(&ts);
|
||||
}
|
||||
|
||||
if (dt_buffer) {
|
||||
zap_buffer_destroy(&dt_buffer);
|
||||
}
|
||||
|
||||
if (closed_chan->state != ZAP_CHANNEL_STATE_DOWN) {
|
||||
zap_set_state_locked(closed_chan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL %d:%d thread ended.\n", closed_chan->span_id, closed_chan->chan_id);
|
||||
zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Processes openzap event
|
||||
* \param span Span on which the event was fired
|
||||
* \param event Event to be treated
|
||||
* \return Success or failure
|
||||
*/
|
||||
static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event)
|
||||
{
|
||||
zap_sigmsg_t sig;
|
||||
zap_analog_data_t *analog_data = event->channel->span->signal_data;
|
||||
int locked = 0;
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = event->channel->chan_id;
|
||||
sig.span_id = event->channel->span_id;
|
||||
sig.channel = event->channel;
|
||||
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n",
|
||||
zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state));
|
||||
|
||||
zap_mutex_lock(event->channel->mutex);
|
||||
locked++;
|
||||
|
||||
switch(event->enum_id) {
|
||||
case ZAP_OOB_RING_START:
|
||||
{
|
||||
if (event->channel->type != ZAP_CHAN_TYPE_FXO) {
|
||||
zap_log(ZAP_LOG_ERROR, "Cannot get a RING_START event on a non-fxo channel, please check your config.\n");
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
|
||||
goto end;
|
||||
}
|
||||
if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) {
|
||||
if (zap_test_flag(analog_data, ZAP_ANALOG_CALLERID)) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID);
|
||||
} else {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_IDLE);
|
||||
}
|
||||
event->channel->ring_count = 1;
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
zap_thread_create_detached(zap_analog_channel_run, event->channel);
|
||||
} else {
|
||||
event->channel->ring_count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_OOB_ONHOOK:
|
||||
{
|
||||
if (zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) {
|
||||
zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
|
||||
if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case ZAP_OOB_FLASH:
|
||||
{
|
||||
if (event->channel->state == ZAP_CHANNEL_STATE_CALLWAITING) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
|
||||
zap_clear_flag_locked(event->channel, ZAP_CHANNEL_STATE_CHANGE);
|
||||
zap_clear_flag_locked(event->channel->span, ZAP_SPAN_STATE_CHANGE);
|
||||
event->channel->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0;
|
||||
}
|
||||
|
||||
zap_channel_rotate_tokens(event->channel);
|
||||
|
||||
if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD) && event->channel->token_count != 1) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
|
||||
} else {
|
||||
sig.event_id = ZAP_SIGEVENT_FLASH;
|
||||
analog_data->sig_cb(&sig);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_OOB_OFFHOOK:
|
||||
{
|
||||
if (event->channel->type == ZAP_CHAN_TYPE_FXS) {
|
||||
if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) {
|
||||
if (zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) {
|
||||
zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
|
||||
}
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
|
||||
} else {
|
||||
if(!analog_data->max_dialstr) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_COLLECT);
|
||||
} else {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE);
|
||||
}
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
zap_thread_create_detached(zap_analog_channel_run, event->channel);
|
||||
}
|
||||
} else {
|
||||
if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) {
|
||||
if (zap_test_flag(event->channel, ZAP_CHANNEL_OFFHOOK)) {
|
||||
zap_channel_command(event->channel, ZAP_COMMAND_ONHOOK, NULL);
|
||||
}
|
||||
}
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
if (locked) {
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
}
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for analog span (monitor)
|
||||
* \param me Current thread
|
||||
* \param obj Span to run in this thread
|
||||
*/
|
||||
static void *zap_analog_run(zap_thread_t *me, void *obj)
|
||||
{
|
||||
zap_span_t *span = (zap_span_t *) obj;
|
||||
zap_analog_data_t *analog_data = span->signal_data;
|
||||
int errs = 0;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n");
|
||||
|
||||
while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) {
|
||||
int waitms = 1000;
|
||||
zap_status_t status;
|
||||
|
||||
if ((status = zap_span_poll_event(span, waitms)) != ZAP_FAIL) {
|
||||
errs = 0;
|
||||
}
|
||||
|
||||
switch(status) {
|
||||
case ZAP_SUCCESS:
|
||||
{
|
||||
zap_event_t *event;
|
||||
while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
|
||||
if (event->enum_id == ZAP_OOB_NOOP) {
|
||||
continue;
|
||||
}
|
||||
if (process_event(span, event) != ZAP_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_FAIL:
|
||||
{
|
||||
zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error);
|
||||
if (++errs > 300) {
|
||||
zap_log(ZAP_LOG_CRIT, "Too Many Errors!\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
zap_clear_flag(analog_data, ZAP_ANALOG_RUNNING);
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG thread ending.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openzap analog signaling module initialisation
|
||||
* \return Success
|
||||
*/
|
||||
static ZIO_SIG_LOAD_FUNCTION(zap_analog_init)
|
||||
{
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openzap analog signaling module definition
|
||||
*/
|
||||
EX_DECLARE_DATA zap_module_t zap_module = {
|
||||
"analog",
|
||||
NULL,
|
||||
NULL,
|
||||
zap_analog_init,
|
||||
zap_analog_configure_span,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
@ -1,709 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* John Wehle (john@feith.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "zap_analog_em.h"
|
||||
|
||||
#ifndef localtime_r
|
||||
struct tm * localtime_r(const time_t *clock, struct tm *result);
|
||||
#endif
|
||||
|
||||
static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj);
|
||||
|
||||
/**
|
||||
* \brief Starts an EM channel thread (outgoing call)
|
||||
* \param zchan Channel to initiate call on
|
||||
* \return Success or failure
|
||||
*
|
||||
* Initialises state, starts tone progress detection and runs the channel in a new a thread.
|
||||
*/
|
||||
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call)
|
||||
{
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
|
||||
zap_channel_clear_needed_tones(zchan);
|
||||
zap_channel_clear_detected_tones(zchan);
|
||||
|
||||
zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
|
||||
|
||||
zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
|
||||
zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING);
|
||||
zap_thread_create_detached(zap_analog_em_channel_run, zchan);
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Starts an EM span thread (monitor)
|
||||
* \param span Span to monitor
|
||||
* \return Success or failure
|
||||
*/
|
||||
static zap_status_t zap_analog_em_start(zap_span_t *span)
|
||||
{
|
||||
zap_analog_em_data_t *analog_data = span->signal_data;
|
||||
zap_set_flag(analog_data, ZAP_ANALOG_EM_RUNNING);
|
||||
return zap_thread_create_detached(zap_analog_em_run, span);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialises an EM span from configuration variables
|
||||
* \param span Span to configure
|
||||
* \param sig_cb Callback function for event signals
|
||||
* \param ap List of configuration variables
|
||||
* \return Success or failure
|
||||
*/
|
||||
static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span)
|
||||
//zap_status_t zap_analog_em_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
|
||||
{
|
||||
zap_analog_em_data_t *analog_data;
|
||||
const char *tonemap = "us";
|
||||
uint32_t digit_timeout = 10;
|
||||
uint32_t max_dialstr = 11;
|
||||
const char *var, *val;
|
||||
int *intval;
|
||||
|
||||
assert(sig_cb != NULL);
|
||||
|
||||
if (span->signal_type) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling.");
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
analog_data = zap_malloc(sizeof(*analog_data));
|
||||
assert(analog_data != NULL);
|
||||
memset(analog_data, 0, sizeof(*analog_data));
|
||||
|
||||
while((var = va_arg(ap, char *))) {
|
||||
if (!strcasecmp(var, "tonemap")) {
|
||||
if (!(val = va_arg(ap, char *))) {
|
||||
break;
|
||||
}
|
||||
tonemap = val;
|
||||
} else if (!strcasecmp(var, "digit_timeout")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
digit_timeout = *intval;
|
||||
} else if (!strcasecmp(var, "max_dialstr")) {
|
||||
if (!(intval = va_arg(ap, int *))) {
|
||||
break;
|
||||
}
|
||||
max_dialstr = *intval;
|
||||
} else {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (digit_timeout < 2000 || digit_timeout > 10000) {
|
||||
digit_timeout = 2000;
|
||||
}
|
||||
|
||||
if (max_dialstr < 2 || max_dialstr > MAX_DIALSTRING) {
|
||||
zap_log(ZAP_LOG_ERROR, "Invalid max_dialstr, setting to %d\n", MAX_DIALSTRING);
|
||||
max_dialstr = MAX_DIALSTRING;
|
||||
}
|
||||
|
||||
span->start = zap_analog_em_start;
|
||||
analog_data->digit_timeout = digit_timeout;
|
||||
analog_data->max_dialstr = max_dialstr;
|
||||
analog_data->sig_cb = sig_cb;
|
||||
span->signal_type = ZAP_SIGTYPE_ANALOG;
|
||||
span->signal_data = analog_data;
|
||||
span->outgoing_call = analog_em_outgoing_call;
|
||||
zap_span_load_tones(span, tonemap);
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieves tone generation output to be sent
|
||||
* \param ts Teletone generator
|
||||
* \param map Tone map
|
||||
* \return -1 on error, 0 on success
|
||||
*/
|
||||
static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
|
||||
{
|
||||
zap_buffer_t *dt_buffer = ts->user_data;
|
||||
int wrote;
|
||||
|
||||
if (!dt_buffer) {
|
||||
return -1;
|
||||
}
|
||||
wrote = teletone_mux_tones(ts, map);
|
||||
zap_buffer_write(dt_buffer, ts->buffer, wrote * 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for EM channel (outgoing call)
|
||||
* \param me Current thread
|
||||
* \param obj Channel to run in this thread
|
||||
*/
|
||||
static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj)
|
||||
{
|
||||
zap_channel_t *zchan = (zap_channel_t *) obj;
|
||||
zap_buffer_t *dt_buffer = NULL;
|
||||
teletone_generation_session_t ts;
|
||||
uint8_t frame[1024];
|
||||
zap_size_t len, rlen;
|
||||
zap_tone_type_t tt = ZAP_TONE_DTMF;
|
||||
char dtmf[128] = "";
|
||||
zap_size_t dtmf_offset = 0;
|
||||
zap_analog_em_data_t *analog_data = zchan->span->signal_data;
|
||||
zap_channel_t *closed_chan;
|
||||
uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000;
|
||||
zap_sigmsg_t sig;
|
||||
zap_status_t status;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread starting.\n");
|
||||
|
||||
ts.buffer = NULL;
|
||||
|
||||
if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!");
|
||||
zap_log(ZAP_LOG_ERROR, "MEM ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!");
|
||||
zap_log(ZAP_LOG_ERROR, "TONE ERROR\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD);
|
||||
teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
|
||||
ts.rate = 8000;
|
||||
#if 0
|
||||
ts.debug = 1;
|
||||
ts.debug_stream = stdout;
|
||||
#endif
|
||||
zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval);
|
||||
zap_buffer_set_loops(dt_buffer, -1);
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = zchan->chan_id;
|
||||
sig.span_id = zchan->span_id;
|
||||
sig.channel = zchan;
|
||||
|
||||
assert(interval != 0);
|
||||
|
||||
while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
|
||||
zap_wait_flag_t flags = ZAP_READ;
|
||||
zap_size_t dlen = 0;
|
||||
|
||||
len = sizeof(frame);
|
||||
|
||||
elapsed += interval;
|
||||
state_counter += interval;
|
||||
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) {
|
||||
switch(zchan->state) {
|
||||
case ZAP_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
if (! zchan->needed_tones[ZAP_TONEMAP_RING]
|
||||
&& zap_test_flag(zchan, ZAP_CHANNEL_WINK)) {
|
||||
if (zap_strlen_zero(zchan->caller_data.ani.digits)) {
|
||||
zap_log(ZAP_LOG_ERROR, "No Digits to send!\n");
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
state_counter = 0;
|
||||
zchan->needed_tones[ZAP_TONEMAP_RING] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1;
|
||||
dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (state_counter > dial_timeout) {
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_WINK)) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
if (state_counter > 10000) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (state_counter > 20000) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_HANGUP:
|
||||
{
|
||||
if (state_counter > 500) {
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) &&
|
||||
(zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE
|
||||
|| zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else {
|
||||
zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING;
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_UP:
|
||||
case ZAP_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
zap_sleep(interval);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
|
||||
zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
|
||||
zap_channel_complete_state(zchan);
|
||||
indicate = 0;
|
||||
state_counter = 0;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n",
|
||||
zchan->span_id, zchan->chan_id,
|
||||
zap_channel_state2str(zchan->state));
|
||||
switch(zchan->state) {
|
||||
case ZAP_CHANNEL_STATE_UP:
|
||||
{
|
||||
zap_channel_use(zchan);
|
||||
zap_channel_clear_needed_tones(zchan);
|
||||
zap_channel_flush_dtmf(zchan);
|
||||
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
|
||||
}
|
||||
|
||||
sig.event_id = ZAP_SIGEVENT_UP;
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALING:
|
||||
{
|
||||
zap_channel_use(zchan);
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_IDLE:
|
||||
{
|
||||
zap_channel_use(zchan);
|
||||
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number);
|
||||
} else {
|
||||
zap_set_string(zchan->caller_data.dnis.digits, dtmf);
|
||||
}
|
||||
|
||||
sig.event_id = ZAP_SIGEVENT_START;
|
||||
|
||||
analog_data->sig_cb(&sig);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DOWN:
|
||||
{
|
||||
sig.event_id = ZAP_SIGEVENT_STOP;
|
||||
analog_data->sig_cb(&sig);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_DIALTONE:
|
||||
{
|
||||
memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
|
||||
*dtmf = '\0';
|
||||
dtmf_offset = 0;
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]);
|
||||
indicate = 1;
|
||||
|
||||
zap_channel_command(zchan, ZAP_COMMAND_WINK, NULL);
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_RING:
|
||||
{
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]);
|
||||
indicate = 1;
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_BUSY:
|
||||
{
|
||||
zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION;
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_CHANNEL_STATE_ATTN:
|
||||
{
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||
zap_buffer_zero(dt_buffer);
|
||||
teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]);
|
||||
indicate = 1;
|
||||
} else {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) {
|
||||
if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {
|
||||
|
||||
if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT);
|
||||
collecting = 1;
|
||||
}
|
||||
dtmf_offset = strlen(dtmf);
|
||||
last_digit = elapsed;
|
||||
sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT;
|
||||
sig.raw_data = dtmf;
|
||||
if (analog_data->sig_cb(&sig) == ZAP_BREAK) {
|
||||
collecting = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
|
||||
last_digit = 0;
|
||||
collecting = 0;
|
||||
}
|
||||
|
||||
if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(flags & ZAP_READ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zchan->detected_tones[0]) {
|
||||
zap_sigmsg_t sig;
|
||||
int i;
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = zchan->chan_id;
|
||||
sig.span_id = zchan->span_id;
|
||||
sig.channel = zchan;
|
||||
sig.event_id = ZAP_SIGEVENT_TONE_DETECTED;
|
||||
|
||||
for (i = 1; i < ZAP_TONEMAP_INVALID; i++) {
|
||||
if (zchan->detected_tones[i]) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id);
|
||||
sig.raw_data = &i;
|
||||
if (analog_data->sig_cb) {
|
||||
analog_data->sig_cb(&sig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zchan->detected_tones[ZAP_TONEMAP_BUSY] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_FAIL1] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_FAIL2] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_FAIL3] ||
|
||||
zchan->detected_tones[ZAP_TONEMAP_ATTN]
|
||||
) {
|
||||
zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n");
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
|
||||
} else if (zchan->detected_tones[ZAP_TONEMAP_RING]) {
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
|
||||
}
|
||||
|
||||
zap_channel_clear_detected_tones(zchan);
|
||||
}
|
||||
|
||||
if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer))) {
|
||||
rlen = len;
|
||||
memset(frame, 0, len);
|
||||
zap_channel_write(zchan, frame, sizeof(frame), &rlen);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!indicate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zchan->effective_codec != ZAP_CODEC_SLIN) {
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
rlen = zap_buffer_read_loop(dt_buffer, frame, len);
|
||||
|
||||
if (zchan->effective_codec != ZAP_CODEC_SLIN) {
|
||||
zio_codec_t codec_func = NULL;
|
||||
|
||||
if (zchan->native_codec == ZAP_CODEC_ULAW) {
|
||||
codec_func = zio_slin2ulaw;
|
||||
} else if (zchan->native_codec == ZAP_CODEC_ALAW) {
|
||||
codec_func = zio_slin2alaw;
|
||||
}
|
||||
|
||||
if (codec_func) {
|
||||
status = codec_func(frame, sizeof(frame), &rlen);
|
||||
} else {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
zap_channel_write(zchan, frame, sizeof(frame), &rlen);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL);
|
||||
|
||||
closed_chan = zchan;
|
||||
zap_channel_close(&zchan);
|
||||
|
||||
zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL);
|
||||
|
||||
if (ts.buffer) {
|
||||
teletone_destroy_session(&ts);
|
||||
}
|
||||
|
||||
if (dt_buffer) {
|
||||
zap_buffer_destroy(&dt_buffer);
|
||||
}
|
||||
|
||||
zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD);
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread ended.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Processes EM events coming from zaptel/dahdi
|
||||
* \param span Span on which the event was fired
|
||||
* \param event Event to be treated
|
||||
* \return Success or failure
|
||||
*/
|
||||
static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event)
|
||||
{
|
||||
zap_sigmsg_t sig;
|
||||
int locked = 0;
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = event->channel->chan_id;
|
||||
sig.span_id = event->channel->span_id;
|
||||
sig.channel = event->channel;
|
||||
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n",
|
||||
zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state));
|
||||
|
||||
zap_mutex_lock(event->channel->mutex);
|
||||
locked++;
|
||||
|
||||
switch(event->enum_id) {
|
||||
case ZAP_OOB_ONHOOK:
|
||||
{
|
||||
if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case ZAP_OOB_OFFHOOK:
|
||||
{
|
||||
if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
|
||||
} else {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE);
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
zap_thread_create_detached(zap_analog_em_channel_run, event->channel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ZAP_OOB_WINK:
|
||||
{
|
||||
if (event->channel->state != ZAP_CHANNEL_STATE_DIALING) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
|
||||
} else {
|
||||
zap_set_flag_locked(event->channel, ZAP_CHANNEL_WINK);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (locked) {
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
}
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Main thread function for EM span (monitor)
|
||||
* \param me Current thread
|
||||
* \param obj Span to run in this thread
|
||||
*/
|
||||
static void *zap_analog_em_run(zap_thread_t *me, void *obj)
|
||||
{
|
||||
zap_span_t *span = (zap_span_t *) obj;
|
||||
zap_analog_em_data_t *analog_data = span->signal_data;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG EM thread starting.\n");
|
||||
|
||||
while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_EM_RUNNING)) {
|
||||
int waitms = 10;
|
||||
zap_status_t status;
|
||||
|
||||
status = zap_span_poll_event(span, waitms);
|
||||
|
||||
switch(status) {
|
||||
case ZAP_SUCCESS:
|
||||
{
|
||||
zap_event_t *event;
|
||||
while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
|
||||
if (event->enum_id == ZAP_OOB_NOOP) {
|
||||
continue;
|
||||
}
|
||||
if (process_event(span, event) != ZAP_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZAP_FAIL:
|
||||
{
|
||||
zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
zap_clear_flag(analog_data, ZAP_ANALOG_EM_RUNNING);
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "ANALOG EM thread ending.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openzap analog EM module initialisation
|
||||
* \return Success
|
||||
*/
|
||||
static ZIO_SIG_LOAD_FUNCTION(zap_analog_em_init)
|
||||
{
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Openzap analog EM module definition
|
||||
*/
|
||||
EX_DECLARE_DATA zap_module_t zap_module = {
|
||||
"analog_em",
|
||||
NULL,
|
||||
NULL,
|
||||
zap_analog_em_init,
|
||||
zap_analog_em_configure_span,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
@ -13,7 +13,7 @@
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include <sangoma_pri.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
@ -33,9 +33,9 @@ typedef struct {
|
||||
|
||||
static call_info_t pidmap[SANGOMA_MAX_CHAN_PER_SPAN];
|
||||
|
||||
ZIO_EVENT_CB_FUNCTION(my_zap_event_handler)
|
||||
ZIO_EVENT_CB_FUNCTION(my_ftdm_event_handler)
|
||||
{
|
||||
if (event->e_type = ZAP_EVENT_DTMF) {
|
||||
if (event->e_type = FTDM_EVENT_DTMF) {
|
||||
char *dtmf = event->data;
|
||||
printf("DTMF %s\n", dtmf);
|
||||
}
|
||||
@ -64,12 +64,12 @@ static void launch_channel(struct sangoma_pri *spri, int channo)
|
||||
fd_set readfds;
|
||||
int mtu_mru=BYTES / 2;
|
||||
int err;
|
||||
zap_channel_t *chan;
|
||||
zap_codec_t codec = ZAP_CODEC_SLIN;
|
||||
ftdm_channel_t *chan;
|
||||
ftdm_codec_t codec = FTDM_CODEC_SLIN;
|
||||
unsigned ms = 20;
|
||||
unsigned int lead = 50;
|
||||
int ifd = -1;
|
||||
zap_tone_type_t tt = ZAP_TONE_DTMF;
|
||||
ftdm_tone_type_t tt = FTDM_TONE_DTMF;
|
||||
char dtmf[] = "1234567890";
|
||||
int loops = 0;
|
||||
|
||||
@ -88,47 +88,47 @@ static void launch_channel(struct sangoma_pri *spri, int channo)
|
||||
memset(inframe, 0, MAX_BYTES);
|
||||
memset(outframe, 0, MAX_BYTES);
|
||||
|
||||
if (zap_channel_open(spri->span, channo, &chan) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_open(spri->span, channo, &chan) != FTDM_SUCCESS) {
|
||||
printf("DEBUG cant open fd!\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 1
|
||||
if (zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_SET_CODEC, &codec) != FTDM_SUCCESS) {
|
||||
printf("Critical Error: Failed to set driver codec!\n");
|
||||
zap_channel_close(&chan);
|
||||
ftdm_channel_close(&chan);
|
||||
exit(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) {
|
||||
printf("Critical Error: Failed to set dtmf detect!\n");
|
||||
zap_channel_close(&chan);
|
||||
ftdm_channel_close(&chan);
|
||||
exit(-1);
|
||||
}
|
||||
zap_channel_set_event_callback(chan, my_zap_event_handler);
|
||||
ftdm_channel_set_event_callback(chan, my_ftdm_event_handler);
|
||||
#endif
|
||||
|
||||
|
||||
if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_SET_INTERVAL, &ms) != FTDM_SUCCESS) {
|
||||
printf("Critical Error: Failed to set codec interval!\n");
|
||||
zap_channel_close(&chan);
|
||||
ftdm_channel_close(&chan);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
file = open("sound.raw", O_RDONLY);
|
||||
if (file < 0){
|
||||
printf("Critical Error: Failed to open sound file!\n");
|
||||
zap_channel_close(&chan);
|
||||
ftdm_channel_close(&chan);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
while(ready) {
|
||||
zap_wait_flag_t flags = ZAP_READ;
|
||||
zap_size_t len;
|
||||
ftdm_wait_flag_t flags = FTDM_READ;
|
||||
ftdm_size_t len;
|
||||
loops++;
|
||||
|
||||
if (lead) {
|
||||
@ -137,23 +137,23 @@ static void launch_channel(struct sangoma_pri *spri, int channo)
|
||||
|
||||
if (!lead && loops == 300) {
|
||||
#if 1
|
||||
if (zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, dtmf) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_SEND_DTMF, dtmf) != FTDM_SUCCESS) {
|
||||
printf("Critical Error: Failed to send dtmf\n");
|
||||
zap_channel_close(&chan);
|
||||
ftdm_channel_close(&chan);
|
||||
exit(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
if (zap_channel_wait(chan, &flags, 2000) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_wait(chan, &flags, 2000) != FTDM_SUCCESS) {
|
||||
printf("wait FAIL! [%s]\n", chan->last_error);
|
||||
break;
|
||||
}
|
||||
|
||||
if (flags & ZAP_READ) {
|
||||
if (flags & FTDM_READ) {
|
||||
len = MAX_BYTES;
|
||||
if (zap_channel_read(chan, inframe, &len) == ZAP_SUCCESS) {
|
||||
if (ftdm_channel_read(chan, inframe, &len) == FTDM_SUCCESS) {
|
||||
//printf("READ: %d\n", len);
|
||||
//write(ifd, inframe, len);
|
||||
if(!lead && (outlen = read(file, outframe, len)) <= 0) {
|
||||
@ -167,7 +167,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo)
|
||||
if (lead) {
|
||||
continue;
|
||||
}
|
||||
zap_channel_write(chan, outframe, sizeof(outframe), &len);
|
||||
ftdm_channel_write(chan, outframe, sizeof(outframe), &len);
|
||||
} else {
|
||||
printf("BREAK");
|
||||
break;
|
||||
@ -181,7 +181,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo)
|
||||
//close(ifd);
|
||||
|
||||
pri_hangup(spri->pri, channo, 16);
|
||||
if (zap_channel_close(&chan) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_close(&chan) != FTDM_SUCCESS) {
|
||||
printf("Critical Error: Failed to close channel [%s]\n", chan->last_error);
|
||||
}
|
||||
|
||||
@ -280,13 +280,13 @@ int main(int argc, char *argv[])
|
||||
debug = atoi(argv[1]);
|
||||
}
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
|
||||
debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include <sangoma_pri.h>
|
||||
#ifndef HAVE_GETTIMEOFDAY
|
||||
|
||||
@ -92,12 +92,12 @@ char *sangoma_pri_event_str(sangoma_pri_event_t event_id)
|
||||
static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen)
|
||||
{
|
||||
struct sangoma_pri *spri = (struct sangoma_pri *) pri->userdata;
|
||||
zap_size_t len = buflen;
|
||||
ftdm_size_t len = buflen;
|
||||
int res;
|
||||
char bb[4096] = "";
|
||||
|
||||
|
||||
if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_read(spri->zdchan, buf, &len) != FTDM_SUCCESS) {
|
||||
printf("D-READ FAIL! [%s]\n", spri->zdchan->last_error);
|
||||
return 0;
|
||||
}
|
||||
@ -106,7 +106,7 @@ static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen)
|
||||
res+=2;
|
||||
|
||||
//print_bits(buf, res-2, bb, sizeof(bb), 1, 0);
|
||||
//zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb);
|
||||
//ftdm_log(FTDM_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -115,16 +115,16 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen)
|
||||
{
|
||||
struct sangoma_pri *spri = (struct sangoma_pri *) pri->userdata;
|
||||
int res;
|
||||
zap_size_t len = buflen -2;
|
||||
ftdm_size_t len = buflen -2;
|
||||
char bb[4096] = "";
|
||||
|
||||
if (zap_channel_write(spri->zdchan, buf, buflen, &len) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_write(spri->zdchan, buf, buflen, &len) != FTDM_SUCCESS) {
|
||||
printf("D-WRITE FAIL! [%s]\n", spri->zdchan->last_error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0);
|
||||
//zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)buflen-2, LINE, bb);
|
||||
//ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)buflen-2, LINE, bb);
|
||||
|
||||
return (int) buflen;
|
||||
}
|
||||
@ -132,11 +132,11 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen)
|
||||
int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, int node, int debug)
|
||||
{
|
||||
int ret = -1;
|
||||
zap_socket_t dfd = 0;
|
||||
ftdm_socket_t dfd = 0;
|
||||
|
||||
memset(spri, 0, sizeof(struct sangoma_pri));
|
||||
|
||||
if (zap_channel_open(span, dchan, &spri->zdchan) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_open(span, dchan, &spri->zdchan) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Unable to open DCHAN %d for span %d (%s)\n", dchan, span, strerror(errno));
|
||||
} else {
|
||||
if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, spri))){
|
||||
|
@ -79,7 +79,7 @@ struct sangoma_pri {
|
||||
void *private_info;
|
||||
event_handler eventmap[MAX_EVENT+1];
|
||||
loop_handler on_loop;
|
||||
zap_channel_t *zdchan;
|
||||
ftdm_channel_t *zdchan;
|
||||
};
|
||||
|
||||
struct sangoma_pri_event_list {
|
||||
|
@ -1,61 +1,61 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
|
||||
static void *test_call(zap_thread_t *me, void *obj)
|
||||
static void *test_call(ftdm_thread_t *me, void *obj)
|
||||
{
|
||||
zap_channel_t *chan = (zap_channel_t *) obj;
|
||||
ftdm_channel_t *chan = (ftdm_channel_t *) obj;
|
||||
uint8_t frame[1024];
|
||||
zap_size_t len;
|
||||
ftdm_size_t len;
|
||||
char *number = strdup("5551212");
|
||||
|
||||
zap_sleep(10 * 1000);
|
||||
ftdm_sleep(10 * 1000);
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "answer call and start echo test\n");
|
||||
|
||||
zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP);
|
||||
zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, number);
|
||||
ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_UP);
|
||||
ftdm_channel_command(chan, FTDM_COMMAND_SEND_DTMF, number);
|
||||
|
||||
while (chan->state == ZAP_CHANNEL_STATE_UP) {
|
||||
zap_wait_flag_t flags = ZAP_READ;
|
||||
while (chan->state == FTDM_CHANNEL_STATE_UP) {
|
||||
ftdm_wait_flag_t flags = FTDM_READ;
|
||||
|
||||
if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) {
|
||||
if (ftdm_channel_wait(chan, &flags, -1) == FTDM_FAIL) {
|
||||
break;
|
||||
}
|
||||
len = sizeof(frame);
|
||||
if (flags & ZAP_READ) {
|
||||
if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) {
|
||||
//zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", len);
|
||||
zap_channel_write(chan, frame, sizeof(frame), &len);
|
||||
if (flags & FTDM_READ) {
|
||||
if (ftdm_channel_read(chan, frame, &len) == FTDM_SUCCESS) {
|
||||
//ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n", len);
|
||||
ftdm_channel_write(chan, frame, sizeof(frame), &len);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chan->state == ZAP_CHANNEL_STATE_UP) {
|
||||
zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY);
|
||||
if (chan->state == FTDM_CHANNEL_STATE_UP) {
|
||||
ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_BUSY);
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "call over\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "call over\n");
|
||||
free(number);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id));
|
||||
ftdm_log(FTDM_LOG_DEBUG, "got sig [%s]\n", ftdm_signal_event2str(sigmsg->event_id));
|
||||
|
||||
switch(sigmsg->event_id) {
|
||||
case ZAP_SIGEVENT_START:
|
||||
zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING);
|
||||
zap_log(ZAP_LOG_DEBUG, "launching thread and indicating ring\n");
|
||||
zap_thread_create_detached(test_call, sigmsg->channel);
|
||||
case FTDM_SIGEVENT_START:
|
||||
ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_RING);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "launching thread and indicating ring\n");
|
||||
ftdm_thread_create_detached(test_call, sigmsg->channel);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
static int R = 0;
|
||||
@ -70,7 +70,7 @@ static void handle_SIGINT(int sig)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_span_t *span;
|
||||
ftdm_span_t *span;
|
||||
int span_id;
|
||||
int digit_timeout = 2000;
|
||||
int max_dialstr = 11;
|
||||
@ -82,41 +82,41 @@ int main(int argc, char *argv[])
|
||||
|
||||
span_id = atoi(argv[1]);
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n");
|
||||
ftdm_log(FTDM_LOG_DEBUG, "OpenFTDM loaded\n");
|
||||
|
||||
if (zap_span_find(span_id, &span) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n");
|
||||
if (ftdm_span_find(span_id, &span) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
if (zap_configure_span("analog", span, on_signal,
|
||||
if (ftdm_configure_span("analog", span, on_signal,
|
||||
"tonemap", "us",
|
||||
"digit_timeout", &digit_timeout,
|
||||
"max_dialstr", &max_dialstr,
|
||||
TAG_END
|
||||
) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n");
|
||||
) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Error configuring OpenFTDM span\n");
|
||||
goto done;
|
||||
}
|
||||
zap_span_start(span);
|
||||
ftdm_span_start(span);
|
||||
|
||||
R = 1;
|
||||
|
||||
while(zap_running() && R) {
|
||||
zap_sleep(1 * 1000);
|
||||
while(ftdm_running() && R) {
|
||||
ftdm_sleep(1 * 1000);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,39 +1,39 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
zap_channel_t *chan;
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
ftdm_channel_t *chan;
|
||||
unsigned ms = 20;
|
||||
zap_codec_t codec = ZAP_CODEC_SLIN;
|
||||
ftdm_codec_t codec = FTDM_CODEC_SLIN;
|
||||
unsigned runs = 1;
|
||||
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
top:
|
||||
//if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) {
|
||||
if (zap_channel_open(1, 1, &chan) == ZAP_SUCCESS) {
|
||||
//if (ftdm_channel_open_any("wanpipe", 0, FTDM_TOP_DOWN, &chan) == FTDM_SUCCESS) {
|
||||
if (ftdm_channel_open(1, 1, &chan) == FTDM_SUCCESS) {
|
||||
int x = 0;
|
||||
printf("opened channel %d:%d\n", chan->span_id, chan->chan_id);
|
||||
|
||||
#if 1
|
||||
if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) {
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_SET_INTERVAL, &ms) == FTDM_SUCCESS) {
|
||||
ms = 0;
|
||||
zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &ms);
|
||||
ftdm_channel_command(chan, FTDM_COMMAND_GET_INTERVAL, &ms);
|
||||
printf("interval set to %u\n", ms);
|
||||
} else {
|
||||
printf("set interval failed [%s]\n", chan->last_error);
|
||||
}
|
||||
#endif
|
||||
if (zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec) == ZAP_SUCCESS) {
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_SET_CODEC, &codec) == FTDM_SUCCESS) {
|
||||
codec = 1;
|
||||
zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &codec);
|
||||
ftdm_channel_command(chan, FTDM_COMMAND_GET_CODEC, &codec);
|
||||
printf("codec set to %u\n", codec);
|
||||
} else {
|
||||
printf("set codec failed [%s]\n", chan->last_error);
|
||||
@ -41,14 +41,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
for(x = 0; x < 25; x++) {
|
||||
unsigned char buf[2048];
|
||||
zap_size_t len = sizeof(buf);
|
||||
zap_wait_flag_t flags = ZAP_READ;
|
||||
ftdm_size_t len = sizeof(buf);
|
||||
ftdm_wait_flag_t flags = FTDM_READ;
|
||||
|
||||
if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) {
|
||||
if (ftdm_channel_wait(chan, &flags, -1) == FTDM_FAIL) {
|
||||
printf("wait FAIL! %u [%s]\n", (unsigned)len, chan->last_error);
|
||||
}
|
||||
if (flags & ZAP_READ) {
|
||||
if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) {
|
||||
if (flags & FTDM_READ) {
|
||||
if (ftdm_channel_read(chan, buf, &len) == FTDM_SUCCESS) {
|
||||
printf("READ: %u\n", (unsigned)len);
|
||||
} else {
|
||||
printf("READ FAIL! %u [%s]\n", (unsigned)len, chan->last_error);
|
||||
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
|
||||
printf("wait fail [%s]\n", chan->last_error);
|
||||
}
|
||||
}
|
||||
zap_channel_close(&chan);
|
||||
ftdm_channel_close(&chan);
|
||||
} else {
|
||||
printf("open fail [%s]\n", chan->last_error);
|
||||
}
|
||||
@ -67,7 +67,7 @@ int main(int argc, char *argv[])
|
||||
goto top;
|
||||
}
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static int R = 0;
|
||||
@ -16,13 +16,13 @@ static void handle_SIGINT(int sig)
|
||||
#endif
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_conf_parameter_t parameters[20];
|
||||
zap_span_t *span;
|
||||
ftdm_conf_parameter_t parameters[20];
|
||||
ftdm_span_t *span;
|
||||
int local_port, remote_port;
|
||||
|
||||
local_port = remote_port = 53000;
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
#if 0
|
||||
if (argc < 2) {
|
||||
printf("invalid arguments\n");
|
||||
@ -30,19 +30,19 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (zap_global_configuration() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error configuring OpenZAP\n");
|
||||
if (ftdm_global_configuration() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error configuring OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
if (zap_span_find_by_name("wp1", &span) != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenZAP span %s\n", argv[1]);
|
||||
if (ftdm_span_find_by_name("wp1", &span) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenFTDM span %s\n", argv[1]);
|
||||
goto done;
|
||||
}
|
||||
parameters[0].var = "sigmod";
|
||||
@ -52,20 +52,20 @@ int main(int argc, char *argv[])
|
||||
parameters[1].var = "signalling";
|
||||
parameters[1].val = "pri_cpe";
|
||||
parameters[2].var = NULL;
|
||||
if (zap_configure_span_signaling("sangoma_boost", span, on_signal, parameters) == ZAP_SUCCESS) {
|
||||
zap_span_start(span);
|
||||
if (ftdm_configure_span_signaling("sangoma_boost", span, on_signal, parameters) == FTDM_SUCCESS) {
|
||||
ftdm_span_start(span);
|
||||
} else {
|
||||
fprintf(stderr, "Error starting SS7_BOOST\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
while(zap_running() && R) {
|
||||
zap_sleep(1 * 1000);
|
||||
while(ftdm_running() && R) {
|
||||
ftdm_sleep(1 * 1000);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
#include "openzap.h"
|
||||
zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data);
|
||||
#include "freetdm.h"
|
||||
ftdm_status_t my_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data);
|
||||
|
||||
struct helper {
|
||||
int fd;
|
||||
int wrote;
|
||||
};
|
||||
|
||||
zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data)
|
||||
ftdm_status_t my_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data)
|
||||
{
|
||||
struct helper *foo = (struct helper *) user_data;
|
||||
size_t len;
|
||||
len = write(foo->fd, buf, buflen * 2);
|
||||
if (!len) return ZAP_FAIL;
|
||||
if (!len) return FTDM_FAIL;
|
||||
foo->wrote += buflen * 2;
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct zap_fsk_modulator fsk_trans;
|
||||
zap_fsk_data_state_t fsk_data = {0};
|
||||
struct ftdm_fsk_modulator fsk_trans;
|
||||
ftdm_fsk_data_state_t fsk_data = {0};
|
||||
int fd = -1;
|
||||
int16_t buf[160] = {0};
|
||||
ssize_t len = 0;
|
||||
@ -48,26 +48,26 @@ int main(int argc, char *argv[])
|
||||
localtime_r(&now, &tm);
|
||||
strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm);
|
||||
|
||||
zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf));
|
||||
ftdm_fsk_data_init(&fsk_data, databuf, sizeof(databuf));
|
||||
#if 1
|
||||
|
||||
zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *)time_str, strlen(time_str));
|
||||
//zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06091213", 8);
|
||||
zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, (uint8_t *)"14149361212", 7);
|
||||
zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, (uint8_t *)"Fred Smith", 10);
|
||||
ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *)time_str, strlen(time_str));
|
||||
//ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06091213", 8);
|
||||
ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, (uint8_t *)"14149361212", 7);
|
||||
ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, (uint8_t *)"Fred Smith", 10);
|
||||
for(x = 0; x < 0; x++)
|
||||
zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, (uint8_t *)url, strlen(url));
|
||||
ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, (uint8_t *)url, strlen(url));
|
||||
#else
|
||||
zap_fsk_data_add_sdmf(&fsk_data, "06061234", "0");
|
||||
//zap_fsk_data_add_sdmf(&state, "06061234", "5551212");
|
||||
ftdm_fsk_data_add_sdmf(&fsk_data, "06061234", "0");
|
||||
//ftdm_fsk_data_add_sdmf(&state, "06061234", "5551212");
|
||||
#endif
|
||||
zap_fsk_data_add_checksum(&fsk_data);
|
||||
ftdm_fsk_data_add_checksum(&fsk_data);
|
||||
|
||||
foo.fd = fd;
|
||||
|
||||
|
||||
zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, 8000, &fsk_data, -14, 180, 5, 300, my_write_sample, &foo);
|
||||
zap_fsk_modulator_send_all((&fsk_trans));
|
||||
ftdm_fsk_modulator_init(&fsk_trans, FSK_BELL202, 8000, &fsk_data, -14, 180, 5, 300, my_write_sample, &foo);
|
||||
ftdm_fsk_modulator_send_all((&fsk_trans));
|
||||
|
||||
printf("%u %d %d\n", (unsigned) fsk_data.dlen, foo.wrote, fsk_trans.est_bytes);
|
||||
|
||||
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (zap_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) {
|
||||
if (ftdm_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) {
|
||||
printf("wtf\n");
|
||||
return 0;
|
||||
}
|
||||
@ -89,19 +89,19 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
while((len = read(fd, buf, sizeof(buf))) > 0) {
|
||||
if (zap_fsk_demod_feed(&fsk_data, buf, len / 2) != ZAP_SUCCESS) {
|
||||
if (ftdm_fsk_demod_feed(&fsk_data, buf, len / 2) != FTDM_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while(zap_fsk_data_parse(&fsk_data, &type, &sp, &mlen) == ZAP_SUCCESS) {
|
||||
zap_copy_string(str, sp, mlen+1);
|
||||
while(ftdm_fsk_data_parse(&fsk_data, &type, &sp, &mlen) == FTDM_SUCCESS) {
|
||||
ftdm_copy_string(str, sp, mlen+1);
|
||||
*(str+mlen) = '\0';
|
||||
zap_clean_string(str);
|
||||
printf("TYPE %u (%s) LEN %u VAL [%s]\n", (unsigned)type, zap_mdmf_type2str(type), (unsigned)mlen, str);
|
||||
ftdm_clean_string(str);
|
||||
printf("TYPE %u (%s) LEN %u VAL [%s]\n", (unsigned)type, ftdm_mdmf_type2str(type), (unsigned)mlen, str);
|
||||
}
|
||||
|
||||
zap_fsk_demod_destroy(&fsk_data);
|
||||
ftdm_fsk_demod_destroy(&fsk_data);
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static int R = 0;
|
||||
@ -17,32 +17,32 @@ static void handle_SIGINT(int sig)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_span_t *span;
|
||||
ftdm_span_t *span;
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
|
||||
if (argc < 2) {
|
||||
printf("umm no\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenZAP span\n");
|
||||
if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenFTDM span\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zap_configure_span("isdn", span, on_signal,
|
||||
if (ftdm_configure_span("isdn", span, on_signal,
|
||||
"mode", "te",
|
||||
"dialect", "national",
|
||||
TAG_END) == ZAP_SUCCESS) {
|
||||
zap_span_start(span);
|
||||
TAG_END) == FTDM_SUCCESS) {
|
||||
ftdm_span_start(span);
|
||||
} else {
|
||||
fprintf(stderr, "Error starting ISDN D-Channel\n");
|
||||
goto done;
|
||||
@ -51,12 +51,12 @@ int main(int argc, char *argv[])
|
||||
signal(SIGINT, handle_SIGINT);
|
||||
R = 1;
|
||||
while(R) {
|
||||
zap_sleep(1 * 1000);
|
||||
ftdm_sleep(1 * 1000);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
|
||||
return 1;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* testm3ua.c
|
||||
* openzap
|
||||
* freetdm
|
||||
*
|
||||
* Created by Shane Burrell on 4/8/08.
|
||||
* Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
@ -8,53 +8,53 @@
|
||||
*/
|
||||
|
||||
#include "testm3ua.h"
|
||||
#include "openzap.h"
|
||||
#include "zap_m3ua.h"
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_m3ua.h"
|
||||
|
||||
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_span_t *span;
|
||||
ftdm_span_t *span;
|
||||
//m3ua_data_t *data;
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
|
||||
if (argc < 5) {
|
||||
printf("more args needed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenZAP span\n");
|
||||
if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenFTDM span\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
if (zap_m3ua_configure_span(span) == ZAP_SUCCESS) {
|
||||
if (ftdm_m3ua_configure_span(span) == FTDM_SUCCESS) {
|
||||
//data = span->signal_data;
|
||||
zap_m3ua_start(span);
|
||||
ftdm_m3ua_start(span);
|
||||
} else {
|
||||
fprintf(stderr, "Error starting M3UA\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
//while(zap_test_flag(data, ZAP_M3UA_RUNNING)) {
|
||||
// zap_sleep(1 * 1000);
|
||||
//while(ftdm_test_flag(data, FTDM_M3UA_RUNNING)) {
|
||||
// ftdm_sleep(1 * 1000);
|
||||
//}
|
||||
|
||||
done:
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include <signal.h>
|
||||
|
||||
static int THREADS[4][31] = { {0} };
|
||||
static int R = 0;
|
||||
static int T = 0;
|
||||
static zap_mutex_t *mutex = NULL;
|
||||
static ftdm_mutex_t *mutex = NULL;
|
||||
|
||||
|
||||
static void *channel_run(zap_thread_t *me, void *obj)
|
||||
static void *channel_run(ftdm_thread_t *me, void *obj)
|
||||
{
|
||||
zap_channel_t *zchan = obj;
|
||||
ftdm_channel_t *ftdmchan = obj;
|
||||
int fd = -1;
|
||||
short buf[160];
|
||||
|
||||
zap_mutex_lock(mutex);
|
||||
ftdm_mutex_lock(mutex);
|
||||
T++;
|
||||
zap_mutex_unlock(mutex);
|
||||
ftdm_mutex_unlock(mutex);
|
||||
|
||||
zap_set_state_locked_wait(zchan, ZAP_CHANNEL_STATE_UP);
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
|
||||
if ((fd = open("test.raw", O_RDONLY, 0)) < 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
while(R == 1 && THREADS[zchan->span_id][zchan->chan_id] == 1) {
|
||||
while(R == 1 && THREADS[ftdmchan->span_id][ftdmchan->chan_id] == 1) {
|
||||
ssize_t bytes = read(fd, buf, sizeof(buf));
|
||||
size_t bbytes;
|
||||
|
||||
@ -35,7 +35,7 @@ static void *channel_run(zap_thread_t *me, void *obj)
|
||||
|
||||
zio_slin2alaw(buf, sizeof(buf), &bbytes);
|
||||
|
||||
if (zap_channel_write(zchan, buf, sizeof(buf), &bbytes) != ZAP_SUCCESS) {
|
||||
if (ftdm_channel_write(ftdmchan, buf, sizeof(buf), &bbytes) != FTDM_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -44,31 +44,31 @@ static void *channel_run(zap_thread_t *me, void *obj)
|
||||
|
||||
end:
|
||||
|
||||
zap_set_state_locked_wait(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
|
||||
|
||||
THREADS[zchan->span_id][zchan->chan_id] = 0;
|
||||
THREADS[ftdmchan->span_id][ftdmchan->chan_id] = 0;
|
||||
|
||||
zap_mutex_lock(mutex);
|
||||
ftdm_mutex_lock(mutex);
|
||||
T = 0;
|
||||
zap_mutex_unlock(mutex);
|
||||
ftdm_mutex_unlock(mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
zap_log(ZAP_LOG_DEBUG, "got sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, zap_signal_event2str(sigmsg->event_id));
|
||||
ftdm_log(FTDM_LOG_DEBUG, "got sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, ftdm_signal_event2str(sigmsg->event_id));
|
||||
|
||||
switch(sigmsg->event_id) {
|
||||
|
||||
case ZAP_SIGEVENT_STOP:
|
||||
case FTDM_SIGEVENT_STOP:
|
||||
THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = -1;
|
||||
break;
|
||||
|
||||
case ZAP_SIGEVENT_START:
|
||||
case FTDM_SIGEVENT_START:
|
||||
if (!THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id]) {
|
||||
THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = 1;
|
||||
zap_thread_create_detached(channel_run, sigmsg->channel);
|
||||
ftdm_thread_create_detached(channel_run, sigmsg->channel);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -76,7 +76,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
break;
|
||||
}
|
||||
|
||||
return ZAP_SUCCESS;
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -84,40 +84,40 @@ static void handle_SIGINT(int sig)
|
||||
{
|
||||
if (sig);
|
||||
|
||||
zap_mutex_lock(mutex);
|
||||
ftdm_mutex_lock(mutex);
|
||||
R = 0;
|
||||
zap_mutex_unlock(mutex);
|
||||
ftdm_mutex_unlock(mutex);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_span_t *span;
|
||||
zap_mutex_create(&mutex);
|
||||
ftdm_span_t *span;
|
||||
ftdm_mutex_create(&mutex);
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
|
||||
if (argc < 2) {
|
||||
printf("umm no\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenZAP span\n");
|
||||
if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenFTDM span\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (zap_configure_span(
|
||||
if (ftdm_configure_span(
|
||||
"libpri", span, on_signal,
|
||||
"node", "cpe",
|
||||
"switch", "euroisdn",
|
||||
@ -125,26 +125,26 @@ int main(int argc, char *argv[])
|
||||
"l1", "alaw",
|
||||
"debug", NULL,
|
||||
"opts", 0,
|
||||
TAG_END) == ZAP_SUCCESS) {
|
||||
TAG_END) == FTDM_SUCCESS) {
|
||||
|
||||
|
||||
zap_span_start(span);
|
||||
ftdm_span_start(span);
|
||||
} else {
|
||||
fprintf(stderr, "Error starting ISDN D-Channel\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
signal(SIGINT, handle_SIGINT);
|
||||
zap_mutex_lock(mutex);
|
||||
ftdm_mutex_lock(mutex);
|
||||
R = 1;
|
||||
zap_mutex_unlock(mutex);
|
||||
ftdm_mutex_unlock(mutex);
|
||||
while(R || T) {
|
||||
zap_sleep(1 * 1000);
|
||||
ftdm_sleep(1 * 1000);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
|
||||
return 1;
|
||||
|
||||
|
@ -1,74 +1,74 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
#include <signal.h>
|
||||
|
||||
static int R = 0;
|
||||
static zap_mutex_t *mutex = NULL;
|
||||
static ftdm_mutex_t *mutex = NULL;
|
||||
|
||||
static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal)
|
||||
{
|
||||
zap_log(ZAP_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", zap_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id);
|
||||
return ZAP_SUCCESS;
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", ftdm_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
static void handle_SIGINT(int sig)
|
||||
{
|
||||
zap_mutex_lock(mutex);
|
||||
ftdm_mutex_lock(mutex);
|
||||
R = 0;
|
||||
zap_mutex_unlock(mutex);
|
||||
ftdm_mutex_unlock(mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_span_t *span;
|
||||
zap_mutex_create(&mutex);
|
||||
ftdm_span_t *span;
|
||||
ftdm_mutex_create(&mutex);
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
|
||||
if (argc < 2) {
|
||||
printf("umm no\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenZAP span\n");
|
||||
if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenFTDM span\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (zap_configure_span("r2", span, on_r2_signal,
|
||||
if (ftdm_configure_span("r2", span, on_r2_signal,
|
||||
"variant", "mx",
|
||||
"max_ani", 10,
|
||||
"max_dnis", 4,
|
||||
"logging", "all",
|
||||
TAG_END) == ZAP_SUCCESS) {
|
||||
TAG_END) == FTDM_SUCCESS) {
|
||||
|
||||
|
||||
zap_span_start(span);
|
||||
ftdm_span_start(span);
|
||||
} else {
|
||||
fprintf(stderr, "Error starting R2 span\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
signal(SIGINT, handle_SIGINT);
|
||||
zap_mutex_lock(mutex);
|
||||
ftdm_mutex_lock(mutex);
|
||||
R = 1;
|
||||
zap_mutex_unlock(mutex);
|
||||
ftdm_mutex_unlock(mutex);
|
||||
while(R) {
|
||||
zap_sleep(1 * 1000);
|
||||
ftdm_sleep(1 * 1000);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
|
||||
return 1;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
return ZAP_FAIL;
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
static int R = 0;
|
||||
@ -16,44 +16,44 @@ static void handle_SIGINT(int sig)
|
||||
#endif
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
zap_span_t *span;
|
||||
ftdm_span_t *span;
|
||||
int local_port, remote_port;
|
||||
|
||||
local_port = remote_port = 53000;
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
|
||||
|
||||
if (argc < 2) {
|
||||
printf("umm no\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (zap_global_init() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenZAP\n");
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error loading OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (zap_global_configuration() != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error configuring OpenZAP\n");
|
||||
if (ftdm_global_configuration() != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error configuring OpenFTDM\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenZAP loaded\n");
|
||||
printf("OpenFTDM loaded\n");
|
||||
|
||||
if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenZAP span\n");
|
||||
if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error finding OpenFTDM span\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
#if 1
|
||||
if (1) {
|
||||
if (zap_configure_span("sangoma_boost", span, on_signal,
|
||||
if (ftdm_configure_span("sangoma_boost", span, on_signal,
|
||||
"sigmod", "sangoma_brid",
|
||||
"local_port", &local_port,
|
||||
"remote_ip", "127.0.0.66",
|
||||
"remote_port", &remote_port,
|
||||
TAG_END) == ZAP_SUCCESS) {
|
||||
zap_span_start(span);
|
||||
TAG_END) == FTDM_SUCCESS) {
|
||||
ftdm_span_start(span);
|
||||
|
||||
} else {
|
||||
fprintf(stderr, "Error starting sangoma_boost\n");
|
||||
@ -62,13 +62,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
while(zap_running() && R) {
|
||||
zap_sleep(1 * 1000);
|
||||
while(ftdm_running() && R) {
|
||||
ftdm_sleep(1 * 1000);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
zap_global_destroy();
|
||||
ftdm_global_destroy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "openzap.h"
|
||||
#include "freetdm.h"
|
||||
|
||||
struct ttmp {
|
||||
int fd;
|
||||
|
@ -32,7 +32,7 @@
|
||||
* 2005 06 11 R. Krten created
|
||||
*/
|
||||
|
||||
#include <openzap.h>
|
||||
#include <freetdm.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -77,7 +77,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr)
|
||||
{
|
||||
dsp_uart_handle_t *handle;
|
||||
|
||||
handle = zap_malloc(sizeof (*handle));
|
||||
handle = ftdm_malloc(sizeof (*handle));
|
||||
if (handle) {
|
||||
memset(handle, 0, sizeof (*handle));
|
||||
|
||||
@ -90,7 +90,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr)
|
||||
void dsp_uart_destroy(dsp_uart_handle_t **handle)
|
||||
{
|
||||
if (*handle) {
|
||||
zap_safe_free(*handle);
|
||||
ftdm_safe_free(*handle);
|
||||
*handle = NULL;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user