提交 42cb2307 authored 作者: Brian West's avatar Brian West

move wanpipe to unsupported please see mod_openzap

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9998 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 d74b12a1
BASE=../../../..
LIBPRI_HOST=http://downloads.digium.com/pub/libpri
LIBPRI=libpri-1.2.6
LIBPRI_FILE=$(LIBPRI).tar.gz
LIBPRI_DIR=$(BASE)/libs/$(LIBPRI)
WANPIPE=wanpipe-3.1.1
WANPIPE_HOST=ftp://ftp.sangoma.com/linux/current_wanpipe/
WANPIPE_FILE=$(WANPIPE).tgz
WANPIPE_DIR=$(BASE)/libs/$(WANPIPE)
WANPIPE_INCLUDE=$(WANPIPE_DIR)/patches/kdrivers/include
WANPIPE_KO=$(WANPIPE_DIR)/patches/kdrivers/src/net/wanpipe.ko
WANPIPE_INSTALLED_KO=$(shell echo "/lib/modules/`uname -r`/kernel/drivers/net/wan/wanpipe.ko")
LIBSANGOMA_DIR=./libsangoma
LOCAL_CFLAGS =-w -I$(WANPIPE_INCLUDE) -I$(LIBSANGOMA_DIR) -I/usr/local/include -I$(LIBPRI_DIR) -I/usr/src/linux/include -I. -I/usr/include
LOCAL_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -I$(switch_srcdir)/libs/libteletone/src -D_GNUC_ -DWANPIPE_TDM_API -w -fPIC
LOCAL_OBJS = ss7boost_client.o $(LIBPRI_DIR)/copy_string.o $(LIBPRI_DIR)/pri.o $(LIBPRI_DIR)/q921.o $(LIBPRI_DIR)/prisched.o $(LIBPRI_DIR)/q931.o $(LIBPRI_DIR)/pri_facility.o $(LIBSANGOMA_DIR)/libsangoma.o $(LIBSANGOMA_DIR)/sangoma_pri.o
WTF=-fPIC -w -std=gnu99 -I$(BASE)/libs/wanpipe-3.1.0/patches/kdrivers/include -I./libsangoma -I/usr/local/include -I../../../../libs/libpri-1.2.4 -I/usr/src/linux/include -I. -I/usr/include -D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -I$(BASE)/libs/libteletone/src -D_GNUC_ -DWANPIPE_TDM_API -w -I$(BASE)/src/include -I$(BASE)/libs/libteletone/src -fPIC -g -O2 -Wall -D_GNU_SOURCE -DHAVE_CONFIG_H
include $(BASE)/build/modmake.rules
mod_wanpipe.o: mod_wanpipe.c
@echo Compiling $<...
$(CC) $(WTF) -c -o $@ $< || exit 1
$(LIBSANGOMA_DIR)/libsangoma.o: $(LIBSANGOMA_DIR)/libsangoma.c
$(CC) -c -I$(WANPIPE_DIR) $(LOCAL_CFLAGS) $(LIBSANGOMA_DIR)/libsangoma.c -o $(LIBSANGOMA_DIR)/libsangoma.o
$(LIBSANGOMA_DIR)/sangoma_pri.o: $(LIBSANGOMA_DIR)/sangoma_pri.c
$(CC) -c -I$(WANPIPE_DIR) $(LOCAL_CFLAGS) $(LIBSANGOMA_DIR)/sangoma_pri.c -o $(LIBSANGOMA_DIR)/sangoma_pri.o
testapp: testapp.c $(LIBSANGOMA_DIR)/libsangoma.o
$(CC) -I$(WANPIPE_DIR)/api/lib $(CFLAGS) $(LOCAL_CFLAGS) lib_api.c testapp.c $(LIBSANGOMA_DIR)/libsangoma.o -o testapp
$(LIBPRI_DIR):
$(GETLIB) $(LIBPRI_HOST) $(LIBPRI_FILE)
$(WANPIPE_DIR):
$(GETLIB) $(WANPIPE_HOST) $(WANPIPE_FILE)
$(WANPIPE_KO): $(WANPIPE_DIR)
cd $(WANPIPE_DIR) && $(MAKE) && $(MAKE) install
@$(TOUCH_TARGET)
$(WANPIPE_INSTALLED_KO): $(WANPIPE_KO)
cd $(WANPIPE_DIR) && $(MAKE) install
local_depend: $(LIBPRI_DIR) $(WANPIPE_KO)
local_install: $(WANPIPE_INSTALLED_KO)
local_clean:
rm -f libsangoma/*.o
# Microsoft Developer Studio Project File - Name="libsangoma" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=libsangoma - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "libsangoma.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "libsangoma.mak" CFG="libsangoma - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "libsangoma - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "libsangoma - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "libsangoma - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "libsangoma - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "libsangoma - Win32 Release"
# Name "libsangoma - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\libsangoma.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\win_api_common.h
# End Source File
# End Group
# End Target
# End Project
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "libsangoma"=.\libsangoma.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################
#ifndef _LIBSNAGOMA_H
#define _LIBSNAGOMA_H
#include <stdio.h>
#define WANPIPE_TDM_API 1
#ifdef WIN32
#ifndef __WINDOWS__
#define __WINDOWS__
#endif
#include <windows.h>
#include <winioctl.h>
#include <conio.h>
#include <stddef.h> //for offsetof()
typedef unsigned __int16 u_int16_t;
typedef unsigned __int32 u_int32_t;
#include <wanpipe_defines.h> //for 'wan_udp_hdr_t'
#include <wanpipe_cfg.h>
#ifdef WANPIPE_TDM_API
#include <wanpipe_tdm_api.h> //for TDMV API
#endif
#include <sang_status_defines.h>//return codes
#include <sang_api.h> //for IOCTL codes
#include <sdla_te1_pmc.h> //RBS definitions
#include <sdla_te1.h> //TE1 macros
#include <sdla_56k.h> //56k macros
#include <sdla_remora.h> //Analog card
#include <sdla_te3.h> //T3 card
#include <sdla_front_end.h> //front-end (T1/E1/56k) commands
#include <sdla_aft_te1.h> //for Wanpipe API
#define _MYDEBUG
#define PROGRAM_NAME "LIBSANGOMA: "
#include <DebugOut.h>
typedef HANDLE sng_fd_t;
#else
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/select.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <netinet/in.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/if.h>
#include <poll.h>
#include <signal.h>
//typedef int sng_fd_t;
#include <linux/wanpipe_defines.h>
#include <linux/wanpipe_cfg.h>
#include <linux/wanpipe.h>
#ifdef WANPIPE_TDM_API
# include <linux/wanpipe_tdm_api.h>
#endif
#endif
#define FNAME_LEN 50
#define FUNC_DBG(x) if(0)printf("%s:%d\n", x, __LINE__)
#define DBG_PRINT if(1)printf
typedef wp_tdm_api_rx_hdr_t sangoma_api_hdr_t;
/* Decodec Span/Chan from interface name */
int sangoma_span_chan_toif(int span, int chan, char *interface_name);
int sangoma_span_chan_fromif(char *interface_name, int *span, int *chan);
int sangoma_interface_toi(char *interface_name, int *span, int *chan);
sng_fd_t sangoma_create_socket_by_name(char *device, char *card);
/* Open Span/Chan devices
* open_tdmapi_span_chan: open device based on span chan values
* sangoma_open_tdmapi_span: open first available device on span
*/
sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan);
sng_fd_t sangoma_open_tdmapi_span(int span);
#define sangoma_create_socket_intr sangoma_open_tdmapi_span_chan
/* Device Rx/Tx functions
* writemsg_tdm: tx header + data from separate buffers
* readmsg_tdm: rx header + data to separate buffers
*/
int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
void *databuf, unsigned short datalen, int flag);
int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
void *databuf, int datalen, int flag);
#define sangoma_readmsg_socket sangoma_readmsg_tdm
#define sangoma_sendmsg_socket sangoma_writemsg_tdm
#ifdef WANPIPE_TDM_API
void sangoma_socket_close(sng_fd_t *sp);
int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags);
/* Get Full TDM API configuration per chan */
int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Get/Set TDM Codec per chan */
int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec);
int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Get/Set USR Tx/Rx Period in milliseconds */
int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period);
int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Get user MTU/MRU values in bytes */
int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Not supported yet */
int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power);
int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Flush buffers from current channel */
int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec);
int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs);
int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* DTMF Detection on Octasic chip */
int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* DTMF Detection on A200 (SLIC) chip */
int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* On/Off hook events on A200 (Analog) card */
int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
#define WP_PRE __FILE__, __FUNCTION__, __LINE__
#define WP_LOG_DEBUG WP_PRE, 7
#define WP_LOG_INFO WP_PRE, 6
#define WP_LOG_NOTICE WP_PRE, 5
#define WP_LOG_WARNING WP_PRE, 4
#define WP_LOG_ERROR WP_PRE, 3
#define WP_LOG_CRIT WP_PRE, 2
#define WP_LOG_ALERT WP_PRE, 1
#define WP_LOG_EMERG WP_PRE, 0
typedef void (*sangoma_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...);
void sangoma_set_logger(sangoma_logger_t logger);
extern sangoma_logger_t global_logger;
#ifndef LIBSANGOMA_GET_HWCODING
#define LIBSANGOMA_GET_HWCODING 1
#endif
int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api);
#endif /* WANPIPE_TDM_API */
#endif
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="libsangoma"
ProjectGUID="{7E60CC2D-E818-4712-8F16-C0E6EC64982F}"
RootNamespace="libsangoma"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories=".;include\api;include\debug;include\octasic;include\pnp;..\libpri"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;WANPIPE_TDM_API;_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/libsangoma.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="4"
WarnAsError="true"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
DisableSpecificWarnings="4100;4214;4201;4706;4311;4312"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
OutputFile=".\Release\libsangoma.lib"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/libsangoma.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;include\api;include\debug;include\octasic;include\pnp;..\libpri"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__WINDOWS__;WANPIPE_TDM_API;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\Debug/libsangoma.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="4"
WarnAsError="true"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
DisableSpecificWarnings="4100;4214;4201;4706;4311;4312"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
OutputFile=".\Debug\libsangoma.lib"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/libsangoma.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="libsangoma.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\sangoma_pri.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath=".\libsangoma.h"
>
</File>
<File
RelativePath=".\sangoma_pri.h"
>
</File>
<File
RelativePath="win_api_common.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
#include <libsangoma.h>
#include <sangoma_pri.h>
#ifndef HAVE_GETTIMEOFDAY
#ifdef WIN32
#include <mmsystem.h>
static __inline int gettimeofday(struct timeval *tp, void *nothing)
{
#ifdef WITHOUT_MM_LIB
SYSTEMTIME st;
time_t tt;
struct tm tmtm;
/* mktime converts local to UTC */
GetLocalTime(&st);
tmtm.tm_sec = st.wSecond;
tmtm.tm_min = st.wMinute;
tmtm.tm_hour = st.wHour;
tmtm.tm_mday = st.wDay;
tmtm.tm_mon = st.wMonth - 1;
tmtm.tm_year = st.wYear - 1900;
tmtm.tm_isdst = -1;
tt = mktime(&tmtm);
tp->tv_sec = tt;
tp->tv_usec = st.wMilliseconds * 1000;
#else
/**
** The earlier time calculations using GetLocalTime
** had a time resolution of 10ms.The timeGetTime, part
** of multimedia apis offer a better time resolution
** of 1ms.Need to link against winmm.lib for this
**/
unsigned long Ticks = 0;
unsigned long Sec = 0;
unsigned long Usec = 0;
Ticks = timeGetTime();
Sec = Ticks / 1000;
Usec = (Ticks - (Sec * 1000)) * 1000;
tp->tv_sec = Sec;
tp->tv_usec = Usec;
#endif /* WITHOUT_MM_LIB */
(void) nothing;
return 0;
}
#endif /* WIN32 */
#endif /* HAVE_GETTIMEOFDAY */
static struct sangoma_pri_event_list SANGOMA_PRI_EVENT_LIST[] = {
{0, SANGOMA_PRI_EVENT_ANY, "ANY"},
{1, SANGOMA_PRI_EVENT_DCHAN_UP, "DCHAN_UP"},
{2, SANGOMA_PRI_EVENT_DCHAN_DOWN, "DCHAN_DOWN"},
{3, SANGOMA_PRI_EVENT_RESTART, "RESTART"},
{4, SANGOMA_PRI_EVENT_CONFIG_ERR, "CONFIG_ERR"},
{5, SANGOMA_PRI_EVENT_RING, "ROUTING"},
{6, SANGOMA_PRI_EVENT_HANGUP, "HANGUP"},
{7, SANGOMA_PRI_EVENT_RINGING, "RINGING"},
{8, SANGOMA_PRI_EVENT_ANSWER, "ANSWER"},
{9, SANGOMA_PRI_EVENT_HANGUP_ACK, "HANGUP_ACK"},
{10, SANGOMA_PRI_EVENT_RESTART_ACK, "RESTART_ACK"},
{11, SANGOMA_PRI_EVENT_FACNAME, "FACNAME"},
{12, SANGOMA_PRI_EVENT_INFO_RECEIVED, "INFO_RECEIVED"},
{13, SANGOMA_PRI_EVENT_PROCEEDING, "PROCEEDING"},
{14, SANGOMA_PRI_EVENT_SETUP_ACK, "SETUP_ACK"},
{15, SANGOMA_PRI_EVENT_HANGUP_REQ, "HANGUP_REQ"},
{16, SANGOMA_PRI_EVENT_NOTIFY, "NOTIFY"},
{17, SANGOMA_PRI_EVENT_PROGRESS, "PROGRESS"},
{18, SANGOMA_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"}
};
char *sangoma_pri_event_str(sangoma_pri_event_t event_id)
{
return SANGOMA_PRI_EVENT_LIST[event_id].name;
}
static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen)
{
unsigned char tmpbuf[sizeof(wp_tdm_api_rx_hdr_t)];
/* NOTE: This code will be different for A104
* A104 receives data + 2byte CRC + 1 byte flag
* A101/2 receives data only */
int res = sangoma_readmsg_socket((sng_fd_t) (pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
buf, buflen,
0);
if (res > 0) {
#ifdef WANPIPE_LEGACY_A104
/* Prior 2.3.4 release A104 API passed up
* 3 extra bytes: 2 CRC + 1 FLAG,
* PRI is expecting only 2 CRC bytes, thus we
* must remove 1 flag byte */
res--;
#else
/* Add 2 byte CRC and set it to ZERO */
memset(&((unsigned char *) buf)[res], 0, 2);
res += 2;
#endif
} else {
res = 0;
}
return res;
}
static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen)
{
unsigned char tmpbuf[sizeof(wp_tdm_api_rx_hdr_t)];
int res;
memset(&tmpbuf[0], 0, sizeof(wp_tdm_api_rx_hdr_t));
if (buflen < 1) {
/* HDLC Frame must be greater than 2byte CRC */
fprintf(stderr, "%s: Got short frame %i\n", __FUNCTION__, buflen);
return 0;
}
/* FIXME: This might cause problems with other libraries
* We must remove 2 bytes from buflen because
* libpri sends 2 fake CRC bytes */
res = sangoma_sendmsg_socket((sng_fd_t) (pri->fd), tmpbuf, sizeof(wp_tdm_api_rx_hdr_t), buf, (unsigned short) buflen - 2, 0);
if (res > 0) {
res = buflen;
}
return res;
}
int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, int node, int debug)
{
int ret = -1;
sng_fd_t dfd = 0;
memset(spri, 0, sizeof(struct sangoma_pri));
if ((dfd = sangoma_open_tdmapi_span_chan(span, dchan)) < 0) {
fprintf(stderr, "Unable to open DCHAN %d for span %d (%s)\n", dchan, span, strerror(errno));
} else {
if ((spri->pri = pri_new_cb((int) dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))) {
spri->span = span;
spri->dchan = dchan;
spri->swtype = swtype;
spri->node = node;
spri->debug = debug;
pri_set_debug(spri->pri, debug);
ret = 0;
} else {
fprintf(stderr, "Unable to create PRI\n");
}
}
return ret;
}
int sangoma_one_loop(struct sangoma_pri *spri)
{
fd_set rfds, efds;
struct timeval now = { 0, 0 }, *next;
pri_event *event;
int sel;
if (spri->on_loop) {
spri->on_loop(spri);
}
FD_ZERO(&rfds);
FD_ZERO(&efds);
#ifdef _MSC_VER
//Windows macro for FD_SET includes a warning C4127: conditional expression is constant
#pragma warning(push)
#pragma warning(disable:4127)
#endif
FD_SET(spri->pri->fd, &rfds);
FD_SET(spri->pri->fd, &efds);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
if ((next = pri_schedule_next(spri->pri))) {
gettimeofday(&now, NULL);
now.tv_sec = next->tv_sec - now.tv_sec;
now.tv_usec = next->tv_usec - now.tv_usec;
if (now.tv_usec < 0) {
now.tv_usec += 1000000;
now.tv_sec -= 1;
}
if (now.tv_sec < 0) {
now.tv_sec = 0;
now.tv_usec = 0;
}
}
sel = select(spri->pri->fd + 1, &rfds, NULL, &efds, next ? &now : NULL);
event = NULL;
if (FD_ISSET(spri->pri->fd, &efds)) {
wanpipe_tdm_api_t tdm_api = {0};
sangoma_tdm_read_event(spri->pri->fd, &tdm_api);
global_logger(WP_LOG_ERROR, "DCHANNEL ERROR! [span %d]\n", spri->span);
}
if (!sel) {
event = pri_schedule_run(spri->pri);
} else if (sel > 0) {
event = pri_check_event(spri->pri);
}
if (event) {
event_handler handler;
/* 0 is catchall event handler */
if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
handler(spri, event->e, event);
} else {
fprintf(stderr, "No event handler found for event %d.\n", event->e);
}
}
return sel;
}
int sangoma_run_pri(struct sangoma_pri *spri)
{
int ret = 0;
for (;;) {
ret = sangoma_one_loop(spri);
if (ret < 0) {
#ifndef WIN32 //This needs to be adressed fror WIN32 still
if (errno == EINTR) {
/* Igonore an interrupted system call */
continue;
}
#endif
printf("Error = %i\n", ret);
perror("Sangoma Run Pri: ");
break;
}
}
return ret;
}
/*****************************************************************************
* libsangoma.c AFT T1/E1: HDLC API Code Library
*
* Author(s): Anthony Minessale II <anthmct@yahoo.com>
* Nenad Corbic <ncorbic@sangoma.com>
*
* Copyright: (c) 2005 Anthony Minessale II
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
*/
#ifndef _SANGOMA_PRI_H
#define _SANGOMA_PRI_H
#include <libpri.h>
#include <pri_internal.h>
#define SANGOMA_MAX_CHAN_PER_SPAN 32
typedef enum {
SANGOMA_PRI_EVENT_ANY = 0,
SANGOMA_PRI_EVENT_DCHAN_UP = PRI_EVENT_DCHAN_UP,
SANGOMA_PRI_EVENT_DCHAN_DOWN = PRI_EVENT_DCHAN_DOWN,
SANGOMA_PRI_EVENT_RESTART = PRI_EVENT_RESTART,
SANGOMA_PRI_EVENT_CONFIG_ERR = PRI_EVENT_CONFIG_ERR,
SANGOMA_PRI_EVENT_RING = PRI_EVENT_RING,
SANGOMA_PRI_EVENT_HANGUP = PRI_EVENT_HANGUP,
SANGOMA_PRI_EVENT_RINGING = PRI_EVENT_RINGING,
SANGOMA_PRI_EVENT_ANSWER = PRI_EVENT_ANSWER,
SANGOMA_PRI_EVENT_HANGUP_ACK = PRI_EVENT_HANGUP_ACK,
SANGOMA_PRI_EVENT_RESTART_ACK = PRI_EVENT_RESTART_ACK,
SANGOMA_PRI_EVENT_FACNAME = PRI_EVENT_FACNAME,
SANGOMA_PRI_EVENT_INFO_RECEIVED = PRI_EVENT_INFO_RECEIVED,
SANGOMA_PRI_EVENT_PROCEEDING = PRI_EVENT_PROCEEDING,
SANGOMA_PRI_EVENT_SETUP_ACK = PRI_EVENT_SETUP_ACK,
SANGOMA_PRI_EVENT_HANGUP_REQ = PRI_EVENT_HANGUP_REQ,
SANGOMA_PRI_EVENT_NOTIFY = PRI_EVENT_NOTIFY,
SANGOMA_PRI_EVENT_PROGRESS = PRI_EVENT_PROGRESS,
SANGOMA_PRI_EVENT_KEYPAD_DIGIT = PRI_EVENT_KEYPAD_DIGIT
} sangoma_pri_event_t;
typedef enum {
SANGOMA_PRI_NETWORK = PRI_NETWORK,
SANGOMA_PRI_CPE = PRI_CPE
} sangoma_pri_node_t;
typedef enum {
SANGOMA_PRI_SWITCH_UNKNOWN = PRI_SWITCH_UNKNOWN,
SANGOMA_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,
SANGOMA_PRI_SWITCH_DMS100 = PRI_SWITCH_DMS100,
SANGOMA_PRI_SWITCH_LUCENT5E = PRI_SWITCH_LUCENT5E,
SANGOMA_PRI_SWITCH_ATT4ESS = PRI_SWITCH_ATT4ESS,
SANGOMA_PRI_SWITCH_EUROISDN_E1 = PRI_SWITCH_EUROISDN_E1,
SANGOMA_PRI_SWITCH_EUROISDN_T1 = PRI_SWITCH_EUROISDN_T1,
SANGOMA_PRI_SWITCH_NI1 = PRI_SWITCH_NI1,
SANGOMA_PRI_SWITCH_GR303_EOC = PRI_SWITCH_GR303_EOC,
SANGOMA_PRI_SWITCH_GR303_TMC = PRI_SWITCH_GR303_TMC,
SANGOMA_PRI_SWITCH_QSIG = PRI_SWITCH_QSIG
} sangoma_pri_switch_t;
typedef enum {
SANGOMA_PRI_READY = (1 << 0)
} sangoma_pri_flag_t;
struct sangoma_pri;
typedef int (*event_handler) (struct sangoma_pri *, sangoma_pri_event_t, pri_event *);
typedef int (*loop_handler) (struct sangoma_pri *);
#define MAX_EVENT 18
struct sangoma_pri {
struct pri *pri;
int span;
int dchan;
unsigned int flags;
void *private_info;
event_handler eventmap[MAX_EVENT + 1];
loop_handler on_loop;
int dfd;
int swtype;
int node;
int debug;
};
struct sangoma_pri_event_list {
int event_id;
int pri_event;
char *name;
};
#define SANGOMA_MAP_PRI_EVENT(spri, event, func) spri.eventmap[event] = func;
char *sangoma_pri_event_str(sangoma_pri_event_t event_id);
int sangoma_one_loop(struct sangoma_pri *spri);
int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, int node, int debug);
int sangoma_run_pri(struct sangoma_pri *spri);
#endif
/*****************************************************************************
* win_api_common.h - Sangoma API for MS Windows. Abstraction of common API calls.
*
* Author(s): David Rokhvarg <davidr@sangoma.com>
*
* Copyright: (c) 1984-2006 Sangoma Technologies Inc.
*
* ============================================================================
*/
#ifndef _WIN_API_COMMON_H
#define _WIN_API_COMMON_H
static
int tdmv_api_ioctl(HANDLE fd, wanpipe_tdm_api_cmd_t * tdm_api_cmd)
{
DWORD ln;
unsigned char id = 0;
int err = 0;
wan_udp.wan_udphdr_request_reply = 0x01;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
//copy data from caller's buffer to driver's buffer
memcpy(wan_udp.wan_udphdr_data, (void *) tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t));
if (DeviceIoControl(fd,
IoctlManagementCommand,
(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln),
(LPOVERLAPPED) NULL) == FALSE) {
//actual ioctl failed
err = 1;
prn(1, "Error: tdmv_api_ioctl(): DeviceIoControl failed!!\n");
return err;
} else {
err = 0;
}
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
//ioctl ok, but command failed
prn(1, "Error: tdmv_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
return 2;
}
//copy data from driver's buffer to caller's buffer
memcpy((void *) tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t));
return 0;
}
static
int wanpipe_api_ioctl(HANDLE fd, wan_cmd_api_t * api_cmd)
{
DWORD ln;
unsigned char id = 0;
int err = 0;
wan_udp.wan_udphdr_request_reply = 0x01;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_command = SIOC_WANPIPE_API;
wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t);
//copy data from caller's buffer to driver's buffer
memcpy(wan_udp.wan_udphdr_data, (void *) api_cmd, sizeof(wan_cmd_api_t));
if (DeviceIoControl(fd,
IoctlManagementCommand,
(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln),
(LPOVERLAPPED) NULL) == FALSE) {
err = 1;
prn(1, "Error: wanpipe_api_ioctl(): DeviceIoControl failed!!\n");
return err;
} else {
err = 0;
}
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
prn(1, "Error: wanpipe_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
return 2;
}
//copy data from driver's buffer to caller's buffer
memcpy((void *) api_cmd, wan_udp.wan_udphdr_data, sizeof(wan_cmd_api_t));
return 0;
}
// Blocking read command. If used after DoApiPollCommand(),
// it will return immediatly, without blocking.
static USHORT DoReadCommand(HANDLE drv, RX_DATA_STRUCT * pRx)
{
DWORD ln;
if (DeviceIoControl(drv, IoctlReadCommand, (LPVOID) NULL, 0L, (LPVOID) pRx, sizeof(RX_DATA_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoReadCommand(): DeviceIoControl failed!\n");
return 1;
} else {
return 0;
}
}
// Blocking write command. If used after DoApiPollCommand(),
// it will return immediatly, without blocking.
static UCHAR DoWriteCommand(HANDLE drv, TX_DATA_STRUCT * pTx)
{
DWORD ln;
if (DeviceIoControl(drv,
IoctlWriteCommand,
(LPVOID) pTx, (ULONG) sizeof(TX_DATA_STRUCT), (LPVOID) pTx, sizeof(TX_DATA_STRUCT), (LPDWORD) (&ln),
(LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoWriteCommand(): DeviceIoControl failed!\n");
return 1;
} else {
return 0;
}
}
// Blocking API Poll command.
static USHORT DoApiPollCommand(HANDLE drv, API_POLL_STRUCT * api_poll_ptr)
{
DWORD ln;
if (DeviceIoControl(drv, IoctlApiPoll, (LPVOID) NULL, 0L, (LPVOID) api_poll_ptr, sizeof(API_POLL_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) ==
FALSE) {
//check messages log
prn(1, "Error: DoApiPollCommand(): DeviceIoControl failed!\n");
return 1;
} else {
return 0;
}
}
static
int DoManagementCommand(HANDLE drv, wan_udp_hdr_t * wan_udp)
{
DWORD ln;
static unsigned char id = 0;
wan_udp->wan_udphdr_request_reply = 0x01;
wan_udp->wan_udphdr_id = id++;
wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
if (DeviceIoControl(drv,
IoctlManagementCommand,
(LPVOID) wan_udp, sizeof(wan_udp_hdr_t), (LPVOID) wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoManagementCommand(): DeviceIoControl failed!\n");
return 1;
} else {
return 0;
}
}
#endif /* _WIN_API_COMMON_H */
/****************************************************************************
* sigboost.h $Revision: 1.1 $
*
* Definitions for the sigboost interface.
*
* WARNING WARNING WARNING
*
* This file is used by sangoma_mgd and perhaps other programs. Any changes
* to this file must be coordinated with other user programs,
*
* Copyright (C) 2005 Xygnada Technology, Inc.
*
****************************************************************************/
#ifndef _SIGBOOST_H_
#define _SIGBOOST_H_
#include <stdint.h>
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_HEARTBEAT = 0x88, /*136 */
};
enum e_sigboost_release_cause_values {
SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0x00,
SIGBOOST_RELEASE_CAUSE_NORMAL = 0x90,
SIGBOOST_RELEASE_CAUSE_BUSY = 0x91,
SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92,
SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93,
SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94
};
enum e_sigboost_call_setup_ack_nack_cause_values {
SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 0x12,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_BIG = 0x13,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_BIG = 0x14,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_SMALL = 0x15,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_SMALL = 0x16,
};
#define MAX_DIALED_DIGITS 31
/* Next two defines are used to create the range of values for call_setup_id
* in the t_sigboost structure.
* 0..((CORE_MAX_SPANS * CORE_MAX_CHAN_PER_SPAN) - 1) */
#define CORE_MAX_SPANS 200
#define CORE_MAX_CHAN_PER_SPAN 30
#define MAX_PENDING_CALLS CORE_MAX_SPANS * CORE_MAX_CHAN_PER_SPAN
/* 0..(MAX_PENDING_CALLS-1) is range of call_setup_id below */
#pragma pack(1)
typedef struct {
uint32_t event_id;
uint32_t seqno;
uint32_t call_setup_id;
uint32_t trunk_group;
uint32_t span;
uint32_t chan;
uint32_t called_number_digits_count;
int8_t called_number_digits[MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t calling_number_digits_count; /* it's an array */
int8_t calling_number_digits[MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t release_cause;
struct timeval tv;
uint32_t calling_number_presentation;
} t_sigboost;
#pragma pack()
#endif
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla 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/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
* Nenad Corbic <ncorbic@sangoma.com>
*
*
* ss7boost_client.c Client for the SS7Boost Protocol
*
*/
#include <ss7boost_client.h>
#include <switch.h>
extern unsigned int txseq;
extern unsigned int rxseq;
struct ss7boost_client_map {
uint32_t event_id;
char *name;
};
static struct ss7boost_client_map ss7boost_client_table[] = {
{SIGBOOST_EVENT_CALL_START, "CALL_START"},
{SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"},
{SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"},
{SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"},
{SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"},
{SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"},
{SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"},
{SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"},
{SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"},
};
static switch_status_t create_udp_socket(ss7boost_client_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n", local_ip, local_port, ip, port);
if (switch_sockaddr_info_get(&mcon->local_addr, local_ip, SWITCH_UNSPEC, local_port, 0, mcon->pool) != SWITCH_STATUS_SUCCESS) {
goto fail;
}
if (switch_sockaddr_info_get(&mcon->remote_addr, ip, SWITCH_UNSPEC, port, 0, mcon->pool) != SWITCH_STATUS_SUCCESS) {
goto fail;
}
if (switch_socket_create(&mcon->socket, AF_INET, SOCK_DGRAM, 0, mcon->pool) == SWITCH_STATUS_SUCCESS) {
if (switch_socket_bind(mcon->socket, mcon->local_addr) != SWITCH_STATUS_SUCCESS) {
goto fail;
}
} else {
goto fail;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
return SWITCH_STATUS_SUCCESS;
fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon)
{
switch_socket_close(mcon->socket);
mcon->socket = NULL;
memset(mcon, 0, sizeof(*mcon));
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
char *local_ip, int local_port, char *ip, int port, switch_memory_pool_t *pool)
{
memset(mcon, 0, sizeof(*mcon));
mcon->pool = pool;
if (create_udp_socket(mcon, local_ip, local_port, ip, port) == SWITCH_STATUS_SUCCESS) {
switch_mutex_init(&mcon->mutex, SWITCH_MUTEX_NESTED, mcon->pool);
return SWITCH_STATUS_SUCCESS;
}
memset(mcon, 0, sizeof(*mcon));
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event)
{
unsigned int fromlen = sizeof(struct sockaddr_in);
switch_size_t bytes = 0;
bytes = sizeof(mcon->event);
if (switch_socket_recvfrom(mcon->local_addr, mcon->socket, 0, (void *) &mcon->event, &bytes) != SWITCH_STATUS_SUCCESS) {
bytes = 0;
}
if (bytes == sizeof(mcon->event) || bytes == (sizeof(mcon->event) - sizeof(uint32_t))) {
if (rxseq != mcon->event.seqno) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", rxseq, mcon->event.seqno);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
}
rxseq++;
*event = &mcon->event;
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event)
{
int err;
switch_size_t len;
if (!event) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Critical Error: No Event Device\n");
return -EINVAL;
}
if (event->span < 0 || event->chan < 0 || event->span > 7 || event->chan > 30) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Critical Error: Invalid Span=%i Chan=%i\n", event->span, event->chan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
}
#ifdef WIN32
//TODO set the tv with win func
#else
gettimeofday(&event->tv, NULL);
#endif
switch_mutex_lock(mcon->mutex);
event->seqno = txseq++;
len = sizeof(*event);
if (switch_socket_sendto(mcon->socket, mcon->remote_addr, 0, (void *) event, &len) != SWITCH_STATUS_SUCCESS) {
err = -1;
}
switch_mutex_unlock(mcon->mutex);
if (len != sizeof(ss7boost_client_event_t)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write Error: [%d][%d][%s]\n", mcon->socket, errno, strerror(errno));
err = -1;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"\nTX EVENT\n"
"===================================\n"
" tType: %s (%0x HEX)\n"
" tSpan: [%d]\n"
" tChan: [%d]\n"
" tCalledNum: %s\n"
" tCallingNum: %s\n"
" tCause: %d\n"
" tInterface: [w%dg%d]\n"
" tEvent ID: [%d]\n"
" tSetup ID: [%d]\n"
" tSeq: [%d]\n"
"===================================\n"
"\n",
ss7boost_client_event_id_name(event->event_id),
event->event_id,
event->span + 1,
event->chan + 1,
(event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"),
(event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"),
event->release_cause, event->span + 1, event->chan + 1, event->event_id, event->call_setup_id, event->seqno);
return err ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = SIGBOOST_EVENT_CALL_START;
if (calling) {
strncpy((char *) event->calling_number_digits, calling, sizeof(event->calling_number_digits) - 1);
event->calling_number_digits_count = strlen(calling);
}
if (called) {
strncpy((char *) event->called_number_digits, called, sizeof(event->called_number_digits) - 1);
event->called_number_digits_count = strlen(called);
}
event->call_setup_id = setup_id;
}
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = event_id;
event->chan = chan;
event->span = span;
}
SWITCH_DECLARE(char *) ss7boost_client_event_id_name(uint32_t event_id)
{
int x;
char *ret = NULL;
for (x = 0; x < sizeof(ss7boost_client_table) / sizeof(struct ss7boost_client_map); x++) {
if (ss7boost_client_table[x].event_id == event_id) {
ret = ss7boost_client_table[x].name;
break;
}
}
return ret;
}
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla 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/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
* Nenad Corbic <ncorbic@sangoma.com>
*
*
* ss7boost_client.h Client for the SS7Boost Protocol
*
*/
#ifndef _SS7BOOST_CLIENT_H
#define _SS7BOOST_CLIENT_H
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <netdb.h>
#include <sigboost.h>
#include <pthread.h>
#include <sys/time.h>
#include <switch.h>
#define ss7boost_client_test_flag(p,flag) ({ \
((p)->flags & (flag)); \
})
#define ss7boost_client_set_flag(p,flag) do { \
((p)->flags |= (flag)); \
} while (0)
#define ss7boost_client_clear_flag(p,flag) do { \
((p)->flags &= ~(flag)); \
} while (0)
#define ss7boost_client_copy_flags(dest,src,flagz) do { \
(dest)->flags &= ~(flagz); \
(dest)->flags |= ((src)->flags & (flagz)); \
} while (0)
typedef t_sigboost ss7boost_client_event_t;
typedef uint32_t ss7boost_client_event_id_t;
struct ss7boost_client_connection {
switch_socket_t *socket;
switch_sockaddr_t *local_addr;
switch_sockaddr_t *remote_addr;
ss7boost_client_event_t event;
unsigned int flags;
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
};
typedef enum {
MSU_FLAG_EVENT = (1 << 0)
} ss7boost_client_flag_t;
typedef struct ss7boost_client_connection ss7boost_client_connection_t;
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
char *local_ip, int local_port, char *ip, int port, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon, ss7boost_client_event_t ** event);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon, ss7boost_client_event_t * event);
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id, int chan, int span);
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called, int setup_id);
SWITCH_DECLARE(char *) ss7boost_client_event_id_name(uint32_t event_id);
#endif
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论