]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
move wanpipe to unsupported please see mod_openzap
authorBrian West <brian@freeswitch.org>
Mon, 13 Oct 2008 19:36:49 +0000 (19:36 +0000)
committerBrian West <brian@freeswitch.org>
Mon, 13 Oct 2008 19:36:49 +0000 (19:36 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9998 d0543943-73ff-0310-b7d9-9358b9ac24b2

17 files changed:
src/mod/endpoints/mod_wanpipe/Makefile [deleted file]
src/mod/endpoints/mod_wanpipe/lib_api.c [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/g711.h [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.dsp [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.dsw [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.so.conf [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.vcproj [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h [deleted file]
src/mod/endpoints/mod_wanpipe/libsangoma/win_api_common.h [deleted file]
src/mod/endpoints/mod_wanpipe/mod_wanpipe.c [deleted file]
src/mod/endpoints/mod_wanpipe/sigboost.h [deleted file]
src/mod/endpoints/mod_wanpipe/ss7boost_client.c [deleted file]
src/mod/endpoints/mod_wanpipe/ss7boost_client.h [deleted file]
src/mod/endpoints/mod_wanpipe/testapp.c [deleted file]

diff --git a/src/mod/endpoints/mod_wanpipe/Makefile b/src/mod/endpoints/mod_wanpipe/Makefile
deleted file mode 100644 (file)
index cb767f4..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-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
diff --git a/src/mod/endpoints/mod_wanpipe/lib_api.c b/src/mod/endpoints/mod_wanpipe/lib_api.c
deleted file mode 100644 (file)
index 205b916..0000000
+++ /dev/null
@@ -1,534 +0,0 @@
-/*****************************************************************************
-* lib_api.c    Common API library
-*
-* Author(s):   Nenad Corbic <ncorbic@sangoma.com>
-*
-* Copyright:   (c) 2003 Sangoma Technologies Inc.
-*
-*              This program is free software; you can redistribute it and/or
-*              modify it under the terms of the GNU General Public License
-*              as published by the Free Software Foundation; either version
-*              2 of the License, or (at your option) any later version.
-* ============================================================================
-*/
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <linux/if_wanpipe.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <linux/if.h>
-
-#include <linux/wanpipe_defines.h>
-#include <linux/wanpipe_cfg.h>
-#include <linux/wanpipe.h>
-
-#include "lib_api.h"
-
-#define SINGLE_CHANNEL 0x2
-#define RANGE_CHANNEL  0x1
-
-
-char read_enable = 0;
-char write_enable = 0;
-char primary_enable = 0;
-int tx_cnt = 1;
-int rx_cnt = 0;
-int tx_size = 10;
-int tx_delay = 0;
-int tx_data = -1;
-int tx_ss7_type = 0;
-int rx_ss7_timer = 0;
-
-unsigned char card_name[WAN_IFNAME_SZ];
-unsigned char if_name[WAN_IFNAME_SZ];
-
-unsigned char sw_if_name[WAN_IFNAME_SZ];
-unsigned char sw_card_name[WAN_IFNAME_SZ];
-
-unsigned char tx_file[WAN_IFNAME_SZ];
-unsigned char rx_file[WAN_IFNAME_SZ];
-
-unsigned char daddr[TX_ADDR_STR_SZ];
-unsigned char saddr[TX_ADDR_STR_SZ];
-unsigned char udata[TX_ADDR_STR_SZ];
-
-int files_used = 0;
-int verbose = 0;
-
-int tx_connections;
-
-int ds_prot = 0;
-int ds_prot_opt = 0;
-int ds_max_mult_cnt = 0;
-unsigned int ds_active_ch = 0;
-int ds_7bit_hdlc = 0;
-int direction = -1;
-
-int tx_channels = 1;
-int cause = 0;
-int diagn = 0;
-
-int card_cnt = 0;
-int i_cnt = 0;
-
-unsigned long parse_active_channel(char *val);
-
-int init_args(int argc, char *argv[])
-{
-       int i;
-       int c_cnt = 0;
-
-       sprintf(daddr, "111");
-       sprintf(saddr, "222");
-       sprintf(udata, "C9");
-
-       for (i = 0; i < argc; i++) {
-
-               if (!strcmp(argv[i], "-i")) {
-
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid Interface Name!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(if_name, argv[i + 1], WAN_IFNAME_SZ);
-                       i_cnt = 1;
-
-               } else if (!strcmp(argv[i], "-si")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid Switch Interface Name!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(sw_if_name, argv[i + 1], WAN_IFNAME_SZ);
-
-               } else if (!strcmp(argv[i], "-c")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid Card Name!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(card_name, argv[i + 1], WAN_IFNAME_SZ);
-                       card_cnt = 1;
-
-               } else if (!strcmp(argv[i], "-sc")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid Switch Card Name!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(sw_card_name, argv[i + 1], WAN_IFNAME_SZ);
-
-               } else if (!strcmp(argv[i], "-r")) {
-                       read_enable = 1;
-                       c_cnt = 1;
-
-               } else if (!strcmp(argv[i], "-w")) {
-                       write_enable = 1;
-                       c_cnt = 1;
-
-               } else if (!strcmp(argv[i], "-pri")) {
-                       primary_enable = 1;
-
-               } else if (!strcmp(argv[i], "-txcnt")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid tx cnt!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               tx_cnt = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid tx cnt!\n");
-                               return WAN_FALSE;
-                       }
-
-               } else if (!strcmp(argv[i], "-rxcnt")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid rx cnt!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               rx_cnt = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid rx cnt!\n");
-                               return WAN_FALSE;
-                       }
-
-               } else if (!strcmp(argv[i], "-txsize")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid tx size!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               tx_size = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid tx size, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-               } else if (!strcmp(argv[i], "-txdelay")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid tx delay!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               tx_delay = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid tx delay, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-               } else if (!strcmp(argv[i], "-txdata")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid tx data!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               tx_data = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid tx data, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-               } else if (!strcmp(argv[i], "-tx_ss7_type")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid tx ss7 type!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               tx_ss7_type = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid tx ss7 type, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-
-               } else if (!strcmp(argv[i], "-rx_ss7_timer")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid rx ss7 timer!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               rx_ss7_timer = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid tx ss7 type, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-
-
-               } else if (!strcmp(argv[i], "-txfile")) {
-
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid Tx File Name!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(tx_file, argv[i + 1], WAN_IFNAME_SZ);
-                       files_used |= TX_FILE_USED;
-
-               } else if (!strcmp(argv[i], "-rxfile")) {
-
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid Rx File Name!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(rx_file, argv[i + 1], WAN_IFNAME_SZ);
-                       files_used |= RX_FILE_USED;
-
-               } else if (!strcmp(argv[i], "-daddr")) {
-
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid daddr str!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(daddr, argv[i + 1], TX_ADDR_STR_SZ);
-
-               } else if (!strcmp(argv[i], "-saddr")) {
-
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid saddr str!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(saddr, argv[i + 1], TX_ADDR_STR_SZ);
-
-               } else if (!strcmp(argv[i], "-udata")) {
-
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid udata str!\n");
-                               return WAN_FALSE;
-                       }
-
-                       strncpy(udata, argv[i + 1], TX_ADDR_STR_SZ);
-
-               } else if (!strcmp(argv[i], "-verbose")) {
-                       verbose = 1;
-
-               } else if (!strcmp(argv[i], "-prot")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid prot!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               ds_prot = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid prot, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-
-
-               } else if (!strcmp(argv[i], "-prot_opt")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid prot_opt!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               ds_prot_opt = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid prot_opt, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-               } else if (!strcmp(argv[i], "-max_mult_cnt")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid max_mult_cnt!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               ds_max_mult_cnt = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid max_mult_cnt, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-               } else if (!strcmp(argv[i], "-active_ch")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid active ch!\n");
-                               return WAN_FALSE;
-                       }
-
-                       ds_active_ch = parse_active_channel(argv[i + 1]);
-               } else if (!strcmp(argv[i], "-txchan")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid channels!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               tx_channels = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid channels, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-               } else if (!strcmp(argv[i], "-diagn")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid diagn!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               diagn = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid diagn, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-
-               } else if (!strcmp(argv[i], "-cause")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid cause!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               cause = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid cause, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-
-               } else if (!strcmp(argv[i], "-7bit_hdlc")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid 7bit hdlc value!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               ds_7bit_hdlc = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid 7bit hdlc, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-
-               } else if (!strcmp(argv[i], "-dir")) {
-                       if (i + 1 > argc - 1) {
-                               printf("ERROR: Invalid direction value!\n");
-                               return WAN_FALSE;
-                       }
-
-                       if (isdigit(argv[i + 1][0])) {
-                               direction = atoi(argv[i + 1]);
-                       } else {
-                               printf("ERROR: Invalid direction, must be a digit!\n");
-                               return WAN_FALSE;
-                       }
-               }
-       }
-
-       if (!i_cnt) {
-               printf("ERROR: No Interface Name!\n");
-               return WAN_FALSE;
-       }
-       if (!card_cnt) {
-               printf("ERROR: No Card name!\n");
-               return WAN_FALSE;
-       }
-       if (!c_cnt) {
-               printf("ERROR: No Read or Write Command!\n");
-               return WAN_FALSE;
-       }
-
-       return WAN_TRUE;
-}
-
-static unsigned char api_usage[] = "\n"
-       "\n"
-       "<options>:\n"
-       "       -i  <ifname>     #interface name\n"
-       "       -c  <card name>  #card name\n"
-       "       -r               #read enable\n"
-       "       -w               #write eable\n"
-       "\n"
-       "<extra options>\n"
-       "       -txcnt   <digit>  #number of tx packets  (Dflt: 1)\n"
-       "       -txsize  <digit>  #tx packet size        (Dflt: 10)\n"
-       "       -txdelay <digit>  #delay in sec after each tx packet (Dflt: 0)\n"
-       "       -txdata  <digit>  #data to tx <1-255>\n"
-       "\n"
-       "       -txfile  <file>   #Use file to tx instead\n"
-       "       -rxfile  <file>   #Save all rx data to a file\n"
-       "       \n"
-       "\n"
-       "       -tx_ss7_type  <digit> # 1=FISU   2=LSSU (repeating)\n"
-       "       -rx_ss7_timer <digit> #Force receive timeout value \n"
-       "\n"
-       "       -rxcnt   <digit>  #number of rx packets before exit\n"
-       "                         #this number overwrites the txcnt\n"
-       "                         #Thus, app will only exit after it\n"
-       "                         #receives the rxcnt number of packets.\n"
-       "       \n"
-       "       -verbose          #Enable verbose mode\n"
-       "\n"
-       "<datascope options>\n"
-       "\n"
-       "       -prot           <digit>   #Protocol Bit map: \n"
-       "                                 #1=FISU, 2=LSSU, 4=MSU, 8=RAW HDLC\n"
-       "       \n"
-       "       -prot_opt       <digit>   #Protocol bit map\n"
-       "                                 #0=None, 1=Delta, 2=Max Multiple\n"
-       "\n"
-       "       -active_ch      <digit>   #Active channel\n"
-       "                                  #ALL = all channels \n"
-       "                                  #1 24 = 1 to 24 \n"
-       "                                  #1.24 = 1 and 24 \n"
-       "                                  #1-4.7-15 = 1 to 4 and 7 to 15\n"
-       "       \n"
-       "       -max_mult_cnt   <digit>   #If Prot_opt == 2 \n"
-       "                                  #max_mult_cnt is the number of \n"
-       "                                  #consecutive duplicate frames \n"
-       "                                  #received before pass up the stack.\n"
-       "       \n"
-       "       -7bit_hdlc      <digit>   #Enable 7 Bit Hdlc Engine\n"
-       "                                 #1=Enable 0=Disable\n"
-       "       \n"
-       "       -dir            <digit>   #Direction 0: Rx  1: Tx  none: All\n"
-       "\n"
-       "<x25 protocol options>\n"
-       "\n"
-       "       -txchan         <digit>  #Number of channels    (dflt=1)\n"
-       "       -cause          <digit>  #disconnect cause      (dflt=0)\n" "   -diagn          <digit>  #disconnect diagnostic (dflt=0)\n" "\n";
-
-void usage(unsigned char *api_name)
-{
-       printf("\n\nAPI %s USAGE:\n\n%s <options> <extra options>\n\n%s\n", api_name, api_name, api_usage);
-}
-
-
-/*============================================================================
- * TE1
- */
-unsigned long get_active_channels(int channel_flag, int start_channel, int stop_channel)
-{
-       int i = 0;
-       unsigned long tmp = 0, mask = 0;
-
-       if ((channel_flag & (SINGLE_CHANNEL | RANGE_CHANNEL)) == 0)
-               return tmp;
-       if (channel_flag & RANGE_CHANNEL) {     /* Range of channels */
-               for (i = start_channel; i <= stop_channel; i++) {
-                       mask = 1 << (i - 1);
-                       tmp |= mask;
-               }
-       } else {                                        /* Single channel */
-               mask = 1 << (stop_channel - 1);
-               tmp |= mask;
-       }
-       return tmp;
-}
-
-
-unsigned long parse_active_channel(char *val)
-{
-       int channel_flag = 0;
-       char *ptr = val;
-       int channel = 0, start_channel = 0;
-       unsigned long tmp = 0;
-
-       if (strcmp(val, "ALL") == 0)
-               return ENABLE_ALL_CHANNELS;
-
-       while (*ptr != '\0') {
-               if (isdigit(*ptr)) {
-                       channel = strtoul(ptr, &ptr, 10);
-                       channel_flag |= SINGLE_CHANNEL;
-               } else {
-                       if (*ptr == '-') {
-                               channel_flag |= RANGE_CHANNEL;
-                               start_channel = channel;
-                       } else {
-                               tmp |= get_active_channels(channel_flag, start_channel, channel);
-                               channel_flag = 0;
-                       }
-                       ptr++;
-               }
-       }
-       if (channel_flag) {
-               tmp |= get_active_channels(channel_flag, start_channel, channel);
-       }
-       return tmp;
-}
-
-void u_delay(int usec)
-{
-       struct timeval tv;
-       tv.tv_usec = usec;
-       tv.tv_sec = 0;
-
-       select(0, NULL, NULL, NULL, &tv);
-}
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/g711.h b/src/mod/endpoints/mod_wanpipe/libsangoma/g711.h
deleted file mode 100644 (file)
index 73533d7..0000000
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * SpanDSP - a series of DSP components for telephony
- *
- * g711.h - In line A-law and u-law conversion routines
- *
- * Written by Steve Underwood <steveu@coppice.org>
- *
- * Copyright (C) 2001 Steve Underwood
- *
- *  Despite my general liking of the GPL, I place this code in the
- *  public domain for the benefit of all mankind - even the slimy
- *  ones who might try to proprietize my work and use it to my
- *  detriment.
- *
- * $Id: g711.h,v 1.1 2006/06/07 15:46:39 steveu Exp $
- */
-
-/*! \file */
-
-/*! \page g711_page A-law and mu-law handling
-Lookup tables for A-law and u-law look attractive, until you consider the impact
-on the CPU cache. If it causes a substantial area of your processor cache to get
-hit too often, cache sloshing will severely slow things down. The main reason
-these routines are slow in C, is the lack of direct access to the CPU's "find
-the first 1" instruction. A little in-line assembler fixes that, and the
-conversion routines can be faster than lookup tables, in most real world usage.
-A "find the first 1" instruction is available on most modern CPUs, and is a
-much underused feature. 
-
-If an assembly language method of bit searching is not available, these routines
-revert to a method that can be a little slow, so the cache thrashing might not
-seem so bad :(
-
-Feel free to submit patches to add fast "find the first 1" support for your own
-favourite processor.
-
-Look up tables are used for transcoding between A-law and u-law, since it is
-difficult to achieve the precise transcoding procedure laid down in the G.711
-specification by other means.
-*/
-
-#if !defined(_G711_H_)
-#define _G711_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef _MSC_VER
-#ifndef __inline__
-#define __inline__ __inline
-#endif
-       typedef unsigned __int8 uint8_t;
-       typedef __int16 int16_t;
-       typedef __int32 int32_t;
-       typedef unsigned __int16 uint16_t;
-#endif
-
-#if defined(__i386__)
-/*! \brief Find the bit position of the highest set bit in a word
-    \param bits The word to be searched
-    \return The bit number of the highest set bit, or -1 if the word is zero. */
-       static __inline__ int top_bit(unsigned int bits) {
-               int res;
-
-               __asm__ __volatile__(" movl $-1,%%edx;\n" " bsrl %%eax,%%edx;\n":"=d"(res)
-                                                        :"a"    (bits));
-                       return res;
-       }
-       /*- End of function --------------------------------------------------------*//*! \brief Find the bit position of the lowest set bit in a word
-          \param bits The word to be searched
-          \return The bit number of the lowest set bit, or -1 if the word is zero. */ static __inline__ int bottom_bit(unsigned int bits) {
-               int res;
-
-               __asm__ __volatile__(" movl $-1,%%edx;\n" " bsfl %%eax,%%edx;\n":"=d"(res)
-                                                        :"a"    (bits));
-               return res;
-       }
-/*- End of function --------------------------------------------------------*/
-#elif defined(__x86_64__)
-       static __inline__ int top_bit(unsigned int bits) {
-               int res;
-
-               __asm__ __volatile__(" movq $-1,%%rdx;\n" " bsrq %%rax,%%rdx;\n":"=d"(res)
-                                                        :"a"    (bits));
-                       return res;
-       }
-/*- End of function --------------------------------------------------------*/ static __inline__ int bottom_bit(unsigned int bits) {
-               int res;
-
-               __asm__ __volatile__(" movq $-1,%%rdx;\n" " bsfq %%rax,%%rdx;\n":"=d"(res)
-                                                        :"a"    (bits));
-               return res;
-       }
-/*- End of function --------------------------------------------------------*/
-#else
-       static __inline__ int top_bit(unsigned int bits) {
-               int i;
-
-               if  (bits == 0)
-                       return -1;
-                   i = 0;
-               if  (bits & 0xFFFF0000) {
-                       bits &= 0xFFFF0000;
-                       i += 16;
-               }
-               if     (bits & 0xFF00FF00) {
-                       bits &= 0xFF00FF00;
-                       i += 8;
-               }
-               if (bits & 0xF0F0F0F0) {
-                       bits &= 0xF0F0F0F0;
-                       i += 4;
-               }
-               if (bits & 0xCCCCCCCC) {
-                       bits &= 0xCCCCCCCC;
-                       i += 2;
-               }
-               if (bits & 0xAAAAAAAA) {
-                       bits &= 0xAAAAAAAA;
-                       i += 1;
-               }
-               return i;
-       }
-/*- End of function --------------------------------------------------------*/
-
-       static __inline__ int bottom_bit(unsigned int bits) {
-               int i;
-
-               if (bits == 0)
-                       return -1;
-               i = 32;
-               if (bits & 0x0000FFFF) {
-                       bits &= 0x0000FFFF;
-                       i -= 16;
-               }
-               if (bits & 0x00FF00FF) {
-                       bits &= 0x00FF00FF;
-                       i -= 8;
-               }
-               if (bits & 0x0F0F0F0F) {
-                       bits &= 0x0F0F0F0F;
-                       i -= 4;
-               }
-               if (bits & 0x33333333) {
-                       bits &= 0x33333333;
-                       i -= 2;
-               }
-               if (bits & 0x55555555) {
-                       bits &= 0x55555555;
-                       i -= 1;
-               }
-               return i;
-       }
-/*- End of function --------------------------------------------------------*/
-#endif
-
-/* N.B. It is tempting to use look-up tables for A-law and u-law conversion.
- *      However, you should consider the cache footprint.
- *
- *      A 64K byte table for linear to x-law and a 512 byte table for x-law to
- *      linear sound like peanuts these days, and shouldn't an array lookup be
- *      real fast? No! When the cache sloshes as badly as this one will, a tight
- *      calculation may be better. The messiest part is normally finding the
- *      segment, but a little inline assembly can fix that on an i386, x86_64 and
- *      many other modern processors.
- */
-
-/*
- * Mu-law is basically as follows:
- *
- *      Biased Linear Input Code        Compressed Code
- *      ------------------------        ---------------
- *      00000001wxyza                   000wxyz
- *      0000001wxyzab                   001wxyz
- *      000001wxyzabc                   010wxyz
- *      00001wxyzabcd                   011wxyz
- *      0001wxyzabcde                   100wxyz
- *      001wxyzabcdef                   101wxyz
- *      01wxyzabcdefg                   110wxyz
- *      1wxyzabcdefgh                   111wxyz
- *
- * Each biased linear code has a leading 1 which identifies the segment
- * number. The value of the segment number is equal to 7 minus the number
- * of leading 0's. The quantization interval is directly available as the
- * four bits wxyz.  * The trailing bits (a - h) are ignored.
- *
- * Ordinarily the complement of the resulting code word is used for
- * transmission, and so the code word is complemented before it is returned.
- *
- * For further information see John C. Bellamy's Digital Telephony, 1982,
- * John Wiley & Sons, pps 98-111 and 472-476.
- */
-
-//#define ULAW_ZEROTRAP                 /* turn on the trap as per the MIL-STD */
-#define ULAW_BIAS        0x84  /* Bias for linear code. */
-
-/*! \brief Encode a linear sample to u-law
-    \param linear The sample to encode.
-    \return The u-law value.
-*/
-       static __inline__ uint8_t linear_to_ulaw(int linear) {
-               uint8_t u_val;
-               int mask;
-               int seg;
-
-               /* Get the sign and the magnitude of the value. */
-               if (linear < 0) {
-                       linear = ULAW_BIAS - linear;
-                       mask = 0x7F;
-               } else {
-                       linear = ULAW_BIAS + linear;
-                       mask = 0xFF;
-               }
-
-               seg = top_bit(linear | 0xFF) - 7;
-
-               /*
-                * Combine the sign, segment, quantization bits,
-                * and complement the code word.
-                */
-               if (seg >= 8)
-                       u_val = (uint8_t) (0x7F ^ mask);
-               else
-                       u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
-#ifdef ULAW_ZEROTRAP
-               /* Optional ITU trap */
-               if (u_val == 0)
-                       u_val = 0x02;
-#endif
-               return u_val;
-       }
-/*- End of function --------------------------------------------------------*/
-
-/*! \brief Decode an u-law sample to a linear value.
-    \param ulaw The u-law sample to decode.
-    \return The linear value.
-*/
-       static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) {
-               int t;
-
-               /* Complement to obtain normal u-law value. */
-               ulaw = ~ulaw;
-               /*
-                * Extract and bias the quantization bits. Then
-                * shift up by the segment number and subtract out the bias.
-                */
-               t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
-               return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
-       }
-/*- End of function --------------------------------------------------------*/
-
-/*
- * A-law is basically as follows:
- *
- *      Linear Input Code        Compressed Code
- *      -----------------        ---------------
- *      0000000wxyza             000wxyz
- *      0000001wxyza             001wxyz
- *      000001wxyzab             010wxyz
- *      00001wxyzabc             011wxyz
- *      0001wxyzabcd             100wxyz
- *      001wxyzabcde             101wxyz
- *      01wxyzabcdef             110wxyz
- *      1wxyzabcdefg             111wxyz
- *
- * For further information see John C. Bellamy's Digital Telephony, 1982,
- * John Wiley & Sons, pps 98-111 and 472-476.
- */
-
-#define ALAW_AMI_MASK       0x55
-
-/*! \brief Encode a linear sample to A-law
-    \param linear The sample to encode.
-    \return The A-law value.
-*/
-       static __inline__ uint8_t linear_to_alaw(int linear) {
-               int mask;
-               int seg;
-
-               if (linear >= 0) {
-                       /* Sign (bit 7) bit = 1 */
-                       mask = ALAW_AMI_MASK | 0x80;
-               } else {
-                       /* Sign (bit 7) bit = 0 */
-                       mask = ALAW_AMI_MASK;
-                       linear = -linear - 8;
-               }
-
-               /* Convert the scaled magnitude to segment number. */
-               seg = top_bit(linear | 0xFF) - 7;
-               if (seg >= 8) {
-                       if (linear >= 0) {
-                               /* Out of range. Return maximum value. */
-                               return (uint8_t) (0x7F ^ mask);
-                       }
-                       /* We must be just a tiny step below zero */
-                       return (uint8_t) (0x00 ^ mask);
-               }
-               /* Combine the sign, segment, and quantization bits. */
-               return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
-       }
-/*- End of function --------------------------------------------------------*/
-
-/*! \brief Decode an A-law sample to a linear value.
-    \param alaw The A-law sample to decode.
-    \return The linear value.
-*/
-       static __inline__ int16_t alaw_to_linear(uint8_t alaw) {
-               int i;
-               int seg;
-
-               alaw ^= ALAW_AMI_MASK;
-               i = ((alaw & 0x0F) << 4);
-               seg = (((int) alaw & 0x70) >> 4);
-               if (seg)
-                       i = (i + 0x108) << (seg - 1);
-               else
-                       i += 8;
-               return (int16_t) ((alaw & 0x80) ? i : -i);
-       }
-/*- End of function --------------------------------------------------------*/
-
-/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711.
-    \param alaw The A-law sample to transcode.
-    \return The best matching u-law value.
-*/
-       uint8_t alaw_to_ulaw(uint8_t alaw);
-
-/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711.
-    \param alaw The u-law sample to transcode.
-    \return The best matching A-law value.
-*/
-       uint8_t ulaw_to_alaw(uint8_t ulaw);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-/*- End of file ------------------------------------------------------------*/
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c
deleted file mode 100644 (file)
index 165066b..0000000
+++ /dev/null
@@ -1,948 +0,0 @@
-#include "libsangoma.h"
-#include <stdarg.h>
-
-#define DFT_CARD "wanpipe1"
-
-#if defined(WIN32)
-//extern int   verbose;
-
-#define DEV_NAME_LEN   100
-char device_name[DEV_NAME_LEN];
-
-/* IOCTL management structures and variables*/
-wan_udp_hdr_t  wan_udp;
-
-#include "win_api_common.h"
-
-static wan_cmd_api_t api_cmd;
-static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data;
-
-/* keeps the LAST (and single) event received */
-static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer;
-
-#endif /* WIN32 */
-
-void sangoma_socket_close(sng_fd_t *sp) 
-{
-#if defined(WIN32)
-       if(     *sp != INVALID_HANDLE_VALUE){
-               CloseHandle(*sp);
-               *sp = INVALID_HANDLE_VALUE;
-       }
-#else
-    if (*sp > -1) {
-       close(*sp);
-       *sp = -1;
-    }
-#endif
-}
-
-int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags)
-{
-#if defined(WIN32)
-       API_POLL_STRUCT api_poll;
-
-       memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT));
-       
-       api_poll.user_flags_bitmap = flags;
-
-       if(DoApiPollCommand(fd, &api_poll)){
-               //failed
-               return 0;
-       }
-
-       switch(api_poll.operation_status)
-       {
-               case SANG_STATUS_RX_DATA_AVAILABLE:
-                       break;
-
-               default:
-                       prn(1, "Error: sangoma_socket_waitfor(): Unknown Operation Status: %d\n", 
-                               api_poll.operation_status);
-                       return 0;
-       }//switch()
-
-       if(api_poll.poll_events_bitmap == 0){
-               prn(1, "Error: invalid Poll Events bitmap: 0x%X\n",
-                       api_poll.poll_events_bitmap);
-       }
-       return api_poll.poll_events_bitmap;
-#else
-    struct pollfd pfds[1];
-    int res;
-
-    memset(&pfds[0], 0, sizeof(pfds[0]));
-    pfds[0].fd = fd;
-    pfds[0].events = flags;
-    res = poll(pfds, 1, timeout);
-    if (res > 0) {
-       if ((pfds[0].revents & POLLERR)) {
-               res = -1;
-       } else if((pfds[0].revents)) {
-               res = 1;
-       }
-    }
-
-    return res;
-#endif
-}
-
-
-int sangoma_span_chan_toif(int span, int chan, char *interface_name)
-{
-       sprintf(interface_name,"s%ic%i",span,chan);
-       return 0;
-}
-
-int sangoma_interface_toi(char *interface_name, int *span, int *chan)
-{
-       char *p=NULL, *sp = NULL, *ch = NULL;
-       int ret = 0;
-       char data[FNAME_LEN];
-
-       strncpy(data, interface_name, FNAME_LEN);
-       if ((data[0])) {
-               for (p = data; *p; p++) {
-                       if (sp && *p == 'g') {
-                               *p = '\0';
-                               ch = (p + 1);
-                               break;
-                       } else if (*p == 'w') {
-                               sp = (p + 1);
-                       }
-               }
-
-               if(ch && sp) {
-                       *span = atoi(sp);
-                       *chan = atoi(ch);
-                       ret = 1;
-               } else {
-                       *span = -1;
-                       *chan = -1;
-               }
-       }
-
-       return ret;
-}
-
-int sangoma_span_chan_fromif(char *interface_name, int *span, int *chan)
-{
-       char *p = NULL, *sp = NULL, *ch = NULL;
-       int ret = 0;
-       char data[FNAME_LEN];
-
-       strncpy(data, interface_name, FNAME_LEN);
-       if ((data[0])) {
-               for (p = data; *p; p++) {
-                       if (sp && *p == 'c') {
-                               *p = '\0';
-                               ch = (p + 1);
-                               break;
-                       } else if (*p == 's') {
-                               sp = (p + 1);
-                       }
-               }
-
-               if(ch && sp) {
-                       *span = atoi(sp);
-                       *chan = atoi(ch);
-                       ret = 1;
-               } else {
-                       *span = -1;
-                       *chan = -1;
-               }
-       }
-
-       return ret;
-}
-
-sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan) 
-{
-       char fname[FNAME_LEN];
-#if defined(WIN32)
-
-       //NOTE: under Windows Interfaces are zero based but 'chan' is 1 based.
-       //              Subtract 1 from 'chan'.
-       _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1);
-
-       //prn(verbose, "Opening device: %s...\n", fname);
-
-       return CreateFile(      fname, 
-                                               GENERIC_READ | GENERIC_WRITE, 
-                                               FILE_SHARE_READ | FILE_SHARE_WRITE,
-                                               (LPSECURITY_ATTRIBUTES)NULL, 
-                                               OPEN_EXISTING,
-                                               FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
-                                               (HANDLE)NULL
-                                               );
-#else
-       int fd=-1;
-
-       sprintf(fname,"/dev/wptdm_s%dc%d",span,chan);
-
-       fd = open(fname, O_RDWR);
-
-       return fd;  
-#endif
-}            
-
-sng_fd_t sangoma_create_socket_by_name(char *device, char *card) 
-{
-       int span,chan;
-       sangoma_interface_toi(device,&span,&chan);
-       
-       return sangoma_open_tdmapi_span_chan(span,chan);
-}
-
-          
-sng_fd_t sangoma_open_tdmapi_span(int span) 
-{
-    int i=0;
-#if defined(WIN32)
-       sng_fd_t fd = INVALID_HANDLE_VALUE;
-
-       for(i = 1; i < 32; i++){
-               if((fd = sangoma_open_tdmapi_span_chan(span, i)) == INVALID_HANDLE_VALUE){
-                       //prn(verbose, "Span: %d, chan: %d: is not running, consider 'busy'\n",
-                       //      span, i);
-                       continue;
-               }
-
-               //get the open handle counter
-               wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; 
-               wan_udp.wan_udphdr_data_len = 0;
-
-               DoManagementCommand(fd, &wan_udp);
-               if(wan_udp.wan_udphdr_return_code){
-                       prn(1, "Error: command GET_OPEN_HANDLES_COUNTER failed! Span: %d, chan: %d\n",
-                               span, i);
-                       //don't forget to close!! otherwize counter will stay incremented.
-                       sangoma_socket_close(&fd);
-                       continue;
-               }
-
-               //prn(verbose, "open handles counter: %d\n", *(int*)&wan_udp.wan_udphdr_data[0]);
-               if(*(int*)&wan_udp.wan_udphdr_data[0] == 1){
-                       //this is the only process using this chan/span, so it is 'free'
-                       //prn(verbose, "Found 'free' Span: %d, chan: %d\n",span, i);
-                       break;
-               }
-               //don't forget to close!! otherwize counter will stay incremented.
-               sangoma_socket_close(&fd);
-       }//for()
-
-#else
-    unsigned char fname[FNAME_LEN];
-       int fd=0;
-       for (i=1;i<32;i++){
-               sprintf(fname,"/dev/wptdm_s%dc%d",span,i);
-               fd = open(fname, O_RDWR);
-               if (fd < 0){
-               continue;
-               }
-               break;
-       }
-#endif 
-    return fd;  
-}      
-
-static char *cut_path(char *in)
-{
-       char *p, *ret = in;
-       char delims[] = "/\\";
-       char *i;
-
-       for (i = delims; *i; i++) {
-               p = in;
-               while ((p = strchr(p, *i)) != 0) {
-                       ret = ++p;
-               }
-       }
-       return ret;
-}
-
-
-static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...)
-{
-       char *fp;
-       char data[1024];
-
-       va_list ap;
-       
-       fp = cut_path(file);
-
-       va_start(ap, fmt);
-
-       vsnprintf(data, sizeof(data), fmt, ap);
-
-       fprintf(stderr, "%s:%d %s() %s", file, line, func, data);
-
-       va_end(ap);
-
-}
-
-sangoma_logger_t global_logger = default_logger;
-
-void sangoma_set_logger(sangoma_logger_t logger)
-{
-       global_logger = logger;
-}
-
-int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag)
-{
-       int rx_len=0;
-
-#if defined(WIN32)
-       static RX_DATA_STRUCT   rx_data;
-       api_header_t                    *pri;
-       wp_tdm_api_rx_hdr_t             *tdm_api_rx_hdr;
-       wp_tdm_api_rx_hdr_t             *user_buf = (wp_tdm_api_rx_hdr_t*)hdrbuf;
-
-       if(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){
-               //error
-               prn(1, "Error: sangoma_readmsg_tdm(): invalid size of user's 'header buffer'.\
-Should be 'sizeof(wp_tdm_api_rx_hdr_t)'.\n");
-               return -1;
-       }
-
-       if(DoReadCommand(fd, &rx_data) ){
-               //error
-               prn(1, "Error: DoReadCommand() failed! Check messages log.\n");
-               return -1;
-       }
-
-       //use our special buffer at rxdata to hold received data
-       pri = &rx_data.api_header;
-       tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t*)rx_data.data;
-
-       user_buf->wp_tdm_api_event_type = pri->operation_status;
-
-       switch(pri->operation_status)
-       {
-       case SANG_STATUS_RX_DATA_AVAILABLE:
-               //prn(verbose, "SANG_STATUS_RX_DATA_AVAILABLE\n");
-
-               if(pri->data_length > datalen){
-                       rx_len=0;
-                       break;
-               }
-               memcpy(databuf, rx_data.data, pri->data_length);
-               rx_len = pri->data_length;
-               break;
-
-       case SANG_STATUS_TDM_EVENT_AVAILABLE:
-               //prn(verbose, "SANG_STATUS_TDM_EVENT_AVAILABLE\n");
-
-               //make event is accessable for the caller directly:
-               memcpy(databuf, rx_data.data, pri->data_length);
-               rx_len = pri->data_length;
-
-               //make copy for use with sangoma_tdm_read_event() - indirect access.
-               memcpy( &last_tdm_api_event_buffer,     tdm_api_rx_hdr, sizeof(wp_tdm_api_rx_hdr_t));
-               break;
-
-       default:
-               switch(pri->operation_status)
-               {
-               case SANG_STATUS_RX_DATA_TIMEOUT:
-                       //no data in READ_CMD_TIMEOUT, try again.
-                       prn(1, "Error: Timeout on read.\n");
-                       break;
-
-               case SANG_STATUS_BUFFER_TOO_SMALL:
-                       //Recieved data longer than the pre-configured maximum.
-                       //Maximum length is set in 'Interface Properties',
-                       //in the 'Device Manager'.
-                       prn(1, "Error: Received data longer than buffer passed to API.\n");
-                       break;
-
-               case SANG_STATUS_LINE_DISCONNECTED:
-                       //Front end monitoring is enabled and Line is
-                       //in disconnected state.
-                       //Check the T1/E1 line is in "Connected" state,
-                       //alse check the Alarms and the message log.
-                       prn(1, "Error: Line disconnected.\n");
-                       break;
-
-               default:
-                       prn(1, "Rx:Unknown Operation Status: %d\n", pri->operation_status);
-                       break;
-               }//switch()
-               return 0;
-       }//switch()
-
-#else
-       struct msghdr msg;
-       struct iovec iov[2];
-
-       memset(&msg,0,sizeof(struct msghdr));
-
-       iov[0].iov_len=hdrlen;
-       iov[0].iov_base=hdrbuf;
-
-       iov[1].iov_len=datalen;
-       iov[1].iov_base=databuf;
-
-       msg.msg_iovlen=2;
-       msg.msg_iov=iov;
-
-       rx_len = read(fd,&msg,datalen+hdrlen);
-
-       if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)){
-               return -EINVAL;
-       }
-
-       rx_len-=sizeof(wp_tdm_api_rx_hdr_t);
-#endif
-    return rx_len;
-}                    
-
-int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen, int flag)
-{
-       int bsent;
-
-#if defined(WIN32)
-       static TX_DATA_STRUCT   local_tx_data;
-       api_header_t                    *pri;
-
-       pri = &local_tx_data.api_header;
-
-       pri->data_length = datalen;
-       memcpy(local_tx_data.data, databuf, pri->data_length);
-
-       //queue data for transmission
-       if(     DoWriteCommand(fd, &local_tx_data)){
-               //error
-               prn(1, "Error: DoWriteCommand() failed!! Check messages log.\n");
-               return -1;
-       }
-
-       bsent=0;
-       //check that frame was transmitted
-       switch(local_tx_data.api_header.operation_status)
-       {
-       case SANG_STATUS_SUCCESS:
-               bsent = datalen;
-               break;
-                               
-       case SANG_STATUS_TX_TIMEOUT:
-               //error
-               prn(1, "****** Error: SANG_STATUS_TX_TIMEOUT ******\n");
-               //Check messages log or look at statistics.
-               break;
-                               
-       case SANG_STATUS_TX_DATA_TOO_LONG:
-               //Attempt to transmit data longer than the pre-configured maximum.
-               //Maximum length is set in 'Interface Properties',
-               //in the 'Device Manager'.
-               prn(1, "****** SANG_STATUS_TX_DATA_TOO_LONG ******\n");
-               break;
-                               
-       case SANG_STATUS_TX_DATA_TOO_SHORT:
-               //Minimum is 1 byte  for Primary   port,
-               //                       2 bytes for Secondary port
-               prn(1, "****** SANG_STATUS_TX_DATA_TOO_SHORT ******\n");
-               break;
-
-       case SANG_STATUS_LINE_DISCONNECTED:
-               //Front end monitoring is enabled and Line is
-               //in disconnected state.
-               //Check the T1/E1 line is in "Connected" state,
-               //alse check the Alarms and the message log.
-               prn(1, "****** SANG_STATUS_LINE_DISCONNECTED ******\n");
-               break;
-
-       default:
-               prn(1, "Unknown return code (0x%X) on transmission!\n",
-                       local_tx_data.api_header.operation_status);
-               break;
-       }//switch()
-#else
-       struct msghdr msg;
-       struct iovec iov[2];
-
-       memset(&msg,0,sizeof(struct msghdr));
-
-       iov[0].iov_len=hdrlen;
-       iov[0].iov_base=hdrbuf;
-
-       iov[1].iov_len=datalen;
-       iov[1].iov_base=databuf;
-
-       msg.msg_iovlen=2;
-       msg.msg_iov=iov;
-
-       bsent = write(fd,&msg,datalen+hdrlen);
-       if (bsent > 0){
-               bsent-=sizeof(wp_tdm_api_tx_hdr_t);
-       }
-#endif
-       return bsent;
-}
-
-
-#ifdef WANPIPE_TDM_API
-
-/*========================================================
- * Execute TDM command
- *
- */
-int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-
-#if defined(WIN32)
-       err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd);
-#else
-       err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd);
-       if (err < 0){
-               char tmp[50];
-               sprintf(tmp,"TDM API: CMD: %i\n",tdm_api->wp_tdm_cmd.cmd);
-               perror(tmp);
-               return -1;
-       }
-#endif
-       return err;
-}
-
-/*========================================================
- * Get Full TDM API configuration per channel
- *
- */
-int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_FULL_CFG;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       printf("TDM API CFG:\n");
-       printf("\thw_tdm_coding:\t%d\n",tdm_api->wp_tdm_cmd.hw_tdm_coding);
-       printf("\tusr_mtu_mru:\t%d\n",tdm_api->wp_tdm_cmd.hw_mtu_mru);
-       printf("\tusr_period:\t%d\n",tdm_api->wp_tdm_cmd.usr_period);
-       printf("\ttdm_codec:\t%d\n",tdm_api->wp_tdm_cmd.tdm_codec);
-       printf("\tpower_level:\t%d\n",tdm_api->wp_tdm_cmd.power_level);
-       printf("\trx_disable:\t%d\n",tdm_api->wp_tdm_cmd.rx_disable);
-       printf("\ttx_disable:\t%d\n",tdm_api->wp_tdm_cmd.tx_disable);
-       printf("\tusr_mtu_mru:\t%d\n",tdm_api->wp_tdm_cmd.usr_mtu_mru);
-       printf("\tidle flag:\t0x%02X\n",tdm_api->wp_tdm_cmd.idle_flag);
-       printf("\tfe alarms:\t0x%02X\n",tdm_api->wp_tdm_cmd.fe_alarms);
-       
-       printf("\trx pkt\t%d\ttx pkt\t%d\n",tdm_api->wp_tdm_cmd.stats.rx_packets,
-                               tdm_api->wp_tdm_cmd.stats.tx_packets);
-       printf("\trx err\t%d\ttx err\t%d\n",
-                               tdm_api->wp_tdm_cmd.stats.rx_errors,
-                               tdm_api->wp_tdm_cmd.stats.tx_errors);
-#ifndef __WINDOWS__
-       printf("\trx ovr\t%d\ttx idl\t%d\n",
-                               tdm_api->wp_tdm_cmd.stats.rx_fifo_errors,
-                               tdm_api->wp_tdm_cmd.stats.tx_carrier_errors);
-#endif                         
-       
-       return 0;
-}
-
-/*========================================================
- * SET Codec on a particular Channel.
- * 
- * Available codecs are defined in 
- * /usr/src/linux/include/linux/wanpipe_cfg.h
- * 
- * enum wan_codec_format {
- *     WP_NONE,
- *     WP_SLINEAR
- * }
- *
- */
-int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC;
-       tdm_api->wp_tdm_cmd.tdm_codec = codec;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-
-       return err;
-}
-
-/*========================================================
- * GET Codec from a particular Channel.
- * 
- * Available codecs are defined in 
- * /usr/src/linux/include/linux/wanpipe_cfg.h
- * 
- * enum wan_codec_format {
- *     WP_NONE,
- *     WP_SLINEAR
- * }
- *
- */
-int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_CODEC;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return tdm_api->wp_tdm_cmd.tdm_codec;   
-}
-
-
-/*========================================================
- * SET Rx/Tx Hardware Period in milliseconds.
- * 
- * Available options are:
- *  10,20,30,40,50 ms      
- *
- */
-int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD;
-       tdm_api->wp_tdm_cmd.usr_period = period;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-
-       return err;
-}
-
-/*========================================================
- * GET Rx/Tx Hardware Period in milliseconds.
- * 
- * Available options are:
- *  10,20,30,40,50 ms      
- *
- */
-int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return tdm_api->wp_tdm_cmd.usr_period;
-}
-
-/*========================================================
- * GET Current User Hardware Coding Format
- *
- * Coding Format will be ULAW/ALAW based on T1/E1 
- */
-
-int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api)
-{
-        int err;
-        tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING;
-        err=sangoma_tdm_cmd_exec(fd,tdm_api);
-        if (err){
-                return err;
-        }
-        return tdm_api->wp_tdm_cmd.hw_tdm_coding;
-}
-
-
-/*========================================================
- * GET Current User MTU/MRU values in bytes.
- * 
- * The USER MTU/MRU values will change each time a PERIOD
- * or CODEC is adjusted.
- */
-int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_MTU_MRU;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return tdm_api->wp_tdm_cmd.usr_mtu_mru;
-}
-
-/*========================================================
- * SET TDM Power Level
- * 
- * This option is not implemented yet
- *
- */
-int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_POWER_LEVEL;
-       tdm_api->wp_tdm_cmd.power_level = power;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-
-       return err;
-}
-
-/*========================================================
- * GET TDM Power Level
- * 
- * This option is not implemented yet
- *
- */
-int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_POWER_LEVEL;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return tdm_api->wp_tdm_cmd.power_level;
-}
-
-int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-#if 0
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_FLUSH_BUFFERS;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-#endif
-       return 0;
-}
-
-int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec) {
-       
-       int err;
-       
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RBS_EVENTS;
-       tdm_api->wp_tdm_cmd.rbs_poll=poll_in_sec; 
-       
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return tdm_api->wp_tdm_cmd.rbs_poll;
-}
-
-
-int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) {
-
-       int err;
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RBS_EVENTS;
-       
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}
-
-int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs) 
-{
-       
-       int err;
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS;
-       tdm_api->wp_tdm_cmd.rbs_tx_bits=rbs; 
-       
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}        
-
-int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
-{
-       wp_tdm_api_rx_hdr_t *rx_event;
-
-#if defined(WIN32)     
-       rx_event = &last_tdm_api_event_buffer;
-#else
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
-       
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       rx_event = &tdm_api->wp_tdm_cmd.event;
-#endif
-
-       switch (rx_event->wp_tdm_api_event_type){
-       
-       case WP_TDM_EVENT_RBS:
-               printf("%d: GOT RBS EVENT %p\n",(int)fd,tdm_api->wp_tdm_event.wp_rbs_event);
-               if (tdm_api->wp_tdm_event.wp_rbs_event) {
-                       tdm_api->wp_tdm_event.wp_rbs_event(fd,rx_event->wp_tdm_api_event_rbs_rx_bits);
-               }
-               
-               break;
-               
-       case WP_TDM_EVENT_DTMF:
-               printf("%d: GOT DTMF EVENT\n",(int)fd);
-               if (tdm_api->wp_tdm_event.wp_dtmf_event) {
-                       tdm_api->wp_tdm_event.wp_dtmf_event(fd,
-                                               rx_event->wp_tdm_api_event_dtmf_digit,
-                                               rx_event->wp_tdm_api_event_dtmf_type,
-                                               rx_event->wp_tdm_api_event_dtmf_port);
-               }
-               break;
-               
-       case WP_TDM_EVENT_RXHOOK:
-               printf("%d: GOT RXHOOK EVENT\n",(int)fd);
-               if (tdm_api->wp_tdm_event.wp_rxhook_event) {
-                       tdm_api->wp_tdm_event.wp_rxhook_event(fd,
-                                               rx_event->wp_tdm_api_event_rxhook_state);
-               }
-               break;
-
-       case WP_TDM_EVENT_RING_DETECT:
-               printf("%d: GOT RXRING EVENT\n",(int)fd);
-               if (tdm_api->wp_tdm_event.wp_rxring_event) {
-                       tdm_api->wp_tdm_event.wp_rxring_event(fd,
-                                               rx_event->wp_tdm_api_event_ring_state);
-               }
-               break;
-
-       case WP_TDM_EVENT_RING_TRIP:
-               printf("%d: GOT ROUTING TRIP EVENT\n",(int)fd);
-               if (tdm_api->wp_tdm_event.wp_ringtrip_event) {
-                       tdm_api->wp_tdm_event.wp_ringtrip_event(fd,
-                                               rx_event->wp_tdm_api_event_ring_state);
-               }
-               break;
-
-       case WP_TDM_EVENT_FE_ALARM:
-               printf("%d: GOT FE ALARMS EVENT %i\n",(int)fd,
-                               rx_event->wp_tdm_api_event_fe_alarm);
-               if (tdm_api->wp_tdm_event.wp_fe_alarm_event) {
-                       tdm_api->wp_tdm_event.wp_fe_alarm_event(fd,
-                                               rx_event->wp_tdm_api_event_fe_alarm);
-               }    
-               
-       default:
-               printf("%d: Unknown TDM event!", (int)fd);
-               break;
-       }
-       
-       return 0;
-}        
-
-int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-       
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_DTMF_EVENTS;
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}
-
-int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_DTMF_EVENTS;
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}
-
-int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
-{
-       int err;
-       
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RM_DTMF_EVENTS;
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}
-
-int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RM_DTMF_EVENTS;
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}
-
-int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RXHOOK_EVENTS;
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}
-
-int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RXHOOK_EVENTS;
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return 0;
-}
-
-/*========================================================
- * GET Front End Alarms
- * 
- */
-int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
-{
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_FE_ALARMS;
-
-       err=sangoma_tdm_cmd_exec(fd,tdm_api);
-       if (err){
-               return err;
-       }
-
-       return tdm_api->wp_tdm_cmd.fe_alarms;
-}         
-
-#endif /* WANPIPE_TDM_API */
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.dsp b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.dsp
deleted file mode 100644 (file)
index 2ddb9af..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-# Microsoft Developer Studio Project File - Name="libsangoma" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Static Library" 0x0104\r
-\r
-CFG=libsangoma - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "libsangoma.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "libsangoma.mak" CFG="libsangoma - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "libsangoma - Win32 Release" (based on "Win32 (x86) Static Library")\r
-!MESSAGE "libsangoma - Win32 Debug" (based on "Win32 (x86) Static Library")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "libsangoma - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir "Release"\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c\r
-# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LIB32=link.exe -lib\r
-# ADD BASE LIB32 /nologo\r
-# ADD LIB32 /nologo\r
-\r
-!ELSEIF  "$(CFG)" == "libsangoma - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "Debug"\r
-# PROP BASE Intermediate_Dir "Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir "Debug"\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LIB32=link.exe -lib\r
-# ADD BASE LIB32 /nologo\r
-# ADD LIB32 /nologo\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "libsangoma - Win32 Release"\r
-# Name "libsangoma - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\libsangoma.c\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=.\win_api_common.h\r
-# End Source File\r
-# End Group\r
-# End Target\r
-# End Project\r
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.dsw b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.dsw
deleted file mode 100644 (file)
index 7f1f938..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00\r
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
-\r
-###############################################################################\r
-\r
-Project: "libsangoma"=.\libsangoma.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Global:\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<3>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h
deleted file mode 100644 (file)
index 14a5d99..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-#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
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.so.conf b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.so.conf
deleted file mode 100644 (file)
index e8e4bdc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/usr/local/lib
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.vcproj b/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.vcproj
deleted file mode 100644 (file)
index 16e2097..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioProject\r
-       ProjectType="Visual C++"\r
-       Version="8.00"\r
-       Name="libsangoma"\r
-       ProjectGUID="{7E60CC2D-E818-4712-8F16-C0E6EC64982F}"\r
-       RootNamespace="libsangoma"\r
-       >\r
-       <Platforms>\r
-               <Platform\r
-                       Name="Win32"\r
-               />\r
-       </Platforms>\r
-       <ToolFiles>\r
-       </ToolFiles>\r
-       <Configurations>\r
-               <Configuration\r
-                       Name="Release|Win32"\r
-                       OutputDirectory=".\Release"\r
-                       IntermediateDirectory=".\Release"\r
-                       ConfigurationType="4"\r
-                       InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"\r
-                       UseOfMFC="0"\r
-                       ATLMinimizesCRunTimeLibraryUsage="false"\r
-                       CharacterSet="2"\r
-                       >\r
-                       <Tool\r
-                               Name="VCPreBuildEventTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCCustomBuildTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCXMLDataGeneratorTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCWebServiceProxyGeneratorTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCMIDLTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCCLCompilerTool"\r
-                               Optimization="2"\r
-                               InlineFunctionExpansion="1"\r
-                               AdditionalIncludeDirectories=".;include\api;include\debug;include\octasic;include\pnp;..\libpri"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_LIB;WANPIPE_TDM_API;_CRT_SECURE_NO_DEPRECATE"\r
-                               StringPooling="true"\r
-                               RuntimeLibrary="2"\r
-                               EnableFunctionLevelLinking="true"\r
-                               PrecompiledHeaderFile=".\Release/libsangoma.pch"\r
-                               AssemblerListingLocation=".\Release/"\r
-                               ObjectFile=".\Release/"\r
-                               ProgramDataBaseFileName=".\Release/"\r
-                               WarningLevel="4"\r
-                               WarnAsError="true"\r
-                               SuppressStartupBanner="true"\r
-                               Detect64BitPortabilityProblems="true"\r
-                               DisableSpecificWarnings="4100;4214;4201;4706;4311;4312"\r
-                       />\r
-                       <Tool\r
-                               Name="VCManagedResourceCompilerTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCResourceCompilerTool"\r
-                               PreprocessorDefinitions="NDEBUG"\r
-                               Culture="1033"\r
-                       />\r
-                       <Tool\r
-                               Name="VCPreLinkEventTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCLibrarianTool"\r
-                               OutputFile=".\Release\libsangoma.lib"\r
-                               SuppressStartupBanner="true"\r
-                       />\r
-                       <Tool\r
-                               Name="VCALinkTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCXDCMakeTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCBscMakeTool"\r
-                               SuppressStartupBanner="true"\r
-                               OutputFile=".\Release/libsangoma.bsc"\r
-                       />\r
-                       <Tool\r
-                               Name="VCFxCopTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCPostBuildEventTool"\r
-                       />\r
-               </Configuration>\r
-               <Configuration\r
-                       Name="Debug|Win32"\r
-                       OutputDirectory=".\Debug"\r
-                       IntermediateDirectory=".\Debug"\r
-                       ConfigurationType="4"\r
-                       InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"\r
-                       UseOfMFC="0"\r
-                       ATLMinimizesCRunTimeLibraryUsage="false"\r
-                       CharacterSet="2"\r
-                       >\r
-                       <Tool\r
-                               Name="VCPreBuildEventTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCCustomBuildTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCXMLDataGeneratorTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCWebServiceProxyGeneratorTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCMIDLTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCCLCompilerTool"\r
-                               Optimization="0"\r
-                               AdditionalIncludeDirectories=".;include\api;include\debug;include\octasic;include\pnp;..\libpri"\r
-                               PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__WINDOWS__;WANPIPE_TDM_API;_CRT_SECURE_NO_DEPRECATE"\r
-                               MinimalRebuild="true"\r
-                               BasicRuntimeChecks="3"\r
-                               RuntimeLibrary="3"\r
-                               PrecompiledHeaderFile=".\Debug/libsangoma.pch"\r
-                               AssemblerListingLocation=".\Debug/"\r
-                               ObjectFile=".\Debug/"\r
-                               ProgramDataBaseFileName=".\Debug/"\r
-                               WarningLevel="4"\r
-                               WarnAsError="true"\r
-                               SuppressStartupBanner="true"\r
-                               Detect64BitPortabilityProblems="true"\r
-                               DebugInformationFormat="3"\r
-                               DisableSpecificWarnings="4100;4214;4201;4706;4311;4312"\r
-                       />\r
-                       <Tool\r
-                               Name="VCManagedResourceCompilerTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCResourceCompilerTool"\r
-                               PreprocessorDefinitions="_DEBUG"\r
-                               Culture="1033"\r
-                       />\r
-                       <Tool\r
-                               Name="VCPreLinkEventTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCLibrarianTool"\r
-                               OutputFile=".\Debug\libsangoma.lib"\r
-                               SuppressStartupBanner="true"\r
-                       />\r
-                       <Tool\r
-                               Name="VCALinkTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCXDCMakeTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCBscMakeTool"\r
-                               SuppressStartupBanner="true"\r
-                               OutputFile=".\Debug/libsangoma.bsc"\r
-                       />\r
-                       <Tool\r
-                               Name="VCFxCopTool"\r
-                       />\r
-                       <Tool\r
-                               Name="VCPostBuildEventTool"\r
-                       />\r
-               </Configuration>\r
-       </Configurations>\r
-       <References>\r
-       </References>\r
-       <Files>\r
-               <Filter\r
-                       Name="Source Files"\r
-                       Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-                       >\r
-                       <File\r
-                               RelativePath="libsangoma.c"\r
-                               >\r
-                               <FileConfiguration\r
-                                       Name="Release|Win32"\r
-                                       >\r
-                                       <Tool\r
-                                               Name="VCCLCompilerTool"\r
-                                               PreprocessorDefinitions=""\r
-                                       />\r
-                               </FileConfiguration>\r
-                               <FileConfiguration\r
-                                       Name="Debug|Win32"\r
-                                       >\r
-                                       <Tool\r
-                                               Name="VCCLCompilerTool"\r
-                                               PreprocessorDefinitions=""\r
-                                       />\r
-                               </FileConfiguration>\r
-                       </File>\r
-                       <File\r
-                               RelativePath=".\sangoma_pri.c"\r
-                               >\r
-                       </File>\r
-               </Filter>\r
-               <Filter\r
-                       Name="Header Files"\r
-                       Filter="h;hpp;hxx;hm;inl"\r
-                       >\r
-                       <File\r
-                               RelativePath=".\libsangoma.h"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath=".\sangoma_pri.h"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="win_api_common.h"\r
-                               >\r
-                       </File>\r
-               </Filter>\r
-       </Files>\r
-       <Globals>\r
-       </Globals>\r
-</VisualStudioProject>\r
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c b/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c
deleted file mode 100644 (file)
index e07b878..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-#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;
-
-}
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h b/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h
deleted file mode 100644 (file)
index 5c3512a..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*****************************************************************************
- * 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
diff --git a/src/mod/endpoints/mod_wanpipe/libsangoma/win_api_common.h b/src/mod/endpoints/mod_wanpipe/libsangoma/win_api_common.h
deleted file mode 100644 (file)
index b787523..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-/*****************************************************************************
- * 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 */
diff --git a/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c b/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
deleted file mode 100644 (file)
index 12b5a07..0000000
+++ /dev/null
@@ -1,2423 +0,0 @@
-/* 
- * 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>
- *
- *
- * mod_wanpipe.c -- WANPIPE PRI Channel Module
- *
- */
-
-#include <switch.h>
-#include <libsangoma.h>
-#include <sangoma_pri.h>
-#include <libteletone.h>
-#include <ss7boost_client.h>
-
-#ifndef INVALID_HANDLE_VALUE
-#define INVALID_HANDLE_VALUE -1
-#endif
-
-//#define DOTRACE
-SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_wanpipe_shutdown);
-SWITCH_MODULE_LOAD_FUNCTION(mod_wanpipe_load);
-SWITCH_MODULE_DEFINITION(mod_wanpipe, mod_wanpipe_load, mod_wanpipe_shutdown, NULL);
-
-#define STRLEN 15
-
-switch_endpoint_interface_t *wanpipe_endpoint_interface;
-static switch_memory_pool_t *module_pool = NULL;
-
-typedef enum {
-       PFLAG_ANSWER = (1 << 0),
-       PFLAG_HANGUP = (1 << 1),
-} PFLAGS;
-
-
-typedef enum {
-       PPFLAG_RING = (1 << 0),
-} PPFLAGS;
-
-typedef enum {
-       TFLAG_MEDIA = (1 << 0),
-       TFLAG_INBOUND = (1 << 1),
-       TFLAG_OUTBOUND = (1 << 2),
-       TFLAG_INCOMING = (1 << 3),
-       TFLAG_PARSE_INCOMING = (1 << 4),
-       TFLAG_ACTIVATE = (1 << 5),
-       TFLAG_DTMF = (1 << 6),
-       TFLAG_DESTROY = (1 << 7),
-       TFLAG_ABORT = (1 << 8),
-       TFLAG_SWITCH = (1 << 9),
-       TFLAG_NOSIG = (1 << 10),
-       TFLAG_BYE = (1 << 11),
-       TFLAG_CODEC = (1 << 12),
-       TFLAG_HANGUP = (1 << 13)
-} TFLAGS;
-
-
-#define DEFAULT_SAMPLES_PER_FRAME 160
-#define MAX_SPANS 128
-
-struct channel_map {
-       char map[SANGOMA_MAX_CHAN_PER_SPAN][SWITCH_UUID_FORMATTED_LENGTH + 1];
-       switch_mutex_t *mutex;
-};
-
-unsigned int txseq = 0;
-unsigned int rxseq = 0;
-
-#define SETUP_LEN CORE_MAX_CHAN_PER_SPAN*CORE_MAX_SPANS+1
-
-struct ss7boost_handle {
-       char *local_ip;
-       char *remote_ip;
-       int local_port;
-       int remote_port;
-       ss7boost_client_connection_t mcon;
-       switch_mutex_t *mutex;
-       struct channel_map span_chanmap[MAX_SPANS];
-       char setup_array[SETUP_LEN][SWITCH_UUID_FORMATTED_LENGTH + 1];
-       uint32_t setup_index;
-};
-
-typedef struct ss7boost_handle ss7boost_handle_t;
-
-static int isup_exec_command(ss7boost_handle_t *ss7boost_handle, int span, int chan, int id, int cmd, int cause);
-
-static struct {
-       int debug;
-       int panic;
-       uint32_t samples_per_frame;
-       int dtmf_on;
-       int dtmf_off;
-       int suppress_dtmf_tone;
-       int ignore_dtmf_tone;
-       int configured_spans;
-       int configured_boost_spans;
-       char *dialplan;
-       char *context;
-       switch_hash_t *call_hash;
-       switch_mutex_t *hash_mutex;
-       switch_mutex_t *channel_mutex;
-       ss7boost_handle_t *ss7boost_handle;
-       uint32_t fxo_index;
-       uint32_t fxs_index;
-} globals;
-
-struct wanpipe_pri_span {
-       int span;
-       int dchan;
-       unsigned int bchans;
-       int node;
-       int pswitch;
-       char *dialplan;
-       unsigned int l1;
-       unsigned int dp;
-       struct sangoma_pri spri;
-};
-
-struct wpsock {
-       sng_fd_t fd;
-       char *name;
-};
-
-typedef struct wpsock wpsock_t;
-
-typedef enum {
-       ANALOG_TYPE_UNKNOWN,
-       ANALOG_TYPE_PHONE_FXS,
-       ANLOG_TYPE_LINE_FXO
-} analog_type_t;
-
-typedef enum {
-       ANALOG_STATE_DOWN,
-       ANALOG_STATE_ONHOOK,
-       ANALOG_STATE_OFFHOOK,
-       ANALOG_STATE_RING
-} analog_state_t;
-
-struct analog_channel {
-       analog_type_t a_type;
-       analog_state_t state;
-       wpsock_t *sock;
-       int chan;
-       int span;
-       char *device;
-       char *user;
-       char *domain;
-       char *cid_name;
-       char *cid_num;
-};
-typedef struct analog_channel analog_channel_t;
-
-#define MAX_ANALOG_CHANNELS 128
-static struct analog_channel *FXS_ANALOG_CHANNELS[MAX_ANALOG_CHANNELS];
-static struct analog_channel *FXO_ANALOG_CHANNELS[MAX_ANALOG_CHANNELS];
-
-static struct wanpipe_pri_span *SPANS[MAX_SPANS];
-
-struct private_object {
-       unsigned int flags;                     /* FLAGS */
-       switch_frame_t read_frame;      /* Frame for Writing */
-       switch_core_session_t *session;
-       switch_codec_t read_codec;
-       switch_codec_t write_codec;
-       unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-       unsigned char auxbuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-       struct sangoma_pri *spri;
-       sangoma_api_hdr_t hdrframe;
-       switch_caller_profile_t *caller_profile;
-       wpsock_t *wpsock;
-       int callno;
-       int span;
-       int cause;
-       q931_call *call;
-       teletone_dtmf_detect_state_t dtmf_detect;
-       teletone_generation_session_t tone_session;
-       switch_buffer_t *dtmf_buffer;
-       unsigned int skip_read_frames;
-       unsigned int skip_write_frames;
-       switch_mutex_t *flag_mutex;
-       int frame_size;
-       ss7boost_handle_t *ss7boost_handle;
-       int boost_chan_number;
-       int boost_span_number;
-       int boost_trunk_group;
-       uint32_t setup_index;
-       uint32_t boost_pres;
-#ifdef DOTRACE
-       int fd;
-       int fd2;
-#endif
-};
-typedef struct private_object private_object_t;
-
-
-
-static void wp_logger(char *file, const char *func, int line, int level, char *fmt, ...)
-{
-       va_list ap;
-       char *data = NULL;
-       int ret;
-
-       va_start(ap, fmt);
-       if ((ret = switch_vasprintf(&data, fmt, ap)) != -1) {
-               switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, "%s", data);
-       }
-       va_end(ap);
-}
-
-static int local_sangoma_tdm_read_event(sng_fd_t fd, wp_tdm_api_rx_hdr_t *rx_event)
-{
-       wanpipe_tdm_api_t tdm_api[1];
-
-#if defined(WIN32)
-       rx_event = &last_tdm_api_event_buffer;
-#else
-       int err;
-
-       tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
-
-       if ((err = sangoma_tdm_cmd_exec(fd, tdm_api))) {
-               return err;
-       }
-
-       rx_event = &tdm_api->wp_tdm_cmd.event;
-#endif
-
-       return 0;
-}
-
-static int analog_set_state(analog_channel_t *alc, analog_state_t state)
-{
-       alc->state = state;
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Changing State to %d\n", state);
-}
-
-static void analog_check_state(analog_channel_t *alc)
-{
-       wanpipe_tdm_api_t tdm_api;
-
-       switch (alc->state) {
-       case ANALOG_STATE_DOWN:
-               sangoma_tdm_enable_rxhook_events(alc->sock->fd, &tdm_api);
-               analog_set_state(alc, ANALOG_STATE_ONHOOK);
-               break;
-       default:
-               break;
-       }
-}
-
-static void analog_parse_event(analog_channel_t *alc)
-{
-       wp_tdm_api_rx_hdr_t rx_event;
-       int err = local_sangoma_tdm_read_event(alc->sock->fd, &rx_event);
-
-       if (err < 0) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reading event!\n");
-               return;
-       }
-
-       switch (rx_event.wp_tdm_api_event_type) {
-       case WP_TDM_EVENT_RXHOOK:
-               printf("hook\n");
-               break;
-       }
-
-}
-
-static void *SWITCH_THREAD_FUNC fxs_thread_run(switch_thread_t *thread, void *obj)
-{
-
-       for (;;) {
-               int i = 0, sel_on = -1;
-               fd_set oob;
-               FD_ZERO(&oob);
-
-               for (i = 0; i < globals.fxs_index; i++) {
-                       int fd;
-                       assert(FXS_ANALOG_CHANNELS[i]);
-                       assert(FXS_ANALOG_CHANNELS[i]->sock);
-
-                       fd = FXS_ANALOG_CHANNELS[i]->sock->fd;
-
-                       analog_check_state(FXS_ANALOG_CHANNELS[i]);
-
-                       FD_SET(fd, &oob);
-
-                       if (fd > sel_on) {
-                               sel_on = fd;
-                       }
-               }
-
-               if (sel_on > -1) {
-                       if (select(++sel_on, NULL, NULL, &oob, NULL)) {
-                               for (i = 0; i < globals.fxs_index; i++) {
-                                       int fd = FXS_ANALOG_CHANNELS[i]->sock->fd;
-                                       if (FD_ISSET(fd, &oob)) {
-                                               analog_parse_event(FXS_ANALOG_CHANNELS[i]);
-                                       }
-                               }
-                       }
-               }
-       }
-}
-
-
-static wpsock_t *wp_open(int span, int chan)
-{
-       sng_fd_t fd;
-       wpsock_t *sock;
-       char name[25];
-
-       snprintf(name, sizeof(name), "s%dc%d", span, chan);
-
-       switch_mutex_lock(globals.hash_mutex);
-       if ((sock = switch_core_hash_find(globals.call_hash, name))) {
-               fd = sock->fd;
-       } else {
-               if ((fd = sangoma_open_tdmapi_span_chan(span, chan)) != INVALID_HANDLE_VALUE) {
-                       if ((sock = malloc(sizeof(*sock)))) {
-                               memset(sock, 0, sizeof(*sock));
-                               sock->fd = fd;
-                               sock->name = strdup(name);
-                               switch_core_hash_insert(globals.call_hash, sock->name, sock);
-                       }
-               }
-       }
-
-       switch_mutex_unlock(globals.hash_mutex);
-
-       return sock;
-}
-
-static int wp_restart(int span, int chan)
-{
-       wpsock_t *sock;
-       sng_fd_t fd;
-       char name[25];
-
-       snprintf(name, sizeof(name), "s%dc%d", span, chan);
-
-       switch_mutex_lock(globals.hash_mutex);
-       if ((sock = switch_core_hash_find(globals.call_hash, name))) {
-               switch_core_hash_delete(globals.call_hash, sock->name);
-               fd = sock->fd;
-       } else {
-               fd = sangoma_open_tdmapi_span_chan(span, chan);
-       }
-       switch_mutex_unlock(globals.hash_mutex);
-
-       if (fd != INVALID_HANDLE_VALUE) {
-               sangoma_socket_close(&fd);
-               return 0;
-       }
-
-       return -1;
-}
-
-
-static void set_global_dialplan(char *dialplan)
-{
-       if (globals.dialplan) {
-               free(globals.dialplan);
-               globals.dialplan = NULL;
-       }
-
-       globals.dialplan = strdup(dialplan);
-}
-
-static void set_global_context(char *context)
-{
-       if (globals.context) {
-               free(globals.context);
-               globals.context = NULL;
-       }
-
-       globals.context = strdup(context);
-}
-
-
-static int str2node(char *node)
-{
-       if (!strcasecmp(node, "cpe"))
-               return PRI_CPE;
-       if (!strcasecmp(node, "network"))
-               return PRI_NETWORK;
-       return -1;
-}
-
-static int str2switch(char *swtype)
-{
-       if (!strcasecmp(swtype, "ni1"))
-               return PRI_SWITCH_NI1;
-       if (!strcasecmp(swtype, "ni2"))
-               return PRI_SWITCH_NI2;
-       if (!strcasecmp(swtype, "dms100"))
-               return PRI_SWITCH_DMS100;
-       if (!strcasecmp(swtype, "lucent5e"))
-               return PRI_SWITCH_LUCENT5E;
-       if (!strcasecmp(swtype, "att4ess"))
-               return PRI_SWITCH_ATT4ESS;
-       if (!strcasecmp(swtype, "euroisdn"))
-               return PRI_SWITCH_EUROISDN_E1;
-       if (!strcasecmp(swtype, "gr303eoc"))
-               return PRI_SWITCH_GR303_EOC;
-       if (!strcasecmp(swtype, "gr303tmc"))
-               return PRI_SWITCH_GR303_TMC;
-       return -1;
-}
-
-
-static int str2l1(char *l1)
-{
-       if (!strcasecmp(l1, "alaw"))
-               return PRI_LAYER_1_ALAW;
-
-       return PRI_LAYER_1_ULAW;
-}
-
-static int str2dp(char *dp)
-{
-       if (!strcasecmp(dp, "international"))
-               return PRI_INTERNATIONAL_ISDN;
-       if (!strcasecmp(dp, "national"))
-               return PRI_NATIONAL_ISDN;
-       if (!strcasecmp(dp, "local"))
-               return PRI_LOCAL_ISDN;
-       if (!strcasecmp(dp, "private"))
-               return PRI_PRIVATE;
-       if (!strcasecmp(dp, "unknown"))
-               return PRI_UNKNOWN;
-
-       return PRI_UNKNOWN;
-}
-
-
-
-static void set_global_dialplan(char *dialplan);
-static void set_global_context(char *context);
-static int str2node(char *node);
-static int str2switch(char *swtype);
-static switch_status_t wanpipe_on_init(switch_core_session_t *session);
-static switch_status_t wanpipe_on_hangup(switch_core_session_t *session);
-static switch_status_t wanpipe_on_exchange_media(switch_core_session_t *session);
-static switch_status_t wanpipe_on_soft_execute(switch_core_session_t *session);
-static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile,
-                                                                                                       switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
-static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
-static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static int check_flags(struct sangoma_pri *spri);
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t *thread, void *obj);
-static switch_status_t config_wanpipe(int reload);
-
-
-static switch_status_t wanpipe_codec_init(private_object_t *tech_pvt)
-{
-       int err = 0;
-       wanpipe_tdm_api_t tdm_api = { {0} };
-       unsigned int rate = 8000;
-       switch_channel_t *channel = NULL;
-
-       if (switch_test_flag(tech_pvt, TFLAG_CODEC)) {
-               return SWITCH_STATUS_SUCCESS;
-       }
-
-
-       channel = switch_core_session_get_channel(tech_pvt->session);
-       assert(channel != NULL);
-
-       err = sangoma_tdm_set_codec(tech_pvt->wpsock->fd, &tdm_api, WP_SLINEAR);
-
-       sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, globals.samples_per_frame / 8);
-       tech_pvt->frame_size = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api);
-
-       if (switch_core_codec_init
-               (&tech_pvt->read_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-                switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
-               switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-               return SWITCH_STATUS_FALSE;
-       }
-
-       if (switch_core_codec_init
-               (&tech_pvt->write_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-                switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
-               switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-               return SWITCH_STATUS_FALSE;
-       }
-       tech_pvt->read_frame.rate = rate;
-       tech_pvt->read_frame.codec = &tech_pvt->read_codec;
-       switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
-       switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
-
-#ifdef DOTRACE
-       tech_pvt->fd = open("/tmp/wp-in.raw", O_WRONLY | O_TRUNC | O_CREAT);
-       tech_pvt->fd2 = open("/tmp/wp-out.raw", O_WRONLY | O_TRUNC | O_CREAT);
-#endif
-
-       /* Setup artificial DTMF stuff */
-       memset(&tech_pvt->tone_session, 0, sizeof(tech_pvt->tone_session));
-       teletone_init_session(&tech_pvt->tone_session, 1024, NULL, NULL);
-
-       if (globals.debug) {
-               tech_pvt->tone_session.debug = globals.debug;
-               tech_pvt->tone_session.debug_stream = stdout;
-       }
-
-       tech_pvt->tone_session.rate = rate;
-       tech_pvt->tone_session.duration = globals.dtmf_on * (tech_pvt->tone_session.rate / 1000);
-       tech_pvt->tone_session.wait = globals.dtmf_off * (tech_pvt->tone_session.rate / 1000);
-
-       if (!globals.ignore_dtmf_tone) {
-               teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, rate);
-       }
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Audio init %s\n", switch_channel_get_name(channel));
-
-       switch_set_flag(tech_pvt, TFLAG_CODEC);
-
-       return SWITCH_STATUS_SUCCESS;
-
-}
-
-
-/* 
-   State methods they get called when the state changes to the specific state 
-   returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
-   so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
-*/
-static switch_status_t wanpipe_on_init(switch_core_session_t *session)
-{
-       private_object_t *tech_pvt;
-       switch_channel_t *channel = NULL;
-       switch_status_t status;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       tech_pvt->read_frame.data = tech_pvt->databuf;
-
-       if (tech_pvt->ss7boost_handle) {
-               if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
-                       ss7boost_client_event_t event;
-
-                       event.calling_number_presentation = tech_pvt->boost_pres;
-                       event.trunk_group = tech_pvt->boost_trunk_group;
-
-                       switch_mutex_lock(tech_pvt->ss7boost_handle->mutex);
-                       tech_pvt->setup_index = ++tech_pvt->ss7boost_handle->setup_index;
-                       if (tech_pvt->ss7boost_handle->setup_index == SETUP_LEN - 1) {
-                               tech_pvt->ss7boost_handle->setup_index = 0;
-                       }
-                       switch_mutex_unlock(tech_pvt->ss7boost_handle->mutex);
-
-                       switch_copy_string(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index],
-                                                          switch_core_session_get_uuid(session), sizeof(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index]));
-
-
-                       ss7boost_client_call_init(&event, tech_pvt->caller_profile->caller_id_number, tech_pvt->caller_profile->destination_number,
-                                                                         tech_pvt->setup_index);
-
-                       if (ss7boost_client_connection_write(&tech_pvt->ss7boost_handle->mcon, &event) <= 0) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Critical System Error: Failed to tx on ISUP socket [%s]\n", strerror(errno));
-                       }
-
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call Called Event TG=%d\n", tech_pvt->boost_trunk_group);
-                       goto done;
-               }
-       }
-
-       if ((status = wanpipe_codec_init(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
-               switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-               return status;
-       }
-
-       if (switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
-               switch_channel_mark_answered(channel);
-       }
-
-  done:
-
-       /* Move channel's state machine to ROUTING */
-       switch_channel_set_state(channel, CS_ROUTING);
-       return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t wanpipe_on_routing(switch_core_session_t *session)
-{
-       switch_channel_t *channel = NULL;
-       private_object_t *tech_pvt = NULL;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE ROUTING\n");
-
-
-
-       return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t wanpipe_on_hangup(switch_core_session_t *session)
-{
-       private_object_t *tech_pvt;
-       switch_channel_t *channel = NULL;
-       struct channel_map *chanmap = NULL;
-
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       switch_core_codec_destroy(&tech_pvt->read_codec);
-       switch_core_codec_destroy(&tech_pvt->write_codec);
-
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE HANGUP\n");
-
-       if (tech_pvt->ss7boost_handle) {
-               switch_mutex_lock(tech_pvt->ss7boost_handle->mutex);
-               *tech_pvt->ss7boost_handle->span_chanmap[tech_pvt->boost_span_number].map[tech_pvt->boost_chan_number] = '\0';
-               switch_mutex_unlock(tech_pvt->ss7boost_handle->mutex);
-               if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
-                       isup_exec_command(tech_pvt->ss7boost_handle,
-                                                         tech_pvt->boost_span_number, tech_pvt->boost_chan_number, -1, SIGBOOST_EVENT_CALL_STOPPED, SIGBOOST_RELEASE_CAUSE_NORMAL);
-               }
-       } else if (tech_pvt->spri) {
-               chanmap = tech_pvt->spri->private_info;
-
-               if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
-                       switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
-                       switch_mutex_lock(chanmap->mutex);
-                       pri_hangup(tech_pvt->spri->pri, tech_pvt->call, switch_channel_get_cause(channel));
-                       pri_destroycall(tech_pvt->spri->pri, tech_pvt->call);
-                       switch_mutex_unlock(chanmap->mutex);
-               }
-
-
-               switch_mutex_lock(globals.channel_mutex);
-               *chanmap->map[tech_pvt->callno] = '\0';
-               switch_mutex_unlock(globals.channel_mutex);
-
-       }
-
-       switch_set_flag_locked(tech_pvt, TFLAG_BYE);
-
-       teletone_destroy_session(&tech_pvt->tone_session);
-
-       switch_buffer_destroy(&tech_pvt->dtmf_buffer);
-
-       return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t wanpipe_on_exchange_media(switch_core_session_t *session)
-{
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE LOOPBACK\n");
-       return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t wanpipe_on_soft_execute(switch_core_session_t *session)
-{
-       private_object_t *tech_pvt;
-       switch_channel_t *channel;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE TRANSMIT\n");
-       return SWITCH_STATUS_SUCCESS;
-}
-
-
-static switch_status_t wanpipe_answer_channel(switch_core_session_t *session)
-{
-       private_object_t *tech_pvt;
-       switch_channel_t *channel = NULL;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       if (tech_pvt->spri) {
-               struct channel_map *chanmap = tech_pvt->spri->private_info;
-
-               if (switch_test_flag(tech_pvt, TFLAG_INBOUND)) {
-                       switch_mutex_lock(chanmap->mutex);
-                       pri_answer(tech_pvt->spri->pri, tech_pvt->call, 0, 1);
-                       switch_mutex_unlock(chanmap->mutex);
-               }
-       } else if (tech_pvt->ss7boost_handle) {
-               isup_exec_command(tech_pvt->ss7boost_handle, tech_pvt->boost_span_number, tech_pvt->boost_chan_number, -1, SIGBOOST_EVENT_CALL_ANSWERED, 0);
-       }
-
-       return SWITCH_STATUS_SUCCESS;
-}
-
-
-
-static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
-{
-       private_object_t *tech_pvt;
-       switch_channel_t *channel = NULL;
-       uint8_t *bp;
-       uint32_t bytes = 0;
-       int bread = 0;
-       char digit_str[80];
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
-               return SWITCH_STATUS_GENERR;
-       }
-
-       bp = tech_pvt->databuf;
-
-       *frame = NULL;
-       memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf));
-       while (bytes < globals.samples_per_frame * 2) {
-               if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
-                       return SWITCH_STATUS_GENERR;
-               }
-
-               if (sangoma_socket_waitfor(tech_pvt->wpsock->fd, 1000, POLLIN | POLLERR | POLLHUP) <= 0) {
-                       return SWITCH_STATUS_GENERR;
-               }
-
-               if ((bread = sangoma_readmsg_socket(tech_pvt->wpsock->fd,
-                                                                                       &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
-                       if (errno == EBUSY) {
-                               continue;
-                       } else {
-                               return SWITCH_STATUS_GENERR;
-                       }
-
-               }
-               bytes += bread;
-               bp += bytes;
-       }
-
-       if (!bytes || switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
-               return SWITCH_STATUS_GENERR;
-       }
-
-       tech_pvt->read_frame.datalen = bytes;
-       tech_pvt->read_frame.samples = bytes / 2;
-
-       if (!globals.ignore_dtmf_tone) {
-               teletone_dtmf_detect(&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
-               teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
-
-               if (digit_str[0]) {
-                       char *p = digit_str;
-                       switch_dtmf_t dtmf = { 0, globals.dtmf_on };
-                       while (p && *p) {
-                               dtmf.digit = *p;
-                               switch_channel_queue_dtmf(channel, &dtmf);
-                               p++;
-                       }
-                       if (globals.debug) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
-                       }
-                       if (globals.suppress_dtmf_tone) {
-                               tech_pvt->skip_read_frames = 20;
-                       }
-               }
-
-               if (tech_pvt->skip_read_frames > 0) {
-                       memset(tech_pvt->read_frame.data, 0, tech_pvt->read_frame.datalen);
-                       tech_pvt->skip_read_frames--;
-               }
-       }
-#ifdef DOTRACE
-       write(tech_pvt->fd2, tech_pvt->read_frame.data, (int) tech_pvt->read_frame.datalen);
-#endif
-       //printf("read %d\n", tech_pvt->read_frame.datalen);
-       *frame = &tech_pvt->read_frame;
-       return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
-{
-       private_object_t *tech_pvt;
-       uint32_t dtmf_blen;
-       void *data = frame->data;
-       int result = 0;
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
-               return SWITCH_STATUS_GENERR;
-       }
-
-       if (tech_pvt->dtmf_buffer && (dtmf_blen = switch_buffer_inuse(tech_pvt->dtmf_buffer))) {
-               uint32_t len = dtmf_blen > frame->datalen ? frame->datalen : dtmf_blen;
-
-               switch_buffer_read(tech_pvt->dtmf_buffer, tech_pvt->auxbuf, len);
-               if (len < frame->datalen) {
-                       uint8_t *data = frame->data;
-                       memcpy(data + len, tech_pvt->auxbuf + len, frame->datalen - len);
-               }
-               data = tech_pvt->auxbuf;
-       }
-
-       if (tech_pvt->skip_write_frames) {
-               tech_pvt->skip_write_frames--;
-               return SWITCH_STATUS_SUCCESS;
-       }
-#ifdef DOTRACE
-       write(tech_pvt->fd, data, frame->datalen);
-#endif
-
-       result = sangoma_sendmsg_socket(tech_pvt->wpsock->fd, &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), data, frame->datalen, 0);
-
-       if (result < 0 && errno != EBUSY) {
-               return SWITCH_STATUS_GENERR;
-       }
-
-       return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t wanpipe_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
-{
-       private_object_t *tech_pvt;
-       switch_channel_t *channel = NULL;
-       switch_status_t status = SWITCH_STATUS_SUCCESS;
-       int wrote = 0;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
-               return SWITCH_STATUS_GENERR;
-       }
-
-       if (!tech_pvt->dtmf_buffer) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Allocate DTMF Buffer....");
-               if (switch_buffer_create_dynamic(&tech_pvt->dtmf_buffer, 1024, 3192, 0) != SWITCH_STATUS_SUCCESS) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Failed to allocate DTMF Buffer!\n");
-                       return SWITCH_STATUS_FALSE;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, "SUCCESS!\n");
-               }
-       }
-
-       tech_pvt->tone_session.duration = dtmf.duration * (tech_pvt->tone_session.rate / 1000);
-       if ((wrote = teletone_mux_tones(&tech_pvt->tone_session, &tech_pvt->tone_session.TONES[(int) dtmf->digit]))) {
-               switch_buffer_write(tech_pvt->dtmf_buffer, tech_pvt->tone_session.buffer, wrote * 2);
-       }
-
-
-       tech_pvt->skip_read_frames = 200;
-
-       return status;
-}
-
-static switch_status_t wanpipe_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
-{
-       switch_channel_t *channel;
-       private_object_t *tech_pvt;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = (private_object_t *) switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
-               return SWITCH_STATUS_GENERR;
-       }
-
-       switch (msg->message_id) {
-       case SWITCH_MESSAGE_INDICATE_NOMEDIA:
-               break;
-       case SWITCH_MESSAGE_INDICATE_MEDIA:
-               break;
-       case SWITCH_MESSAGE_INDICATE_HOLD:
-               break;
-       case SWITCH_MESSAGE_INDICATE_UNHOLD:
-               break;
-       case SWITCH_MESSAGE_INDICATE_BRIDGE:
-               break;
-       case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
-               break;
-       case SWITCH_MESSAGE_INDICATE_REDIRECT:
-               break;
-       case SWITCH_MESSAGE_INDICATE_ANSWER:
-               wanpipe_answer_channel(session);
-               break;
-       case SWITCH_MESSAGE_INDICATE_PROGRESS:
-               break;
-       case SWITCH_MESSAGE_INDICATE_RINGING:
-               break;
-       default:
-               break;
-       }
-
-       return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t wanpipe_kill_channel(switch_core_session_t *session, int sig)
-{
-       private_object_t *tech_pvt;
-       switch_channel_t *channel = NULL;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
-
-       tech_pvt = switch_core_session_get_private(session);
-       assert(tech_pvt != NULL);
-
-       switch (sig) {
-       case SWITCH_SIG_KILL:
-               switch_clear_flag_locked(tech_pvt, TFLAG_MEDIA);
-               break;
-       default:
-               break;
-       }
-
-       return SWITCH_STATUS_SUCCESS;
-
-}
-
-
-switch_io_routines_t wanpipe_io_routines = {
-       /*.outgoing_channel */ wanpipe_outgoing_channel,
-       /*.read_frame */ wanpipe_read_frame,
-       /*.write_frame */ wanpipe_write_frame,
-       /*.kill_channel */ wanpipe_kill_channel,
-       /*.send_dtmf */ wanpipe_send_dtmf,
-       /*.receive_message */ wanpipe_receive_message
-};
-
-switch_state_handler_table_t wanpipe_state_handlers = {
-       /*.on_init */ wanpipe_on_init,
-       /*.on_routing */ wanpipe_on_routing,
-       /*.on_execute */ NULL,
-       /*.on_hangup */ wanpipe_on_hangup,
-       /*.on_exchange_media */ wanpipe_on_exchange_media,
-       /*.on_soft_execute */ wanpipe_on_soft_execute
-};
-
-static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile,
-                                                                                                       switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
-{
-       char *bchan = NULL;
-       char name[128] = "";
-       char *protocol = NULL;
-       char *dest;
-       int ready = 0, is_pri = 0, is_boost = 0, is_raw = 0;
-       switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-       private_object_t *tech_pvt;
-       switch_channel_t *channel;
-       switch_caller_profile_t *caller_profile = NULL;
-       int callno = 0;
-       struct sangoma_pri *spri;
-       int span = 0, autospan = 0, autochan = 0;
-       char *num, *p;
-       struct channel_map *chanmap = NULL;
-
-       if (!outbound_profile) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
-               cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-               goto error;
-       }
-
-       protocol = strdup(outbound_profile->destination_number);
-       assert(protocol != NULL);
-
-       if (!(dest = strchr(protocol, '/'))) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error No protocol specified!\n");
-               cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-               goto error;
-       }
-
-       *dest++ = '\0';
-
-       if (!strcasecmp(protocol, "raw")) {
-               bchan = dest;
-               is_raw = ready = 1;
-       } else if (!strcasecmp(protocol, "pri")) {
-               if ((is_pri = globals.configured_spans)) {
-                       ready = is_pri;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error No PRI Spans Configured.\n");
-               }
-       } else if (!strcasecmp(protocol, "ss7boost")) {
-               if ((is_boost = globals.configured_boost_spans)) {
-                       ready = is_boost;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error No SS7BOOST Spans Configured.\n");
-               }
-       }
-
-       if (!ready) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Continue!\n");
-               cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
-               goto error;
-       }
-
-       outbound_profile->destination_number = dest;
-
-       if (!(*new_session = switch_core_session_request(wanpipe_endpoint_interface, pool))) {
-               cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-               goto error;
-       }
-
-       switch_core_session_add_stream(*new_session, NULL);
-       if ((tech_pvt = (private_object_t *) switch_core_session_alloc(*new_session, sizeof(private_object_t)))) {
-               memset(tech_pvt, 0, sizeof(*tech_pvt));
-               switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
-               channel = switch_core_session_get_channel(*new_session);
-               switch_core_session_set_private(*new_session, tech_pvt);
-               tech_pvt->session = *new_session;
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-               switch_core_session_destroy(new_session);
-               cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-               goto error;
-       }
-
-
-       caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
-
-       if (is_pri) {
-               num = caller_profile->destination_number;
-               if ((p = strchr(num, '/'))) {
-                       *p++ = '\0';
-
-                       if (*num == 'a') {
-                               span = 1;
-                               autospan = 1;
-                       } else if (*num == 'A') {
-                               span = MAX_SPANS - 1;
-                               autospan = -1;
-                       } else {
-                               if (num && *num > 47 && *num < 58) {
-                                       span = atoi(num);
-                               } else {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Syntax\n");
-                                       switch_core_session_destroy(new_session);
-                                       cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-                                       goto error;
-                               }
-                       }
-                       num = p;
-                       if ((p = strchr(num, '/'))) {
-                               *p++ = '\0';
-                               if (*num == 'a') {
-                                       autochan = 1;
-                               } else if (*num == 'A') {
-                                       autochan = -1;
-                               } else if (num && *num > 47 && *num < 58) {
-                                       callno = atoi(num);
-                               } else {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Syntax\n");
-                                       switch_core_session_destroy(new_session);
-                                       cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-                                       goto error;
-                               }
-                               caller_profile->destination_number = p;
-                       } else {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Syntax\n");
-                               switch_core_session_destroy(new_session);
-                               cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-                               goto error;
-                       }
-               }
-       }
-
-       tech_pvt->caller_profile = caller_profile;
-
-       if (is_raw) {
-               int chan, span;
-
-               if (sangoma_span_chan_fromif(bchan, &span, &chan)) {
-                       if (!(tech_pvt->wpsock = wp_open(span, chan))) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n", span, chan, strerror(errno));
-                               switch_core_session_destroy(new_session);
-                               cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-                               goto error;
-                       }
-                       switch_set_flag_locked(tech_pvt, TFLAG_NOSIG);
-                       snprintf(name, sizeof(name), "wanpipe/%s/nosig", bchan);
-                       switch_channel_set_name(channel, name);
-                       switch_channel_set_caller_profile(channel, caller_profile);
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid address\n");
-                       switch_core_session_destroy(new_session);
-                       cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
-                       goto error;
-               }
-       } else if (is_pri) {
-               switch_mutex_lock(globals.channel_mutex);
-               callno = 0;
-               while (!callno) {
-                       if (autospan > 0 && span == MAX_SPANS - 1) {
-                               break;
-                       }
-
-                       if (autospan < 0 && span == 0) {
-                               break;
-                       }
-
-                       if (SPANS[span] && (spri = &SPANS[span]->spri) && switch_test_flag(spri, SANGOMA_PRI_READY)) {
-                               chanmap = spri->private_info;
-
-                               if (autochan > 0) {
-                                       for (callno = 1; callno < SANGOMA_MAX_CHAN_PER_SPAN; callno++) {
-                                               if ((SPANS[span]->bchans & (1 << callno)) && !*chanmap->map[callno]) {
-                                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, callno);
-                                                       goto done;
-                                               }
-                                       }
-                                       callno = 0;
-                               } else if (autochan < 0) {
-                                       for (callno = SANGOMA_MAX_CHAN_PER_SPAN; callno > 0; callno--) {
-                                               if ((SPANS[span]->bchans & (1 << callno)) && !*chanmap->map[callno]) {
-                                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, callno);
-                                                       goto done;
-                                               }
-                                       }
-                                       callno = 0;
-                               }
-                       }
-
-                       if (autospan > 0) {
-                               span++;
-                       } else if (autospan < 0) {
-                               span--;
-                       }
-               }
-         done:
-               switch_mutex_unlock(globals.channel_mutex);
-
-               if (!spri || callno == 0 || callno == (SANGOMA_MAX_CHAN_PER_SPAN)) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No Free Channels!\n");
-                       switch_core_session_destroy(new_session);
-                       cause = SWITCH_CAUSE_SWITCH_CONGESTION;
-                       goto error;
-               }
-
-               tech_pvt->callno = callno;
-
-               if (spri) {
-                       struct channel_map *chanmap = spri->private_info;
-                       switch_mutex_lock(chanmap->mutex);
-                       if (tech_pvt->call = pri_new_call(spri->pri)) {
-                               struct pri_sr *sr;
-
-                               snprintf(name, sizeof(name), "wanpipe/pri/s%dc%d/%s", spri->span, callno, caller_profile->destination_number);
-                               switch_channel_set_name(channel, name);
-                               switch_channel_set_caller_profile(channel, caller_profile);
-                               sr = pri_sr_new();
-                               pri_sr_set_channel(sr, callno, 0, 0);
-                               pri_sr_set_bearer(sr, 0, SPANS[span]->l1);
-                               pri_sr_set_called(sr, caller_profile->destination_number, SPANS[span]->dp, 1);
-                               pri_sr_set_caller(sr,
-                                                                 caller_profile->caller_id_number,
-                                                                 caller_profile->caller_id_name, SPANS[span]->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
-                               pri_sr_set_redirecting(sr,
-                                                                          caller_profile->caller_id_number, SPANS[span]->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
-
-                               if (pri_setup(spri->pri, tech_pvt->call, sr)) {
-                                       switch_core_session_destroy(new_session);
-                                       pri_sr_free(sr);
-                                       cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-                                       switch_mutex_unlock(chanmap->mutex);
-                                       goto error;
-                               }
-
-                               if (!(tech_pvt->wpsock = wp_open(spri->span, callno))) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd!\n");
-                                       switch_core_session_destroy(new_session);
-                                       pri_sr_free(sr);
-                                       cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-                                       switch_mutex_unlock(chanmap->mutex);
-                                       goto error;
-                               }
-                               pri_sr_free(sr);
-                               switch_copy_string(chanmap->map[callno], switch_core_session_get_uuid(*new_session), sizeof(chanmap->map[callno]));
-                               tech_pvt->spri = spri;
-                       }
-                       switch_mutex_unlock(chanmap->mutex);
-               }
-       } else if (is_boost) {
-               char *p;
-
-               if ((p = strchr(caller_profile->destination_number, '/'))) {
-                       char *grp = caller_profile->destination_number;
-                       *p = '\0';
-                       caller_profile->destination_number = p + 1;
-                       tech_pvt->boost_trunk_group = atoi(grp + 1) - 1;
-                       if (tech_pvt->boost_trunk_group < 0) {
-                               tech_pvt->boost_trunk_group = 0;
-                       }
-               }
-               sprintf(name, "wanpipe/ss7boost/%s", caller_profile->destination_number);
-               switch_channel_set_name(channel, name);
-               tech_pvt->ss7boost_handle = globals.ss7boost_handle;
-
-               if (session && switch_core_session_compare(session, *new_session)) {
-                       private_object_t *otech_pvt = switch_core_session_get_private(session);
-                       tech_pvt->boost_pres = otech_pvt->boost_pres;
-               }
-
-       }
-
-       tech_pvt->caller_profile = caller_profile;
-       switch_channel_set_flag(channel, CF_OUTBOUND);
-       switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
-       switch_channel_set_state(channel, CS_INIT);
-       cause = SWITCH_CAUSE_SUCCESS;
-
-
-  error:
-       switch_safe_free(protocol);
-       return cause;
-}
-
-
-#ifdef WIN32
-static void s_pri_error(char *s)
-#else
-static void s_pri_error(struct pri *pri, char *s)
-#endif
-{
-       if (globals.debug) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, s);
-       }
-}
-
-#ifdef WIN32
-static void s_pri_message(char *s)
-{
-       s_pri_error(s);
-}
-#else
-static void s_pri_message(struct pri *pri, char *s)
-{
-       s_pri_error(pri, s);
-}
-#endif
-
-SWITCH_MODULE_LOAD_FUNCTION(mod_wanpipe_load)
-{
-       switch_status_t status = SWITCH_STATUS_SUCCESS;
-
-       sangoma_set_logger(wp_logger);
-
-       memset(SPANS, 0, sizeof(SPANS));
-
-       pri_set_error(s_pri_error);
-       pri_set_message(s_pri_message);
-
-       module_pool = pool;
-
-       memset(&globals, 0, sizeof(globals));
-       switch_core_hash_init(&globals.call_hash, module_pool);
-       switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, module_pool);
-       switch_mutex_init(&globals.channel_mutex, SWITCH_MUTEX_NESTED, module_pool);
-
-       /* start the pri's */
-       if ((status = config_wanpipe(0)) != SWITCH_STATUS_SUCCESS) {
-               return status;
-       }
-
-       /* connect my internal structure to the blank pointer passed to me */
-       *module_interface = switch_loadable_module_create_module_interface(pool, modname);
-       wanpipe_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
-       wanpipe_endpoint_interface->interface_name = "wanpipe";
-       wanpipe_endpoint_interface->io_routines = &wanpipe_io_routines;
-       wanpipe_endpoint_interface->state_handler = &wanpipe_state_handlers;
-
-       /* indicate that the module should continue to be loaded */
-       return status;
-}
-
-SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_wanpipe_shutdown)
-{
-       switch_core_hash_destroy(&globals.call_hash);
-       return SWITCH_STATUS_SUCCESS;
-}
-
-/*event Handlers */
-
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "number is: %s\n", pevent->ring.callednum);
-       if (strlen(pevent->ring.callednum) > 3) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "final number is: %s\n", pevent->ring.callednum);
-               pri_answer(spri->pri, pevent->ring.call, 0, 1);
-       }
-       return 0;
-}
-
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-       struct channel_map *chanmap;
-       switch_core_session_t *session;
-       private_object_t *tech_pvt;
-
-       chanmap = spri->private_info;
-       if ((session = switch_core_session_locate(chanmap->map[pevent->hangup.channel]))) {
-               switch_channel_t *channel = NULL;
-
-               channel = switch_core_session_get_channel(session);
-               assert(channel != NULL);
-
-               if (switch_channel_get_state(channel) < CS_HANGUP) {
-
-
-                       tech_pvt = switch_core_session_get_private(session);
-                       assert(tech_pvt != NULL);
-                       chanmap = tech_pvt->spri->private_info;
-                       if (!tech_pvt->call) {
-                               tech_pvt->call = pevent->hangup.call;
-                       }
-
-                       tech_pvt->cause = pevent->hangup.cause;
-                       switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
-                       switch_channel_hangup(channel, tech_pvt->cause);
-                       switch_mutex_lock(chanmap->mutex);
-                       pri_destroycall(tech_pvt->spri->pri, tech_pvt->call);
-                       switch_mutex_unlock(chanmap->mutex);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Hanging up channel s%dc%d\n", spri->span, pevent->hangup.channel);
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Duplicate Hang up on channel s%dc%d\n", spri->span, pevent->hangup.channel);
-               }
-               switch_core_session_rwunlock(session);
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Hanging up nonexistant channel s%dc%d\n", spri->span, pevent->hangup.channel);
-       }
-
-
-       return 0;
-}
-
-static int on_answer(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-       switch_core_session_t *session;
-       switch_channel_t *channel;
-       struct channel_map *chanmap;
-
-
-       chanmap = spri->private_info;
-
-       if ((session = switch_core_session_locate(chanmap->map[pevent->answer.channel]))) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Answer on channel s%dc%d\n", spri->span, pevent->answer.channel);
-               channel = switch_core_session_get_channel(session);
-               assert(channel != NULL);
-               switch_channel_mark_answered(channel);
-               switch_core_session_rwunlock(session);
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Answer on channel s%dc%d but it's not in use?\n", spri->span, pevent->answer.channel);
-       }
-
-       return 0;
-}
-
-
-static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-       switch_core_session_t *session;
-       switch_channel_t *channel;
-       struct channel_map *chanmap;
-
-       chanmap = spri->private_info;
-
-       if ((session = switch_core_session_locate(chanmap->map[pevent->proceeding.channel]))) {
-               switch_core_session_message_t *msg;
-
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d\n", spri->span, pevent->proceeding.channel);
-
-               channel = switch_core_session_get_channel(session);
-               assert(channel != NULL);
-
-               switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_PROGRESS);
-               switch_channel_mark_pre_answered(channel);
-
-               switch_core_session_rwunlock(session);
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d but it's not in use?\n",
-                                                 spri->span, pevent->proceeding.channel);
-       }
-
-       return 0;
-}
-
-
-static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-       switch_core_session_t *session;
-       switch_channel_t *channel;
-       struct channel_map *chanmap;
-
-
-       chanmap = spri->private_info;
-
-       if ((session = switch_core_session_locate(chanmap->map[pevent->ringing.channel]))) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d\n", spri->span, pevent->ringing.channel);
-               channel = switch_core_session_get_channel(session);
-               assert(channel != NULL);
-
-               switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
-               switch_channel_mark_ring_ready(channel);
-
-               switch_core_session_rwunlock(session);
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d %s but it's not in use?\n", spri->span,
-                                                 pevent->ringing.channel, chanmap->map[pevent->ringing.channel]);
-       }
-
-       return 0;
-}
-
-
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-       char name[128];
-       switch_core_session_t *session = NULL;
-       switch_channel_t *channel;
-       struct channel_map *chanmap;
-       int ret = 0;
-
-       switch_mutex_lock(globals.channel_mutex);
-
-       chanmap = spri->private_info;
-       if ((session = switch_core_session_locate(chanmap->map[pevent->ring.channel]))) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--Duplicate Ring on channel s%dc%d (ignored)\n", spri->span, pevent->ring.channel);
-               switch_core_session_rwunlock(session);
-               ret = 0;
-               goto done;
-       }
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Ring on channel s%dc%d (from %s to %s)\n", spri->span, pevent->ring.channel,
-                                         pevent->ring.callingnum, pevent->ring.callednum);
-
-       switch_mutex_unlock(chanmap->mutex);
-       pri_proceeding(spri->pri, pevent->ring.call, pevent->ring.channel, 0);
-       pri_acknowledge(spri->pri, pevent->ring.call, pevent->ring.channel, 0);
-       switch_mutex_unlock(chanmap->mutex);
-
-       if ((session = switch_core_session_request(wanpipe_endpoint_interface, NULL))) {
-               private_object_t *tech_pvt;
-               char ani2str[4] = "";
-               //wanpipe_tdm_api_t tdm_api;
-
-               switch_core_session_add_stream(session, NULL);
-               if ((tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) {
-                       memset(tech_pvt, 0, sizeof(*tech_pvt));
-                       switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
-                       channel = switch_core_session_get_channel(session);
-                       switch_core_session_set_private(session, tech_pvt);
-                       sprintf(name, "wanpipe/pri/s%dc%d", spri->span, pevent->ring.channel);
-                       switch_channel_set_name(channel, name);
-                       tech_pvt->session = session;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
-                       switch_core_session_destroy(&session);
-                       ret = 0;
-                       goto done;
-               }
-
-               if (pevent->ring.ani2 >= 0) {
-                       snprintf(ani2str, 5, "%.2d", pevent->ring.ani2);
-               }
-
-               if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-                                                                                                                                 NULL, globals.dialplan, "FreeSWITCH", pevent->ring.callingnum,
-#ifdef WIN32
-                                                                                                                                 NULL,
-#else
-                                                                                                                                 pevent->ring.callingani,
-#endif
-                                                                                                                                 switch_strlen_zero(ani2str) ? NULL : ani2str,
-                                                                                                                                 NULL, NULL, (char *) modname, globals.context, pevent->ring.callednum))) {
-                       switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
-               }
-
-               switch_set_flag_locked(tech_pvt, TFLAG_INBOUND);
-               tech_pvt->spri = spri;
-               tech_pvt->cause = -1;
-
-               if (!tech_pvt->call) {
-                       tech_pvt->call = pevent->ring.call;
-               }
-
-               tech_pvt->callno = pevent->ring.channel;
-               tech_pvt->span = spri->span;
-
-               if (!(tech_pvt->wpsock = wp_open(spri->span, pevent->ring.channel))) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd!\n");
-               }
-
-               switch_copy_string(chanmap->map[pevent->ring.channel], switch_core_session_get_uuid(session), sizeof(chanmap->map[pevent->ring.channel]));
-
-               switch_channel_set_state(channel, CS_INIT);
-               if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
-                       switch_core_session_destroy(&session);
-                       ret = 0;
-                       goto done;
-               }
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create new Inbound Channel!\n");
-       }
-
-  done:
-       switch_mutex_unlock(globals.channel_mutex);
-
-       return ret;
-}
-
-static int check_flags(struct sangoma_pri *spri)
-{
-
-       return 0;
-}
-
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-       switch_core_session_t *session;
-       struct channel_map *chanmap;
-
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Restarting s%dc%d\n", spri->span, pevent->restart.channel);
-
-       if (pevent->restart.channel < 1) {
-               return 0;
-       }
-
-
-       chanmap = spri->private_info;
-
-       if ((session = switch_core_session_locate(chanmap->map[pevent->restart.channel]))) {
-               switch_channel_t *channel;
-               channel = switch_core_session_get_channel(session);
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hanging Up channel %s\n", switch_channel_get_name(channel));
-               switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-               switch_core_session_rwunlock(session);
-       }
-
-       wp_restart(spri->span, pevent->restart.channel);
-
-       return 0;
-}
-
-static int on_dchan_up(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-
-       if (!switch_test_flag(spri, SANGOMA_PRI_READY)) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Span %d D-Chan UP!\n", spri->span);
-               switch_set_flag(spri, SANGOMA_PRI_READY);
-       }
-
-       return 0;
-}
-
-static int on_dchan_down(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-
-       if (switch_test_flag(spri, SANGOMA_PRI_READY)) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Span %d D-Chan DOWN!\n", spri->span);
-               switch_clear_flag(spri, SANGOMA_PRI_READY);
-       }
-
-       return 0;
-}
-
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
-{
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span, event_type, sangoma_pri_event_str(event_type));
-       return 0;
-}
-
-
-static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t *thread, void *obj)
-{
-       struct sangoma_pri *spri = obj;
-       struct channel_map chanmap;
-
-       memset(&chanmap, 0, sizeof(chanmap));
-
-       switch_event_t *s_event;
-
-
-       switch_mutex_init(&chanmap.mutex, SWITCH_MUTEX_NESTED, module_pool);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_ANY, on_anything);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RING, on_ring);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RINGING, on_ringing);
-       //SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_SETUP_ACK, on_proceed);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_PROCEEDING, on_proceed);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_ANSWER, on_answer);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_DCHAN_UP, on_dchan_up);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_DCHAN_DOWN, on_dchan_down);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_HANGUP_REQ, on_hangup);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_HANGUP, on_hangup);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_INFO_RECEIVED, on_info);
-       SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RESTART, on_restart);
-
-       spri->on_loop = check_flags;
-       spri->private_info = &chanmap;
-
-       if (switch_event_create(&s_event, SWITCH_EVENT_PUBLISH) == SWITCH_STATUS_SUCCESS) {
-               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_pri._tcp");
-               switch_event_fire(&s_event);
-       }
-
-       sangoma_run_pri(spri);
-
-       free(spri);
-       return NULL;
-}
-
-static void pri_thread_launch(struct sangoma_pri *spri)
-{
-       switch_thread_t *thread;
-       switch_threadattr_t *thd_attr = NULL;
-
-       switch_threadattr_create(&thd_attr, module_pool);
-       switch_threadattr_detach_set(thd_attr, 1);
-       switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_thread_create(&thread, thd_attr, pri_thread_run, spri, module_pool);
-
-}
-
-
-static int isup_exec_command(ss7boost_handle_t *ss7boost_handle, int span, int chan, int id, int cmd, int cause)
-{
-       ss7boost_client_event_t oevent;
-       int r = 0;
-
-       switch_mutex_lock(ss7boost_handle->mutex);
-       ss7boost_client_event_init(&oevent, cmd, chan, span);
-       oevent.release_cause = cause;
-
-       if (id >= 0) {
-               oevent.call_setup_id = id;
-       }
-
-       if (ss7boost_client_connection_write(&ss7boost_handle->mcon, &oevent) <= 0) {
-               r = -1;
-       }
-
-       switch_mutex_unlock(ss7boost_handle->mutex);
-
-       return r;
-}
-
-#ifdef USE_WAITFOR_SOCKET
-static int waitfor_socket(int fd, int timeout, int flags)
-{
-       struct pollfd pfds[1];
-       int res;
-
-       memset(&pfds[0], 0, sizeof(pfds[0]));
-       pfds[0].fd = fd;
-       pfds[0].events = flags;
-       res = poll(pfds, 1, timeout);
-
-       if (res > 0) {
-               if (pfds[0].revents & POLLIN) {
-                       res = 1;
-               } else if ((pfds[0].revents & POLLERR)) {
-                       res = -1;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "System Error: Poll Event Error no event!\n");
-                       res = -1;
-               }
-       }
-
-       return res;
-}
-#endif
-
-
-static void validate_number(unsigned char *s)
-{
-       unsigned char *p;
-       for (p = s; *p; p++) {
-               if (*p < 48 || *p > 57) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encountered a non-numeric character [%c]!\n", *p);
-                       *p = '\0';
-                       break;
-               }
-       }
-}
-
-
-static void handle_call_stop(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       char *uuid = ss7boost_handle->span_chanmap[event->span].map[event->chan];
-
-       if (*uuid) {
-               switch_core_session_t *session;
-
-               if ((session = switch_core_session_locate(uuid))) {
-                       private_object_t *tech_pvt;
-                       switch_channel_t *channel;
-
-                       channel = switch_core_session_get_channel(session);
-                       assert(channel != NULL);
-
-                       tech_pvt = switch_core_session_get_private(session);
-                       assert(tech_pvt != NULL);
-                       switch_set_flag_locked(tech_pvt, TFLAG_BYE);
-                       switch_channel_hangup(channel, event->release_cause);
-                       switch_core_session_rwunlock(session);
-               }
-               *uuid = '\0';
-
-       }
-
-       isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0);
-
-
-}
-
-static void handle_call_start(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       switch_core_session_t *session = NULL;
-       switch_channel_t *channel = NULL;
-       char name[128];
-
-       if (*ss7boost_handle->span_chanmap[event->span].map[event->chan]) {
-               isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_START_NACK, SIGBOOST_RELEASE_CAUSE_BUSY);
-               return;
-       }
-
-
-       if ((session = switch_core_session_request(wanpipe_endpoint_interface, NULL))) {
-               private_object_t *tech_pvt;
-
-               switch_core_session_add_stream(session, NULL);
-               if ((tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) {
-                       memset(tech_pvt, 0, sizeof(*tech_pvt));
-                       switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
-                       channel = switch_core_session_get_channel(session);
-                       switch_core_session_set_private(session, tech_pvt);
-                       sprintf(name, "wanpipe/ss7boost/s%dc%d", event->span + 1, event->chan + 1);
-                       switch_channel_set_name(channel, name);
-                       tech_pvt->session = session;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
-                       goto fail;
-               }
-
-
-               if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-                                                                                                                                 NULL, globals.dialplan, "FreeSWITCH(boost)", (char *) event->calling_number_digits,
-#ifdef WIN32
-                                                                                                                                 NULL,
-#else
-                                                                                                                                 (char *) event->calling_number_digits,
-#endif
-                                                                                                                                 NULL, NULL, NULL, (char *) modname, NULL, (char *) event->called_number_digits))) {
-                       switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
-               }
-
-               switch_set_flag_locked(tech_pvt, TFLAG_INBOUND);
-
-               tech_pvt->cause = -1;
-
-               tech_pvt->ss7boost_handle = ss7boost_handle;
-               tech_pvt->boost_span_number = event->span;
-               tech_pvt->boost_chan_number = event->chan;
-               tech_pvt->boost_pres = event->calling_number_presentation;
-
-               if (!(tech_pvt->wpsock = wp_open(event->span + 1, event->chan + 1))) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open channel %d:%d\n", event->span + 1, event->chan + 1);
-                       goto fail;
-               }
-
-               switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan], switch_core_session_get_uuid(session),
-                                                  sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
-
-               switch_channel_set_state(channel, CS_INIT);
-               isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_START_ACK, 0);
-               switch_core_session_thread_launch(session);
-               return;
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create new Inbound Channel!\n");
-       }
-
-
-  fail:
-       if (session) {
-               switch_core_session_destroy(&session);
-       }
-
-       isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_STOPPED, SIGBOOST_RELEASE_CAUSE_BUSY);
-
-}
-
-
-static void handle_heartbeat(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Heartbeat!\n");
-
-       isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_HEARTBEAT, 0);
-}
-
-
-static void handle_call_start_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       char *uuid = ss7boost_handle->setup_array[event->call_setup_id];
-
-       if (*uuid) {
-               switch_core_session_t *session;
-
-               if ((session = switch_core_session_locate(uuid))) {
-                       private_object_t *tech_pvt;
-                       switch_channel_t *channel;
-
-                       channel = switch_core_session_get_channel(session);
-                       assert(channel != NULL);
-
-                       tech_pvt = switch_core_session_get_private(session);
-                       assert(tech_pvt != NULL);
-
-                       tech_pvt->ss7boost_handle = ss7boost_handle;
-                       tech_pvt->boost_span_number = event->span;
-                       tech_pvt->boost_chan_number = event->chan;
-
-                       switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan], switch_core_session_get_uuid(session),
-                                                          sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
-
-
-
-                       if (!tech_pvt->wpsock) {
-                               if (!(tech_pvt->wpsock = wp_open(tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1))) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
-                                                                         tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1, strerror(errno));
-                                       switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                                       return;
-                               }
-                               if (wanpipe_codec_init(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                                       switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                                       return;
-                               }
-                       }
-
-                       switch_channel_mark_pre_answered(channel);
-
-                       switch_core_session_rwunlock(session);
-               }
-               *uuid = '\0';
-       }
-}
-
-static void handle_call_start_nack_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       // WTF IS THIS! ?
-}
-
-static void handle_call_answer(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       char *uuid = ss7boost_handle->span_chanmap[event->span].map[event->chan];
-
-       if (*uuid) {
-               switch_core_session_t *session;
-
-               if ((session = switch_core_session_locate(uuid))) {
-                       private_object_t *tech_pvt;
-                       switch_channel_t *channel;
-
-                       channel = switch_core_session_get_channel(session);
-                       assert(channel != NULL);
-
-                       tech_pvt = switch_core_session_get_private(session);
-                       assert(tech_pvt != NULL);
-
-                       if (!tech_pvt->wpsock) {
-                               if (!(tech_pvt->wpsock = wp_open(tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1))) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
-                                                                         tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1, strerror(errno));
-                                       switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                                       return;
-                               }
-                               if (wanpipe_codec_init(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                                       switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                                       return;
-                               }
-                       }
-
-                       switch_channel_mark_answered(channel);
-                       switch_core_session_rwunlock(session);
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Session %s missing!\n", uuid);
-                       *uuid = '\0';
-               }
-
-       } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No UUID?\n");
-       }
-}
-
-static void handle_call_stop_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       // TODO anything here?
-}
-
-
-static void handle_call_start_nack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       char *uuid = ss7boost_handle->setup_array[event->call_setup_id];
-
-       if (*uuid) {
-               switch_core_session_t *session;
-
-               if ((session = switch_core_session_locate(uuid))) {
-                       private_object_t *tech_pvt;
-                       switch_channel_t *channel;
-
-                       channel = switch_core_session_get_channel(session);
-                       assert(channel != NULL);
-
-                       tech_pvt = switch_core_session_get_private(session);
-                       assert(tech_pvt != NULL);
-
-                       tech_pvt->ss7boost_handle = ss7boost_handle;
-                       tech_pvt->boost_span_number = event->span;
-                       tech_pvt->boost_chan_number = event->chan;
-
-                       switch_channel_hangup(channel, event->release_cause);
-
-                       isup_exec_command(ss7boost_handle, event->span, event->chan, event->call_setup_id, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0);
-
-                       switch_core_session_rwunlock(session);
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Session %s missing!\n", uuid);
-               }
-               *uuid = '\0';
-       }
-}
-
-static int parse_ss7_event(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
-{
-       int ret = 0;
-
-       switch_mutex_lock(ss7boost_handle->mutex);
-
-       validate_number((unsigned char *) event->called_number_digits);
-       validate_number((unsigned char *) event->calling_number_digits);
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                                         "\nRX EVENT\n"
-                                         "===================================\n"
-                                         "           rType: %s (%0x HEX)\n"
-                                         "           rSpan: [%d]\n"
-                                         "           rChan: [%d]\n"
-                                         "  rCalledNum: %s\n"
-                                         " rCallingNum: %s\n"
-                                         "      rCause: %s\n"
-                                         " rInterface : [w%dg%d]\n"
-                                         "  rEvent ID : [%d]\n"
-                                         "   rSetup ID: [%d]\n"
-                                         "        rSeq: [%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"),
-                                         switch_channel_cause2str(event->release_cause),
-                                         event->span + 1, event->chan + 1, event->event_id, event->call_setup_id, event->seqno);
-
-
-       switch (event->event_id) {
-
-       case SIGBOOST_EVENT_CALL_START:
-               handle_call_start(ss7boost_handle, event);
-               break;
-       case SIGBOOST_EVENT_CALL_STOPPED:
-               handle_call_stop(ss7boost_handle, event);
-               break;
-       case SIGBOOST_EVENT_CALL_START_ACK:
-               handle_call_start_ack(ss7boost_handle, event);
-               break;
-       case SIGBOOST_EVENT_CALL_START_NACK:
-               handle_call_start_nack(ss7boost_handle, event);
-               break;
-       case SIGBOOST_EVENT_CALL_ANSWERED:
-               handle_call_answer(ss7boost_handle, event);
-               break;
-       case SIGBOOST_EVENT_HEARTBEAT:
-               handle_heartbeat(ss7boost_handle, event);
-               break;
-       case SIGBOOST_EVENT_CALL_START_NACK_ACK:
-               handle_call_start_nack_ack(ss7boost_handle, event);
-               break;
-       case SIGBOOST_EVENT_CALL_STOPPED_ACK:
-               handle_call_stop_ack(ss7boost_handle, event);
-               break;
-       default:
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Warning no handler implemented for [%s]\n",
-                                                 ss7boost_client_event_id_name(event->event_id));
-               break;
-       }
-       switch_mutex_unlock(ss7boost_handle->mutex);
-       return ret;
-}
-
-static void *SWITCH_THREAD_FUNC boost_thread_run(switch_thread_t *thread, void *obj)
-{
-       ss7boost_handle_t *ss7boost_handle = (ss7boost_handle_t *) obj;
-       ss7boost_client_event_t *event;
-
-       if (ss7boost_client_connection_open(&ss7boost_handle->mcon,
-                                                                               ss7boost_handle->local_ip,
-                                                                               ss7boost_handle->local_port,
-                                                                               ss7boost_handle->remote_ip, ss7boost_handle->remote_port, module_pool) != SWITCH_STATUS_SUCCESS) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "FATAL ERROR CREATING CLIENT CONNECTION\n");
-               return NULL;
-       }
-
-       isup_exec_command(ss7boost_handle, 0, 0, -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0);
-
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Started\n");
-
-       switch_mutex_lock(globals.hash_mutex);
-       globals.configured_boost_spans++;
-       switch_mutex_unlock(globals.hash_mutex);
-
-       globals.ss7boost_handle = ss7boost_handle;
-
-       for (;;) {
-               if (ss7boost_client_connection_read(&ss7boost_handle->mcon, &event) == SWITCH_STATUS_SUCCESS) {
-                       struct timeval current;
-                       struct timeval difftime;
-                       gettimeofday(&current, NULL);
-                       timersub(&current, &event->tv, &difftime);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket Event [%s] T=%d:%d\n",
-                                                         ss7boost_client_event_id_name(event->event_id), (int) difftime.tv_sec, (int) difftime.tv_usec);
-
-                       parse_ss7_event(ss7boost_handle, event);
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: Reading from Boost Socket! %s\n", strerror(errno));
-                       break;
-               }
-       }
-
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Close udp socket\n");
-       ss7boost_client_connection_close(&ss7boost_handle->mcon);
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Ended\n");
-
-
-       return NULL;
-}
-
-static void launch_ss7boost_handle(ss7boost_handle_t *ss7boost_handle)
-{
-       switch_thread_t *thread;
-       switch_threadattr_t *thd_attr = NULL;
-
-       switch_threadattr_create(&thd_attr, module_pool);
-       switch_threadattr_detach_set(thd_attr, 1);
-       switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_thread_create(&thread, thd_attr, boost_thread_run, ss7boost_handle, module_pool);
-}
-
-
-
-static switch_status_t config_wanpipe(int reload)
-{
-       char *cf = "wanpipe.conf";
-       int current_span = 0, min_span = 0, max_span = 0;
-       switch_xml_t cfg, xml, settings, param, pri_spans, ss7boost_handles, span, analog_channels, channel;
-
-       globals.samples_per_frame = DEFAULT_SAMPLES_PER_FRAME;
-       globals.dtmf_on = 150;
-       globals.dtmf_off = 50;
-
-
-
-       if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
-               return SWITCH_STATUS_TERM;
-       }
-
-
-       if ((settings = switch_xml_child(cfg, "settings"))) {
-               for (param = switch_xml_child(settings, "param"); param; param = param->next) {
-                       char *var = (char *) switch_xml_attr_soft(param, "name");
-                       char *val = (char *) switch_xml_attr_soft(param, "value");
-
-                       if (!strcmp(var, "debug")) {
-                               globals.debug = atoi(val);
-                       } else if (!strcmp(var, "ms-per-frame")) {
-                               globals.samples_per_frame = atoi(val) * 8;
-                       } else if (!strcmp(var, "dtmf-on")) {
-                               globals.dtmf_on = atoi(val);
-                       } else if (!strcmp(var, "dtmf-off")) {
-                               globals.dtmf_off = atoi(val);
-                       } else if (!strcmp(var, "dialplan")) {
-                               set_global_dialplan(val);
-                       } else if (!strcmp(var, "context")) {
-                               set_global_context(val);
-                       } else if (!strcmp(var, "suppress-dtmf-tone")) {
-                               globals.suppress_dtmf_tone = switch_true(val);
-                       } else if (!strcmp(var, "ignore-dtmf-tone")) {
-                               globals.ignore_dtmf_tone = switch_true(val);
-                       }
-               }
-       }
-
-       ss7boost_handles = switch_xml_child(cfg, "ss7boost_handles");
-       for (span = switch_xml_child(ss7boost_handles, "handle"); span; span = span->next) {
-               char *local_ip = NULL, *remote_ip = NULL;
-               int local_port = 0, remote_port = 0;
-               ss7boost_handle_t *ss7boost_handle;
-
-               for (param = switch_xml_child(span, "param"); param; param = param->next) {
-                       char *var = (char *) switch_xml_attr_soft(param, "name");
-                       char *val = (char *) switch_xml_attr_soft(param, "value");
-
-                       if (!strcasecmp(var, "local-ip")) {
-                               local_ip = val;
-                       } else if (!strcasecmp(var, "local-port")) {
-                               local_port = atoi(val);
-                       } else if (!strcasecmp(var, "remote-ip")) {
-                               remote_ip = val;
-                       } else if (!strcasecmp(var, "remote-port")) {
-                               remote_port = atoi(val);
-                       }
-               }
-
-
-               if (!(local_ip && local_port && remote_ip && remote_port)) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Config, skipping...\n");
-                       continue;
-               }
-
-               assert(ss7boost_handle = malloc(sizeof(*ss7boost_handle)));
-               memset(ss7boost_handle, 0, sizeof(*ss7boost_handle));
-               ss7boost_handle->local_ip = switch_core_strdup(module_pool, local_ip);
-               ss7boost_handle->local_port = local_port;
-               ss7boost_handle->remote_ip = switch_core_strdup(module_pool, remote_ip);
-               ss7boost_handle->remote_port = remote_port;
-
-               switch_mutex_init(&ss7boost_handle->mutex, SWITCH_MUTEX_NESTED, module_pool);
-               launch_ss7boost_handle(ss7boost_handle);
-               break;
-       }
-
-       analog_channels = switch_xml_child(cfg, "analog_channels");
-       for (channel = switch_xml_child(analog_channels, "channel"); channel; channel = channel->next) {
-               char *c_type = (char *) switch_xml_attr(channel, "type");
-               char *c_dev = (char *) switch_xml_attr(channel, "device");
-               char *user = NULL;
-               char *domain = NULL;
-               char *cid_name = NULL, *cid_num = NULL;
-               analog_channel_t *alc;
-               analog_type_t a_type = ANALOG_TYPE_UNKNOWN;
-               wpsock_t *sock;
-               int chan, span;
-
-               if (!c_type) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required attribute 'type'\n");
-                       continue;
-               }
-
-               if (!strcasecmp(c_type, "phone") || !strcasecmp(c_type, "fxs")) {
-                       a_type = ANALOG_TYPE_PHONE_FXS;
-               } else if (!strcasecmp(c_type, "line") || !strcasecmp(c_type, "fxo")) {
-                       a_type = ANLOG_TYPE_LINE_FXO;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid type '%s'\n", c_type);
-                       continue;
-               }
-
-               if (!c_dev) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required attribute 'device'\n");
-                       continue;
-               }
-
-               if (!sangoma_span_chan_fromif(c_dev, &span, &chan)) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid device name '%s'\n", c_dev);
-                       continue;
-               }
-
-               if (!(sock = wp_open(span, chan))) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open device '%s' (%s)\n", c_dev, strerror(errno));
-                       continue;
-               }
-
-               for (param = switch_xml_child(channel, "param"); param; param = param->next) {
-                       char *var = (char *) switch_xml_attr_soft(param, "name");
-                       char *val = (char *) switch_xml_attr_soft(param, "value");
-
-                       if (!strcasecmp(var, "user")) {
-                               user = var;
-                       } else if (!strcasecmp(var, "domain")) {
-                               domain = val;
-                       } else if (!strcasecmp(var, "caller-id-name")) {
-                               cid_name = val;
-                       } else if (!strcasecmp(var, "caller-id-number")) {
-                               cid_num = val;
-                       }
-               }
-
-               assert((alc = malloc(sizeof(*alc))));
-               memset(alc, 0, sizeof(*alc));
-               if (user) {
-                       alc->user = strdup(user);
-               }
-               if (domain) {
-                       alc->domain = strdup(domain);
-               }
-               if (cid_name) {
-                       alc->cid_name = strdup(cid_name);
-               }
-               if (cid_num) {
-                       alc->cid_name = strdup(cid_num);
-               }
-
-               alc->a_type = a_type;
-               alc->sock = sock;
-               alc->chan = chan;
-               alc->span = span;
-
-               if (a_type == ANALOG_TYPE_PHONE_FXS) {
-                       FXS_ANALOG_CHANNELS[globals.fxs_index++] = alc;
-               } else {
-                       FXO_ANALOG_CHANNELS[globals.fxo_index++] = alc;
-               }
-       }
-
-
-       if (globals.fxs_index) {
-               switch_thread_t *thread;
-               switch_threadattr_t *thd_attr = NULL;
-
-               switch_threadattr_create(&thd_attr, module_pool);
-               switch_threadattr_detach_set(thd_attr, 1);
-               switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-               switch_thread_create(&thread, thd_attr, fxs_thread_run, NULL, module_pool);
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting FXS Thread!\n");
-       }
-
-
-       pri_spans = switch_xml_child(cfg, "pri_spans");
-       for (span = switch_xml_child(pri_spans, "span"); span; span = span->next) {
-               char *id = (char *) switch_xml_attr(span, "id");
-               int32_t i = 0;
-
-               current_span = 0;
-
-               if (id) {
-                       char *p;
-
-                       min_span = atoi(id);
-                       if ((p = strchr(id, '-'))) {
-                               p++;
-                               max_span = atoi(p);
-                       } else {
-                               max_span = min_span;
-                       }
-                       if (min_span < 1 || max_span < min_span) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Span Config! [%s]\n", id);
-                               continue;
-                       }
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing SPAN ID!\n");
-                       continue;
-               }
-
-               for (i = min_span; i <= max_span; i++) {
-                       current_span = i;
-
-                       if (current_span <= 0 || current_span > MAX_SPANS) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid SPAN %d!\n", current_span);
-                               current_span = 0;
-                               continue;
-                       }
-
-                       if (!SPANS[current_span]) {
-                               if (!(SPANS[current_span] = switch_core_alloc(module_pool, sizeof(*SPANS[current_span])))) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "MEMORY ERROR\n");
-                                       break;
-                               }
-                               SPANS[current_span]->span = current_span;
-                       }
-
-
-                       for (param = switch_xml_child(span, "param"); param; param = param->next) {
-                               char *var = (char *) switch_xml_attr_soft(param, "name");
-                               char *val = (char *) switch_xml_attr_soft(param, "value");
-
-                               if (!strcmp(var, "dchan")) {
-                                       SPANS[current_span]->dchan = atoi(val);
-                               } else if (!strcmp(var, "bchan")) {
-                                       char from[128];
-                                       char *to;
-                                       switch_copy_string(from, val, sizeof(from));
-                                       if ((to = strchr(from, '-'))) {
-                                               int fromi, toi, x = 0;
-                                               *to++ = '\0';
-                                               fromi = atoi(from);
-                                               toi = atoi(to);
-                                               if (fromi > 0 && toi > 0 && fromi < toi && fromi < MAX_SPANS && toi < MAX_SPANS) {
-                                                       for (x = fromi; x <= toi; x++) {
-                                                               SPANS[current_span]->bchans |= (1 << x);
-                                                       }
-                                               } else {
-                                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid bchan range!\n");
-                                               }
-                                       } else {
-                                               int i = atoi(val);
-                                               if (i > 0 && i < 31) {
-                                                       SPANS[current_span]->bchans |= (1 << i);
-                                               } else {
-                                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid bchan!\n");
-                                               }
-                                       }
-                               } else if (!strcmp(var, "node")) {
-                                       SPANS[current_span]->node = str2node(val);
-                               } else if (!strcmp(var, "switch")) {
-                                       SPANS[current_span]->pswitch = str2switch(val);
-                               } else if (!strcmp(var, "dp")) {
-                                       SPANS[current_span]->dp = str2dp(val);
-                               } else if (!strcmp(var, "l1")) {
-                                       SPANS[current_span]->l1 = str2l1(val);
-                               }
-                       }
-               }
-       }
-       switch_xml_free(xml);
-
-       if (!globals.dialplan) {
-               set_global_dialplan("XML");
-       }
-
-       globals.configured_spans = 0;
-       for (current_span = 1; current_span < MAX_SPANS; current_span++) {
-               if (SPANS[current_span]) {
-
-                       if (!SPANS[current_span]->l1) {
-                               SPANS[current_span]->l1 = PRI_LAYER_1_ULAW;
-                       }
-                       if (sangoma_init_pri(&SPANS[current_span]->spri,
-                                                                current_span, SPANS[current_span]->dchan, SPANS[current_span]->pswitch, SPANS[current_span]->node, globals.debug)) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot launch span %d\n", current_span);
-                               continue;
-                       }
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Launch span %d\n", current_span);
-                       pri_thread_launch(&SPANS[current_span]->spri);
-                       switch_mutex_lock(globals.hash_mutex);
-                       globals.configured_spans++;
-                       switch_mutex_unlock(globals.hash_mutex);
-               }
-       }
-
-       return SWITCH_STATUS_SUCCESS;
-}
-
-/* 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 expandtab:
- */
diff --git a/src/mod/endpoints/mod_wanpipe/sigboost.h b/src/mod/endpoints/mod_wanpipe/sigboost.h
deleted file mode 100644 (file)
index 25cb812..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
- * 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
diff --git a/src/mod/endpoints/mod_wanpipe/ss7boost_client.c b/src/mod/endpoints/mod_wanpipe/ss7boost_client.c
deleted file mode 100644 (file)
index 4ef380b..0000000
+++ /dev/null
@@ -1,243 +0,0 @@
-/* 
- * 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;
-}
diff --git a/src/mod/endpoints/mod_wanpipe/ss7boost_client.h b/src/mod/endpoints/mod_wanpipe/ss7boost_client.h
deleted file mode 100644 (file)
index 89be001..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/* 
- * 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
diff --git a/src/mod/endpoints/mod_wanpipe/testapp.c b/src/mod/endpoints/mod_wanpipe/testapp.c
deleted file mode 100644 (file)
index edc4230..0000000
+++ /dev/null
@@ -1,425 +0,0 @@
-/*****************************************************************************
-* aft_api.c    AFT T1/E1: HDLC API Sample Code
-*
-* Author(s):   Nenad Corbic <ncorbic@sangoma.com>
-*
-* Copyright:   (c) 2003-2004 Sangoma Technologies Inc.
-*
-*              This program is free software; you can redistribute it and/or
-*              modify it under the terms of the GNU General Public License
-*              as published by the Free Software Foundation; either version
-*              2 of the License, or (at your option) any later version.
-* ============================================================================
-*/
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <linux/if_wanpipe.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <linux/if.h>
-#include <linux/wanpipe_defines.h>
-#include <linux/wanpipe_cfg.h>
-#include <linux/wanpipe.h>
-#include <libsangoma.h>
-#include "lib_api.h"
-
-#define MAX_TX_DATA     5000   /* Size of tx data */
-#define MAX_FRAMES     5000            /* Number of frames to transmit */
-
-#define MAX_RX_DATA    5000
-
-unsigned short Rx_lgth;
-
-unsigned char Rx_data[MAX_RX_DATA];
-unsigned char Tx_data[MAX_TX_DATA + sizeof(wp_tdm_api_rx_hdr_t)];
-
-/* Prototypes */
-int MakeConnection(void);
-void handle_span_chan(void);
-void sig_end(int sigid);
-
-int dev_fd;
-FILE *tx_fd = NULL, *rx_fd = NULL;
-wanpipe_tdm_api_t tdm_api;
-
-
-/***************************************************
-* HANDLE SOCKET 
-*
-*   o Read a socket 
-*   o Cast data received to api_rx_element_t data type 
-*   o The received packet contains 16 bytes header 
-*
-*      ------------------------------------------
-*      |  16 bytes      |        X bytes        ...
-*      ------------------------------------------
-*         Header              Data
-*
-* o Data structures:
-* ------------------
-* typedef struct {
-*      union {
-*              struct {
-*                      unsigned char   _event_type;
-*                      unsigned char   _rbs_rx_bits;
-*                      unsigned int    _time_stamp;
-*              }wp_event;
-*              struct {
-*                      unsigned char   _rbs_rx_bits;
-*                      unsigned int    _time_stamp;
-*              }wp_rx;
-*              unsigned char   reserved[16];
-*      }wp_rx_hdr_u;
-* #define wp_api_event_type            wp_rx_hdr_u.wp_event._event_type
-* #define wp_api_event_rbs_rx_bits     wp_rx_hdr_u.wp_event._rbs_rx_bits
-* #define wp_api_event_time_stamp      wp_rx_hdr_u.wp_event._time_stamp
-* } wp_tdm_api_rx_hdr_t;
-* 
-* typedef struct {
-*         wp_tdm_api_rx_hdr_t  hdr;
-*         unsigned char                data[1];
-* } wp_tdm_api_rx_element_t;
-* 
-* typedef struct {
-*      union {
-*              struct {
-*                      unsigned char   _rbs_rx_bits;
-*                      unsigned int    _time_stamp;
-*              }wp_tx;
-*              unsigned char   reserved[16];
-*      }wp_tx_hdr_u;
-* #define wp_api_time_stamp    wp_tx_hdr_u.wp_tx._time_stamp
-* } wp_tdm_api_tx_hdr_t;
-* 
-* typedef struct {
-*         wp_tdm_api_tx_hdr_t  hdr;
-*         unsigned char                data[1];
-* } wp_tdm_api_tx_element_t;
-*                     
-* #define WPTDM_A_BIT 0x08
-* #define WPTDM_B_BIT 0x04
-* #define WPTDM_C_BIT 0x02
-* #define WPTDM_D_BIT 0x01
-*
-*/
-
-void handle_span_chan(void)
-{
-       unsigned int Rx_count, Tx_count, Tx_length;
-       wp_tdm_api_rx_element_t *api_rx_el;
-       wp_tdm_api_tx_element_t *api_tx_el;
-       fd_set ready, write, oob;
-       int err, i;
-
-#if 0
-       int rlen;
-       int stream_sync = 0;
-#endif
-
-       Rx_count = 0;
-       Tx_count = 0;
-
-       if (tdm_api.wp_tdm_cmd.hdlc) {
-               Tx_length = tx_size;
-       } else {
-               Tx_length = tdm_api.wp_tdm_cmd.usr_mtu_mru;
-       }
-
-       printf("\n\nSocket Handler: Rx=%d Tx=%i TxCnt=%i TxLen=%i TxDelay=%i\n", read_enable, write_enable, tx_cnt, tx_size, tx_delay);
-
-       /* Initialize the Tx Data buffer */
-       memset(&Tx_data[0], 0, MAX_TX_DATA + sizeof(wp_tdm_api_rx_hdr_t));
-
-       /* Cast the Tx data packet with the tx element
-        * structure.  We must insert a 16 byte
-        * driver header, which driver will remove 
-        * before passing packet out the physical port */
-       api_tx_el = (wp_tdm_api_tx_element_t *) &Tx_data[0];
-
-
-       /* Create a Tx packet based on user info, or
-        * by deafult incrementing number starting from 0 */
-       for (i = 0; i < Tx_length; i++) {
-               if (tx_data == -1) {
-                       api_tx_el->data[i] = (unsigned char) i;
-               } else {
-#if 0
-                       api_tx_el->data[i] = (unsigned char) tx_data + (i % 4);
-#else
-                       api_tx_el->data[i] = (unsigned char) tx_data;
-#endif
-               }
-       }
-
-       sangoma_tdm_enable_rxhook_events(dev_fd, &tdm_api);
-
-       /* Main Rx Tx OOB routine */
-       for (;;) {
-
-               /* Initialize all select() descriptors */
-               FD_ZERO(&ready);
-               FD_ZERO(&write);
-               FD_ZERO(&oob);
-               FD_SET(dev_fd, &oob);
-               FD_SET(dev_fd, &ready);
-
-               if (write_enable) {
-                       FD_SET(dev_fd, &write);
-               }
-
-               /* Select will block, until:
-                *  1: OOB event, link level change
-                *  2: Rx data available
-                *  3: Interface able to Tx */
-
-               if (select(dev_fd + 1, &ready, &write, &oob, NULL)) {
-
-                       fflush(stdout);
-                       if (FD_ISSET(dev_fd, &oob)) {
-
-                               /* An OOB event is pending, usually indicating
-                                * a link level change */
-
-                               err = sangoma_tdm_read_event(dev_fd, &tdm_api);
-
-                               if (err < 0) {
-                                       printf("Failed to receive OOB %i , %i\n", Rx_count, err);
-                                       err = ioctl(dev_fd, SIOC_WANPIPE_SOCK_STATE, 0);
-                                       printf("Sock state is %s\n", (err == 0) ? "CONNECTED" : (err == 1) ? "DISCONNECTED" : "CONNECTING");
-                                       break;
-                               }
-
-                               printf("GOT OOB EXCEPTION CMD Exiting\n");
-                       }
-
-
-                       if (FD_ISSET(dev_fd, &ready)) {
-
-                               /* An Rx packet is pending
-                                *  1: Read the rx packet into the Rx_data
-                                *     buffer. Confirm len > 0
-                                *
-                                *  2: Cast Rx_data to the api_rx_element.
-                                *     Thus, removing a 16 byte header
-                                *     attached by the driver.
-                                *
-                                *  3. Check error_flag:
-                                *      CRC,Abort..etc 
-                                */
-
-                               memset(Rx_data, 0, sizeof(Rx_data));
-
-                               err = sangoma_readmsg_tdm(dev_fd, Rx_data, sizeof(wp_tdm_api_rx_hdr_t), &Rx_data[sizeof(wp_tdm_api_rx_hdr_t)], MAX_RX_DATA, 0);
-
-
-                               if (!read_enable) {
-                                       goto bitstrm_skip_read;
-                               }
-
-                               /* err indicates bytes received */
-                               if (err <= 0) {
-                                       printf("\nError receiving data\n");
-                                       break;
-                               }
-
-                               api_rx_el = (wp_tdm_api_rx_element_t *) & Rx_data[0];
-
-                               /* Check the packet length */
-                               Rx_lgth = err;
-                               if (Rx_lgth <= 0) {
-                                       printf("\nShort frame received (%d)\n", Rx_lgth);
-                                       return;
-                               }
-#if 0
-                               if (api_rx_el->data[0] == tx_data && api_rx_el->data[1] == (tx_data + 1)) {
-                                       if (!stream_sync) {
-                                               printf("GOT SYNC %x\n", api_rx_el->data[0]);
-                                       }
-                                       stream_sync = 1;
-                               } else {
-                                       if (stream_sync) {
-                                               printf("OUT OF SYNC: %x\n", api_rx_el->data[0]);
-                                       }
-                               }
-#endif
-
-                               ++Rx_count;
-
-                               if (verbose) {
-#if 0
-                                       printf("Received %i Length = %i\n", Rx_count, Rx_lgth);
-
-                                       printf("Data: ");
-                                       for (i = 0; i < Rx_lgth; i++) {
-                                               printf("0x%02X ", api_rx_el->data[i]);
-                                       }
-                                       printf("\n");
-#endif
-                               } else {
-                                       //putchar('R');
-                               }
-
-
-#if 0
-                               switch (api_rx_el->hdr.wp_api_event_type) {
-                               case WP_TDM_EVENT_DTMF:
-                                       printf("DTMV Event: %c (%s:%s)!\n",
-                                                  api_rx_el->hdr.wp_api_event_dtmf_digit,
-                                                  (api_rx_el->hdr.wp_api_event_dtmf_type & WP_TDM_EVENT_DTMF_ROUT) ? "ROUT" : "SOUT",
-                                                  (api_rx_el->hdr.wp_api_event_dtmf_type & WP_TDM_EVENT_DTMF_PRESET) ? "PRESET" : "STOP");
-                                       break;
-                               case WP_TDM_EVENT_RXHOOK:
-                                       printf("RXHOOK Event: %s!\n", (api_rx_el->hdr.wp_api_event_rxhook_state & WP_TDM_EVENT_RXHOOK_OFF) ? "OFF-HOOK" : "ON-HOOK");
-                                       break;
-                               case WP_TDM_EVENT_RING:
-                                       printf("RING Event: %s!\n", (api_rx_el->hdr.wp_api_event_ring_state & WP_TDM_EVENT_RING_PRESENT) ? "PRESENT" : "STOP");
-                                       break;
-                               }
-#endif
-
-                               if (rx_cnt > 0 && Rx_count >= rx_cnt) {
-                                       break;
-                               }
-                         bitstrm_skip_read:
-                               ;
-                       }
-
-                       if (FD_ISSET(dev_fd, &write)) {
-
-
-                               err = sangoma_writemsg_tdm(dev_fd, Tx_data, 16, &Tx_data[16], Tx_length, 0);
-                               if (err <= 0) {
-                                       if (errno == EBUSY) {
-                                               if (verbose) {
-                                                       printf("Sock busy try again!\n");
-                                               }
-                                               /* Socket busy try sending again ! */
-                                       } else {
-                                               printf("Faild to send %i \n", errno);
-                                               perror("Send: ");
-                                               break;
-                                       }
-                               } else {
-
-                                       ++Tx_count;
-
-                                       if (verbose) {
-                                               //printf("Packet sent: Sent %i : %i\n",
-                                               //  err,Tx_count);
-                                       } else {
-                                               //putchar('T');
-                                       }
-                               }
-                       }
-
-                       if (tx_delay) {
-                               usleep(tx_delay);
-                       }
-
-                       if (tx_cnt && tx_size && Tx_count >= tx_cnt && !(files_used & TX_FILE_USED)) {
-
-                               write_enable = 0;
-                               if (rx_cnt > 0) {
-                                       /* Dont break let rx finish */
-                               } else {
-                                       break;
-                               }
-                       }
-               }
-       }
-
-       sangoma_tdm_disable_rxhook_events(dev_fd, &tdm_api);
-       if (tx_fd) {
-               fclose(tx_fd);
-       }
-       if (rx_fd) {
-               fclose(rx_fd);
-       }
-       close(dev_fd);
-       return;
-
-}
-
-int rxhook_event(int fd, unsigned char state)
-{
-       printf("%d: RXHOOK Event: %s!\n", fd, (state & WAN_EVENT_RXHOOK_OFF) ? "OFF-HOOK" : "ON-HOOK");
-       return 0;
-}
-
-/***************************************************************
- * Main:
- *
- *    o Make a socket connection to the driver.
- *    o Call handle_span_chan() to read the socket 
- *
- **************************************************************/
-
-
-int main(int argc, char *argv[])
-{
-       int proceed;
-
-       proceed = init_args(argc, argv);
-       if (proceed != WAN_TRUE) {
-               usage(argv[0]);
-               return -1;
-       }
-
-       signal(SIGINT, &sig_end);
-       memset(&tdm_api, 0, sizeof(tdm_api));
-       tdm_api.wp_tdm_event.wp_rxhook_event = &rxhook_event;
-
-       printf("TDM RXHOOK PTR = %p\n", tdm_api.wp_tdm_event.wp_rxhook_event);
-
-       dev_fd = -1;
-
-       dev_fd = sangoma_open_tdmapi_span_chan(atoi(card_name), atoi(if_name));
-       if (dev_fd < 0) {
-               printf("Failed to open span chan (%s:%s:%d:%d)\n", card_name, if_name, atoi(card_name), atoi(if_name));
-               exit(1);
-       }
-       printf("HANDLING SPAN %i CHAN %i FD=%i\n", atoi(card_name), atoi(if_name), dev_fd);
-
-       sangoma_tdm_set_codec(dev_fd, &tdm_api, WP_NONE);
-       sangoma_get_full_cfg(dev_fd, &tdm_api);
-
-       handle_span_chan();
-       close(dev_fd);
-       return 0;
-
-       return 0;
-};
-
-
-void sig_end(int sigid)
-{
-
-       printf("Got Signal %i\n", sigid);
-
-       sangoma_tdm_disable_rxhook_events(dev_fd, &tdm_api);
-
-       if (tx_fd) {
-               fclose(tx_fd);
-       }
-       if (rx_fd) {
-               fclose(rx_fd);
-       }
-
-       if (dev_fd) {
-               close(dev_fd);
-       }
-
-
-       exit(1);
-}