Add ss7boost signalling to mod_wanpipe

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4430 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-03-02 19:12:26 +00:00
parent 71a5fbfbd1
commit 47c2cceedc
5 changed files with 1357 additions and 222 deletions

View File

@ -1,7 +1,7 @@
CFLAGS +=-I/usr/local/include -I/usr/src/libpri -I/usr/src/linux/include -I. -I/usr/include
CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API
LDFLAGS += -lsangoma
OBJS = ss7boost_client.o mod_wanpipe.o
ifeq ($(OSARCH),Darwin)
LINKER=g++
@ -14,9 +14,12 @@ all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN)
depends:
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libsangoma --prefix=$(PREFIX) --with-libpri=/usr/src/libpri
$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c
%.o: %.c
$(CC) $(CFLAGS) $(MOD_CFLAGS) -g -ggdb -Werror -fPIC -c $< -o $@
$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(OBJS) $(MODNAME).c
$(CC) $(CFLAGS) -fPIC -c $(MODNAME).c -o $(MODNAME).o
$(LINKER) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(MODNAME).o $(LDFLAGS)
$(LINKER) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(OBJS) $(LDFLAGS)
clean:
rm -fr *.$(DYNAMIC_LIB_EXTEN) *.o *~

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,82 @@
/****************************************************************************
* 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

View File

@ -0,0 +1,263 @@
/*
* 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;
}

View File

@ -0,0 +1,107 @@
/*
* 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