-
-#define FNAME_LEN 50
-
-
-#if defined(__WINDOWS__)
-/* This might be broken on windows, as POLL_EVENT_TELEPHONY seems to be commented out in sang_api.h.. it should be added to POLLPRI */
-#define POLLPRI (POLL_EVENT_LINK_STATE | POLL_EVENT_LINK_CONNECT | POLL_EVENT_LINK_DISCONNECT)
-#endif
-
-/* return -1 for error, 0 for timeout or 1 for success. *flags is set to the poll evetns POLLIN | POLLOUT | POLLPRI based on the result of the poll */
-/* on windows we actually have POLLPRI defined with several events, so we could theoretically poll */
-/* for specific events. Is there any way to do this on *nix as well? */
-
-/* a cross platform way to poll on an actual pollset (span and/or list of spans) will probably also be needed for analog */
-/* so we can have one analong handler thread that will deal with all the idle analog channels for events */
-/* the alternative would be for the driver to provide one socket for all of the oob events for all analog channels */
-static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags)
-{
-#if defined(__WINDOWS__)
- DWORD ln;
- API_POLL_STRUCT api_poll;
-
- memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT));
-
- api_poll.user_flags_bitmap = *flags;
- api_poll.timeout = timeout;
-
- if (!DeviceIoControl(
- fd,
- IoctlApiPoll,
- (LPVOID)NULL,
- 0L,
- (LPVOID)&api_poll,
- sizeof(API_POLL_STRUCT),
- (LPDWORD)(&ln),
- (LPOVERLAPPED)NULL)) {
- return -1;
- }
-
- *flags = 0;
-
- switch(api_poll.operation_status)
- {
- case SANG_STATUS_RX_DATA_AVAILABLE:
- break;
-
- case SANG_STATUS_RX_DATA_TIMEOUT:
- return 0;
-
- default:
- return -1;
- }
-
- if (api_poll.poll_events_bitmap == 0){
- return -1;
- }
-
- if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) {
- return 0;
- }
-
- *flags = api_poll.poll_events_bitmap;
-
- return 1;
-#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);
- *flags = 0;
-
- if (pfds[0].revents & POLLERR) {
- res = -1;
- }
-
- if (res > 0) {
- *flags = pfds[0].revents;
- }
-
- return res;
-#endif
-}
-
-/* on windows right now, there is no way to specify if we want to read events here or not, we allways get them here */
-/* we need some what to select if we are reading regular tdm msgs or events */
-/* need to either have 2 functions, 1 for events, 1 for regural read, or a flag on this function to choose */
-/* 2 functions preferred. Need implementation for the event function for both nix and windows that is threadsafe */
-static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen)
-{
- /* What do we need to do here to avoid having to do all */
- /* the memcpy's on windows and still maintain api compat with nix */
- int rx_len=0;
-#if defined(__WINDOWS__)
- 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;
- DWORD ln;
-
- if (hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){
- return -1;
- }
-
- if (!DeviceIoControl(
- fd,
- IoctlReadCommand,
- (LPVOID)NULL,
- 0L,
- (LPVOID)&rx_data,
- sizeof(RX_DATA_STRUCT),
- (LPDWORD)(&ln),
- (LPOVERLAPPED)NULL
- )){
- return -1;
- }
-
- 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:
- if (pri->data_length > datalen){
- break;
- }
- memcpy(databuf, rx_data.data, pri->data_length);
- rx_len = pri->data_length;
- break;
-
- default:
- break;
- }
-
-#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;
-}
-
-static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen)
-{
- /* What do we need to do here to avoid having to do all */
- /* the memcpy's on windows and still maintain api compat with nix */
- int bsent = 0;
-#if defined(__WINDOWS__)
- static TX_DATA_STRUCT local_tx_data;
- api_header_t *pri;
- DWORD ln;
-
- /* Are these really not needed or used??? What about for nix?? */
- (void)hdrbuf;
- (void)hdrlen;
-
- pri = &local_tx_data.api_header;
-
- pri->data_length = datalen;
- memcpy(local_tx_data.data, databuf, pri->data_length);
-
- if (!DeviceIoControl(
- fd,
- IoctlWriteCommand,
- (LPVOID)&local_tx_data,
- (ULONG)sizeof(TX_DATA_STRUCT),
- (LPVOID)&local_tx_data,
- sizeof(TX_DATA_STRUCT),
- (LPDWORD)(&ln),
- (LPOVERLAPPED)NULL
- )){
- return -1;
- }
-
- if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) {
- bsent = datalen;
- }
-#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;
-}
-
-#endif /* _SANGOMA_TDM_API_H */
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/include/uart.h b/libs/openzap/src/include/uart.h
deleted file mode 100644
index 89c3a13abc..0000000000
--- a/libs/openzap/src/include/uart.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * uart.h
- *
- * Copyright (c) 2005 Robert Krten. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This module contains the manifest constants and declarations for
- * the UART module.
- *
- * 2005 06 19 R. Krten created
-*/
-
-#ifndef __UART_H__
-#define __UART_H__
-
-typedef void (*bytehandler_func_t) (void *, int);
-typedef void (*bithandler_func_t) (void *, int);
-
-
-typedef struct dsp_uart_attr_s
-{
- bytehandler_func_t bytehandler; /* byte handler */
- void *bytehandler_arg; /* arbitrary ID passed to bytehandler as first argument */
-} dsp_uart_attr_t;
-
-typedef struct
-{
- dsp_uart_attr_t attr;
- int have_start; /* wait for start bit to show up */
- int data; /* data buffer */
- int nbits; /* number of bits accumulated so far */
-} dsp_uart_handle_t;
-
-/*
- * Function prototypes
- *
- * General calling order is:
- * a) create the attributes structure (dsp_uart_attr_init)
- * b) initialize fields in the attributes structure (dsp_uart_attr_set_*)
- * c) create a Bell-202 handle (dsp_uart_create)
- * d) feed bits through dsp_uart_bit_handler
-*/
-
-void dsp_uart_attr_init(dsp_uart_attr_t *attributes);
-
-bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attributes, void **bytehandler_arg);
-void dsp_uart_attr_set_bytehandler(dsp_uart_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg);
-
-dsp_uart_handle_t * dsp_uart_create(dsp_uart_attr_t *attributes);
-void dsp_uart_destroy(dsp_uart_handle_t **handle);
-
-void dsp_uart_bit_handler(void *handle, int bit);
-
-#endif
-
diff --git a/libs/openzap/src/include/zap_buffer.h b/libs/openzap/src/include/zap_buffer.h
deleted file mode 100644
index 1a2b264f90..0000000000
--- a/libs/openzap/src/include/zap_buffer.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_BUFFER_H
-#define ZAP_BUFFER_H
-
-#include "openzap.h"
-
-/**
- * @defgroup zap_buffer Buffer Routines
- * @ingroup buffer
- * The purpose of this module is to make a plain buffering interface that can be used for read/write buffers
- * throughout the application.
- * @{
- */
-struct zap_buffer;
-typedef struct zap_buffer zap_buffer_t;
-
-/*! \brief Allocate a new dynamic zap_buffer
- * \param buffer returned pointer to the new buffer
- * \param blocksize length to realloc by as data is added
- * \param start_len ammount of memory to reserve initially
- * \param max_len length the buffer is allowed to grow to
- * \return status
- */
-OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len);
-
-/*! \brief Get the length of a zap_buffer_t
- * \param buffer any buffer of type zap_buffer_t
- * \return int size of the buffer.
- */
-OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer);
-
-/*! \brief Get the freespace of a zap_buffer_t
- * \param buffer any buffer of type zap_buffer_t
- * \return int freespace in the buffer.
- */
-OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer);
-
-/*! \brief Get the in use amount of a zap_buffer_t
- * \param buffer any buffer of type zap_buffer_t
- * \return int ammount of buffer curently in use
- */
-OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer);
-
-/*! \brief Read data from a zap_buffer_t up to the ammount of datalen if it is available. Remove read data from buffer.
- * \param buffer any buffer of type zap_buffer_t
- * \param data pointer to the read data to be returned
- * \param datalen amount of data to be returned
- * \return int ammount of data actually read
- */
-OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen);
-
-/*! \brief Read data endlessly from a zap_buffer_t
- * \param buffer any buffer of type zap_buffer_t
- * \param data pointer to the read data to be returned
- * \param datalen amount of data to be returned
- * \return int ammount of data actually read
- * \note Once you have read all the data from the buffer it will loop around.
- */
-OZ_DECLARE(zap_size_t) zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen);
-
-/*! \brief Assign a number of loops to read
- * \param buffer any buffer of type zap_buffer_t
- * \param loops the number of loops (-1 for infinite)
- */
-OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int32_t loops);
-
-/*! \brief Write data into a zap_buffer_t up to the length of datalen
- * \param buffer any buffer of type zap_buffer_t
- * \param data pointer to the data to be written
- * \param datalen amount of data to be written
- * \return int amount of buffer used after the write, or 0 if no space available
- */
-OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen);
-
-/*! \brief Remove data from the buffer
- * \param buffer any buffer of type zap_buffer_t
- * \param datalen amount of data to be removed
- * \return int size of buffer, or 0 if unable to toss that much data
- */
-OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen);
-
-/*! \brief Remove all data from the buffer
- * \param buffer any buffer of type zap_buffer_t
- */
-OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer);
-
-/*! \brief Destroy the buffer
- * \param buffer buffer to destroy
- * \note only neccessary on dynamic buffers (noop on pooled ones)
- */
-OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer);
-
-/*! \brief Seek to offset from the beginning of the buffer
- * \param buffer buffer to seek
- * \param datalen offset in bytes
- * \return new position
- */
-OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen);
-
-/** @} */
-
-OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen);
-
-#endif
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/include/zap_config.h b/libs/openzap/src/include/zap_config.h
deleted file mode 100644
index db62b459a5..0000000000
--- a/libs/openzap/src/include/zap_config.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * @defgroup config Config File Parser
- * @ingroup config
- * This module implements a basic interface and file format parser
- *
- *
- *
- * EXAMPLE
- *
- * [category1]
- * var1 => val1
- * var2 => val2
- * \# lines that begin with \# are comments
- * \#var3 => val3
- *
- * @{
- */
-
-#ifndef ZAP_CONFIG_H
-#define ZAP_CONFIG_H
-
-#include "openzap.h"
-#define ZAP_URL_SEPARATOR "://"
-
-
-#ifdef WIN32
-#define ZAP_PATH_SEPARATOR "\\"
-#ifndef ZAP_CONFIG_DIR
-#define ZAP_CONFIG_DIR "c:\\openzap"
-#endif
-#define zap_is_file_path(file) (*(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR))
-#else
-#define ZAP_PATH_SEPARATOR "/"
-#ifndef ZAP_CONFIG_DIR
-#define ZAP_CONFIG_DIR "/etc/openzap"
-#endif
-#define zap_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
-#endif
-
-typedef struct zap_config zap_config_t;
-
-/*! \brief A simple file handle representing an open configuration file **/
-struct zap_config {
- /*! FILE stream buffer to the opened file */
- FILE *file;
- /*! path to the file */
- char path[512];
- /*! current category */
- char category[256];
- /*! current section */
- char section[256];
- /*! buffer of current line being read */
- char buf[1024];
- /*! current line number in file */
- int lineno;
- /*! current category number in file */
- int catno;
- /*! current section number in file */
- int sectno;
-
- int lockto;
-};
-
-/*!
- \brief Open a configuration file
- \param cfg (zap_config_t *) config handle to use
- \param file_path path to the file
- \return 1 (true) on success 0 (false) on failure
-*/
-int zap_config_open_file(zap_config_t * cfg, const char *file_path);
-
-/*!
- \brief Close a previously opened configuration file
- \param cfg (zap_config_t *) config handle to use
-*/
-void zap_config_close_file(zap_config_t * cfg);
-
-/*!
- \brief Retrieve next name/value pair from configuration file
- \param cfg (zap_config_t *) config handle to use
- \param var pointer to aim at the new variable name
- \param val pointer to aim at the new value
-*/
-int zap_config_next_pair(zap_config_t * cfg, char **var, char **val);
-
-/*!
- \brief Retrieve the CAS bits from a configuration string value
- \param strvalue pointer to the configuration string value (expected to be in format whatever:xxxx)
- \param outbits pointer to aim at the CAS bits
-*/
-OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits);
-
-
-/** @} */
-#endif
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/include/zap_cpu_monitor.h b/libs/openzap/src/include/zap_cpu_monitor.h
deleted file mode 100644
index 8eb057cde3..0000000000
--- a/libs/openzap/src/include/zap_cpu_monitor.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* * Copyright (c) 2009, Sangoma Technologies
- * Moises Silva
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *
- * Contributors:
- * David Yat Sin
- *
- */
-
-/*! \brief opaque cpu stats structure */
-struct zap_cpu_monitor_stats;
-
-/*!
- * \brief create a new cpu monitor
- * \return profile timer structure previously created with new_profile_timer, NULL on error
- */
-OZ_DECLARE(struct zap_cpu_monitor_stats*) zap_new_cpu_monitor(void);
-
-/*!
- * \brief Deletes cpu_monitor
- */
-OZ_DECLARE(void) zap_delete_cpu_monitor(struct zap_cpu_monitor_stats *p);
-
-/*!
- * \brief provides the percentage of idle system time
- * \param p cpu_stats structure previously created with zap_new_cpu_monitor
- * \param pointer to store the percentage of idle time
- * \return -1 on error 0 for success
- */
-OZ_DECLARE(zap_status_t) zap_cpu_get_system_idle_time (struct zap_cpu_monitor_stats *p, double *idle_percentage);
-
-
-
-
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/include/zap_dso.h b/libs/openzap/src/include/zap_dso.h
deleted file mode 100644
index e3519cbb46..0000000000
--- a/libs/openzap/src/include/zap_dso.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Cross Platform dso/dll load abstraction
- * Copyright(C) 2008 Michael Jerris
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so.
- *
- * This work is provided under this license on an "as is" basis, without warranty of any kind,
- * either expressed or implied, including, without limitation, warranties that the covered code
- * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
- * risk as to the quality and performance of the covered code is with you. Should any covered
- * code prove defective in any respect, you (not the initial developer or any other contributor)
- * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
- * constitutes an essential part of this license. No use of any covered code is authorized hereunder
- * except under this disclaimer.
- *
- */
-
-
-#ifndef _ZAP_DSO_H
-#define _ZAP_DSO_H
-
-typedef void (*zap_func_ptr_t) (void);
-typedef void * zap_dso_lib_t;
-
-void zap_dso_destroy(zap_dso_lib_t *lib);
-zap_dso_lib_t zap_dso_open(const char *path, char **err);
-void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err);
-
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet
- */
-
diff --git a/libs/openzap/src/include/zap_m3ua.h b/libs/openzap/src/include/zap_m3ua.h
deleted file mode 100644
index 5dfadd06d5..0000000000
--- a/libs/openzap/src/include/zap_m3ua.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * zap_m3ua.h
- * openzap
- *
- * Created by Shane Burrell on 4/3/08.
- * Copyright 2008 Shane Burrell. All rights reserved.
- *
- * Copyright (c) 2007, Anthony Minessale II, Nenad Corbic
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-//#include "m3ua_client.h"
-#include "openzap.h"
-enum e_sigboost_event_id_values
-{
- SIGBOOST_EVENT_CALL_START = 0x80, /*128*/
- SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129*/
- SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130*/
- SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131*/
- SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/
- SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/
- SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/
- SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/
- SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/
- /* Following IDs are ss7boost to sangoma_mgd only. */
- SIGBOOST_EVENT_HEARTBEAT = 0x89, /*137*/
- SIGBOOST_EVENT_INSERT_CHECK_LOOP = 0x8a, /*138*/
- SIGBOOST_EVENT_REMOVE_CHECK_LOOP = 0x8b, /*139*/
- SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE = 0x8c, /*140*/
-};
-enum e_sigboost_release_cause_values
-{
- SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0,
- SIGBOOST_RELEASE_CAUSE_NORMAL = 16,
- SIGBOOST_RELEASE_CAUSE_BUSY = 17,
- /* probable elimination */
- //SIGBOOST_RELEASE_CAUSE_BUSY = 0x91, /* 145 */
- //SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92, /* 146 */
- //SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93, /* 147 */
- //SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94, /* 148 */
-};
-
-enum e_sigboost_call_setup_ack_nack_cause_values
-{
- SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 117, /* unused Q.850 value */
- SIGBOOST_CALL_SETUP_NACK_TEST_CKT_BUSY = 118, /* unused Q.850 value */
- SIGBOOST_CALL_SETUP_NACK_INVALID_NUMBER = 28,
- /* probable elimination */
- //SIGBOOST_CALL_SETUP_RESERVED = 0x00,
- //SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
- //SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
- //SIGBOOST_CALL_SETUP_NACK_AUTO_CALL_GAP = 0x17,
-};
-typedef enum {
- M3UA_SPAN_SIGNALING_M3UA,
- M3UA_SPAN_SIGNALING_SS7BOX,
-
-} M3UA_TSpanSignaling;
-#define M3UA_SPAN_STRINGS "M3UA", "SS7BOX"
-ZAP_STR2ENUM_P(m3ua_str2span, m3ua_span2str, M3UA_TSpanSignaling)
-
-
-
-typedef enum {
- ZAP_M3UA_RUNNING = (1 << 0)
-} zap_m3uat_flag_t;
-
-/*typedef struct m3ua_data {
- m3uac_connection_t mcon;
- m3uac_connection_t pcon;
- zio_signal_cb_t signal_cb;
- uint32_t flags;
-} m3ua_data_t;
-
-*/
-/*typedef struct mu3a_link {
- ss7bc_connection_t mcon;
- ss7bc_connection_t pcon;
- zio_signal_cb_t signal_cb;
- uint32_t flags;
-} zap_m3ua_data_t;
-*/
-
-zap_status_t m3ua_init(zap_io_interface_t **zint);
-zap_status_t m3ua_destroy(void);
-zap_status_t m3ua_start(zap_span_t *span);
-
-
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h
deleted file mode 100644
index 3bd974deca..0000000000
--- a/libs/openzap/src/include/zap_threadmutex.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Cross Platform Thread/Mutex abstraction
- * Copyright(C) 2007 Michael Jerris
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so.
- *
- * This work is provided under this license on an "as is" basis, without warranty of any kind,
- * either expressed or implied, including, without limitation, warranties that the covered code
- * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
- * risk as to the quality and performance of the covered code is with you. Should any covered
- * code prove defective in any respect, you (not the initial developer or any other contributor)
- * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
- * constitutes an essential part of this license. No use of any covered code is authorized hereunder
- * except under this disclaimer.
- *
- */
-
-
-#ifndef _ZAP_THREADMUTEX_H
-#define _ZAP_THREADMUTEX_H
-
-#include "openzap.h"
-
-typedef struct zap_mutex zap_mutex_t;
-typedef struct zap_thread zap_thread_t;
-typedef void *(*zap_thread_function_t) (zap_thread_t *, void *);
-
-OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data);
-OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size);
-OZ_DECLARE(void) zap_thread_override_default_stacksize(zap_size_t size);
-OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex);
-OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex);
-OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex);
-OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex);
-OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex);
-
-OZ_DECLARE(zap_status_t) zap_interrupt_create(zap_interrupt_t **ininterrupt, zap_socket_t device);
-OZ_DECLARE(zap_status_t) zap_interrupt_wait(zap_interrupt_t *interrupt, int ms);
-OZ_DECLARE(zap_status_t) zap_interrupt_signal(zap_interrupt_t *interrupt);
-OZ_DECLARE(zap_status_t) zap_interrupt_destroy(zap_interrupt_t **ininterrupt);
-OZ_DECLARE(zap_status_t) zap_interrupt_multiple_wait(zap_interrupt_t *interrupts[], zap_size_t size, int ms);
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
-
diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h
deleted file mode 100644
index 862d0f0051..0000000000
--- a/libs/openzap/src/include/zap_types.h
+++ /dev/null
@@ -1,642 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_TYPES_H
-#define ZAP_TYPES_H
-#include "fsk.h"
-
-#ifdef WIN32
-#define ZAP_INVALID_SOCKET INVALID_HANDLE_VALUE
-#else
-#define ZAP_INVALID_SOCKET -1
-#endif
-#define zap_array_len(obj) sizeof(obj)/sizeof(obj[0])
-
-#ifdef WIN32
-#include
-typedef HANDLE zap_socket_t;
-typedef unsigned __int64 uint64_t;
-typedef unsigned __int32 uint32_t;
-typedef unsigned __int16 uint16_t;
-typedef unsigned __int8 uint8_t;
-typedef __int64 int64_t;
-typedef __int32 int32_t;
-typedef __int16 int16_t;
-typedef __int8 int8_t;
-typedef intptr_t zap_ssize_t;
-typedef int zap_filehandle_t;
-#else
-#include
-#include
-#include
-#include
-typedef int zap_socket_t;
-typedef ssize_t zap_ssize_t;
-typedef int zap_filehandle_t;
-#endif
-
-#define TAG_END NULL
-
-typedef size_t zap_size_t;
-struct zap_io_interface;
-typedef struct zap_interrupt zap_interrupt_t;
-
-#define ZAP_COMMAND_OBJ_INT *((int *)obj)
-#define ZAP_COMMAND_OBJ_CHAR_P (char *)obj
-#define ZAP_COMMAND_OBJ_FLOAT *((float *)obj)
-#define ZAP_FSK_MOD_FACTOR 0x10000
-#define ZAP_DEFAULT_DTMF_ON 250
-#define ZAP_DEFAULT_DTMF_OFF 50
-
-#define ZAP_END -1
-#define ZAP_ANY_STATE -1
-
-typedef uint64_t zap_time_t;
-
-typedef enum {
- ZAP_ENDIAN_BIG = 1,
- ZAP_ENDIAN_LITTLE = -1
-} zap_endian_t;
-
-typedef enum {
- ZAP_CID_TYPE_SDMF = 0x04,
- ZAP_CID_TYPE_MDMF = 0x80
-} zap_cid_type_t;
-
-typedef enum {
- MDMF_DATETIME = 1,
- MDMF_PHONE_NUM = 2,
- MDMF_DDN = 3,
- MDMF_NO_NUM = 4,
- MDMF_PHONE_NAME = 7,
- MDMF_NO_NAME = 8,
- MDMF_ALT_ROUTE = 9,
- MDMF_INVALID = 10
-} zap_mdmf_type_t;
-#define MDMF_STRINGS "X", "DATETIME", "PHONE_NUM", "DDN", "NO_NUM", "X", "X", "PHONE_NAME", "NO_NAME", "ALT_ROUTE", "INVALID"
-ZAP_STR2ENUM_P(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t)
-
-#define ZAP_TONEMAP_LEN 128
-typedef enum {
- ZAP_TONEMAP_NONE,
- ZAP_TONEMAP_DIAL,
- ZAP_TONEMAP_RING,
- ZAP_TONEMAP_BUSY,
- ZAP_TONEMAP_FAIL1,
- ZAP_TONEMAP_FAIL2,
- ZAP_TONEMAP_FAIL3,
- ZAP_TONEMAP_ATTN,
- ZAP_TONEMAP_CALLWAITING_CAS,
- ZAP_TONEMAP_CALLWAITING_SAS,
- ZAP_TONEMAP_CALLWAITING_ACK,
- ZAP_TONEMAP_INVALID
-} zap_tonemap_t;
-#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "FAIL1", "FAIL2", "FAIL3", "ATTN", "CALLWAITING-CAS", "CALLWAITING-SAS", "CALLWAITING-ACK", "INVALID"
-ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t)
-
-typedef enum {
- ZAP_TRUNK_E1,
- ZAP_TRUNK_T1,
- ZAP_TRUNK_J1,
- ZAP_TRUNK_BRI,
- ZAP_TRUNK_BRI_PTMP,
- ZAP_TRUNK_FXO,
- ZAP_TRUNK_FXS,
- ZAP_TRUNK_EM,
- ZAP_TRUNK_NONE
-} zap_trunk_type_t;
-#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "EM", "NONE"
-ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t)
-
-typedef enum {
- ZAP_ANALOG_START_KEWL,
- ZAP_ANALOG_START_LOOP,
- ZAP_ANALOG_START_GROUND,
- ZAP_ANALOG_START_WINK,
- ZAP_ANALOG_START_NA
-} zap_analog_start_type_t;
-#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "WINK", "NA"
-ZAP_STR2ENUM_P(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t)
-
-typedef enum {
- ZAP_OOB_DTMF,
- ZAP_OOB_ONHOOK,
- ZAP_OOB_OFFHOOK,
- ZAP_OOB_WINK,
- ZAP_OOB_FLASH,
- ZAP_OOB_RING_START,
- ZAP_OOB_RING_STOP,
- ZAP_OOB_ALARM_TRAP,
- ZAP_OOB_ALARM_CLEAR,
- ZAP_OOB_NOOP,
- ZAP_OOB_CAS_BITS_CHANGE,
- ZAP_OOB_INVALID
-} zap_oob_event_t;
-#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "NOOP", "CAS_BITS_CHANGE", "INVALID"
-ZAP_STR2ENUM_P(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t)
-
-typedef enum {
- ZAP_ALARM_NONE = 0,
- ZAP_ALARM_RECOVER = (1 << 0),
- ZAP_ALARM_LOOPBACK = (1 << 2),
- ZAP_ALARM_YELLOW = (1 << 3),
- ZAP_ALARM_RED = (1 << 4),
- ZAP_ALARM_BLUE = (1 << 5),
- ZAP_ALARM_NOTOPEN = ( 1 << 6),
- ZAP_ALARM_AIS = ( 1 << 7),
- ZAP_ALARM_RAI = ( 1 << 8),
- ZAP_ALARM_GENERAL = ( 1 << 30)
-} zap_alarm_flag_t;
-
-typedef enum {
- ZAP_SIGTYPE_NONE,
- ZAP_SIGTYPE_ISDN,
- ZAP_SIGTYPE_RBS,
- ZAP_SIGTYPE_ANALOG,
- ZAP_SIGTYPE_SANGOMABOOST,
- ZAP_SIGTYPE_M3UA,
- ZAP_SIGTYPE_R2
-} zap_signal_type_t;
-
-typedef enum {
- ZAP_SIGEVENT_START,
- ZAP_SIGEVENT_STOP,
- ZAP_SIGEVENT_TRANSFER,
- ZAP_SIGEVENT_ANSWER,
- ZAP_SIGEVENT_UP,
- ZAP_SIGEVENT_FLASH,
- ZAP_SIGEVENT_PROGRESS,
- ZAP_SIGEVENT_PROGRESS_MEDIA,
- ZAP_SIGEVENT_NOTIFY,
- ZAP_SIGEVENT_TONE_DETECTED,
- ZAP_SIGEVENT_ALARM_TRAP,
- ZAP_SIGEVENT_ALARM_CLEAR,
- ZAP_SIGEVENT_MISC,
- ZAP_SIGEVENT_COLLECTED_DIGIT,
- ZAP_SIGEVENT_ADD_CALL,
- ZAP_SIGEVENT_RESTART,
- ZAP_SIGEVENT_INVALID
-} zap_signal_event_t;
-#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \
- "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "COLLECTED_DIGIT", "ADD_CALL", "RESTART", "INVALID"
-ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t)
-
-typedef enum {
- ZAP_EVENT_NONE,
- ZAP_EVENT_DTMF,
- ZAP_EVENT_OOB,
- ZAP_EVENT_COUNT
-} zap_event_type_t;
-
-typedef enum {
- ZAP_TOP_DOWN,
- ZAP_BOTTOM_UP
-} zap_direction_t;
-
-typedef enum {
- ZAP_SUCCESS,
- ZAP_FAIL,
- ZAP_MEMERR,
- ZAP_TIMEOUT,
- ZAP_NOTIMPL,
- ZAP_CHECKSUM_ERROR,
- ZAP_STATUS_COUNT,
- ZAP_BREAK
-} zap_status_t;
-
-typedef enum {
- ZAP_NO_FLAGS = 0,
- ZAP_READ = (1 << 0),
- ZAP_WRITE = (1 << 1),
- ZAP_EVENTS = (1 << 2)
-} zap_wait_flag_t;
-
-typedef enum {
- ZAP_CODEC_ULAW = 0,
- ZAP_CODEC_ALAW = 8,
- ZAP_CODEC_SLIN = 10,
- ZAP_CODEC_NONE = (1 << 30)
-} zap_codec_t;
-
-typedef enum {
- ZAP_TONE_DTMF = (1 << 0)
-} zap_tone_type_t;
-
-typedef enum {
- ZAP_COMMAND_NOOP,
- ZAP_COMMAND_SET_INTERVAL,
- ZAP_COMMAND_GET_INTERVAL,
- ZAP_COMMAND_SET_CODEC,
- ZAP_COMMAND_GET_CODEC,
- ZAP_COMMAND_SET_NATIVE_CODEC,
- ZAP_COMMAND_GET_NATIVE_CODEC,
- ZAP_COMMAND_ENABLE_DTMF_DETECT,
- ZAP_COMMAND_DISABLE_DTMF_DETECT,
- ZAP_COMMAND_SEND_DTMF,
- ZAP_COMMAND_SET_DTMF_ON_PERIOD,
- ZAP_COMMAND_GET_DTMF_ON_PERIOD,
- ZAP_COMMAND_SET_DTMF_OFF_PERIOD,
- ZAP_COMMAND_GET_DTMF_OFF_PERIOD,
- ZAP_COMMAND_GENERATE_RING_ON,
- ZAP_COMMAND_GENERATE_RING_OFF,
- ZAP_COMMAND_OFFHOOK,
- ZAP_COMMAND_ONHOOK,
- ZAP_COMMAND_FLASH,
- ZAP_COMMAND_WINK,
- ZAP_COMMAND_ENABLE_PROGRESS_DETECT,
- ZAP_COMMAND_DISABLE_PROGRESS_DETECT,
- ZAP_COMMAND_TRACE_INPUT,
- ZAP_COMMAND_TRACE_OUTPUT,
- ZAP_COMMAND_TRACE_END_ALL,
- ZAP_COMMAND_ENABLE_CALLERID_DETECT,
- ZAP_COMMAND_DISABLE_CALLERID_DETECT,
- ZAP_COMMAND_ENABLE_ECHOCANCEL,
- ZAP_COMMAND_DISABLE_ECHOCANCEL,
- ZAP_COMMAND_ENABLE_ECHOTRAIN,
- ZAP_COMMAND_DISABLE_ECHOTRAIN,
- ZAP_COMMAND_SET_CAS_BITS,
- ZAP_COMMAND_GET_CAS_BITS,
- ZAP_COMMAND_SET_RX_GAIN,
- ZAP_COMMAND_GET_RX_GAIN,
- ZAP_COMMAND_SET_TX_GAIN,
- ZAP_COMMAND_GET_TX_GAIN,
- ZAP_COMMAND_FLUSH_TX_BUFFERS,
- ZAP_COMMAND_FLUSH_RX_BUFFERS,
- ZAP_COMMAND_FLUSH_BUFFERS,
- ZAP_COMMAND_SET_PRE_BUFFER_SIZE,
- ZAP_COMMAND_ENABLE_LOOP,
- ZAP_COMMAND_DISABLE_LOOP,
- ZAP_COMMAND_COUNT
-} zap_command_t;
-
-typedef enum {
- ZAP_SPAN_CONFIGURED = (1 << 0),
- ZAP_SPAN_READY = (1 << 1),
- ZAP_SPAN_STATE_CHANGE = (1 << 2),
- ZAP_SPAN_SUSPENDED = (1 << 3),
- ZAP_SPAN_IN_THREAD = (1 << 4),
- ZAP_SPAN_STOP_THREAD = (1 << 5)
-} zap_span_flag_t;
-
-typedef enum {
- ZAP_CHAN_TYPE_B,
- ZAP_CHAN_TYPE_DQ921,
- ZAP_CHAN_TYPE_DQ931,
- ZAP_CHAN_TYPE_FXS,
- ZAP_CHAN_TYPE_FXO,
- ZAP_CHAN_TYPE_EM,
- ZAP_CHAN_TYPE_CAS,
- ZAP_CHAN_TYPE_COUNT
-} zap_chan_type_t;
-
-#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID"
-ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t)
-
-#define ZAP_IS_VOICE_CHANNEL(zap_chan) ((zap_chan)->type != ZAP_CHAN_TYPE_DQ921 && (zap_chan)->type != ZAP_CHAN_TYPE_DQ931)
-
-typedef enum {
- ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0),
- ZAP_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1),
- ZAP_CHANNEL_FEATURE_CODECS = (1 << 2),
- ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 3),
- ZAP_CHANNEL_FEATURE_CALLERID = (1 << 4),
- ZAP_CHANNEL_FEATURE_PROGRESS = (1 << 5),
- ZAP_CHANNEL_FEATURE_CALLWAITING = (1 << 6)
-} zap_channel_feature_t;
-
-typedef enum {
- ZAP_CHANNEL_STATE_DOWN,
- ZAP_CHANNEL_STATE_HOLD,
- ZAP_CHANNEL_STATE_SUSPENDED,
- ZAP_CHANNEL_STATE_DIALTONE,
- ZAP_CHANNEL_STATE_COLLECT,
- ZAP_CHANNEL_STATE_RING,
- ZAP_CHANNEL_STATE_BUSY,
- ZAP_CHANNEL_STATE_ATTN,
- ZAP_CHANNEL_STATE_GENRING,
- ZAP_CHANNEL_STATE_DIALING,
- ZAP_CHANNEL_STATE_GET_CALLERID,
- ZAP_CHANNEL_STATE_CALLWAITING,
- ZAP_CHANNEL_STATE_RESTART,
- ZAP_CHANNEL_STATE_PROGRESS,
- ZAP_CHANNEL_STATE_PROGRESS_MEDIA,
- ZAP_CHANNEL_STATE_UP,
- ZAP_CHANNEL_STATE_IDLE,
- ZAP_CHANNEL_STATE_TERMINATING,
- ZAP_CHANNEL_STATE_CANCEL,
- ZAP_CHANNEL_STATE_HANGUP,
- ZAP_CHANNEL_STATE_HANGUP_COMPLETE,
- ZAP_CHANNEL_STATE_IN_LOOP,
- ZAP_CHANNEL_STATE_INVALID
-} zap_channel_state_t;
-#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \
- "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \
- "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", \
- "HANGUP", "HANGUP_COMPLETE", "IN_LOOP", "INVALID"
-ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t)
-
-typedef enum {
- ZAP_CHANNEL_CONFIGURED = (1 << 0),
- ZAP_CHANNEL_READY = (1 << 1),
- ZAP_CHANNEL_OPEN = (1 << 2),
- ZAP_CHANNEL_DTMF_DETECT = (1 << 3),
- ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4),
- ZAP_CHANNEL_TRANSCODE = (1 << 5),
- ZAP_CHANNEL_BUFFER = (1 << 6),
- ZAP_CHANNEL_EVENT = (1 << 7),
- ZAP_CHANNEL_INTHREAD = (1 << 8),
- ZAP_CHANNEL_WINK = (1 << 9),
- ZAP_CHANNEL_FLASH = (1 << 10),
- ZAP_CHANNEL_STATE_CHANGE = (1 << 11),
- ZAP_CHANNEL_HOLD = (1 << 12),
- ZAP_CHANNEL_INUSE = (1 << 13),
- ZAP_CHANNEL_OFFHOOK = (1 << 14),
- ZAP_CHANNEL_RINGING = (1 << 15),
- ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16),
- ZAP_CHANNEL_CALLERID_DETECT = (1 << 17),
- ZAP_CHANNEL_OUTBOUND = (1 << 18),
- ZAP_CHANNEL_SUSPENDED = (1 << 19),
- ZAP_CHANNEL_3WAY = (1 << 20),
- ZAP_CHANNEL_PROGRESS = (1 << 21),
- ZAP_CHANNEL_MEDIA = (1 << 22),
- ZAP_CHANNEL_ANSWERED = (1 << 23),
- ZAP_CHANNEL_MUTE = (1 << 24),
- ZAP_CHANNEL_USE_RX_GAIN = (1 << 25),
- ZAP_CHANNEL_USE_TX_GAIN = (1 << 26),
-} zap_channel_flag_t;
-
-typedef enum {
- ZSM_NONE,
- ZSM_UNACCEPTABLE,
- ZSM_ACCEPTABLE
-} zap_state_map_type_t;
-
-typedef enum {
- ZSD_INBOUND,
- ZSD_OUTBOUND,
-} zap_state_direction_t;
-
-#define ZAP_MAP_NODE_SIZE 512
-#define ZAP_MAP_MAX ZAP_CHANNEL_STATE_INVALID+2
-
-struct zap_state_map_node {
- zap_state_direction_t direction;
- zap_state_map_type_t type;
- zap_channel_state_t check_states[ZAP_MAP_MAX];
- zap_channel_state_t states[ZAP_MAP_MAX];
-};
-typedef struct zap_state_map_node zap_state_map_node_t;
-
-struct zap_state_map {
- zap_state_map_node_t nodes[ZAP_MAP_NODE_SIZE];
-};
-typedef struct zap_state_map zap_state_map_t;
-
-typedef struct zap_channel zap_channel_t;
-typedef struct zap_event zap_event_t;
-typedef struct zap_sigmsg zap_sigmsg_t;
-typedef struct zap_span zap_span_t;
-typedef struct zap_caller_data zap_caller_data_t;
-typedef struct zap_io_interface zap_io_interface_t;
-
-struct zap_stream_handle;
-typedef struct zap_stream_handle zap_stream_handle_t;
-
-typedef zap_status_t (*zap_stream_handle_raw_write_function_t) (zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen);
-typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t *handle, const char *fmt, ...);
-
-#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, uint32_t chan_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan)
-#define ZIO_CHANNEL_OUTGOING_CALL_ARGS (zap_channel_t *zchan)
-#define ZIO_SPAN_POLL_EVENT_ARGS (zap_span_t *span, uint32_t ms)
-#define ZIO_SPAN_NEXT_EVENT_ARGS (zap_span_t *span, zap_event_t **event)
-#define ZIO_SIGNAL_CB_ARGS (zap_sigmsg_t *sigmsg)
-#define ZIO_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event)
-#define ZIO_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen)
-#define ZIO_CONFIGURE_SPAN_ARGS (zap_span_t *span, const char *str, zap_chan_type_t type, char *name, char *number)
-#define ZIO_CONFIGURE_ARGS (const char *category, const char *var, const char *val, int lineno)
-#define ZIO_OPEN_ARGS (zap_channel_t *zchan)
-#define ZIO_CLOSE_ARGS (zap_channel_t *zchan)
-#define ZIO_CHANNEL_DESTROY_ARGS (zap_channel_t *zchan)
-#define ZIO_SPAN_DESTROY_ARGS (zap_span_t *span)
-#define ZIO_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj)
-#define ZIO_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to)
-#define ZIO_GET_ALARMS_ARGS (zap_channel_t *zchan)
-#define ZIO_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
-#define ZIO_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
-#define ZIO_IO_LOAD_ARGS (zap_io_interface_t **zio)
-#define ZIO_IO_UNLOAD_ARGS (void)
-#define ZIO_SIG_LOAD_ARGS (void)
-#define ZIO_SIG_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap)
-#define ZIO_SIG_UNLOAD_ARGS (void)
-#define ZIO_API_ARGS (zap_stream_handle_t *stream, const char *data)
-
-typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ;
-typedef zap_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ;
-typedef zap_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ;
-typedef zap_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ;
-typedef zap_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ;
-typedef zap_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ;
-typedef zap_status_t (*zio_codec_t) ZIO_CODEC_ARGS ;
-typedef zap_status_t (*zio_configure_span_t) ZIO_CONFIGURE_SPAN_ARGS ;
-typedef zap_status_t (*zio_configure_t) ZIO_CONFIGURE_ARGS ;
-typedef zap_status_t (*zio_open_t) ZIO_OPEN_ARGS ;
-typedef zap_status_t (*zio_close_t) ZIO_CLOSE_ARGS ;
-typedef zap_status_t (*zio_channel_destroy_t) ZIO_CHANNEL_DESTROY_ARGS ;
-typedef zap_status_t (*zio_span_destroy_t) ZIO_SPAN_DESTROY_ARGS ;
-typedef zap_status_t (*zio_get_alarms_t) ZIO_GET_ALARMS_ARGS ;
-typedef zap_status_t (*zio_command_t) ZIO_COMMAND_ARGS ;
-typedef zap_status_t (*zio_wait_t) ZIO_WAIT_ARGS ;
-typedef zap_status_t (*zio_read_t) ZIO_READ_ARGS ;
-typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ;
-typedef zap_status_t (*zio_io_load_t) ZIO_IO_LOAD_ARGS ;
-typedef zap_status_t (*zio_sig_load_t) ZIO_SIG_LOAD_ARGS ;
-typedef zap_status_t (*zio_sig_configure_t) ZIO_SIG_CONFIGURE_ARGS ;
-typedef zap_status_t (*zio_io_unload_t) ZIO_IO_UNLOAD_ARGS ;
-typedef zap_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_ARGS ;
-typedef zap_status_t (*zio_api_t) ZIO_API_ARGS ;
-
-
-#define ZIO_CHANNEL_REQUEST_FUNCTION(name) zap_status_t name ZIO_CHANNEL_REQUEST_ARGS
-#define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) zap_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS
-#define ZIO_SPAN_POLL_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_POLL_EVENT_ARGS
-#define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_NEXT_EVENT_ARGS
-#define ZIO_SIGNAL_CB_FUNCTION(name) zap_status_t name ZIO_SIGNAL_CB_ARGS
-#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS
-#define ZIO_CODEC_FUNCTION(name) OZ_DECLARE_NONSTD(zap_status_t) name ZIO_CODEC_ARGS
-#define ZIO_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_SPAN_ARGS
-#define ZIO_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_ARGS
-#define ZIO_OPEN_FUNCTION(name) zap_status_t name ZIO_OPEN_ARGS
-#define ZIO_CLOSE_FUNCTION(name) zap_status_t name ZIO_CLOSE_ARGS
-#define ZIO_CHANNEL_DESTROY_FUNCTION(name) zap_status_t name ZIO_CHANNEL_DESTROY_ARGS
-#define ZIO_SPAN_DESTROY_FUNCTION(name) zap_status_t name ZIO_SPAN_DESTROY_ARGS
-#define ZIO_GET_ALARMS_FUNCTION(name) zap_status_t name ZIO_GET_ALARMS_ARGS
-#define ZIO_COMMAND_FUNCTION(name) zap_status_t name ZIO_COMMAND_ARGS
-#define ZIO_WAIT_FUNCTION(name) zap_status_t name ZIO_WAIT_ARGS
-#define ZIO_READ_FUNCTION(name) zap_status_t name ZIO_READ_ARGS
-#define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS
-#define ZIO_IO_LOAD_FUNCTION(name) zap_status_t name ZIO_IO_LOAD_ARGS
-#define ZIO_SIG_LOAD_FUNCTION(name) zap_status_t name ZIO_SIG_LOAD_ARGS
-#define ZIO_SIG_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_SIG_CONFIGURE_ARGS
-#define ZIO_IO_UNLOAD_FUNCTION(name) zap_status_t name ZIO_IO_UNLOAD_ARGS
-#define ZIO_SIG_UNLOAD_FUNCTION(name) zap_status_t name ZIO_SIG_UNLOAD_ARGS
-#define ZIO_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS
-
-#include "zap_dso.h"
-
-
-
-typedef struct {
- char name[256];
- zio_io_load_t io_load;
- zio_io_unload_t io_unload;
- zio_sig_load_t sig_load;
- zio_sig_configure_t sig_configure;
- zio_sig_unload_t sig_unload;
- zap_dso_lib_t lib;
- char path[256];
-} zap_module_t;
-
-#ifndef __FUNCTION__
-#define __FUNCTION__ (const char *)__func__
-#endif
-
-#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__
-#define ZAP_LOG_LEVEL_DEBUG 7
-#define ZAP_LOG_LEVEL_INFO 6
-#define ZAP_LOG_LEVEL_NOTICE 5
-#define ZAP_LOG_LEVEL_WARNING 4
-#define ZAP_LOG_LEVEL_ERROR 3
-#define ZAP_LOG_LEVEL_CRIT 2
-#define ZAP_LOG_LEVEL_ALERT 1
-#define ZAP_LOG_LEVEL_EMERG 0
-
-#define ZAP_LOG_DEBUG ZAP_PRE, ZAP_LOG_LEVEL_DEBUG
-#define ZAP_LOG_INFO ZAP_PRE, ZAP_LOG_LEVEL_INFO
-#define ZAP_LOG_NOTICE ZAP_PRE, ZAP_LOG_LEVEL_NOTICE
-#define ZAP_LOG_WARNING ZAP_PRE, ZAP_LOG_LEVEL_WARNING
-#define ZAP_LOG_ERROR ZAP_PRE, ZAP_LOG_LEVEL_ERROR
-#define ZAP_LOG_CRIT ZAP_PRE, ZAP_LOG_LEVEL_CRIT
-#define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT
-#define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG
-
-typedef struct zap_fsk_data_state zap_fsk_data_state_t;
-typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state);
-typedef zap_status_t (*zap_fsk_write_sample_t)(int16_t *buf, zap_size_t buflen, void *user_data);
-typedef void (*zap_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...);
-typedef struct hashtable zap_hash_t;
-typedef struct hashtable_iterator zap_hash_iterator_t;
-typedef struct key zap_hash_key_t;
-typedef struct value zap_hash_val_t;
-typedef struct zap_bitstream zap_bitstream_t;
-typedef struct zap_fsk_modulator zap_fsk_modulator_t;
-typedef zap_status_t (*zap_span_start_t)(zap_span_t *span);
-typedef zap_status_t (*zap_span_stop_t)(zap_span_t *span);
-
-typedef enum {
- ZAP_CAUSE_NONE = 0,
- ZAP_CAUSE_UNALLOCATED = 1,
- ZAP_CAUSE_NO_ROUTE_TRANSIT_NET = 2,
- ZAP_CAUSE_NO_ROUTE_DESTINATION = 3,
- ZAP_CAUSE_CHANNEL_UNACCEPTABLE = 6,
- ZAP_CAUSE_CALL_AWARDED_DELIVERED = 7,
- ZAP_CAUSE_NORMAL_CLEARING = 16,
- ZAP_CAUSE_USER_BUSY = 17,
- ZAP_CAUSE_NO_USER_RESPONSE = 18,
- ZAP_CAUSE_NO_ANSWER = 19,
- ZAP_CAUSE_SUBSCRIBER_ABSENT = 20,
- ZAP_CAUSE_CALL_REJECTED = 21,
- ZAP_CAUSE_NUMBER_CHANGED = 22,
- ZAP_CAUSE_REDIRECTION_TO_NEW_DESTINATION = 23,
- ZAP_CAUSE_EXCHANGE_ROUTING_ERROR = 25,
- ZAP_CAUSE_DESTINATION_OUT_OF_ORDER = 27,
- ZAP_CAUSE_INVALID_NUMBER_FORMAT = 28,
- ZAP_CAUSE_FACILITY_REJECTED = 29,
- ZAP_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30,
- ZAP_CAUSE_NORMAL_UNSPECIFIED = 31,
- ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34,
- ZAP_CAUSE_NETWORK_OUT_OF_ORDER = 38,
- ZAP_CAUSE_NORMAL_TEMPORARY_FAILURE = 41,
- ZAP_CAUSE_SWITCH_CONGESTION = 42,
- ZAP_CAUSE_ACCESS_INFO_DISCARDED = 43,
- ZAP_CAUSE_REQUESTED_CHAN_UNAVAIL = 44,
- ZAP_CAUSE_PRE_EMPTED = 45,
- ZAP_CAUSE_FACILITY_NOT_SUBSCRIBED = 50,
- ZAP_CAUSE_OUTGOING_CALL_BARRED = 52,
- ZAP_CAUSE_INCOMING_CALL_BARRED = 54,
- ZAP_CAUSE_BEARERCAPABILITY_NOTAUTH = 57,
- ZAP_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58,
- ZAP_CAUSE_SERVICE_UNAVAILABLE = 63,
- ZAP_CAUSE_BEARERCAPABILITY_NOTIMPL = 65,
- ZAP_CAUSE_CHAN_NOT_IMPLEMENTED = 66,
- ZAP_CAUSE_FACILITY_NOT_IMPLEMENTED = 69,
- ZAP_CAUSE_SERVICE_NOT_IMPLEMENTED = 79,
- ZAP_CAUSE_INVALID_CALL_REFERENCE = 81,
- ZAP_CAUSE_INCOMPATIBLE_DESTINATION = 88,
- ZAP_CAUSE_INVALID_MSG_UNSPECIFIED = 95,
- ZAP_CAUSE_MANDATORY_IE_MISSING = 96,
- ZAP_CAUSE_MESSAGE_TYPE_NONEXIST = 97,
- ZAP_CAUSE_WRONG_MESSAGE = 98,
- ZAP_CAUSE_IE_NONEXIST = 99,
- ZAP_CAUSE_INVALID_IE_CONTENTS = 100,
- ZAP_CAUSE_WRONG_CALL_STATE = 101,
- ZAP_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102,
- ZAP_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103,
- ZAP_CAUSE_PROTOCOL_ERROR = 111,
- ZAP_CAUSE_INTERWORKING = 127,
- ZAP_CAUSE_SUCCESS = 142,
- ZAP_CAUSE_ORIGINATOR_CANCEL = 487,
- ZAP_CAUSE_CRASH = 500,
- ZAP_CAUSE_SYSTEM_SHUTDOWN = 501,
- ZAP_CAUSE_LOSE_RACE = 502,
- ZAP_CAUSE_MANAGER_REQUEST = 503,
- ZAP_CAUSE_BLIND_TRANSFER = 600,
- ZAP_CAUSE_ATTENDED_TRANSFER = 601,
- ZAP_CAUSE_ALLOTTED_TIMEOUT = 602,
- ZAP_CAUSE_USER_CHALLENGE = 603,
- ZAP_CAUSE_MEDIA_TIMEOUT = 604
-} zap_call_cause_t;
-
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
-
diff --git a/libs/openzap/src/isdn/5ESSStateNT.c b/libs/openzap/src/isdn/5ESSStateNT.c
deleted file mode 100644
index 1eb9415422..0000000000
--- a/libs/openzap/src/isdn/5ESSStateNT.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*****************************************************************************
-
- FileName: 5ESSStateNT.c
-
- Contents: AT&T 5ESS ISDN State Engine for NT (Network Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Copyright (c) 2007, Michael S. Collins, All rights reserved.
- email:mcollins@fcnetwork.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "5ESS.h"
-
-/*****************************************************************************
- Function: ATT5ESSCreateNT
-
- Description: Will create the AT&T 5ESS ISDN NT as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void ATT5ESSCreateNT(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingNT, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingNT, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, Q931ProcConnectNT, Q931Umes_Connect, Q931Pmes_Connect);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, Q931ProcConnectAckNT, Q931Umes_ConnectAck, Q931Pmes_ConnectAck);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressNT, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupNT, Q931Umes_Setup, Q931Pmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckNT, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeNT, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckNT, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectNT, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendNT, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckNT, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectNT, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationNT, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectNT, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseNT, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteNT, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartNT, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckNT, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationNT, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyNT, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusNT, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryNT, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentNT, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityNT, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldNT, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckNT, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectNT, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterNT, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveNT, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckNT, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectNT, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
- Q931SetIEProc(Q931ie_GENERIC_DIGITS, i, Q931Pie_GenericDigits, Q931Uie_GenericDigits);
-
- Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_FACILITY, i, Q931Pie_Generic, Q931Uie_Generic);
-
- /* The following define a state machine. The point is that the Message */
- /* procs can when search this to find out if the message/state */
- /* combination is legale. If not, the proc for unexpected message apply.*/
-
- /* TODO define state table here */
-}
diff --git a/libs/openzap/src/isdn/5ESSStateTE.c b/libs/openzap/src/isdn/5ESSStateTE.c
deleted file mode 100644
index e2ededd9ac..0000000000
--- a/libs/openzap/src/isdn/5ESSStateTE.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/*****************************************************************************
-
- FileName: 5ESSStateTE.c
-
- Contents: AT&T 5ESS ISDN State Engine for TE (User Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- This reference implementation uses a process per message,
- meaning that each message must check call states. This
- is easier for dialect maintenance as each message proc
- can be replaced individually. A new TE variant only
- need to copy the Q931CreateTE and replace those procs or
- need to override.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Copyright (c) 2007, Michael S. Collins, All rights reserved.
- email:mcollins@fcnetwork.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "5ESS.h"
-extern L3INT Q931L4HeaderSpace;
-
-/*****************************************************************************
- Function: ATT5ESSCreateTE
-
- Description: Will create the AT&T 5ESS TE as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void ATT5ESSCreateTE(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingTE, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingTE, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, ATT5ESSProc0x07TE, ATT5ESSUmes_0x07, ATT5ESSPmes_0x07);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, ATT5ESSProc0x0fTE, ATT5ESSUmes_0x0f, ATT5ESSPmes_0x0f);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressTE, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupTE, ATT5ESSUmes_Setup, ATT5ESSPmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckTE, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeTE, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckTE, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectTE, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendTE, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckTE, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectTE, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationTE, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectTE, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseTE, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteTE, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartTE, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckTE, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationTE, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyTE, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusTE, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryTE, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentTE, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityTE, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldTE, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckTE, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectTE, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterTE, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveTE, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckTE, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectTE, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANGE_STATUS, i, Q931Pie_ChangeStatus, Q931Uie_ChangeStatus);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
- Q931SetIEProc(Q931ie_GENERIC_DIGITS, i, Q931Pie_GenericDigits, Q931Uie_GenericDigits);
-
- Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_FACILITY, i, Q931Pie_Generic, Q931Uie_Generic);
-
- /* The following define a state machine. The point is that the Message */
- /* procs can when search this to find out if the message/state */
- /* combination is legale. If not, the proc for unexpected message apply.*/
-
- /* State 0 Idle */
- Q931AddStateEntry(i, Q931_U0, Q931mes_RESUME, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_STATUS, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE_COMPLETE, 4);
-
- /* State 1 Call Initiating */
- Q931AddStateEntry(i, Q931_U1, Q931mes_DISCONNECT, 2);
- Q931AddStateEntry(i, Q931_U1, Q931mes_SETUP_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_RELEASE_COMPLETE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CONNECT, 4);
-
- /* State 2 Overlap Sending */
- Q931AddStateEntry(i, Q931_U2, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_RELEASE, 2);
-
- /* State 3 Outgoing Call Proceeding */
- Q931AddStateEntry(i, Q931_U3, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_RELEASE, 2);
-
- /* State 4 Call Delivered */
- Q931AddStateEntry(i, Q931_U4, Q931mes_CONNECT, 4);
-
- /* State 6 Call Precent */
- Q931AddStateEntry(i, Q931_U6, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CALL_PROCEEDING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE_COMPLETE, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U6, Q931mes_DISCONNECT, 4);
-
- /* State 7 Call Received */
- Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2);
-
- /* State 8 Connect request */
- Q931AddStateEntry(i, Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4);
-
- /* State 9 Incoming Call Proceeding */
- Q931AddStateEntry(i, Q931_U9, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_PROGRESS, 2);
-
- /* State 10 Active */
- Q931AddStateEntry(i, Q931_U10, Q931mes_SUSPEND, 2);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 4);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 2);
-
- /* State 11 Disconnect Request */
- Q931AddStateEntry(i, Q931_U11, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_NOTIFY, 4);
-
- /* State 12 Disconnect Ind */
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 2);
-
- /* State 15 Suspend Request */
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_REJECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_RELEASE, 4);
-
-/* TODO
- Q931AddStateEntry(i, Q931_U17,
- Q931AddStateEntry(i, Q931_U19,
- Q931AddStateEntry(i, Q931_U25,
-*/
-}
-
-/*****************************************************************************
-
- Function: ATT5ESSProc0x0fTE
-
-*****************************************************************************/
-L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (pMes->ProtDisc == 8) {
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- }
- if (iFrom == 4) {
- /* TODO Add proc here*/
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom ==2) {
- /* TODO Add proc here*/
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
-
- if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) {
- printf("autoServiceAck is on, responding to Service Req from network...\n");
- Q931AckService(pTrunk, buf);
- }
- }
- return ret;
-
-}
-
-/*****************************************************************************
-
- Function: ATT5ESSProc0x07TE
-
-*****************************************************************************/
-L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (pMes->ProtDisc == 8) {
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- }
- if (iFrom == 4) {
- /* TODO Add proc here*/
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here*/
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-
-}
diff --git a/libs/openzap/src/isdn/5ESSmes.c b/libs/openzap/src/isdn/5ESSmes.c
deleted file mode 100644
index 7cdd21e7cc..0000000000
--- a/libs/openzap/src/isdn/5ESSmes.c
+++ /dev/null
@@ -1,361 +0,0 @@
-/*****************************************************************************
-
- FileName: 5ESSmes.c
-
- Contents: Pack/Unpack functions. These functions will unpack a 5ESS ISDN
- message from the bit packed original format into structs
- that contains variables sized by the user. It will also pack
- the struct back into a Q.931 message as required.
-
- See 5ESS.h for description.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Copyright (c) 2007, Michael S. Collins, All rights reserved.
- email:mcollins@fcnetwork.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-*****************************************************************************/
-
-#include "5ESS.h"
-
-/*****************************************************************************
-
- Function: ATT5ESSUmes_Setup
-
-*****************************************************************************/
-L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT ir = 0;
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
- L3UCHAR last_codeset = 0, codeset = 0;
- L3UCHAR shift_nolock = 1;
-
- while (IOff < Size) {
-
- if (shift_nolock) {
- codeset = last_codeset;
- }
-
- if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT) {
- shift_nolock = (IBuf[IOff] & 0x08);
- if (shift_nolock) {
- last_codeset = codeset;
- }
- codeset = ((IBuf[IOff] & 0x07));
- IOff++;
- }
-
- if (codeset == 0) {
- switch (IBuf[IOff])
- {
- case Q931ie_SENDING_COMPLETE:
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_NETWORK_SPECIFIC_FACILITIES:
- case Q931ie_DISPLAY:
- case Q931ie_DATETIME:
- case Q931ie_KEYPAD_FACILITY:
- case Q931ie_SIGNAL:
- case Q931ie_CALLING_PARTY_NUMBER:
- case Q931ie_CALLING_PARTY_SUBADDRESS:
- case Q931ie_CALLED_PARTY_NUMBER:
- case Q931ie_CALLED_PARTY_SUBADDRESS:
- case Q931ie_TRANSIT_NETWORK_SELECTION:
- case Q931ie_LOW_LAYER_COMPATIBILITY:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- case Q931ie_FACILITY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- case Q931ie_REPEAT_INDICATOR:
- if (ir < 2) {
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- ir++;
- } else {
- return Q931E_ILLEGAL_IE;
- }
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- } else if (codeset == 6) {
- switch (IBuf[IOff])
- {
- case Q931ie_GENERIC_DIGITS:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- } else if (codeset == 7) {
- switch (IBuf[IOff])
- {
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- } else {
- return Q931E_ILLEGAL_IE;
- }
- }
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: ATT5ESSPmes_Setup
-
- Decription: Pack a Q931mes_Generic into a real Q.931 message. The user will
- set up a SETUP message and issue this to the stack where it
- is processed by Q931ProcSetup that processes and validates
- it before it actually sends it out. This function is called
- to compute the real Q.931 message.
-
- Parameters: IBuf[IN] Ptr to un-packed struct
- ISize[IN] Size of input buffer (unpacked message).
- OBuf[OUT] Ptr to packed 'octet' wise message.
- OSize[OUT] Size of packed message.
-
- Called By: Q931ProcSetup
-
-*****************************************************************************/
-L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3INT rc = Q931E_NO_ERROR;
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Sending Complete */
- if (Q931IsIEPresent(pMes->SendComplete)) {
- OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff);
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->RepeatInd)) {
- OBuf[Octet++] = (L3UCHAR)(pMes->RepeatInd & 0x00ff);
- }
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- } else {
- rc = Q931E_BEARERCAP;
- }
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Network specific facilities */
- if (Q931IsIEPresent(pMes->NetFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_NETWORK_SPECIFIC_FACILITIES](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Date/Time */
- if (Q931IsIEPresent(pMes->DateTime)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Keypad Facility */
- if (Q931IsIEPresent(pMes->KeypadFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Calling Party Number */
- if (Q931IsIEPresent(pMes->CallingNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Calling Party Subaddress */
- if (Q931IsIEPresent(pMes->CallingSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Called Party number */
- if (Q931IsIEPresent(pMes->CalledNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Called party subaddress */
- if (Q931IsIEPresent(pMes->CalledSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Transit network selection */
- if (Q931IsIEPresent(pMes->TransNetSel)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->LLRepeatInd)) {
- rc = Q931E_UNKNOWN_IE;/* TODO */
- }
-
- /* Low Layer Compatibility */
- if (Q931IsIEPresent(pMes->LLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-
-/*****************************************************************************
-
- Function: ATT5ESSUmes_0x0f
-
-*****************************************************************************/
-L3INT ATT5ESSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- if (mes->ProtDisc == 8) {
- return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: ATT5ESSPmes_0x0f
-
-*****************************************************************************/
-L3INT ATT5ESSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;
-
- if (mes->ProtDisc == 8) {
- return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: ATT5ESSUmes_0x07
-
-*****************************************************************************/
-L3INT ATT5ESSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- if (mes->ProtDisc == 8) {
- return Q931Umes_Connect(pTrunk, IBuf, mes, IOff, Size);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: ATT5ESSPmes_0x07
-
-*****************************************************************************/
-L3INT ATT5ESSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;
-
- if (mes->ProtDisc == 8) {
- return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
diff --git a/libs/openzap/src/isdn/DMSStateNT.c b/libs/openzap/src/isdn/DMSStateNT.c
deleted file mode 100644
index e8814ba8ef..0000000000
--- a/libs/openzap/src/isdn/DMSStateNT.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*****************************************************************************
-
- FileName: DMSStateNT.c
-
- Contents: DMS-100 ISDN State Engine for NT (Network Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "DMS.h"
-
-/*****************************************************************************
- Function: DMSCreateNT
-
- Description: Will create the National ISDN NT as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void DMSCreateNT(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingNT, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingNT, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, Q931ProcConnectNT, Q931Umes_Connect, Q931Pmes_Connect);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, Q931ProcConnectAckNT, Q931Umes_ConnectAck, Q931Pmes_ConnectAck);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressNT, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupNT, DMSUmes_Setup, DMSPmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckNT, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeNT, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckNT, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectNT, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendNT, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckNT, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectNT, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationNT, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectNT, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseNT, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteNT, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartNT, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckNT, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationNT, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyNT, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusNT, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryNT, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentNT, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityNT, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldNT, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckNT, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectNT, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterNT, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveNT, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckNT, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectNT, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
- Q931SetIEProc(Q931ie_GENERIC_DIGITS, i, Q931Pie_GenericDigits, Q931Uie_GenericDigits);
-
- /* The following define a state machine. The point is that the Message */
- /* procs can when search this to find out if the message/state */
- /* combination is legale. If not, the proc for unexpected message apply.*/
-
- /* TODO define state table here */
-}
diff --git a/libs/openzap/src/isdn/DMSStateTE.c b/libs/openzap/src/isdn/DMSStateTE.c
deleted file mode 100644
index cb740d3c2f..0000000000
--- a/libs/openzap/src/isdn/DMSStateTE.c
+++ /dev/null
@@ -1,284 +0,0 @@
-/*****************************************************************************
-
- FileName: DMSStateTE.c
-
- Contents: DMS-100 ISDN State Engine for TE (User Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- This reference implementation uses a process per message,
- meaning that each message must check call states. This
- is easier for dialect maintenance as each message proc
- can be replaced individually. A new TE variant only
- need to copy the Q931CreateTE and replace those procs or
- need to override.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "DMS.h"
-extern L3INT Q931L4HeaderSpace;
-
-/*****************************************************************************
- Function: DMSCreateTE
-
- Description: Will create the National TE as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void DMSCreateTE(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingTE, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingTE, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, DMSProc0x07TE, DMSUmes_0x07, DMSPmes_0x07);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, DMSProc0x0fTE, DMSUmes_0x0f, DMSPmes_0x0f);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressTE, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupTE, DMSUmes_Setup, DMSPmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckTE, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeTE, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckTE, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectTE, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendTE, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckTE, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectTE, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationTE, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectTE, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseTE, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteTE, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartTE, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckTE, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationTE, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyTE, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusTE, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryTE, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentTE, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityTE, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldTE, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckTE, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectTE, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterTE, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveTE, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckTE, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectTE, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANGE_STATUS, i, Q931Pie_ChangeStatus, Q931Uie_ChangeStatus);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
- Q931SetIEProc(Q931ie_GENERIC_DIGITS, i, Q931Pie_GenericDigits, Q931Uie_GenericDigits);
-
- /* The following define a state machine. The point is that the Message */
- /* procs can when search this to find out if the message/state */
- /* combination is legale. If not, the proc for unexpected message apply.*/
-
- /* State 0 Idle */
- Q931AddStateEntry(i, Q931_U0, Q931mes_RESUME, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_STATUS, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE_COMPLETE, 4);
-
- /* State 1 Call Initiating */
- Q931AddStateEntry(i, Q931_U1, Q931mes_DISCONNECT, 2);
- Q931AddStateEntry(i, Q931_U1, Q931mes_SETUP_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_RELEASE_COMPLETE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CONNECT, 4);
-
- /* State 2 Overlap Sending */
- Q931AddStateEntry(i, Q931_U2, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_RELEASE, 2);
-
- /* State 3 Outgoing Call Proceeding */
- Q931AddStateEntry(i, Q931_U3, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_RELEASE, 2);
-
- /* State 4 Call Delivered */
- Q931AddStateEntry(i, Q931_U4, Q931mes_CONNECT, 4);
-
- /* State 6 Call Precent */
- Q931AddStateEntry(i, Q931_U6, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CALL_PROCEEDING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE_COMPLETE, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U6, Q931mes_DISCONNECT, 4);
-
- /* State 7 Call Received */
- Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2);
-
- /* State 8 Connect request */
- Q931AddStateEntry(i, Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4);
-
- /* State 9 Incoming Call Proceeding */
- Q931AddStateEntry(i, Q931_U9, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_PROGRESS, 2);
-
- /* State 10 Active */
- Q931AddStateEntry(i, Q931_U10, Q931mes_SUSPEND, 2);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 4);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 2);
-
- /* State 11 Disconnect Request */
- Q931AddStateEntry(i, Q931_U11, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_NOTIFY, 4);
-
- /* State 12 Disconnect Ind */
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 2);
-
- /* State 15 Suspend Request */
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_REJECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_RELEASE, 4);
-
-/* TODO
- Q931AddStateEntry(i, Q931_U17,
- Q931AddStateEntry(i, Q931_U19,
- Q931AddStateEntry(i, Q931_U25,
-*/
-}
-
-/*****************************************************************************
-
- Function: DMSProc0x0fTE
-
-*****************************************************************************/
-L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (pMes->ProtDisc == 8) {
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- }
- if (iFrom == 4) {
- /* TODO Add proc here*/
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here*/
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
-
- if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) {
- Q931AckService(pTrunk, buf);
- }
- }
- return ret;
-
-}
-
-/*****************************************************************************
-
- Function: DMSProc0x07TE
-
-*****************************************************************************/
-L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (pMes->ProtDisc == 8) {
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- }
- if (iFrom == 4) {
- /* TODO Add proc here*/
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here*/
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-
-}
diff --git a/libs/openzap/src/isdn/DMSmes.c b/libs/openzap/src/isdn/DMSmes.c
deleted file mode 100644
index 3ce82f2ded..0000000000
--- a/libs/openzap/src/isdn/DMSmes.c
+++ /dev/null
@@ -1,344 +0,0 @@
-/*****************************************************************************
-
- FileName: DMSmes.c
-
- Contents: Pack/Unpack functions. These functions will unpack a DMS-100 ISDN
- message from the bit packed original format into structs
- that contains variables sized by the user. It will also pack
- the struct back into a Q.931 message as required.
-
- See national.h for description.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-*****************************************************************************/
-
-#include "DMS.h"
-
-/*****************************************************************************
-
- Function: DMSUmes_Setup
-
-*****************************************************************************/
-L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT ir = 0;
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
- L3UCHAR last_codeset = 0, codeset = 0;
- L3UCHAR shift_lock = 1;
-
- while (IOff < Size) {
- if (!shift_lock) {
- codeset = last_codeset;
- }
-
- if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) {
- shift_lock = (IBuf[IOff] & 0x08);
- if (shift_lock) {
- last_codeset = codeset;
- }
- codeset = ((IBuf[IOff] & 0x07));
- IOff++;
- }
-
- if (codeset == 0) {
- switch (IBuf[IOff]) {
- case Q931ie_SENDING_COMPLETE:
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_NETWORK_SPECIFIC_FACILITIES:
- case Q931ie_DISPLAY:
- case Q931ie_DATETIME:
- case Q931ie_KEYPAD_FACILITY:
- case Q931ie_SIGNAL:
- case Q931ie_CALLING_PARTY_NUMBER:
- case Q931ie_CALLING_PARTY_SUBADDRESS:
- case Q931ie_CALLED_PARTY_NUMBER:
- case Q931ie_CALLED_PARTY_SUBADDRESS:
- case Q931ie_TRANSIT_NETWORK_SELECTION:
- case Q931ie_LOW_LAYER_COMPATIBILITY:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- case Q931ie_REPEAT_INDICATOR:
- if (ir < 2) {
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- ir++;
- } else {
- return Q931E_ILLEGAL_IE;
- }
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- } else if (codeset == 6) {
- switch (IBuf[IOff]) {
- case Q931ie_GENERIC_DIGITS:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
-
- } else {
- return Q931E_ILLEGAL_IE;
- }
- }
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: DMSPmes_Setup
-
- Decription: Pack a Q931mes_Generic into a real Q.931 message. The user will
- set up a SETUP message and issue this to the stack where it
- is processed by Q931ProcSetup that processes and validates
- it before it actually sends it out. This function is called
- to compute the real Q.931 message.
-
- Parameters: IBuf[IN] Ptr to un-packed struct
- ISize[IN] Size of input buffer (unpacked message).
- OBuf[OUT] Ptr to packed 'octet' wise message.
- OSize[OUT] Size of packed message.
-
- Called By: Q931ProcSetup
-
-*****************************************************************************/
-L3INT DMSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3INT rc = Q931E_NO_ERROR;
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Sending Complete */
- if (Q931IsIEPresent(pMes->SendComplete)) {
- OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff);
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->RepeatInd)) {
- OBuf[Octet++] = (L3UCHAR)(pMes->RepeatInd & 0x00ff);
- }
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- } else {
- rc = Q931E_BEARERCAP;
- }
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Network spesific facilities */
- if (Q931IsIEPresent(pMes->NetFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_NETWORK_SPECIFIC_FACILITIES](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Date/Time */
- if (Q931IsIEPresent(pMes->DateTime)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Keypad Facility */
- if (Q931IsIEPresent(pMes->KeypadFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Calling Party Number */
- if (Q931IsIEPresent(pMes->CallingNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Calling Party Subaddress */
- if (Q931IsIEPresent(pMes->CallingSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Called Party number */
- if (Q931IsIEPresent(pMes->CalledNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
-
- /* Called party subaddress */
- if (Q931IsIEPresent(pMes->CalledSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Transit network selection */
- if (Q931IsIEPresent(pMes->TransNetSel)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->LLRepeatInd)) {
- rc = Q931E_UNKNOWN_IE;/* TODO */
- }
-
- /* Low Layer Compatibility */
- if (Q931IsIEPresent(pMes->LLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-
-/*****************************************************************************
-
- Function: DMSUmes_0x0f
-
-*****************************************************************************/
-L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- if (mes->ProtDisc == 8) {
- return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: DMSPmes_0x0f
-
-*****************************************************************************/
-L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;
-
- if (mes->ProtDisc == 8) {
- return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: DMSUmes_0x07
-
-*****************************************************************************/
-L3INT DMSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- if (mes->ProtDisc == 8) {
- return Q931Umes_Connect(pTrunk, IBuf, mes, IOff, Size);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: DMSPmes_0x07
-
-*****************************************************************************/
-L3INT DMSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;
-
- if (mes->ProtDisc == 8) {
- return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- if (mes->ProtDisc == 3) {
- return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize);
- }
-
- return Q931E_UNKNOWN_MESSAGE;
-}
diff --git a/libs/openzap/src/isdn/EuroISDNStateNT.c b/libs/openzap/src/isdn/EuroISDNStateNT.c
deleted file mode 100644
index 6b26c91e04..0000000000
--- a/libs/openzap/src/isdn/EuroISDNStateNT.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*****************************************************************************
-
- FileName: EuroISDNStateNT.c
-
- Contents: EuroISDN State Engine for NT (Network Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q931.h"
diff --git a/libs/openzap/src/isdn/EuroISDNStateTE.c b/libs/openzap/src/isdn/EuroISDNStateTE.c
deleted file mode 100644
index ef6b39e8e5..0000000000
--- a/libs/openzap/src/isdn/EuroISDNStateTE.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*****************************************************************************
-
- FileName: EuroISDNStateTE.c
-
- Contents: EuroISDN State Engine for TE (User Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q931.h"
-
-/*
- EuroISDN is a sub-set of Q.931. Q.931 is very generic as it embrase a lot,
- while EuroISDN is more exact and make decitions on some of the
- 'implementation options' in the original standard. EuroISDN will
- however run smoothly under the generic space, so these functions are more
- for show
-*/
-#if 0
-static void EuroISDNCreateTE(L3UCHAR i)
-{
- Q931CreateTE(i);
-}
-#endif
diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c
deleted file mode 100644
index 0496e09f5c..0000000000
--- a/libs/openzap/src/isdn/Q921.c
+++ /dev/null
@@ -1,3517 +0,0 @@
-/*****************************************************************************
-
- FileName: q921.c
-
- Description: Contains the implementation of a Q.921 protocol
-
- Created: 27.dec.2000/JVB
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-*****************************************************************************/
-
-/****************************************************************************
- * Changes:
- *
- * - June-August 2008: Stefan Knoblich :
- * Add PTMP TEI management (NT + TE mode)
- * Add timers
- * Add retransmit counters
- * Add logging
- * Various cleanups
- * Queues, retransmission of I frames
- * PTMP NT mode
- *
- *
- * TODO:
- *
- * - Cleanup queueing, test retransmission
- *
- * - Q921Start() /-Stop() TEI acquire + release
- * (move everything related into these functions)
- *
- * - Q.921 '97 Appendix I (and maybe III, IV)
- *
- * - More complete Appendix II
- *
- * - Test PTP mode
- *
- * - PTMP NT mode (in progress)
- *
- * - NT mode TEI management: (ab)use T202 for TEI Check Request retransmission
- *
- * - General cleanup (move all non-public declarations into private header file)
- *
- * - Statistics, per-Frame type debug message filter
- *
- ****************************************************************************/
-
-#include
-#include
-#include
-#include
-
-#include "Q921.h"
-#include "Q921priv.h"
-#include "mfifo.h"
-
-#ifdef WIN32
-#pragma warning(disable:4100 4244)
-#endif
-
-/******************************************************************************************************
- * Actual code below this line
- ******************************************************************************************************/
-
-
-/**
- * Q921StateNames
- * \brief Static array of state name / value mappings
- */
-static struct Q921StateName {
- Q921State_t value;
- const char *name;
-} Q921StateNames[10] = {
- { Q921_STATE_STOPPED, "Stopped" },
- { Q921_STATE_TEI_UNASSIGNED, "TEI Unassigned" },
- { Q921_STATE_TEI_AWAITING, "TEI Awaiting Assignment" },
- { Q921_STATE_TEI_ESTABLISH, "TEI Awaiting Establishment" },
- { Q921_STATE_TEI_ASSIGNED, "TEI Assigned" },
- { Q921_STATE_AWAITING_ESTABLISHMENT, "Awaiting Establishment" },
- { Q921_STATE_AWAITING_RELEASE, "Awaiting Release" },
- { Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, "Multiple Frame Mode Established" },
- { Q921_STATE_TIMER_RECOVERY, "Timer Recovery" },
- { 0, 0 }
-};
-
-/**
- * Q921State2Name
- * \brief Convert state value to name
- * \param[in] state the state value
- * \return the state name or "Unknown"
- *
- * \author Stefan Knoblich
- */
-static const char *Q921State2Name(Q921State_t state)
-{
- struct Q921StateName *p = Q921StateNames;
-
- while(p->name) {
- if(p->value == state)
- return p->name;
- p++;
- }
-
- return "Unknown";
-}
-
-
-/**
- * Q921SendEnquiry
- */
-static int Q921SendEnquiry(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* send enquiry: begin */
- if(Q921_CHECK_FLAG(link, Q921_FLAG_RECV_BUSY)) {
-
- Q921SendRNR(trunk, trunk->sapi, Q921_COMMAND(trunk), tei, 1);
- }
- else {
- Q921SendRR(trunk, trunk->sapi, Q921_COMMAND(trunk), tei, 1);
- }
-
- /* clear acknowledge pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
-
- /* "Start" T200 */
- Q921T200TimerReset(trunk, tei);
-
- /* send enquiry: end */
- return 1;
-}
-
-/**
- * Q921SendEnquiryResponse
- */
-static int Q921SendEnquiryResponse(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* send enquiry: begin */
- if(Q921_CHECK_FLAG(link, Q921_FLAG_RECV_BUSY)) {
-
- Q921SendRNR(trunk, trunk->sapi, Q921_RESPONSE(trunk), tei, 1);
- }
- else {
- Q921SendRR(trunk, trunk->sapi, Q921_RESPONSE(trunk), tei, 1);
-
- /* clear acknowledge pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- /* send enquiry: end */
- return 1;
-}
-
-/**
- * Q921ResetExceptionConditions
- * \brief Reset Q.921 Exception conditions procedure
- * \param trunk Q.921 data structure
- * \param tei TEI
- * \todo Do something
- */
-static void Q921ResetExceptionConditions(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* Clear peer receiver busy */
- Q921_CLEAR_FLAG(link, Q921_FLAG_PEER_RECV_BUSY);
-
- /* Clear reject exception */
- Q921_CLEAR_FLAG(link, Q921_FLAG_REJECT);
-
- /* Clear own receiver busy */
- Q921_CLEAR_FLAG(link, Q921_FLAG_RECV_BUSY);
-
- /* Clear acknowledge pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
-
- return;
-}
-
-/**
- * Q921EstablishDataLink
- * \brief Q.921 Establish data link procedure
- * \param trunk Q.921 data structure
- * \param tei TEI
- * \return always 1 (success)
- */
-static int Q921EstablishDataLink(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* reset exception conditions */
- Q921ResetExceptionConditions(trunk, tei);
-
- /* RC = 0 */
- link->N200 = 0;
-
- /* Send SABME */
- Q921SendSABME(trunk, trunk->sapi, Q921_COMMAND(trunk), tei, 1);
-
- /* Restart T200, stop T203 */
- Q921T200TimerReset(trunk, tei);
- Q921T203TimerStop(trunk, tei);
-
- return 1;
-}
-
-/**
- * Q921NrErrorRecovery
- * \brief NR(R) Error recovery procedure
- * \param trunk Q.921 data structure
- * \param tei TEI
- * \return always 1 (success)
- */
-static int Q921NrErrorRecovery(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* MDL Error indication (J) */
-
- /* Establish datalink */
- Q921EstablishDataLink(trunk, tei);
-
- /* Clear L3 initiated */
- Q921_CLEAR_FLAG(link, Q921_FLAG_L3_INITIATED);
-
- return 1;
-}
-
-
-/**
- * Q921InvokeRetransmission
- * \brief I Frame retransmission procedure
- * \param trunk Q.921 data structure
- * \param tei TEI
- * \param nr N(R) for retransmission
- * \return always 1 (success)
- */
-static int Q921InvokeRetransmission(L2TRUNK trunk, L2UCHAR tei, L2UCHAR nr)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
- L2UCHAR *mes;
- L2INT qpos, qnum, size = 0;
-
- qnum = MFIFOGetMesCount(link->IFrameResendQueue);
- qpos = qnum - 1;
-
- /*
- * slightly different than what is shown in the spec
- * (Q.921 '97 Annex B, Figure B.9, page 104)
- *
- * what the above mentioned figure probably means is:
- * "as long as V(S) != N(R), move the pointer marking
- * the first frame to start resending at to the previous
- * frame"
- *
- * if we actually implemented it as shown in the figure, we'd be
- * resending frames in the wrong order (moving backwards in time)
- * meaning we'd have to add an incoming queue to reorder the frames
- *
- */
- /*
- * TODO: There's a "traditional" off-by-one error hidden in the original
- * mfifo implementation + it's late, i'm tired and being lazy,
- * so i'll probably have added another one :P
- *
- * wow, the first while loop sucks and can be removed
- */
- while(link->vs != nr && qpos > 0) { /* ???? */
- /* V(S) = V(S) - 1 */
- Q921_DEC_COUNTER(link->vs); /* huh? backwards? */
-
- /* next frame in queue (backtrack along I queue) ??? */
- qpos--;
- }
-
- /*
- * being lazy and trying to avoid mod 128 math this way...
- */
- if(link->vs != nr && !qpos) {
- /* fatal, we don't have enough history to resend all missing frames */
- /* TODO: how to handle this? */
- }
-
- /*
- * resend frames in correct order (oldest missing frame first,
- * contrary to what the spec figure shows)
- */
- while(qpos < qnum) {
- /* Grab frame's buffer ptr and size from queue */
- mes = MFIFOGetMesPtrOffset(link->IFrameResendQueue, &size, qpos);
- if(mes) {
- /* requeue frame (TODO: check queue full condition) */
- MFIFOWriteMes(link->IFrameQueue, mes, size);
-
- /* set I frame queued */
- }
-
- qpos++;
- }
-
- return 1;
-}
-
-
-static int Q921AcknowledgePending(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- case Q921_STATE_TIMER_RECOVERY:
- if(Q921_CHECK_FLAG(link, Q921_FLAG_ACK_PENDING)) {
- /* clear acknowledge pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
-
- /* send RR */
- Q921SendRR(trunk, trunk->sapi, Q921_COMMAND(trunk), tei, 0);
-
- return 1;
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-/*****************************************************************************
-
- Function: Q921_InitTrunk
-
- Decription: Initialize a Q.921 trunk so it is ready for use. This
- function MUST be called before you call any other functions.
-
-*****************************************************************************/
-int Q921_InitTrunk(L2TRUNK trunk,
- L2UCHAR sapi,
- L2UCHAR tei,
- Q921NetUser_t NetUser,
- Q921NetType_t NetType,
- L2INT hsize,
- Q921Tx21CB_t cb21,
- Q921Tx23CB_t cb23,
- void *priv21,
- void *priv23)
-{
- int numlinks = 0;
-
- trunk->sapi = sapi;
- trunk->tei = tei;
- trunk->NetUser = NetUser;
- trunk->NetType = NetType;
- trunk->Q921Tx21Proc = cb21;
- trunk->Q921Tx23Proc = cb23;
- trunk->PrivateData21 = priv21;
- trunk->PrivateData23 = priv23;
- trunk->Q921HeaderSpace = hsize;
-
- numlinks = Q921_IS_PTMP_NT(trunk) ? Q921_TEI_MAX : 1;
-
- if (trunk->initialized != INITIALIZED_MAGIC) {
- MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10);
-
- /*
- * Allocate space for per-link context(s)
- */
- trunk->context = malloc(numlinks * sizeof(struct Q921_Link));
- if(!trunk->context)
- return -1;
-
- trunk->initialized = INITIALIZED_MAGIC;
- }
-
- /* timeout default values */
- trunk->T200Timeout = 1000; /* 1 second */
- trunk->T203Timeout = 10000; /* 10 seconds */
- trunk->T202Timeout = 2000; /* 2 seconds */
- trunk->T201Timeout = 200000; /* 200 seconds */
- trunk->TM01Timeout = 10000; /* 10 seconds */
-
- /* octet / retransmit counter default limits */
- trunk->N200Limit = 3; /* 3 retransmits */
- trunk->N201Limit = 260; /* 260 octets */
- trunk->N202Limit = 3; /* 3 retransmits */
- trunk->k = 7; /* 7 outstanding ACKs */
-
- /* reset counters, timers, etc. */
- trunk->T202 = 0;
- trunk->N202 = 0;
-
- /* Reset per-link contexts */
- memset(trunk->context, 0, numlinks * sizeof(struct Q921_Link));
-
- /* clear tei map */
- memset(trunk->tei_map, 0, Q921_TEI_MAX + 1);
-
- if(Q921_IS_PTMP(trunk)) {
- /*
- * We're either the Network side (NT, TEI = 0)
- * or user-side equipment (TE) which will get it's TEI via
- * dynamic assignment
- */
- trunk->tei = 0;
- }
-
- return 0;
-}
-
-
-/**
- * Q921Tx21Proc
- * \brief Submit frame to layer 1 (for sending)
- * \param[in] trunk Pointer to trunk struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- */
-static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size)
-{
- Q921LogMesg(trunk, Q921_LOG_DEBUG, 0, Msg, size, "Sending frame");
-
- return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size);
-}
-
-
-/**
- * Q921Tx23Proc
- * \brief Submit frame to layer 3
- * \param[in] trunk Pointer to trunk struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- */
-static int Q921Tx23Proc(L2TRUNK trunk, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *Msg, L2INT size)
-{
- return trunk->Q921Tx23Proc(trunk->PrivateData23, ind, tei, Msg, size);
-}
-
-
-/**
- * Q921LogProc
- * \brief Used for logging, converts to string and submits to higher level log function via callback
- * \param[in] trunk Pointer to trunk struct
- * \param[in] level Q921 Loglevel
- * \param[in] fmt format of logmessage
- * \return >= 0 on success, < 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921Log(L2TRUNK trunk, Q921LogLevel_t level, const char *fmt, ...)
-{
- char buf[Q921_LOGBUFSIZE];
- L2INT len;
- va_list ap;
-
- if(!trunk->Q921LogProc)
- return 0;
-
- if(trunk->loglevel < level)
- return 0;
-
- va_start(ap, fmt);
-
- len = vsnprintf(buf, sizeof(buf)-1, fmt, ap);
- if(len <= 0) {
- /* TODO: error handling */
- return -1;
- }
- if(len >= sizeof(buf))
- len = sizeof(buf) - 1;
-
- buf[len] = '\0';
-
- va_end(ap);
-
- return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, len);
-}
-
-
-static int print_hex(char *buf, int bsize, const unsigned char *in, const int len)
-{
- static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
- int offset = 0;
- int pos = 0;
- int nr = 0;
-
- buf[pos++] = '[';
- bsize -= 3;
-
- while((bsize - pos) > 0 && offset < len) {
- buf[pos++] = hex[(in[offset] & 0xF0) >> 4];
- buf[pos++] = hex[(in[offset++] & 0x0F)];
-
- if(++nr == 32 && offset < len && (bsize - pos) > 3) {
- nr = 0;
- buf[pos++] = ']';
- buf[pos++] = '\n';
- buf[pos++] = '[';
- }
- else if(offset < len) {
- buf[pos++] = ' ';
- }
- }
-
- buf[pos++] = ']';
- buf[pos++] = '\n';
- buf[pos] = '\0';
-
- return pos;
-}
-
-#define APPEND_MSG(buf, off, lef, fmt, ...) \
- len = snprintf(buf + off, lef, fmt, ##__VA_ARGS__); \
- if(len > 0) { \
- off += len; \
- lef -= len; \
- } else { \
- goto out; \
- }
-
-/**
- * Q921LogProcMesg
- * \brief Used for logging, converts to string and submits to higher level log function via callback
- * \param[in] trunk Pointer to trunk struct
- * \param[in] level Q921 Loglevel
- * \param[in] received direction of the message (received = 1, sending = 0)
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \param[in] fmt format of logmessage
- * \return >= 0 on success, < 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2UCHAR *mes, L2INT size, const char *fmt, ...)
-{
- char buf[Q921_LOGBUFSIZE];
- size_t len, left;
- va_list ap;
-
- if(!trunk->Q921LogProc)
- return 0;
-
- if(trunk->loglevel < level)
- return 0;
-
- if(!mes)
- return 0;
-
- memset(buf, 0, sizeof(buf));
-
- left = sizeof(buf) - 1;
-
- va_start(ap, fmt);
-
- len = vsnprintf(buf, left, fmt, ap);
- if(len > 0)
- left -= len;
- else {
- /* TODO: error handling */
- return -1;
- }
-
- va_end(ap);
-
- if(trunk->loglevel == Q921_LOG_DEBUG) {
- char pbuf[1024];
- size_t pleft, poffset;
- L2UCHAR sapi, tei, cr;
- L2UCHAR *pmes = mes + trunk->Q921HeaderSpace;
- struct Q921_Link *link;
-
- memset(pbuf, 0, sizeof(pbuf));
-
- pleft = sizeof(pbuf);
- poffset = 0;
-
- /*
- * Decode packet
- */
- sapi = (pmes[0] & 0xfc) >> 2;
- cr = (pmes[0] & 0x02) >> 1;
- tei = (pmes[1] & 0xfe) >> 1;
- link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* make cr actually useful */
- cr = (received) ? Q921_IS_COMMAND(trunk, cr) : Q921_IS_RESPONSE(trunk, cr);
-
- /* filter */
- if((pmes[2] & 0x01) == 0x00) {
- ;
- }
- else if((pmes[2] & 0x03) == 0x01) {
- ; //return 0;
- }
- else if((pmes[2] & 0x03) == 0x03) {
- ;
- }
-
- APPEND_MSG(pbuf, poffset, pleft, "\n----------------- Q.921 Packet [%s%s] ---------------\n", received ? "Incoming" : "Outgoing",
- (tei == link->tei || tei == Q921_TEI_BCAST) ? "" : ", Ignored" );
-
- /* common header */
- APPEND_MSG(pbuf, poffset, pleft, " SAPI: %u, TEI: %u, C/R: %s (%d)\n\n", sapi, tei, (cr) ? "Command" : "Response", (mes[0] & 0x02) >> 1 );
-
- /*
- * message specific
- */
- if((pmes[2] & 0x01) == 0x00) {
- /*
- * I frame
- */
- L2UCHAR pf = pmes[3] & 0x01; /* poll / final flag */
- L2UCHAR nr = pmes[3] >> 1; /* receive sequence number */
- L2UCHAR ns = pmes[2] >> 1; /* send sequence number */
-
- APPEND_MSG(pbuf, poffset, pleft, " Type: I Frame\n P/F: %d, N(S): %d, N(R): %d [V(A): %d, V(R): %d, V(S): %d]\n", pf, ns, nr,
- link->va, link->vr, link->vs);
-
- /* Dump content of I Frames for foreign TEIs */
- if(tei != link->tei) {
- APPEND_MSG(pbuf, poffset, pleft, " CONTENT:\n");
-
- len = print_hex(pbuf + poffset, (int)pleft, &pmes[4], size - (trunk->Q921HeaderSpace + 4));
- poffset += len;
- pleft -= len;
- }
- }
- else if((pmes[2] & 0x03) == 0x01) {
- /*
- * S frame
- */
- L2UCHAR sv = (pmes[2] & 0x0c) >> 2; /* supervisory format id */
- L2UCHAR pf = pmes[3] & 0x01; /* poll / final flag */
- L2UCHAR nr = pmes[3] >> 1; /* receive sequence number */
- const char *type;
-
- switch(sv) {
- case 0x00: /* RR : Receive Ready */
- type = "RR (Receive Ready)";
- break;
-
- case 0x02: /* RNR : Receive Not Ready */
- type = "RNR (Receiver Not Ready)";
- break;
-
- case 0x04: /* REJ : Reject */
- type = "REJ (Reject)";
- break;
-
- default: /* Invalid / Unknown */
- type = "Unknown";
- break;
- }
-
- APPEND_MSG(pbuf, poffset, pleft, " Type: S Frame, SV: %s\n P/F: %d, N(R): %d [V(A): %d, V(R): %d, V(S): %d]\n", type, pf, nr,
- link->va, link->vr, link->vs);
- }
- else if((pmes[2] & 0x03) == 0x03) {
- /*
- * U frame
- */
- L2UCHAR m = (pmes[2] & 0xe0) >> 3 | (pmes[2] & 0x0c) >> 2; /* modifier function id */
- L2UCHAR pf = (pmes[2] & 0x10) >> 4; /* poll / final flag */
- const char *type;
-
- switch(m) {
- case 0x00:
- type = "UI (Unnumbered Information)";
- break;
-
- case 0x03:
- type = "DM (Disconnected Mode)";
- break;
-
- case 0x08:
- type = "DISC (Disconnect)";
- break;
-
- case 0x0c:
- type = "UA (Unnumbered Acknowledgement)";
- break;
-
- case 0x0f:
- type = "SABME";
- break;
-
- case 0x11:
- type = "FRMR (Frame Reject)";
- break;
-
- case 0x17:
- type = "XID (Exchange Identification)";
- break;
-
- default:
- type = "Unknown";
- }
-
-
- APPEND_MSG(pbuf, poffset, pleft, " Type: U Frame (%s)\n P/F: %d\n", type, pf);
-
- if(m == 0x00) {
- switch(pmes[3]) {
- case Q921_LAYER_ENT_ID_TEI:
- type = "TEI Mgmt";
- break;
-
- case Q921_LAYER_ENT_ID_Q931:
- type = "Q.931";
- break;
-
- default:
- type = "Unknown";
- }
-
- if(pmes[3] == Q921_LAYER_ENT_ID_TEI) {
- const char *command = "";
-
- switch(pmes[6]) {
- case Q921_TEI_ID_REQUEST:
- command = "Request";
- break;
- case Q921_TEI_ID_VERIFY:
- command = "Verify";
- break;
- case Q921_TEI_ID_CHECKREQ:
- command = "Check req";
- break;
- case Q921_TEI_ID_CHECKRESP:
- command = "Check resp";
- break;
- case Q921_TEI_ID_REMOVE:
- command = "Remove";
- break;
- case Q921_TEI_ID_ASSIGNED:
- command = "Assign";
- break;
- case Q921_TEI_ID_DENIED:
- command = "Denied";
- break;
- }
- APPEND_MSG(pbuf, poffset, pleft, " ENT ID: %d (%s), COMMAND: %d (%s), RI: %#x, AI: %d\n",
- pmes[3], type, pmes[6], command, (int)((pmes[4] << 8) | pmes[5]), pmes[7] >> 1);
- }
- else {
- APPEND_MSG(pbuf, poffset, pleft, " ENT ID: %d (%s), MESSAGE CONTENT:\n", pmes[3], type);
-
- len = print_hex(pbuf + poffset, (int)pleft, &pmes[3], size - (trunk->Q921HeaderSpace + 3));
- poffset += len;
- pleft -= len;
- }
- }
- }
- else {
- /*
- * Unknown
- */
- strncat(pbuf + poffset, " -- unknown frame type --\n", pleft);
-
- len = (sizeof(pbuf) - poffset) - strlen(pbuf + poffset);
- if(len > 0) {
- poffset += len;
- pleft -= len;
- } else
- goto out;
- }
-
- APPEND_MSG(pbuf, poffset, pleft, "\n Q.921 state: \"%s\" (%d) [flags: %c%c%c%c]\n", Q921State2Name(link->state), link->state,
- Q921_CHECK_FLAG(link, Q921_FLAG_ACK_PENDING) ? 'A' : '-',
- Q921_CHECK_FLAG(link, Q921_FLAG_REJECT) ? 'R' : '-',
- Q921_CHECK_FLAG(link, Q921_FLAG_PEER_RECV_BUSY) ? 'P' : '-',
- Q921_CHECK_FLAG(link, Q921_FLAG_RECV_BUSY) ? 'B' : '-');
-
- strncat(pbuf + poffset, "----------------------------------------------\n\n", pleft);
-
- len = (sizeof(pbuf) - poffset) - strlen(pbuf + poffset);
- if(len > 0) {
- poffset += len;
- pleft -= len;
- } else
- goto out;
-
-
- /* concat buffers together */
- len = strlen(pbuf);
- if(len <= left)
- strncat(buf, pbuf, left);
- else
- strncat(buf, "-- packet truncated --\n", left);
- }
-
-out:
- buf[sizeof(buf) - 1] = '\0';
-
- return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, (int)strlen(buf));
-}
-
-/*****************************************************************************
-
- Function: Q921TimeTick
-
- Description: Called periodically from an external source to allow the
- stack to process and maintain it's own timers.
-
- Return Value: none
-
-*****************************************************************************/
-static L2ULONG (*Q921GetTimeProc) (void) = NULL; /* callback for func reading time in ms */
-static L2ULONG tLast = {0};
-
-static L2ULONG Q921GetTime(void)
-{
- L2ULONG tNow = 0;
-
- if(Q921GetTimeProc)
- {
- tNow = Q921GetTimeProc();
- if(tNow < tLast) /* wrapped */
- {
- /* TODO */
- }
- tLast = tNow;
- }
- return tNow;
-}
-
-/*
- * T200 handling (per-TEI in PTMP NT mode, tei=0 otherwise)
- */
-static void Q921T200TimerStart(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- if (!link->T200) {
- link->T200 = Q921GetTime() + trunk->T200Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T200 (timeout: %d msecs) started for TEI %d\n", trunk->T200Timeout, tei);
- }
-}
-
-static void Q921T200TimerStop(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->T200 = 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T200 stopped for TEI %d\n", tei);
-}
-
-static void Q921T200TimerReset(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->T200 = Q921GetTime() + trunk->T200Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T200 (timeout: %d msecs) restarted for TEI %d\n", trunk->T200Timeout, tei);
-}
-
-/*
- * T203 handling (per-TEI in PTMP NT mode, tei=0 otherwise)
- */
-static void Q921T203TimerStart(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- if (!link->T203) {
- link->T203 = Q921GetTime() + trunk->T203Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T203 (timeout: %d msecs) started for TEI %d\n", trunk->T203Timeout, tei);
- }
-}
-
-static void Q921T203TimerStop(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->T203 = 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T203 stopped for TEI %d\n", tei);
-}
-
-static void Q921T203TimerReset(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->T203 = Q921GetTime() + trunk->T203Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T203 (timeout: %d msecs) restarted for TEI %d\n", trunk->T203Timeout, tei);
-}
-
-/*
- * T202 handling (TEI message timeout, TE mode only)
- */
-static void Q921T202TimerStart(L2TRUNK trunk)
-{
- if (!trunk->T202) {
- trunk->T202 = Q921GetTime() + trunk->T202Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T202 (timeout: %d msecs) started\n", trunk->T202Timeout);
- }
-}
-
-static void Q921T202TimerStop(L2TRUNK trunk)
-{
- trunk->T202 = 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T202 stopped\n");
-}
-
-static void Q921T202TimerReset(L2TRUNK trunk)
-{
- trunk->T202 = Q921GetTime() + trunk->T202Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T202 (timeout: %d msecs) restarted\n", trunk->T202Timeout);
-}
-
-/*
- * T201 handling (TEI management (NT side), per-TEI)
- */
-static void Q921T201TimerStart(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- if (!link->T201) {
- link->T201 = Q921GetTime() + trunk->T201Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T201 (timeout: %d msecs) started for TEI %d\n", trunk->T201Timeout, tei);
- }
-}
-
-static void Q921T201TimerStop(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->T201 = 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T201 stopped for TEI %d\n", tei);
-}
-
-#ifdef __UNUSED_FOR_NOW__
-static void Q921T201TimerReset(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->T201 = Q921GetTime() + trunk->T201Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T201 (timeout: %d msecs) restarted for TEI %d\n", trunk->T201Timeout, tei);
-}
-#endif
-
-/*
- * TM01 handling (Datalink inactivity shutdown timer)
- */
-static void Q921TM01TimerStart(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- if (!link->TM01) {
- link->TM01 = Q921GetTime() + trunk->TM01Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "TM01 (timeout: %d msecs) started for TEI %d\n", trunk->TM01Timeout, tei);
- }
-}
-
-#ifdef __UNUSED_FOR_NOW__
-static void Q921TM01TimerStop(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->TM01 = 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "TM01 stopped for TEI %d\n", tei);
-}
-#endif
-
-static void Q921TM01TimerReset(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- link->TM01 = Q921GetTime() + trunk->TM01Timeout;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "TM01 (timeout: %d msecs) restarted for TEI %d\n", trunk->TM01Timeout, tei);
-}
-
-/*
- * Expiry callbacks
- */
-static void Q921T200TimerExpire(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
- struct Q921_Link *trlink = Q921_TRUNK_CONTEXT(trunk);
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T200 expired for TEI %d (trunk TEI %d)\n", tei, trlink->tei);
-
- /* Stop timer first */
- Q921T200TimerStop(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_AWAITING_ESTABLISHMENT:
- if(link->N200 >= trunk->N200Limit) {
- /* Discard I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* MDL-Error indication (G) */
- Q921Log(trunk, Q921_LOG_ERROR, "Failed to establish Q.921 link in %d retries\n", link->N200);
-
- /* DL-Release indication */
- Q921Tx23Proc(trunk, Q921_DL_RELEASE, tei, NULL, 0);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_TEI_ASSIGNED, tei);
- } else {
- /* Increment retry counter */
- link->N200++;
-
- /* Send SABME */
- Q921SendSABME(trunk,
- trunk->sapi,
- Q921_COMMAND(trunk),
- tei,
- 1);
-
- /* Start T200 */
- Q921T200TimerStart(trunk, tei);
- }
- break;
-
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- link->N200 = 0;
-
- if(!Q921_CHECK_FLAG(link, Q921_FLAG_PEER_RECV_BUSY)) {
- /* get last transmitted I frame */
-
- /* V(S) = V(S) - 1 */
- Q921_DEC_COUNTER(link->vs);
-
- /* retransmit I frame */
-
- /* V(S) = V(S) + 1 (done by Q921SendI() ) */
- //Q921_INC_COUNTER(link->vs);
-
- /* clear acknowledge pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
-
- /* Start T200 */
- Q921T200TimerStart(trunk, tei);
- } else {
- /* transmit enquiry */
- Q921SendEnquiry(trunk, tei);
- }
-
- /* increment counter */
- link->N200++;
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_TIMER_RECOVERY, tei);
- break;
-
- case Q921_STATE_TIMER_RECOVERY:
- if(link->N200 == trunk->N200Limit) {
- /* MDL Error indication (I) */
-
- /* Establish data link */
- Q921EstablishDataLink(trunk, tei);
-
- /* Clear L3 initiated */
- Q921_CLEAR_FLAG(link, Q921_FLAG_L3_INITIATED);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- } else {
- if(link->vs == link->va) {
- /* transmit enquiry */
- Q921SendEnquiry(trunk, tei);
-
- } else if(!Q921_CHECK_FLAG(link, Q921_FLAG_PEER_RECV_BUSY)) {
- /* get last transmitted frame */
-
- /* V(S) = V(S) - 1 */
- Q921_DEC_COUNTER(link->vs);
-
- /* retrans frame */
-
- /* V(S) = V(S) + 1 (done by Q921SendI() ) */
- //Q921_INC_COUNTER(link->vs);
-
- /* clear acknowledge pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
-
- /* Start T200 */
- Q921T200TimerStart(trunk, tei);
- }
-
- /* increment counter */
- link->N200++;
-
- /* no state change */
- }
- break;
-
- default:
- break;
- }
-}
-
-static void Q921T203TimerExpire(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
- struct Q921_Link *trlink = Q921_TRUNK_CONTEXT(trunk);
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T203 expired for TEI %d (trunk TEI %d)\n", tei, trlink->tei);
-
- /* Stop Timer first */
- Q921T203TimerStop(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- /* Send Enquiry */
- Q921SendEnquiry(trunk, tei);
-
- /* RC = 0 */
- link->N200 = 0;
-
- /* no state change */
- break;
-
- default:
- break;
- }
-}
-
-static void Q921T202TimerExpire(L2TRUNK trunk)
-{
- struct Q921_Link *link = Q921_TRUNK_CONTEXT(trunk);
-
- Q921T202TimerReset(trunk);
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T202 expired for Q.921 trunk with TEI %d\n", link->tei);
-
- /* todo: implement resend counter */
-
- switch(link->state) {
- case Q921_STATE_TEI_ASSIGNED: /* Tei identity verify timeout */
- Q921TeiSendVerifyRequest(trunk);
- break;
-
- default: /* Tei assignment request timeout (TODO: refine) */
-
- if(trunk->N202 >= trunk->N202Limit) {
- /* Too many retransmits, reset counter, stop timer and handle case (TODO) */
- trunk->N202 = 0;
-
- Q921T202TimerStop(trunk);
-
- return;
- }
- Q921TeiSendAssignRequest(trunk);
-
- trunk->N202++;
- }
-}
-
-static void Q921T201TimerExpire(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
- struct Q921_Link *trlink = Q921_TRUNK_CONTEXT(trunk);
-
- Q921Log(trunk, Q921_LOG_DEBUG, "T201 expired for TEI %d (trunk TEI: %d)\n", tei, trlink->tei);
-
- Q921T201TimerStop(trunk, tei);
-
- /* NOTE: abusing N202 for this */
- if(link->N202 < trunk->N202Limit) {
- /* send check request */
- Q921TeiSendCheckRequest(trunk, tei);
-
- /* increment counter */
- link->N202++;
- } else {
- /* put context in STOPPED state */
- Q921ChangeState(trunk, Q921_STATE_STOPPED, tei);
-
- /* NOTE: should we clear the link too? */
- memset(link, 0, sizeof(struct Q921_Link));
-
- /* mark TEI free */
- trunk->tei_map[tei] = 0;
- }
-}
-
-#ifdef __UNUSED_FOR_NOW__
-static void Q921TM01TimerExpire(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
- struct Q921_Link *trlink = Q921_TRUNK_CONTEXT(trunk);
-
- Q921Log(trunk, Q921_LOG_DEBUG, "TM01 expired for TEI %d (trunk TEI: %d)\n", tei, trlink->tei);
-
- /* Restart TM01 */
- Q921TM01TimerReset(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- case Q921_STATE_TIMER_RECOVERY:
-/*
- * NT-only, needs more support from L3
- */
-#if 0
- /* No activity, shutdown link */
- Q921SendDISC(trunk, trunk->sapi, Q921_COMMAND(trunk), tei, 1);
-
- /* clear I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* change state */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_RELEASE, tei);
-#endif
- break;
-
- default:
- break;
- }
-}
-#endif
-
-/*
- * Timer Tick function
- */
-void Q921TimerTick(L2TRUNK trunk)
-{
- struct Q921_Link *link;
- L2ULONG tNow = Q921GetTime();
- int numlinks = Q921_IS_PTMP_NT(trunk) ? Q921_TEI_MAX : 1;
- int x;
-
- for(x = 0; x <= numlinks; x++) {
- link = Q921_LINK_CONTEXT(trunk, x);
-
- /* TODO: check if TEI is assigned and skip check if not (speedup!) */
- if(link->state == Q921_STATE_STOPPED)
- continue;
-
- if (link->T200 && tNow > link->T200) {
- Q921T200TimerExpire(trunk, link->tei);
- }
- if (link->T203 && tNow > link->T203) {
- Q921T203TimerExpire(trunk, link->tei);
- }
-
- if(Q921_IS_PTMP_NT(trunk) && link->tei) {
- if (link->T201 && tNow > link->T201) {
- Q921T201TimerExpire(trunk, link->tei);
- }
- }
-
- if(!Q921_IS_PTMP_NT(trunk)) {
- if (trunk->T202 && tNow > trunk->T202) {
- Q921T202TimerExpire(trunk);
- }
- }
-
- /* Send enqueued I frame, if available */
- Q921SendQueuedIFrame(trunk, link->tei);
-
- /* Send ack if pending */
- Q921AcknowledgePending(trunk, link->tei);
- }
-
-}
-
-void Q921SetGetTimeCB(L2ULONG (*callback)(void))
-{
- Q921GetTimeProc = callback;
-}
-
-/*****************************************************************************
-
- Function: Q921QueueHDLCFrame
-
- Description: Called to receive and queue an incoming HDLC frame. Will
- queue this in Q921HDLCInQueue. The called must either call
- Q921Rx12 directly afterwards or signal Q921Rx12 to be called
- later. Q921Rx12 will read from the same queue and process
- the frame.
-
- This function assumes that the message contains header
- space. This is removed for internal Q921 processing, but
- must be keept for I frames.
-
- Parameters: trunk trunk #
- b ptr to frame;
- size size of frame in bytes
-
-*****************************************************************************/
-int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size)
-{
- return MFIFOWriteMes(trunk->HDLCInQueue, b, size);
-}
-
-/**
- * Q921EnqueueI
- * \brief Put I frame into transmit queue
- *
- */
-static int Q921EnqueueI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, Tei);
-
- /* I frame header */
- mes[trunk->Q921HeaderSpace+0] = ((Sapi << 2) & 0xfc) | ((cr << 1) & 0x02);
- mes[trunk->Q921HeaderSpace+1] = (Tei << 1) | 0x01;
- mes[trunk->Q921HeaderSpace+2] = 0x00;
- mes[trunk->Q921HeaderSpace+3] = (pf & 0x01);
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Enqueueing I frame for TEI %d [%d]\n", link->tei, Tei);
-
- /* transmit queue, (TODO: check for full condition!) */
- MFIFOWriteMes(link->IFrameQueue, mes, size);
-
- /* try to send queued frame */
- Q921SendQueuedIFrame(trunk, link->tei);
-
- return 1;
-}
-
-/**
- * Q921SendQueuedIFrame
- * \brief Try to transmit queued I frame (if available)
- */
-static int Q921SendQueuedIFrame(L2TRUNK trunk, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- L2INT size = 0;
- L2UCHAR *mes;
-
- if(MFIFOGetMesCount(link->IFrameQueue) == 0) {
- return 0;
- }
-
- /* Link ready? */
- if(link->state != Q921_STATE_MULTIPLE_FRAME_ESTABLISHED) {
- return 0;
- }
-
- /* peer receiver busy? */
- if(Q921_CHECK_FLAG(link, Q921_FLAG_PEER_RECV_BUSY)) {
- return 0;
- }
-
- /* V(S) = V(A) + k? */
- if(link->vs == ((link->va + trunk->k) % 128)) {
- Q921Log(trunk, Q921_LOG_WARNING, "Maximum number (%d) of outstanding I frames reached for TEI %d\n", trunk->k, tei);
- return 0;
- }
-
- mes = MFIFOGetMesPtr(link->IFrameQueue, &size);
- if(mes) {
- /* Fill in + update counter values */
- mes[trunk->Q921HeaderSpace+2] = link->vs << 1;
- mes[trunk->Q921HeaderSpace+3] |= link->vr << 1;
-
- if(MFIFOGetMesCount(link->IFrameQueue) == 0) {
- /* clear I frame queued */
- }
-
- /* Send I frame */
- Q921Tx21Proc(trunk, mes, size);
-
- /* V(S) = V(S) + 1 */
- Q921_INC_COUNTER(link->vs);
-
- /* clear acknowledge pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
-
- /* T200 running? */
- if(!link->T200) {
- /* Stop T203, Start T200 */
- Q921T200TimerStart(trunk, tei);
- Q921T203TimerStop(trunk, tei);
- }
-
- /* put frame into resend queue */
- MFIFOWriteMesOverwrite(link->IFrameResendQueue, mes, size);
-
- /* dequeue frame */
- MFIFOKillNext(link->IFrameQueue);
-
- /* Restart TM01 */
- if(Q921_IS_NT(trunk)) {
- Q921TM01TimerReset(trunk, tei);
- }
-
- /* no state change */
- return 1;
- }
-
- return 0;
-}
-
-/**
- * Q921SendS
- * \brief Prepare and send S frame
- */
-static int Q921SendS(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR sv, L2UCHAR *mes, L2INT size)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, Tei);
-
- if(!Q921_IS_READY(link)) {
- /* don't even bother trying */
- Q921Log(trunk, Q921_LOG_DEBUG, "Link not ready, discarding S frame for TEI %d\n", Tei);
- return 0;
- }
-
- /* S frame header */
- mes[trunk->Q921HeaderSpace+0] = ((Sapi << 2) & 0xfc) | ((cr << 1) & 0x02);
- mes[trunk->Q921HeaderSpace+1] = (Tei << 1) | 0x01;
- mes[trunk->Q921HeaderSpace+2] = ((sv << 2) & 0x0c) | 0x01;
- mes[trunk->Q921HeaderSpace+3] = (link->vr << 1) | (pf & 0x01);
-
- return Q921Tx21Proc(trunk, mes, size);
-}
-
-
-/**
- * Q921SendU
- * \brief Prepare and send U frame
- */
-static int Q921SendU(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR m, L2UCHAR *mes, L2INT size)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, Tei);
-
- /* U frame header */
- mes[trunk->Q921HeaderSpace+0] = ((Sapi << 2) & 0xfc) | ((cr << 1) & 0x02);
- mes[trunk->Q921HeaderSpace+1] = (Tei << 1) | 0x01;
- mes[trunk->Q921HeaderSpace+2] = ((m << 3) & 0xe0) | ((pf << 4) & 0x10) | ((m << 2) & 0x0c) | 0x03;
-
- /* link not ready? enqueue non-TEI-mgmt UI (DL-UNIT DATA) frames */
- if(m == 0x00 && Sapi != Q921_SAPI_TEI && link->state < Q921_STATE_TEI_ASSIGNED) {
-
- /* write frame to queue */
- MFIFOWriteMes(link->UIFrameQueue, mes, size);
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Link not ready, UI Frame of size %d bytes queued for TEI %d\n", size, Tei);
- return 1;
- }
-
- return Q921Tx21Proc(trunk, mes, size);
-}
-
-/**
- * TODO: NT mode handling? Need a way to get Link context from Q.931
- */
-int Q921Rx32(L2TRUNK trunk, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR * Mes, L2INT Size)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei); /* TODO: need real link tei for NT mode */
- L2INT res = 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Got frame from Q.931, type: %d, tei: %d, size: %d\n", ind, tei, Size);
-
- switch(ind) {
- case Q921_DL_ESTABLISH:
- /*
- * Hmm...
- */
- switch(link->state) {
- case Q921_STATE_TEI_ASSIGNED:
- if(!Q921_IS_NT(trunk)) {
- /* establish data link */
- Q921EstablishDataLink(trunk, link->tei);
-
- /* Set layer 3 initiated */
- Q921_SET_FLAG(link, Q921_FLAG_L3_INITIATED);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, link->tei);
- }
- break;
-
- case Q921_STATE_AWAITING_ESTABLISHMENT:
- if(!Q921_IS_NT(trunk)) {
- /* Discard I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* Set layer 3 initiated */
- Q921_SET_FLAG(link, Q921_FLAG_L3_INITIATED);
- }
- break;
-
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- case Q921_STATE_TIMER_RECOVERY:
- if(!Q921_IS_NT(trunk)) {
- /* Discard I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* establish data link */
- Q921EstablishDataLink(trunk, link->tei);
-
- /* Set layer 3 initiated */
- Q921_SET_FLAG(link, Q921_FLAG_L3_INITIATED);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, link->tei);
- }
- break;
-
- default:
- break;
- }
- break;
-
- case Q921_DL_RELEASE:
- switch(link->state) {
- case Q921_STATE_TEI_ASSIGNED:
- /* send DL-RELEASE confirm */
- Q921Tx23Proc(trunk, Q921_DL_RELEASE, tei, NULL, 0);
- break;
-
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- case Q921_STATE_TIMER_RECOVERY:
- if(!Q921_IS_NT(trunk)) {
- /* Discard I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* RC = 0 */
- link->N200 = 0;
-
- /* send DISC command */
- Q921SendDISC(trunk, trunk->sapi, Q921_COMMAND(trunk), link->tei, 1);
-
- /* Stop T203, restart T200 */
- if(link->state == Q921_STATE_MULTIPLE_FRAME_ESTABLISHED) {
- Q921T203TimerStop(trunk, link->tei);
- }
- Q921T200TimerReset(trunk, link->tei);
-
- /* change state */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_RELEASE, link->tei);
- }
- break;
-
- default:
- break;
- }
- break;
-
- case Q921_DL_DATA: /* DL-DATA request */
- res = Q921EnqueueI(trunk,
- trunk->sapi,
- Q921_COMMAND(trunk),
- link->tei,
- 0,
- Mes,
- Size);
-
- if(link->state < Q921_STATE_MULTIPLE_FRAME_ESTABLISHED) {
- /* Treat as implicit DL-ESTABLISH request */
-
- /* establish data link */
- Q921EstablishDataLink(trunk, link->tei);
-
- /* Set layer 3 initiated */
- Q921_SET_FLAG(link, Q921_FLAG_L3_INITIATED);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, link->tei);
- }
- break;
-
- case Q921_DL_UNIT_DATA: /* DL-UNIT DATA request */
- res = Q921SendUN(trunk,
- trunk->sapi,
- Q921_COMMAND(trunk),
- Q921_TEI_BCAST,
- 0,
- Mes,
- Size);
- /* NOTE: Let the other side initiate link establishment */
- break;
-
- default:
- break;
- }
-
- return res;
-}
-/*****************************************************************************
-
- Function: Q921SendRR
-
- Description: Compose and send Receive Ready.
-
- Parameters: trunk trunk #
- Sapi Sapi
- cr C/R field.
- Tei Tei.
- pf P/F fiels octet 5
-
- Return Value: 0 if failed, 1 if Send.
-
-*****************************************************************************/
-
-static int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
-{
- L2UCHAR mes[25];
-
- return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x00, mes, trunk->Q921HeaderSpace+4);
-}
-
-/*****************************************************************************
-
- Function: Q921SendRNR
-
- Description: Compose and send Receive Nor Ready
-
- Parameters: trunk trunk #
- Sapi Sapi
- cr C/R field.
- Tei Tei.
- pf P/F fiels octet 5
-
- Return Value: 0 if failed, 1 if Send.
-
-*****************************************************************************/
-static int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
-{
- L2UCHAR mes[25];
-
- return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x01, mes, trunk->Q921HeaderSpace+4);
-}
-
-/*****************************************************************************
-
- Function: Q921SendREJ
-
- Description: Compose and Send Reject.
-
- Parameters: trunk trunk #
- Sapi Sapi
- cr C/R field.
- Tei Tei.
- pf P/F fiels octet 5
-
- Return Value: 0 if failed, 1 if Send.
-
-*****************************************************************************/
-static int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
-{
- L2UCHAR mes[25];
-
- return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x03, mes, trunk->Q921HeaderSpace+4);
-}
-
-/*****************************************************************************
-
- Function: Q921SendSABME
-
- Description: Compose and send SABME
-
- Parameters: trunk trunk #
- Sapi Sapi
- cr C/R field.
- Tei Tei.
- pf P fiels octet 4
-
- Return Value: 0 if failed, 1 if Send.
-
-*****************************************************************************/
-static int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
-{
- L2UCHAR mes[25];
-
- return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x0f, mes, trunk->Q921HeaderSpace+3);
-}
-
-
-/**
- * Q921Start
- * \brief Start trunk
- * \param[in] trunk pointer to Q921 data struct
- * \return > 0 on success; <= 0 on error
- */
-int Q921Start(L2TRUNK trunk)
-{
- int x, numlinks = Q921_IS_PTMP_NT(trunk) ? Q921_TEI_MAX : 1;
- struct Q921_Link *link = Q921_TRUNK_CONTEXT(trunk);
-
- if(trunk->initialized != INITIALIZED_MAGIC)
- return 0;
-
- memset(trunk->context, 0, numlinks * sizeof(struct Q921_Link));
-
- /* Common init part */
- for(x = 0; x <= numlinks; x++) {
- link = Q921_LINK_CONTEXT(trunk, x);
-
- link->state = Q921_STATE_TEI_UNASSIGNED;
- link->tei = 0;
-
- /* Initialize per-TEI I + UI queues */
- MFIFOCreate(link->UIFrameQueue, Q921MAXHDLCSPACE, 10);
- MFIFOCreate(link->IFrameQueue, Q921MAXHDLCSPACE, 10);
- MFIFOCreate(link->IFrameResendQueue, Q921MAXHDLCSPACE, 10);
- }
-
- if(Q921_IS_PTMP_TE(trunk)) {
- link->state = Q921_STATE_TEI_UNASSIGNED;
- link->tei = 0;
- }
- else if(Q921_IS_PTMP_NT(trunk)) {
- link = Q921_TRUNK_CONTEXT(trunk);
-
- link->state = Q921_STATE_TEI_ASSIGNED;
- link->tei = trunk->tei;
-
- /* clear tei map */
- memset(trunk->tei_map, 0, Q921_TEI_MAX + 1);
- }
- else {
- link->state = Q921_STATE_TEI_ASSIGNED;
- link->tei = trunk->tei;
- }
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Starting trunk %p (sapi: %d, tei: %d, mode: %s %s)\n",
- trunk,
- trunk->sapi,
- link->tei,
- Q921_IS_PTMP(trunk) ? "PTMP" : "PTP",
- Q921_IS_TE(trunk) ? "TE" : "NT");
-
- if(Q921_IS_PTP(trunk)) {
- Q921Log(trunk, Q921_LOG_DEBUG, "Sending SABME\n");
-
- return Q921SendSABME(trunk,
- trunk->sapi,
- Q921_COMMAND(trunk),
- link->tei,
- 1);
-
- } else if(Q921_IS_PTMP_NT(trunk)) {
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Revoking all TEIs\n");
-
- return Q921TeiSendRemoveRequest(trunk, Q921_TEI_BCAST); /* Revoke all TEIs in use */
- } else {
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Requesting TEI\n");
-
- return Q921TeiSendAssignRequest(trunk);
- }
-}
-
-
-/**
- * Q921Stop
- * \brief Stop trunk
- * \param[in] trunk pointer to Q921 data struct
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-int Q921Stop(L2TRUNK trunk)
-{
- struct Q921_Link *link;
- int x, numlinks;
-
- if(!trunk)
- return -1;
-
- link = Q921_TRUNK_CONTEXT(trunk);
- numlinks = Q921_IS_PTMP_NT(trunk) ? Q921_TEI_MAX : 1;
-
- if(Q921_IS_STOPPED(link))
- return 0;
-
- /* Release TEI */
- if(Q921_IS_PTMP_TE(trunk)) {
- /* send verify request */
- Q921TeiSendVerifyRequest(trunk);
-
- /* drop TEI */
- link->tei = 0;
- }
-
- /* Stop timers, stop link, flush queues */
- for(x = 0; x <= numlinks; x++) {
- Q921T200TimerStop(trunk, x);
- Q921T203TimerStop(trunk, x);
- Q921T201TimerStop(trunk, x);
-
- /* Change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_STOPPED, x);
-
- /* Flush per-tei I/UI queues */
- MFIFOClear(link->UIFrameQueue);
- MFIFOClear(link->IFrameQueue);
- MFIFOClear(link->IFrameResendQueue);
- }
- Q921T202TimerStop(trunk);
-
- /* Flush HDLC queue */
- MFIFOClear(trunk->HDLCInQueue);
-
- return 0;
-}
-
-
-/*****************************************************************************
-
- Function: Q921SendDM
-
- Description: Compose and Send DM (Disconnected Mode)
-
- Parameters: trunk trunk #
- Sapi Sapi
- cr C/R field.
- Tei Tei.
- pf F fiels octet 4
-
- Return Value: 0 if failed, 1 if Send.
-
-*****************************************************************************/
-static int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
-{
- L2UCHAR mes[25];
-
- return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x03, mes, trunk->Q921HeaderSpace+3);
-}
-
-/*****************************************************************************
-
- Function: Q921SendDISC
-
- Description: Compose and Send Disconnect
-
- Parameters: trunk trunk #
- Sapi Sapi
- cr C/R field.
- Tei Tei.
- pf P fiels octet 4
-
- Return Value: 0 if failed, 1 if Send.
-
-*****************************************************************************/
-static int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
-{
- L2UCHAR mes[25];
-
- return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x08, mes, trunk->Q921HeaderSpace+3);
-}
-
-/*****************************************************************************
-
- Function: Q921SendUA
-
- Description: Compose and Send UA
-
- Parameters: trunk trunk #
- Sapi Sapi
- cr C/R field.
- Tei Tei.
- pf F fiels octet 4
-
- Return Value: 0 if failed, 1 if Send.
-
-*****************************************************************************/
-static int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
-{
- L2UCHAR mes[25];
-
- return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x0c, mes, trunk->Q921HeaderSpace+3);
-}
-
-static int Q921SendUN(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf, L2UCHAR *mes, L2INT size)
-{
- return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x00, mes, size+trunk->Q921HeaderSpace+3);
-}
-
-
-/**
- * Q921ProcSABME
- * \brief Handle incoming SABME
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success, <= 0 on error
- */
-static int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR pf = (mes[2] & 0x10) >> 4; /* poll / final flag */
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_TEI_ASSIGNED:
- /* send UA */
- Q921SendUA(trunk,
- trunk->sapi,
- Q921_RESPONSE(trunk), /* or command? */
- tei, pf);
-
- /* clear counters */
- link->vr=0;
- link->vs=0;
- link->va=0;
-
- /* TODO: send DL-Establish indication to Q.931 */
- Q921Tx23Proc(trunk, Q921_DL_ESTABLISH, tei, NULL, 0);
-
- /* start T203 */
- Q921T203TimerStart(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, tei);
- break;
-
- case Q921_STATE_AWAITING_ESTABLISHMENT:
- /* send UA */
- Q921SendUA(trunk,
- trunk->sapi,
- Q921_RESPONSE(trunk),
- tei, pf);
-
- /* no state change */
- break;
-
- case Q921_STATE_AWAITING_RELEASE:
- /* send DM */
- Q921SendDM(trunk,
- trunk->sapi,
- Q921_RESPONSE(trunk),
- tei, pf);
-
- /* no state change */
- break;
-
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- case Q921_STATE_TIMER_RECOVERY:
- /* send UA */
- Q921SendUA(trunk,
- trunk->sapi,
- Q921_RESPONSE(trunk),
- tei, pf);
-
- /* clear exception conditions */
- Q921ResetExceptionConditions(trunk, tei);
-
- /* send MDL-Error indication */
-
- /* V(S) == V(A) ? */
- if(link->vs != link->va) {
- /* clear I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* DL-Establish indication */
- Q921Tx23Proc(trunk, Q921_DL_ESTABLISH, tei, NULL, 0);
- }
-
- /* clear counters */
- link->vr=0;
- link->vs=0;
- link->va=0;
-
- /* Stop T200, start T203 */
- Q921T200TimerStop(trunk, tei);
- Q921T203TimerStart(trunk, tei);
-
- /* state change only if in TIMER_RECOVERY state */
- if(link->state == Q921_STATE_TIMER_RECOVERY)
- Q921ChangeState(trunk, Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, tei);
- break;
-
- default:
- break;
- }
-
- return 1;
-}
-
-
-/**
- * Q921ProcDM
- * \brief Handle incoming DM
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success, <= 0 on error
- */
-static int Q921ProcDM(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR pf = (mes[2] & 0x10) >> 4; /* poll / final flag */
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_TEI_ASSIGNED:
- if(!pf) {
- /* to next state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- case Q921_STATE_AWAITING_ESTABLISHMENT:
- case Q921_STATE_AWAITING_RELEASE:
- if(pf) {
- if(link->state == Q921_STATE_AWAITING_ESTABLISHMENT) {
- /* Discard I queue */
- MFIFOClear(link->IFrameQueue);
- }
-
- /* Send DL-Release indication to Q.931 */
- Q921Tx23Proc(trunk, Q921_DL_RELEASE, tei, NULL, 0);
-
- /* Stop T200 */
- Q921T200TimerStop(trunk, tei);
-
- /* Change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_TEI_ASSIGNED, tei);
- }
- break;
-
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- if(pf) {
- /* MDL-Error indication (B) */
-
- /* no state change */
- } else {
- /* MDL-Error indication (E) */
-
- /* establish data link */
- Q921EstablishDataLink(trunk, tei);
-
- /* clear L3 initiated */
- Q921_CLEAR_FLAG(link, Q921_FLAG_L3_INITIATED);
-
- /* change state (no action?) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- case Q921_STATE_TIMER_RECOVERY:
- if(pf) {
- /* MDL Error indication (B) */
- } else {
- /* MDL Error indication (E) */
- }
-
- /* establish data link */
- Q921EstablishDataLink(trunk, tei);
-
- /* clear layer 3 initiated */
- Q921_CLEAR_FLAG(link, Q921_FLAG_L3_INITIATED);
-
- /* change state */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- break;
-
- default:
- break;
- }
-
- return 1;
-}
-
-/**
- * Q921ProcUA
- * \brief Handle incoming UA
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success, <= 0 on error
- */
-static int Q921ProcUA(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR pf = (mes[2] & 0x10) >> 4; /* poll / final flag */
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_TEI_ASSIGNED:
- case Q921_STATE_TIMER_RECOVERY:
- /* MDL Error indication (C, D) */
- Q921Log(trunk, Q921_LOG_ERROR, "Received UA frame in invalid state\n");
- break;
-
- case Q921_STATE_AWAITING_ESTABLISHMENT:
- if(pf) {
- /* TODO: other fancy stuff (see docs) */
- if(Q921_CHECK_FLAG(link, Q921_FLAG_L3_INITIATED)) { /* layer3 initiated */
- link->vr = 0;
-
- /* DL-Establish confirm */
- Q921Tx23Proc(trunk, Q921_DL_ESTABLISH_CONFIRM, tei, NULL, 0);
-
- } else if(link->vs != link->va) {
-
- /* discard I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* DL-Establish indication */
- Q921Tx23Proc(trunk, Q921_DL_ESTABLISH, tei, NULL, 0);
- }
-
- /* Stop T200, start T203 */
- Q921T200TimerStop(trunk, tei);
- Q921T203TimerStart(trunk, tei);
-
- link->vs = 0;
- link->va = 0;
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, tei);
- } else {
- /* MDL Error indication (C, D) */
- Q921Log(trunk, Q921_LOG_ERROR, "Received UA frame is not a response to a request\n");
-
- /* no state change */
- }
- break;
-
- case Q921_STATE_AWAITING_RELEASE:
- if(pf) {
- /* DL Release confirm */
- Q921Tx23Proc(trunk, Q921_DL_RELEASE_CONFIRM, tei, NULL, 0);
-
- /* Stop T200 */
- Q921T200TimerStop(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_TEI_ASSIGNED, tei);
- } else {
- /* MDL Error indication (D) */
- Q921Log(trunk, Q921_LOG_ERROR, "Received UA frame is not a response to a request\n");
-
- /* no state change */
- }
- break;
-
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- /* MDL Error indication (C, D) */
- Q921Log(trunk, Q921_LOG_ERROR, "Received UA frame in invalid state\n");
-
- /* no state change */
- break;
-
- default:
- break;
- }
-
- return 1;
-}
-
-
-/**
- * Q921ProcDISC
- * \brief Handle incoming DISC
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success, <= 0 on error
- */
-static int Q921ProcDISC(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR pf = (mes[2] & 0x10) >> 4; /* poll / final flag */
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_TEI_ASSIGNED:
- case Q921_STATE_AWAITING_ESTABLISHMENT:
- /* Send DM */
- Q921SendDM(trunk,
- trunk->sapi,
- Q921_RESPONSE(trunk),
- tei, pf);
-
- /* no state change */
- break;
-
- case Q921_STATE_AWAITING_RELEASE:
- Q921SendUA(trunk,
- trunk->sapi,
- Q921_RESPONSE(trunk),
- tei, pf);
-
- /* no state change */
- break;
-
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- case Q921_STATE_TIMER_RECOVERY:
- /* Discard I queue */
- MFIFOClear(link->IFrameQueue);
-
- /* send UA */
- Q921SendUA(trunk,
- trunk->sapi,
- Q921_RESPONSE(trunk),
- tei, pf);
-
- /* DL Release indication */
- Q921Tx23Proc(trunk, Q921_DL_RELEASE, tei, NULL, 0);
-
- /* Stop T200 */
- Q921T200TimerStop(trunk, tei);
-
- if(link->state == Q921_STATE_MULTIPLE_FRAME_ESTABLISHED) {
- /* Stop T203 */
- Q921T203TimerStop(trunk, tei);
- }
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_TEI_ASSIGNED, tei);
- break;
-
- default:
- Q921Log(trunk, Q921_LOG_ERROR, "Invalid DISC received in state \"%s\" (%d)", Q921State2Name(link->state), link->state);
- break;
- }
-
- return 1;
-}
-
-
-/**
- * Q921ProcRR
- * \brief Handle incoming RR
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success, <= 0 on error
- */
-static int Q921ProcRR(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR cr = (mes[0] & 0x02) >> 1;
- L2UCHAR pf = mes[3] & 0x01; /* poll / final flag */
- L2UCHAR nr = (mes[3] >> 1);
-// L2UCHAR sapi = (mes[0] & 0xfc) >> 2;
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- /* clear receiver peer busy */
- Q921_CLEAR_FLAG(link, Q921_FLAG_PEER_RECV_BUSY);
-
- if (Q921_IS_COMMAND(trunk, cr)) { /* if this is a command */
- if(pf) {
- /* Enquiry response */
- Q921SendEnquiryResponse(trunk, tei);
- }
- } else {
- if(pf) {
- /* MDL Error indication */
- }
- }
-
- /* */
- if(link->va <= nr && nr <= link->vs) {
-
- if(nr == link->vs) {
- /* V(A) = N(R) */
- link->va = nr;
-
- /* Stop T200, restart T203 */
- Q921T200TimerStop(trunk, tei);
- Q921T203TimerReset(trunk, tei);
-
- } else if(nr == link->va) {
-
- /* do nothing */
-
- } else {
- /* V(A) = N(R) */
- link->va = nr;
-
- /* Restart T200 */
- Q921T200TimerReset(trunk, tei);
- }
- /* no state change */
-
- } else {
- /* N(R) Error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- case Q921_STATE_TIMER_RECOVERY:
- /* clear receiver peer busy */
- Q921_CLEAR_FLAG(link, Q921_FLAG_PEER_RECV_BUSY);
-
- /* command + P? */
- if(Q921_IS_COMMAND(trunk, cr) && pf) {
- /* Enquiry response */
- Q921SendEnquiryResponse(trunk, tei);
- }
-
- /* */
- if(link->va <= nr && nr <= link->vs) {
- /* V(A) = N(R) */
- link->va = nr;
-
- if(!Q921_IS_COMMAND(trunk, cr) && pf) {
- /* Stop T200, start T203 */
- Q921T200TimerStop(trunk, tei);
- Q921T203TimerStart(trunk, tei);
-
- /* Invoke retransmission */
- Q921InvokeRetransmission(trunk, tei, nr);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, tei);
- }
- /* no state change otherwise */
- } else {
- /* N(R) Error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- default:
- break;
- }
- return 1;
-}
-
-
-/**
- * Q921ProcREJ
- * \brief Handle incoming REJ
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success, <= 0 on error
- */
-static int Q921ProcREJ(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR cr = (mes[0] & 0x02) >> 1;
- L2UCHAR pf = mes[3] & 0x01; /* poll / final flag */
- L2UCHAR nr = (mes[3] >> 1);
-// L2UCHAR sapi = (mes[0] & 0xfc) >> 2;
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- /* clear receiver peer busy */
- Q921_CLEAR_FLAG(link, Q921_FLAG_PEER_RECV_BUSY);
-
- /* command? */
- if(Q921_IS_COMMAND(trunk, cr)) {
- if(pf) {
- /* Enquiry response */
- Q921SendEnquiryResponse(trunk, tei);
- }
- } else {
- if(pf) {
- /* MDL Error indication (A) */
- }
- }
-
- /* */
- if(link->va <= nr && nr <= link->vs) {
-
- /* V(A) = N(R) */
- link->va = nr;
-
- /* Stop T200, start T203 */
- Q921T200TimerStop(trunk, tei);
- Q921T203TimerStart(trunk, tei);
-
- /* Invoke retransmission of frame >N(R) (?) */
- Q921InvokeRetransmission(trunk, tei, nr);
-
- /* no state change */
- } else {
- /* N(R) Error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- case Q921_STATE_TIMER_RECOVERY:
- /* clear receiver peer busy */
- Q921_CLEAR_FLAG(link, Q921_FLAG_PEER_RECV_BUSY);
-
- /* command + P ? */
- if(Q921_IS_COMMAND(trunk, cr) && pf) {
- /* Enquiry response */
- Q921SendEnquiryResponse(trunk, tei);
- }
-
- /* */
- if(link->va <= nr && nr <= link->vs) {
-
- /* V(A) = N(R) */
- link->va = nr;
-
- if(!Q921_IS_COMMAND(trunk, cr) && pf) {
- /* Stop T200, start T203 */
- Q921T200TimerStop(trunk, tei);
- Q921T203TimerStart(trunk, tei);
-
- /* Invoke retransmission */
- Q921InvokeRetransmission(trunk, tei, nr);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, tei);
- }
- /* no state change otherwise */
- } else {
- /* N(R) Error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- default:
- break;
- }
-
- return 1;
-}
-
-
-/**
- * Q921ProcRNR
- * \brief Handle incoming RNR
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success, <= 0 on error
- */
-static int Q921ProcRNR(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR cr = (mes[0] & 0x02) >> 1;
- L2UCHAR pf = mes[3] & 0x01; /* poll / final flag */
- L2UCHAR nr = (mes[3] >> 1);
-// L2UCHAR sapi = (mes[0] & 0xfc) >> 2;
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- /* set peer receiver busy */
- Q921_SET_FLAG(link, Q921_FLAG_PEER_RECV_BUSY);
-
- /* command? */
- if(Q921_IS_COMMAND(trunk, cr)) {
- if(pf) {
- /* Enquiry response */
- Q921SendEnquiryResponse(trunk, tei);
- }
- } else {
- if(pf) {
- /* MDL Error indication (A) */
- }
- }
-
- /* */
- if(link->va <= nr && nr <= link->vs) {
-
- /* V(A) = N(R) */
- link->va = nr;
-
- /* Stop T203, restart T200 */
- Q921T200TimerReset(trunk, tei);
- Q921T203TimerStop(trunk, tei);
-
- /* no state change */
- } else {
- /* N(R) Error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- case Q921_STATE_TIMER_RECOVERY:
- /* set peer receiver busy */
- Q921_SET_FLAG(link, Q921_FLAG_PEER_RECV_BUSY);
-
- /* command + P? */
- if(Q921_IS_COMMAND(trunk, cr) && pf) {
- /* Enquiry response */
- Q921SendEnquiryResponse(trunk, tei);
- }
-
- /* */
- if(link->va <= nr && nr <= link->vs) {
-
- /* V(A) = N(R) */
- link->va = nr;
-
- if(!Q921_IS_COMMAND(trunk, cr) && pf) {
- /* Restart T200 */
- Q921T200TimerReset(trunk, tei);
-
- /* Invoke retransmission */
- Q921InvokeRetransmission(trunk, tei, nr);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, tei);
- }
- /* no state change otherwise */
- } else {
- /* N(R) Error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- default:
- break;
- }
-
- return 1;
-}
-
-#if 0
-static int Q921SetReceiverBusy(L2TRUNK trunk)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- if(!Q921_CHECK_FLAG(link, Q921_FLAG_RECV_BUSY)) {
- /* set own receiver busy */
- Q921_SET_FLAG(link, Q921_FLAG_RECV_BUSY);
-
- /* send RR response */
- Q921SendRR(trunk, trunk->sapi, Q921_RESPONSE(trunk), link->tei, 0);
-
- /* clear ack pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- break;
-
- case Q921_STATE_TIMER_RECOVERY:
- if(!Q921_CHECK_FLAG(link, Q921_FLAG_RECV_BUSY)) {
- /* set own receiver busy */
- Q921_SET_FLAG(link, Q921_FLAG_RECV_BUSY);
-
- /* send RNR response */
- Q921SendRNR(trunk, trunk->sapi, Q921_RESPONSE(trunk), link->tei, 0);
-
- /* clear ack pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-static int Q921ClearReceiverBusy(L2TRUNK trunk)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- case Q921_STATE_TIMER_RECOVERY:
- if(Q921_CHECK_FLAG(link, Q921_FLAG_RECV_BUSY)) {
- /* clear own receiver busy */
- Q921_CLEAR_FLAG(link, Q921_FLAG_RECV_BUSY);
-
- /* send RNR response */
- Q921SendRNR(trunk, trunk->sapi, Q921_RESPONSE(trunk), link->tei, 0);
-
- /* clear ack pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-#endif
-
-static int Q921ProcIFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- /* common fields: get sapi, tei and cr */
-// L2UCHAR sapi = (mes[0] & 0xfc) >> 2;
-// L2UCHAR cr = (mes[0] & 0x02) >> 1;
- L2UCHAR tei = (mes[1] & 0xfe) >> 1;
- L2UCHAR pf = mes[3] & 0x01; /* poll / final flag */
- L2UCHAR nr = mes[3] >> 1; /* receive sequence number */
- L2UCHAR ns = mes[2] >> 1; /* send sequence number */
- L2UCHAR discard = 0;
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* Ignore I frames in earlier states */
- if(link->state < Q921_STATE_MULTIPLE_FRAME_ESTABLISHED) {
- Q921Log(trunk, Q921_LOG_NOTICE, "I frame in invalid state ignored\n");
- return 0;
- }
-
- /* Receiver busy? */
- if(Q921_CHECK_FLAG(link, Q921_FLAG_RECV_BUSY)) {
- /* discard information */
- discard = 1;
-
- if(pf) {
- /* send RNR Response */
- Q921SendRNR(trunk, trunk->sapi, Q921_RESPONSE(trunk), tei, 1);
-
- /* Clear ack pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- }
- else {
- if(ns != link->vr) {
- /* discard information */
- discard = 1;
-
- if(Q921_CHECK_FLAG(link, Q921_FLAG_REJECT) && pf) {
-
- /* Send RR response */
- Q921SendRR(trunk, trunk->sapi, Q921_RESPONSE(trunk), tei, 1);
-
- /* clear ack pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- else if(!Q921_CHECK_FLAG(link, Q921_FLAG_REJECT)){
-
- /* set reject exception */
- Q921_SET_FLAG(link, Q921_FLAG_REJECT);
-
- /* Send REJ response */
- Q921SendREJ(trunk, trunk->sapi, Q921_RESPONSE(trunk), tei, pf);
-
- /* clear ack pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- }
- else {
- /* V(R) = V(R) + 1 */
- Q921_INC_COUNTER(link->vr);
-
- /* clear reject exception */
- Q921_CLEAR_FLAG(link, Q921_FLAG_REJECT);
-
- /* DL-Data indication */
- Q921Tx23Proc(trunk, Q921_DL_DATA, tei, mes, size);
-
- if(pf) {
- /* Send RR response */
- Q921SendRR(trunk, trunk->sapi, Q921_RESPONSE(trunk), tei, 1);
-
- /* clear ack pending */
- Q921_CLEAR_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- else if(!Q921_CHECK_FLAG(link, Q921_FLAG_ACK_PENDING)) {
- /* ack pending */
-
- /* Send RR response */
- Q921SendRR(trunk, trunk->sapi, Q921_RESPONSE(trunk), tei, 0);
-
- /* set ack pending*/
- Q921_SET_FLAG(link, Q921_FLAG_ACK_PENDING);
- }
- }
- }
-
-
- switch(link->state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- if(link->va <= nr && nr <= link->vs) {
- if(Q921_CHECK_FLAG(link, Q921_FLAG_PEER_RECV_BUSY)) {
- link->va = nr;
- }
- else if(nr == link->vs) {
- /* V(A) = N(R) */
- link->va = nr;
-
- /* stop t200, restart t203 */
- Q921T200TimerStop(trunk, tei);
- Q921T203TimerReset(trunk, tei);
- }
- else if(nr != link->va) {
- /* V(A) = N(R) */
- link->va = nr;
-
- /* restart T200 */
- Q921T200TimerReset(trunk, tei);
- }
-
- /* Restart TM01 */
- if(Q921_IS_NT(trunk)) {
- Q921TM01TimerReset(trunk, tei);
- }
- }
- else {
- /* N(R) error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- case Q921_STATE_TIMER_RECOVERY:
- if(link->va <= nr && nr <= link->vs) {
- /* V(A) = N(R) */
- link->va = nr;
-
- /* Restart TM01 */
- if(Q921_IS_NT(trunk)) {
- Q921TM01TimerReset(trunk, tei);
- }
- }
- else {
- /* N(R) error recovery */
- Q921NrErrorRecovery(trunk, tei);
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_AWAITING_ESTABLISHMENT, tei);
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-
-static int Q921ProcSFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR sv = (mes[2] & 0x0c) >> 2; /* supervisory format id */
- //L2UCHAR pf = mes[3] & 0x01; /* poll / final flag */
- //L2UCHAR nr = mes[3] >> 1; /* receive sequence number */
- L2INT res = -1;
-
- switch(sv) {
- case 0x00: /* RR : Receive Ready */
- res = Q921ProcRR(trunk, mes, size);
- break;
-
- case 0x02: /* RNR : Receive Not Ready */
- res = Q921ProcRNR(trunk, mes, size);
- break;
-
- case 0x04: /* REJ : Reject */
- res = Q921ProcREJ(trunk, mes, size);
- break;
-
- default: /* Invalid / Unknown */
- Q921Log(trunk, Q921_LOG_ERROR, "Invalid S frame type %d\n", sv);
- break;
- }
-
- return res;
-}
-
-
-
-static int Q921ProcUFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR m = (mes[2] & 0xe0) >> 3 | (mes[2] & 0x0c) >> 2; /* modifier function id */
-// L2UCHAR pf = (mes[2] & 0x10) >> 4; /* poll / final flag */
- L2INT res = -1;
-
- switch(m) {
- case 0x00: /* UN : Unnumbered Information */
- if(mes[3] == Q921_LAYER_ENT_ID_TEI)
- {
- if(!Q921_IS_PTMP(trunk)) {
- /* wtf? nice try */
- return res;
- }
-
- switch(mes[6]) {
- case Q921_TEI_ID_REQUEST: /* (TE ->) NT */
- res = Q921TeiProcAssignRequest(trunk, mes, size);
- break;
-
- case Q921_TEI_ID_ASSIGNED: /* (NT ->) TE */
- case Q921_TEI_ID_DENIED:
- res = Q921TeiProcAssignResponse(trunk, mes, size);
- break;
-
- case Q921_TEI_ID_CHECKREQ: /* (NT ->) TE */
- res = Q921TeiProcCheckRequest(trunk, mes, size);
- break;
-
- case Q921_TEI_ID_CHECKRESP: /* (TE ->) NT */
- res = Q921TeiProcCheckResponse(trunk, mes, size);
- break;
-
- case Q921_TEI_ID_REMOVE: /* (NT ->) TE */
- res = Q921TeiProcRemoveRequest(trunk, mes, size);
- break;
-
- case Q921_TEI_ID_VERIFY: /* (TE ->) NT */
- res = Q921TeiProcVerifyRequest(trunk, mes, size);
- break;
-
- default: /* Invalid / Unknown */
- Q921Log(trunk, Q921_LOG_ERROR, "Invalid UN message from TEI management/endpoint\n");
- break;
- }
- }
- else if(mes[3] == Q921_LAYER_ENT_ID_Q931) {
-
- Q921Log(trunk, Q921_LOG_DEBUG, "UI Frame for Layer 3 received\n");
-
- res = Q921Tx23Proc(trunk, Q921_DL_UNIT_DATA, 0, mes, size);
- }
- break;
-
- case 0x03: /* DM : Disconnect Mode */
- res = Q921ProcDM(trunk, mes, size);
- break;
-
- case 0x08: /* DISC : Disconnect */
- res = Q921ProcDISC(trunk, mes, size);
- break;
-
- case 0x0c: /* UA : Unnumbered Acknowledgement */
- res = Q921ProcUA(trunk, mes, size);
- break;
-
- case 0x0f: /* SABME : Set Asynchronous Balanced Mode Extend */
- res = Q921ProcSABME(trunk, mes, size);
- break;
-
- case 0x11: /* FRMR : Frame Reject */
- case 0x17: /* XID : Exchange Identification */
- res = 0;
- break;
-
- default: /* Unknown / Invalid */
- Q921Log(trunk, Q921_LOG_ERROR, "Invalid U frame type: %d\n", m);
- break;
- }
-
- return res;
-}
-
-
-/*****************************************************************************
-
- Function: Q921Rx12
-
- Description: Called to process a message frame from layer 1. Will
- identify the message and call the proper 'processor' for
- layer 2 messages and forward I frames to the layer 3 entity.
-
- Q921Rx12 will check the input fifo for a message, and if a
- message exist process one message before it exits. The caller
- must either call Q921Rx12 polling or keep track on #
- messages in the queue.
-
- Parameters: trunk trunk #.
-
- Return Value: # messages processed (always 1 or 0).
-
-*****************************************************************************/
-int Q921Rx12(L2TRUNK trunk)
-{
- L2INT size; /* receive size & Q921 frame size*/
- L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size);
-
- if(smes)
- {
- struct Q921_Link *link;
- L2UCHAR sapi, tei;
- L2UCHAR *mes;
- L2INT rs;
-
- rs = size - trunk->Q921HeaderSpace;
- mes = &smes[trunk->Q921HeaderSpace];
-
- Q921LogMesg(trunk, Q921_LOG_DEBUG, 1, mes, rs, "New packet received (%d bytes)", rs);
-
- /* common fields: get sapi, tei and cr */
- sapi = (mes[0] & 0xfc) >> 2;
- tei = (mes[1] & 0xfe) >> 1;
- link = Q921_LINK_CONTEXT(trunk, tei);
-
- if(Q921_IS_PTMP_TE(trunk) && (
- (link->state >= Q921_STATE_TEI_ASSIGNED && tei != link->tei && tei != Q921_TEI_BCAST) || /* Assigned TEI: Only BCAST and directed */
- (link->state == Q921_STATE_TEI_UNASSIGNED && tei != Q921_TEI_BCAST))) /* No assigned TEI: Only BCAST */
- {
- /* Ignore Messages with foreign TEIs */
- goto out;
- }
-
- if((mes[2] & 0x01) == 0x00) { /* I frame */
- Q921ProcIFrame(trunk, mes, rs);
- }
- else if((mes[2] & 0x03) == 0x01) { /* S frame */
- Q921ProcSFrame(trunk, mes, rs);
- }
- else if((mes[2] & 0x03) == 0x03) { /* U frame */
- Q921ProcUFrame(trunk, mes, rs);
- }
- else {
- Q921Log(trunk, Q921_LOG_ERROR, "Invalid frame type: %d\n", (int)(mes[2] & 0x03));
- /* TODO: send FRMR or REJ */
- }
-
-out:
- MFIFOKillNext(trunk->HDLCInQueue);
-
- return 1;
- }
-
- return 0;
-}
-
-/*
- * Misc
- */
-/**
- * Q921SetLogCB
- * \brief Set logging callback
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] func pointer to logging callback function
- * \param[in] priv pointer to private data
- *
- * \author Stefan Knoblich
- */
-void Q921SetLogCB(L2TRUNK trunk, Q921LogCB_t func, void *priv)
-{
- if(!trunk)
- return;
-
- trunk->Q921LogProc = func;
- trunk->PrivateDataLog = priv;
-}
-
-/**
- * Q921SetLogLevel
- * \brief Set loglevel of Q.921 logging functions
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] level new loglevel
- *
- * \author Stefan Knoblich
- */
-void Q921SetLogLevel(L2TRUNK trunk, Q921LogLevel_t level)
-{
- if(!trunk)
- return;
-
- if (level < Q921_LOG_NONE) {
- level = Q921_LOG_NONE;
- } else if (level > Q921_LOG_DEBUG) {
- level = Q921_LOG_DEBUG;
- }
-
- trunk->loglevel = level;
-}
-
-
-/**
- * Q921ChangeState
- * \brief Change state, invoke neccessary actions
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] state state to change to
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921ChangeState(L2TRUNK trunk, Q921State_t state, L2UCHAR tei)
-{
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
- Q921State_t oldstate = link->state;
- int res = 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Changing state from \"%s\" (%d) to \"%s\" (%d) for TEI %d\n",
- Q921State2Name(oldstate), oldstate,
- Q921State2Name(state), state,
- tei);
-
- /*
- * generic actions (depending on the target state only)
- */
- switch(state) {
- case Q921_STATE_MULTIPLE_FRAME_ESTABLISHED:
- /* Start TM01 */
- if(Q921_IS_NT(trunk)) {
- Q921TM01TimerStart(trunk, tei);
- }
- break;
-
- default:
- break;
- }
-
- /*
- * actions that depend on type of the old -> new state transition
- */
- switch(oldstate) {
- case Q921_STATE_STOPPED:
-
- switch(state) {
- case Q921_STATE_TEI_UNASSIGNED:
- if(Q921_IS_PTMP_TE(trunk)) {
- res = Q921TeiSendAssignRequest(trunk);
- }
- break;
-
- case Q921_STATE_TEI_ASSIGNED:
- if(Q921_IS_PTMP_NT(trunk)) {
- res = Q921TeiSendRemoveRequest(trunk, Q921_TEI_BCAST);
- }
- break;
-
- default:
- break;
- }
- break;
-
- default:
- break;
- }
-
- link->state = state;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Q921ChangeState() returns %d, new state is \"%s\" (%d) for TEI %d\n", res, Q921State2Name(state), state, tei);
-
- return res;
-}
-
-/*
- * TEI Management functions
- * \note All TEI-mgmt UN frames are sent with cr = command!
- */
-static int Q921TeiSend(L2TRUNK trunk, L2UCHAR type, L2USHORT ri, L2UCHAR ai)
-{
- L2UCHAR mes[10];
- L2UCHAR offset = Q921_UFRAME_DATA_OFFSET(trunk);
-
- mes[offset++] = Q921_LAYER_ENT_ID_TEI; /* layer management entity identifier */
- mes[offset++] = (ri & 0xff00) >> 8; /* reference number upper part */
- mes[offset++] = ri & 0xff; /* reference number lower part */
- mes[offset++] = type; /* message type: Identity Request */
- mes[offset++] = ai << 1 | 0x01; /* action indicator: TEI */
-
- return Q921SendU(trunk, Q921_SAPI_TEI, Q921_COMMAND(trunk), Q921_TEI_BCAST, 0, 0x00, mes, offset);
-}
-
-
-/**
- * Q921TeiSendAssignRequest
- * \brief Ask for new TEI (TE mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \return > 0 on success, <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiSendAssignRequest(L2TRUNK trunk)
-{
- struct Q921_Link *link = Q921_TRUNK_CONTEXT(trunk);
- L2INT res;
-
- if (!Q921_IS_PTMP_TE(trunk)) /* only ptmp te mode*/
- return 0;
-
-#ifndef WIN32
- link->ri = (L2USHORT)(random() % 0xffff);
-#else
- link->ri = (L2USHORT)(rand() % 0xffff); //todo
-#endif
-
- /* send TEI assign request */
- res = Q921TeiSend(trunk, Q921_TEI_ID_REQUEST, link->ri, Q921_TEI_BCAST);
-
- /* start T202 */
- Q921T202TimerStart(trunk);
-
- return res;
-}
-
-
-/**
- * Q921TeiProcessAssignResponse
- * \brief Process assign response (TE mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiProcAssignResponse(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- struct Q921_Link *link = Q921_TRUNK_CONTEXT(trunk);
- L2UCHAR offset = Q921_UFRAME_DATA_OFFSET(trunk);
- L2USHORT ri = 0;
-
- if (!Q921_IS_PTMP_TE(trunk)) /* PTMP TE only */
- return 0;
-
- ri = (mes[offset + 1] << 8) | mes[offset + 2];
-
- if(ri != link->ri) {
- /* hmmm ..., not our response i guess */
- return 0;
- }
-
- switch(mes[offset + 3]) {
- case Q921_TEI_ID_ASSIGNED:
- /* Yay, use the new TEI and change state to assigned */
- link->tei = mes[offset + 4] >> 1;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Assigned TEI %d, setting state to TEI_ASSIGNED\n", link->tei);
-
- Q921ChangeState(trunk, Q921_STATE_TEI_ASSIGNED, link->tei);
- break;
-
- case Q921_TEI_ID_DENIED:
- /* oops, what to do now? */
- if ((mes[offset + 4] >> 1) == Q921_TEI_BCAST) {
- /* No more free TEIs? this is bad */
-
- //Q921TeiSendVerifyRequest(trunk, Q921_TEI_BCAST); /* TODO: does this work ?? */
- } else {
- /* other reason, this is fatal, shutdown link */
- }
-
- Q921Log(trunk, Q921_LOG_DEBUG, "TEI assignment has been denied, reason: %s\n",
- ((mes[offset +4] >> 1) == Q921_TEI_BCAST) ? "No free TEIs available" : "Unknown");
-
- Q921ChangeState(trunk, Q921_STATE_TEI_UNASSIGNED, link->tei);
- break;
-
- default:
- return 0;
- }
-
- /* stop T202 */
- Q921T202TimerStop(trunk);
-
- return 1;
-}
-
-
-/**
- * Q921TeiSendVerifyRequest
- * \brief Verify TEI (TE mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiSendVerifyRequest(L2TRUNK trunk)
-{
- struct Q921_Link *link = Q921_TRUNK_CONTEXT(trunk);
- L2INT res;
-
- if (!Q921_IS_PTMP_TE(trunk)) /* only ptmp te mode*/
- return 0;
-
- /* Request running? */
- if (trunk->T202)
- return 0;
-
- /* Send TEI verify request */
- res = Q921TeiSend(trunk, Q921_TEI_ID_VERIFY, link->ri, link->tei);
-
- /* start T202 */
- Q921T202TimerStart(trunk);
-
- return res;
-}
-
-
-/**
- * Q921TeiProcCheckRequest
- * \brief Process Check Request (TE mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiProcCheckRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- struct Q921_Link *link = Q921_TRUNK_CONTEXT(trunk);
- L2UCHAR offset = Q921_UFRAME_DATA_OFFSET(trunk);
- L2UCHAR tei = (mes[offset + 4] >> 1); /* action indicator => tei */
- L2INT res = 0;
-
- if (!Q921_IS_PTMP_TE(trunk)) /* ptmp te mode only */
- return 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Received TEI Check request for TEI %d\n", tei);
-
- if (tei == Q921_TEI_BCAST || tei == link->tei) {
- /*
- * Broadcast TEI check or for our assigned TEI
- */
-
- /* send TEI check reponse */
- res = Q921TeiSend(trunk, Q921_TEI_ID_CHECKRESP, link->ri, link->tei);
-
- Q921T202TimerStop(trunk);
- }
-
- return res;
-}
-
-
-/**
- * Q921TeiProcRemoveRequest
- * \brief Process remove Request (TE mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiProcRemoveRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- struct Q921_Link *link = Q921_TRUNK_CONTEXT(trunk);
- L2UCHAR offset = Q921_UFRAME_DATA_OFFSET(trunk);
- L2UCHAR tei = (mes[offset + 4] >> 1); /* action indicator => tei */
- L2INT res = 0;
-
- if (!Q921_IS_PTMP_TE(trunk)) /* ptmp te mode only */
- return 0;
-
- Q921Log(trunk, Q921_LOG_DEBUG, "Received TEI Remove request for TEI %d\n", tei);
-
- if (tei == Q921_TEI_BCAST || tei == link->tei) {
- /*
- * Broadcast TEI remove or for our assigned TEI
- */
-
- /* reset tei */
- link->tei = 0;
-
- /* change state (no action) */
- Q921ChangeState(trunk, Q921_STATE_TEI_UNASSIGNED, link->tei);
-
- /* TODO: hmm, request new one ? */
- res = Q921TeiSendAssignRequest(trunk);
- }
- return res;
-}
-
-
-/**
- * Q921TeiProcAssignRequest
- * \brief Process assign request from peer (NT mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiProcAssignRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR offset = Q921_UFRAME_DATA_OFFSET(trunk);
- L2USHORT ri = 0;
- L2UCHAR tei = 0;
-
- if (!Q921_IS_PTMP_NT(trunk)) /* PTMP NT only */
- return 0;
-
- ri = (mes[offset + 1] << 8) | mes[offset + 2];
- tei = mes[offset + 4] >> 1;
-
- if(tei == Q921_TEI_BCAST) {
- int x;
-
- /* dynamically allocate TEI */
- for(x = Q921_TEI_DYN_MIN, tei = 0; x <= Q921_TEI_MAX; x++) {
- if(!trunk->tei_map[x]) {
- tei = x;
- break;
- }
- }
- }
- else if(!(tei > 0 && tei < Q921_TEI_DYN_MIN)) {
- /* reject TEIs that are not in the static area */
- Q921TeiSendDenyResponse(trunk, 0, ri);
-
- return 0;
- }
-
- if(!tei) {
- /* no free TEI found */
- Q921TeiSendDenyResponse(trunk, Q921_TEI_BCAST, ri);
- }
- else {
- struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei);
-
- /* mark used */
- trunk->tei_map[tei] = 1;
-
- /* assign tei */
- link->tei = tei;
-
- /* put context in TEI ASSIGNED state */
- Q921ChangeState(trunk, Q921_STATE_TEI_ASSIGNED, tei);
-
- /* send assign response */
- Q921TeiSendAssignedResponse(trunk, tei, ri);
-
- /* Start T201 */
- Q921T201TimerStart(trunk, tei);
- }
- return 0;
-}
-
-/**
- * Q921TeiSendCheckRequest
- * \brief Send check request (NT mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] tei TEI to check
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiSendCheckRequest(L2TRUNK trunk, L2UCHAR tei)
-{
- L2INT res = 0;
-
- if (!Q921_IS_PTMP_NT(trunk)) /* PTMP NT only */
- return 0;
-
- /* send TEI check request */
- res = Q921TeiSend(trunk, Q921_TEI_ID_CHECKREQ, 0, tei);
-
- /* (Re-)Start T201 timer */
- Q921T201TimerStart(trunk, tei);
-
- return res;
-}
-
-/**
- * Q921TeiProcCheckResponse
- * \brief Process Check Response (NT mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiProcCheckResponse(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- struct Q921_Link *link;
- L2UCHAR offset = Q921_UFRAME_DATA_OFFSET(trunk);
- L2USHORT ri = 0;
- L2UCHAR tei = 0;
-
- if (!Q921_IS_PTMP_NT(trunk)) /* PTMP NT mode only */
- return 0;
-
- ri = (mes[offset + 1] << 8) | mes[offset + 2];
- tei = mes[offset + 4] >> 1;
-
- /* restart T201 */
- Q921T201TimerStop(trunk, tei);
-
- /* reset counter */
- link = Q921_LINK_CONTEXT(trunk, tei);
- link->N202 = 0;
-
- if(!(tei > 0 && tei < Q921_TEI_MAX) || !trunk->tei_map[tei]) {
- /* TODO: Should we send a DISC first? */
-
- /* TEI not assigned? Invalid TEI? */
- Q921TeiSendRemoveRequest(trunk, tei);
-
- /* change state */
- Q921ChangeState(trunk, Q921_STATE_STOPPED, tei);
-
- /* clear */
- memset(link, 0, sizeof(struct Q921_Link));
- } else {
- /* Start T201 */
- Q921T201TimerStart(trunk, tei);
- }
-
- return 0;
-}
-
-
-/**
- * Q921TeiProcVerifyRequest
- * \brief Process Verify Request (NT mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] mes pointer to message buffer
- * \param[in] size size of message
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiProcVerifyRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
-{
- L2UCHAR resp[25];
- L2UCHAR offset = Q921_UFRAME_DATA_OFFSET(trunk);
- L2UCHAR tei = 0;
-
- if (!Q921_IS_PTMP_NT(trunk)) /* PTMP NT mode only */
- return 0;
-
- tei = mes[offset + 4] >> 1;
-
- /* todo: handle response... verify assigned TEI */
- resp[offset + 0] = 0;
-
- return 0;
-}
-
-/**
- * Q921TeiSendDenyResponse
- * \brief Send Deny Response (NT mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiSendDenyResponse(L2TRUNK trunk, L2UCHAR tei, L2USHORT ri)
-{
- if (!Q921_IS_PTMP_NT(trunk)) /* PTMP NT only */
- return 0;
-
- return Q921TeiSend(trunk, Q921_TEI_ID_DENIED, ri, tei);
-}
-
-
-/**
- * Q921TeiSendAssignedResponse
- * \brief Send Assigned Response (NT mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] tei TEI to assign
- * \param[in] ri RI of request
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiSendAssignedResponse(L2TRUNK trunk, L2UCHAR tei, L2USHORT ri)
-{
- if (!Q921_IS_PTMP_NT(trunk)) /* PTMP NT only */
- return 0;
-
- return Q921TeiSend(trunk, Q921_TEI_ID_ASSIGNED, ri, tei);
-}
-
-/**
- * Q921TeiSendRemoveRequest
- * \brief Send Remove Request (NT mode only)
- * \param[in] trunk pointer to Q921 data struct
- * \param[in] tei TEI to remove
- * \return > 0 on success; <= 0 on error
- *
- * \author Stefan Knoblich
- */
-static int Q921TeiSendRemoveRequest(L2TRUNK trunk, L2UCHAR tei)
-{
- if (!Q921_IS_PTMP_NT(trunk)) /* PTMP NT only */
- return 0;
-
- return Q921TeiSend(trunk, Q921_TEI_ID_REMOVE, 0, tei);
-}
diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c
deleted file mode 100644
index b245c144d8..0000000000
--- a/libs/openzap/src/isdn/Q931.c
+++ /dev/null
@@ -1,888 +0,0 @@
-/*****************************************************************************
-
- FileName: Q931.c
-
- Contents: Implementation of Q.931 stack main interface functions.
- See q931.h for description.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q921.h"
-#include "Q931.h"
-#include "national.h"
-#include "DMS.h"
-#include "5ESS.h"
-
-
-/*****************************************************************************
-
- Dialect function pointers tables.
-
- The following function pointer arrays define pack/unpack functions and
- processing furnctions for the different Q.931 based dialects.
-
- The arrays are initialized with pointers to dummy functions and later
- overrided with pointers to actual functions as new dialects are added.
-
- The initial Q.931 will as an example define 2 dialects as it treats User
- and Network mode as separate ISDN dialects.
-
- The API messages Q931AddProc, Q931AddMes, Q931AddIE are used to initialize
- these table entries during system inititialization of a stack.
-
-*****************************************************************************/
-q931proc_func_t *Q931Proc[Q931MAXDLCT][Q931MAXMES];
-
-q931umes_func_t *Q931Umes[Q931MAXDLCT][Q931MAXMES];
-q931pmes_func_t *Q931Pmes[Q931MAXDLCT][Q931MAXMES];
-
-q931uie_func_t *Q931Uie[Q931MAXDLCT][Q931MAXIE];
-q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE];
-
-q931timeout_func_t *Q931Timeout[Q931MAXDLCT][Q931MAXTIMER];
-q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER];
-
-void (*Q931CreateDialectCB[Q931MAXDLCT])(L3UCHAR iDialect) = { NULL, NULL };
-
-Q931State Q931st[Q931MAXSTATE];
-
-/*****************************************************************************
-
- Core system tables and variables.
-
-*****************************************************************************/
-
-L3INT Q931L4HeaderSpace = {0}; /* header space to be ignoder/inserted */
- /* at head of each message. */
-
-L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */
-
-/*****************************************************************************
-
- Main interface callback functions.
-
-*****************************************************************************/
-
-Q931ErrorCB_t Q931ErrorProc; /* callback for error messages. */
-L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */
-
-/*****************************************************************************
-
- Function: Q931SetL4HeaderSpace
-
- Description: Set the # of bytes to be inserted/ignored at the head of
- each message. Q931 will issue a message with space for header
- and the user will use this to fill in whatever header info
- is required to support the architecture used.
-
-*****************************************************************************/
-void Q931SetL4HeaderSpace(L3INT space)
-{
- Q931L4HeaderSpace = space;
-}
-
-/*****************************************************************************
-
- Function: Q931SetL2HeaderSpace
-
- Description: Set the # of bytes to be inserted/ignored at the head of
- each message. Q931 will issue a message with space for header
- and the user will use this to fill in whatever header info
- is required to support the architecture used.
-
-*****************************************************************************/
-void Q931SetL2HeaderSpace(L3INT space)
-{
- Q931L2HeaderSpace = space;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcDummy
-
- Description: Dummy function for message processing.
-
-*****************************************************************************/
-L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c)
-{
- return Q931E_INTERNAL;
-}
-
-/*****************************************************************************
-
- Function: Q931UmesDummy
-
- Description: Dummy function for message processing
-
-*****************************************************************************/
-L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size)
-{
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: Q931UieDummy
-
- Description: Dummy function for message processing
-
-*****************************************************************************/
-L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- return Q931E_UNKNOWN_IE;
-}
-
-/*****************************************************************************
-
- Function: Q931PmesDummy
-
- Description: Dummy function for message processing
-
-*****************************************************************************/
-L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- return Q931E_UNKNOWN_MESSAGE;
-}
-
-/*****************************************************************************
-
- Function: Q931PieDummy
-
- Description: Dummy function for message processing
-
-*****************************************************************************/
-L3INT Q931PieDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- return Q931E_UNKNOWN_IE;
-}
-
-/*****************************************************************************
-
- Function: Q931TxDummy
-
- Description: Dummy function for message processing
-
-*****************************************************************************/
-L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n)
-{
- return Q931E_MISSING_CB;
-}
-
-/*****************************************************************************
-
- Function: Q931ErrorDummy
-
- Description: Dummy function for error processing
-
-*****************************************************************************/
-L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c)
-{
- return 0;
-}
-
-/*****************************************************************************
-
- Function: Q931Initialize
-
- Description: This function Initialize the stack.
-
- Will set up the trunk array, channel
- arrays and initialize Q931 function arrays before it finally
- set up EuroISDN processing with User as dialect 0 and
- Network as dialect 1.
-
- Note: Initialization of other stacks should be inserted after
- the initialization of EuroISDN.
-
-*****************************************************************************/
-void Q931Initialize()
-{
- L3INT x,y;
-
- /* Secure the callbacks to default procs */
- Q931ErrorProc = Q931ErrorDummy;
-
- /* The user will only add the message handlers and IE handlers he need,
- * so we need to initialize every single entry to a default function
- * that will throw an appropriate error if they are ever called.
- */
- for (x = 0; x < Q931MAXDLCT; x++) {
- for (y = 0; y < Q931MAXMES; y++) {
- Q931Proc[x][y] = Q931ProcDummy;
- Q931Umes[x][y] = Q931UmesDummy;
- Q931Pmes[x][y] = Q931PmesDummy;
- }
- for (y = 0; y < Q931MAXIE; y++) {
- Q931Pie[x][y] = Q931PieDummy;
- Q931Uie[x][y] = Q931UieDummy;
- }
- for (y = 0; y < Q931MAXTIMER; y++) {
- Q931Timeout[x][y] = Q931TimeoutDummy;
- Q931Timer[x][y] = 0;
- }
- }
-
- if (Q931CreateDialectCB[Q931_Dialect_Q931 + Q931_TE] == NULL)
- Q931AddDialect(Q931_Dialect_Q931 + Q931_TE, Q931CreateTE);
-
- if (Q931CreateDialectCB[Q931_Dialect_Q931 + Q931_NT] == NULL)
- Q931AddDialect(Q931_Dialect_Q931 + Q931_NT, Q931CreateNT);
-
- if (Q931CreateDialectCB[Q931_Dialect_National + Q931_TE] == NULL)
- Q931AddDialect(Q931_Dialect_National + Q931_TE, nationalCreateTE);
-
- if (Q931CreateDialectCB[Q931_Dialect_National + Q931_NT] == NULL)
- Q931AddDialect(Q931_Dialect_National + Q931_NT, nationalCreateNT);
-
- if (Q931CreateDialectCB[Q931_Dialect_DMS + Q931_TE] == NULL)
- Q931AddDialect(Q931_Dialect_DMS + Q931_TE, DMSCreateTE);
-
- if (Q931CreateDialectCB[Q931_Dialect_DMS + Q931_NT] == NULL)
- Q931AddDialect(Q931_Dialect_DMS + Q931_NT, DMSCreateNT);
-
- if (Q931CreateDialectCB[Q931_Dialect_5ESS + Q931_TE] == NULL)
- Q931AddDialect(Q931_Dialect_5ESS + Q931_TE, ATT5ESSCreateTE);
-
- if (Q931CreateDialectCB[Q931_Dialect_5ESS + Q931_NT] == NULL)
- Q931AddDialect(Q931_Dialect_5ESS + Q931_NT, ATT5ESSCreateNT);
-
- /* The last step we do is to call the callbacks to create the dialects */
- for (x = 0; x < Q931MAXDLCT; x++) {
- if (Q931CreateDialectCB[x] != NULL) {
- Q931CreateDialectCB[x]((L3UCHAR)x);
- }
- }
-}
-
-/**
- * Q931TimerTick
- * \brief Periodically called to update and check for expired timers
- * \param pTrunk Q.931 trunk
- */
-void Q931TimerTick(Q931_TrunkInfo_t *pTrunk)
-{
- struct Q931_Call *call = NULL;
- L3ULONG now = 0;
- L3INT x;
-
- /* TODO: Loop through all active calls, check timers and call timout procs
- * if timers are expired.
- * Implement a function array so each dialect can deal with their own
- * timeouts.
- */
- now = Q931GetTime();
-
- for (x = 0; x < Q931MAXCALLPERTRUNK; x++) {
- call = &pTrunk->call[x];
-
- if (!call->InUse || !call->Timer || !call->TimerID)
- continue;
-
- if (call->Timer <= now) {
- /* Stop Timer */
- Q931StopTimer(pTrunk, x, call->TimerID);
-
- /* Invoke dialect timeout callback */
- Q931Timeout[pTrunk->Dialect][call->TimerID](pTrunk, x);
- }
- }
-}
-
-/*****************************************************************************
-
- Function: Q931Rx23
-
- Description: Receive message from layer 2 (LAPD). Receiving a message
- is always done in 2 steps. First the message must be
- interpreted and translated to a static struct. Secondly
- the message is processed and responded to.
-
- The Q.931 message contains a static header that is
- interpreted in this function. The rest is interpreted
- in a sub function according to mestype.
-
- Parameters: pTrunk [IN] Ptr to trunk info.
- buf [IN] Ptr to buffer containing message.
- Size [IN] Size of message.
-
- Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
- see q931errors.h for details.
-
-*****************************************************************************/
-L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, L3INT Size)
-{
- L3UCHAR *Mes = NULL;
- L3INT RetCode = Q931E_NO_ERROR;
- Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf;
- L3INT ISize;
- L3INT IOff = 0;
- L3INT L2HSize = Q931L2HeaderSpace;
-
- switch (ind) {
- case Q921_DL_UNIT_DATA: /* DL-UNITDATA indication (UI frame, 3 byte header) */
- L2HSize = 3;
-
- case Q921_DL_DATA: /* DL-DATA indication (I frame, 4 byte header) */
- /* Reset our decode buffer */
- memset(pTrunk->L3Buf, 0, sizeof(pTrunk->L3Buf));
-
- /* L2 Header Offset */
- Mes = &buf[L2HSize];
-
- /* Protocol Discriminator */
- m->ProtDisc = Mes[IOff++];
-
- /* CRV */
- m->CRVFlag = (Mes[IOff + 1] >> 7) & 0x01;
- m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize);
-
- /* Message Type */
- m->MesType = Mes[IOff++];
-
- /* Store tei */
- m->Tei = tei;
-
- /* d'oh a little ugly but this saves us from:
- * a) doing Q.921 work in the lower levels (extracting the TEI ourselves)
- * b) adding a tei parameter to _all_ Proc functions
- */
- if (tei) {
- L3INT callIndex = 0;
-
- /* Find the call using CRV */
- RetCode = Q931FindCRV(pTrunk, m->CRV, &callIndex);
- if (RetCode == Q931E_NO_ERROR && !pTrunk->call[callIndex].Tei) {
- pTrunk->call[callIndex].Tei = tei;
- }
- }
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Received message from Q.921 (ind %d, tei %d, size %d)\nMesType: %d, CRVFlag %d (%s), CRV %d (Dialect: %d)\n", ind, m->Tei, Size,
- m->MesType, m->CRVFlag, m->CRVFlag ? "Terminator" : "Originator", m->CRV, pTrunk->Dialect);
-
- RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, IOff, Size - L2HSize);
- if (RetCode >= Q931E_NO_ERROR) {
- RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2);
- }
- break;
-
- default:
- break;
- }
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q931Tx34
-
- Description: Called from the stack to send a message to layer 4.
-
- Parameters: Mes[IN] Ptr to message buffer.
- Size[IN] Message size in bytes.
-
- Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
- see q931errors.h for details.
-
-*****************************************************************************/
-L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size)
-{
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Sending message to Layer4 (size: %d)\n", Size);
-
- if (pTrunk->Q931Tx34CBProc) {
- return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size);
- }
- return Q931E_MISSING_CB;
-}
-
-/*****************************************************************************
-
- Function: Q931Rx43
-
- Description: Receive message from Layer 4 (application).
-
- Parameters: pTrunk[IN] Trunk #.
- buf[IN] Message Pointer.
- Size[IN] Message size in bytes.
-
- Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
- see q931errors.h for details.
-
-*****************************************************************************/
-L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size)
-{
- Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
- L3INT RetCode = Q931E_NO_ERROR;
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Receiving message from Layer4 (size: %d, type: %d)\n", Size, ptr->MesType);
-
- RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Q931Rx43 return code: %d\n", RetCode);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q931Tx32
-
- Description: Called from the stack to send a message to L2. The input is
- always a non-packed message so it will first make a proper
- call to create a packed message before it transmits that
- message to layer 2.
-
- Parameters: pTrunk[IN] Trunk #
- buf[IN] Ptr to message buffer.
- Size[IN] Message size in bytes.
-
- Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
- see q931errors.h for details.
-
-*****************************************************************************/
-L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT Size)
-{
- Q931mes_Generic *ptr = (Q931mes_Generic*)Mes;
- L3INT RetCode = Q931E_NO_ERROR;
- L3INT iDialect = pTrunk->Dialect;
- L3INT Offset = bcast ? (Q931L2HeaderSpace - 1) : Q931L2HeaderSpace;
- L3INT OSize;
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Sending message to Q.921 (size: %d)\n", Size);
-
- memset(pTrunk->L2Buf, 0, sizeof(pTrunk->L2Buf));
-
- /* Call pack function through table. */
- RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Offset], &OSize);
- if (RetCode >= Q931E_NO_ERROR) {
- L3INT callIndex;
- L3UCHAR tei = 0;
-
- if (ptr->CRV) {
- /* Find the call using CRV */
- RetCode = Q931FindCRV(pTrunk, ptr->CRV, &callIndex);
- if (RetCode != Q931E_NO_ERROR)
- return RetCode;
-
- tei = pTrunk->call[callIndex].Tei;
- }
-
- if (pTrunk->Q931Tx32CBProc) {
- RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, bcast ? Q921_DL_UNIT_DATA : Q921_DL_DATA, tei, pTrunk->L2Buf, OSize + Offset);
- } else {
- RetCode = Q931E_MISSING_CB;
- }
- }
-
- return RetCode;
-}
-
-
-/*****************************************************************************
-
- Function: Q931SetError
-
- Description: Called from the stack to indicate an error.
-
- Parameters: ErrID ID of ie or message causing error.
- ErrPar1 Error parameter 1
- ErrPar2 Error parameter 2.
-
-
-*****************************************************************************/
-void Q931SetError(Q931_TrunkInfo_t *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2)
-{
- if (pTrunk->Q931ErrorCBProc) {
- pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2);
- } else {
- Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2);
- }
-}
-
-void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar)
-{
- Q931ErrorProc = Q931ErrorPar;
-}
-
-/*****************************************************************************
-
- Function: Q931CreateCRV
-
- Description: Create a CRV entry and return it's index. The function will
- locate a free entry in the call tables allocate it and
- allocate a unique CRV value attached to it.
-
- Parameters: pTrunk [IN] Trunk number
- callindex [OUT] return call table index.
-
- Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
- see q931errors.h for details.
-****************************************************************************/
-L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex)
-{
- L3INT CRV = Q931GetUniqueCRV(pTrunk);
-
- return Q931AllocateCRV(pTrunk, CRV, callIndex);
-}
-
-
-L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV)
-{
- int callIndex;
-
- if ((Q931FindCRV(pTrunk, CRV, &callIndex)) == Q931E_NO_ERROR) {
- pTrunk->call[callIndex].InUse = 0;
- return Q931E_NO_ERROR;
- }
-
- return Q931E_INVALID_CRV;
-}
-
-/*****************************************************************************
-
- Function: Q931AllocateCRV
-
- Description: Allocate a call table entry and assigns the given CRV value
- to it.
-
- Parameters: pTrunk [IN] Trunk number
- iCRV [IN] Call Reference Value.
- callindex [OUT] return call table index.
-
- Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
- see q931errors.h for details.
-
-*****************************************************************************/
-L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex)
-{
- L3INT x;
- for (x = 0; x < Q931MAXCALLPERTRUNK; x++) {
- if (!pTrunk->call[x].InUse) {
- pTrunk->call[x].CRV = iCRV;
- pTrunk->call[x].BChan = 255;
- pTrunk->call[x].State = 0; /* null state - idle */
- pTrunk->call[x].TimerID = 0; /* no timer running */
- pTrunk->call[x].Timer = 0;
- pTrunk->call[x].InUse = 1; /* mark as used */
- *callIndex = x;
- return Q931E_NO_ERROR;
- }
- }
- return Q931E_TOMANYCALLS;
-}
-
-/*****************************************************************************
-
- Function: Q931GetCallState
-
- Description: Look up CRV and return current call state. A non existing
- CRV is the same as state zero (0).
-
- Parameters: pTrunk [IN] Trunk number.
- iCRV [IN] CRV
-
- Return Value: Call State.
-
-*****************************************************************************/
-L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV)
-{
- L3INT x;
- for (x = 0; x < Q931MAXCALLPERTRUNK; x++) {
- if (pTrunk->call[x].InUse) {
- if (pTrunk->call[x].CRV == iCRV) {
- return pTrunk->call[x].State;
- }
- }
- }
- return 0; /* assume state zero for non existing CRV's */
-}
-
-/**
- * Q931StartTimer
- * \brief Start a timer
- * \param pTrunk Q.931 trunk
- * \param callindex Index of the call
- * \param iTimerID ID of timer
- * \return always 0
- */
-L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimerID)
-{
-#if 0
- L3ULONG duration = Q931Timer[pTrunk->Dialect][iTimerID];
-
- if (duration) {
- pTrunk->call[callIndex].Timer = Q931GetTime() + duration;
- pTrunk->call[callIndex].TimerID = iTimerID;
- }
-#endif
- return 0;
-}
-
-/**
- * Q931StopTimer
- * \brief Stop a timer
- * \param pTrunk Q.931 trunk
- * \param callindex Index of the call
- * \param iTimerID ID of timer
- * \return always 0
- */
-L3INT Q931StopTimer(Q931_TrunkInfo_t *pTrunk, L3INT callindex, L3USHORT iTimerID)
-{
- if (pTrunk->call[callindex].TimerID == iTimerID)
- pTrunk->call[callindex].TimerID = 0;
-
- return 0;
-}
-
-L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState)
-{
- pTrunk->call[callIndex].State = iState;
-
- return 0;
-}
-
-L3ULONG Q931GetTime()
-{
- L3ULONG tNow = 0;
- static L3ULONG tLast = 0;
-
- if (Q931GetTimeProc != NULL) {
- tNow = Q931GetTimeProc();
- if (tNow < tLast) { /* wrapped */
- /* TODO */
- }
- tLast = tNow;
- }
- return tNow;
-}
-
-void Q931SetGetTimeCB(L3ULONG (*callback)(void))
-{
- Q931GetTimeProc = callback;
-}
-
-L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex)
-{
- L3INT x;
- for (x = 0; x < Q931MAXCALLPERTRUNK; x++) {
- if (pTrunk->call[x].InUse) {
- if (pTrunk->call[x].CRV == crv) {
- *callindex = x;
- return Q931E_NO_ERROR;
- }
- }
- }
- return Q931E_INVALID_CRV;
-}
-
-
-void Q931AddDialect(L3UCHAR i, void (*callback)(L3UCHAR iD ))
-{
- if (i < Q931MAXDLCT) {
- Q931CreateDialectCB[i] = callback;
- }
-}
-
-/*****************************************************************************
- Function: Q931AddStateEntry
-
- Description: Find an empty entry in the dialects state table and add this
- entry.
-*****************************************************************************/
-void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir)
-{
- int x;
- for (x = 0; x < Q931MAXSTATE; x++) {
- if (Q931st[x].Message == 0) {
- Q931st[x].State = iState;
- Q931st[x].Message = iMes;
- Q931st[x].Direction = cDir;
- /* TODO Sort table and use bsearch */
- return;
- }
- }
-}
-
-/*****************************************************************************
- Function: Q931IsEventLegal
-
- Description: Check state table for matching criteria to indicate if this
- Message is legal in this state or not.
-
- Note: Someone write a bsearch or invent something smart here
- please - sequential is ok for now.
-*****************************************************************************/
-L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir)
-{
- int x;
- /* TODO Sort table and use bsearch */
- for (x = 0; x < Q931MAXSTATE; x++) {
- if (Q931st[x].State == iState && Q931st[x].Message == iMes &&
- Q931st[x].Direction == cDir) {
- return L3TRUE;
- }
- }
- return L3FALSE;
-}
-
-/*****************************************************************************
- Function: q931_error_to_name()
-
- Description: Check state table for matching criteria to indicate if this
- Message is legal in this state or not.
-
- Note: Someone write a bsearch or invent something smart here
- please - sequential is ok for now.
-*****************************************************************************/
-static const char *q931_error_names[] = {
- "Q931E_NO_ERROR", /* 0 */
-
- "Q931E_UNKNOWN_MESSAGE", /* -3001 */
- "Q931E_ILLEGAL_IE", /* -3002 */
- "Q931E_UNKNOWN_IE", /* -3003 */
- "Q931E_BEARERCAP", /* -3004 */
- "Q931E_HLCOMP", /* -3005 */
- "Q931E_LLCOMP", /* -3006 */
- "Q931E_INTERNAL", /* -3007 */
- "Q931E_MISSING_CB", /* -3008 */
- "Q931E_UNEXPECTED_MESSAGE", /* -3009 */
- "Q931E_ILLEGAL_MESSAGE", /* -3010 */
- "Q931E_TOMANYCALLS", /* -3011 */
- "Q931E_INVALID_CRV", /* -3012 */
- "Q931E_CALLID", /* -3013 */
- "Q931E_CALLSTATE", /* -3014 */
- "Q931E_CALLEDSUB", /* -3015 */
- "Q931E_CALLEDNUM", /* -3016 */
- "Q931E_CALLINGNUM", /* -3017 */
- "Q931E_CALLINGSUB", /* -3018 */
- "Q931E_CAUSE", /* -3019 */
- "Q931E_CHANID", /* -3020 */
- "Q931E_DATETIME", /* -3021 */
- "Q931E_DISPLAY", /* -3022 */
- "Q931E_KEYPADFAC", /* -3023 */
- "Q931E_NETFAC", /* -3024 */
- "Q931E_NOTIFIND", /* -3025 */
- "Q931E_PROGIND", /* -3026 */
- "Q931E_RESTARTIND", /* -3027 */
- "Q931E_SEGMENT", /* -3028 */
- "Q931E_SIGNAL", /* -3029 */
- "Q931E_GENERIC_DIGITS" /* -3030 */
-
-};
-
-#define Q931_MAX_ERROR 30
-
-const char *q931_error_to_name(q931_error_t error)
-{
- int index = 0;
- if ((int)error < 0) {
- index = (((int)error * -1) -3000);
- }
- if (index < 0 || index > Q931_MAX_ERROR) {
- return "";
- }
- return q931_error_names[index];
-}
-/*
- * Logging
- */
-#include
-
-L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, ...)
-{
- char buf[Q931_LOGBUFSIZE];
- L3INT len;
- va_list ap;
-
- if (!trunk->Q931LogCBProc)
- return 0;
-
- if (trunk->loglevel < level)
- return 0;
-
- va_start(ap, fmt);
-
- len = vsnprintf(buf, sizeof(buf)-1, fmt, ap);
- if (len <= 0) {
- /* TODO: error handling */
- return -1;
- }
- if (len >= sizeof(buf))
- len = sizeof(buf) - 1;
-
- buf[len] = '\0';
-
- va_end(ap);
-
- return trunk->Q931LogCBProc(trunk->PrivateDataLog, level, buf, len);
-}
-
-/**
- * Q921SetLogCB
- * \brief Set Logging callback function and private data
- */
-void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv)
-{
- trunk->Q931LogCBProc = func;
- trunk->PrivateDataLog = priv;
-}
-
-/**
- * Q921SetLogLevel
- * \brief Set Loglevel
- */
-void Q931SetLogLevel(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level)
-{
- if(!trunk)
- return;
-
- if (level < Q931_LOG_NONE) {
- level = Q931_LOG_NONE;
- } else if (level > Q931_LOG_DEBUG) {
- level = Q931_LOG_DEBUG;
- }
-
- trunk->loglevel = level;
-}
-
-/**
- * Q931TimeoutDummy
- * \brief Dummy handler for timeouts
- * \param pTrunk Q.931 trunk
- * \param callIndex Index of call
- */
-L3INT Q931TimeoutDummy(Q931_TrunkInfo_t *pTrunk, L3INT callIndex)
-{
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Timer %d of call %d (CRV: %d) timed out\n", pTrunk->call[callIndex].TimerID, callIndex, pTrunk->call[callIndex].CRV);
-
- return 0;
-}
diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c
deleted file mode 100644
index 8d05fb6d03..0000000000
--- a/libs/openzap/src/isdn/Q931StateNT.c
+++ /dev/null
@@ -1,1218 +0,0 @@
-/*****************************************************************************
-
- FileName: q931StateNT.c
-
- Contents: Q.931 State Engine for NT (Network Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q931.h"
-
-extern L3INT Q931L4HeaderSpace;
-
-/*****************************************************************************
- Function: Q931CreateNT
-
- Description: Will create the Q931 NT as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void Q931CreateNT(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingNT, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingNT, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, Q931ProcConnectNT, Q931Umes_Connect, Q931Pmes_Connect);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, Q931ProcConnectAckNT, Q931Umes_ConnectAck, Q931Pmes_ConnectAck);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressNT, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupNT, Q931Umes_Setup, Q931Pmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckNT, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeNT, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckNT, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectNT, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendNT, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckNT, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectNT, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationNT, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectNT, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseNT, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteNT, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartNT, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckNT, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationNT, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyNT, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusNT, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryNT, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentNT, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityNT, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldNT, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckNT, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectNT, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterNT, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveNT, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckNT, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectNT, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
-
- Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_FACILITY, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_REDIRECTING_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
-
- /* The following define a state machine. The point is that the Message
- * procs can when search this to find out if the message/state
- * combination is legale. If not, the proc for unexpected message apply.
- */
-
- /* TODO define state table here */
-
- /* Timer default values */
- Q931SetTimerDefault(i, Q931_TIMER_T301, 180000); /* T301: 180s */
- Q931SetTimerDefault(i, Q931_TIMER_T302, 15000); /* T302: 15s */
- Q931SetTimerDefault(i, Q931_TIMER_T303, 4000); /* T303: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T304, 20000); /* T304: 20s */
- Q931SetTimerDefault(i, Q931_TIMER_T305, 30000); /* T305: 30s */
- Q931SetTimerDefault(i, Q931_TIMER_T306, 30000); /* T306: 30s */
- Q931SetTimerDefault(i, Q931_TIMER_T307, 180000); /* T307: 180s */
- Q931SetTimerDefault(i, Q931_TIMER_T308, 4000); /* T308: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T309, 60000); /* T309: 60s */
- Q931SetTimerDefault(i, Q931_TIMER_T310, 10000); /* T310: 10s */
- Q931SetTimerDefault(i, Q931_TIMER_T312, 12000); /* T312: 12s */
- Q931SetTimerDefault(i, Q931_TIMER_T314, 4000); /* T314: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T316, 120000); /* T316: 120s */
- Q931SetTimerDefault(i, Q931_TIMER_T317, 90000); /* T317: 90s */
- Q931SetTimerDefault(i, Q931_TIMER_T320, 30000); /* T320: 30s */
- Q931SetTimerDefault(i, Q931_TIMER_T321, 30000); /* T321: 30s */
- Q931SetTimerDefault(i, Q931_TIMER_T322, 4000); /* T322: 4s */
-}
-
-/*****************************************************************************
-
- Function: Q931ProcAlertingNT
-
-*****************************************************************************/
-L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* Reset 4 sec timer. */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcCallProceedingNT
-
-*****************************************************************************/
-L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcConnectNT
-
-*****************************************************************************/
-L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcConnectAckNT
-
-*****************************************************************************/
-L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcProgressNT
-
-*****************************************************************************/
-L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSetupNT
-
- Description: Process a SETUP message.
-
- *****************************************************************************/
-L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
- L3INT rc = 0;
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Reject SETUP on existing calls */
- if (Q931GetCallState(pTrunk, pMes->CRV) != Q931_U0) {
- Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
- return Q931E_UNEXPECTED_MESSAGE;
- }
-
- /* outgoing call */
- if (iFrom == 4) {
- ret = Q931CreateCRV(pTrunk, &callIndex);
- if (ret)
- return ret;
-
- pMes->CRV = pTrunk->call[callIndex].CRV;
-
- /*
- * Outgoing SETUP message will be broadcasted in PTMP mode
- */
- ret = Q931Tx32Data(pTrunk, Q931_IS_PTP(pTrunk) ? 0 : 1, buf, pMes->Size);
- if (ret)
- return ret;
-
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- Q931SetState(pTrunk, callIndex, Q931_U1);
- }
- /* incoming call */
- else {
- /* Locate free CRV entry and store info */
- ret = Q931AllocateCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR) {
- /* Not possible to allocate CRV entry, so must reject call */
- Q931Disconnect(pTrunk, iFrom, pMes->CRV, 42);
- return ret;
- }
-
- /* store TEI in call */
- pTrunk->call[callIndex].Tei = pMes->Tei;
-
- /* Send setup indication to user */
- ret = Q931Tx34(pTrunk, (L3UCHAR*)pMes, pMes->Size);
- if (ret != Q931E_NO_ERROR) {
- return ret;
- } else {
- /* Must be full queue, meaning we can't process the call */
- /* so we must disconnect */
- Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
- return ret;
- }
-#if 0
- /* TODO: Unreachable code??? */
- /* Set state U6 */
- Q931SetState(pTrunk, callIndex, Q931_U6);
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
-#endif
- }
-
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSetupAckNT
-
- Description: Used to acknowedge a SETUP. Usually the first initial
- response recevide back used to buy some time.
-
- Note that ChanID (B Channel Assignment) might come here from
- NT side.
-
-*****************************************************************************/
-L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcResumeNT
-
-*****************************************************************************/
-L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcResumeAckNT
-
-*****************************************************************************/
-L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcResumeRejectNT
-
-*****************************************************************************/
-L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSuspendNT
-
-*****************************************************************************/
-L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSuspendAckNT
-
-*****************************************************************************/
-L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSuspendRejectNT
-
-*****************************************************************************/
-L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcInformationNT
-
-*****************************************************************************/
-L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcDisconnectNT
-
-*****************************************************************************/
-L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcReleaseNT
-
-*****************************************************************************/
-L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcReleaseCompleteNT
-
-*****************************************************************************/
-L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRestartNT
-
-*****************************************************************************/
-L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRestartAckNT
-
-*****************************************************************************/
-L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcCongestionControlNT
-
-*****************************************************************************/
-L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcInformationNT
-
-*****************************************************************************/
-L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcNotifyNT
-
-*****************************************************************************/
-L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcStatusNT
-
-*****************************************************************************/
-L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcStatusEnquiryNT
-
-*****************************************************************************/
-L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSegmentNT
-
-*****************************************************************************/
-L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/****************************************************************************/
-/******************* Q.932 - Supplementary Services *************************/
-/****************************************************************************/
-
-/*****************************************************************************
-
- Function: Q932ProcFacilityNT
-
-*****************************************************************************/
-L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcHoldNT
-
-*****************************************************************************/
-L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcHoldAckNT
-
-*****************************************************************************/
-L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcHoldRejectNT
-
-*****************************************************************************/
-L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcRegisterTE
-
-*****************************************************************************/
-L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcRetrieveNT
-
-*****************************************************************************/
-L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRetrieveAckNT
-
-*****************************************************************************/
-L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRetrieveRejectNT
-
-*****************************************************************************/
-L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here*/
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c
deleted file mode 100644
index 562dd0b458..0000000000
--- a/libs/openzap/src/isdn/Q931StateTE.c
+++ /dev/null
@@ -1,1310 +0,0 @@
-/*****************************************************************************
-
- FileName: q931StateTE.c
-
- Contents: Q.931 State Engine for TE (User Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- This reference implementation uses a process per message,
- meaning that each message must check call states. This
- is easier for dialect maintenance as each message proc
- can be replaced individually. A new TE variant only
- need to copy the Q931CreateTE and replace those procs or
- need to override.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q931.h"
-
-extern L3INT Q931L4HeaderSpace;
-
-/*****************************************************************************
- Function: Q931CreateTE
-
- Description: Will create the Q931 TE as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void Q931CreateTE(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingTE, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingTE, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, Q931ProcConnectTE, Q931Umes_Connect, Q931Pmes_Connect);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, Q931ProcConnectAckTE, Q931Umes_ConnectAck, Q931Pmes_ConnectAck);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressTE, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupTE, Q931Umes_Setup, Q931Pmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckTE, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeTE, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckTE, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectTE, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendTE, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckTE, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectTE, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationTE, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectTE, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseTE, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteTE, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartTE, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckTE, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationTE, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyTE, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusTE, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryTE, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentTE, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityTE, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldTE, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckTE, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectTE, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterTE, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveTE, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckTE, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectTE, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
-
- Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_FACILITY, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_REDIRECTING_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
-
- /* The following define a state machine. The point is that the Message
- * procs can when search this to find out if the message/state
- * combination is legale. If not, the proc for unexpected message apply.
- */
-
- /* State 0 Idle */
- Q931AddStateEntry(i, Q931_U0, Q931mes_RESUME, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_STATUS, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE_COMPLETE, 4);
-
- /* State 1 Call Initiating */
- Q931AddStateEntry(i, Q931_U1, Q931mes_DISCONNECT, 2);
- Q931AddStateEntry(i, Q931_U1, Q931mes_SETUP_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_RELEASE_COMPLETE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CONNECT, 4);
-
- /* State 2 Overlap Sending */
- Q931AddStateEntry(i, Q931_U2, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_RELEASE, 2);
-
- /* State 3 Outgoing Call Proceeding */
- Q931AddStateEntry(i, Q931_U3, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_RELEASE, 2);
-
- /* State 4 Call Delivered */
- Q931AddStateEntry(i, Q931_U4, Q931mes_CONNECT, 4);
-
- /* State 6 Call Precent */
- Q931AddStateEntry(i, Q931_U6, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CALL_PROCEEDING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE_COMPLETE, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U6, Q931mes_DISCONNECT, 4);
-
- /* State 7 Call Received */
- Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2);
-
- /* State 8 Connect request */
- Q931AddStateEntry(i, Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4);
-
- /* State 9 Incoming Call Proceeding */
- Q931AddStateEntry(i, Q931_U9, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_PROGRESS, 2);
-
- /* State 10 Active */
- Q931AddStateEntry(i, Q931_U10, Q931mes_SUSPEND, 2);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 4);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 2);
-
- /* State 11 Disconnect Request */
- Q931AddStateEntry(i, Q931_U11, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_NOTIFY, 4);
-
- /* State 12 Disconnect Ind */
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 2);
-
- /* State 15 Suspend Request */
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_REJECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_RELEASE, 4);
-
-/* TODO
- Q931AddStateEntry(i, Q931_U17,
- Q931AddStateEntry(i, Q931_U19,
- Q931AddStateEntry(i, Q931_U25,
-*/
-
- /* Timer default values */
- Q931SetTimerDefault(i, Q931_TIMER_T301, 180000); /* T301: 180s */
- Q931SetTimerDefault(i, Q931_TIMER_T302, 15000); /* T302: 15s */
- Q931SetTimerDefault(i, Q931_TIMER_T303, 4000); /* T303: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T304, 30000); /* T304: 30s */
- Q931SetTimerDefault(i, Q931_TIMER_T305, 30000); /* T305: 30s */
- Q931SetTimerDefault(i, Q931_TIMER_T308, 4000); /* T308: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T309, 60000); /* T309: 60s */
- Q931SetTimerDefault(i, Q931_TIMER_T310, 60000); /* T310: 60s */
- Q931SetTimerDefault(i, Q931_TIMER_T313, 4000); /* T313: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T314, 4000); /* T314: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T316, 120000); /* T316: 120s */
- Q931SetTimerDefault(i, Q931_TIMER_T317, 90000); /* T317: 90s */
- Q931SetTimerDefault(i, Q931_TIMER_T318, 4000); /* T318: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T319, 4000); /* T319: 4s */
- Q931SetTimerDefault(i, Q931_TIMER_T321, 30000); /* T321: 30s */
- Q931SetTimerDefault(i, Q931_TIMER_T322, 4000); /* T322: 4s */
-}
-
-/*****************************************************************************
-
- Function: Q931ProcAlertingTE
-
-*****************************************************************************/
-L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* Reset 4 sec timer. */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcCallProceedingTE
-
-*****************************************************************************/
-L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcConnectTE
-
-*****************************************************************************/
-L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- if (pTrunk->autoConnectAck) {
- Q931AckConnect(pTrunk, buf);
- }
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcConnectAckTE
-
-*****************************************************************************/
-L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcProgressTE
-
-*****************************************************************************/
-L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSetupTE
-
-*****************************************************************************/
-L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
- L3INT rc = 0;
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Reject SETUP on existing calls */
- if (Q931GetCallState(pTrunk, pMes->CRV) != Q931_U0) {
- Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
- return Q931E_UNEXPECTED_MESSAGE;
- }
-
- /* outgoing call */
- if (iFrom == 4) {
- ret = Q931CreateCRV(pTrunk, &callIndex);
- if (ret)
- return ret;
- pMes->CRV = pTrunk->call[callIndex].CRV;
-
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- if (ret)
- return ret;
-
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
-
- /* TODO: Add this back when we get the state stuff more filled out */
- /*Q931SetState(pTrunk, callIndex, Q931_U1);*/
- }
- /* incoming call */
- else {
- /* Locate free CRV entry and store info */
- ret = Q931AllocateCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR) {
- /* Not possible to allocate CRV entry, so must reject call */
- Q931Disconnect(pTrunk, iFrom, pMes->CRV, 42);
- return ret;
- }
-
- /* Send setup indication to user */
- ret = Q931Tx34(pTrunk, (L3UCHAR*)pMes, pMes->Size);
- if (ret != Q931E_NO_ERROR) {
- if (pTrunk->autoSetupAck) {
- Q931AckSetup(pTrunk, buf);
- }
- return ret;
- } else {
- /* Must be full queue, meaning we can't process the call */
- /* so we must disconnect */
- Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
- return ret;
- }
-#if 0
- /* TODO: Unreachable code??? */
- /* Set state U6 */
- Q931SetState(pTrunk, callIndex, Q931_U6);
-
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
-#endif
- }
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSetupAckTE
-
- Description: Used to acknowedge a SETUP. Usually the first initial
- response recevide back used to buy some time. L4 sending this
- should only be passed on. L2 sending this means that we set
- a new timer (and pass it to L4).
-
- Note that ChanID (B Channel Assignment) might come here from
- NT side.
-
-*****************************************************************************/
-L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcResumeTE
-
-*****************************************************************************/
-L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (Q931GetCallState(pTrunk, pMes->CRV) == Q931_U0 && iFrom ==4) {
- /* Call reference selection */
- ret = Q931CreateCRV(pTrunk, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
- pMes->CRV = pTrunk->call[callIndex].CRV;
-
- /* Send RESUME to network */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* Start timer T318 */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T318);
-
- /* set state U17 */
- Q931SetState(pTrunk, callIndex, Q931_U17);
- } else {
- return Q931E_ILLEGAL_MESSAGE;
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcResumeAckTE
-
-*****************************************************************************/
-L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcResumeRejectTE
-
-*****************************************************************************/
-L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSuspendTE
-
-*****************************************************************************/
-L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSuspendAckTE
-
-*****************************************************************************/
-L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSuspendRejectTE
-
-*****************************************************************************/
-L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcInformationTE
-
-*****************************************************************************/
-L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcDisconnectTE
-
-*****************************************************************************/
-L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Processing DISCONNECT message from %s for CRV: %d (%#hx)\n",
- iFrom == 4 ? "Local" : "Remote", pMes->CRV, pMes->CRV);
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcReleaseTE
-
-*****************************************************************************/
-L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT state = Q931GetCallState(pTrunk, pMes->CRV);
- L3INT ret = Q931E_NO_ERROR;
-
- if (iFrom == 4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (state == Q931_U0 && iFrom == 2) {
- Q931Tx34(pTrunk, buf, pMes->Size);
- ret = Q931ReleaseComplete(pTrunk, buf);
- } else {
- ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom);
- }
- if (pMes->CRV && iFrom == 2) {
- /* Find the call using CRV */
- if ((Q931FindCRV(pTrunk, pMes->CRV, &callIndex)) != Q931E_NO_ERROR)
- return ret;
- pTrunk->call[callIndex].InUse = 0;
- }
-
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcReleaseCompleteTE
-
-*****************************************************************************/
-L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- } else {
- if (pMes->CRV) {
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
- pTrunk->call[callIndex].InUse = 0;
-
- /* TODO: experimental, send RELEASE_COMPLETE message */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRestartTE
-
-*****************************************************************************/
-L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (pMes->CRV) {
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- }
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
-
- if (pTrunk->autoRestartAck) {
- Q931AckRestart(pTrunk, buf);
- }
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRestartAckTE
-
-*****************************************************************************/
-L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- if (pMes->CRV) {
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- }
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcCongestionControlTE
-
-*****************************************************************************/
-L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcInformationTE
-
-*****************************************************************************/
-L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcNotifyTE
-
-*****************************************************************************/
-L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcStatusTE
-
-*****************************************************************************/
-L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcStatusEnquiryTE
-
-*****************************************************************************/
-L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcSegmentTE
-
-*****************************************************************************/
-L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/****************************************************************************/
-/******************* Q.932 - Supplementary Services *************************/
-/****************************************************************************/
-
-/*****************************************************************************
-
- Function: Q932ProcRetrieveTE
-
-*****************************************************************************/
-L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcRetrieveTE
-
-*****************************************************************************/
-L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcRetrieveTE
-
-*****************************************************************************/
-L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcRetrieveTE
-
-*****************************************************************************/
-L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcRegisterTE
-
-*****************************************************************************/
-L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q932ProcRetrieveTE
-
-*****************************************************************************/
-L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRetrieveAckTE
-
-*****************************************************************************/
-L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
-
-/*****************************************************************************
-
- Function: Q931ProcRetrieveRejectTE
-
-*****************************************************************************/
-L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
-{
- Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
- L3INT callIndex;
- L3INT ret = Q931E_NO_ERROR;
-
- /* Find the call using CRV */
- ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
- if (ret != Q931E_NO_ERROR)
- return ret;
-
- /* TODO chack against state table for illegal or unexpected message here */
-
- /* TODO - Set correct timer here */
- Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
- if (iFrom ==4) {
- /* TODO Add proc here */
- ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
- }
- else if (iFrom == 2) {
- /* TODO Add proc here */
- ret = Q931Tx34(pTrunk, buf, pMes->Size);
- }
- return ret;
-}
diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c
deleted file mode 100644
index ed0d13836b..0000000000
--- a/libs/openzap/src/isdn/Q931api.c
+++ /dev/null
@@ -1,598 +0,0 @@
-/*****************************************************************************
-
- FileName: Q931api.c
-
- Contents: api (Application Programming Interface) functions.
- See q931.h for description.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q931.h"
-#include "memory.h"
-
-extern L3INT Q931L4HeaderSpace;
-
-/*
-L3INT Q931CreateMesIndex(L3INT mc)
-{
- if(mc < 0 || mc > 127 )
- return Q931E_INTERNAL;
-
- if(Q931MesCount >127)
- return Q931E_INTERNAL;
-
- Q931MesIndex[mc] = Q931MesCount ++;
-
- return Q931E_NO_ERROR;
-}
-*/
-/*
-L3INT Q931CreateIEIndex(L3INT iec)
-{
- if(iec < 0 || iec > 127 )
- return Q931E_INTERNAL;
-
- if(Q931IECount > 127)
- return Q931E_INTERNAL;
-
- Q931IEIndex[iec] = Q931IECount ++;
-
- return Q931E_NO_ERROR;
-}
-*/
-
-L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk,
- Q931Dialect_t Dialect,
- Q931NetUser_t NetUser,
- Q931_TrunkType_t TrunkType,
- Q931Tx34CB_t Q931Tx34CBProc,
- Q931Tx32CB_t Q931Tx32CBProc,
- Q931ErrorCB_t Q931ErrorCBProc,
- void *PrivateData32,
- void *PrivateData34)
-{
- int y, dchannel, maxchans, has_sync = 0;
-
- switch(TrunkType)
- {
- case Q931_TrType_E1:
- dchannel = 16;
- maxchans = 31;
- has_sync = 1;
- break;
-
- case Q931_TrType_T1:
- case Q931_TrType_J1:
- dchannel = 24;
- maxchans = 24;
- break;
-
- case Q931_TrType_BRI:
- case Q931_TrType_BRI_PTMP:
- dchannel = 3;
- maxchans = 3;
- break;
-
- default:
- return 0;
- }
-
- pTrunk->Q931Tx34CBProc = Q931Tx34CBProc;
- pTrunk->Q931Tx32CBProc = Q931Tx32CBProc;
- pTrunk->Q931ErrorCBProc = Q931ErrorCBProc;
- pTrunk->PrivateData32 = PrivateData32;
- pTrunk->PrivateData34 = PrivateData34;
-
- pTrunk->LastCRV = 0;
- pTrunk->Dialect = Dialect + NetUser;
- pTrunk->Enabled = 0;
- pTrunk->TrunkType = TrunkType;
- pTrunk->NetUser = NetUser;
- pTrunk->TrunkState = 0;
- pTrunk->autoRestartAck = 0;
- for(y=0; y < Q931MAXCHPERTRUNK; y++)
- {
- pTrunk->ch[y].Available = 1;
-
- if(has_sync && y == 0)
- {
- pTrunk->ch[y].ChanType = Q931_ChType_Sync;
- }
- else if(y == dchannel)
- {
- pTrunk->ch[y].ChanType = Q931_ChType_D;
- }
- else if(y > maxchans)
- {
- pTrunk->ch[y].ChanType = Q931_ChType_NotUsed;
- }
- else
- {
- pTrunk->ch[y].ChanType = Q931_ChType_B;
- }
- }
-
- for(y=0; y < Q931MAXCALLPERTRUNK; y++)
- {
- pTrunk->call[y].InUse = 0;
-
- }
- return 1;
-}
-
-void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, q931proc_func_t *Q931ProcFunc, q931umes_func_t *Q931UmesFunc, q931pmes_func_t *Q931PmesFunc)
-{
- if(Q931ProcFunc != NULL)
- Q931Proc[dialect][mes] = Q931ProcFunc;
- if(Q931UmesFunc != NULL)
- Q931Umes[dialect][mes] = Q931UmesFunc;
- if(Q931PmesFunc != NULL)
- Q931Pmes[dialect][mes] = Q931PmesFunc;
-}
-
-void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, q931pie_func_t *Q931PieProc, q931uie_func_t *Q931UieProc)
-{
- if(Q931PieProc != NULL)
- Q931Pie[dialect][iec] = Q931PieProc;
- if(Q931UieProc != NULL)
- Q931Uie[dialect][iec] = Q931UieProc;
-}
-
-void Q931SetTimeoutProc(L3UCHAR dialect, L3UCHAR timer, q931timeout_func_t *Q931TimeoutProc)
-{
- if(Q931Timeout != NULL)
- Q931Timeout[dialect][timer] = Q931TimeoutProc;
-}
-
-void Q931SetTimerDefault(L3UCHAR dialect, L3UCHAR timer, q931timer_t timeout)
-{
- Q931Timer[dialect][timer] = timeout;
-}
-
-L3INT Q931GetMesSize(Q931mes_Generic *pMes)
-{
-
- L3UCHAR *p = &pMes->buf[0];
- L3INT Size = (L3INT)(p - (L3UCHAR *)pMes);
- return Size;
-}
-
-/*****************************************************************************
-
- Function: q931AppendIE
-
- Description: Append IE to the message.
-
- Parameters: pm Ptr to message.
- pi Ptr to information element
-
- Return Value ie setting
-
-*****************************************************************************/
-
-ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi)
-{
- ie IE = 0;
- Q931mes_Generic * pMes= (Q931mes_Generic *)pm;
- Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi;
- L3INT iISize = pIE->Size;
-
- L3UCHAR *pBuf = &pMes->buf[0];
- L3INT Off = (L3INT)(pMes->Size - (pBuf - pm));
- IE = (ie)(Off | 0x8000);
-
- memcpy(&pm[pMes->Size], pi, iISize);
-
- pMes->Size += iISize;
-
- return IE;
-}
-
-/*****************************************************************************
-*****************************************************************************/
-static L3INT crv={1};
-
-L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk)
-{
- L3INT max = (Q931_IS_BRI(pTrunk)) ? Q931_BRI_MAX_CRV : Q931_PRI_MAX_CRV;
-
- crv++;
- crv = (crv <= max) ? crv : 1;
-
- return crv;
-}
-
-L3INT Q931InitMesGeneric(Q931mes_Generic *pMes)
-{
- memset(pMes, 0, sizeof(*pMes));
- pMes->ProtDisc = 0x08;
- pMes->Size = Q931GetMesSize(pMes);
-
- return 0;
-}
-
-L3INT Q931InitMesResume(Q931mes_Generic * pMes)
-{
- pMes->ProtDisc = 0x08;
- pMes->CRV = 0; /* CRV to be allocated, might be receive*/
- pMes->MesType = Q931mes_RESUME;
-
- pMes->Size = Q931GetMesSize(pMes);
- pMes->CallID = 0; /* Channel Identification */
- return 0;
-}
-
-L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes)
-{
- pMes->ProtDisc = 0x08;
- pMes->CRV = 0; /* CRV to be allocated, might be receive*/
- pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE;
-
- pMes->Size = Q931GetMesSize(pMes);
- pMes->ChanID = 0; /* Channel Identification */
- pMes->Display = 0;
- pMes->RestartInd = 0;
- pMes->RestartWin = 0;
- return 0;
-}
-
-L3INT Q931InitIEBearerCap(Q931ie_BearerCap *pIE)
-{
- pIE->IEId = Q931ie_BEARER_CAPABILITY;
- pIE->Size = sizeof(Q931ie_BearerCap);
- pIE->CodStand = 0;
- pIE->ITC = 0;
- pIE->TransMode = 0;
- pIE->ITR = 0x10;
- pIE->RateMul = 0;
-
- pIE->Layer1Ident = 0;
- pIE->UIL1Prot = 0; /* User Information Layer 1 Protocol */
- pIE->SyncAsync = 0; /* Sync/Async */
- pIE->Negot = 0;
- pIE->UserRate = 0;
- pIE->InterRate = 0; /* Intermediate Rate */
- pIE->NIConTx = 0;
- pIE->NIConRx = 0;
- pIE->FlowCtlTx = 0; /* Flow control on Tx */
- pIE->FlowCtlRx = 0; /* Flow control on Rx */
- pIE->HDR = 0;
- pIE->MultiFrame = 0; /* Multi frame support */
- pIE->Mode = 0;
- pIE->LLInegot = 0;
- pIE->Assignor = 0; /* Assignor/assignee */
- pIE->InBandNeg = 0; /* In-band/out-band negot. */
- pIE->NumStopBits = 0; /* Number of stop bits */
- pIE->NumDataBits = 0; /* Number of data bits. */
- pIE->Parity = 0;
- pIE->DuplexMode = 0;
- pIE->ModemType = 0;
- pIE->Layer2Ident = 0;
- pIE->UIL2Prot = 0; /* User Information Layer 2 Protocol */
- pIE->Layer3Ident = 0;
- pIE->UIL3Prot = 0; /* User Information Layer 3 Protocol */
- pIE->AL3Info1 = 0;
- pIE->AL3Info2 = 0;
-
- return 0;
-}
-
-L3INT Q931InitIEChanID(Q931ie_ChanID *pIE)
-{
- pIE->IEId = Q931ie_CHANNEL_IDENTIFICATION;
- pIE->Size = sizeof(Q931ie_ChanID);
- pIE->IntIDPresent = 0; /* Int. id. present */
- pIE->IntType = 0; /* Int. type */
- pIE->PrefExcl = 0; /* Pref./Excl. */
- pIE->DChanInd = 0; /* D-channel ind. */
- pIE->InfoChanSel = 0; /* Info. channel selection */
- pIE->InterfaceID = 0; /* Interface identifier */
- pIE->CodStand = 0; /* Code standard */
- pIE->NumMap = 0; /* Number/Map */
- pIE->ChanMapType = 0; /* Channel type/Map element type */
- pIE->ChanSlot = 0; /* Channel number/Slot map */
-
- return 0;
-}
-
-L3INT Q931InitIEProgInd(Q931ie_ProgInd * pIE)
-{
- pIE->IEId = Q931ie_PROGRESS_INDICATOR;
- pIE->Size = sizeof(Q931ie_ProgInd);
- pIE->CodStand = 0; /* Coding standard */
- pIE->Location = 0; /* Location */
- pIE->ProgDesc = 0; /* Progress description */
-
- return 0;
-}
-
-L3INT Q931InitIENetFac(Q931ie_NetFac * pIE)
-{
- pIE->IEId = Q931ie_NETWORK_SPECIFIC_FACILITIES;
- pIE->Size = sizeof(Q931ie_NetFac);
- pIE->LenNetID = 0; /* Length of network facilities id. */
- pIE->TypeNetID = 0; /* Type of network identification */
- pIE->NetIDPlan = 0; /* Network identification plan. */
- pIE->NetFac = 0; /* Network specific facility spec. */
- pIE->NetID[0] = 0;
- return 0;
-}
-
-L3INT Q931InitIEDisplay(Q931ie_Display * pIE)
-{
- pIE->IEId = Q931ie_DISPLAY;
- pIE->Size = sizeof(Q931ie_Display);
- pIE->Display[0] = 0;
- return 0;
-}
-
-L3INT Q931InitIEDateTime(Q931ie_DateTime * pIE)
-{
- pIE->IEId = Q931ie_DATETIME;
- pIE->Size = sizeof(Q931ie_DateTime);
- pIE->Year = 0; /* Year */
- pIE->Month = 0; /* Month */
- pIE->Day = 0; /* Day */
- pIE->Hour = 0; /* Hour */
- pIE->Minute = 0; /* Minute */
- pIE->Second = 0; /* Second */
-
- return 0;
-}
-
-L3INT Q931InitIEKeypadFac(Q931ie_KeypadFac * pIE)
-{
- pIE->IEId = Q931ie_KEYPAD_FACILITY;
- pIE->Size = sizeof(Q931ie_KeypadFac);
- pIE->KeypadFac[0] = 0;
- return 0;
-}
-
-L3INT Q931InitIESignal(Q931ie_Signal * pIE)
-{
- pIE->IEId = Q931ie_SIGNAL;
- pIE->Size = sizeof(Q931ie_Signal);
- pIE->Signal = 0;
- return 0;
-}
-
-L3INT Q931InitIECallingNum(Q931ie_CallingNum * pIE)
-{
- pIE->IEId = Q931ie_CALLING_PARTY_NUMBER;
- pIE->Size = sizeof(Q931ie_CallingNum);
- pIE->TypNum = 0; /* Type of number */
- pIE->NumPlanID = 0; /* Numbering plan identification */
- pIE->PresInd = 0; /* Presentation indicator */
- pIE->ScreenInd = 0; /* Screening indicator */
- pIE->Digit[0] = 0; /* Number digits (IA5) */
-
- return 0;
-}
-
-L3INT Q931InitIECallingSub(Q931ie_CallingSub * pIE)
-{
- pIE->IEId = Q931ie_CALLING_PARTY_SUBADDRESS;
- pIE->Size = sizeof(Q931ie_CallingSub);
- pIE->TypNum = 0; /* Type of subaddress */
- pIE->OddEvenInd = 0; /* Odd/Even indicator */
- pIE->Digit[0] = 0; /* Digits */
-
- return 0;
-}
-
-L3INT Q931InitIECalledNum(Q931ie_CalledNum * pIE)
-{
- pIE->IEId = Q931ie_CALLED_PARTY_NUMBER;
- pIE->Size = sizeof(Q931ie_CalledNum);
- pIE->TypNum = 0; /* Type of Number */
- pIE->NumPlanID = 0; /* Numbering plan identification */
- pIE->Digit[0] = 0; /* Digit (IA5) */
-
- return 0;
-}
-
-L3INT Q931InitIECalledSub(Q931ie_CalledSub * pIE)
-{
- pIE->IEId = Q931ie_CALLED_PARTY_SUBADDRESS;
- pIE->Size = sizeof(Q931ie_CalledSub);
- pIE->TypNum = 0; /* Type of subaddress */
- pIE->OddEvenInd = 0; /* Odd/Even indicator */
- pIE->Digit[0] = 0; /* Digits */
-
- return 0;
-}
-
-L3INT Q931InitIETransNetSel(Q931ie_TransNetSel * pIE)
-{
- pIE->IEId = Q931ie_TRANSIT_NETWORK_SELECTION;
- pIE->Size = sizeof(Q931ie_TransNetSel);
- pIE->Type = 0; /* Type of network identifier */
- pIE->NetIDPlan = 0; /* Network idetification plan */
- pIE->NetID[0] = 0; /* Network identification(IA5) */
-
- return 0;
-}
-
-L3INT Q931InitIELLComp(Q931ie_LLComp * pIE)
-{
- pIE->IEId = Q931ie_LOW_LAYER_COMPATIBILITY;
- pIE->Size = sizeof(Q931ie_LLComp);
-
- pIE->CodStand = 0; /* Coding standard */
- pIE->ITransCap = 0; /* Information transfer capability */
- pIE->NegotInd = 0; /* Negot indic. */
- pIE->TransMode = 0; /* Transfer Mode */
- pIE->InfoRate = 0; /* Information transfer rate */
- pIE->RateMul = 0; /* Rate multiplier */
- pIE->Layer1Ident = 0; /* Layer 1 ident. */
- pIE->UIL1Prot = 0; /* User information layer 1 protocol */
- pIE->SyncAsync = 0; /* Synch/asynch */
- pIE->Negot = 0; /* Negot */
- pIE->UserRate = 0; /* User rate */
- pIE->InterRate = 0; /* Intermediate rate */
- pIE->NIConTx = 0; /* NIC on Tx */
- pIE->NIConRx = 0; /* NIC on Rx */
- pIE->FlowCtlTx = 0; /* Flow control on Tx */
- pIE->FlowCtlRx = 0; /* Flow control on Rx */
- pIE->HDR = 0; /* Hdr/no hdr */
- pIE->MultiFrame = 0; /* Multiframe */
- pIE->ModeL1 = 0; /* Mode L1 */
- pIE->NegotLLI = 0; /* Negot. LLI */
- pIE->Assignor = 0; /* Assignor/Assignor ee */
- pIE->InBandNeg = 0; /* In-band negot. */
- pIE->NumStopBits = 0; /* Number of stop bits */
- pIE->NumDataBits = 0; /* Number of data bits */
- pIE->Parity = 0; /* Parity */
- pIE->DuplexMode = 0; /* Duplex Mode */
- pIE->ModemType = 0; /* Modem type */
- pIE->Layer2Ident = 0; /* Layer 2 ident. */
- pIE->UIL2Prot = 0; /* User information layer 2 protocol */
- pIE->ModeL2 = 0; /* ModeL2 */
- pIE->Q933use = 0; /* Q.9333 use */
- pIE->UsrSpcL2Prot = 0; /* User specified layer 2 protocol info */
- pIE->WindowSize = 0; /* Window size (k) */
- pIE->Layer3Ident = 0; /* Layer 3 ident */
- pIE->OptL3Info = 0; /* Optional layer 3 protocol info. */
- pIE->ModeL3 = 0; /* Mode of operation */
-#if 0
- pIE->ModeX25op = 0; /* Mode of operation X.25 */
-#endif
- pIE->DefPackSize = 0; /* Default packet size */
- pIE->PackWinSize = 0; /* Packet window size */
- pIE->AddL3Info = 0; /* Additional Layer 3 protocol info */
-
- return 0;
-}
-
-L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE)
-{
- pIE->IEId = Q931ie_HIGH_LAYER_COMPATIBILITY;
- pIE->Size = sizeof(Q931ie_HLComp);
-
- return 0;
-}
-
-L3INT Q931ProcUnknownMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom)
-{
- /* TODO: Unhandled paramaters */
- (void)pTrunk;
- (void)b;
- (void)iFrom;
-
- return 0;
-}
-
-L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom)
-{
- /* TODO: Unhandled paramaters */
- (void)pTrunk;
- (void)b;
- (void)iFrom;
-
- return 0;
-}
-
-L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause)
-{
- /* TODO: Unhandled paramaters */
- (void)pTrunk;
- (void)iTo;
- (void)iCRV;
- (void)iCause;
-
- return 0;
-}
-
-L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
-{
- Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
- ptr->MesType = Q931mes_RELEASE_COMPLETE;
- ptr->CRVFlag = !(ptr->CRVFlag);
- return Q931Tx32Data(pTrunk,0,buf,ptr->Size);
-}
-
-L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
-{
- L3INT RetCode;
-
- Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
- ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE;
- //if (ptr->CRV) {
- ptr->CRVFlag = !(ptr->CRVFlag);
- //}
-
- RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
-
- return RetCode;
-}
-
-L3INT Q931AckSetup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
-{
- L3INT RetCode;
-
- Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
- ptr->MesType = Q931mes_SETUP_ACKNOWLEDGE;
-
- RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
-
- return RetCode;
-}
-
-L3INT Q931AckConnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
-{
- L3INT RetCode;
-
- Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
- ptr->MesType = Q931mes_CONNECT_ACKNOWLEDGE;
-
- RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
-
- return RetCode;
-}
-
-L3INT Q931AckService(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
-{
- L3INT RetCode;
-
- Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
- ptr->MesType = Q931mes_SERVICE_ACKNOWLEDGE;
- if (ptr->CRV) {
- ptr->CRVFlag = !(ptr->CRVFlag);
- }
-
- RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
-
- return RetCode;
-}
-
-Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS)
-Q931_STR2ENUM(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count)
diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c
deleted file mode 100644
index 62312ee654..0000000000
--- a/libs/openzap/src/isdn/Q931ie.c
+++ /dev/null
@@ -1,3074 +0,0 @@
-/*****************************************************************************
-
- FileName: Q931ie.c
-
- Contents: Information Element Pack/Unpack functions.
-
- These functions will pack out a Q931 message from the bit
- packed original format into structs that are easier to process
- and pack the same structs back into bit fields when sending
- messages out.
-
- The messages contains a short for each possible IE. The MSB
- bit flags the precense of an IE, while the remaining bits
- are the offset into a buffer to find the actual IE.
-
- Each IE are supported by 3 functions:
-
- Q931Pie_XXX Pack struct into Q.931 IE
- Q931Uie_XXX Unpack Q.931 IE into struct
- Q931InitIEXXX Initialize IE (see Q931api.c).
-
- Dialect Note: This file will only contain standard DSS1 IE. Other IE as
- used in QSIG, NI2, Q.932 etc are located in separate files.
-
- See q931.h for description.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q931.h"
-
-#ifdef _MSC_VER
-#ifndef __inline__
-#define __inline__ __inline
-#endif
-#if (_MSC_VER >= 1400) /* VC8+ */
-#ifndef _CRT_SECURE_NO_DEPRECATE
-#define _CRT_SECURE_NO_DEPRECATE
-#endif
-#ifndef _CRT_NONSTDC_NO_DEPRECATE
-#define _CRT_NONSTDC_NO_DEPRECATE
-#endif
-#endif
-#ifndef strcasecmp
-#define strcasecmp(s1, s2) _stricmp(s1, s2)
-#endif
-#ifndef strncasecmp
-#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
-#endif
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
-#endif
-
-/*****************************************************************************
-
- Macro: Q931MoreIE
-
- Description: Local helper macro detecting if there is more IE space left
- based on the 3 standard parameters Octet, Off and IESpace.
- This can be used to test if the IE is completed to avoid
- that the header of the next IE is interpreted as a part of
- the current IE.
-
-*****************************************************************************/
-#define Q931MoreIE() (Octet + Off - 2 < IESize)
-
-#define Q931IESizeTest(x) {\
- if (Octet + Off - 2 != IESize) {\
- Q931SetError(pTrunk, x, Octet, Off);\
- return x;\
- }\
-}
-
-/*****************************************************************************
-
- Function: Q931ReadExt
-
- Description: Many of the octets in the standard have an MSB 'ext.1'. This
- means that the octet usually is the latest octet, but that a
- futhure standard may extend the octet. A stack must be able
- to handle such extensions by skipping the extension octets.
-
- This function will increase the offset counter with 1 for
- each octet with an MSB of zero. This will allow the stack to
- skip extensions wihout knowing anything about them.
-
- Parameters: IBuf ptr to octet array.
- Off Starting offset counter
-
- Return Value: New offset value.
-
-*****************************************************************************/
-
-L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off)
-{
- L3INT c = 0;
- while ((IBuf[c] & 0x80) == 0) {
- c++;
- }
- return Off + c;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_BearerCap
-
- Description: Unpack a bearer capability ie.
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-
-L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_BearerCap *pie = (Q931ie_BearerCap*)OBuf;
- ie *pIE = &pMsg->BearerCap;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->CodStand = ieGetOctet((IBuf[Octet] & 0x60) >> 5);
- pie->ITC = ieGetOctet(IBuf[Octet] & 0x1f);
- Off = Q931ReadExt(&IBuf[Octet], Off);
- Octet++;
-
- /* Octet 4 */
- pie->TransMode = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5);
- pie->ITR = ieGetOctet(IBuf[Octet + Off] & 0x1f);
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- Octet++;
-
- /* Octet 4.1. Rate multiplier is only present if ITR = Multirate */
- if (pie->ITR == 0x18) {
- pie->RateMul = ieGetOctet(IBuf[Octet + Off] & 0x7f);
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- Off ++;
- }
-
- /* Octet 5 */
- if ((IBuf[Octet + Off] & 0x60) == 0x20 && Q931MoreIE()) {
- pie->Layer1Ident = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5);
- pie->UIL1Prot = ieGetOctet(IBuf[Octet + Off] & 0x1f);
- Octet++;
-
- /* Octet 5a. The octet may be present if ITC is unrestrictd digital info
- * and UIL1Prot is either V.110, I.460 and X.30 or V.120. It may also
- * be present if ITC = 3.1 kHz audio and UIL1Prot is G.711.
- * Bit 8 of Octet 5 = 0 indicates that 5a is present.
- */
-
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- if (((pie->ITC == 0x08) && (pie->UIL1Prot == 0x01 || pie->UIL1Prot == 0x08))
- || ((pie->ITC == 0x10) && (pie->UIL1Prot == 0x02 || pie->UIL1Prot == 0x03))) {
- pie->SyncAsync = ieGetOctet((IBuf[Octet + Off] & 0x40) >> 6);
- pie->Negot = ieGetOctet((IBuf[Octet + Off] & 0x20) >> 5);
- pie->UserRate = ieGetOctet(IBuf[Octet + Off] & 0x1f);
- Off ++;
- }
- else {
- /* We have detected bit 8 = 0, but no setting that require the */
- /* additional octets ??? */
- Q931SetError(pTrunk, Q931E_BEARERCAP, 5,Off);
- return Q931E_BEARERCAP;
- }
-
- /* Octet 5b. Two different structures used. */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- if (pie->UIL1Prot == 0x01) { /* ITU V.110, I.460 and X.30 */
- pie->InterRate = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5);
- pie->NIConTx = ieGetOctet((IBuf[Octet + Off] & 0x10) >> 4);
- pie->NIConRx = ieGetOctet((IBuf[Octet + Off] & 0x08) >> 3);
- pie->FlowCtlTx = ieGetOctet((IBuf[Octet + Off] & 0x04) >> 2);
- pie->FlowCtlRx = ieGetOctet((IBuf[Octet + Off] & 0x20) >> 1);
- Off++;
- }
- else if (pie->UIL1Prot == 0x08) { /* ITU V.120 */
- pie->HDR = ieGetOctet((IBuf[Octet + Off] & 0x40) >> 6);
- pie->MultiFrame = ieGetOctet((IBuf[Octet + Off] & 0x20) >> 5);
- pie->Mode = ieGetOctet((IBuf[Octet + Off] & 0x10) >> 4);
- pie->LLInegot = ieGetOctet((IBuf[Octet + Off] & 0x08) >> 3);
- pie->Assignor = ieGetOctet((IBuf[Octet + Off] & 0x04) >> 2);
- pie->InBandNeg = ieGetOctet((IBuf[Octet + Off] & 0x02) >> 1);
- Off++;
- }
- else {
- Q931SetError(pTrunk,Q931E_BEARERCAP, 5,Off);
- return Q931E_BEARERCAP;
- }
-
- /* Octet 5c */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->NumStopBits = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5);
- pie->NumDataBits = ieGetOctet((IBuf[Octet + Off] & 0x18) >> 3);
- pie->Parity = ieGetOctet(IBuf[Octet + Off] & 0x07);
- Off++;
-
- /* Octet 5d */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->DuplexMode = ieGetOctet((IBuf[Octet + Off] & 0x40) >> 6);
- pie->ModemType = ieGetOctet(IBuf[Octet + Off] & 0x3f);
- Off ++;
- }
- }
- }
- }
- }
-
- /* Octet 6 */
- if ((IBuf[Octet + Off] & 0x60) == 0x40 && Q931MoreIE()) {
- pie->Layer2Ident = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5);
- pie->UIL2Prot = ieGetOctet(IBuf[Octet + Off] & 0x1f);
-
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- Octet ++;
- }
-
- /* Octet 7 */
- if ((IBuf[Octet + Off] & 0x60) == 0x60 && Q931MoreIE()) {
- pie->Layer3Ident = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5);
- pie->UIL3Prot = ieGetOctet(IBuf[Octet + Off] & 0x1f);
- Octet++;
-
- /* Octet 7a */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- if (pie->UIL3Prot == 0x0c) {
- pie->AL3Info1 = ieGetOctet(IBuf[Octet + Off] & 0x0f);
- Off++;
-
- /* Octet 7b */
- if (IsQ931Ext(IBuf[Octet + Off])) {
- pie->AL3Info2 = ieGetOctet(IBuf[Octet + Off] & 0x0f);
- Off++;
- }
- }
- else {
- Q931SetError(pTrunk,Q931E_BEARERCAP, 7, Off);
- return Q931E_BEARERCAP;
-
- }
- }
- }
-
- Q931IESizeTest(Q931E_BEARERCAP);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_BearerCap);
- pie->Size = sizeof(Q931ie_BearerCap);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_BearerCap
-
- Description: Packing a Q.931 Bearer Capability element from a generic
- struct into a packed octet structure in accordance with the
- standard.
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-
-L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_BearerCap *pIE = (Q931ie_BearerCap*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet; /* remember current offset */
- L3INT li;
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Encoding Bearer Capability IE\n");
-
- OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ;
- li = (*Octet)++; /* remember length position */
-
- /* Octet 3 - Coding standard / Information transfer capability */
- OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | (pIE->ITC & 0x1f);
-
- /* Octet 4 - Transfer mode / Information transfer rate */
- OBuf[(*Octet)++] = 0x80 | ((pIE->TransMode << 5) & 0x60) | (pIE->ITR & 0x1f);
-
- if (pIE->ITR == 0x18) {
- /* Octet 4.1 - Rate Multiplier */
- OBuf[(*Octet)++] = 0x80 | (pIE->RateMul & 0x7f);
- }
-
- /* Octet 5 - Layer 1 Ident / User information layer 1 protocol */
- if (pIE->Layer1Ident == 0x01) {
- if (((pIE->ITC == 0x08) && (pIE->UIL1Prot == 0x01 || pIE->UIL1Prot == 0x08)) ||
- ((pIE->ITC == 0x10) && (pIE->UIL1Prot == 0x02 || pIE->UIL1Prot == 0x03))) {
- OBuf[(*Octet)++] = 0x00 | ((pIE->Layer1Ident << 5) & 0x60) | (pIE->UIL1Prot & 0x15);
-
- /* Octet 5a - SyncAsync/Negot/UserRate */
- OBuf[(*Octet)++] = 0x00 | ((pIE->SyncAsync << 6) & 0x40) | ((pIE->Negot << 5) & 0x20) | (pIE->UserRate & 0x1f);
-
- /* Octet 5b - one of two types */
- if (pIE->UIL1Prot == 0x01) { /* ITU V.110, I.460 and X.30 */
- /* Octet 5b - Intermed rate/ Nic on Tx/Nix on Rx/FlowCtlTx/FlowCtlRx */
- OBuf[(*Octet)++] = 0x00
- | ((pIE->InterRate << 6) & 0x60)
- | ((pIE->NIConTx << 4) & 0x10)
- | ((pIE->NIConRx << 3) & 0x08)
- | ((pIE->FlowCtlTx << 2) & 0x04)
- | ((pIE->FlowCtlRx << 1) & 0x02);
- }
- else if (pIE->UIL1Prot == 0x08) { /* ITU V.120 */
- /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/
- OBuf[(*Octet)++] = 0x00
- | ((pIE->InterRate << 6) & 0x60)
- | ((pIE->MultiFrame << 5) & 0x20)
- | ((pIE->Mode << 4) & 0x10)
- | ((pIE->LLInegot << 3) & 0x08)
- | ((pIE->Assignor << 2) & 0x04)
- | ((pIE->InBandNeg << 1) & 0x02);
- }
-
- /* Octet 5c - NumStopBits/NumStartBits/Parity */
- OBuf[(*Octet)++] = 0x00
- | ((pIE->NumStopBits << 5) & 0x60)
- | ((pIE->NumDataBits << 3) & 0x18)
- | (pIE->Parity & 0x07);
-
- /* Octet 5d - Duplex Mode/Modem Type */
- OBuf[(*Octet)++] = 0x80 | ((pIE->DuplexMode << 6) & 0x40) | (pIE->ModemType & 0x3f);
- }
- else {
- OBuf[(*Octet)++] = 0x80 | ((pIE->Layer1Ident << 5) & 0x60) | (pIE->UIL1Prot & 0x1f);
- }
- }
-
- /* Octet 6 - Layer2Ident/User information layer 2 prtocol */
- if (pIE->Layer2Ident == 0x02) {
- OBuf[(*Octet)++] = 0x80 | ((pIE->Layer2Ident << 5) & 0x60) | (pIE->UIL2Prot & 0x1f);
- }
-
- /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */
- if (pIE->Layer3Ident == 0x03) {
- if (pIE->UIL3Prot == 0x0c) {
- OBuf[(*Octet)++] = 0x00 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f);
-
- /* Octet 7a - Additional information layer 3 msb */
- OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1 & 0x0f);
-
- /* Octet 7b - Additional information layer 3 lsb */
- OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2 & 0x0f);
- }
- else {
- OBuf[(*Octet)++] = 0x80 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f);
- }
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_CallID
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_CallID *pie = (Q931ie_CallID*)OBuf;
- ie *pIE = &pMsg->CallID;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- do {
- pie->CallId[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- x++;
- } while (Q931MoreIE());
-
- Q931IESizeTest(Q931E_CALLID);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CallID) + x - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_CallID
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-
-L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_CallID *pIE = (Q931ie_CallID*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;/* remember current offset */
- L3INT li;
- L3INT sCI = pIE->Size - sizeof(Q931ie_CallID) + 1;
- L3INT x;
-
- OBuf[(*Octet)++] = Q931ie_CALL_IDENTITY ;
- li = (*Octet)++; /* remember length position */
-
- for (x = 0; x < sCI; x++) {
- OBuf[(*Octet)++] = pIE->CallId[x];
- }
-
- OBuf[(*Octet) - 1] |= 0x80; /* set complete flag at last octet*/
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_CallState
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_CallState *pie = (Q931ie_CallState*)OBuf;
- ie *pIE = &pMsg->CallState;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->CodStand = (IBuf[Octet + Off] >> 6) & 0x03;
- pie->CallState = IBuf[Octet + Off] & 0x3f;
- Octet++;
-
- Q931IESizeTest(Q931E_CALLSTATE);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CallState);
- pie->Size = sizeof(Q931ie_CallState);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_CallState
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_CallState *pIE = (Q931ie_CallState*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet; /* remember current offset */
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_CALL_STATE;
- li = (*Octet)++; /* remember length position */
-
- OBuf[(*Octet)++] = (pIE->CodStand << 6) | (pIE->CallState & 0x3f);
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_CalledSub
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_CalledSub *pie = (Q931ie_CalledSub*)OBuf;
- ie *pIE = &pMsg->CalledSub;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x;
- L3INT IESize;
-
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->TypNum = (IBuf[Octet + Off] >> 4) & 0x07;
- pie->OddEvenInd = (IBuf[Octet + Off] >> 3) & 0x01;
- Octet++;
-
- /* Octet 4 */
- x = 0;
- do {
- pie->Digit[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- x++;
- } while (Q931MoreIE() && x < 20);
-
- Q931IESizeTest(Q931E_CALLEDSUB);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_CalledSub
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_CalledSub *pIE = (Q931ie_CalledSub*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT sN = pIE->Size - sizeof(Q931ie_CalledSub) + 1;
- L3INT x;
-
- /* Octet 1 */
- OBuf[(*Octet)++] = Q931ie_CALLED_PARTY_SUBADDRESS;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->OddEvenInd << 3);
-
- /* Octet 4 */
- for (x = 0; xDigit[x];
- }
-
- OBuf[(*Octet) - 1] |= 0x80; /* Terminate bit */
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_CalledNum
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_CalledNum *pie = (Q931ie_CalledNum*)OBuf;
- ie *pIE = &pMsg->CalledNum;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x;
- L3INT IESize; /* # digits in this case */
-
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->TypNum = (IBuf[Octet + Off] >> 4) & 0x07;
- pie->NumPlanID = IBuf[Octet + Off] & 0x0f;
- Octet++;
-
- /* Octet 4*/
- x = 0;
- do {
- pie->Digit[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- x++;
- } while ((IBuf[Octet + Off]&0x80) == 0 && Q931MoreIE());
-
- pie->Digit[x] = '\0';
-
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_CalledNum
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_CalledNum *pIE = (Q931ie_CalledNum*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT sN = pIE->Size - sizeof(Q931ie_CalledNum);
- L3INT x;
-
- /* Octet 1 */
- OBuf[(*Octet)++] = Q931ie_CALLED_PARTY_NUMBER;
-
- /* Octet 2 */
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->NumPlanID);
-
- /* Octet 4 */
- for (x = 0; xDigit[x];
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_CallingNum
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_CallingNum *pie = (Q931ie_CallingNum*)OBuf;
- ie *pIE = &pMsg->CallingNum;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x;
- L3INT IESize;
-
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->TypNum = (IBuf[Octet + Off] >> 4) & 0x07;
- pie->NumPlanID = IBuf[Octet + Off] & 0x0f;
-
- /* Octet 3a */
- if ((IBuf[Octet + Off] & 0x80) == 0) {
- Off++;
- pie->PresInd = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->ScreenInd = IBuf[Octet + Off] & 0x03;
- }
- Octet++;
-
- /* Octet 4 */
- x = 0;
- while (Q931MoreIE()) {
- pie->Digit[x++] = IBuf[Octet + Off] & 0x7f;
-
- if ((IBuf[Octet + Off] & 0x80) != 0) {
- break;
- }
- Off++;
- }
- pie->Digit[x] = '\0';
-
- Q931IESizeTest(Q931E_CALLINGNUM);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_CallingNum
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_CallingNum *pIE = (Q931ie_CallingNum*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT sN = pIE->Size - sizeof(Q931ie_CallingNum);
- L3INT x;
-
- /* Octet 1 */
- OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_NUMBER;
-
- /* Octet 2 */
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x00 | (pIE->TypNum << 4) | (pIE->NumPlanID);
-
- /* Octet 4 */
- OBuf[(*Octet)++] = 0x80;
-
- /* Octet 5 */
- for (x = 0; xDigit[x];
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_CallingSub
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_CallingSub *pie = (Q931ie_CallingSub*)OBuf;
- ie *pIE = &pMsg->CallingSub;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x;
- L3INT IESize;
-
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->TypNum = (IBuf[Octet + Off] >> 4) & 0x07;
- pie->OddEvenInd = (IBuf[Octet + Off] >> 3) & 0x01;
- Octet++;
-
- /* Octet 4*/
- x = 0;
- do {
- pie->Digit[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- x++;
- } while (Q931MoreIE() && x < 20);
-
- Q931IESizeTest(Q931E_CALLINGSUB);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_CallingSub
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_CallingSub *pIE = (Q931ie_CallingSub*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT sN = pIE->Size - sizeof(Q931ie_CallingSub) + 1;
- L3INT x;
-
- /* Octet 1 */
- OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_SUBADDRESS;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->OddEvenInd << 3);
-
- /* Octet 4 */
- for (x = 0; xDigit[x];
- }
-
- OBuf[(*Octet) - 1] |= 0x80; /* Terminate bit */
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_Cause
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_Cause *pie = (Q931ie_Cause*)OBuf;
- ie *pIE = &pMsg->Cause;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2*/
- IESize = IBuf[Octet++];
-
- /* Octet 3*/
- pie->CodStand = (IBuf[Octet + Off]>>5) & 0x03;
- pie->Location = IBuf[Octet + Off] & 0x0f;
-
- /* Octet 3a */
- if ((IBuf[Octet + Off] & 0x80) == 0) {
- Off++;
- pie->Recom = IBuf[Octet + Off] & 0x7f;
- }
- Octet++;
-
- /* Octet 4 */
- pie->Value = IBuf[Octet + Off] & 0x7f;
- Octet++;
-
- /* Consume optional Diagnostic bytes */
- while (Q931MoreIE()) {
- Off++;
- };
-
- Q931IESizeTest(Q931E_CAUSE);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_Cause);
- pie->Size = sizeof(Q931ie_Cause);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_Cause
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_Cause *pIE = (Q931ie_Cause*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_CAUSE;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | pIE->Location;
-
- /* Octet 3a - currently not supported in send */
-
- /* Octet 4 */
- OBuf[(*Octet)++] = 0x80 | pIE->Value;
-
- /* Octet 5 - diagnostics not supported in send */
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_CongLevel
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf;
- ie *pIE = &pMsg->CongestionLevel;
- L3INT Off = 0;
- L3INT Octet = 0;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet] & 0xf0;
- pie->CongLevel = IBuf[Octet] & 0x0f;
- Octet ++;
-
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CongLevel);
- pie->Size = sizeof(Q931ie_CongLevel);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_CongLevel
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_CongLevel *pIE = (Q931ie_CongLevel*)IBuf;
- L3INT rc = 0;
- /* L3INT Beg = *Octet; */
-
- OBuf[(*Octet)++] = Q931ie_CONGESTION_LEVEL | pIE->CongLevel;
-
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_ChanID
-
- Parameters: IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_ChanID *pie = (Q931ie_ChanID*)OBuf;
- ie *pIE = &pMsg->ChanID;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-//18 04 e1 80 83 01
- *pIE = 0;
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Decoding ChanID IE\n");
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->IntIDPresent = (IBuf[Octet] >> 6) & 0x01;
- pie->IntType = (IBuf[Octet] >> 5) & 0x01;
- pie->PrefExcl = (IBuf[Octet] >> 3) & 0x01;
- pie->DChanInd = (IBuf[Octet] >> 2) & 0x01;
- pie->InfoChanSel = IBuf[Octet] & 0x03;
-
- Off = Q931ReadExt(&IBuf[Octet++], Off);
-
- /* Octet 3.1 */
- if (pie->IntIDPresent) {
- pie->InterfaceID = IBuf[Octet + Off] & 0x7f;
-
- /* Temp fix. Interface id can be extended using the extension bit */
- /* this will read the octets, but do nothing with them. this is done */
- /* because the usage of this field is a little unclear */
- /* 30.jan.2001/JVB */
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- Off++;
- }
-
- if ((Octet + Off - 2) != IESize) {
- /* Octet 3.2 */
- if (pie->IntType == 1) { /* PRI etc */
- pie->CodStand = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->NumMap = (IBuf[Octet + Off] >> 4) & 0x01;
- pie->ChanMapType = IBuf[Octet + Off] & 0x0f;
- Off++;
-
- /* Octet 3.3 */
- /* Temp fix. Assume B channel. H channels not supported */
- pie->ChanSlot = IBuf[Octet + Off] & 0x7f;
-
- /* Some dialects don't follow the extension coding properly for this, but this should be safe for all */
- if ((Octet + Off - 1) != IESize) {
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- }
- Off++;
- }
- }
-
- Q931IESizeTest(Q931E_CHANID);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_ChanID);
- pie->Size = sizeof(Q931ie_ChanID);
-
- if (pTrunk->loglevel == Q931_LOG_DEBUG) {
- const char *iface;
- char tmp[100] = "";
-
- if (!pie->IntType) {
- switch (pie->InfoChanSel) {
- case 0x0:
- iface = "None";
- break;
- case 0x1:
- iface = "B1";
- break;
- case 0x2:
- iface = "B2";
- break;
- default:
- iface = "Any Channel";
- }
-
- snprintf(tmp, sizeof(tmp)-1, "InfoChanSel: %d (%s)", pie->InfoChanSel, iface);
- }
-
- Q931Log(pTrunk, Q931_LOG_DEBUG,
- "\n-------------------------- Q.931 Channel ID ------------------------\n"
- " Pref/Excl: %s, Interface Type: %s\n"
- " %s\n"
- "--------------------------------------------------------------------\n\n",
- ((pie->PrefExcl) ? "Preferred" : "Exclusive"),
- ((pie->IntType) ? "PRI/Other" : "BRI"),
- tmp);
- }
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_ChanID
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_ChanID *pIE = (Q931ie_ChanID*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet; /* remember current offset */
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION;
- li = (*Octet)++; /* remember length position */
-
- /* Octet 3 flags & BRI chan # */
- OBuf[(*Octet)++] = 0x80
- | ((pIE->IntIDPresent << 6) & 0x40)
- | ((pIE->IntType << 5) & 0x20)
- | ((pIE->PrefExcl << 3) & 0x08)
- | (pIE->InfoChanSel & 0x03);
-
- /* Octet 3.1 - Interface Identifier */
- if (pIE->IntIDPresent) {
- OBuf[(*Octet)++] = 0x80 | (pIE->InterfaceID & 0x7f);
- }
-
- /* Octet 3.2 & 3.3 - PRI */
- if (pIE->IntType) {
- OBuf[(*Octet)++] = 0x80
- | ((pIE->CodStand << 5) & 0x60)
- | ((pIE->NumMap << 4) & 0x10)
- | (pIE->ChanMapType & 0x0f); /* TODO: support all possible channel map types */
-
- /* Octet 3.3 Channel number */
- switch (pIE->ChanMapType) {
- case 0x6: /* Slot map: H0 Channel Units */ /* unsupported, Octets 3.3.1 - 3.3.3 */
- return Q931E_CHANID;
-
- case 0x8: /* Slot map: H11 Channel Units */
- case 0x9: /* Slot map: H12 Channel Units */
- default: /* Channel number */
- OBuf[(*Octet)++] = 0x80 | (pIE->ChanSlot & 0x7f);
- break;
- }
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-
-/*****************************************************************************
-
- Function: Q931Uie_CRV
-
- Description: Reading CRV.
-
- The CRV is currently returned in the return value that
- Q921Rx23 will assign to the CRV field in the unpacked
- message. CRV is basically 2 bytes etc, but the spec allows
- the use of longer CRV values.
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: CRV
-
-*****************************************************************************/
-L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff)
-{
- L3USHORT CRV = 0;
- L3INT Octet = *IOff;
- L3INT l = IBuf[Octet++];
-
- if (l == 1) { /* One octet CRV */
- CRV = IBuf[Octet++] & 0x7F;
- }
- else if (l == 2) { /* two octet CRV */
- CRV = (IBuf[Octet++] & 0x7f) << 8;
- CRV |= IBuf[Octet++];
- }
- else {
- /* Long CRV is not used, so we skip this */
- /* TODO: is it right to set to 0 here? */
- CRV = 0;
- Octet += l;
- }
-
- *IOff = Octet;
- return CRV;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_DateTime
-
- Parameters: pTrunk [IN] Ptr to trunk information.
- pIE [OUT] ptr to Information Element id.
- IBuf [IN] ptr to a packed ie.
- OBuf [OUT] ptr to buffer for Unpacked ie.
- IOff [IN\OUT] Input buffer offset
- OOff [IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf;
- ie *pIE = &pMsg->DateTime;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize = 0;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 - Year */
- pie->Year = IBuf[Octet++];
-
- /* Octet 4 - Month */
- pie->Month = IBuf[Octet++];
-
- /* Octet 5 - Day */
- pie->Day = IBuf[Octet++];
-
- /*******************************************************************
- The remaining part of the IE are optioinal, but only the length
- can now tell us wherever these fields are present or not
- (always remember: IESize does not include ID and Size octet)
- ********************************************************************/
- pie->Format = 0;
-
- /* Octet 6 - Hour (optional)*/
- if (IESize >= 4) {
- pie->Format = 1;
- pie->Hour = IBuf[Octet++];
-
- /* Octet 7 - Minute (optional)*/
- if (IESize >= 5) {
- pie->Format = 2;
- pie->Minute = IBuf[Octet++];
-
- /* Octet 8 - Second (optional)*/
- if (IESize >= 6) {
- pie->Format = 3;
- pie->Second = IBuf[Octet++];
- }
- }
- }
-
- Q931IESizeTest(Q931E_DATETIME);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_DateTime);
- pie->Size = sizeof(Q931ie_DateTime);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_DateTime
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_DateTime *pIE = (Q931ie_DateTime*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_DATETIME;
- li = (*Octet)++;
-
- OBuf[(*Octet)++] = pIE->Year;
- OBuf[(*Octet)++] = pIE->Month;
- OBuf[(*Octet)++] = pIE->Day;
- if (pIE->Format >= 1) {
- OBuf[(*Octet)++] = pIE->Hour;
-
- if (pIE->Format >= 2) {
- OBuf[(*Octet)++] = pIE->Minute;
-
- if (pIE->Format >= 3) {
- OBuf[(*Octet)++] = pIE->Second;
- }
- }
- }
-
- OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_Display
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_Display *pie = (Q931ie_Display*)OBuf;
- ie *pIE = &pMsg->Display;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
- L3INT x;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
- IESize = IBuf[Octet++];
-
- for (x = 0; xDisplay[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
-
- Q931IESizeTest(Q931E_DISPLAY);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_Display
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_Display *pIE = (Q931ie_Display*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT DSize;
- L3INT x;
-
- OBuf[(*Octet)++] = Q931ie_DISPLAY;
- li = (*Octet)++;
-
- DSize = pIE->Size - sizeof(Q931ie_Display);
-
- for (x = 0; x< DSize; x++) {
-
- OBuf[(*Octet)++] = pIE->Display[x];
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_HLComp
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf;
- ie *pIE = &pMsg->HLComp;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet */
- IESize = IBuf[Octet++];
-
- /* Octet 3*/
- pie->CodStand = (IBuf[Octet + Off] >>5) & 0x03;
- pie->Interpret = (IBuf[Octet + Off] >>2) & 0x07;
- pie->PresMeth = IBuf[Octet + Off] & 0x03;
- Octet++;
-
- /* Octet 4 */
- pie->HLCharID = IBuf[Octet + Off] & 0x7f;
- Octet++;
-
- /* Octet 4a*/
- if ((IBuf[Octet + Off - 1] & 0x80) == 0 && Q931MoreIE()) {
- if (pie->HLCharID == 0x5e || pie->HLCharID == 0x5f) {
- pie->EHLCharID = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
- else if ( pie->HLCharID >= 0xc3 && pie->HLCharID <= 0xcf) {
- pie->EVideoTlfCharID = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
- else {
- /* error Octet 4a indicated, but invalid value in Octet 4. */
- Q931SetError(pTrunk,Q931E_HLCOMP, 4, Off);
- return Q931E_HLCOMP;
- }
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- }
-
- Q931IESizeTest(Q931E_HLCOMP);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_HLComp);
- pie->Size = sizeof(Q931ie_HLComp);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_HLComp
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_HLComp *pIE = (Q931ie_HLComp*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_HIGH_LAYER_COMPATIBILITY;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | ((pIE->Interpret << 2) & 0x1c) | (pIE->PresMeth & 0x03);
-
- /* Octet 4 */
- OBuf[(*Octet)++] = pIE->HLCharID;
-
- /* Octet 4a */
- if (pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) {
- OBuf[(*Octet)++] = 0x80 | (pIE->EHLCharID & 0x7f);
- }
- else if ( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) {
- OBuf[(*Octet)++] = 0x80 | (pIE->EVideoTlfCharID & 0x7f);
- }
- else {
- OBuf[(*Octet) - 1] |= 0x80;
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_KeypadFac
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_KeypadFac *pie = (Q931ie_KeypadFac*)OBuf;
- ie *pIE = &pMsg->KeypadFac;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
- L3INT x;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
- IESize = IBuf[Octet++];
-
- for (x = 0; xKeypadFac[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
-
- Q931IESizeTest(Q931E_KEYPADFAC);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_KeypadFac
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_KeypadFac *pIE = (Q931ie_KeypadFac*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT DSize;
- L3INT x;
-
- OBuf[(*Octet)++] = Q931ie_KEYPAD_FACILITY;
- li = (*Octet)++;
-
- DSize = pIE->Size - sizeof(Q931ie_KeypadFac) + 1;
-
- for (x = 0; x< DSize; x++) {
- OBuf[(*Octet)++] = pIE->KeypadFac[x];
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_LLComp
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_LLComp *pie = (Q931ie_LLComp*)OBuf;
- ie *pIE = &pMsg->LLComp;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->CodStand = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->ITransCap = IBuf[Octet + Off] & 0x1f;
- Octet++;
-
- /* Octet 3a*/
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->NegotInd = (IBuf[Octet + Off] >> 6) & 0x01;
- Off++;
- }
-
- /* Octet 4 */
- pie->TransMode = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->InfoRate = IBuf[Octet + Off] & 0x1f;
-
- Octet++;
-
- /* Octet 4.1 */
- if (pie->InfoRate == 0x14) { /* Mutirate */
- pie->RateMul = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
-
- /* Octet 5 - Layer 1 Ident */
- if ((IBuf[Octet + Off] & 0x60) == 0x20) { /* Layer 1 Ident ? */
- pie->Layer1Ident = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->UIL1Prot = IBuf[Octet + Off] & 0x1f;
- Octet++;
-
- /* Octet 5a */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->SyncAsync = (IBuf[Octet + Off] >> 6) & 0x01;
- pie->Negot = (IBuf[Octet + Off] >> 5) & 0x01;
- pie->UserRate = IBuf[Octet + Off] & 0x1f;
- Off++;
-
- /* Octet 5b - 2 options */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- if (pie->UIL1Prot == 0x01) { /* V.110, I.460 and X.30*/
- pie->InterRate = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->NIConTx = (IBuf[Octet + Off] >> 4) & 0x01;
- pie->NIConRx = (IBuf[Octet + Off] >> 3) & 0x01;
- pie->FlowCtlTx = (IBuf[Octet + Off] >> 2) & 0x01;
- pie->FlowCtlRx = (IBuf[Octet + Off] >> 1) & 0x01;
- Off++;
- }
- else if (pie->UIL1Prot == 0x80) { /* V.120 */
- pie->HDR = (IBuf[Octet + Off] >> 6) & 0x01;
- pie->MultiFrame = (IBuf[Octet + Off] >> 5) & 0x01;
- pie->ModeL1 = (IBuf[Octet + Off] >> 4) & 0x01;
- pie->NegotLLI = (IBuf[Octet + Off] >> 3) & 0x01;
- pie->Assignor = (IBuf[Octet + Off] >> 2) & 0x01;
- pie->InBandNeg = (IBuf[Octet + Off] >> 1) & 0x01;
- Off++;
- }
- else if (pie->UIL1Prot == 0x07) { /* non standard */
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- Off++;
- }
- else {
- Q931SetError(pTrunk,Q931E_LLCOMP, 5,2);
- return Q931E_LLCOMP;
- }
-
- /* Octet 5c */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->NumStopBits = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->NumDataBits = (IBuf[Octet + Off] >> 3) & 0x03;
- pie->Parity = IBuf[Octet + Off] & 0x07;
- Off++;
-
- /* Octet 5d */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->DuplexMode = (IBuf[Octet + Off] >> 6) & 0x01;
- pie->ModemType = IBuf[Octet + Off] & 0x3f;
- Off = Q931ReadExt(&IBuf[Octet + Off], Off);
- Off++;
- }
- }
- }
- }
- }
-
- /* Octet 6 - Layer 2 Ident */
- if ((IBuf[Octet + Off] & 0x60) == 0x40) { /* Layer 1 Ident ? */
- pie->Layer2Ident = (IBuf[Octet + Off] >>5) & 0x03;
- pie->UIL2Prot = IBuf[Octet + Off] & 0x1f;
- Octet++;
-
- /* Octet 6a */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- if (pie->UIL2Prot == 0x10) { /* 2nd 6a */
- pie->UsrSpcL2Prot = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
- else { /* assume 1st 6a */
- pie->ModeL2 = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->Q933use = IBuf[Octet + Off] & 0x03;
- Off++;
- }
- /* Octet 6b */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->WindowSize = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
- }
- }
-
- /* Octet 7 - layer 3 Ident */
- if ((IBuf[Octet + Off] & 0x60) == 0x60) { /* Layer 3 Ident ? */
- pie->Layer3Ident = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->UIL3Prot = IBuf[Octet + Off] & 0x1f;
- Octet++;
-
- /* Octet 7a */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- if (pie->UIL3Prot == 0x0b) {
- /* Octet 7a + 7b AddL3Info */
- pie->AddL3Info = ((IBuf[Octet + Off] << 4) & 0xf0)
- | (IBuf[Octet + Off + 1] & 0x0f);
- Off += 2;
- }
- else {
- if (pie->UIL3Prot == 0x1f) {
- pie->ModeL3 = (IBuf[Octet + Off] >> 5) & 0x03;
- Off++;
- }
- else {
- pie->OptL3Info = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
-
- /* Octet 7b*/
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->DefPackSize = IBuf[Octet + Off] & 0x0f;
- Off++;
-
- /* Octet 7c */
- if (IsQ931Ext(IBuf[Octet + Off - 1])) {
- pie->PackWinSize= IBuf[Octet + Off] & 0x7f;
- }
- }
- }
- }
- }
-
- Q931IESizeTest(Q931E_LLCOMP);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_LLComp);
- pie->Size = sizeof(Q931ie_LLComp);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_LLComp
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_LLComp *pIE = (Q931ie_LLComp*)IBuf;
- L3INT rc = 0;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_LOW_LAYER_COMPATIBILITY;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = (pIE->CodStand << 6) | pIE->ITransCap;
-
- /* Octet 3a */
- OBuf[(*Octet)++] = 0x80 | (pIE->NegotInd << 6);
-
- /* Octet 4 */
- OBuf[(*Octet)++] = 0x80 | (pIE->TransMode << 5) | pIE->InfoRate;
-
- /* Octet 4.1 */
- if (pIE->InfoRate == 0x18) {
- OBuf[(*Octet)++] = 0x80 | pIE->RateMul;
- }
-
- /* Octet 5 */
- if (pIE->Layer1Ident == 0x01) {
- OBuf[(*Octet)++] = (pIE->Layer1Ident << 5) | pIE->UIL1Prot;
-
- /* Octet 5a */
- if ((pIE->ITransCap == 0x08 && (pIE->UIL1Prot == 0x01 || pIE->UIL1Prot == 0x08))
- || (pIE->ITransCap == 0x10 && (pIE->UIL1Prot == 0x02 || pIE->UIL1Prot == 0x03))) {
- OBuf[(*Octet)++] = (pIE->SyncAsync<<6) | (pIE->Negot<<5) | pIE->UserRate;
-
- /* Octet 5b*/
- if (pIE->UIL1Prot == 0x01) {
- OBuf[(*Octet)++] = (pIE->InterRate << 5)
- | (pIE->NIConTx << 4)
- | (pIE->NIConTx << 3)
- | (pIE->FlowCtlTx << 2)
- | (pIE->FlowCtlRx << 1);
- }
- else if (pIE->UIL1Prot == 0x08) {
- OBuf[(*Octet)++] = (pIE->HDR << 6)
- | (pIE->MultiFrame << 5)
- | (pIE->ModeL1 << 4)
- | (pIE->NegotLLI << 3)
- | (pIE->Assignor << 2)
- | (pIE->InBandNeg << 1);
- }
- else {
- OBuf[(*Octet) - 1] |= 0x80;
- }
-
- /* How to detect wherever 5c and 5d is to present is not clear
- * but they have been inculded as 'standard'
- * Octet 5c
- */
- if (pIE->UIL1Prot == 0x01 || pIE->UIL1Prot == 0x08) {
- OBuf[(*Octet)++] = (pIE->NumStopBits << 5) | (pIE->NumDataBits << 3) | pIE->Parity ;
-
- /* Octet 5d */
- OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode << 6) | pIE->ModemType;
- }
- }
- else {
- OBuf[(*Octet) - 1] |= 0x80;
- }
- }
-
- /* Octet 6 */
- if (pIE->Layer2Ident == 0x02) {
- OBuf[(*Octet)++] = (pIE->Layer2Ident << 5) | pIE->UIL2Prot;
-
- /* Octet 6a*/
- if (pIE->UIL2Prot == 0x02 /* Q.921/I.441 */
- || pIE->UIL2Prot == 0x06 /* X.25 link layer */
- || pIE->UIL2Prot == 0x07 /* X.25 multilink */
- || pIE->UIL2Prot == 0x09 /* HDLC ARM */
- || pIE->UIL2Prot == 0x0a /* HDLC NRM */
- || pIE->UIL2Prot == 0x0b /* HDLC ABM */
- || pIE->UIL2Prot == 0x0d /* X.75 SLP */
- || pIE->UIL2Prot == 0x0e /* Q.922 */
- || pIE->UIL2Prot == 0x11) { /* ISO/ECE 7776 DTE-DCE */
- OBuf[(*Octet)++] = (pIE->ModeL2 << 5) | pIE->Q933use;
-
- /* Octet 6b */
- OBuf[(*Octet)++] = 0x80 | pIE->WindowSize;
- }
- else if (pIE->UIL2Prot == 0x10) { /* User Specific */
- OBuf[(*Octet)++] = 0x80 | pIE->UsrSpcL2Prot;
- }
- else {
- OBuf[(*Octet) - 1] |= 0x80;
- }
- }
-
- /* Octet 7 */
- if (pIE->Layer3Ident == 0x03) {
- OBuf[(*Octet)++] = (pIE->Layer3Ident << 5) | pIE->UIL3Prot;
-
- /* Octet 7a - 3 different ones */
- if (pIE->UIL3Prot == 0x10) {
- OBuf[(*Octet++)] = 0x80 | pIE->OptL3Info;
- }
- else if (pIE->UIL3Prot == 0x06
- || pIE->UIL3Prot == 0x07
- || pIE->UIL3Prot == 0x08) {
- OBuf[(*Octet)++] = pIE->ModeL3 << 5;
-
- /* Octet 7b note 7 */
- OBuf[(*Octet)++] = pIE->DefPackSize;
-
- /* Octet 7c note 7 */
- OBuf[(*Octet)++] = 0x80 | pIE->PackWinSize;
- }
- else if (pIE->UIL3Prot == 0x0b) {
- OBuf[(*Octet)++] = (pIE->AddL3Info >> 4) & 0x0f;
- OBuf[(*Octet)++] = 0x80 | (pIE->AddL3Info & 0x0f);
- }
- else {
- OBuf[(*Octet) - 1] |= 0x80;
- }
- }
- else {
- Q931SetError(pTrunk,Q931E_LLCOMP, 7,0);
- rc = Q931E_LLCOMP;
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_NetFac
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_NetFac *pie = (Q931ie_NetFac*)OBuf;
- ie *pIE = &pMsg->NetFac;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- pie->LenNetID = IBuf[Octet + Off]; /* full octet is used */
- Octet++;
-
- if (pie->LenNetID > 0) {
- /* Octet 3.1 */
- pie->TypeNetID = (IBuf[Octet + Off] >> 4) & 0x0f;
- pie->NetIDPlan = IBuf[Octet + Off] & 0x0f;
- Off = Q931ReadExt(&IBuf[Octet], Off);
- Off++;
-
- /* Octet 3.2*/
- for (x = 0; x < pie->LenNetID; x++) {
- pie->NetID[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
- }
-
- /* Octet 4*/
- pie->NetFac = IBuf[Octet + Off]; /* Full Octet is used */
- Octet++;
-
- Q931IESizeTest(Q931E_NETFAC);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_NetFac
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_NetFac *pIE = (Q931ie_NetFac*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT x;
-
- OBuf[(*Octet)++] = Q931ie_NETWORK_SPECIFIC_FACILITIES;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = pIE->LenNetID;
-
- if (pIE->LenNetID > 0) {
- /* Octet 3.1 */
- OBuf[(*Octet)++] = 0x80 | (pIE->TypeNetID << 4) | pIE->NetIDPlan;
-
- /* Octet 3.2 */
- for (x = 0; x LenNetID; x++) {
- OBuf[(*Octet)++] = pIE->NetID[x];
- }
- }
-
- /* Octet 4 */
- OBuf[(*Octet)++] = pIE->NetFac;
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_NotifInd
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_NotifInd *pie = (Q931ie_NotifInd*)OBuf;
- ie *pIE = &pMsg->NotifInd;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2*/
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->Notification = IBuf[Octet + Off] & 0x7f;
-
- Off = Q931ReadExt(&IBuf[Octet], Off);
- Octet++;
-
- Q931IESizeTest(Q931E_NOTIFIND);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_NotifInd);
- pie->Size = sizeof(Q931ie_NotifInd);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_NotifInd
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_NotifInd *pIE = (Q931ie_NotifInd*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_NOTIFICATION_INDICATOR;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = pIE->Notification;
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_ProgInd
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_ProgInd *pie = (Q931ie_ProgInd*)OBuf;
- ie *pIE = &pMsg->ProgInd;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->CodStand = (IBuf[Octet + Off] >> 5) & 0x03;
- pie->Location = IBuf[Octet + Off] & 0x0f;
-
- Off = Q931ReadExt(&IBuf[Octet], Off);
- Octet++;
-
- /* Octet 4 */
- pie->ProgDesc = IBuf[Octet + Off] & 0x7f;
- Off = Q931ReadExt(&IBuf[Octet], Off);
- Octet++;
-
- Q931IESizeTest(Q931E_PROGIND);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_ProgInd);
- pie->Size = sizeof(Q931ie_ProgInd);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_ProgInd
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset L3INTo OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_ProgInd *pIE = (Q931ie_ProgInd*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_PROGRESS_INDICATOR;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | pIE->Location;
-
- /* Octet 4 */
- OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc;
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_RepeatInd
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf;
- ie *pIE = &pMsg->RepeatInd;
- L3INT Off = 0;
- L3INT Octet = 0;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet] & 0xf0;
- pie->RepeatInd = IBuf[Octet] & 0x0f;
- Octet ++;
-
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_RepeatInd);
- pie->Size = sizeof(Q931ie_RepeatInd);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_RepeatInd
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_RepeatInd *pIE = (Q931ie_RepeatInd*)IBuf;
- L3INT rc = 0;
- /* L3INT Beg = *Octet; */
-
- OBuf[(*Octet)++] = Q931ie_REPEAT_INDICATOR | pIE->RepeatInd;
-
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_RevChargeInd
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- ie iE;
- /* ie *pIE = &pMsg->RevChargeInd; */
- Q931SetIE(iE, *OOff);
-
- return iE;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_RevChargeInd
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_RestartInd
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_RestartInd *pie = (Q931ie_RestartInd*)OBuf;
- ie *pIE = &pMsg->RestartInd;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->Class = IBuf[Octet + Off] & 0x07;
- pie->Spare = IBuf[Octet + Off] & 0x78;
-
- Off = Q931ReadExt(&IBuf[Octet], Off);
- Octet++;
-
- Q931IESizeTest(Q931E_RESTARTIND);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_RestartInd);
- pie->Size = sizeof(Q931ie_RestartInd);
-
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_RestartInd
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_RestartInd *pIE = (Q931ie_RestartInd*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_RESTART_INDICATOR;
- li = (*Octet)++;
-
- /* Octet 3*/
- OBuf[(*Octet)++] = 0x80 | pIE->Class ;
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_Segment
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_Segment *pie = (Q931ie_Segment*)OBuf;
- ie *pIE = &pMsg->Segment;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
- Octet++;
-
- /* Octet 2*/
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->FSI = (IBuf[Octet + Off] & 0x80) >> 7;
- pie->NumSegRem = IBuf[Octet + Off] & 0x7f;
- Octet++;
-
- /* Octet 4 */
- pie->SegType = IBuf[Octet + Off] & 0x7f;
- Octet++;
-
- Q931IESizeTest(Q931E_SEGMENT);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_Segment);
- pie->Size = sizeof(Q931ie_Segment);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_Segment
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_Segment *pIE = (Q931ie_Segment*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_SEGMENTED_MESSAGE;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = (pIE->FSI << 7) | pIE->NumSegRem;
-
- /* Octet 4 */
- OBuf[(*Octet)++] = pIE->SegType;
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_SendComplete
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf;
- ie *pIE = &pMsg->SendComplete;
- L3INT Off = 0;
- L3INT Octet = 0;
-
- *pIE = 0;
- Octet++;
-
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_SendComplete);
- pie->Size = sizeof(Q931ie_SendComplete);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_ProgInd
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- /* Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; */
- L3INT rc = Q931E_NO_ERROR;
- /* L3INT Beg = *Octet; */
-
- OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE;
-
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_Signal
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_Signal *pie = (Q931ie_Signal*)OBuf;
- ie *pIE = &pMsg->Signal;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->Signal = IBuf[Octet + Off];
- Octet++;
-
- Q931IESizeTest(Q931E_SIGNAL);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_Signal);
- pie->Size = sizeof(Q931ie_Signal);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_Signal
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_Signal *pIE = (Q931ie_Signal*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_SIGNAL;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = pIE->Signal;
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_TransNetSel
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_TransNetSel *pie = (Q931ie_TransNetSel*)OBuf;
- ie *pIE = &pMsg->TransNetSel;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x = 0;
- L3INT l;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- l = IBuf[Octet++] - 3;
-
- /* Octet 3 */
- pie->Type = (IBuf[Octet + Off] >> 4) & 0x07;
-
- Off = Q931ReadExt(&IBuf[Octet], Off);
- Octet++;
-
- for (x = 0; x < l; x++) {
- pie->NetID[x] = IBuf[Octet + Off] & 0x7f;
- Off++;
- }
-
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_TransNetSel
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_TransNetSel *pIE = (Q931ie_TransNetSel*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT x;
- L3INT l;
-
- OBuf[(*Octet)++] = Q931ie_TRANSIT_NETWORK_SELECTION;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | (pIE->Type << 4) | pIE->NetIDPlan;
-
- /* Octet 4 */
- l = pIE->Size - sizeof(Q931ie_TransNetSel) + 1;
- for (x = 0; x < l; x++) {
- OBuf[(*Octet)++] = pIE->NetID[x];
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_UserUser
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_UserUser *pie = (Q931ie_UserUser*)OBuf;
- ie *pIE = &pMsg->UserUser;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT l;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- l = IBuf[Octet++] - 1;
-
- /* Octet 3 */
- pie->ProtDisc = IBuf[Octet++];
-
- for (Off = 0; Off < l; Off++) {
- pie->User[Off] = IBuf[Octet + Off];
- }
-
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_UserUser) + Off - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + Off - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_UserUser
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_UserUser *pIE = (Q931ie_UserUser*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
- L3INT x;
- L3INT l;
-
- OBuf[(*Octet)++] = Q931ie_USER_USER;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = pIE->ProtDisc;
-
- /* Octet 4 */
- l = pIE->Size - sizeof(Q931ie_UserUser) + 1;
- for (x = 0; x < l; x++) {
- OBuf[(*Octet)++] = pIE->User[x];
- }
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_GenericDigits
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_GenericDigits *pie = (Q931ie_GenericDigits*)OBuf;
- ie *pIE = &pMsg->GenericDigits;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT x;
- L3INT IESize;
-
- *pIE = 0;
-
- /* Octet 1 */
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->Type = (IBuf[Octet]) & 0x1F;
- pie->Encoding = (IBuf[Octet] >> 5) & 0x07;
- Octet++;
-
- /* Octet 4*/
- if (pie->Encoding == 0) { /* BCD Even */
- x = 0;
- do {
- pie->Digit[x++] = IBuf[Octet + Off] & 0x0f;
- pie->Digit[x++] = (IBuf[Octet + Off] >> 4) & 0x0f;
- Off++;
- } while (Q931MoreIE());
- } else if (pie->Encoding == 1) { /* BCD Odd */
- x = 0;
- do {
- pie->Digit[x++] = IBuf[Octet + Off] & 0x0f;
- if (Q931MoreIE()) {
- pie->Digit[x] = (IBuf[Octet + Off] >> 4) & 0x0f;
- }
- x++;
- Off++;
- } while (Q931MoreIE());
- } else if (pie->Encoding == 2) { /* IA5 */
- x = 0;
- do {
- pie->Digit[x++] = IBuf[Octet + Off] & 0x7f;
- Off++;
- } while (Q931MoreIE());
- } else {
- /* Binary encoding type unkown */
- Q931SetError(pTrunk, Q931E_GENERIC_DIGITS, Octet, Off);
- return Q931E_GENERIC_DIGITS;
- }
-
- Q931IESizeTest(Q931E_GENERIC_DIGITS);
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x - 1;
- pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x - 1);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_GenericDigits
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-
-L3INT Q931Pie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- OBuf[(*Octet)++] = (Q931ie_GENERIC_DIGITS & 0xFF);
- OBuf[(*Octet)++] = 0;
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Uie_ChangeStatus
-
- Parameters: pIE[OUT] ptr to Information Element id.
- IBuf[IN] ptr to a packed ie.
- OBuf[OUT] ptr to buffer for Unpacked ie.
- IOff[IN\OUT] Input buffer offset
- OOff[IN\OUT] Output buffer offset
-
- Ibuf and OBuf points directly to buffers. The IOff and OOff
- must be updated, but are otherwise not used in the ie unpack.
-
- Return Value: Error Message
-
-*****************************************************************************/
-L3INT Q931Uie_ChangeStatus(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
-{
- Q931ie_ChangeStatus *pie = (Q931ie_ChangeStatus*)OBuf;
- ie *pIE = &pMsg->ChangeStatus;
- L3INT Off = 0;
- L3INT Octet = 0;
- L3INT IESize;
-
- *pIE = 0;
-
- pie->IEId = IBuf[Octet++];
-
- /* Octet 2 */
- IESize = IBuf[Octet++];
-
- /* Octet 3 */
- pie->Preference = (IBuf[Octet + Off] >> 6) & 0x01;
- pie->Spare = IBuf[Octet + Off] & 0x38;
- pie->NewStatus = IBuf[Octet + Off] & 0x07;
- Octet++;
-
- Q931SetIE(*pIE, *OOff);
-
- *IOff = (*IOff) + Octet + Off;
- *OOff = (*OOff) + sizeof(Q931ie_ChangeStatus);
- pie->Size = sizeof(Q931ie_ChangeStatus);
-
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pie_ChangeStatus
-
- Parameters: IBuf[IN] Ptr to struct.
- OBuf[OUT] Ptr tp packed output buffer.
- Octet[IN/OUT] Offset into OBuf.
-
- Return Value: Error code, 0 = OK
-
-*****************************************************************************/
-L3INT Q931Pie_ChangeStatus(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- Q931ie_ChangeStatus *pIE = (Q931ie_ChangeStatus*)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Beg = *Octet;
- L3INT li;
-
- OBuf[(*Octet)++] = Q931ie_CHANGE_STATUS;
- li = (*Octet)++;
-
- /* Octet 3 */
- OBuf[(*Octet)++] = 0x80 | pIE->NewStatus | ((pIE->Preference & 0x01) << 6);
-
- OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2;
- return rc;
-}
-
-
-
-L3INT Q931Uie_Generic(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff)
-{
- L3INT Octet = 0;
- L3UCHAR id = 0;
-
- /* id */
- id = IBuf[Octet++];
-
- /* Length */
- Octet += IBuf[Octet];
- Octet++;
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Discarding IE %#hhx with length %d\n", id, Octet - 2);
-
- *IOff += Octet;
- return Q931E_NO_ERROR;
-}
-
-L3INT Q931Pie_Generic(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
-{
- /* do nothing */
- return Q931E_NO_ERROR;
-}
diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c
deleted file mode 100644
index 8e34a170e1..0000000000
--- a/libs/openzap/src/isdn/Q931mes.c
+++ /dev/null
@@ -1,1870 +0,0 @@
-/*****************************************************************************
-
- FileName: Q931mes.c
-
- Contents: Pack/Unpack functions. These functions will unpack a Q931
- message from the bit packed original format into structs
- that contains variables sized by the user. It will also pack
- the struct back into a Q.931 message as required.
-
- See q931.h for description.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-*****************************************************************************/
-
-#include "Q931.h"
-
-/**
- * Q931MesgHeader
- * \brief Create Q.931 Message header
- */
-L3INT Q931MesgHeader(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *mes, L3UCHAR *OBuf, L3INT Size, L3INT *IOff)
-{
- L3INT Octet = *IOff;
-
- Q931Log(pTrunk, Q931_LOG_DEBUG, "Creating Q.931 Message Header:\n ProtDisc %d (%#x), CRV %d (%#x), CRVflag: %d (%#x), MesType: %d (%#x)\n",
- mes->ProtDisc, mes->ProtDisc, mes->CRV, mes->CRV, mes->CRVFlag, mes->CRVFlag, mes->MesType, mes->MesType);
-
- OBuf[Octet++] = mes->ProtDisc; /* Protocol discriminator */
- if (!Q931_IS_BRI(pTrunk)) {
- OBuf[Octet++] = 2; /* length is 2 octets */
- OBuf[Octet++] = (L3UCHAR)((mes->CRV >> 8) & 0x7f) | ((mes->CRVFlag << 7) & 0x80); /* msb */
- OBuf[Octet++] = (L3UCHAR) (mes->CRV & 0xff); /* lsb */
- } else {
- OBuf[Octet++] = 1; /* length is 1 octet */
- OBuf[Octet++] = (L3UCHAR) (mes->CRV & 0x7f) | ((mes->CRVFlag << 7) & 0x80); /* CRV & flag */
- }
- OBuf[Octet++] = mes->MesType; /* message header */
-
- *IOff = Octet;
- return 0;
-}
-
-
-/*****************************************************************************
-
- Function: Q931Umes_Alerting
-
-*****************************************************************************/
-
-L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_DISPLAY:
- case Q931ie_SIGNAL:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- case Q931ie_USER_USER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Alerting
-
-*****************************************************************************/
-L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_CallProceeding
-
-*****************************************************************************/
-L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_DISPLAY:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_CallProceeding
-
-*****************************************************************************/
-L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_CongestionControl
-
-*****************************************************************************/
-L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(mes);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-
-/*****************************************************************************
-
- Function: Q931Pmes_CongestionControl
-
-*****************************************************************************/
-L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- *OSize = 0;
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Connect
-
-*****************************************************************************/
-L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_DISPLAY:
- case Q931ie_DATETIME:
- case Q931ie_SIGNAL:
- case Q931ie_LOW_LAYER_COMPATIBILITY:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- case Q931ie_CONNECTED_NUMBER: /* not actually used, seen while testing BRI PTMP TE */
- case Q931ie_USER_USER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
-
- default:
- Q931Log(pTrunk, Q931_LOG_ERROR, "Illegal IE %#hhx in Connect Message\n", IBuf[IOff]);
-
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Connect
-
-*****************************************************************************/
-L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Date/Time */
- if (Q931IsIEPresent(pMes->DateTime)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Low Layer Compatibility */
- if (Q931IsIEPresent(pMes->LLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_ConnectAck
-
-*****************************************************************************/
-L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_DISPLAY:
- case Q931ie_SIGNAL:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-
-/*****************************************************************************
-
- Function: Q931Pmes_ConnectAck
-
-*****************************************************************************/
-L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Disconnect
-
-*****************************************************************************/
-L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CAUSE:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_DISPLAY:
- case Q931ie_SIGNAL:
- case Q931ie_FACILITY:
- case Q931ie_USER_USER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Disconnect
-
-*****************************************************************************/
-L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Cause */
- if (Q931IsIEPresent(pMes->Cause)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CAUSE](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Information
-
-*****************************************************************************/
-L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_SENDING_COMPLETE:
- case Q931ie_DISPLAY:
- case Q931ie_KEYPAD_FACILITY:
- case Q931ie_CALLED_PARTY_NUMBER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Information
-
-*****************************************************************************/
-L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Sending Complete */
- if (Q931IsIEPresent(pMes->SendComplete)) {
- OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff);
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Keypad Facility */
- if (Q931IsIEPresent(pMes->KeypadFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Called Party number */
- if (Q931IsIEPresent(pMes->CalledNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Notify
-
-*****************************************************************************/
-L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_NOTIFICATION_INDICATOR:
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Notify
-
-*****************************************************************************/
-L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Progress
-
-*****************************************************************************/
-L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CAUSE:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_DISPLAY:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Progress
-
-*****************************************************************************/
-L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Cause */
- if (Q931IsIEPresent(pMes->Cause)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CAUSE](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Release
-
-*****************************************************************************/
-L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CAUSE:
- case Q931ie_DISPLAY:
- case Q931ie_SIGNAL:
- case Q931ie_USER_USER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Release
-
-*****************************************************************************/
-L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Cause */
- if (Q931IsIEPresent(pMes->Cause)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CAUSE](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_ReleaseComplete
-
-*****************************************************************************/
-L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CAUSE:
- case Q931ie_DISPLAY:
- case Q931ie_SIGNAL:
- case Q931ie_USER_USER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_ReleaseComplete
-
-*****************************************************************************/
-L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Cause */
- if (Q931IsIEPresent(pMes->Cause)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CAUSE](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Restart
-
-*****************************************************************************/
-L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_DISPLAY:
- case Q931ie_RESTART_INDICATOR:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Restart
-
-*****************************************************************************/
-L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* ChanID */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* RestartInd */
- if (Q931IsIEPresent(pMes->RestartInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_RestartAck
-
-*****************************************************************************/
-L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size)
-{
- Q931mes_Generic *mes = (Q931mes_Generic*)OBuf;
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_DISPLAY:
- case Q931ie_RESTART_INDICATOR:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_RestartAck
-
-*****************************************************************************/
-L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* ChanID */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* RestartInd */
- if (Q931IsIEPresent(pMes->RestartInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Resume
-
-*****************************************************************************/
-L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CALL_IDENTITY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Resume
-
-*****************************************************************************/
-L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Call Identity */
- if (Q931IsIEPresent(pMes->CallID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_ResumeAck
-
-*****************************************************************************/
-L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-
-/*****************************************************************************
-
- Function: Q931Pmes_ResumeAck
-
-*****************************************************************************/
-L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_ResumeReject
-
-*****************************************************************************/
-L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CAUSE:
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-
-/*****************************************************************************
-
- Function: Q931Pmes_ResumeReject
-
-*****************************************************************************/
-L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Cause */
- if (Q931IsIEPresent(pMes->Cause)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CAUSE](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT OOff)
-{
- L3INT i = IOff;
-
- return IOff - i;
-}
-
-L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- *OSize = 0;
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Setup
-
-*****************************************************************************/
-L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT ir = 0;
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_SENDING_COMPLETE:
- IOff++;
- break;
-
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_NETWORK_SPECIFIC_FACILITIES:
- case Q931ie_DISPLAY:
- case Q931ie_DATETIME:
- case Q931ie_KEYPAD_FACILITY:
- case Q931ie_SIGNAL:
- case Q931ie_CALLING_PARTY_NUMBER:
- case Q931ie_CALLING_PARTY_SUBADDRESS:
- case Q931ie_CALLED_PARTY_NUMBER:
- case Q931ie_CALLED_PARTY_SUBADDRESS:
- case Q931ie_TRANSIT_NETWORK_SELECTION:
- case Q931ie_LOW_LAYER_COMPATIBILITY:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- case Q931ie_FACILITY:
- case Q931ie_USER_USER:
- case Q931ie_REDIRECTING_NUMBER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
-
- case Q931ie_REPEAT_INDICATOR:
- if (ir < 2) {
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- ir++;
- } else {
- return Q931E_ILLEGAL_IE;
- }
- break;
-
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Setup
-
- Decription: Pack a Q931mes_Generic into a real Q.931 message. The user will
- set up a SETUP message and issue this to the stack where it
- is processed by Q931ProcSetup that processes and validates
- it before it actually sends it out. This function is called
- to compute the real Q.931 message.
-
- Parameters: IBuf[IN] Ptr to un-packed struct
- ISize[IN] Size of input buffer (unpacked message).
- OBuf[OUT] Ptr to packed 'octet' wise message.
- OSize[OUT] Size of packed message.
-
- Called By: Q931ProcSetup
-
-*****************************************************************************/
-L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Sending Complete */
- if (Q931IsIEPresent(pMes->SendComplete)) {
- OBuf[Octet++] = (L3UCHAR)Q931ie_SENDING_COMPLETE & 0xff;
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->RepeatInd)) {
- OBuf[Octet++] = (L3UCHAR)Q931ie_REPEAT_INDICATOR & 0xff;
- }
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- } else {
- rc = Q931E_BEARERCAP;
- }
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Network spesific facilities */
- if (Q931IsIEPresent(pMes->NetFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_NETWORK_SPECIFIC_FACILITIES](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Date/Time */
- if (Q931IsIEPresent(pMes->DateTime)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Keypad Facility */
- if (Q931IsIEPresent(pMes->KeypadFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Calling Party Number */
- if (Q931IsIEPresent(pMes->CallingNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Calling Party Subaddress */
- if (Q931IsIEPresent(pMes->CallingSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Called Party number */
- if (Q931IsIEPresent(pMes->CalledNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Called party subaddress */
- if (Q931IsIEPresent(pMes->CalledSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Transit network selection */
- if (Q931IsIEPresent(pMes->TransNetSel)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->LLRepeatInd)) {
- rc = Q931E_UNKNOWN_IE;/* TODO */
- }
-
- /* Low Layer Compatibility */
- if (Q931IsIEPresent(pMes->LLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_SetupAck
-
-*****************************************************************************/
-L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_DISPLAY:
- case Q931ie_SIGNAL:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_SetupAck
-
-*****************************************************************************/
-L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Status
-
-*****************************************************************************/
-L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CAUSE:
- case Q931ie_CALL_STATE:
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-
-/*****************************************************************************
-
- Function: Q931Pmes_Status
-
-*****************************************************************************/
-L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Cause */
- if (Q931IsIEPresent(pMes->Cause)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CAUSE](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Call State */
- if (Q931IsIEPresent(pMes->CallState)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALL_STATE](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_StatusEnquiry
-
-*****************************************************************************/
-L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_StatusEnquiry
-
-*****************************************************************************/
-L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
-
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Suspend
-
-*****************************************************************************/
-L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CALL_IDENTITY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Suspend
-
-*****************************************************************************/
-L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Call Identity */
- if (Q931IsIEPresent(pMes->CallID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_SuspendAck
-
-*****************************************************************************/
-L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_SuspendAck
-
-*****************************************************************************/
-L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_SuspendReject
-
-*****************************************************************************/
-L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CAUSE:
- case Q931ie_DISPLAY:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_SuspendReject
-
-*****************************************************************************/
-L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Cause */
- if (Q931IsIEPresent(pMes->Cause)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CAUSE](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_UserInformation
-
-*****************************************************************************/
-L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT I, L3INT O)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(mes);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_UserInformation
-
-*****************************************************************************/
-L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- *OSize = 0;
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_Service
-
-*****************************************************************************/
-L3INT Q931Umes_Service(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CHANNEL_IDENTIFICATION:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- case Q931ie_CHANGE_STATUS:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Service
-
-*****************************************************************************/
-L3INT Q931Pmes_Service(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Display */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- if (Q931IsIEPresent(pMes->ChangeStatus)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANGE_STATUS](pTrunk, Q931GetIEPtr(pMes->ChangeStatus,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
-
-/*****************************************************************************
-
- Function: Q931Umes_ServiceAck
-
-*****************************************************************************/
-L3INT Q931Umes_ServiceAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
-
- while (IOff < Size) {
- switch (IBuf[IOff]) {
- case Q931ie_CHANNEL_IDENTIFICATION:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- case Q931ie_CHANGE_STATUS:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- }
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_ServiceAck
-
-*****************************************************************************/
-L3INT Q931Pmes_ServiceAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT rc = Q931E_NO_ERROR;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- if (Q931IsIEPresent(pMes->ChangeStatus)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANGE_STATUS](pTrunk, Q931GetIEPtr(pMes->ChangeStatus,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c
deleted file mode 100644
index 574499a241..0000000000
--- a/libs/openzap/src/isdn/Q932mes.c
+++ /dev/null
@@ -1,286 +0,0 @@
-/*****************************************************************************
-
- FileName: Q932mes.c
-
- Contents: Q.932 Message Encoders/Decoders
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "Q931.h"
-
-/*****************************************************************************
-
- Function: Q932Umes_Facility
-
-*****************************************************************************/
-
-L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Facility
-
-*****************************************************************************/
-L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q932Umes_Hold
-
-*****************************************************************************/
-
-L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Hold
-
-*****************************************************************************/
-L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q932Umes_HoldAck
-
-*****************************************************************************/
-
-L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_HoldAck
-
-*****************************************************************************/
-L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q932Umes_HoldReject
-
-*****************************************************************************/
-
-L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_HoldReject
-
-*****************************************************************************/
-L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q932Umes_Register
-
-*****************************************************************************/
-
-L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Register
-
-*****************************************************************************/
-L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q932Umes_Retrieve
-
-*****************************************************************************/
-
-L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_Retrieve
-
-*****************************************************************************/
-L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q932Umes_RetrieveAck
-
-*****************************************************************************/
-
-L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_RetrieveAck
-
-*****************************************************************************/
-L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
-
-/*****************************************************************************
-
- Function: Q932Umes_RetrieveReject
-
-*****************************************************************************/
-
-L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT OOff = 0;
-
- /* TODO */
-
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: Q931Pmes_RetrieveReject
-
-*****************************************************************************/
-L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3BOOL RetCode = L3FALSE;
-
- NoWarning(OBuf);
- NoWarning(IBuf);
-
- return RetCode;
-}
diff --git a/libs/openzap/src/isdn/include/5ESS.h b/libs/openzap/src/isdn/include/5ESS.h
deleted file mode 100644
index dd364ed537..0000000000
--- a/libs/openzap/src/isdn/include/5ESS.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/******************************************************************************
-
- FileName: 5ESS.h
-
- Contents: Header and definition for the AT&T 5ESS ISDN dialect. The
- header contains the following parts:
-
- - Definition of codes
- - Definition of information elements (5ESSie_).
- - Definition of messages (5ESSmes_).
- - Function prototypes.
-
- Description: The AT&T 5ESS ISDN dialect here covers ????
-
- Related Files: 5ESS.h AT&T 5ESS ISDN Definitions
- 5ESSie.c AT&T 5ESS ISDN IE encoders/coders (not extant yet)
- See Q931ie.c for IE encoders/coders
- 5ESSStateTE.c AT&T 5ESS ISDN TE State Engine
- 5ESSStateNT.c AT&T 5ESS ISDN NT State Engine
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Copyright (c) 2007, Michael S. Collins, All rights reserved.
- email:mcollins@fcnetwork.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-******************************************************************************/
-
-#ifndef _5ESS_NL
-#define _5ESS_NL
-
-#include "Q931.h"
-
-/*****************************************************************************
-
- Q.931 Message codes
- Only 5ESS specific message and ie types
- here the rest are inherited from Q931.h
-
-*****************************************************************************/
-
-
-/*****************************************************************************
-
- Q.931 Message Pack/Unpack functions. Implemented in 5ESSmes.c
- Note: Because C variables may not begin with numeric digit, all identifiers
- are prefixed with "ATT5ESS" instead of a bare "5ESS"
-
-*****************************************************************************/
-L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
-L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT ATT5ESSUmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
-L3INT ATT5ESSPmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-
-L3INT ATT5ESSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
-L3INT ATT5ESSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT ATT5ESSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
-L3INT ATT5ESSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-
-
-
-/*****************************************************************************
-
- Q.931 Process Function Prototyping. Implemented in 5ESSStateTE.c
-
-*****************************************************************************/
-L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom);
-L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom);
-
-
-void ATT5ESSCreateTE(L3UCHAR i);
-void ATT5ESSCreateNT(L3UCHAR i);
-
-#endif /* _5ESS_NL */
diff --git a/libs/openzap/src/isdn/include/DMS.h b/libs/openzap/src/isdn/include/DMS.h
deleted file mode 100644
index 605a61aa6e..0000000000
--- a/libs/openzap/src/isdn/include/DMS.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/******************************************************************************
-
- FileName: national.h
-
- Contents: Header and definition for the National ISDN dialect. The
- header contents the following parts:
- - Definition of codes
- - Definition of information elements (nationalie_).
- - Definition of messages (nationalmes_).
- - Function prototypes.
-
- Description: The National ISDN dialect here covers ????
-
- Related Files: national.h National ISDN Definitions
- nationalie.c National ISDN IE encoders/coders
- nationalStateTE.c National ISDN TE State Engine
- nationalStateNT.c National ISDN NT State Engine
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-******************************************************************************/
-
-#ifndef _DMS_NL
-#define _DMS_NL
-
-#include "Q931.h"
-
-/*****************************************************************************
-
- Q.931 Message codes
- Only National specific message and ie types
- here the rest are inherited from national.h
-
-*****************************************************************************/
-
-
-/*****************************************************************************
-
- Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c
-
-*****************************************************************************/
-L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
-L3INT DMSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT DMSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
-L3INT DMSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
-L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-
-/*****************************************************************************
-
- Q.931 Process Function Prototyping. Implemented in nationalStateTE.c
-
-*****************************************************************************/
-
-L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom);
-L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom);
-
-void DMSCreateTE(L3UCHAR i);
-void DMSCreateNT(L3UCHAR i);
-
-#endif /* _DMS_NL */
diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h
deleted file mode 100644
index cb21a157ea..0000000000
--- a/libs/openzap/src/isdn/include/Q921.h
+++ /dev/null
@@ -1,227 +0,0 @@
-/*****************************************************************************
-
- FileName: q921.h
-
- Description: Contains headers of a Q.921 protocol.
-
- Note: This header file is the only include file that should be
- acessed by users of the Q.921 stack.
-
- Interface: The Q.921 stack contains 2 layers.
-
- - One interface layer.
- - One driver layer.
-
- The interface layer contains the interface functions required
- for a layer 2 stack to be able to send and receive messages.
-
- The driver layer will simply feed bytes into the ship as
- required and queue messages received out from the ship.
-
- Q921TimeTick The Q.921 like any other blackbox
- modules contains no thread by it's own
- and must therefore be called regularly
- by an external 'thread' to do maintenance
- etc.
-
- Q921Rx32 Receive message from layer 3. Called by
- the layer 3 stack to send a message.
-
-
- NOTE: The following are not yet implemented
-
- OnQ921Error Function called every if an error is
- detected.
-
- OnQ921Log Function called if logging is active.
-
-
- Maintenance/Configuration interface
- Logging
- DL_ message passing to layer 3
- Timers
- Api commands to tell 921 to stop and start for a trunk
-
- Created: 27.dec.2000/JVB
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-*****************************************************************************/
-
-/****************************************************************************
- * Changes:
- *
- * - June,July 2008: Stefan Knoblich :
- * Add PTMP TEI management
- * Add timers
- * Add retransmit counters
- * Add logging
- * Various cleanups
- *
- ****************************************************************************/
-
-#ifndef _Q921
-#define _Q921
-
-#define Q921MAXHDLCSPACE 3000
-#define L2UCHAR unsigned char /* Min 8 bit */
-#define L2USHORT unsigned short /* 16 bit */
-#define L2INT int /* Min 16 bit signed */
-#define L2ULONG unsigned long /* Min 32 bit */
-#define L2TRUNK Q921Data_t *
-
-#define Q921_TEI_BCAST 127
-#define Q921_TEI_MAX Q921_TEI_BCAST
-
-#define Q921_TEI_DYN_MIN 64
-#define Q921_TEI_DYN_MAX 126
-
-
-typedef enum /* Network/User Mode */
-{
- Q921_TE=0, /* 0 : User Mode */
- Q921_NT=1 /* 1 : Network Mode */
-} Q921NetUser_t;
-
-typedef enum /* Type of connection */
-{
- Q921_PTP=0, /* 0 : Point-To-Point */
- Q921_PTMP=1 /* 1 : Point-To-Multipoint */
-} Q921NetType_t;
-
-typedef enum
-{
- Q921_LOG_NONE = -1,
- Q921_LOG_EMERG = 0,
- Q921_LOG_ALERT,
- Q921_LOG_CRIT,
- Q921_LOG_ERROR,
- Q921_LOG_WARNING,
- Q921_LOG_NOTICE,
- Q921_LOG_INFO,
- Q921_LOG_DEBUG
-} Q921LogLevel_t;
-
-
-/*
- * Messages for L2 <-> L3 communication
- */
-typedef enum {
- Q921_DL_ESTABLISH = 0,
- Q921_DL_ESTABLISH_CONFIRM,
- Q921_DL_RELEASE,
- Q921_DL_RELEASE_CONFIRM,
- Q921_DL_DATA,
- Q921_DL_UNIT_DATA
-} Q921DLMsg_t;
-
-typedef int (*Q921Tx21CB_t) (void *, L2UCHAR *, L2INT);
-typedef int (*Q921Tx23CB_t) (void *, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *, L2INT);
-typedef int (*Q921LogCB_t) (void *, Q921LogLevel_t, char *, L2INT);
-
-struct Q921_Link;
-
-typedef struct Q921Data
-{
- L2INT initialized;
-
- L2UCHAR sapi; /*!< User assigned SAPI */
- L2UCHAR tei; /*!< User assigned TEI value */
-
- L2INT Q921HeaderSpace;
- Q921NetUser_t NetUser;
- Q921NetType_t NetType;
-
- struct Q921_Link *context; /*!< per-TEI / link context space */
-
- /* timers */
- L2ULONG T202; /*!< PTMP TE mode TEI retransmit timer */
- L2ULONG T200Timeout;
- L2ULONG T201Timeout;
- L2ULONG T202Timeout;
- L2ULONG T203Timeout;
-
- L2ULONG TM01Timeout;
-
- /* counters */
- L2ULONG N200Limit; /*!< max retransmit */
-
- L2ULONG N202; /*!< PTMP TE mode retransmit counter */
- L2ULONG N202Limit; /*!< PTMP TE mode max retransmit */
-
- L2ULONG N201Limit; /*!< max number of octets */
- L2ULONG k; /*!< max number of unacknowledged I frames */
-
- /* callbacks and callback data pointers */
- Q921Tx21CB_t Q921Tx21Proc;
- Q921Tx23CB_t Q921Tx23Proc;
- void *PrivateData21;
- void *PrivateData23;
-
- /* logging */
- Q921LogLevel_t loglevel; /*!< trunk loglevel */
- Q921LogCB_t Q921LogProc; /*!< log callback procedure */
- void *PrivateDataLog; /*!< private data pointer for log proc */
-
- /* tei mgmt */
- L2UCHAR tei_map[Q921_TEI_MAX]; /*!< */
-
- L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; /*!< HDLC input queue */
-} Q921Data_t;
-
-/*
- * Public functions
- */
-int Q921_InitTrunk(L2TRUNK trunk,
- L2UCHAR sapi,
- L2UCHAR tei,
- Q921NetUser_t NetUser,
- Q921NetType_t NetType,
- L2INT hsize,
- Q921Tx21CB_t cb21,
- Q921Tx23CB_t cb23,
- void *priv21,
- void *priv23);
-int Q921Start(L2TRUNK trunk);
-int Q921Stop(L2TRUNK trunk);
-
-void Q921SetLogCB(L2TRUNK trunk, Q921LogCB_t func, void *priv);
-void Q921SetLogLevel(L2TRUNK trunk, Q921LogLevel_t level);
-
-int Q921Rx12(L2TRUNK trunk);
-int Q921Rx32(L2TRUNK trunk, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR * Mes, L2INT Size);
-
-int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size);
-
-void Q921SetGetTimeCB(L2ULONG (*callback)(void));
-void Q921TimerTick(L2TRUNK trunk);
-
-#endif
diff --git a/libs/openzap/src/isdn/include/Q921priv.h b/libs/openzap/src/isdn/include/Q921priv.h
deleted file mode 100644
index d2d838c399..0000000000
--- a/libs/openzap/src/isdn/include/Q921priv.h
+++ /dev/null
@@ -1,321 +0,0 @@
-/*****************************************************************************
-
- FileName: Q921priv.h
-
- Description: Private declarations
-
- Created: 08.Aug.2008/STKN
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2008, Stefan Knoblich, axsentis GmbH. All rights reserved.
- email:s.knoblich@axsentis.de
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-*****************************************************************************/
-#ifndef _Q921_PRIV_H_
-#define _Q921_PRIV_H_
-
-#ifdef _MSC_VER
-#ifndef __inline__
-#define __inline__ __inline
-#endif
-#if (_MSC_VER >= 1400) /* VC8+ */
-#ifndef _CRT_SECURE_NO_DEPRECATE
-#define _CRT_SECURE_NO_DEPRECATE
-#endif
-#ifndef _CRT_NONSTDC_NO_DEPRECATE
-#define _CRT_NONSTDC_NO_DEPRECATE
-#endif
-#endif
-#ifndef strcasecmp
-#define strcasecmp(s1, s2) _stricmp(s1, s2)
-#endif
-#ifndef strncasecmp
-#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
-#endif
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
-#endif
-
-typedef enum /* Q.921 States */
-{
- Q921_STATE_STOPPED = 0, /* Trunk stopped */
- Q921_STATE_TEI_UNASSIGNED = 1, /* TEI unassigned */
- Q921_STATE_TEI_AWAITING, /* Assign awaiting TEI */
- Q921_STATE_TEI_ESTABLISH, /* Establish awaiting TEI */
- Q921_STATE_TEI_ASSIGNED, /* TEI assigned */
- Q921_STATE_AWAITING_ESTABLISHMENT, /* Awaiting establishment */
- Q921_STATE_AWAITING_RELEASE, /* Awaiting release */
- Q921_STATE_MULTIPLE_FRAME_ESTABLISHED, /* Multiple frame established */
- Q921_STATE_TIMER_RECOVERY /* Timer recovery */
-} Q921State_t;
-
-/*
- * Flags
- */
-enum Q921_Flags {
- Q921_FLAG_L3_INITIATED = (1 << 0),
-
- Q921_FLAG_UI_FRAME_QUEUED = (1 << 1),
- Q921_FLAG_I_FRAME_QUEUED = (1 << 2),
-
- Q921_FLAG_ACK_PENDING = (1 << 3),
- Q921_FLAG_REJECT = (1 << 4),
-
- Q921_FLAG_RECV_BUSY = (1 << 5),
- Q921_FLAG_PEER_RECV_BUSY = (1 << 6)
-};
-
-#define Q921_SET_FLAG(x, f) ((x)->flags |= f)
-#define Q921_CHECK_FLAG(x, f) ((x)->flags & f)
-#define Q921_CLEAR_FLAG(x, f) ((x)->flags &= ~f)
-
-
-/*
- * dynamic TEI handling
- */
-#define Q921_SAPI_TEI 63 /* SAPI for all TEI Messages */
-#define Q921_LAYER_ENT_ID_TEI 0x0f /* UN Layer Management Entity ID for TEI Mgmt */
-#define Q921_LAYER_ENT_ID_Q931 0x08 /* Q.931 Layer Management Entity ID */
-
-
-typedef enum {
- Q921_TEI_ID_REQUEST = 1,
- Q921_TEI_ID_ASSIGNED,
- Q921_TEI_ID_DENIED,
- Q921_TEI_ID_CHECKREQ,
- Q921_TEI_ID_CHECKRESP,
- Q921_TEI_ID_REMOVE,
- Q921_TEI_ID_VERIFY
-} Q921TeiMessageType_t;
-
-
-/**
- * Per-Datalink context
- */
-struct Q921_Link {
- L2UCHAR tei; /*!< This endpoint's TEI */
-
- L2UCHAR va;
- L2UCHAR vs;
- L2UCHAR vr;
-
- L2INT flags;
- Q921State_t state;
-
- L2ULONG N202; /*!< PTMP TE mode retransmit counter */
- L2ULONG N200; /*!< retransmit counter (per-TEI in PTMP NT mode) */
-
- L2ULONG TM01; /*!< Datalink inactivity disconnect timer */
-
- L2ULONG T200;
- L2ULONG T201; /*!< PTMP NT mode timer */
- L2ULONG T203;
-
- L2USHORT ri; /*!< random id for TEI request mgmt */
-
- /* I + UI Frame queue */
- L2UCHAR UIFrameQueue[Q921MAXHDLCSPACE];
- L2UCHAR IFrameQueue[Q921MAXHDLCSPACE];
- L2UCHAR IFrameResendQueue[Q921MAXHDLCSPACE];
-};
-
-
-#define Q921_LINK_CONTEXT(tr, tei) \
- (Q921_IS_PTMP_NT(tr) && tei != Q921_TEI_BCAST) ? ((struct Q921_Link *)&(tr)->context[tei]) : (tr)->context
-
-#define Q921_TRUNK_CONTEXT(tr) \
- (tr)->context
-
-#define Q921_LOGBUFSIZE 2000
-#define INITIALIZED_MAGIC 42
-
-/*
- * Helper macros
- */
-#define Q921_INC_COUNTER(x) (x = (x + 1) % 128)
-#define Q921_DEC_COUNTER(x) (x = (x) ? (x - 1) : 127)
-
-#define Q921_UFRAME_HEADER_SIZE 3
-#define Q921_UFRAME_DATA_OFFSET(tr) ((tr)->Q921HeaderSpace + Q921_UFRAME_HEADER_SIZE)
-
-#define Q921_SFRAME_HEADER_SIZE 4
-#define Q921_SFRAME_DATA_OFFSET(tr) ((tr)->Q921HeaderSpace + Q921_SFRAME_HEADER_SIZE)
-
-#define Q921_IFRAME_HEADER_SIZE 4
-#define Q921_IFRAME_DATA_OFFSET(tr) ((tr)->Q921HeaderSpace + Q921_IFRAME_HEADER_SIZE)
-
-#define Q921_IS_TE(x) ((x)->NetUser == Q921_TE)
-#define Q921_IS_NT(x) ((x)->NetUser == Q921_NT)
-
-#define Q921_IS_STOPPED(tr) ((tr)->state == Q921_STATE_STOPPED)
-
-/* TODO: rework this one */
-#define Q921_IS_READY(tr) ((tr)->state >= Q921_STATE_TEI_ASSIGNED)
-
-#define Q921_IS_PTMP(x) ((x)->NetType == Q921_PTMP)
-#define Q921_IS_PTMP_TE(x) ((x)->NetType == Q921_PTMP && (x)->NetUser == Q921_TE)
-#define Q921_IS_PTMP_NT(x) ((x)->NetType == Q921_PTMP && (x)->NetUser == Q921_NT)
-
-#define Q921_IS_PTP(x) ((x)->NetType == Q921_PTP)
-#define Q921_IS_PTP_TE(x) ((x)->NetType == Q921_PTP && (x)->NetUser == Q921_TE)
-#define Q921_IS_PTP_NT(x) ((x)->NetType == Q921_PTP && (x)->NetUser == Q921_NT)
-
-/* Make life a little easier */
-#define Q921_COMMAND(x) ((x)->NetUser == Q921_TE ? 0 : 1)
-#define Q921_RESPONSE(x) ((x)->NetUser == Q921_TE ? 1 : 0)
-
-#define Q921_IS_COMMAND(tr, x) ((x) == (Q921_IS_TE(tr) ? 1 : 0))
-#define Q921_IS_RESPONSE(tr, x) ((x) == (Q921_IS_TE(tr) ? 0 : 1))
-
-
-/*******************************************************************************
- * Private functions
- *******************************************************************************/
-
-/*
- * L1 / L2 Interface
- */
-static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size);
-static int Q921Tx23Proc(L2TRUNK trunk, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *Msg, L2INT size);
-
-
-/*
- * Timers
- */
-static L2ULONG Q921GetTime(void);
-
-static void Q921T200TimerStart(L2TRUNK trunk, L2UCHAR tei);
-static void Q921T200TimerStop(L2TRUNK trunk, L2UCHAR tei);
-static void Q921T200TimerReset(L2TRUNK trunk, L2UCHAR tei);
-static void Q921T200TimerExpire(L2TRUNK trunk, L2UCHAR tei);
-
-static void Q921T201TimerStart(L2TRUNK trunk, L2UCHAR tei);
-static void Q921T201TimerStop(L2TRUNK trunk, L2UCHAR tei);
-/* static void Q921T201TimerReset(L2TRUNK trunk, L2UCHAR tei); - Unused for now */
-static void Q921T201TimerExpire(L2TRUNK trunk, L2UCHAR tei);
-
-static void Q921T202TimerStart(L2TRUNK trunk);
-static void Q921T202TimerStop(L2TRUNK trunk);
-static void Q921T202TimerReset(L2TRUNK trunk);
-static void Q921T202TimerExpire(L2TRUNK trunk);
-
-static void Q921T203TimerStart(L2TRUNK trunk, L2UCHAR tei);
-static void Q921T203TimerStop(L2TRUNK trunk, L2UCHAR tei);
-static void Q921T203TimerReset(L2TRUNK trunk, L2UCHAR tei);
-static void Q921T203TimerExpire(L2TRUNK trunk, L2UCHAR tei);
-
-static void Q921TM01TimerStart(L2TRUNK trunk, L2UCHAR tei);
-/* static void Q921TM01TimerStop(L2TRUNK trunk, L2UCHAR tei); - Unused for now */
-static void Q921TM01TimerReset(L2TRUNK trunk, L2UCHAR tei);
-/* static void Q921TM01TimerExpire(L2TRUNK trunk, L2UCHAR tei); - Unused for now */
-
-/*
- * Frame encoding
- */
-static int Q921SendS(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR sv, L2UCHAR *mes, L2INT size);
-static int Q921SendU(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR m, L2UCHAR *mes, L2INT size);
-
-static int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
-static int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
-static int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
-static int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
-static int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
-static int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
-static int Q921SendUN(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf, L2UCHAR *mes, L2INT size);
-static int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
-
-/*
- * Frame decoding
- */
-static int Q921ProcIFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcSFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcUFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-
-static int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcDM(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcUA(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcDISC(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcRR(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcRNR(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921ProcREJ(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-
-
-/*
- * (Common) procedures defined in the Q.921 SDL
- */
-static int Q921SendEnquiry(L2TRUNK trunk, L2UCHAR tei);
-static int Q921SendEnquiryResponse(L2TRUNK trunk, L2UCHAR tei);
-static void Q921ResetExceptionConditions(L2TRUNK trunk, L2UCHAR tei);
-static int Q921EstablishDataLink(L2TRUNK trunk, L2UCHAR tei);
-static int Q921NrErrorRecovery(L2TRUNK trunk, L2UCHAR tei);
-static int Q921InvokeRetransmission(L2TRUNK trunk, L2UCHAR tei, L2UCHAR nr);
-static int Q921AcknowledgePending(L2TRUNK trunk, L2UCHAR tei);
-/*
-static int Q921SetReceiverBusy(L2TRUNK trunk);
-static int Q921ClearReceiverBusy(L2TRUNK trunk);
-*/
-
-/*
- * Queueing
- */
-static int Q921SendQueuedIFrame(L2TRUNK trunk, L2UCHAR tei);
-static int Q921EnqueueI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size);
-
-/*
- * TEI management
- */
-static int Q921TeiSendAssignRequest(L2TRUNK trunk);
-static int Q921TeiProcAssignResponse(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921TeiSendVerifyRequest(L2TRUNK trunk);
-static int Q921TeiProcCheckRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921TeiProcRemoveRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921TeiProcAssignRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921TeiProcCheckResponse(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921TeiProcVerifyRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
-static int Q921TeiSendRemoveRequest(L2TRUNK trunk, L2UCHAR tei);
-static int Q921TeiSendDenyResponse(L2TRUNK trunk, L2UCHAR tei, L2USHORT ri);
-static int Q921TeiSendAssignedResponse(L2TRUNK trunk, L2UCHAR tei, L2USHORT ri);
-static int Q921TeiSendCheckRequest(L2TRUNK trunk, L2UCHAR tei);
-
-/*
- * Logging
- */
-static int Q921Log(L2TRUNK trunk, Q921LogLevel_t level, const char *fmt, ...);
-static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2UCHAR *mes, L2INT size, const char *fmt, ...);
-
-/*
- * State handling
- */
-static int Q921ChangeState(L2TRUNK trunk, Q921State_t state, L2UCHAR tei);
-
-#endif
diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h
deleted file mode 100644
index 0dbafd9f11..0000000000
--- a/libs/openzap/src/isdn/include/Q931.h
+++ /dev/null
@@ -1,1175 +0,0 @@
-/******************************************************************************
-
- FileName: Q931.h
-
- Contents: Header and definition for the ITU-T Q.931 stack. The
- header contents the following parts:
-
- - Definition of codes
- - Definition of information elements (Q931ie_).
- - Definition of messages (Q931mes_).
- - Definitian of variables (var_).
- - Function prototypes.
-
- Description: The Q.931 stack provided here covers ITU-T Q.931 w/Q.932
- supplementary services for both PRI, BRI and variants.
- The stack is generic and designed to deal with variants as
- needed.
-
- The stack uses the following interface functions:
-
- - Q931Initialize Initialize the Q.931 stack.
- - Q931Rx23 Receive a message from layer 2
- - Q931Tx32 Send a message to layer 2
- - Q931Rx43 Receive a message from layer 4 or above.
- - Q931Tx34 Send a message to layer 4 or above.
- - Q931TimeTick Periodical timer processing.
- - Q931ErrorProc Callback for stack error message.
-
- The protocol is a module with no external dependencies and
- can easely be ported to any operating system like Windows,
- Linux, rtos and others.
-
- Related Files: Q931.h Q.931 Definitions
- Q931.c Q.931 Interface Functions.
- Q931api.c Low level L4 API functions.
-
- Q932.h Q.932 Suplementary Services
- Q932mes.c Q.932 encoders/coders
-
- Q931mes.c Q.931 Message encoders/coders
- Q931ie.c Q.931 IE encoders/coders
- Q931StateTE.c Generic Q.931 TE State Engine
- Q931StateNT.c Generic Q.931 NT State Engine
-
- Design Note 1: For each variant please add separate files starting with
- the variant short-name as follows:
-
- .h Spesific headers needed.
- mes.c Message encoders/decores.
- ie.c IE encoders/decoders.
- StateTE.c TE side state engine.
- StateNT.c NT side state engine.
-
- Design Note 2: The stack is deliberatly made non-threading. Use 1
- thread per Trunk, but lock access from the timertick
- and rx, tx functions. And make sure the callbacks only
- dump messages to a queue, no time-consuming processing
- inside stack processing.
-
- All stack processing is async 'fire and forget', meaning
- that there are not, and should not be any time-consuming
- processing within the stack-time. The best way to thread
- a stack is to use one single thread that signal 5 queues.
-
- - Incoming L2 queue.
- - Incoming L4 queue.
- - Outgoing L2 queue.
- - Outgoing L4 queue.
- - Error/Trace queue.
-
- Design Note 3: DSP optimization. The L3 (Rx23) can be called directly
- from a HDLC receiver without usage of queues for optimized
- processing. But keep in mind that Q.931 calls Tx34 or Tx32
- as part of receiving a message from Layer 2.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-******************************************************************************/
-
-#ifndef _Q931_NL
-#define _Q931_NL
-
-/* uncomment the #define below to add x.25 support to the Q.931 */
-/* #define Q931_X25_SUPPORT */
-
-#include "stdio.h"
-
-#ifdef _MSC_VER
-#pragma warning(disable:4100)
-#ifndef strcasecmp
-#define strcasecmp(s1, s2) _stricmp(s1, s2)
-#endif
-#endif
-#include
-
-
-/*****************************************************************************
-
- Enum helper macros
-
-*****************************************************************************/
-#define Q931_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL };
-#define Q931_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type);
-#define Q931_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \
- _TYPE _FUNC1 (const char *name) \
- { \
- int i; \
- _TYPE t = _MAX ; \
- \
- for (i = 0; i < _MAX ; i++) { \
- if (!strcasecmp(name, _STRINGS[i])) { \
- t = (_TYPE) i; \
- break; \
- } \
- } \
- \
- return t; \
- } \
- const char * _FUNC2 (_TYPE type) \
- { \
- if (type > _MAX) { \
- type = _MAX; \
- } \
- return _STRINGS[(int)type]; \
- } \
-
-/*****************************************************************************
-
- Error Codes
-
-*****************************************************************************/
-typedef enum {
- Q931E_NO_ERROR = 0,
-
- Q931E_UNKNOWN_MESSAGE = -3001,
- Q931E_ILLEGAL_IE = -3002,
- Q931E_UNKNOWN_IE = -3003,
- Q931E_BEARERCAP = -3004,
- Q931E_HLCOMP = -3005,
- Q931E_LLCOMP = -3006,
- Q931E_INTERNAL = -3007,
- Q931E_MISSING_CB = -3008,
- Q931E_UNEXPECTED_MESSAGE = -3009,
- Q931E_ILLEGAL_MESSAGE = -3010,
- Q931E_TOMANYCALLS = -3011,
- Q931E_INVALID_CRV = -3012,
- Q931E_CALLID = -3013,
- Q931E_CALLSTATE = -3014,
- Q931E_CALLEDSUB = -3015,
- Q931E_CALLEDNUM = -3016,
- Q931E_CALLINGNUM = -3017,
- Q931E_CALLINGSUB = -3018,
- Q931E_CAUSE = -3019,
- Q931E_CHANID = -3020,
- Q931E_DATETIME = -3021,
- Q931E_DISPLAY = -3022,
- Q931E_KEYPADFAC = -3023,
- Q931E_NETFAC = -3024,
- Q931E_NOTIFIND = -3025,
- Q931E_PROGIND = -3026,
- Q931E_RESTARTIND = -3027,
- Q931E_SEGMENT = -3028,
- Q931E_SIGNAL = -3029,
- Q931E_GENERIC_DIGITS = -3030
-} q931_error_t;
-
-/* The q931_error_t enum should be kept in sync with the q931_error_names array in Q931.c */
-
-const char *q931_error_to_name(q931_error_t error);
-
-/*****************************************************************************
-
- Some speed optimization can be achieved by changing all variables to the
- word size of your processor. A 32 bit processor has to do a lot of extra
- work to read a packed 8 bit integer. Changing all fields to 32 bit integer
- will result in usage of some extra space, but will speed up the stack.
-
- The stack has been designed to allow L3UCHAR etc. to be any size of 8 bit
- or larger.
-
-*****************************************************************************/
-
-#define L3UCHAR unsigned char /* Min 8 bit */
-#define L3USHORT unsigned short /* Min 16 bit unsigned */
-#define L3UINT unsigned int /* Min 16 bit unsigned */
-#define L3INT int /* Min 16 bit signed */
-#define L3ULONG unsigned long /* Min 32 bit */
-#define L3BOOL char /* Min 1 bit, valuse 0 & 1 only */
-
-#define L3TRUE 1
-#define L3FALSE 0
-
-/*****************************************************************************
-
- Global defines.
-
-*****************************************************************************/
-
-typedef L3USHORT ie; /* Special data type to hold a dynamic */
- /* or optional information element as */
- /* part of a message struct. MSB = 1 */
- /* indicate that the ie is present, the */
- /* last 15 bits is an offset ( or the */
- /* value for single octet ) to the */
- /* struct holding the ie. Offset = 0 */
- /* is buf[1] etc. */
- /* ie == 0xffff indicates error */
-
-/*****************************************************************************
-
- MAXTRUNKS sets how many physical trunks this system might have. This
- number should be keept at a minimum since it will use global space.
-
- It is recommended that you leave MAXCHPERTRUNK as is
-
-*****************************************************************************/
-
-#define Q931_LOGBUFSIZE 1024 /* size of logging buffer */
-
-#define Q931L4BUF 1000 /* size of message buffer */
-
-#define Q931L2BUF 300 /* size of message buffer */
-
-#define Q931MAXTRUNKS 4 /* Total number of trunks that will be */
- /* processed by this instance of the */
- /* stack */
-
-#define Q931MAXCHPERTRUNK 32 /* Number of channels per trunk. The */
- /* stack uses a static set of 32 */
- /* channels regardless if it is E1, T1 */
- /* or BRI that actually is used. */
-
-#define Q931MAXCALLPERTRUNK (Q931MAXCHPERTRUNK * 2)
- /* Number of max active CRV per trunk. */
- /* Q.931 can have more calls than there */
- /* are channels. */
-
-
-#define Q931_IS_BRI(x) ((x)->TrunkType == Q931_TrType_BRI || (x)->TrunkType == Q931_TrType_BRI_PTMP)
-#define Q931_IS_PRI(x) (!Q931_IS_BRI(x))
-
-#define Q931_IS_PTP(x) ((x)->TrunkType != Q931_TrType_BRI_PTMP)
-#define Q931_IS_PTMP(X) ((x)->TrunkType == Q931_TrType_BRI_PTMP)
-
-#define Q931_BRI_MAX_CRV 127
-#define Q931_PRI_MAX_CRV 32767
-
-/*****************************************************************************
-
- The following defines control the dialect switch tables and should only be
- changed when a new dialect needs to be inserted into the stack.
-
- This stack uses an array of functions to know which function to call as
- it receives a SETUP message etc. A new dialect can when choose to use
- the proc etc. for standard Q.931 or insert a modified proc.
-
- This technique has also been used to distinguish between user and network
- mode to make the code as easy to read and maintainable as possible.
-
- A message and IE index have been used to save space. These indexes allowes
- the message or IE code to be used directly and will give back a new index
- into the table.
-
-*****************************************************************************/
-
-/* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */
-/* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */
-/* not used. */
-#define Q931MAXDLCT 8 /* Max dialects included in this */
- /* compile. User and Network count as */
- /* one dialect each. */
-
-#define Q931MAXMES 128 /* Number of messages */
-#define Q931MAXIE 255 /* Number of IE */
-#define Q931MAXUSEDIE 50 /* Maximum number of ie types per Dialect */
-#define Q931MAXCODESETS 7 /* Maximum number of codests (by spec, 0-7) */
-#define Q931MAXSTATE 100 /* Size of state tables */
-#define Q931MAXTIMER 25 /* Maximum number of timers */
-
-/*****************************************************************************
-
- Call States for ITU-T Q.931 TE (User Mode)
-
-*****************************************************************************/
-
-#define Q931_U0 0
-#define Q931_U1 1
-#define Q931_U2 2
-#define Q931_U3 3
-#define Q931_U4 4
-#define Q931_U6 6
-#define Q931_U7 7
-#define Q931_U8 8
-#define Q931_U9 9
-#define Q931_U10 10
-#define Q931_U11 11
-#define Q931_U12 12
-#define Q931_U15 15
-#define Q931_U17 17
-#define Q931_U19 19
-#define Q931_U25 25
-
-/*****************************************************************************
-
- Call States for ITU-T Q.931 NT (Network Mode)
-
-*****************************************************************************/
-#define Q931_N0 (0x0100 | 0)
-#define Q931_N1 (0x0100 | 1)
-#define Q931_N2 (0x0100 | 2)
-#define Q931_N3 (0x0100 | 3)
-#define Q931_N4 (0x0100 | 4)
-#define Q931_N6 (0x0100 | 6)
-#define Q931_N7 (0x0100 | 7)
-#define Q931_N8 (0x0100 | 8)
-#define Q931_N9 (0x0100 | 9)
-#define Q931_N10 (0x0100 | 11)
-#define Q931_N11 (0x0100 | 11)
-#define Q931_N12 (0x0100 | 12)
-#define Q931_N15 (0x0100 | 15)
-#define Q931_N17 (0x0100 | 17)
-#define Q931_N19 (0x0100 | 19)
-#define Q931_N22 (0x0100 | 22)
-#define Q931_N25 (0x0100 | 25)
-
-/*****************************************************************************
-
- Q.931 Message codes
-
-*****************************************************************************/
-
-#define Q931mes_ALERTING 0x01 /* 0000 0001 */
-#define Q931mes_CALL_PROCEEDING 0x02 /* 0000 0010 */
-#define Q931mes_CONNECT 0x07 /* 0000 0111 */
-#define Q931mes_CONNECT_ACKNOWLEDGE 0x0f /* 0000 1111 */
-#define Q931mes_PROGRESS 0x03 /* 0000 0011 */
-#define Q931mes_SETUP 0x05 /* 0000 0101 */
-#define Q931mes_SETUP_ACKNOWLEDGE 0x0d /* 0000 1101 */
-#define Q931mes_RESUME 0x26 /* 0010 0110 */
-#define Q931mes_RESUME_ACKNOWLEDGE 0x2e /* 0010 1110 */
-#define Q931mes_RESUME_REJECT 0x22 /* 0010 0010 */
-#define Q931mes_SUSPEND 0x25 /* 0010 0101 */
-#define Q931mes_SUSPEND_ACKNOWLEDGE 0x2d /* 0010 1101 */
-#define Q931mes_SUSPEND_REJECT 0x21 /* 0010 0001 */
-#define Q931mes_USER_INFORMATION 0x20 /* 0010 0000 */
-#define Q931mes_DISCONNECT 0x45 /* 0100 0101 */
-#define Q931mes_RELEASE 0x4d /* 0100 1101 */
-#define Q931mes_RELEASE_COMPLETE 0x5a /* 0101 1010 */
-#define Q931mes_RESTART 0x46 /* 0100 0110 */
-#define Q931mes_RESTART_ACKNOWLEDGE 0x4e /* 0100 1110 */
-#define Q931mes_CONGESTION_CONTROL 0x79 /* 0111 1001 */
-#define Q931mes_INFORMATION 0x7b /* 0111 1011 */
-#define Q931mes_NOTIFY 0x6e /* 0110 1110 */
-#define Q931mes_STATUS 0x7d /* 0111 1101 */
-#define Q931mes_STATUS_ENQUIRY 0x75 /* 0111 0101 */
-#define Q931mes_SEGMENT 0x60 /* 0110 0000 */
-
-#define Q931mes_SERVICE 0x0f /* 0000 1111 */
-#define Q931mes_SERVICE_ACKNOWLEDGE 0x07 /* 0000 0111 */
-
-
-/**
- * Generic Q.931 Timers
- */
-enum {
- Q931_TIMER_T300 = 1, /* */
- Q931_TIMER_T301,
- Q931_TIMER_T302,
- Q931_TIMER_T303,
- Q931_TIMER_T304,
- Q931_TIMER_T305,
- Q931_TIMER_T306,
- Q931_TIMER_T307,
- Q931_TIMER_T308,
- Q931_TIMER_T309,
- Q931_TIMER_T310,
- Q931_TIMER_T311,
- Q931_TIMER_T312,
- Q931_TIMER_T313,
- Q931_TIMER_T314,
- Q931_TIMER_T315,
- Q931_TIMER_T316,
- Q931_TIMER_T317,
- Q931_TIMER_T318,
- Q931_TIMER_T319,
- Q931_TIMER_T320,
- Q931_TIMER_T321,
- Q931_TIMER_T322,
-};
-
-/**
- * Q.931 ToN
- */
-enum {
- Q931_TON_UNKNOWN = 0x00,
- Q931_TON_INTERNATIONAL = 0x01,
- Q931_TON_NATIONAL = 0x02,
- Q931_TON_NETWORK_SPECIFIC = 0x03,
- Q931_TON_SUBSCRIBER_NUMBER = 0x04,
- Q931_TON_ABBREVIATED_NUMBER = 0x06,
- Q931_TON_RESERVED = 0x07
-};
-
-/**
- * Q.931 Numbering Plan
- */
-enum {
- Q931_NUMPLAN_UNKNOWN = 0x00,
- Q931_NUMPLAN_E164 = 0x01,
- Q931_NUMPLAN_X121 = 0x03,
- Q931_NUMPLAN_F69 = 0x04,
- Q931_NUMPLAN_NATIONAL = 0x08,
- Q931_NUMPLAN_PRIVATE = 0x09,
- Q931_NUMPLAN_RESERVED = 0x0e
-};
-
-/**
- * Q.931 Presentation Indicator
- */
-enum {
- Q931_PRES_ALLOWED = 0x00,
- Q931_PRES_RESTRICTED = 0x01,
- Q931_PRES_NOT_AVAILABLE = 0x02,
- Q931_PRES_RESERVED = 0x03
-};
-
-/**
- * Q.931 Screening Indicator
- */
-enum {
- Q931_SCREEN_USER_NOT_SCREENED = 0x00,
- Q931_SCREEN_USER_VERIFIED_PASSED = 0x01,
- Q931_SCREEN_USER_VERIFIED_FAILED = 0x02,
- Q931_SCREEN_NETWORK = 0x03
-};
-
-/**
- * Q.931 Coding Standard
- */
-enum {
- Q931_CODING_ITU = 0x00,
- Q931_CODING_ISO = 0x01,
- Q931_CODING_NATIONAL = 0x02,
- Q931_CODING_NETWORK = 0x03
-};
-
-/**
- * Q.931 High layer characteristik id
- */
-enum {
- Q931_HLCHAR_TELEPHONY = 0x01,
- Q931_HLCHAR_FAX_G23 = 0x04,
- Q931_HLCHAR_FAX_G4 = 0x21,
- Q931_HLCHAR_FAX_G4II = 0x24,
- Q931_HLCHAR_T102 = 0x32,
- Q931_HLCHAR_T101 = 0x33,
- Q931_HLCHAR_F60 = 0x35,
- Q931_HLCHAR_X400 = 0x38,
- Q931_HLCHAR_X200 = 0x41
-};
-
-/**
- * Q.931 User information layer 1 protocol
- */
-enum {
- Q931_UIL1P_V110 = 0x01,
- Q931_UIL1P_I460 = 0x01,
- Q931_UIL1P_X30 = 0x01,
-
- Q931_UIL1P_G711U = 0x02,
- Q931_UIL1P_G711A = 0x03,
- Q931_UIL1P_G721 = 0x04,
-
- Q931_UIL1P_H221 = 0x05,
- Q931_UIL1P_H242 = 0x05,
-
- Q931_UIL1P_H223 = 0x06,
- Q931_UIL1P_H245 = 0x06,
-
- Q931_UIL1P_RATE_ADAP = 0x07,
-
- Q931_UIL1P_V120 = 0x08,
- Q931_UIL1P_X31 = 0x09
-};
-
-/**
- * Q.931 Information Transfer Capability
- */
-enum {
- Q931_ITC_SPEECH = 0x00,
- Q931_ITC_UNRESTRICTED = 0x08,
- Q931_ITC_RESTRICTED = 0x09,
- Q931_ITC_3K1_AUDIO = 0x10,
- Q931_ITC_UNRESTRICTED_TONES = 0x11,
- Q931_ITC_VIDEO = 0x18
-};
-
-/**
- * Q.931 Information transfer rate
- */
-enum {
- Q931_ITR_PACKET = 0x00,
- Q931_ITR_64K = 0x10,
- Q931_ITR_128K = 0x11,
- Q931_ITR_384K = 0x13,
- Q931_ITR_1536K = 0x15,
- Q931_ITR_1920K = 0x17,
- Q931_ITR_MULTI = 0x18
-};
-
-/*****************************************************************************
-
- Struct: Q931mes_Header
-
- Description: Used to read the header & message code.
-
-*****************************************************************************/
-typedef struct {
- L3UINT Size; /* Size of message in bytes */
- L3UCHAR ProtDisc; /* Protocol Discriminator */
- L3UCHAR MesType; /* Message type */
- L3UCHAR CRVFlag; /* Call reference value flag */
- L3INT CRV; /* Call reference value */
-
-} Q931mes_Header;
-
-/*****************************************************************************
-
- Struct: Q931mes_Generic
-
- Description: Generic header containing all IE's. This is not used, but is
- provided in case a proprietary variant needs it.
-
-*****************************************************************************/
-typedef struct {
- L3UINT Size; /* Size of message in bytes */
- L3UCHAR ProtDisc; /* Protocol Discriminator */
- L3UCHAR MesType; /* Message type */
- L3UCHAR CRVFlag; /* Call reference value flag */
- L3INT CRV; /* Call reference value */
-
- /* WARNING: don't touch anything above this line (TODO: use Q931mes_Header directly to make sure it's the same) */
-
- L3UCHAR Tei; /* TEI */
-
- ie Shift;
- ie MoreData;
- ie SendComplete;
- ie CongestionLevel;
- ie RepeatInd;
-
- ie Segment; /* Segmented message */
- ie BearerCap; /* Bearer Capability */
- ie Cause; /* Cause */
- ie CallState; /* Call State */
- ie CallID; /* Call Identity */
- ie ChanID; /* Channel Identification */
- ie ChangeStatus; /* Change Staus */
- ie ProgInd; /* Progress Indicator */
- ie NetFac; /* Network Spesific Facilities */
- ie NotifInd; /* Notification Indicator */
- ie Display; /* Display */
- ie DateTime; /* Date/Time */
- ie KeypadFac; /* Keypad Facility */
- ie Signal; /* Signal */
- ie InfoRate; /* Information rate */
- ie EndEndTxDelay; /* End to End Transmit Delay */
- ie TransDelSelInd; /* Transmit Delay Sel. and Ind. */
- ie PackParam; /* Packed Layer Binary parameters */
- ie PackWinSize; /* Packet Layer Window Size */
- ie PackSize; /* Packed Size */
- ie ClosedUserGrp; /* Closed User Group */
- ie RevChargeInd; /* Reverse Charging Indicator */
- ie CalledNum; /* Called Party Number */
- ie CalledSub; /* Called Party subaddress */
- ie CallingNum; /* Calling Party Number */
- ie CallingSub; /* Calling Party Subaddress */
- ie RedirNum; /* Redirection Number */
- ie TransNetSel; /* Transmit Network Selection */
- ie LLRepeatInd; /* Repeat Indicator 2 LLComp */
- ie RestartWin; /* Restart Window */
- ie RestartInd; /* Restart Indicator */
- ie LLComp; /* Low Layer Compatibility */
- ie HLComp; /* High Layer Compatibility */
- ie UserUser; /* User-user */
- ie Escape; /* Escape for extension */
- ie Switchhook;
- ie FeatAct;
- ie FeatInd;
- ie GenericDigits;
-
- L3UCHAR buf[1]; /* Buffer for IE's */
-
-} Q931mes_Generic;
-
-
-/*****************************************************************************
-
- Struct: Q931_TrunkInfo
-
- Description: TrunkInfo is the struct entry used to store Q.931 related
- information and state for E1/T1/J1 trunks and associated
- channels in the system.
-
- The user should store this information outside this stack
- and needs to feed the interface functions with a pointer to
- the TrunkInfo entry.
-
-*****************************************************************************/
-typedef struct Q931_TrunkInfo Q931_TrunkInfo_t;
-
-typedef enum {
- Q931_LOG_NONE = -1,
- Q931_LOG_EMERG,
- Q931_LOG_ALERT,
- Q931_LOG_CRIT,
- Q931_LOG_ERROR,
- Q931_LOG_WARNING,
- Q931_LOG_NOTICE,
- Q931_LOG_INFO,
- Q931_LOG_DEBUG
-} Q931LogLevel_t;
-
-typedef L3INT (*Q931Tx34CB_t) (void *,L3UCHAR *, L3INT);
-typedef L3INT (*Q931Tx32CB_t) (void *, L3INT, L3UCHAR, L3UCHAR *, L3INT);
-typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT);
-typedef L3INT (*Q931LogCB_t) (void *, Q931LogLevel_t, char *, L3INT);
-
-typedef enum { /* Network/User Mode. */
- Q931_TE=0, /* 0 : User Mode */
- Q931_NT=1 /* 1 : Network Mode */
-} Q931NetUser_t;
-
-typedef enum { /* Dialect enum */
- Q931_Dialect_Q931 = 0,
- Q931_Dialect_National = 2,
- Q931_Dialect_DMS = 4,
- Q931_Dialect_5ESS = 6, /* Coming soon to a PRI stack near you! */
-
- Q931_Dialect_Count
-} Q931Dialect_t;
-#define DIALECT_STRINGS "q931", "", "national", "", "dms", "", "5ess", ""
-Q931_STR2ENUM_P(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t)
-
-typedef enum { /* Trunk Line Type. */
- Q931_TrType_E1 = 0, /* 0 : E1 Trunk */
- Q931_TrType_T1 = 1, /* 1 : T1 Trunk */
- Q931_TrType_J1 = 2, /* 2 : J1 Trunk */
- Q931_TrType_BRI = 3, /* 3 : BRI Trunk */
- Q931_TrType_BRI_PTMP = 4 /* 4 : BRI PTMP Trunk */
-} Q931_TrunkType_t;
-
-typedef enum { /* Trunk State */
- Q931_TrState_NoAlignment=0, /* Trunk not aligned */
- Q931_TrState_Aligning=1, /* Aligning in progress */
- Q931_TrState_Aligned=2 /* Trunk Aligned */
-} Q931_TrunkState_t;
-
-typedef enum {
- Q931_ChType_NotUsed=0, /* Unused Channel */
- Q931_ChType_B=1, /* B Channel (Voice) */
- Q931_ChType_D=2, /* D Channel (Signalling) */
- Q931_ChType_Sync=3 /* Sync Channel */
-} Q931_ChanType_t;
-
-struct Q931_Call
-{
- L3UCHAR InUse; /* Indicate if entry is in use. */
- /* 0 = Not in Use */
- /* 1 = Active Call. */
-
- L3UCHAR Tei; /* Associated TEI */
-
- L3UCHAR BChan; /* Associated B Channel. */
- /* 0 - 31 valid B chan */
- /* 255 = Not allocated */
-
- L3INT CRV; /* Associated CRV. */
-
- L3UINT State; /* Call State. */
- /* 0 is Idle, but other values are */
- /* defined per dialect. */
- /* Default usage is 1-99 for TE and */
- /* 101 - 199 for NT. */
-
- L3ULONG Timer; /* Timer in ms. The TimeTick will check */
- /* if this has exceeded the timeout, and */
- /* if so call the timers timeout proc. */
-
- L3USHORT TimerID; /* Timer Identification/State */
- /* actual values defined by dialect */
- /* 0 : No timer running */
- /* ITU-T Q.931:301 - 322 Timer running */
-};
-
-struct Q931_TrunkInfo
-{
- Q931NetUser_t NetUser; /* Network/User Mode. */
- Q931_TrunkType_t TrunkType; /* Trunk Line Type. */
- Q931Dialect_t Dialect; /* Q.931 Based dialect index. */
-
- Q931Tx34CB_t Q931Tx34CBProc;
- Q931Tx32CB_t Q931Tx32CBProc;
- Q931ErrorCB_t Q931ErrorCBProc;
- Q931LogCB_t Q931LogCBProc;
- void *PrivateData32;
- void *PrivateData34;
- void *PrivateDataLog;
-
- Q931LogLevel_t loglevel;
-
- L3UCHAR Enabled; /* Enabled/Disabled */
- /* 0 = Disabled */
- /* 1 = Enabled */
-
- Q931_TrunkState_t TrunkState;
-
- L3INT LastCRV; /* Last used crv for the trunk. */
-
- L3UCHAR L3Buf[Q931L4BUF]; /* message buffer for messages to be */
- /* send from Q.931 L4. */
-
- L3UCHAR L2Buf[Q931L2BUF]; /* buffer for messages send to L2. */
-
- /* The auto flags below switch on/off automatic Ack messages. SETUP ACK */
- /* as an example can be sent by the stack in response to SETUP to buy */
- /* time in processing on L4. Setting this to true will cause the stack */
- /* to automatically send this. */
-
- L3BOOL autoSetupAck; /* Indicate if the stack should send */
- /* SETUP ACK or not. 0=No, 1 = Yes. */
-
- L3BOOL autoConnectAck; /* Indicate if the stack should send */
- /* CONNECT ACT or not. 0=No, 1=Yes. */
-
- L3BOOL autoRestartAck; /* Indicate if the stack should send */
- /* RESTART ACK or not. 0=No, 1=Yes. */
-
- L3BOOL autoServiceAck; /* Indicate if the stack should send */
- /* SERVICE ACK or not. 0=No, 1=Yes. */
-
- /* channel array holding info per channel. Usually defined to 32 */
- /* channels to fit an E1 since T1/J1 and BRI will fit inside a E1. */
- struct _charray
- {
- Q931_ChanType_t ChanType; /* Unused, B, D, Sync */
-
- L3UCHAR Available; /* Channel Available Flag */
- /* 0 : Avaiabled */
- /* 1 : Used */
-
- L3INT CRV; /* Associated CRV */
-
- } ch[Q931MAXCHPERTRUNK];
-
- /* Active Call information indentified by CRV. See Q931AllocateCRV for */
- /* initialization of call table. */
- struct Q931_Call call[Q931MAXCALLPERTRUNK];
-};
-
-/*****************************************************************************
-
- Struct: Q931State
-
- Description: Define a Q931 State, legal events and next state for each
- event. Used to simplify the state engine logic. Each state
- engine defines its own state table and the logic need only
- call a helper function to check if the message is legal
- at this stage.
-
-*****************************************************************************/
-typedef struct
-{
- L3INT State;
- L3INT Message;
- L3UCHAR Direction;
-} Q931State;
-
-/*****************************************************************************
-
- Proc table external references.
-
- The proc tables are defined in Q931.c and initialized in Q931Initialize.
-
-*****************************************************************************/
-typedef L3INT (q931proc_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *, L3INT);
-
-typedef L3INT (q931umes_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
-typedef L3INT (q931pmes_func_t) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-
-typedef L3INT (q931uie_func_t) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff);
-typedef L3INT (q931pie_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
-
-typedef L3INT (q931timeout_func_t) (Q931_TrunkInfo_t *pTrunk, L3INT callIndex);
-typedef L3ULONG q931timer_t;
-
-extern q931proc_func_t *Q931Proc[Q931MAXDLCT][Q931MAXMES];
-
-extern q931umes_func_t *Q931Umes[Q931MAXDLCT][Q931MAXMES];
-extern q931pmes_func_t *Q931Pmes[Q931MAXDLCT][Q931MAXMES];
-
-extern q931uie_func_t *Q931Uie[Q931MAXDLCT][Q931MAXIE];
-extern q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE];
-
-extern q931timeout_func_t *Q931Timeout[Q931MAXDLCT][Q931MAXTIMER];
-extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER];
-
-
-/*****************************************************************************
-
- Macro: GetIETotoSize
-
- Syntax: L3INT GetIETotSize(InfoElem ie);
-
- Description: Compute the total size in bytes of an info element including
- size of 'header'.
-
-*****************************************************************************/
-#define Q931GetIETotSize(ie) (((ie.InfoID & 0x80) != 0) ? 1 : ie.LenIE) + 2)
-
-/*****************************************************************************
-
- Macro: IsIEPresent
-
- Syntax: BOOL IsIEPresent(ie InfoElement);
-
- Description: Return TRUE if the Information Element is included.
-
-*****************************************************************************/
-#define Q931IsIEPresent(x) ((x & 0x8000) != 0)
-
-/*****************************************************************************
-
- Macro: GetIEOffset and GetIEValue
-
- Syntax: L3INT GetIEOffset(ie InfoElement)
- L3INT GetIEValue(ie InfoElement)
-
- Description: Returns the offset (or the value )to the Information Element.
-
- Note: GetIEValue assumes that the 15 lsb bit is the value of a
- single octet information element. This macro can not be used
- on a variable information element.
-
-*****************************************************************************/
-#define Q931GetIEOffset(x) (x & 0x7fff)
-#define Q931GetIEValue(x) (x & 0x7fff)
-
-/*****************************************************************************
-
- Macro: Q931GetIEPtr
-
- Syntax: void * Q931GetIEPtr(ie InfoElement, L3UCHAR * Buf);
-
- Description: Compute a Ptr to the information element.
-
-*****************************************************************************/
-#define Q931GetIEPtr(ie,buf) ((void *)&buf[Q931GetIEOffset(ie)])
-
-/*****************************************************************************
-
- Macro: SetIE
-
- Syntax: void SetIE(ie InfoElement, L3INT Offset);
-
- Description: Set an information element.
-
-*****************************************************************************/
-#define Q931SetIE(x,o) { x = (ie)(o) | 0x8000; }
-
-/*****************************************************************************
-
- Macro: IsQ931Ext
-
- Syntax BOOL IsQ931Ext(L3UCHAR c)
-
- Description: Return true Check if the msb (bit 8) is 0. This indicate
- that the octet is extended.
-
-*****************************************************************************/
-#define IsQ931Ext(x) ((x & 0x80) == 0)
-
-/*****************************************************************************
-
- Macro: ieGetOctet
-
- Syntax: unsigned L3UCHAR ieGetOctet(L3INT e)
-
- Description: Macro to fetch one byte from an integer. Mostly used to
- avoid warnings.
-
-*****************************************************************************/
-#define ieGetOctet(x) ((L3UCHAR)(x))
-
-/*****************************************************************************
-
- Macro: NoWarning
-
- Syntax: void NoWarning(x)
-
- Description: Macro to suppress unreferenced formal parameter warnings
-
- Used during creation of the stack since the stack is
- developed for Warning Level 4 and this creates a lot of
- warning for the initial empty functions.
-
-*****************************************************************************/
-#define NoWarning(x) (x = x)
-
-/*****************************************************************************
-
- External references. See Q931.c for details.
-
-*****************************************************************************/
-
-#include "Q931ie.h"
-
-#include "Q932.h"
-
-/*****************************************************************************
-
- Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c
-
-*****************************************************************************/
-L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_Service(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931Pmes_ServiceAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-
-
-L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
-L3INT Q931Umes_Service(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
-L3INT Q931Umes_ServiceAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
-
-
-/*****************************************************************************
-
- Q.931 Process Function Prototyping. Implemented in Q931StateTE.c
-
-*****************************************************************************/
-L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-
-L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-
-L3INT Q931ProcUnknownMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
-
-/*****************************************************************************
-
- Interface Function Prototypes. Implemented in Q931.c
-
-*****************************************************************************/
-void Q931TimerTick(Q931_TrunkInfo_t *pTrunk);
-L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * Mes, L3INT Size);
-L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT Size);
-L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
-L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
-void Q931SetError(Q931_TrunkInfo_t *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2);
-
-void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar);
-
-void Q931CreateTE(L3UCHAR i);
-void Q931CreateNT(L3UCHAR i);
-void Q931SetMesCreateCB(L3INT (*callback)(void));
-void Q931SetDialectCreateCB(L3INT (*callback)(L3INT));
-void Q931SetHeaderSpace(L3INT space);
-
-void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, q931proc_func_t *Q931ProcFunc, q931umes_func_t *Q931UmesFunc, q931pmes_func_t *Q931PmesFunc);
-void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, q931pie_func_t *Q931PieProc, q931uie_func_t *Q931UieProc);
-void Q931SetTimeoutProc(L3UCHAR dialect, L3UCHAR timer, q931timeout_func_t *Q931TimeoutProc);
-void Q931SetTimerDefault(L3UCHAR dialect, L3UCHAR timer, q931timer_t timeout);
-
-void Q931Initialize(void);
-void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect));
-L3INT Q931InitMesSetup(Q931mes_Generic *p);
-L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes);
-L3INT Q931InitMesGeneric(Q931mes_Generic *pMes);
-
-L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex);
-L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV);
-L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex);
-L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex);
-L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV);
-L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimer);
-L3INT Q931StopTimer(Q931_TrunkInfo_t *pTrunk, L3INT callindex, L3USHORT iTimer);
-L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState);
-L3ULONG Q931GetTime(void);
-void Q931SetGetTimeCB(L3ULONG (*callback)(void));
-void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir);
-L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir);
-
-/*****************************************************************************
-
- Q.931 Low Level API Function Prototyping. Implemented in Q931API.c
-
-*****************************************************************************/
-ie Q931AppendIE(L3UCHAR *pm, L3UCHAR *pi);
-L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk);
-
-L3INT Q931InitIEBearerCap(Q931ie_BearerCap *p);
-L3INT Q931InitIEChanID(Q931ie_ChanID *p);
-L3INT Q931InitIEProgInd(Q931ie_ProgInd *p);
-L3INT Q931InitIENetFac(Q931ie_NetFac * pIE);
-L3INT Q931InitIEDisplay(Q931ie_Display * pIE);
-L3INT Q931InitIEDateTime(Q931ie_DateTime * pIE);
-L3INT Q931InitIEKeypadFac(Q931ie_KeypadFac * pIE);
-L3INT Q931InitIESignal(Q931ie_Signal * pIE);
-L3INT Q931InitIECallingNum(Q931ie_CallingNum * pIE);
-L3INT Q931InitIECallingSub(Q931ie_CallingSub * pIE);
-L3INT Q931InitIECalledNum(Q931ie_CalledNum * pIE);
-L3INT Q931InitIECalledSub(Q931ie_CalledSub * pIE);
-L3INT Q931InitIETransNetSel(Q931ie_TransNetSel * pIE);
-L3INT Q931InitIELLComp(Q931ie_LLComp * pIE);
-L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE);
-
-L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause);
-L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
-L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
-L3INT Q931AckConnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
-L3INT Q931AckSetup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
-L3INT Q931AckService(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
-
-L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk,
- Q931Dialect_t Dialect,
- Q931NetUser_t NetUser,
- Q931_TrunkType_t TrunkType,
- Q931Tx34CB_t Q931Tx34CBProc,
- Q931Tx32CB_t Q931Tx32CBProc,
- Q931ErrorCB_t Q931ErrorCBProc,
- void *PrivateData32,
- void *PrivateData34);
-
-L3INT Q931GetMesSize(Q931mes_Generic *pMes);
-L3INT Q931InitMesResume(Q931mes_Generic * pMes);
-
-L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, ...);
-void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv);
-void Q931SetLogLevel(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level);
-
-void Q931SetL4HeaderSpace(L3INT space);
-void Q931SetL2HeaderSpace(L3INT space);
-L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c);
-L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
-L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff);
-L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q931PieDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
-L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n);
-L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c);
-L3INT Q931TimeoutDummy(Q931_TrunkInfo_t *pTrunk, L3INT callIndex);
-
-L3INT Q931MesgHeader(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *mes, L3UCHAR *OBuf, L3INT Size, L3INT *IOff);
-
-#endif /* _Q931_NL */
diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h
deleted file mode 100644
index 65dba4e261..0000000000
--- a/libs/openzap/src/isdn/include/Q931ie.h
+++ /dev/null
@@ -1,1205 +0,0 @@
-/******************************************************************************
-
- FileName: Q931ie.h
-
- Contents: Header and definition for the ITU-T Q.931 ie
- structures and functions
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-******************************************************************************/
-
-#ifndef _Q931IE_NL
-#define _Q931IE_NL
-
-/* Codesets */
-
-typedef enum {
-
- Q931_CODESET_0 = ( 0 ),
- Q931_CODESET_1 = ( 1 << 8 ),
- Q931_CODESET_2 = ( 2 << 8 ),
- Q931_CODESET_3 = ( 3 << 8 ),
- Q931_CODESET_4 = ( 4 << 8 ),
- Q931_CODESET_5 = ( 5 << 8 ),
- Q931_CODESET_6 = ( 6 << 8 ),
- Q931_CODESET_7 = ( 7 << 8 )
-
-} q931_codeset_t;
-
-/* Single octet information elements */
-#define Q931ie_SHIFT 0x90 /* 1001 ---- */
-#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */
-#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0001 */
-#define Q931ie_CONGESTION_LEVEL 0xb0 /* 1011 ---- */
-#define Q931ie_REPEAT_INDICATOR 0xd0 /* 1101 ---- */
-
-/* Variable Length Information Elements */
-#define Q931ie_SEGMENTED_MESSAGE 0x00 /* 0000 0000 */
-#define Q931ie_CHANGE_STATUS 0x01 /* 0000 0001 */
-#define Q931ie_BEARER_CAPABILITY 0x04 /* 0000 0100 */
-#define Q931ie_CAUSE 0x08 /* 0000 1000 */
-#define Q931ie_CALL_IDENTITY 0x10 /* 0001 0000 */
-#define Q931ie_CALL_STATE 0x14 /* 0001 0100 */
-#define Q931ie_CHANNEL_IDENTIFICATION 0x18 /* 0001 1000 */
-#define Q931ie_PROGRESS_INDICATOR 0x1e /* 0001 1110 */
-#define Q931ie_NETWORK_SPECIFIC_FACILITIES 0x20 /* 0010 0000 */
-#define Q931ie_NOTIFICATION_INDICATOR 0x27 /* 0010 0111 */
-#define Q931ie_DISPLAY 0x28 /* 0010 1000 */
-#define Q931ie_DATETIME 0x29 /* 0010 1001 */
-#define Q931ie_KEYPAD_FACILITY 0x2c /* 0010 1100 */
-#define Q931ie_SIGNAL 0x34 /* 0011 0100 */
-#define Q931ie_SWITCHOOK 0x36 /* 0011 0110 */
-#define Q931ie_FEATURE_ACTIVATION 0x38 /* 0011 1000 */
-#define Q931ie_FEATURE_INDICATION 0x39 /* 0011 1001 */
-#define Q931ie_INFORMATION_RATE 0x40 /* 0100 0000 */
-#define Q931ie_END_TO_END_TRANSIT_DELAY 0x42 /* 0100 0010 */
-#define Q931ie_TRANSIT_DELAY_SELECTION_AND_IND 0x43 /* 0100 0011 */
-#define Q931ie_PACKED_LAYER_BIMARY_PARAMETERS 0x44 /* 0100 0100 */
-#define Q931ie_PACKED_LAYER_WINDOW_SIZE 0x45 /* 0100 0101 */
-#define Q931ie_PACKED_SIZE 0x46 /* 0100 0110 */
-#define Q931ie_CALLING_PARTY_NUMBER 0x6c /* 0110 1100 */
-#define Q931ie_CALLING_PARTY_SUBADDRESS 0x6d /* 0110 1101 */
-#define Q931ie_CALLED_PARTY_NUMBER 0x70 /* 0111 0000 */
-#define Q931ie_CALLED_PARTY_SUBADDRESS 0x71 /* 0111 0001 */
-#define Q931ie_REDIRECTING_NUMBER 0x74 /* 0111 0100 */
-#define Q931ie_TRANSIT_NETWORK_SELECTION 0x78 /* 0111 1000 */
-#define Q931ie_RESTART_INDICATOR 0x79 /* 0111 1001 */
-#define Q931ie_LOW_LAYER_COMPATIBILITY 0x7c /* 0111 1100 */
-#define Q931ie_HIGH_LAYER_COMPATIBILITY 0x7d /* 0111 1101 */
-#define Q931ie_USER_USER 0x7e /* 0111 1110 */
-#define Q931ie_ESCAPE_FOR_EX 0x7f /* 0111 1111 */
-
-/* Variable Length Codeset 6 Information Elements */
-#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */
-
-/* Variable Length Information Element to shut up BRI testing */
-#define Q931ie_CONNECTED_NUMBER 0x4c /* 0100 1101 */
-#define Q931ie_FACILITY 0x1c /* 0001 1101 */
-
-
-/*****************************************************************************
-
- Struct: Q931ie_BearerCap
-
- Description: Bearer Capability Information Element.
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00000100 for Bearer Capability */
- L3UCHAR Size; /* Length of Information Element */
-
- L3UCHAR CodStand; /* Coding Standard. */
- /* 00 - ITU-T */
- /* 01 - ISO/IEC */
- /* 10 - National standard */
- /* 11 - Network side spesific */
-
- L3UCHAR ITC; /* Information Transfer Capability */
- /* 00000 - Speech */
- /* 01000 - Unrestricted digital info */
- /* 01001 - Restricted digital info */
- /* 10000 - 3.1 kHz audio */
- /* 10001 - Unrestricted with tones */
- /* 11000 - Video */
-
- L3UCHAR TransMode; /* Transfer Mode. */
- /* 00 - Circuit mode */
- /* 10 - Packet mode */
-
- L3UCHAR ITR; /* Information Transfer Rate. */
- /* 00000 - Packed mode */
- /* 10000 - 64 kbit/s */
- /* 10001 - 2 x 64 kbit/s */
- /* 10011 - 384 kbit/s */
- /* 10101 - 1536 kbit/s */
- /* 10111 - 1920 kbit/s */
- /* 11000 - Multirat (64 kbit/s base) */
-
- L3UCHAR RateMul; /* Rate Multiplier */
-
- L3UCHAR Layer1Ident; /* Layer 1 Ident. */
-
- L3UCHAR UIL1Prot; /* User Information Layer 1 Protocol */
- /* 00001 : ITU-T V.110, I.460 and X.30 */
- /* 00010 : G.711 my-law */
- /* 00011 : G.711 A-law */
- /* 00100 : G.721 */
- /* 00101 : H.221 and H.242 */
- /* 00110 : H.223 and H.245 */
- /* 00111 : Non ITU-T Standard */
- /* 01000 : ITU-T V.120 */
- /* 01001 : ITU-T X.31 HDLC flag stuff. */
-
- L3UCHAR SyncAsync; /* Sync/Async */
- /* 0 : Syncronous data */
- /* 1 : Asyncronous data */
-
- L3UCHAR Negot; /* Negotiation */
- /* 0 : In-band negotiation not possib. */
- /* 1 : In-band negotiation possible */
-
- L3UCHAR UserRate; /* User rate */
- /* 00000 : I.460, V.110, X,30 */
- /* 00001 : 0.6 kbit/s x.1 */
- /* 00010 : 1.2 kbit/s */
- /* 00011 : 2.4 kbit/s */
- /* 00100 : 3.6 kbit/s */
- /* 00101 : 4.8 kbit/s */
- /* 00110 : 7.2 kbit/s */
- /* 00111 : 8 kbit/s I.460 */
- /* 01000 : 9.6 kbit/s */
- /* 01001 : 14.4 kbit/s */
- /* 01010 : 16 kbit/s */
- /* 01011 : 19.2 kbit/s */
- /* 01100 : 32 kbit/s */
- /* 01101 : 38.4 kbit/s */
- /* 01110 : 48 kbit/s */
- /* 01111 : 56 kbit/s */
- /* 10000 : 57.6 kbit/s */
- /* 10010 : 28.8 kbit/s */
- /* 10100 : 24 kbit/s */
- /* 10101 : 0.1345 kbit/s */
- /* 10110 : 0.100 kbit/s */
- /* 10111 : 0.075/1.2 kbit/s */
- /* 11000 : 1.2/0.075/kbit/s */
- /* 11001 : 0.050 kbit/s */
- /* 11010 : 0.075 kbit/s */
- /* 11011 : 0.110 kbit/s */
- /* 11100 : 0.150 kbit/s */
- /* 11101 : 0.200 kbit/s */
- /* 11110 : 0.300 kbit/s */
- /* 11111 : 12 kbit/s */
-
- L3UCHAR InterRate; /* Intermediate Rate */
- /* 00 : Not used */
- /* 01 : 8 kbit/s */
- /* 10 : 16 kbit/s */
- /* 11 : 32 kbit/s */
-
- L3UCHAR NIConTx; /* Network Indepentend Clock on transmit*/
- /* 0 : Not required to send data clc */
- /* 1 : Send data w/NIC clc */
-
- L3UCHAR NIConRx; /* NIC on Rx */
- /* 0 : Cannot accept indep. clc */
- /* 1 : data with indep. clc accepted */
-
- L3UCHAR FlowCtlTx; /* Flow control on Tx */
- /* 0 : Send Flow ctrl not required */
- /* 1 : Send flow ctrl required */
-
- L3UCHAR FlowCtlRx; /* Flow control on Rx */
- /* 0 : cannot use receive flow ctrl */
- /* 1 : Receive flow ctrl accepted */
- L3UCHAR HDR; /* HDR/No HDR */
- L3UCHAR MultiFrame; /* Multi frame support */
- /* 0 : multiframe not supported */
- /* 1 : multiframe supported */
-
- L3UCHAR Mode; /* Mode of operation */
- /* 0 : bit transparent mode of operat. */
- /* 1 : protocol sesitive mode of op. */
-
- L3UCHAR LLInegot; /* Logical link id negotiation (oct. 5b)*/
- /* 0 : default LLI=256 only */
- /* 1 : Full protocol negotiation */
-
- L3UCHAR Assignor; /* Assignor/assignee */
- /* 0 : Default Asignee */
- /* 1 : Assignor only */
-
- L3UCHAR InBandNeg; /* In-band/out-band negot. */
- /* 0 : negot done w/ USER INFO mes */
- /* 1 : negot done in-band w/link zero */
-
- L3UCHAR NumStopBits; /* Number of stop bits */
- /* 00 : Not used */
- /* 01 : 1 bit */
- /* 10 : 1.5 bits */
- /* 11 : 2 bits */
-
- L3UCHAR NumDataBits; /* Number of data bits. */
- /* 00 : not used */
- /* 01 : 5 bits */
- /* 10 : 7 bits */
- /* 11 : 8 bits */
-
- L3UCHAR Parity; /* Parity Information */
- /* 000 : Odd */
- /* 010 : Even */
- /* 011 : None */
- /* 100 : Forced to 0 */
- /* 101 : Forced to 1 */
-
- L3UCHAR DuplexMode; /* Mode duplex */
- /* 0 : Half duplex */
- /* 1 : Full duplex */
-
- L3UCHAR ModemType; /* Modem type, see Q.931 p 64 */
-
- L3UCHAR Layer2Ident; /* Layer 2 Ident */
-
- L3UCHAR UIL2Prot; /* User Information Layer 2 Protocol */
- /* 00010 : Q.921/I.441 */
- /* 00110 : X.25 */
- /* 01100 : LAN logical link */
-
- L3UCHAR Layer3Ident; /* Layer 3 ident. */
-
- L3UCHAR UIL3Prot; /* User Information Layer 3 Protocol */
- /* 00010 : Q.931 */
- /* 00110 : X.25 */
- /* 01011 : ISO/IEC TR 9577 */
-
- L3UCHAR AL3Info1; /* additional layer 3 info 1 */
-
- L3UCHAR AL3Info2; /* additional layer 3 info 2 */
-
-} Q931ie_BearerCap;
-
-/*****************************************************************************
-
- Struct: Q931ie_CallID
-
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00010000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CallId[1]; /* Call identity */
-
-} Q931ie_CallID;
-
-/*****************************************************************************
-
- Struct: Q931ie_CallState
-
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00010100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CodStand; /* Coding Standard */
- L3UCHAR CallState; /* Call State Value */
-
-} Q931ie_CallState;
-
-/*****************************************************************************
-
- Struct: Q931ie_Cause
-
- Description: Cause IE as described in Q.850
-
-*****************************************************************************/
-typedef struct {
-
- L3UCHAR IEId; /* 00010100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CodStand; /* Coding Standard */
- L3UCHAR Location; /* Location */
- L3UCHAR Recom; /* Recommendation */
- L3UCHAR Value; /* Cause Value */
- L3UCHAR Diag[1]; /* Optional Diagnostics Field */
-
-} Q931ie_Cause;
-
-/*****************************************************************************
-
- Struct: Q931ie_CalledNum
-
-*****************************************************************************/
-typedef struct {
-
- L3UCHAR IEId; /* 01110000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR TypNum; /* Type of Number */
- L3UCHAR NumPlanID; /* Numbering plan identification */
- L3UCHAR Digit[1]; /* Digit (IA5) */
-
-} Q931ie_CalledNum;
-
-/*****************************************************************************
-
- Struct: Q931ie_CalledSub
-
- Description: Called party subaddress
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 01110001 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR TypNum; /* Type of subaddress */
- L3UCHAR OddEvenInd; /* Odd/Even indicator */
- L3UCHAR Digit[1]; /* digits */
-
-} Q931ie_CalledSub;
-
-/*****************************************************************************
-
- Struct: Q931ie_CallingNum
-
- Description: Calling party number
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 01101100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR TypNum; /* Type of number */
- L3UCHAR NumPlanID; /* Numbering plan identification */
- L3UCHAR PresInd; /* Presentation indicator */
- L3UCHAR ScreenInd; /* Screening indicator */
- L3UCHAR Digit[1]; /* Number digits (IA5) */
-
-} Q931ie_CallingNum;
-
-/*****************************************************************************
-
- Struct: Q931ie_CallingSub
-
- Description: Calling party subaddress
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 01101101 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR TypNum; /* Type of subaddress */
- L3UCHAR OddEvenInd; /* Odd/Even indicator */
- L3UCHAR Digit[1]; /* digits */
-
-} Q931ie_CallingSub;
-
-/*****************************************************************************
-
- Struct: Q931ie_ChanID
-
- Description: Channel identification
-
- Channel Identificationis one of the IE elements that differ
- between BRI and PRI. IntType = 1 = BRI and ChanSlot is used
- for channel number, while InfoChanSel is used for BRI.
-
- ChanID is one of the most important IE as it is passed
- either though SETUP or CALL PROCEEDING to select the channel
- to be used.
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00011000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR IntIDPresent; /* Int. id. present */
- L3UCHAR IntType; /* Interface Type */
- /* 0 : Basic Interface (BRI) */
- /* 1 : Other interfaces, PRI etc. */
-
- L3UCHAR PrefExcl; /* Pref./Excl. */
- /* 0 : Indicated channel is preffered */
- /* 1 : Exclusive, no other accepted */
-
- L3UCHAR DChanInd; /* D-channel ind. */
- /* 0 : chan is NOT D chan. */
- /* 1 : chan is D chan */
-
- L3UCHAR InfoChanSel; /* Info. channel selection */
- /* 00 : No channel */
- /* 01 : B1 channel */
- /* 10 : B2 channel */
- /* 11 : Any channel */
-
- L3UCHAR InterfaceID; /* Interface identifier */
-
- L3UCHAR CodStand; /* Code standard */
- /* 00 : ITU-T standardization coding */
- /* 01 : ISO/IEC Standard */
- /* 10 : National Standard */
- /* 11 : Standard def. by network. */
-
- L3UCHAR NumMap; /* Number/Map */
- /* 0 : chan is in following octet */
- /* 1 : chan is indicated by slot map */
-
- L3UCHAR ChanMapType; /* Channel type/Map element type */
- /* 0011 : B Channel units */
- /* 0110 : H0 channel units */
- /* 1000 : H11 channel units */
- /* 1001 : H12 channel units */
-
- L3UCHAR ChanSlot; /* Channel number */
-
-} Q931ie_ChanID;
-
-/*****************************************************************************
-
- Struct: Q931ie_DateTime
-
- Description: Date/time
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00101001 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Year; /* Year */
- L3UCHAR Month; /* Month */
- L3UCHAR Day; /* Day */
- L3UCHAR Hour; /* Hour */
- L3UCHAR Minute; /* Minute */
- L3UCHAR Second; /* Second */
- L3UCHAR Format; /* Indicate presense of Hour, Min & sec */
- /* 0 : Only Date */
- /* 1 : Hour present */
- /* 2 : Hour and Minute present */
- /* 3 : Hour, Minute and Second present */
-} Q931ie_DateTime;
-
-/*****************************************************************************
-
- Struct: Q931ie_Display
-
- Description: Display
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00101000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Display[1]; /* Display information (IA5) */
-
-} Q931ie_Display;
-
-/*****************************************************************************
-
- Struct: Q931ie_HLComp
-
- Description: High layer compatibility
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 01111101 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CodStand; /* Coding standard */
- L3UCHAR Interpret; /* Interpretation */
- L3UCHAR PresMeth; /* Presentation methor of prot. profile */
- L3UCHAR HLCharID; /* High layer characteristics id. */
- L3UCHAR EHLCharID; /* Extended high layer character. id. */
- L3UCHAR EVideoTlfCharID; /* Ext. videotelephony char. id. */
-
-} Q931ie_HLComp;
-
-/*****************************************************************************
-
- Struct: Q931ie_KeypadFac
-
- Description: Keypad facility
-
-*****************************************************************************/
-
-typedef struct {
- L3UCHAR IEId; /* 00101100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR KeypadFac[1]; /* dynamic buffer */
-
-} Q931ie_KeypadFac;
-
-/*****************************************************************************
-
- Struct: Q931ie_LLComp
-
- Description: Low layer compatibility
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 01111100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CodStand; /* Coding standard */
- /* 00 - ITU-T */
- /* 01 - ISO/IEC */
- /* 10 - National standard */
- /* 11 - Network side spesific */
-
- L3UCHAR ITransCap; /* Information transfer capability */
- /* 00000 - Speech */
- /* 01000 - Unrestricted digital info */
- /* 01001 - Restricted digital info */
- /* 10000 - 3.1 kHz audio */
- /* 10001 - Unrestricted with tones */
- /* 11000 - Video */
-
- L3UCHAR NegotInd; /* Negot indic. */
- /* 0 : Out-band neg. not possib. */
- /* 1 : Out-band neg. possible */
-
- L3UCHAR TransMode; /* Transfer Mode */
- /* 00 : Circuit Mode */
- /* 10 : Packed Mode */
-
- L3UCHAR InfoRate; /* Information transfer rate */
- /* 00000 - Packed mode */
- /* 10000 - 64 kbit/s */
- /* 10001 - 2 x 64 kbit/s */
- /* 10011 - 384 kbit/s */
- /* 10101 - 1536 kbit/s */
- /* 10111 - 1920 kbit/s */
- /* 11000 - Multirat (64 kbit/s base) */
-
- L3UCHAR RateMul; /* Rate multiplier */
- L3UCHAR Layer1Ident; /* Layer 1 ident. */
- L3UCHAR UIL1Prot; /* User information layer 1 protocol */
- /* 00001 : ITU-T V.110, I.460 and X.30 */
- /* 00010 : G.711 my-law */
- /* 00011 : G.711 A-law */
- /* 00100 : G.721 */
- /* 00101 : H.221 and H.242 */
- /* 00110 : H.223 and H.245 */
- /* 00111 : Non ITU-T Standard */
- /* 01000 : ITU-T V.120 */
- /* 01001 : ITU-T X.31 HDLC flag stuff. */
-
- L3UCHAR SyncAsync; /* Synch/asynch */
- /* 0 : Syncronous data */
- /* 1 : Asyncronous data */
-
- L3UCHAR Negot; /* Negot */
- /* 0 : In-band negotiation not possib. */
- /* 1 : In-band negotiation possible */
-
- L3UCHAR UserRate; /* User rate */
- /* 00000 : I.460, V.110, X,30 */
- /* 00001 : 0.6 kbit/s x.1 */
- /* 00010 : 1.2 kbit/s */
- /* 00011 : 2.4 kbit/s */
- /* 00100 : 3.6 kbit/s */
- /* 00101 : 4.8 kbit/s */
- /* 00110 : 7.2 kbit/s */
- /* 00111 : 8 kbit/s I.460 */
- /* 01000 : 9.6 kbit/s */
- /* 01001 : 14.4 kbit/s */
- /* 01010 : 16 kbit/s */
- /* 01011 : 19.2 kbit/s */
- /* 01100 : 32 kbit/s */
- /* 01101 : 38.4 kbit/s */
- /* 01110 : 48 kbit/s */
- /* 01111 : 56 kbit/s */
- /* 10000 : 57.6 kbit/s */
- /* 10010 : 28.8 kbit/s */
- /* 10100 : 24 kbit/s */
- /* 10101 : 0.1345 kbit/s */
- /* 10110 : 0.100 kbit/s */
- /* 10111 : 0.075/1.2 kbit/s */
- /* 11000 : 1.2/0.075/kbit/s */
- /* 11001 : 0.050 kbit/s */
- /* 11010 : 0.075 kbit/s */
- /* 11011 : 0.110 kbit/s */
- /* 11100 : 0.150 kbit/s */
- /* 11101 : 0.200 kbit/s */
- /* 11110 : 0.300 kbit/s */
- /* 11111 : 12 kbit/s */
-
- L3UCHAR InterRate; /* Intermediate rate */
- /* 00 : Not used */
- /* 01 : 8 kbit/s */
- /* 10 : 16 kbit/s */
- /* 11 : 32 kbit/s */
-
- L3UCHAR NIConTx; /* Network Indepentend Clock on transmit*/
- /* 0 : Not required to send data clc */
- /* 1 : Send data w/NIC clc */
-
- L3UCHAR NIConRx; /* NIC on Rx */
- /* 0 : Cannot accept indep. clc */
- /* 1 : data with indep. clc accepted */
-
- L3UCHAR FlowCtlTx; /* Flow control on Tx */
- /* 0 : Send Flow ctrl not required */
- /* 1 : Send flow ctrl required */
-
- L3UCHAR FlowCtlRx; /* Flow control on Rx */
- /* 0 : cannot use receive flow ctrl */
- /* 1 : Receive flow ctrl accepted */
- L3UCHAR HDR; /* HDR/No HDR */
- L3UCHAR MultiFrame; /* Multi frame support */
- /* 0 : multiframe not supported */
- /* 1 : multiframe supported */
-
- L3UCHAR ModeL1; /* Mode L1 */
- /* 0 : bit transparent mode of operat. */
- /* 1 : protocol sesitive mode of op. */
-
- L3UCHAR NegotLLI; /* Negot. LLI */
- /* 0 : default LLI=256 only */
- /* 1 : Full protocol negotiation */
-
- L3UCHAR Assignor; /* Assignor/Assignor ee */
- /* 0 : Default Asignee */
- /* 1 : Assignor only */
-
- L3UCHAR InBandNeg; /* In-band negot. */
- /* 0 : negot done w/ USER INFO mes */
- /* 1 : negot done in-band w/link zero */
-
- L3UCHAR NumStopBits; /* Number of stop bits */
- /* 00 : Not used */
- /* 01 : 1 bit */
- /* 10 : 1.5 bits */
- /* 11 : 2 bits */
-
- L3UCHAR NumDataBits; /* Number of data bits. */
- /* 00 : not used */
- /* 01 : 5 bits */
- /* 10 : 7 bits */
- /* 11 : 8 bits */
-
- L3UCHAR Parity; /* Parity Information */
- /* 000 : Odd */
- /* 010 : Even */
- /* 011 : None */
- /* 100 : Forced to 0 */
- /* 101 : Forced to 1 */
-
- L3UCHAR DuplexMode; /* Mode duplex */
- /* 0 : Half duplex */
- /* 1 : Full duplex */
-
- L3UCHAR ModemType; /* Modem type, see Q.931 p 89 */
-
- L3UCHAR Layer2Ident; /* Layer 2 ident. */
-
- L3UCHAR UIL2Prot; /* User information layer 2 protocol */
- /* 00001 : Basic mode ISO 1745 */
- /* 00010 : Q.921/I.441 */
- /* 00110 : X.25 single link */
- /* 00111 : X.25 multilink */
- /* 01000 : Extended LAPB T.71 */
- /* 01001 : HDLC ARM */
- /* 01010 : HDLC NRM */
- /* 01011 : HDLC ABM */
- /* 01100 : LAN logical link */
- /* 01101 : X.75 SLP */
- /* 01110 : Q.922 */
- /* 01111 : Q.922 core aspect */
- /* 10000 : User specified */
- /* 10001 : ISO/IEC 7776 DTE-DCE */
-
- L3UCHAR ModeL2; /* Mode */
- /* 01 : Normal Mode of operation */
- /* 10 : Extended mode of operation */
-
- L3UCHAR Q933use; /* Q.9333 use */
-
- L3UCHAR UsrSpcL2Prot; /* User specified layer 2 protocol info */
-
- L3UCHAR WindowSize; /* Window size (k) */
-
- L3UCHAR Layer3Ident; /* Layer 3 ident */
-
- L3UCHAR UIL3Prot; /* User Information Layer 3 protocol */
- /* 00010 : Q.931 */
- /* 00110 : X.25 */
- /* 00111 : 8208 */
- /* 01000 : X.233 ... */
- /* 01001 : 6473 */
- /* 01010 : T.70 */
- /* 01011 : ISO/IEC TR 9577 */
- /* 10000 : User specified */
- L3UCHAR OptL3Info; /* Optional Leyer 3 info */
-
- L3UCHAR ModeL3; /* Mode of operation */
- /* 01 : Normal packed seq. numbering */
- /* 10 : Extended packed seq. numbering */
-
- L3UCHAR DefPackSize; /* Default packet size */
-
- L3UCHAR PackWinSize; /* Packet window size */
-
- L3UCHAR AddL3Info; /* Additional Layer 3 protocol info */
-
-} Q931ie_LLComp;
-
-/*****************************************************************************
-
- Struct: Q931ie_NetFac;
-
- Description: Network-specific facilities
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00100000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR LenNetID; /* Length of network facilities id. */
- L3UCHAR TypeNetID; /* Type of network identification */
- L3UCHAR NetIDPlan; /* Network identification plan. */
- L3UCHAR NetFac; /* Network specific facility spec. */
- L3UCHAR NetID[1]; /* Network id. (IA5) */
-
-} Q931ie_NetFac;
-
-/*****************************************************************************
-
- Struct: Q931ie_NotifInd;
-
- Description: Notification Indicator
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00100000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Notification; /* Notification descriptor */
-
-} Q931ie_NotifInd;
-
-/*****************************************************************************
-
- Struct: Q931ie_ProgInd
-
- Description: Progress indicator
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00011110 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CodStand; /* Coding standard */
- L3UCHAR Location; /* Location */
- L3UCHAR ProgDesc; /* Progress description */
-
-} Q931ie_ProgInd;
-
-/*****************************************************************************
-
- Struct; Q931ie_Segment
-
- Description: Segmented message
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00000000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR FSI; /* First segment indicator */
- L3UCHAR NumSegRem; /* Number of segments remaining */
- L3UCHAR SegType; /* Segment message type */
-
-} Q931ie_Segment;
-
-
-typedef struct {
-
- L3UCHAR IEId; /* 00000000 */
- L3UCHAR Size; /* Length of Information Element */
-
-} Q931ie_SendComplete;
-
-/*****************************************************************************
-
- Struct: Q931ie_Signal
-
- Description: Signal
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00000000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Signal; /* Signal value */
- /* 00000000 Dial tone on */
- /* 00000001 Ring back tone on */
- /* 00000010 Intercept tone on */
- /* 00000011 Network congestion on */
- /* 00000100 Busy tone on */
- /* 00000101 Confirm tone on */
- /* 00000110 Answer tone on */
- /* 00000111 Call waiting tone */
- /* 00001000 Off-hook warning tone */
- /* 00001001 Pre-emption tone on */
- /* 00111111 Tones off */
- /* 01000000 Alerting on - pattern 0 */
- /* 01000001 Alerting on - pattern 1 */
- /* 01000010 Alerting on - pattern 2 */
- /* 01000011 Alerting on - pattern 3 */
- /* 01000100 Alerting on - pattern 4 */
- /* 01000101 Alerting on - pattern 5 */
- /* 01000110 Alerting on - pattern 6 */
- /* 01000111 Alerting on - pattern 7 */
- /* 01001111 Alerting off */
-} Q931ie_Signal;
-
-/*****************************************************************************
-
- Struct: Q931ie_TransDelSelInd
-
- description: Transit delay selection and indication
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 00000000 */
- L3UCHAR Size; /* Length of Information Element */
- L3ULONG TxDSIValue; /* Trans. delay sel. & ind. value */
-
-} Q931ie_TransDelSelInd;
-#endif
-
-/*****************************************************************************
-
- Struct: Q931ie_TransNetSel
-
- Description: Transit network selection
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 01111000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Type; /* Type of network identifier */
- L3UCHAR NetIDPlan; /* Network idetification plan */
- L3UCHAR NetID[1]; /* Network identification(IA5) */
-
-} Q931ie_TransNetSel;
-
-/*****************************************************************************
-
- Struct: Q931ie_UserUser
-
- Description: User-user
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 01111110 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR ProtDisc; /* Protocol discriminator */
- L3UCHAR User[1]; /* User information */
-
-} Q931ie_UserUser;
-
-/*****************************************************************************
-
- Struct: Q931ie_ClosedUserGrp
-
- Description: Closed user group
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 01000111 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CUGInd; /* CUG indication */
- L3UCHAR CUG[1]; /* CUG index code (IA5) */
-
-} Q931ie_ClosedUserGrp;
-#endif
-
-/*****************************************************************************
-
- Struct: Q931ie_CongLevel
-
- Description: Congestion Level
-
-*****************************************************************************/
-typedef struct {
-
- L3UCHAR IEId; /* 01000111 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR CongLevel; /* Conguestion Level */
-
-} Q931ie_CongLevel;
-
-/*****************************************************************************
-
- Struct: Q931ie_EndEndTxDelay
-
- Description: End to end transit delay
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 01000010 */
- L3UCHAR Size; /* Length of Information Element */
- L3ULONG CumTxDelay; /* Cumulative transit delay value */
- L3ULONG ReqTxDelay; /* Requested end to end transit delay */
- L3ULONG MaxTxDelay; /* Maximum transit delay */
-
-} Q931ie_EndEndTxDelay;
-#endif
-
-/*****************************************************************************
-
- Struct: Q931ie_InfoRate
-
- Description: Information Rate
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 01100000 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR InInfoRate; /* Incoming information rate */
- L3UCHAR OutInfoRate; /* Outgoing information rate */
- L3UCHAR MinInInfoRate; /* Minimum incoming information rate */
- L3UCHAR MinOutInfoRate; /* Minimum outgoing information rate */
-
-} Q931ie_InfoRate;
-#endif
-
-/*****************************************************************************
-
- Struct: Q931ie_PackParam
-
- Description: Packed layer binary parameters
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 01000100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR FastSel; /* Fast selected */
- L3UCHAR ExpData; /* Exp. data */
- L3UCHAR DelConf; /* Delivery conf */
- L3UCHAR Modulus; /* Modulus */
-
-} Q931ie_PackParam;
-#endif
-
-/*****************************************************************************
-
- Struct: Q931ie_PackWinSize
-
- Description: Packed window size
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 01000101 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR ForwardValue; /* Forward value */
- L3UCHAR BackwardValue; /* Backward value */
-
-} Q931ie_PackWinSize;
-#endif
-
-/*****************************************************************************
-
- Struct: Q931ie_PackSize
-
- Description: Packet size
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 01000110 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR ForwardValue; /* Forward value */
- L3UCHAR BackwardValue; /* Backward value */
-
-} Q931ie_PackSize;
-#endif
-
-/*****************************************************************************
-
- Struct: Q931ie_RedirNum
-
- Description: Redirecting number
-
-*****************************************************************************/
-#ifdef Q931_X25_SUPPORT
-typedef struct {
-
- L3UCHAR IEId; /* 01110100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR TypeNum; /* Type of number */
- L3UCHAR NumPlanID; /* Number plan identification */
- L3UCHAR PresInd; /* Presentation indicator */
- L3UCHAR ScreenInd; /* Screening indicator */
- L3UCHAR Reason; /* Reason for redirection */
- L3UCHAR Digit[1]; /* Number digits (IA5) */
-
-} Q931ie_RedirNum;
-#endif
-
-typedef struct {
-
- L3UCHAR IEId; /* 01110100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR RepeatInd; /* 0010 Prioritized list for selecting */
- /* one possible. */
-} Q931ie_RepeatInd;
-
-typedef struct {
-
- L3UCHAR IEId; /* 01110100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Spare; /* Spare */
- L3UCHAR Class; /* Class */
- /* 000 Indicate channels */
- /* 110 Single interface */
- /* 111 All interfaces */
-} Q931ie_RestartInd;
-
-typedef struct {
-
- L3UCHAR IEId; /* 01110100 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Preference; /* Preference 0 = reserved, 1 = channel */
- L3UCHAR Spare; /* Spare */
- L3UCHAR NewStatus; /* NewStatus */
- /* 000 In service */
- /* 001 Maintenance */
- /* 010 Out of service */
-} Q931ie_ChangeStatus;
-
-/*****************************************************************************
-
- Struct: Q931ie_GenericDigits
-
-
-*****************************************************************************/
-
-typedef struct {
-
- L3UCHAR IEId; /* 00110111 */
- L3UCHAR Size; /* Length of Information Element */
- L3UCHAR Type; /* Type of number */
- L3UCHAR Encoding; /* Encoding of number */
- L3UCHAR Digit[1]; /* Number digits (IA5) */
-
-} Q931ie_GenericDigits;
-
-
-/*****************************************************************************
-
- Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c
-
-*****************************************************************************/
-q931pie_func_t Q931Pie_ChangeStatus;
-q931pie_func_t Q931Pie_BearerCap;
-q931pie_func_t Q931Pie_ChanID;
-q931pie_func_t Q931Pie_ProgInd;
-q931pie_func_t Q931Pie_Display;
-q931pie_func_t Q931Pie_Signal;
-q931pie_func_t Q931Pie_HLComp;
-q931pie_func_t Q931Pie_Segment;
-q931pie_func_t Q931Pie_DateTime;
-q931pie_func_t Q931Pie_Cause;
-q931pie_func_t Q931Pie_SendComplete;
-q931pie_func_t Q931Pie_KeypadFac;
-q931pie_func_t Q931Pie_NotifInd;
-q931pie_func_t Q931Pie_CallID;
-q931pie_func_t Q931Pie_RepeatInd;
-q931pie_func_t Q931Pie_NetFac;
-q931pie_func_t Q931Pie_CallingNum;
-q931pie_func_t Q931Pie_CallingSub;
-q931pie_func_t Q931Pie_CalledNum;
-q931pie_func_t Q931Pie_CalledSub;
-q931pie_func_t Q931Pie_CalledNum;
-q931pie_func_t Q931Pie_TransNetSel;
-q931pie_func_t Q931Pie_LLComp;
-q931pie_func_t Q931Pie_CallState;
-q931pie_func_t Q931Pie_RestartInd;
-q931pie_func_t Q931Pie_UserUser;
-
-q931pie_func_t Q931Pie_GenericDigits;
-
-L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff);
-
-q931uie_func_t Q931Uie_ChangeStatus;
-q931uie_func_t Q931Uie_BearerCap;
-q931uie_func_t Q931Uie_ChanID;
-q931uie_func_t Q931Uie_ProgInd;
-q931uie_func_t Q931Uie_Display;
-q931uie_func_t Q931Uie_Signal;
-q931uie_func_t Q931Uie_HLComp;
-q931uie_func_t Q931Uie_Segment;
-q931uie_func_t Q931Uie_DateTime;
-q931uie_func_t Q931Uie_Cause;
-q931uie_func_t Q931Uie_SendComplete;
-q931uie_func_t Q931Uie_KeypadFac;
-q931uie_func_t Q931Uie_NotifInd;
-q931uie_func_t Q931Uie_CallID;
-q931uie_func_t Q931Uie_RepeatInd;
-q931uie_func_t Q931Uie_NetFac;
-q931uie_func_t Q931Uie_CallingNum;
-q931uie_func_t Q931Uie_CallingSub;
-q931uie_func_t Q931Uie_CalledNum;
-q931uie_func_t Q931Uie_CalledSub;
-q931uie_func_t Q931Uie_TransNetSel;
-q931uie_func_t Q931Uie_LLComp;
-q931uie_func_t Q931Uie_CallState;
-q931uie_func_t Q931Uie_RestartInd;
-q931uie_func_t Q931Uie_UserUser;
-
-q931uie_func_t Q931Uie_GenericDigits;
-
-
-L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off);
-L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff);
-L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
-L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff);
-L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
-
-L3INT Q931Uie_Generic(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff);
-L3INT Q931Pie_Generic(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
-
-#endif /* _Q931IE_NL */
diff --git a/libs/openzap/src/isdn/include/Q932.h b/libs/openzap/src/isdn/include/Q932.h
deleted file mode 100644
index 9b69a34a02..0000000000
--- a/libs/openzap/src/isdn/include/Q932.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*****************************************************************************
-
- FileName: Q932.h
-
- Contents: Header w/structs for Q932 Suplementary Services.
-
- NB: Do NOT include this header directly, include Q931.h
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-/*****************************************************************************
- Q.932 Additional Message codes
-*****************************************************************************/
-
-#define Q932mes_HOLD 0x24 /* 0010 0100 */
-#define Q932mes_HOLD_ACKNOWLEDGE 0x28 /* 0010 1000 */
-#define Q932mes_HOLD_REJECT 0x30 /* 0011 0000 */
-#define Q932mes_RETRIEVE 0x31 /* 0011 0001 */
-#define Q932mes_RETRIEVE_ACKNOWLEDGE 0x33 /* 0011 0011 */
-#define Q932mes_RETRIEVE_REJECT 0x37 /* 0011 0111 */
-#define Q932mes_FACILITY 0x62 /* 0110 0010 */
-#define Q932mes_REGISTER 0x64 /* 0110 0100 */
-
-/*****************************************************************************
- Q.932 Additional EI Codes
-*****************************************************************************/
-#define Q932ie_FACILITY 0x1c /* 0001 1100 */
-
-/*****************************************************************************
- Function Prototypes.
-*****************************************************************************/
-L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-
-L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom);
-
-L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-
-L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
-L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
-L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
-L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
-L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
-L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
-L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
-L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * OBuf, L3INT I, L3INT O);
diff --git a/libs/openzap/src/isdn/include/mfifo.h b/libs/openzap/src/isdn/include/mfifo.h
deleted file mode 100644
index 4c1d850d81..0000000000
--- a/libs/openzap/src/isdn/include/mfifo.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*****************************************************************************
-
- Filename: mfifo.h
-
- Contents: header for MFIFO
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-#ifndef _MFIFO
-#define _MFIFO
-
-/*****************************************************************************
-
- Struct: MINDEX
-
- Description: Message Index used to index a dynamic size Message FIFO.
-
-*****************************************************************************/
-typedef struct _mindex {
- int offset; /* offset to message in buf */
- int size; /* size of message in bytes */
-} MINDEX;
-
-/*****************************************************************************
-
- Struct: MFIFO
-
- Description: Message FIFO. Provides a dynamic sized message based FIFO
- queue.
-
-*****************************************************************************/
-typedef struct {
- int first; /* first out */
- int last; /* last in + 1 */
- int bsize; /* buffer size */
- unsigned char *buf; /* ptr to start of buffer */
- int ixsize; /* index size */
- MINDEX ix[1]; /* message index */
-} MFIFO;
-
-/*****************************************************************************
- Function prototypes.
-*****************************************************************************/
-int MFIFOCreate(unsigned char *buf, int size, int index);
-void MFIFOClear(unsigned char * buf);
-int MFIFOGetLBOffset(unsigned char *buf);
-int MFIFOGetFBOffset(unsigned char *buf);
-void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off);
-int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size);
-unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size);
-void MFIFOKillNext(unsigned char *buf);
-
-unsigned char * MFIFOGetMesPtrOffset(unsigned char *buf, int *size, const int pos);
-int MFIFOGetMesCount(unsigned char *buf);
-int MFIFOWriteMesOverwrite(unsigned char *buf, unsigned char *mes, int size);
-
-#endif
diff --git a/libs/openzap/src/isdn/include/national.h b/libs/openzap/src/isdn/include/national.h
deleted file mode 100644
index cff26aa4a4..0000000000
--- a/libs/openzap/src/isdn/include/national.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/******************************************************************************
-
- FileName: national.h
-
- Contents: Header and definition for the National ISDN dialect. The
- header contents the following parts:
- - Definition of codes
- - Definition of information elements (nationalie_).
- - Definition of messages (nationalmes_).
- - Function prototypes.
-
- Description: The National ISDN dialect here covers ????
-
- Related Files: national.h National ISDN Definitions
- nationalie.c National ISDN IE encoders/coders
- nationalStateTE.c National ISDN TE State Engine
- nationalStateNT.c National ISDN NT State Engine
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-******************************************************************************/
-
-#ifndef _national_NATIONAL_NL
-#define _national_NATIONAL_NL
-
-#include "Q931.h"
-
-/*****************************************************************************
-
- Q.931 Message codes
- Only National specific message and ie types
- here the rest are inherited from national.h
-
-*****************************************************************************/
-
-
-/*****************************************************************************
-
- Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c
-
-*****************************************************************************/
-L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
-L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
-
-#include "DMS.h"
-
-/*****************************************************************************
-
- Q.931 Process Function Prototyping. Implemented in nationalStateTE.c
-
-*****************************************************************************/
-
-void nationalCreateTE(L3UCHAR i);
-void nationalCreateNT(L3UCHAR i);
-
-#endif /* _national_NATIONAL_NL */
diff --git a/libs/openzap/src/isdn/mfifo.c b/libs/openzap/src/isdn/mfifo.c
deleted file mode 100644
index 28528f9b64..0000000000
--- a/libs/openzap/src/isdn/mfifo.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*****************************************************************************
-
- Filename: mfifo.c
-
- Description: mfifo is a message orriented fifo system with support of
- both message and byte per byte retriaval of messages.
-
- The fifo has been designed with two usages in mind:
-
- - Queueing of frames for hdlc and feeding out byte per byte
- with the possibility of re-sending of frames etc.
-
- - fifo for messages of dynamic size.
-
- The fifo is allocated on top of any buffer and creates an
- index of message in the queue. The user can write/read
- messages or write messages and read the message one byte
- at the time.
-
- Interface:
- MFIFOCreate Create/reset/initialize fifo.
- MFIFOClear Clear FIFO.
- MFIFOWriteMes Write message into fifo
- * MFIFOReadMes Read message from fifo.
- MFIFOGetMesPtr Get ptr to next message.
- MFIFOKillNext Kill next message.
-
- * currently not implemented.
-
- Note: The message will always be saved continuously. If there is not
- sufficient space at the end of the buffer, the fifo will skip
- the last bytes and save the message at the top of the buffer.
-
- This is required to allow direct ptr access to messages
- stored in the queue.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "mfifo.h"
-#include
-#include
-
-/*****************************************************************************
-
- Function: MFIFOCreate
-
- Description: Creates a fifo on top of an existing buffer.
-
- Parameters: buf ptr to buffer.
- size size of buffer in bytes.
- index size of index entries (max no messages).
-
- Return value: 0 if failure, 1 if ok.
-
-*****************************************************************************/
-int MFIFOCreate(unsigned char *buf, int size, int index)
-{
- MFIFO *mf = (MFIFO *)buf;
-
- mf->first = mf->last = 0;
- mf->ixsize = index;
- mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * index)];
-
- if (mf->buf > &buf[size])
- return 0;
-
- mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * index);
-
- return 1;
-}
-
-/*****************************************************************************
-
- Function: MFIFOClear
-
- Description: Clear the FIFO
-
- Paremeters: buf ptr to fifo
-
- Return Value: none
-
-*****************************************************************************/
-void MFIFOClear(unsigned char * buf)
-{
- MFIFO *mf = (MFIFO *)buf;
-
- mf->first = mf->last = 0;
-}
-
-/*****************************************************************************
-
- Function: MFIFOGetLBOffset
-
- Description: Helper function caclulating offset to the 'first out' byte.
-
- Paremeters: buf ptr to fifo
-
- Return Value: offset.
-
-*****************************************************************************/
-int MFIFOGetLBOffset(unsigned char *buf)
-{
- MFIFO *mf = (MFIFO *)buf;
-
- if (mf->last != mf->first)
- return mf->ix[mf->last].offset;
-
- return 0;
-}
-
-/*****************************************************************************
-
- Function: MFIFOGetFBOffset
-
- Description: Helper function calculating the offset to the 'first in'
- byte in the buffer. This is the position the next byte
- entering the fifo will occupy.
-
- Paremeters: buf ptr to fifo
-
- Return Value: offset
-
-*****************************************************************************/
-int MFIFOGetFBOffset(unsigned char *buf)
-{
- MFIFO *mf = (MFIFO *)buf;
- int x;
-
- if (mf->last == mf->first)
- return 0;
-
- x = mf->first - 1;
-
- if (x < 0)
- x = mf->ixsize - 1;
-
- return mf->ix[x].offset + mf->ix[x].size;
-}
-
-/*****************************************************************************
-
- Function: MFIFOWriteIX
-
- Description: Helper function writing a calculated entry. The function
- will perform a memcpy to move the message and set the index
- values as well as increase the 'first in' index.
-
- Paremeters: buf ptr to fifo
- mes ptr to message
- size size of message in bytes.
- ix index to index entry.
- off offset to position to receive the message
-
- Return Value: none
-
-*****************************************************************************/
-void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off)
-{
- MFIFO *mf = (MFIFO *)buf;
- int x;
-
- memcpy(&mf->buf[off], mes, size);
- mf->ix[ix].offset = off;
- mf->ix[ix].size = size;
-
- x = mf->first + 1;
-
- if (x >= mf->ixsize)
- x = 0;
-
- mf->first = x;
-}
-
-/*****************************************************************************
-
- Function: MFIFOWriteMes
-
- Description:
-
- Paremeters:
-
- Return Value:
-
-*****************************************************************************/
-int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size)
-{
- MFIFO *mf = (MFIFO *)buf;
- int of, ol, x;
-
- x = mf->first + 1;
-
- if (x >= mf->ixsize)
- x = 0;
-
- if (x == mf->last)
- return 0; /* full queue */
-
- of = MFIFOGetFBOffset(buf);
- ol = MFIFOGetLBOffset(buf);
- if (mf->last == mf->first) { /* empty queue */
- mf->first = mf->last = 0; /* optimize */
-
- MFIFOWriteIX(buf, mes, size, mf->first, 0);
- return 1;
- }
- else if (of > ol) {
- if (mf->bsize - of >= size) {
- MFIFOWriteIX(buf, mes, size, mf->first, of);
- return 1;
- }
- else if (ol > size) {
- MFIFOWriteIX(buf, mes, size, mf->first, ol);
- return 1;
- }
- }
- else if (ol - of > size) {
- MFIFOWriteIX(buf, mes, size, mf->first, of);
- return 1;
- }
-
- return 0;
-}
-
-/*****************************************************************************
-
- Function: MFIFOGetMesPtr
-
- Description:
-
- Paremeters:
-
- Return Value:
-
-*****************************************************************************/
-unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size)
-{
- MFIFO *mf = (MFIFO *)buf;
-
- if (mf->first == mf->last) {
- return NULL;
- }
-
- *size = mf->ix[mf->last].size;
- return &mf->buf[mf->ix[mf->last].offset];
-}
-
-/*****************************************************************************
-
- Function: MFIFOKillNext
-
- Description:
-
- Paremeters:
-
- Return Value:
-
-*****************************************************************************/
-void MFIFOKillNext(unsigned char *buf)
-{
- MFIFO *mf = (MFIFO *)buf;
- int x;
-
- if (mf->first != mf->last) {
- x = mf->last + 1;
- if (x >= mf->ixsize) {
- x = 0;
- }
-
- mf->last = x;
- }
-}
-
-
-/*
- * Queue-style accessor functions
- */
-
-/**
- * MFIFOGetMesPtrOffset
- * \brief Get pointer to and size of message at position x
- */
-unsigned char * MFIFOGetMesPtrOffset(unsigned char *buf, int *size, const int pos)
-{
- MFIFO *mf = (MFIFO *)buf;
- int x;
-
- if (mf->first == mf->last) {
- return NULL;
- }
-
- if (pos < 0 || pos >= mf->ixsize) {
- return NULL;
- }
-
- x = pos - mf->last;
- if (x < 0) {
- x += (mf->ixsize - 1);
- }
-
- *size = mf->ix[x].size;
- return &mf->buf[mf->ix[x].offset];
-}
-
-
-/**
- * MFIFOGetMesCount
- * \brief How many messages are currently in the buffer?
- */
-int MFIFOGetMesCount(unsigned char *buf)
-{
- MFIFO *mf = (MFIFO *)buf;
-
- if (mf->first == mf->last) {
- return 0;
- }
- else if (mf->first > mf->last) {
- return mf->first - mf->last;
- }
- else {
- return (mf->ixsize - mf->last) + mf->first;
- }
-}
-
-/**
- * MFIFOWriteMesOverwrite
- * \brief Same as MFIFOWriteMes but old frames will be overwritten if the fifo is full
- */
-int MFIFOWriteMesOverwrite(unsigned char *buf, unsigned char *mes, int size)
-{
- MFIFO *mf = (MFIFO *)buf;
- int of, ol, x;
-
- x = mf->first + 1;
-
- if (x >= mf->ixsize)
- x = 0;
-
- if (x == mf->last) {
- /* advance last pointer */
- mf->last++;
-
- if (mf->last >= mf->ixsize)
- mf->last = 0;
- }
-
- of = MFIFOGetFBOffset(buf);
- ol = MFIFOGetLBOffset(buf);
-
- if (mf->last == mf->first) { /* empty queue */
- mf->first = mf->last = 0; /* optimize */
-
- MFIFOWriteIX(buf, mes, size, mf->first, 0);
- return 1;
- }
- else if (of > ol) {
- if (mf->bsize - of >= size) {
- MFIFOWriteIX(buf, mes, size, mf->first, of);
- return 1;
- }
- else if (ol > size) {
- MFIFOWriteIX(buf, mes, size, mf->first, ol);
- return 1;
- }
- }
- else if (ol - of > size) {
- MFIFOWriteIX(buf, mes, size, mf->first, of);
- return 1;
- }
- return 0;
-}
diff --git a/libs/openzap/src/isdn/nationalStateNT.c b/libs/openzap/src/isdn/nationalStateNT.c
deleted file mode 100644
index b150999650..0000000000
--- a/libs/openzap/src/isdn/nationalStateNT.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*****************************************************************************
-
- FileName: nationalStateNT.c
-
- Contents: National ISDN State Engine for NT (Network Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "national.h"
-
-/*****************************************************************************
- Function: nationalCreateNT
-
- Description: Will create the National ISDN NT as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void nationalCreateNT(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingNT, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingNT, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, Q931ProcConnectNT, Q931Umes_Connect, Q931Pmes_Connect);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, Q931ProcConnectAckNT, Q931Umes_ConnectAck, Q931Pmes_ConnectAck);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressNT, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupNT, nationalUmes_Setup, nationalPmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckNT, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeNT, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckNT, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectNT, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendNT, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckNT, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectNT, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationNT, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectNT, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseNT, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteNT, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartNT, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckNT, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationNT, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyNT, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusNT, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryNT, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentNT, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityNT, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldNT, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckNT, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectNT, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterNT, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveNT, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckNT, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectNT, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
- Q931SetIEProc(Q931ie_GENERIC_DIGITS, i, Q931Pie_GenericDigits, Q931Uie_GenericDigits);
-
- Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_FACILITY, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_REDIRECTING_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
-
- /* The following define a state machine. The point is that the Message */
- /* procs can when search this to find out if the message/state */
- /* combination is legale. If not, the proc for unexpected message apply.*/
-
- /* TODO define state table here */
-}
diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c
deleted file mode 100644
index 46731d0910..0000000000
--- a/libs/openzap/src/isdn/nationalStateTE.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*****************************************************************************
-
- FileName: nationalStateTE.c
-
- Contents: National ISDN State Engine for TE (User Mode).
-
- The controlling state engine for Q.931 is the state engine
- on the NT side. The state engine on the TE side is a slave
- of this. The TE side maintain it's own states as described in
- ITU-T Q931, but will in raise conditions be overridden by
- the NT side.
-
- This reference implementation uses a process per message,
- meaning that each message must check call states. This
- is easier for dialect maintenance as each message proc
- can be replaced individually. A new TE variant only
- need to copy the Q931CreateTE and replace those procs or
- need to override.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-*****************************************************************************/
-
-#include "national.h"
-extern L3INT Q931L4HeaderSpace;
-
-/*****************************************************************************
- Function: nationalCreateTE
-
- Description: Will create the National TE as a Dialect in the stack. The first
- bulk set up the message handlers, the second bulk the IE
- encoders/coders, and the last bulk set up the state table.
-
- Parameters: i Dialect index
-*****************************************************************************/
-void nationalCreateTE(L3UCHAR i)
-{
- Q931SetMesProc(Q931mes_ALERTING, i, Q931ProcAlertingTE, Q931Umes_Alerting, Q931Pmes_Alerting);
- Q931SetMesProc(Q931mes_CALL_PROCEEDING, i, Q931ProcCallProceedingTE, Q931Umes_CallProceeding, Q931Pmes_CallProceeding);
- Q931SetMesProc(Q931mes_CONNECT, i, DMSProc0x07TE, DMSUmes_0x07, DMSPmes_0x07);
- Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i, DMSProc0x0fTE, DMSUmes_0x0f, DMSPmes_0x0f);
- Q931SetMesProc(Q931mes_PROGRESS, i, Q931ProcProgressTE, Q931Umes_Progress, Q931Pmes_Progress);
- Q931SetMesProc(Q931mes_SETUP, i, Q931ProcSetupTE, nationalUmes_Setup, nationalPmes_Setup);
- Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE, i, Q931ProcSetupAckTE, Q931Umes_SetupAck, Q931Pmes_SetupAck);
- Q931SetMesProc(Q931mes_RESUME, i, Q931ProcResumeTE, Q931Umes_Resume, Q931Pmes_Resume);
- Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE, i, Q931ProcResumeAckTE, Q931Umes_ResumeAck, Q931Pmes_ResumeAck);
- Q931SetMesProc(Q931mes_RESUME_REJECT, i, Q931ProcResumeRejectTE, Q931Umes_ResumeReject, Q931Pmes_ResumeReject);
- Q931SetMesProc(Q931mes_SUSPEND, i, Q931ProcSuspendTE, Q931Umes_Suspend, Q931Pmes_Suspend);
- Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i, Q931ProcSuspendAckTE, Q931Umes_SuspendAck, Q931Pmes_SuspendAck);
- Q931SetMesProc(Q931mes_SUSPEND_REJECT, i, Q931ProcSuspendRejectTE, Q931Umes_SuspendReject, Q931Pmes_SuspendReject);
- Q931SetMesProc(Q931mes_USER_INFORMATION, i, Q931ProcUserInformationTE, Q931Umes_UserInformation, Q931Pmes_UserInformation);
- Q931SetMesProc(Q931mes_DISCONNECT, i, Q931ProcDisconnectTE, Q931Umes_Disconnect, Q931Pmes_Disconnect);
- Q931SetMesProc(Q931mes_RELEASE, i, Q931ProcReleaseTE, Q931Umes_Release, Q931Pmes_Release);
- Q931SetMesProc(Q931mes_RELEASE_COMPLETE, i, Q931ProcReleaseCompleteTE, Q931Umes_ReleaseComplete, Q931Pmes_ReleaseComplete);
- Q931SetMesProc(Q931mes_RESTART, i, Q931ProcRestartTE, Q931Umes_Restart, Q931Pmes_Restart);
- Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i, Q931ProcRestartAckTE, Q931Umes_RestartAck, Q931Pmes_RestartAck);
- Q931SetMesProc(Q931mes_CONGESTION_CONTROL, i, Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
- Q931SetMesProc(Q931mes_INFORMATION, i, Q931ProcInformationTE, Q931Umes_Information, Q931Pmes_Information);
- Q931SetMesProc(Q931mes_NOTIFY, i, Q931ProcNotifyTE, Q931Umes_Notify, Q931Pmes_Notify);
- Q931SetMesProc(Q931mes_STATUS, i, Q931ProcStatusTE, Q931Umes_Status, Q931Pmes_Status);
- Q931SetMesProc(Q931mes_STATUS_ENQUIRY, i, Q931ProcStatusEnquiryTE, Q931Umes_StatusEnquiry, Q931Pmes_StatusEnquiry);
- Q931SetMesProc(Q931mes_SEGMENT, i, Q931ProcSegmentTE, Q931Umes_Segment, Q931Pmes_Segment);
-
- Q931SetMesProc(Q932mes_FACILITY, i, Q932ProcFacilityTE, Q932Umes_Facility, Q932Pmes_Facility);
- Q931SetMesProc(Q932mes_HOLD, i, Q932ProcHoldTE, Q932Umes_Hold, Q932Pmes_Hold);
- Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE, i, Q932ProcHoldAckTE, Q932Umes_HoldAck, Q932Pmes_HoldAck);
- Q931SetMesProc(Q932mes_HOLD_REJECT, i, Q932ProcHoldRejectTE, Q932Umes_HoldReject, Q932Pmes_HoldReject);
- Q931SetMesProc(Q932mes_REGISTER, i, Q932ProcRegisterTE, Q932Umes_Register, Q932Pmes_Register);
- Q931SetMesProc(Q932mes_RETRIEVE, i, Q932ProcRetrieveTE, Q932Umes_Retrieve, Q932Pmes_Retrieve);
- Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckTE, Q932Umes_RetrieveAck, Q932Pmes_RetrieveAck);
- Q931SetMesProc(Q932mes_RETRIEVE_REJECT, i, Q932ProcRetrieveRejectTE, Q932Umes_RetrieveReject, Q932Pmes_RetrieveReject);
-
- /* Set up the IE encoder/decoder handle table.*/
- Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE, i, Q931Pie_Segment, Q931Uie_Segment);
- Q931SetIEProc(Q931ie_BEARER_CAPABILITY, i, Q931Pie_BearerCap, Q931Uie_BearerCap);
- Q931SetIEProc(Q931ie_CAUSE, i, Q931Pie_Cause, Q931Uie_Cause);
- Q931SetIEProc(Q931ie_CALL_IDENTITY, i, Q931Pie_CallID, Q931Uie_CallID);
- Q931SetIEProc(Q931ie_CALL_STATE, i, Q931Pie_CallState, Q931Uie_CallState);
- Q931SetIEProc(Q931ie_CHANGE_STATUS, i, Q931Pie_ChangeStatus, Q931Uie_ChangeStatus);
- Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION, i, Q931Pie_ChanID, Q931Uie_ChanID);
- Q931SetIEProc(Q931ie_PROGRESS_INDICATOR, i, Q931Pie_ProgInd, Q931Uie_ProgInd);
- Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES, i, Q931Pie_NetFac, Q931Uie_NetFac);
- Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR, i, Q931Pie_NotifInd, Q931Uie_NotifInd);
- Q931SetIEProc(Q931ie_DISPLAY, i, Q931Pie_Display, Q931Uie_Display);
- Q931SetIEProc(Q931ie_DATETIME, i, Q931Pie_DateTime, Q931Uie_DateTime);
- Q931SetIEProc(Q931ie_KEYPAD_FACILITY, i, Q931Pie_KeypadFac, Q931Uie_KeypadFac);
- Q931SetIEProc(Q931ie_SIGNAL, i, Q931Pie_Signal, Q931Uie_Signal);
- Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER, i, Q931Pie_CallingNum, Q931Uie_CallingNum);
- Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS, i, Q931Pie_CallingSub, Q931Uie_CallingSub);
- Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER, i, Q931Pie_CalledNum, Q931Uie_CalledNum);
- Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS, i, Q931Pie_CalledSub, Q931Uie_CalledSub);
- Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION, i, Q931Pie_TransNetSel, Q931Uie_TransNetSel);
- Q931SetIEProc(Q931ie_RESTART_INDICATOR, i, Q931Pie_RestartInd, Q931Uie_RestartInd);
- Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY, i, Q931Pie_LLComp, Q931Uie_LLComp);
- Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY, i, Q931Pie_HLComp, Q931Uie_HLComp);
- Q931SetIEProc(Q931ie_USER_USER, i, Q931Pie_UserUser, Q931Uie_UserUser);
- Q931SetIEProc(Q931ie_GENERIC_DIGITS, i, Q931Pie_GenericDigits, Q931Uie_GenericDigits);
-
- Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_FACILITY, i, Q931Pie_Generic, Q931Uie_Generic);
- Q931SetIEProc(Q931ie_REDIRECTING_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
-
- /* The following define a state machine. The point is that the Message
- * procs can when search this to find out if the message/state
- * combination is legale. If not, the proc for unexpected message apply.
- */
-
- /* State 0 Idle */
- Q931AddStateEntry(i, Q931_U0, Q931mes_RESUME, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_SETUP, 2);
- Q931AddStateEntry(i, Q931_U0, Q931mes_STATUS, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U0, Q931mes_RELEASE_COMPLETE, 4);
-
- /* State 1 Call Initiating */
- Q931AddStateEntry(i, Q931_U1, Q931mes_DISCONNECT, 2);
- Q931AddStateEntry(i, Q931_U1, Q931mes_SETUP_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_RELEASE_COMPLETE, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U1, Q931mes_CONNECT, 4);
-
- /* State 2 Overlap Sending */
- Q931AddStateEntry(i, Q931_U2, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CALL_PROCEEDING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U2, Q931mes_RELEASE, 2);
-
- /* State 3 Outgoing Call Proceeding */
- Q931AddStateEntry(i, Q931_U3, Q931mes_PROGRESS, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_ALERTING, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_CONNECT, 4);
- Q931AddStateEntry(i, Q931_U3, Q931mes_RELEASE, 2);
-
- /* State 4 Call Delivered */
- Q931AddStateEntry(i, Q931_U4, Q931mes_CONNECT, 4);
-
- /* State 6 Call Precent */
- Q931AddStateEntry(i, Q931_U6, Q931mes_INFORMATION, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CALL_PROCEEDING, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE_COMPLETE, 2);
- Q931AddStateEntry(i, Q931_U6, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U6, Q931mes_DISCONNECT, 4);
-
- /* State 7 Call Received */
- Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2);
-
- /* State 8 Connect request */
- Q931AddStateEntry(i, Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4);
-
- /* State 9 Incoming Call Proceeding */
- Q931AddStateEntry(i, Q931_U9, Q931mes_CONNECT, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_ALERTING, 2);
- Q931AddStateEntry(i, Q931_U9, Q931mes_PROGRESS, 2);
-
- /* State 10 Active */
- Q931AddStateEntry(i, Q931_U10, Q931mes_SUSPEND, 2);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 4);
- Q931AddStateEntry(i, Q931_U10, Q931mes_NOTIFY, 2);
-
- /* State 11 Disconnect Request */
- Q931AddStateEntry(i, Q931_U11, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U11, Q931mes_NOTIFY, 4);
-
- /* State 12 Disconnect Ind */
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 4);
- Q931AddStateEntry(i, Q931_U12, Q931mes_RELEASE, 2);
-
- /* State 15 Suspend Request */
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_ACKNOWLEDGE, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_SUSPEND_REJECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_DISCONNECT, 4);
- Q931AddStateEntry(i, Q931_U15, Q931mes_RELEASE, 4);
-
-/* TODO
- Q931AddStateEntry(i, Q931_U17,
- Q931AddStateEntry(i, Q931_U19,
- Q931AddStateEntry(i, Q931_U25,
-*/
-}
diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c
deleted file mode 100644
index 6d8350fbcd..0000000000
--- a/libs/openzap/src/isdn/nationalmes.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/*****************************************************************************
-
- FileName: nationalmes.c
-
- Contents: Pack/Unpack functions. These functions will unpack a National ISDN
- message from the bit packed original format into structs
- that contains variables sized by the user. It will also pack
- the struct back into a Q.931 message as required.
-
- See national.h for description.
-
- License/Copyright:
-
- Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
- email:janvb@caselaboratories.com
-
- Copyright (c) 2007, Michael Jerris. All rights reserved.
- email:mike@jerris.com
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the Case Labs, Ltd nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-*****************************************************************************/
-
-#include "national.h"
-
-/*****************************************************************************
-
- Function: nationalUmes_Setup
-
-*****************************************************************************/
-L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
-{
- L3INT ir = 0;
- L3INT OOff = 0;
- L3INT rc = Q931E_NO_ERROR;
- L3UCHAR last_codeset = 0, codeset = 0;
- L3UCHAR shift_lock = 1;
-
- while (IOff < Size) {
- if (!shift_lock) {
- codeset = last_codeset;
- }
-
- if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) {
- shift_lock = (IBuf[IOff] & 0x08);
- if (shift_lock) {
- last_codeset = codeset;
- }
- codeset = ((IBuf[IOff] & 0x07));
- IOff++;
- }
-
- if (codeset == 0) {
- switch (IBuf[IOff]) {
- case Q931ie_SENDING_COMPLETE:
- case Q931ie_BEARER_CAPABILITY:
- case Q931ie_CHANNEL_IDENTIFICATION:
- case Q931ie_PROGRESS_INDICATOR:
- case Q931ie_NETWORK_SPECIFIC_FACILITIES:
- case Q931ie_DISPLAY:
- case Q931ie_DATETIME:
- case Q931ie_KEYPAD_FACILITY:
- case Q931ie_SIGNAL:
- case Q931ie_CALLING_PARTY_NUMBER:
- case Q931ie_CALLING_PARTY_SUBADDRESS:
- case Q931ie_CALLED_PARTY_NUMBER:
- case Q931ie_CALLED_PARTY_SUBADDRESS:
- case Q931ie_TRANSIT_NETWORK_SELECTION:
- case Q931ie_LOW_LAYER_COMPATIBILITY:
- case Q931ie_HIGH_LAYER_COMPATIBILITY:
- case Q931ie_FACILITY:
- case Q931ie_REDIRECTING_NUMBER:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- case Q931ie_REPEAT_INDICATOR:
- if (ir < 2) {
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- ir++;
- } else {
- return Q931E_ILLEGAL_IE;
- }
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
- } else if (codeset == 6) {
- switch (IBuf[IOff]) {
- case Q931ie_GENERIC_DIGITS:
- rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
- if (rc != Q931E_NO_ERROR)
- return rc;
- break;
- default:
- return Q931E_ILLEGAL_IE;
- break;
- }
-
- } else {
- return Q931E_ILLEGAL_IE;
- }
- }
- mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
- return Q931E_NO_ERROR;
-}
-
-/*****************************************************************************
-
- Function: nationalPmes_Setup
-
- Decription: Pack a Q931mes_Generic into a real Q.931 message. The user will
- set up a SETUP message and issue this to the stack where it
- is processed by Q931ProcSetup that processes and validates
- it before it actually sends it out. This function is called
- to compute the real Q.931 message.
-
- Parameters: IBuf[IN] Ptr to un-packed struct
- ISize[IN] Size of input buffer (unpacked message).
- OBuf[OUT] Ptr to packed 'octet' wise message.
- OSize[OUT] Size of packed message.
-
- Called By: Q931ProcSetup
-
-*****************************************************************************/
-L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
-{
- L3INT rc = Q931E_NO_ERROR;
- Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
- L3INT Octet = 0;
-
- /* Q931 Message Header */
- Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
-
- /* Sending Complete */
- if (Q931IsIEPresent(pMes->SendComplete)) {
- OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff);
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->RepeatInd)) {
- OBuf[Octet++] = (L3UCHAR)(pMes->RepeatInd & 0x00ff);
- }
-
- /* Bearer capability */
- if (Q931IsIEPresent(pMes->BearerCap)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
- else {
- rc = Q931E_BEARERCAP;
- }
-
- /* Channel Identification */
- if (Q931IsIEPresent(pMes->ChanID)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Progress indicator */
- if (Q931IsIEPresent(pMes->ProgInd)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Network spesific facilities */
- if (Q931IsIEPresent(pMes->NetFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_NETWORK_SPECIFIC_FACILITIES](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Display */
- if (Q931IsIEPresent(pMes->Display)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Date/Time */
- if (Q931IsIEPresent(pMes->DateTime)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Keypad Facility */
- if (Q931IsIEPresent(pMes->KeypadFac)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Signal */
- if (Q931IsIEPresent(pMes->Signal)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Calling Party Number */
- if (Q931IsIEPresent(pMes->CallingNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Calling Party Subaddress */
- if (Q931IsIEPresent(pMes->CallingSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Called Party number */
- if (Q931IsIEPresent(pMes->CalledNum)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Called party subaddress */
- if (Q931IsIEPresent(pMes->CalledSub)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Transit network selection */
- if (Q931IsIEPresent(pMes->TransNetSel)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* Repeat Indicator */
- if (Q931IsIEPresent(pMes->LLRepeatInd)) {
- rc = Q931E_UNKNOWN_IE;/* TODO */
- }
-
- /* Low Layer Compatibility */
- if (Q931IsIEPresent(pMes->LLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- /* High Layer Compatibility */
- if (Q931IsIEPresent(pMes->HLComp)) {
- if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
- return rc;
- }
-
- *OSize = Octet;
- return rc;
-}
diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c
deleted file mode 100644
index da92525310..0000000000
--- a/libs/openzap/src/libteletone_detect.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * libteletone
- * Copyright (C) 2005-2014, Anthony Minessale II
- *
- * Much less efficient expansion interface was added to allow for the detection of
- * a single arbitrary tone combination which may also exceed 2 simultaneous tones.
- * (controlled by compile time constant TELETONE_MAX_TONES)
- *
- * Copyright (C) 2006 Anthony Minessale II
- *
- * libteletone_detect.c Tone Detection Code
- *
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *********************************************************************************
- *
- * Derived from tone_detect.c - General telephony tone detection, and specific
- * detection of DTMF.
- *
- * 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.
- *
- *
- *
- */
-
-#include
-
-#ifndef _MSC_VER
-#include
-#endif
-#include
-#include
-#include
-#include
-
-
-static teletone_detection_descriptor_t dtmf_detect_row[GRID_FACTOR];
-static teletone_detection_descriptor_t dtmf_detect_col[GRID_FACTOR];
-static teletone_detection_descriptor_t dtmf_detect_row_2nd[GRID_FACTOR];
-static teletone_detection_descriptor_t dtmf_detect_col_2nd[GRID_FACTOR];
-
-static float dtmf_row[] = {697.0f, 770.0f, 852.0f, 941.0f};
-static float dtmf_col[] = {1209.0f, 1336.0f, 1477.0f, 1633.0f};
-
-static char dtmf_positions[] = "123A" "456B" "789C" "*0#D";
-
-static void goertzel_init(teletone_goertzel_state_t *goertzel_state, teletone_detection_descriptor_t *tdesc) {
- goertzel_state->v2 = goertzel_state->v3 = 0.0;
- goertzel_state->fac = tdesc->fac;
-}
-
-TELETONE_API(void) teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state,
- int16_t sample_buffer[],
- int samples)
-{
- int i;
- float v1;
-
- for (i = 0; i < samples; i++) {
- v1 = goertzel_state->v2;
- goertzel_state->v2 = goertzel_state->v3;
- goertzel_state->v3 = (float)(goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]);
- }
-}
-#ifdef _MSC_VER
-#pragma warning(disable:4244)
-#endif
-
-#define teletone_goertzel_result(gs) (double)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac))
-
-TELETONE_API(void) teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate)
-{
- int i;
- float theta;
-
- dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0;
-
- for (i = 0; i < GRID_FACTOR; i++) {
- theta = (float)(M_TWO_PI*(dtmf_row[i]/(float)sample_rate));
- dtmf_detect_row[i].fac = (float)(2.0*cos(theta));
-
- theta = (float)(M_TWO_PI*(dtmf_col[i]/(float)sample_rate));
- dtmf_detect_col[i].fac = (float)(2.0*cos(theta));
-
- theta = (float)(M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate));
- dtmf_detect_row_2nd[i].fac = (float)(2.0*cos(theta));
-
- theta = (float)(M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate));
- dtmf_detect_col_2nd[i].fac = (float)(2.0*cos(theta));
-
- goertzel_init (&dtmf_detect_state->row_out[i], &dtmf_detect_row[i]);
- goertzel_init (&dtmf_detect_state->col_out[i], &dtmf_detect_col[i]);
- goertzel_init (&dtmf_detect_state->row_out2nd[i], &dtmf_detect_row_2nd[i]);
- goertzel_init (&dtmf_detect_state->col_out2nd[i], &dtmf_detect_col_2nd[i]);
-
- dtmf_detect_state->energy = 0.0;
- }
- dtmf_detect_state->current_sample = 0;
- dtmf_detect_state->detected_digits = 0;
- dtmf_detect_state->lost_digits = 0;
- dtmf_detect_state->digits[0] = '\0';
- dtmf_detect_state->mhit = 0;
-}
-
-TELETONE_API(void) teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map)
-{
- float theta = 0;
- int x = 0;
-
- if (!mt->sample_rate) {
- mt->sample_rate = 8000;
- }
-
- if (!mt->min_samples) {
- mt->min_samples = 102;
- }
-
- mt->min_samples *= (mt->sample_rate / 8000);
-
- if (!mt->positive_factor) {
- mt->positive_factor = 2;
- }
-
- if(!mt->negative_factor) {
- mt->negative_factor = 10;
- }
-
- if (!mt->hit_factor) {
- mt->hit_factor = 2;
- }
-
- for(x = 0; x < TELETONE_MAX_TONES; x++) {
- if ((int) map->freqs[x] == 0) {
- break;
- }
- mt->tone_count++;
- theta = (float)(M_TWO_PI*(map->freqs[x]/(float)mt->sample_rate));
- mt->tdd[x].fac = (float)(2.0 * cos(theta));
- goertzel_init (&mt->gs[x], &mt->tdd[x]);
- goertzel_init (&mt->gs2[x], &mt->tdd[x]);
- }
-
-}
-
-TELETONE_API(int) teletone_multi_tone_detect (teletone_multi_tone_t *mt,
- int16_t sample_buffer[],
- int samples)
-{
- int sample, limit = 0, j, x = 0;
- float v1, famp;
- float eng_sum = 0, eng_all[TELETONE_MAX_TONES] = {0.0};
- int gtest = 0, see_hit = 0;
-
- for (sample = 0; sample >= 0 && sample < samples; sample = limit) {
- mt->total_samples++;
-
- if ((samples - sample) >= (mt->min_samples - mt->current_sample)) {
- limit = sample + (mt->min_samples - mt->current_sample);
- } else {
- limit = samples;
- }
- if (limit < 0 || limit > samples) {
- limit = samples;
- }
-
- for (j = sample; j < limit; j++) {
- famp = sample_buffer[j];
-
- mt->energy += famp*famp;
-
- for(x = 0; x < TELETONE_MAX_TONES && x < mt->tone_count; x++) {
- v1 = mt->gs[x].v2;
- mt->gs[x].v2 = mt->gs[x].v3;
- mt->gs[x].v3 = (float)(mt->gs[x].fac * mt->gs[x].v2 - v1 + famp);
-
- v1 = mt->gs2[x].v2;
- mt->gs2[x].v2 = mt->gs2[x].v3;
- mt->gs2[x].v3 = (float)(mt->gs2[x].fac*mt->gs2[x].v2 - v1 + famp);
- }
- }
-
- mt->current_sample += (limit - sample);
- if (mt->current_sample < mt->min_samples) {
- continue;
- }
-
- eng_sum = 0;
- for(x = 0; x < TELETONE_MAX_TONES && x < mt->tone_count; x++) {
- eng_all[x] = (float)(teletone_goertzel_result (&mt->gs[x]));
- eng_sum += eng_all[x];
- }
-
- gtest = 0;
- for(x = 0; x < TELETONE_MAX_TONES && x < mt->tone_count; x++) {
- gtest += teletone_goertzel_result (&mt->gs2[x]) < eng_all[x] ? 1 : 0;
- }
-
- if ((gtest >= 2 || gtest == mt->tone_count) && eng_sum > 42.0 * mt->energy) {
- if(mt->negatives) {
- mt->negatives--;
- }
- mt->positives++;
-
- if(mt->positives >= mt->positive_factor) {
- mt->hits++;
- }
- if (mt->hits >= mt->hit_factor) {
- see_hit++;
- mt->positives = mt->negatives = mt->hits = 0;
- }
- } else {
- mt->negatives++;
- if(mt->positives) {
- mt->positives--;
- }
- if(mt->negatives > mt->negative_factor) {
- mt->positives = mt->hits = 0;
- }
- }
-
- /* Reinitialise the detector for the next block */
- for(x = 0; x < TELETONE_MAX_TONES && x < mt->tone_count; x++) {
- goertzel_init (&mt->gs[x], &mt->tdd[x]);
- goertzel_init (&mt->gs2[x], &mt->tdd[x]);
- }
-
- mt->energy = 0.0;
- mt->current_sample = 0;
- }
-
- return see_hit;
-}
-
-
-TELETONE_API(int) teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state,
- int16_t sample_buffer[],
- int samples)
-{
- float row_energy[GRID_FACTOR];
- float col_energy[GRID_FACTOR];
- float famp;
- float v1;
- int i;
- int j;
- int sample;
- int best_row;
- int best_col;
- char hit;
- int limit;
-
- hit = 0;
- for (sample = 0; sample < samples; sample = limit) {
- /* BLOCK_LEN is optimised to meet the DTMF specs. */
- if ((samples - sample) >= (BLOCK_LEN - dtmf_detect_state->current_sample)) {
- limit = sample + (BLOCK_LEN - dtmf_detect_state->current_sample);
- } else {
- limit = samples;
- }
-
- for (j = sample; j < limit; j++) {
- int x = 0;
- famp = sample_buffer[j];
-
- dtmf_detect_state->energy += famp*famp;
-
- for(x = 0; x < GRID_FACTOR; x++) {
- v1 = dtmf_detect_state->row_out[x].v2;
- dtmf_detect_state->row_out[x].v2 = dtmf_detect_state->row_out[x].v3;
- dtmf_detect_state->row_out[x].v3 = (float)(dtmf_detect_state->row_out[x].fac*dtmf_detect_state->row_out[x].v2 - v1 + famp);
-
- v1 = dtmf_detect_state->col_out[x].v2;
- dtmf_detect_state->col_out[x].v2 = dtmf_detect_state->col_out[x].v3;
- dtmf_detect_state->col_out[x].v3 = (float)(dtmf_detect_state->col_out[x].fac*dtmf_detect_state->col_out[x].v2 - v1 + famp);
-
- v1 = dtmf_detect_state->col_out2nd[x].v2;
- dtmf_detect_state->col_out2nd[x].v2 = dtmf_detect_state->col_out2nd[x].v3;
- dtmf_detect_state->col_out2nd[x].v3 = (float)(dtmf_detect_state->col_out2nd[x].fac*dtmf_detect_state->col_out2nd[x].v2 - v1 + famp);
-
- v1 = dtmf_detect_state->row_out2nd[x].v2;
- dtmf_detect_state->row_out2nd[x].v2 = dtmf_detect_state->row_out2nd[x].v3;
- dtmf_detect_state->row_out2nd[x].v3 = (float)(dtmf_detect_state->row_out2nd[x].fac*dtmf_detect_state->row_out2nd[x].v2 - v1 + famp);
- }
-
- }
-
- dtmf_detect_state->current_sample += (limit - sample);
- if (dtmf_detect_state->current_sample < BLOCK_LEN) {
- continue;
- }
- /* We are at the end of a DTMF detection block */
- /* Find the peak row and the peak column */
- row_energy[0] = teletone_goertzel_result (&dtmf_detect_state->row_out[0]);
- col_energy[0] = teletone_goertzel_result (&dtmf_detect_state->col_out[0]);
-
- for (best_row = best_col = 0, i = 1; i < GRID_FACTOR; i++) {
- row_energy[i] = teletone_goertzel_result (&dtmf_detect_state->row_out[i]);
- if (row_energy[i] > row_energy[best_row]) {
- best_row = i;
- }
- col_energy[i] = teletone_goertzel_result (&dtmf_detect_state->col_out[i]);
- if (col_energy[i] > col_energy[best_col]) {
- best_col = i;
- }
- }
- hit = 0;
- /* Basic signal level test and the twist test */
- if (row_energy[best_row] >= DTMF_THRESHOLD &&
- col_energy[best_col] >= DTMF_THRESHOLD &&
- col_energy[best_col] < row_energy[best_row]*DTMF_REVERSE_TWIST &&
- col_energy[best_col]*DTMF_NORMAL_TWIST > row_energy[best_row]) {
- /* Relative peak test */
- for (i = 0; i < GRID_FACTOR; i++) {
- if ((i != best_col && col_energy[i]*DTMF_RELATIVE_PEAK_COL > col_energy[best_col]) ||
- (i != best_row && row_energy[i]*DTMF_RELATIVE_PEAK_ROW > row_energy[best_row])) {
- break;
- }
- }
- /* ... and second harmonic test */
- if (i >= GRID_FACTOR && (row_energy[best_row] + col_energy[best_col]) > 42.0*dtmf_detect_state->energy &&
- teletone_goertzel_result (&dtmf_detect_state->col_out2nd[best_col])*DTMF_2ND_HARMONIC_COL < col_energy[best_col] &&
- teletone_goertzel_result (&dtmf_detect_state->row_out2nd[best_row])*DTMF_2ND_HARMONIC_ROW < row_energy[best_row]) {
- hit = dtmf_positions[(best_row << 2) + best_col];
- /* Look for two successive similar results */
- /* The logic in the next test is:
- We need two successive identical clean detects, with
- something different preceeding it. This can work with
- back to back differing digits. More importantly, it
- can work with nasty phones that give a very wobbly start
- to a digit. */
- if (hit == dtmf_detect_state->hit3 && dtmf_detect_state->hit3 != dtmf_detect_state->hit2) {
- dtmf_detect_state->mhit = hit;
- dtmf_detect_state->digit_hits[(best_row << 2) + best_col]++;
- dtmf_detect_state->detected_digits++;
- if (dtmf_detect_state->current_digits < TELETONE_MAX_DTMF_DIGITS) {
- dtmf_detect_state->digits[dtmf_detect_state->current_digits++] = hit;
- dtmf_detect_state->digits[dtmf_detect_state->current_digits] = '\0';
- }
- else
- {
- dtmf_detect_state->lost_digits++;
- }
- }
- }
- }
- dtmf_detect_state->hit1 = dtmf_detect_state->hit2;
- dtmf_detect_state->hit2 = dtmf_detect_state->hit3;
- dtmf_detect_state->hit3 = hit;
- /* Reinitialise the detector for the next block */
- for (i = 0; i < GRID_FACTOR; i++) {
- goertzel_init (&dtmf_detect_state->row_out[i], &dtmf_detect_row[i]);
- goertzel_init (&dtmf_detect_state->col_out[i], &dtmf_detect_col[i]);
- goertzel_init (&dtmf_detect_state->row_out2nd[i], &dtmf_detect_row_2nd[i]);
- goertzel_init (&dtmf_detect_state->col_out2nd[i], &dtmf_detect_col_2nd[i]);
- }
- dtmf_detect_state->energy = 0.0;
- dtmf_detect_state->current_sample = 0;
- }
- if ((!dtmf_detect_state->mhit) || (dtmf_detect_state->mhit != hit)) {
- dtmf_detect_state->mhit = 0;
- return(0);
- }
- return (hit);
-}
-
-
-TELETONE_API(int) teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state,
- char *buf,
- int max)
-{
- teletone_assert(dtmf_detect_state->current_digits <= TELETONE_MAX_DTMF_DIGITS);
-
- if (max > dtmf_detect_state->current_digits) {
- max = dtmf_detect_state->current_digits;
- }
- if (max > 0) {
- memcpy (buf, dtmf_detect_state->digits, max);
- memmove (dtmf_detect_state->digits, dtmf_detect_state->digits + max, dtmf_detect_state->current_digits - max);
- dtmf_detect_state->current_digits -= max;
- }
- buf[max] = '\0';
- return max;
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c
deleted file mode 100644
index f0ab59e488..0000000000
--- a/libs/openzap/src/libteletone_generate.c
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- * libteletone_generate.c -- Tone Generator
- *
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include
-
-#define SMAX 32767
-#define SMIN -32768
-#define normalize_to_16bit(n) if (n > SMAX) n = SMAX; else if (n < SMIN) n = SMIN;
-
-#ifdef _MSC_VER
-#pragma warning(disable:4706)
-#endif
-
-TELETONE_API_DATA int16_t TELETONE_SINES[SINE_TABLE_MAX] = {
- 0x00c9, 0x025b, 0x03ed, 0x057f, 0x0711, 0x08a2, 0x0a33, 0x0bc4,
- 0x0d54, 0x0ee4, 0x1073, 0x1201, 0x138f, 0x151c, 0x16a8, 0x1833,
- 0x19be, 0x1b47, 0x1cd0, 0x1e57, 0x1fdd, 0x2162, 0x22e5, 0x2467,
- 0x25e8, 0x2768, 0x28e5, 0x2a62, 0x2bdc, 0x2d55, 0x2ecc, 0x3042,
- 0x31b5, 0x3327, 0x3497, 0x3604, 0x3770, 0x38d9, 0x3a40, 0x3ba5,
- 0x3d08, 0x3e68, 0x3fc6, 0x4121, 0x427a, 0x43d1, 0x4524, 0x4675,
- 0x47c4, 0x490f, 0x4a58, 0x4b9e, 0x4ce1, 0x4e21, 0x4f5e, 0x5098,
- 0x51cf, 0x5303, 0x5433, 0x5560, 0x568a, 0x57b1, 0x58d4, 0x59f4,
- 0x5b10, 0x5c29, 0x5d3e, 0x5e50, 0x5f5e, 0x6068, 0x616f, 0x6272,
- 0x6371, 0x646c, 0x6564, 0x6657, 0x6747, 0x6832, 0x691a, 0x69fd,
- 0x6add, 0x6bb8, 0x6c8f, 0x6d62, 0x6e31, 0x6efb, 0x6fc2, 0x7083,
- 0x7141, 0x71fa, 0x72af, 0x735f, 0x740b, 0x74b3, 0x7556, 0x75f4,
- 0x768e, 0x7723, 0x77b4, 0x7840, 0x78c8, 0x794a, 0x79c9, 0x7a42,
- 0x7ab7, 0x7b27, 0x7b92, 0x7bf9, 0x7c5a, 0x7cb7, 0x7d0f, 0x7d63,
- 0x7db1, 0x7dfb, 0x7e3f, 0x7e7f, 0x7eba, 0x7ef0, 0x7f22, 0x7f4e,
- 0x7f75, 0x7f98, 0x7fb5, 0x7fce, 0x7fe2, 0x7ff1, 0x7ffa, 0x7fff
-};
-
-
-TELETONE_API(int) teletone_set_tone(teletone_generation_session_t *ts, int index, ...)
-{
- va_list ap;
- int i = 0;
- teletone_process_t x = 0;
-
- va_start(ap, index);
- while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) {
- ts->TONES[index].freqs[i++] = x;
- }
- va_end(ap);
-
- return (i > TELETONE_MAX_TONES) ? -1 : 0;
-
-}
-
-TELETONE_API(int) teletone_set_map(teletone_tone_map_t *map, ...)
-{
- va_list ap;
- int i = 0;
- teletone_process_t x = 0;
-
- va_start(ap, map);
- while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) {
- map->freqs[i++] = x;
- }
- va_end(ap);
-
- return (i > TELETONE_MAX_TONES) ? -1 : 0;
-
-}
-
-TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data)
-{
- memset(ts, 0, sizeof(*ts));
- ts->rate = 8000;
- ts->channels = 1;
- ts->duration = 2000;
- ts->wait = 500;
- ts->tmp_duration = -1;
- ts->tmp_wait = -1;
- ts->handler = handler;
- ts->user_data = user_data;
- ts->volume = -7;
- ts->decay_step = 0;
- ts->decay_factor = 1;
- if (buflen) {
- if ((ts->buffer = calloc(buflen, sizeof(teletone_audio_t))) == 0) {
- return -1;
- }
- ts->datalen = buflen;
- } else {
- ts->dynamic = 1024;
- }
- /* Add Standard DTMF Tones */
- teletone_set_tone(ts, '1', 697.0, 1209.0, 0.0);
- teletone_set_tone(ts, '2', 697.0, 1336.0, 0.0);
- teletone_set_tone(ts, '3', 697.0, 1477.0, 0.0);
- teletone_set_tone(ts, 'A', 697.0, 1633.0, 0.0);
- teletone_set_tone(ts, '4', 770.0, 1209.0, 0.0);
- teletone_set_tone(ts, '5', 770.0, 1336.0, 0.0);
- teletone_set_tone(ts, '6', 770.0, 1477.0, 0.0);
- teletone_set_tone(ts, 'B', 770.0, 1633.0, 0.0);
- teletone_set_tone(ts, '7', 859.0, 1209.0, 0.0);
- teletone_set_tone(ts, '8', 859.0, 1336.0, 0.0);
- teletone_set_tone(ts, '9', 859.0, 1477.0, 0.0);
- teletone_set_tone(ts, 'C', 859.0, 1633.0, 0.0);
- teletone_set_tone(ts, '*', 941.0, 1209.0, 0.0);
- teletone_set_tone(ts, '0', 941.0, 1336.0, 0.0);
- teletone_set_tone(ts, '#', 941.0, 1477.0, 0.0);
- teletone_set_tone(ts, 'D', 941.0, 1633.0, 0.0);
-
- return 0;
-}
-
-TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts)
-{
- if (ts->buffer) {
- free(ts->buffer);
- ts->buffer = NULL;
- ts->samples = 0;
- }
- return 0;
-}
-
-static int ensure_buffer(teletone_generation_session_t *ts, int need)
-{
- need += ts->samples;
- need *= sizeof(teletone_audio_t);
- need *= ts->channels;
-
- if (need > ts->datalen) {
- teletone_audio_t *tmp;
- ts->datalen = need + ts->dynamic;
- tmp = realloc(ts->buffer, ts->datalen);
- if (!tmp) {
- return -1;
- }
- ts->buffer = tmp;
- }
-
- return 0;
-}
-
-TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map)
-{
- /*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/
- int i, c;
- int freqlen = 0;
- teletone_dds_state_t tones[TELETONE_MAX_TONES+1];
- //int decay = 0;
- int duration;
- int wait = 0;
- int32_t sample;
- int32_t dc = 0;
- float vol = ts->volume;
- ts->samples = 0;
- memset(tones, 0, sizeof(tones[0]) * TELETONE_MAX_TONES);
- duration = (ts->tmp_duration > -1) ? ts->tmp_duration : ts->duration;
- wait = (ts->tmp_wait > -1) ? ts->tmp_wait : ts->wait;
-
- if (map->freqs[0] > 0) {
- for (freqlen = 0; freqlen < TELETONE_MAX_TONES && map->freqs[freqlen]; freqlen++) {
- teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, 0);
- teletone_dds_state_set_tx_level(&tones[freqlen], vol);
- }
-
- if (ts->channels > 1) {
- duration *= ts->channels;
- }
-
- if (ts->dynamic) {
- if (ensure_buffer(ts, duration)) {
- return -1;
- }
- }
-
- for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) {
- if (ts->decay_direction && ++dc >= ts->decay_step) {
- float nvol = vol + ts->decay_direction * ts->decay_factor;
- int j;
-
- if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) {
- vol = nvol;
- for (j = 0; j < TELETONE_MAX_TONES && map->freqs[j]; j++) {
- teletone_dds_state_set_tx_level(&tones[j], vol);
- }
- dc = 0;
- }
- }
-
- sample = 128;
-
- for (i = 0; i < freqlen; i++) {
- int32_t s = teletone_dds_state_modulate_sample(&tones[i], 0);
- sample += s;
- }
- sample /= freqlen;
- ts->buffer[ts->samples] = (teletone_audio_t)sample;
-
- for (c = 1; c < ts->channels; c++) {
- ts->buffer[ts->samples+1] = ts->buffer[ts->samples];
- ts->samples++;
- }
-
- }
- }
- if (ts->dynamic) {
- if (ensure_buffer(ts, wait)) {
- return -1;
- }
- }
- for (c = 0; c < ts->channels; c++) {
- for (i = 0; i < wait && ts->samples < ts->datalen; i++) {
- ts->buffer[ts->samples++] = 0;
- }
- }
-
- if (ts->debug && ts->debug_stream) {
- if (map->freqs[0] <= 0) {
- fprintf(ts->debug_stream, "wait %d (%dms)\n", wait, wait / (ts->rate / 1000));
- } else {
- fprintf(ts->debug_stream, "Generate: (");
-
- for (i = 0; i < TELETONE_MAX_TONES && map->freqs[i]; i++) {
- fprintf(ts->debug_stream, "%s%0.2f", i == 0 ? "" : "+",map->freqs[i]);
- }
-
- fprintf(ts->debug_stream,
- ") [volume %0.2fdB; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %0.2fdB; decay_step %d(%dms); wrote %d bytes]\n",
- ts->volume,
- duration,
- duration / (ts->rate / 1000),
- ts->channels,
- ts->channels == 1 ? "" : "s",
- wait,
- wait / (ts->rate / 1000),
- ts->decay_factor,
- ts->decay_step,
- ts->decay_step / (ts->rate / 1000),
- ts->samples * 2);
- }
- }
- return ts->samples;
-}
-
-/* don't ask */
-static char *my_strdup (const char *s)
-{
- size_t len = strlen (s) + 1;
- void *new = malloc (len);
-
- if (new == NULL) {
- return NULL;
- }
-
- return (char *) memcpy (new, s, len);
-}
-
-TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cmd)
-{
- char *data = NULL, *cur = NULL, *end = NULL;
- int var = 0, LOOPING = 0;
-
- if (!cmd) {
- return -1;
- }
-
- do {
- if (!(data = my_strdup(cmd))) {
- return -1;
- }
-
- cur = data;
-
- while (*cur) {
- var = 0;
- if (*cur == ' ' || *cur == '\r' || *cur == '\n') {
- cur++;
- continue;
- }
-
- if ((end = strchr(cur, ';')) != 0) {
- *end++ = '\0';
- }
-
- if (*(cur + 1) == '=') {
- var = 1;
- switch(*cur) {
- case 'c':
- ts->channels = atoi(cur + 2);
- break;
- case 'r':
- ts->rate = atoi(cur + 2);
- break;
- case 'd':
- ts->duration = atoi(cur + 2) * (ts->rate / 1000);
- break;
- case 'v':
- {
- float vol = (float)atof(cur + 2);
- if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) {
- ts->volume = vol;
- }
- }
- break;
- case '>':
- ts->decay_step = atoi(cur + 2) * (ts->rate / 1000);
- ts->decay_direction = -1;
- break;
- case '<':
- ts->decay_step = atoi(cur + 2) * (ts->rate / 1000);
- ts->decay_direction = 1;
- break;
- case '+':
- ts->decay_factor = (float)atof(cur + 2);
- break;
- case 'w':
- ts->wait = atoi(cur + 2) * (ts->rate / 1000);
- break;
- case 'l':
- ts->loops = atoi(cur + 2);
- break;
- case 'L':
- if (!LOOPING) {
- ts->LOOPS = atoi(cur + 2);
- }
- LOOPING++;
- break;
- }
- } else {
- while (*cur) {
- char *p = NULL, *e = NULL;
- teletone_tone_map_t mymap, *mapp = NULL;
-
- if (*cur == ' ' || *cur == '\r' || *cur == '\n') {
- cur++;
- continue;
- }
-
- ts->tmp_duration = -1;
- ts->tmp_wait = -1;
-
- memset(&mymap, 0, sizeof(mymap));
-
- if (*(cur + 1) == '(') {
- p = cur + 2;
- if (*cur) {
- char *next;
- int i = 0;
- if ((e = strchr(p, ')')) != 0) {
- *e++ = '\0';
- }
- do {
- if ((next = strchr(p, ',')) != 0) {
- *next++ = '\0';
- }
- if (i == 0) {
- ts->tmp_duration = atoi(p) * (ts->rate / 1000);
- i++;
- } else if (i == 1) {
- ts->tmp_wait = atoi(p) * (ts->rate / 1000);
- i++;
- } else {
- mymap.freqs[i++ - 2] = atof(p);
- }
- p = next;
-
- } while (next && (i-2) < TELETONE_MAX_TONES);
- if (i > 2 && *cur == '%') {
- mapp = &mymap;
- } else if ((i != 2 || *cur == '%')) {
- if (ts->debug && ts->debug_stream) {
- fprintf(ts->debug_stream, "Syntax Error!\n");
- }
- goto bottom;
- }
- }
- }
-
- if (*cur && !mapp) {
- if (*cur > 0 && *cur < TELETONE_TONE_RANGE) {
- mapp = &ts->TONES[(int)*cur];
- } else if (ts->debug && ts->debug_stream) {
- fprintf(ts->debug_stream, "Map [%c] Out Of Range!\n", *cur);
- }
- }
-
- if (mapp) {
- if (mapp->freqs[0]) {
- if (ts->handler) {
- do {
- ts->handler(ts, mapp);
- if (ts->loops > 0) {
- ts->loops--;
- }
- } while (ts->loops);
- }
- } else if (ts->debug && ts->debug_stream) {
- fprintf(ts->debug_stream, "Ignoring Empty Map [%c]!\n", *cur);
- }
- }
-
- if (e) {
- cur = e;
- } else {
- cur++;
- }
- }
- }
-
- if (end) {
- cur = end;
- } else if (*cur){
- cur++;
- }
- }
- bottom:
- free(data);
- data = NULL;
- if (ts->LOOPS > 0) {
- ts->LOOPS--;
- }
-
- } while (ts->LOOPS);
-
- return 0;
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/m3ua/mstm3ua.c b/libs/openzap/src/m3ua/mstm3ua.c
deleted file mode 100644
index 1d8179c58d..0000000000
--- a/libs/openzap/src/m3ua/mstm3ua.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* WARNING WORK IN PROGRESS
- * mstm3ua.c
- * mstss7d port
- *
- * Created by Shane Burrell on 2/2/08.
- * Copyright 2008 Shane Burrell. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "mstm3ua.h"
-
-
-
-
-
-int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg)
-
-{
-
- *bytemsg++ = M_VERSION_REL1; // 1 Verison
- //bytemsg[1] = 0x00; // 2 RESERVED
- //bytemsg[2] = M_CLASS_XFER; // 3 Msg Class
- //SS7 BOX Kludge
- *bytemsg++ = 0x01; // 2 RESERVED
- *bytemsg++ = 0x00; // 2 RESERVED
-
- *bytemsg++ = M_TYPE_DATA ; // 4 Msg Type
-
- *bytemsg++ = len; // 5 Msg LENGTH 81 32bit field
- *bytemsg++ = 0x00; // 6
- *bytemsg++ = 0x00; // 7
- *bytemsg++ = 0x00; // 8
- return(0);
-
-};
\ No newline at end of file
diff --git a/libs/openzap/src/m3ua/mstm3ua.h b/libs/openzap/src/m3ua/mstm3ua.h
deleted file mode 100644
index 13527dac35..0000000000
--- a/libs/openzap/src/m3ua/mstm3ua.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * mstm3ua.h
- * mstss7d
- *
- * Created by Shane Burrell on 3/2/08.
- * Copyright 2008 Shane Burrell. All rights reserved.
- *
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-typedef unsigned long m3ua_ulong;
-typedef unsigned short m3ua_ushort;
-typedef unsigned char m3ua_uchar;
-
-typedef unsigned char u8;
-typedef unsigned short u16; /* Note: multi-byte values are little-endian */
-typedef unsigned long u32;
-
-
-
-
-#define M_TAG_NETWORK_APPEARANCE 1
-#define M_TAG_PROTOCOL_DATA 3
-#define M_TAG_INFO_STRING 4
-#define M_TAG_AFFECTED_DPC 5
-#define M_TAG_ROUTING_CONTEXT 6
-#define M_TAG_DIAGNOSTIC_INFORMATION 7
-#define M_TAG_HEARTBEAT_DATA 8
-#define M_TAG_UNAVAILABILITY_CAUSE 9
-#define M_TAG_REASON 10
-#define M_TAG_TRAFFIC_MODE_TYPE 11
-#define M_TAG_ERROR_CODE 12
-#define M_TAG_STATUS_TYPE 13
-#define M_TAG_CONGESTED_INDICATIONS 14
-
-#define M_VERSION_REL1 1
-
-#define M_CLASS_MGMT 0x00
-#define M_CLASS_XFER 0x01
-#define M_CLASS_SSNM 0x02
-#define M_CLASS_ASPSM 0x03
-#define M_CLASS_ASPTM 0x04
-#define M_CLASS_RKM 0x09
-
-#define M_TYPE_ERR (0|M_CLASS_MGMT
-
-#define M_TYPE_NTFY (1|M_CLASS_XFER)
-#define M_TYPE_DATA (1|M_CLASS_XFER)
-
-#define M_TYPE_DUNA (1|M_CLASS_SSNM)
-#define M_TYPE_DAVA (2|M_CLASS_SSNM)
-#define M_TYPE_DUAD (3|M_CLASS_SSNM)
-#define M_TYPE_SCON (4|M_CLASS_SSNM)
-#define M_TYPE_DUPU (5|M_CLASS_SSNM)
-
-#define M_TYPE_UP (1|M_CLASS_ASPSM)
-#define M_TYPE_DOWN (2|M_CLASS_ASPSM)
-#define M_TYPE_BEAT (3|M_CLASS_ASPSM)
-#define M_TYPE_UP_ACK (4|M_CLASS_ASPSM)
-#define M_TYPE_DOWN_ACK (5|M_CLASS_ASPSM)
-#define M_TYPE_BEAT_ACK (6|M_CLASS_ASPSM)
-
-#define M_TYPE_ACTIVE (1|M_CLASS_ASPTM)
-#define M_TYPE_INACTIVE (2|M_CLASS_ASPTM)
-#define M_TYPE_ACTIVE_ACK (3|M_CLASS_ASPTM)
-#define M_TYPE_INACTIVE_ACK (4|M_CLASS_ASPTM)
-
-#define M_CLASS_MASK 0xff00
-#define M_TYPE_MASK 0x00ff
-
diff --git a/libs/openzap/src/m3ua_client.c b/libs/openzap/src/m3ua_client.c
deleted file mode 100644
index ff1369c188..0000000000
--- a/libs/openzap/src/m3ua_client.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * m3ua_client.c
- * openzap
- *
- * Created by Shane Burrell on 4/3/08.
- * Copyright 2008 Shane Burrell. All rights reserved.
- *
- *
- * Copyright (c) 2007, Anthony Minessale II, Nenad Corbic
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#if HAVE_NETDB_H
-#include
-#endif
-
-#include "openzap.h"
-#include
-
-
-#ifndef HAVE_GETHOSTBYNAME_R
-extern int gethostbyname_r (const char *__name,
- struct hostent *__result_buf,
- char *__buf, size_t __buflen,
- struct hostent **__result,
- int *__h_errnop);
-#endif
-
-struct m3uac_map {
- uint32_t event_id;
- const char *name;
-};
-
-static struct m3uac_map m3uac_table[] = {
- {M3UA_EVENT_CALL_START, "CALL_START"},
- {M3UA_EVENT_CALL_START_ACK, "CALL_START_ACK"},
- {M3UA_EVENT_CALL_START_NACK, "CALL_START_NACK"},
- {M3UA_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"},
- {M3UA_EVENT_CALL_ANSWERED, "CALL_ANSWERED"},
- {M3UA_EVENT_CALL_STOPPED, "CALL_STOPPED"},
- {M3UA_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"},
- {M3UA_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"},
- {M3UA_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"},
- {M3UA_EVENT_HEARTBEAT, "HEARTBEAT"},
- {M3UA_EVENT_INSERT_CHECK_LOOP, "LOOP START"},
- {M3UA_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"}
-};
-
-
-
-static int create_conn_socket(m3uac_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
-{
- int rc;
- struct hostent *result, *local_result;
- char buf[512], local_buf[512];
- int err = 0;
-
- memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp));
- memset(&mcon->local_hp, 0, sizeof(mcon->local_hp));
- mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
-
- zap_log(ZAP_LOG_DEBUG, "Creating L=%s:%d R=%s:%d\n",
- local_ip,local_port,ip,port);
-
- if (mcon->socket >= 0) {
- int flag;
-
- flag = 1;
- gethostbyname_r(ip, &mcon->remote_hp, buf, sizeof(buf), &result, &err);
- gethostbyname_r(local_ip, &mcon->local_hp, local_buf, sizeof(local_buf), &local_result, &err);
- if (result && local_result) {
- mcon->remote_addr.sin_family = mcon->remote_hp.h_addrtype;
- memcpy((char *) &mcon->remote_addr.sin_addr.s_addr, mcon->remote_hp.h_addr_list[0], mcon->remote_hp.h_length);
- mcon->remote_addr.sin_port = htons(port);
-
- mcon->local_addr.sin_family = mcon->local_hp.h_addrtype;
- memcpy((char *) &mcon->local_addr.sin_addr.s_addr, mcon->local_hp.h_addr_list[0], mcon->local_hp.h_length);
- mcon->local_addr.sin_port = htons(local_port);
-
-
- setsockopt(mcon->socket, IPPROTO_SCTP, SCTP_NODELAY, (char *)&flag, sizeof(int));
-
- rc=listen(mcon->socket,100);
- if (rc) {
- close(mcon->socket);
- mcon->socket = -1;
-
- }
- }
- }
-
- zap_mutex_create(&mcon->mutex);
-
- return mcon->socket;
-}
-
-int m3uac_connection_close(m3uac_connection_t *mcon)
-{
- if (mcon->socket > -1) {
- close(mcon->socket);
- }
-
- zap_mutex_lock(mcon->mutex);
- zap_mutex_unlock(mcon->mutex);
- zap_mutex_destroy(&mcon->mutex);
- memset(mcon, 0, sizeof(*mcon));
- mcon->socket = -1;
-
- return 0;
-}
-
-int m3uac_connection_open(m3uac_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
-{
- create_conn_socket(mcon, local_ip, local_port, ip, port);
- return mcon->socket;
-}
-
-
-int m3uac_exec_command(m3uac_connection_t *mcon, int span, int chan, int id, int cmd, int cause)
-{
- m3uac_event_t oevent;
- int retry = 5;
-
- m3uac_event_init(&oevent, cmd, chan, span);
- oevent.release_cause = cause;
-
- if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART) {
- mcon->rxseq_reset = 1;
- mcon->txseq = 0;
- mcon->rxseq = 0;
- mcon->txwindow = 0;
- }
-
- if (id >= 0) {
- oevent.call_setup_id = id;
- }
-
- while (m3uac_connection_write(mcon, &oevent) <= 0) {
- if (--retry <= 0) {
- zap_log(ZAP_LOG_CRIT, "Failed to tx on M3UA socket: %s\n", strerror(errno));
- return -1;
- } else {
- zap_log(ZAP_LOG_WARNING, "Failed to tx on M3UA socket: %s :retry %i\n", strerror(errno), retry);
- zap_sleep(1);
- }
- }
-
- return 0;
-}
-
-
-
-m3uac_event_t *m3uac_connection_read(m3uac_connection_t *mcon, int iteration)
-{
- unsigned int fromlen = sizeof(struct sockaddr_in);
- int bytes = 0;
-
- bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT,
- (struct sockaddr *) &mcon->local_addr, &fromlen);
-
- if (bytes == sizeof(mcon->event) || bytes == (sizeof(mcon->event)-sizeof(uint32_t))) {
-
- if (mcon->rxseq_reset) {
- if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) {
- zap_log(ZAP_LOG_DEBUG, "Rx sync ok\n");
- mcon->rxseq = mcon->event.fseqno;
- return &mcon->event;
- }
- errno=EAGAIN;
- zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n");
- return NULL;
- }
-
- mcon->txwindow = mcon->txseq - mcon->event.bseqno;
- mcon->rxseq++;
-
- if (mcon->rxseq != mcon->event.fseqno) {
- zap_log(ZAP_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno);
- return NULL;
- }
-
- return &mcon->event;
- } else {
- if (iteration == 0) {
- zap_log(ZAP_LOG_CRIT, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
- return NULL;
- }
- }
-
- return NULL;
-}
-
-m3uac_event_t *m3uac_connection_readp(m3uac_connection_t *mcon, int iteration)
-{
- unsigned int fromlen = sizeof(struct sockaddr_in);
- int bytes = 0;
-
- bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen);
-
- if (bytes == sizeof(mcon->event) || bytes == (sizeof(mcon->event)-sizeof(uint32_t))) {
- return &mcon->event;
- } else {
- if (iteration == 0) {
- zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
- return NULL;
- }
- }
-
- return NULL;
-}
-
-
-int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_event_t *event)
-{
- int err;
-
- if (!event || mcon->socket < 0 || !mcon->mutex) {
- zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n");
- return -EINVAL;
- }
-
- if (event->span > 16 || event->chan > 31) {
- zap_log(ZAP_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", m3uac_event_id_name(event->event_id), event->span,event->chan);
- return -1;
- }
-
- gettimeofday(&event->tv,NULL);
-
- zap_mutex_lock(mcon->mutex);
- event->fseqno = mcon->txseq++;
- event->bseqno = mcon->rxseq;
- err = sendto(mcon->socket, event, sizeof(m3uac_event_t), 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr));
- zap_mutex_unlock(mcon->mutex);
-
- if (err != sizeof(m3uac_event_t)) {
- err = -1;
- }
-
- zap_log(ZAP_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n",
- m3uac_event_id_name(event->event_id),
- event->event_id,
- event->span+1,
- event->chan+1,
- event->release_cause,
- event->call_setup_id,
- event->fseqno,
- (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"),
- (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A")
- );
-
- return err;
-}
-
-void m3uac_call_init(m3uac_event_t *event, const char *calling, const char *called, int setup_id)
-{
- memset(event, 0, sizeof(m3uac_event_t));
- event->event_id = M3UA_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;
-
-}
-
-void m3uac_event_init(m3uac_event_t *event, m3uac_event_id_t event_id, int chan, int span)
-{
- memset(event, 0, sizeof(ss7bc_event_t));
- event->event_id = event_id;
- event->chan = chan;
- event->span = span;
-}
-
-const char *m3uac_event_id_name(uint32_t event_id)
-{
- unsigned int x;
- const char *ret = NULL;
-
- for (x = 0 ; x < sizeof(m3uac_table)/sizeof(struct m3uac_map); x++) {
- if (m3uac_table[x].event_id == event_id) {
- ret = m3uac_table[x].name;
- break;
- }
- }
-
- return ret;
-}
-
-/* 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 noet:
- */
-
-
diff --git a/libs/openzap/src/m3ua_client.h b/libs/openzap/src/m3ua_client.h
deleted file mode 100644
index c8b62b0a35..0000000000
--- a/libs/openzap/src/m3ua_client.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * m3ua_client.h
- * openzap
- *
- * Created by Shane Burrell on 4/3/08.
- * Copyright 2008 Shane Burrell. All rights reserved.
- *
- * Copyright (c) 2007-2014, Anthony Minessale II, Nenad Corbic
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-// Fix this for portability
-#include
-//#include
-#include
-#include
-#include
-//#include
-#include
-
-#define MAX_DIALED_DIGITS 31
-#define MAX_CALLING_NAME 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 */
-#define SIZE_RDNIS 80
-
-//#undef MSGWINDOW
-#define MSGWINDOW
-
-
-typedef struct
-{
- uint32_t event_id;
- uint32_t fseqno;
-#ifdef MSGWINDOW
- uint32_t bseqno;
-#endif
- uint16_t call_setup_id;
- uint32_t trunk_group;
- uint32_t span;
- uint32_t chan;
- uint8_t called_number_digits_count;
- char called_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
- uint8_t calling_number_digits_count; /* it's an array */
- char calling_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
- uint8_t release_cause;
- struct timeval tv;
- /* ref. Q.931 Table 4-11 and Q.951 Section 3 */
- uint8_t calling_number_screening_ind;
- uint8_t calling_number_presentation;
- char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */
-
-} t_m3ua;
-
-typedef t_m3ua m3uac_event_t;
-typedef uint32_t m3uac_event_id_t;
-
-
-typedef struct m3uac_ip_cfg
-{
- char local_ip[25];
- int local_port;
- char remote_ip[25];
- int remote_port;
-}m3uac_ip_cfg_t;
-
-struct m3uac_connection {
- zap_socket_t socket;
- struct sockaddr_in local_addr;
- struct sockaddr_in remote_addr;
- m3uac_event_t event;
- struct hostent remote_hp;
- struct hostent local_hp;
- unsigned int flags;
- zap_mutex_t *mutex;
- FILE *log;
- unsigned int txseq;
- unsigned int rxseq;
- unsigned int txwindow;
- unsigned int rxseq_reset;
- m3uac_ip_cfg_t cfg;
- uint32_t hb_elapsed;
- int up;
-};
-
-typedef enum {
- MSU_FLAG_EVENT = (1 << 0)
-} m3uac_flag_t;
-
-typedef struct m3uac_connection m3uac_connection_t;
-
-static inline void sctp_no_nagle(int socket)
-{
- //int flag = 1;
- //setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int));
-}
-
-int m3uac_connection_close(m3uac_connection_t *mcon);
-int m3uac_connection_open(m3uac_connection_t *mcon, char *local_ip, int local_port, char *ip, int port);
-m3uac_event_t *m3uac_connection_read(m3uac_connection_t *mcon, int iteration);
-m3uac_event_t *m3uac_connection_readp(m3uac_connection_t *mcon, int iteration);
-int m3uac_connection_write(m3uac_connection_t *mcon, m3uac_event_t *event);
-void m3uac_event_init(m3uac_event_t *event, m3uac_event_id_t event_id, int chan, int span);
-void m3uac_call_init(m3uac_event_t *event, const char *calling, const char *called, int setup_id);
-const char *m3uac_event_id_name(uint32_t event_id);
-int m3uac_exec_command(m3uac_connection_t *mcon, int span, int chan, int id, int cmd, int cause);
-
-
-
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj
deleted file mode 100644
index 964393805c..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj
+++ /dev/null
@@ -1,202 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj
deleted file mode 100644
index da21d1f48f..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj
+++ /dev/null
@@ -1,353 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c
deleted file mode 100644
index 9c72b9e3eb..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c
+++ /dev/null
@@ -1,1026 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "openzap.h"
-#include "zap_analog.h"
-
-#ifndef localtime_r
-struct tm * localtime_r(const time_t *clock, struct tm *result);
-#endif
-
-static void *zap_analog_channel_run(zap_thread_t *me, void *obj);
-
-/**
- * \brief Starts an FXO channel thread (outgoing call)
- * \param zchan Channel to initiate call on
- * \return Success or failure
- *
- * Initialises state, starts tone progress detection and runs the channel in a new a thread.
- */
-static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call)
-{
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
- zap_channel_clear_needed_tones(zchan);
- zap_channel_clear_detected_tones(zchan);
-
- zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
- zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL);
- zchan->needed_tones[ZAP_TONEMAP_DIAL] = 1;
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING);
- zap_thread_create_detached(zap_analog_channel_run, zchan);
- return ZAP_SUCCESS;
- }
-
- return ZAP_FAIL;
-}
-
-/**
- * \brief Starts an FXS channel thread (outgoing call)
- * \param zchan Channel to initiate call on
- * \return Success or failure
- *
- * Indicates call waiting if channel is already in use, otherwise runs the channel in a new thread.
- */
-static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call)
-{
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CALLWAITING);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_GENRING);
- zap_thread_create_detached(zap_analog_channel_run, zchan);
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Starts an analog span thread (monitor)
- * \param span Span to monitor
- * \return Success or failure
- */
-static zap_status_t zap_analog_start(zap_span_t *span)
-{
- zap_analog_data_t *analog_data = span->signal_data;
- zap_set_flag(analog_data, ZAP_ANALOG_RUNNING);
- return zap_thread_create_detached(zap_analog_run, span);
-}
-
-/**
- * \brief Initialises an analog span from configuration variables
- * \param span Span to configure
- * \param sig_cb Callback function for event signals
- * \param ap List of configuration variables
- * \return Success or failure
- */
-static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span)
-//zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
-{
- zap_analog_data_t *analog_data;
- const char *tonemap = "us";
- const char *hotline = "";
- uint32_t digit_timeout = 10;
- uint32_t max_dialstr = MAX_DTMF;
- const char *var, *val;
- int *intval;
- uint32_t flags = ZAP_ANALOG_CALLERID;
- int callwaiting = 1;
- unsigned i = 0;
-
- assert(sig_cb != NULL);
-
- if (span->signal_type) {
- snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling.");
- return ZAP_FAIL;
- }
-
- analog_data = malloc(sizeof(*analog_data));
- assert(analog_data != NULL);
- memset(analog_data, 0, sizeof(*analog_data));
-
- while ((var = va_arg(ap, char *))) {
- if (!strcasecmp(var, "tonemap")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- tonemap = val;
- } else if (!strcasecmp(var, "digit_timeout")) {
- if (!(intval = va_arg(ap, int *))) {
- break;
- }
- digit_timeout = *intval;
- } else if (!strcasecmp(var, "enable_callerid")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
-
- if (zap_true(val)) {
- flags |= ZAP_ANALOG_CALLERID;
- } else {
- flags &= ~ZAP_ANALOG_CALLERID;
- }
- } else if (!strcasecmp(var, "max_dialstr")) {
- if (!(intval = va_arg(ap, int *))) {
- break;
- }
- max_dialstr = *intval;
- } else if (!strcasecmp(var, "hotline")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- hotline = val;
- } else if (!strcasecmp(var, "callwaiting")) {
- if (!(intval = va_arg(ap, int *))) {
- break;
- }
- callwaiting = *intval;
- } else {
- snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
- return ZAP_FAIL;
- }
- }
-
-
- if (digit_timeout < 2000 || digit_timeout > 10000) {
- digit_timeout = 2000;
- }
-
- if ((max_dialstr < 1 && !strlen(hotline)) || max_dialstr > MAX_DTMF) {
- max_dialstr = MAX_DTMF;
- }
-
- if (callwaiting) {
- for (i = 1; i <= span->chan_count; i++) {
- zap_log(ZAP_LOG_DEBUG, "Enabling call waiting for channel %d:%d\n", span->channels[i]->span_id, span->channels[i]->chan_id);
- zap_channel_set_feature(span->channels[i], ZAP_CHANNEL_FEATURE_CALLWAITING);
- }
- }
-
- span->start = zap_analog_start;
- analog_data->flags = flags;
- analog_data->digit_timeout = digit_timeout;
- analog_data->max_dialstr = max_dialstr;
- span->signal_cb = sig_cb;
- strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline));
- span->signal_type = ZAP_SIGTYPE_ANALOG;
- span->signal_data = analog_data;
- span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call;
- zap_span_load_tones(span, tonemap);
-
- return ZAP_SUCCESS;
-
-}
-
-/**
- * \brief Retrieves tone generation output to be sent
- * \param ts Teletone generator
- * \param map Tone map
- * \return -1 on error, 0 on success
- */
-static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
-{
- zap_buffer_t *dt_buffer = ts->user_data;
- int wrote;
-
- if (!dt_buffer) {
- return -1;
- }
- wrote = teletone_mux_tones(ts, map);
- zap_buffer_write(dt_buffer, ts->buffer, wrote * 2);
- return 0;
-}
-
-/**
- * \brief Sends caller id on an analog channel (FSK coded)
- * \param zchan Channel to send caller id on
- */
-static void send_caller_id(zap_channel_t *zchan)
-{
- zap_fsk_data_state_t fsk_data;
- uint8_t databuf[1024] = "";
- char time_str[9];
- struct tm tm;
- time_t now;
- zap_mdmf_type_t mt = MDMF_INVALID;
-
- time(&now);
-#ifdef WIN32
- _tzset();
- _localtime64_s(&tm, &now);
-#else
- localtime_r(&now, &tm);
-#endif
- strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm);
-
- zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf));
- zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *) time_str, 8);
-
- if (zap_strlen_zero(zchan->caller_data.cid_num.digits)) {
- mt = MDMF_NO_NUM;
- zap_set_string(zchan->caller_data.cid_num.digits, "O");
- } else if (!strcasecmp(zchan->caller_data.cid_num.digits, "P") || !strcasecmp(zchan->caller_data.cid_num.digits, "O")) {
- mt = MDMF_NO_NUM;
- } else {
- mt = MDMF_PHONE_NUM;
- }
- zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_num.digits, (uint8_t)strlen(zchan->caller_data.cid_num.digits));
-
- if (zap_strlen_zero(zchan->caller_data.cid_name)) {
- mt = MDMF_NO_NAME;
- zap_set_string(zchan->caller_data.cid_name, "O");
- } else if (!strcasecmp(zchan->caller_data.cid_name, "P") || !strcasecmp(zchan->caller_data.cid_name, "O")) {
- mt = MDMF_NO_NAME;
- } else {
- mt = MDMF_PHONE_NAME;
- }
- zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_name, (uint8_t)strlen(zchan->caller_data.cid_name));
-
- zap_fsk_data_add_checksum(&fsk_data);
- zap_channel_send_fsk_data(zchan, &fsk_data, -14);
-}
-
-/**
- * \brief Main thread function for analog channel (outgoing call)
- * \param me Current thread
- * \param obj Channel to run in this thread
- */
-static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
-{
- zap_channel_t *zchan = (zap_channel_t *) obj;
- zap_buffer_t *dt_buffer = NULL;
- teletone_generation_session_t ts;
- uint8_t frame[1024];
- zap_size_t len, rlen;
- zap_tone_type_t tt = ZAP_TONE_DTMF;
- char dtmf[MAX_DTMF+1] = "";
- zap_size_t dtmf_offset = 0;
- zap_analog_data_t *analog_data = zchan->span->signal_data;
- zap_channel_t *closed_chan;
- uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000;
- zap_sigmsg_t sig;
- zap_status_t status;
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n");
-
- ts.buffer = NULL;
-
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
- goto done;
- }
-
- if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!");
- zap_log(ZAP_LOG_ERROR, "MEM ERROR\n");
- goto done;
- }
-
- if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!");
- zap_log(ZAP_LOG_ERROR, "TONE ERROR\n");
- goto done;
- }
-
- zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD);
- teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
- ts.rate = 8000;
-#if 0
- ts.debug = 1;
- ts.debug_stream = stdout;
-#endif
- zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval);
- zap_buffer_set_loops(dt_buffer, -1);
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
-
- assert(interval != 0);
-
- while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
- zap_wait_flag_t flags = ZAP_READ;
- zap_size_t dlen = 0;
-
- len = sizeof(frame);
-
- elapsed += interval;
- state_counter += interval;
-
- if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) {
- switch(zchan->state) {
- case ZAP_CHANNEL_STATE_GET_CALLERID:
- {
- if (state_counter > 5000 || !zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) {
- zap_channel_command(zchan, ZAP_COMMAND_DISABLE_CALLERID_DETECT, NULL);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_DIALING:
- {
- if (state_counter > dial_timeout) {
- if (zchan->needed_tones[ZAP_TONEMAP_DIAL]) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_GENRING:
- {
- if (state_counter > 60000) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- } else if (!zchan->fsk_buffer || !zap_buffer_inuse(zchan->fsk_buffer)) {
- zap_sleep(interval);
- continue;
- }
- }
- break;
- case ZAP_CHANNEL_STATE_DIALTONE:
- {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_HOLD) && state_counter > 10000) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_BUSY:
- {
- if (state_counter > 20000) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_ATTN:
- {
- if (state_counter > 20000) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_HANGUP:
- {
- if (state_counter > 500) {
- if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) {
- zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
- }
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) &&
- (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE
- || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING;
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_CALLWAITING:
- {
- int done = 0;
-
- if (zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] == 1) {
- send_caller_id(zchan);
- zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++;
- } else if (state_counter > 600 && !zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) {
- send_caller_id(zchan);
- zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++;
- } else if (state_counter > 1000 && !zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) {
- done = 1;
- } else if (state_counter > 10000) {
- if (zchan->fsk_buffer) {
- zap_buffer_zero(zchan->fsk_buffer);
- } else {
- zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0);
- }
-
- ts.user_data = zchan->fsk_buffer;
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]);
- ts.user_data = dt_buffer;
- done = 1;
- }
-
- if (done) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
- zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
- zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0;
- }
- }
- case ZAP_CHANNEL_STATE_UP:
- case ZAP_CHANNEL_STATE_IDLE:
- {
- zap_sleep(interval);
- continue;
- }
- break;
- case ZAP_CHANNEL_STATE_DOWN:
- {
- goto done;
- }
- break;
- default:
- break;
- }
- } else {
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
- zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
- zap_channel_complete_state(zchan);
- indicate = 0;
- state_counter = 0;
-
- zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n",
- zchan->span_id, zchan->chan_id,
- zap_channel_state2str(zchan->state));
- switch(zchan->state) {
- case ZAP_CHANNEL_STATE_UP:
- {
- zap_channel_use(zchan);
- zap_channel_clear_needed_tones(zchan);
- zap_channel_flush_dtmf(zchan);
-
- if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
- zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
- }
-
- if (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer)) {
- zap_log(ZAP_LOG_DEBUG, "Cancel FSK transmit due to early answer.\n");
- zap_buffer_zero(zchan->fsk_buffer);
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) {
- zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
- }
-
- if (zchan->token_count == 1) {
- zap_clear_flag(zchan, ZAP_CHANNEL_HOLD);
- }
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_HOLD)) {
- zap_clear_flag(zchan, ZAP_CHANNEL_HOLD);
- sig.event_id = ZAP_SIGEVENT_ADD_CALL;
- } else {
- sig.event_id = ZAP_SIGEVENT_UP;
- }
-
- zap_span_send_signal(zchan->span, &sig);
- continue;
- }
- break;
- case ZAP_CHANNEL_STATE_DIALING:
- {
- zap_channel_use(zchan);
- }
- break;
- case ZAP_CHANNEL_STATE_IDLE:
- {
- zap_channel_use(zchan);
- sig.event_id = ZAP_SIGEVENT_START;
-
- if (zchan->type == ZAP_CHAN_TYPE_FXO) {
- zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number);
- } else {
- zap_set_string(zchan->caller_data.dnis.digits, dtmf);
- }
-
- zap_span_send_signal(zchan->span, &sig);
- continue;
- }
- break;
- case ZAP_CHANNEL_STATE_DOWN:
- {
- sig.event_id = ZAP_SIGEVENT_STOP;
- zap_span_send_signal(zchan->span, &sig);
- goto done;
- }
- break;
- case ZAP_CHANNEL_STATE_DIALTONE:
- {
- memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
- *dtmf = '\0';
- dtmf_offset = 0;
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]);
- indicate = 1;
- }
- break;
- case ZAP_CHANNEL_STATE_CALLWAITING:
- {
- zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0;
- if (zchan->fsk_buffer) {
- zap_buffer_zero(zchan->fsk_buffer);
- } else {
- zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0);
- }
-
- ts.user_data = zchan->fsk_buffer;
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_CAS]);
- ts.user_data = dt_buffer;
- }
- break;
- case ZAP_CHANNEL_STATE_GENRING:
- {
- zap_sigmsg_t sig;
-
- send_caller_id(zchan);
- zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_ON, NULL);
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
- sig.event_id = ZAP_SIGEVENT_PROGRESS;
- zap_span_send_signal(zchan->span, &sig);
-
- }
- break;
- case ZAP_CHANNEL_STATE_GET_CALLERID:
- {
- memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
- zap_channel_command(zchan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL);
- continue;
- }
- break;
- case ZAP_CHANNEL_STATE_RING:
- {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]);
- indicate = 1;
-
- }
- break;
- case ZAP_CHANNEL_STATE_BUSY:
- {
- zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION;
- if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]);
- indicate = 1;
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_ATTN:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]);
- indicate = 1;
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- break;
- default:
- break;
- }
- }
-
-
- if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) {
- if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {
-
- if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT);
- collecting = 1;
- }
- dtmf_offset = strlen(dtmf);
- last_digit = elapsed;
- sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT;
- sig.raw_data = dtmf;
- if (zap_span_send_signal(zchan->span, &sig) == ZAP_BREAK) {
- collecting = 0;
- }
- }
- else if(!analog_data->max_dialstr)
- {
- last_digit = elapsed;
- collecting = 0;
- strcpy(dtmf, analog_data->hotline);
- }
- }
-
-
- if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) >= analog_data->max_dialstr))) {
- zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
- last_digit = 0;
- collecting = 0;
- }
-
- if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) {
- continue;
- }
-
- if (!(flags & ZAP_READ)) {
- continue;
- }
-
- if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error);
- goto done;
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_FXO && zchan->detected_tones[0]) {
- zap_sigmsg_t sig;
- int i;
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
- sig.event_id = ZAP_SIGEVENT_TONE_DETECTED;
-
- for (i = 1; i < ZAP_TONEMAP_INVALID; i++) {
- if (zchan->detected_tones[i]) {
- zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id);
- sig.raw_data = &i;
- zap_span_send_signal(zchan->span, &sig);
- }
- }
-
- if (zchan->detected_tones[ZAP_TONEMAP_BUSY] ||
- zchan->detected_tones[ZAP_TONEMAP_FAIL1] ||
- zchan->detected_tones[ZAP_TONEMAP_FAIL2] ||
- zchan->detected_tones[ZAP_TONEMAP_FAIL3] ||
- zchan->detected_tones[ZAP_TONEMAP_ATTN]
- ) {
- zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n");
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else if (zchan->detected_tones[ZAP_TONEMAP_DIAL]) {
- if (zap_strlen_zero(zchan->caller_data.ani.digits)) {
- zap_log(ZAP_LOG_ERROR, "No Digits to send!\n");
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- state_counter = 0;
- zchan->needed_tones[ZAP_TONEMAP_RING] = 1;
- zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1;
- zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1;
- zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1;
- zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1;
- dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000;
- }
- }
- } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
- }
-
- zap_channel_clear_detected_tones(zchan);
- }
-
- if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer)) || (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer))) {
- //rlen = len;
- //memset(frame, 0, len);
- //zap_channel_write(zchan, frame, sizeof(frame), &rlen);
- continue;
- }
-
- if (!indicate) {
- continue;
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
- zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
- }
-
- if (zchan->effective_codec != ZAP_CODEC_SLIN) {
- len *= 2;
- }
-
- rlen = zap_buffer_read_loop(dt_buffer, frame, len);
-
- if (zchan->effective_codec != ZAP_CODEC_SLIN) {
- zio_codec_t codec_func = NULL;
-
- if (zchan->native_codec == ZAP_CODEC_ULAW) {
- codec_func = zio_slin2ulaw;
- } else if (zchan->native_codec == ZAP_CODEC_ALAW) {
- codec_func = zio_slin2alaw;
- }
-
- if (codec_func) {
- status = codec_func(frame, sizeof(frame), &rlen);
- } else {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!");
- goto done;
- }
- }
-
- zap_channel_write(zchan, frame, sizeof(frame), &rlen);
- }
-
- done:
-
-
- if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
- zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL);
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) {
- zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
- }
-
-
- closed_chan = zchan;
- zap_channel_close(&zchan);
-
- zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL);
-
- if (ts.buffer) {
- teletone_destroy_session(&ts);
- }
-
- if (dt_buffer) {
- zap_buffer_destroy(&dt_buffer);
- }
-
- if (closed_chan->state != ZAP_CHANNEL_STATE_DOWN) {
- zap_set_state_locked(closed_chan, ZAP_CHANNEL_STATE_DOWN);
- }
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL %d:%d thread ended.\n", closed_chan->span_id, closed_chan->chan_id);
- zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD);
-
- return NULL;
-}
-
-/**
- * \brief Processes openzap event
- * \param span Span on which the event was fired
- * \param event Event to be treated
- * \return Success or failure
- */
-static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event)
-{
- zap_sigmsg_t sig;
- zap_analog_data_t *analog_data = event->channel->span->signal_data;
- int locked = 0;
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = event->channel->chan_id;
- sig.span_id = event->channel->span_id;
- sig.channel = event->channel;
-
-
- zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n",
- zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state));
-
- zap_mutex_lock(event->channel->mutex);
- locked++;
-
- switch(event->enum_id) {
- case ZAP_OOB_RING_START:
- {
- if (event->channel->type != ZAP_CHAN_TYPE_FXO) {
- zap_log(ZAP_LOG_ERROR, "Cannot get a RING_START event on a non-fxo channel, please check your config.\n");
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
- goto end;
- }
- if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) {
- if (zap_test_flag(analog_data, ZAP_ANALOG_CALLERID)) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID);
- } else {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_IDLE);
- }
- event->channel->ring_count = 1;
- zap_mutex_unlock(event->channel->mutex);
- locked = 0;
- zap_thread_create_detached(zap_analog_channel_run, event->channel);
- } else {
- event->channel->ring_count++;
- }
- }
- break;
- case ZAP_OOB_ONHOOK:
- {
- if (zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) {
- zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
- }
-
- if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
- }
-
- }
- break;
- case ZAP_OOB_FLASH:
- {
- if (event->channel->state == ZAP_CHANNEL_STATE_CALLWAITING) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
- zap_clear_flag_locked(event->channel, ZAP_CHANNEL_STATE_CHANGE);
- zap_clear_flag_locked(event->channel->span, ZAP_SPAN_STATE_CHANGE);
- event->channel->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0;
- }
-
- zap_channel_rotate_tokens(event->channel);
-
- if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD) && event->channel->token_count != 1) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
- } else {
- sig.event_id = ZAP_SIGEVENT_FLASH;
- zap_span_send_signal(span, &sig);
- }
- }
- break;
- case ZAP_OOB_OFFHOOK:
- {
- if (event->channel->type == ZAP_CHAN_TYPE_FXS) {
- if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) {
- if (zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) {
- zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL);
- }
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
- } else {
- if(!analog_data->max_dialstr) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_COLLECT);
- } else {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE);
- }
- zap_mutex_unlock(event->channel->mutex);
- locked = 0;
- zap_thread_create_detached(zap_analog_channel_run, event->channel);
- }
- } else {
- if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) {
- if (zap_test_flag(event->channel, ZAP_CHANNEL_OFFHOOK)) {
- zap_channel_command(event->channel, ZAP_COMMAND_ONHOOK, NULL);
- }
- }
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- case ZAP_OOB_DTMF:
- {
- const char * digit_str = (const char *)event->data;
- if(digit_str) {
- if (event->channel->state == ZAP_CHANNEL_STATE_CALLWAITING && (*digit_str == 'D' || *digit_str == 'A')) {
- event->channel->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++;
- } else {
- zio_event_cb_t event_callback = NULL;
-
- zap_channel_queue_dtmf(event->channel, digit_str);
- if (span->event_callback) {
- event_callback = span->event_callback;
- } else if (event->channel->event_callback) {
- event_callback = event->channel->event_callback;
- }
-
- if (event_callback) {
- event->channel->event_header.channel = event->channel;
- event->channel->event_header.e_type = ZAP_EVENT_DTMF;
- event->channel->event_header.data = (void *)digit_str;
- event_callback(event->channel, &event->channel->event_header);
- event->channel->event_header.e_type = ZAP_EVENT_NONE;
- event->channel->event_header.data = NULL;
- }
-
- }
- zap_safe_free(event->data);
- }
- }
- case ZAP_OOB_ALARM_TRAP:
- {
- zap_set_flag_locked(event->channel, ZAP_CHANNEL_SUSPENDED);
- }
- case ZAP_OOB_ALARM_CLEAR:
- {
- zap_clear_flag_locked(event->channel, ZAP_CHANNEL_SUSPENDED);
- }
- }
-
- end:
-
- if (locked) {
- zap_mutex_unlock(event->channel->mutex);
- }
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Main thread function for analog span (monitor)
- * \param me Current thread
- * \param obj Span to run in this thread
- */
-static void *zap_analog_run(zap_thread_t *me, void *obj)
-{
- zap_span_t *span = (zap_span_t *) obj;
- zap_analog_data_t *analog_data = span->signal_data;
- int errs = 0;
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n");
-
- while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) {
- int waitms = 1000;
- zap_status_t status;
-
- if ((status = zap_span_poll_event(span, waitms)) != ZAP_FAIL) {
- errs = 0;
- }
-
- switch(status) {
- case ZAP_SUCCESS:
- {
- zap_event_t *event;
- while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
- if (event->enum_id == ZAP_OOB_NOOP) {
- continue;
- }
- if (process_event(span, event) != ZAP_SUCCESS) {
- goto end;
- }
- }
- }
- break;
- case ZAP_FAIL:
- {
- zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error);
- if (++errs > 300) {
- zap_log(ZAP_LOG_CRIT, "Too Many Errors!\n");
- goto end;
- }
- }
- break;
- default:
- break;
- }
-
- }
-
- end:
-
- zap_clear_flag(analog_data, ZAP_ANALOG_RUNNING);
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG thread ending.\n");
-
- return NULL;
-}
-
-/**
- * \brief Openzap analog signaling module initialisation
- * \return Success
- */
-static ZIO_SIG_LOAD_FUNCTION(zap_analog_init)
-{
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Openzap analog signaling module definition
- */
-EX_DECLARE_DATA zap_module_t zap_module = {
- "analog",
- NULL,
- NULL,
- zap_analog_init,
- zap_analog_configure_span,
- NULL
-};
-
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h
deleted file mode 100644
index 287441796c..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_ANALOG_H
-#define ZAP_ANALOG_H
-#include "openzap.h"
-
-typedef enum {
- ZAP_ANALOG_RUNNING = (1 << 0),
- ZAP_ANALOG_CALLERID = (1 << 1)
-} zap_analog_flag_t;
-
-#define ZAP_MAX_HOTLINE_STR 20
-#define MAX_DTMF 256
-
-struct zap_analog_data {
- uint32_t flags;
- uint32_t max_dialstr;
- uint32_t digit_timeout;
- char hotline[ZAP_MAX_HOTLINE_STR];
-};
-
-
-
-static void *zap_analog_run(zap_thread_t *me, void *obj);
-typedef struct zap_analog_data zap_analog_data_t;
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj
deleted file mode 100644
index bff0716d4c..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj
+++ /dev/null
@@ -1,202 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj
deleted file mode 100644
index 35a0d89da0..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj
+++ /dev/null
@@ -1,353 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c
deleted file mode 100644
index 6ddf7e2394..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c
+++ /dev/null
@@ -1,707 +0,0 @@
-/*
- * Copyright (c) 2008-2012, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Contributor(s):
- *
- * John Wehle (john@feith.com)
- *
- */
-
-#include "openzap.h"
-#include "zap_analog_em.h"
-
-#ifndef localtime_r
-struct tm * localtime_r(const time_t *clock, struct tm *result);
-#endif
-
-static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj);
-
-/**
- * \brief Starts an EM channel thread (outgoing call)
- * \param zchan Channel to initiate call on
- * \return Success or failure
- *
- * Initialises state, starts tone progress detection and runs the channel in a new a thread.
- */
-static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call)
-{
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
- zap_channel_clear_needed_tones(zchan);
- zap_channel_clear_detected_tones(zchan);
-
- zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
-
- zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
- zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING);
- zap_thread_create_detached(zap_analog_em_channel_run, zchan);
- return ZAP_SUCCESS;
- }
-
- return ZAP_FAIL;
-}
-
-/**
- * \brief Starts an EM span thread (monitor)
- * \param span Span to monitor
- * \return Success or failure
- */
-static zap_status_t zap_analog_em_start(zap_span_t *span)
-{
- zap_analog_em_data_t *analog_data = span->signal_data;
- zap_set_flag(analog_data, ZAP_ANALOG_EM_RUNNING);
- return zap_thread_create_detached(zap_analog_em_run, span);
-}
-
-/**
- * \brief Initialises an EM span from configuration variables
- * \param span Span to configure
- * \param sig_cb Callback function for event signals
- * \param ap List of configuration variables
- * \return Success or failure
- */
-static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span)
-//zap_status_t zap_analog_em_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
-{
- zap_analog_em_data_t *analog_data;
- const char *tonemap = "us";
- uint32_t digit_timeout = 10;
- uint32_t max_dialstr = 11;
- const char *var, *val;
- int *intval;
-
- assert(sig_cb != NULL);
-
- if (span->signal_type) {
- snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling.");
- return ZAP_FAIL;
- }
-
- analog_data = malloc(sizeof(*analog_data));
- assert(analog_data != NULL);
- memset(analog_data, 0, sizeof(*analog_data));
-
- while((var = va_arg(ap, char *))) {
- if (!strcasecmp(var, "tonemap")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- tonemap = val;
- } else if (!strcasecmp(var, "digit_timeout")) {
- if (!(intval = va_arg(ap, int *))) {
- break;
- }
- digit_timeout = *intval;
- } else if (!strcasecmp(var, "max_dialstr")) {
- if (!(intval = va_arg(ap, int *))) {
- break;
- }
- max_dialstr = *intval;
- } else {
- snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
- return ZAP_FAIL;
- }
- }
-
-
- if (digit_timeout < 2000 || digit_timeout > 10000) {
- digit_timeout = 2000;
- }
-
- if (max_dialstr < 2 || max_dialstr > MAX_DIALSTRING) {
- zap_log(ZAP_LOG_ERROR, "Invalid max_dialstr, setting to %d\n", MAX_DIALSTRING);
- max_dialstr = MAX_DIALSTRING;
- }
-
- span->start = zap_analog_em_start;
- analog_data->digit_timeout = digit_timeout;
- analog_data->max_dialstr = max_dialstr;
- span->signal_cb = sig_cb;
- span->signal_type = ZAP_SIGTYPE_ANALOG;
- span->signal_data = analog_data;
- span->outgoing_call = analog_em_outgoing_call;
- zap_span_load_tones(span, tonemap);
-
- return ZAP_SUCCESS;
-
-}
-
-/**
- * \brief Retrieves tone generation output to be sent
- * \param ts Teletone generator
- * \param map Tone map
- * \return -1 on error, 0 on success
- */
-static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
-{
- zap_buffer_t *dt_buffer = ts->user_data;
- int wrote;
-
- if (!dt_buffer) {
- return -1;
- }
- wrote = teletone_mux_tones(ts, map);
- zap_buffer_write(dt_buffer, ts->buffer, wrote * 2);
- return 0;
-}
-
-/**
- * \brief Main thread function for EM channel (outgoing call)
- * \param me Current thread
- * \param obj Channel to run in this thread
- */
-static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj)
-{
- zap_channel_t *zchan = (zap_channel_t *) obj;
- zap_buffer_t *dt_buffer = NULL;
- teletone_generation_session_t ts;
- uint8_t frame[1024];
- zap_size_t len, rlen;
- zap_tone_type_t tt = ZAP_TONE_DTMF;
- char dtmf[128] = "";
- zap_size_t dtmf_offset = 0;
- zap_analog_em_data_t *analog_data = zchan->span->signal_data;
- zap_channel_t *closed_chan;
- uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000;
- zap_sigmsg_t sig;
- zap_status_t status;
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread starting.\n");
-
- ts.buffer = NULL;
-
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
- goto done;
- }
-
- if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!");
- zap_log(ZAP_LOG_ERROR, "MEM ERROR\n");
- goto done;
- }
-
- if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!");
- zap_log(ZAP_LOG_ERROR, "TONE ERROR\n");
- goto done;
- }
-
- zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD);
- teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
- ts.rate = 8000;
-#if 0
- ts.debug = 1;
- ts.debug_stream = stdout;
-#endif
- zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval);
- zap_buffer_set_loops(dt_buffer, -1);
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
-
- assert(interval != 0);
-
- while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
- zap_wait_flag_t flags = ZAP_READ;
- zap_size_t dlen = 0;
-
- len = sizeof(frame);
-
- elapsed += interval;
- state_counter += interval;
-
- if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) {
- switch(zchan->state) {
- case ZAP_CHANNEL_STATE_DIALING:
- {
- if (! zchan->needed_tones[ZAP_TONEMAP_RING]
- && zap_test_flag(zchan, ZAP_CHANNEL_WINK)) {
- if (zap_strlen_zero(zchan->caller_data.ani.digits)) {
- zap_log(ZAP_LOG_ERROR, "No Digits to send!\n");
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- state_counter = 0;
- zchan->needed_tones[ZAP_TONEMAP_RING] = 1;
- zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1;
- zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1;
- zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1;
- zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1;
- dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000;
- }
- }
- break;
- }
- if (state_counter > dial_timeout) {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_WINK)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_DIALTONE:
- {
- if (state_counter > 10000) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_BUSY:
- {
- if (state_counter > 20000) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_ATTN:
- {
- if (state_counter > 20000) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_HANGUP:
- {
- if (state_counter > 500) {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) &&
- (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE
- || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else {
- zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING;
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_UP:
- case ZAP_CHANNEL_STATE_IDLE:
- {
- zap_sleep(interval);
- continue;
- }
- break;
- case ZAP_CHANNEL_STATE_DOWN:
- {
- goto done;
- }
- break;
- default:
- break;
- }
- } else {
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
- zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
- zap_channel_complete_state(zchan);
- indicate = 0;
- state_counter = 0;
-
- zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n",
- zchan->span_id, zchan->chan_id,
- zap_channel_state2str(zchan->state));
- switch(zchan->state) {
- case ZAP_CHANNEL_STATE_UP:
- {
- zap_channel_use(zchan);
- zap_channel_clear_needed_tones(zchan);
- zap_channel_flush_dtmf(zchan);
-
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
- zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
- }
-
- sig.event_id = ZAP_SIGEVENT_UP;
-
- zap_span_send_signal(zchan->span, &sig);
- continue;
- }
- break;
- case ZAP_CHANNEL_STATE_DIALING:
- {
- zap_channel_use(zchan);
- }
- break;
- case ZAP_CHANNEL_STATE_IDLE:
- {
- zap_channel_use(zchan);
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number);
- } else {
- zap_set_string(zchan->caller_data.dnis.digits, dtmf);
- }
-
- sig.event_id = ZAP_SIGEVENT_START;
-
- zap_span_send_signal(zchan->span, &sig);
- continue;
- }
- break;
- case ZAP_CHANNEL_STATE_DOWN:
- {
- sig.event_id = ZAP_SIGEVENT_STOP;
- zap_span_send_signal(zchan->span, &sig);
- goto done;
- }
- break;
- case ZAP_CHANNEL_STATE_DIALTONE:
- {
- memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
- *dtmf = '\0';
- dtmf_offset = 0;
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]);
- indicate = 1;
-
- zap_channel_command(zchan, ZAP_COMMAND_WINK, NULL);
- }
- break;
- case ZAP_CHANNEL_STATE_RING:
- {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]);
- indicate = 1;
- }
- break;
- case ZAP_CHANNEL_STATE_BUSY:
- {
- zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION;
- if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]);
- indicate = 1;
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_ATTN:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]);
- indicate = 1;
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- break;
- default:
- break;
- }
- }
-
-
- if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) {
- if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {
-
- if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT);
- collecting = 1;
- }
- dtmf_offset = strlen(dtmf);
- last_digit = elapsed;
- sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT;
- sig.raw_data = dtmf;
- if (zap_span_send_signal(zchan->span, &sig) == ZAP_BREAK) {
- collecting = 0;
- }
- }
- }
-
-
- if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) {
- zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
- last_digit = 0;
- collecting = 0;
- }
-
- if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) {
- continue;
- }
-
- if (!(flags & ZAP_READ)) {
- continue;
- }
-
- if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error);
- goto done;
- }
-
- if (zchan->detected_tones[0]) {
- zap_sigmsg_t sig;
- int i;
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
- sig.event_id = ZAP_SIGEVENT_TONE_DETECTED;
-
- for (i = 1; i < ZAP_TONEMAP_INVALID; i++) {
- if (zchan->detected_tones[i]) {
- zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id);
- sig.raw_data = &i;
- zap_span_send_signal(zchan->span, &sig);
- }
- }
-
- if (zchan->detected_tones[ZAP_TONEMAP_BUSY] ||
- zchan->detected_tones[ZAP_TONEMAP_FAIL1] ||
- zchan->detected_tones[ZAP_TONEMAP_FAIL2] ||
- zchan->detected_tones[ZAP_TONEMAP_FAIL3] ||
- zchan->detected_tones[ZAP_TONEMAP_ATTN]
- ) {
- zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n");
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY);
- } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
- }
-
- zap_channel_clear_detected_tones(zchan);
- }
-
- if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer))) {
- rlen = len;
- memset(frame, 0, len);
- zap_channel_write(zchan, frame, sizeof(frame), &rlen);
- continue;
- }
-
- if (!indicate) {
- continue;
- }
-
- if (zchan->effective_codec != ZAP_CODEC_SLIN) {
- len *= 2;
- }
-
- rlen = zap_buffer_read_loop(dt_buffer, frame, len);
-
- if (zchan->effective_codec != ZAP_CODEC_SLIN) {
- zio_codec_t codec_func = NULL;
-
- if (zchan->native_codec == ZAP_CODEC_ULAW) {
- codec_func = zio_slin2ulaw;
- } else if (zchan->native_codec == ZAP_CODEC_ALAW) {
- codec_func = zio_slin2alaw;
- }
-
- if (codec_func) {
- status = codec_func(frame, sizeof(frame), &rlen);
- } else {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!");
- goto done;
- }
- }
-
- zap_channel_write(zchan, frame, sizeof(frame), &rlen);
- }
-
- done:
-
- zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL);
-
- closed_chan = zchan;
- zap_channel_close(&zchan);
-
- zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL);
-
- if (ts.buffer) {
- teletone_destroy_session(&ts);
- }
-
- if (dt_buffer) {
- zap_buffer_destroy(&dt_buffer);
- }
-
- zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD);
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread ended.\n");
-
- return NULL;
-}
-
-/**
- * \brief Processes EM events coming from zaptel/dahdi
- * \param span Span on which the event was fired
- * \param event Event to be treated
- * \return Success or failure
- */
-static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event)
-{
- zap_sigmsg_t sig;
- int locked = 0;
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = event->channel->chan_id;
- sig.span_id = event->channel->span_id;
- sig.channel = event->channel;
-
-
- zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n",
- zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state));
-
- zap_mutex_lock(event->channel->mutex);
- locked++;
-
- switch(event->enum_id) {
- case ZAP_OOB_ONHOOK:
- {
- if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
- }
-
- }
- break;
- case ZAP_OOB_OFFHOOK:
- {
- if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
- } else {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE);
- zap_mutex_unlock(event->channel->mutex);
- locked = 0;
- zap_thread_create_detached(zap_analog_em_channel_run, event->channel);
- }
- break;
- }
- case ZAP_OOB_WINK:
- {
- if (event->channel->state != ZAP_CHANNEL_STATE_DIALING) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
- } else {
- zap_set_flag_locked(event->channel, ZAP_CHANNEL_WINK);
- }
-
- }
- break;
- }
- if (locked) {
- zap_mutex_unlock(event->channel->mutex);
- }
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Main thread function for EM span (monitor)
- * \param me Current thread
- * \param obj Span to run in this thread
- */
-static void *zap_analog_em_run(zap_thread_t *me, void *obj)
-{
- zap_span_t *span = (zap_span_t *) obj;
- zap_analog_em_data_t *analog_data = span->signal_data;
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG EM thread starting.\n");
-
- while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_EM_RUNNING)) {
- int waitms = 10;
- zap_status_t status;
-
- status = zap_span_poll_event(span, waitms);
-
- switch(status) {
- case ZAP_SUCCESS:
- {
- zap_event_t *event;
- while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
- if (event->enum_id == ZAP_OOB_NOOP) {
- continue;
- }
- if (process_event(span, event) != ZAP_SUCCESS) {
- goto end;
- }
- }
- }
- break;
- case ZAP_FAIL:
- {
- zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error);
- }
- break;
- default:
- break;
- }
-
- }
-
- end:
-
- zap_clear_flag(analog_data, ZAP_ANALOG_EM_RUNNING);
-
- zap_log(ZAP_LOG_DEBUG, "ANALOG EM thread ending.\n");
-
- return NULL;
-}
-
-/**
- * \brief Openzap analog EM module initialisation
- * \return Success
- */
-static ZIO_SIG_LOAD_FUNCTION(zap_analog_em_init)
-{
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Openzap analog EM module definition
- */
-EX_DECLARE_DATA zap_module_t zap_module = {
- "analog_em",
- NULL,
- NULL,
- zap_analog_em_init,
- zap_analog_em_configure_span,
- NULL
-};
-
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h b/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h
deleted file mode 100644
index 47e431288f..0000000000
--- a/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2008-2012, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Contributor(s):
- *
- * John Wehle (john@feith.com)
- *
- */
-
-#ifndef ZAP_ANALOG_EM_H
-#define ZAP_ANALOG_EM_H
-#include "openzap.h"
-
-#define MAX_DIALSTRING 256
-
-typedef enum {
- ZAP_ANALOG_EM_RUNNING = (1 << 0)
-} zap_analog_em_flag_t;
-
-
-struct zap_analog_data {
- uint32_t flags;
- uint32_t max_dialstr;
- uint32_t digit_timeout;
-};
-
-static void *zap_analog_em_run(zap_thread_t *me, void *obj);
-typedef struct zap_analog_data zap_analog_em_data_t;
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj
deleted file mode 100644
index 19dc74fd8f..0000000000
--- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj
+++ /dev/null
@@ -1,316 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj
deleted file mode 100644
index 75815df561..0000000000
--- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj
+++ /dev/null
@@ -1,465 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c
deleted file mode 100644
index 750a70eaab..0000000000
--- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c
+++ /dev/null
@@ -1,2420 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * Workaround for missing u_int / u_short types on solaris
- */
-#if defined(HAVE_LIBPCAP) && defined(__SunOS)
-#define __EXTENSIONS__
-#endif
-
-#include "openzap.h"
-#include "Q931.h"
-#include "Q921.h"
-#ifdef WIN32
-#include
-#else
-#include
-#endif
-
-#include "zap_isdn.h"
-
-#define LINE "--------------------------------------------------------------------------------"
-//#define IODEBUG
-
-/* helper macros */
-#define ZAP_SPAN_IS_BRI(x) ((x)->trunk_type == ZAP_TRUNK_BRI || (x)->trunk_type == ZAP_TRUNK_BRI_PTMP)
-#define ZAP_SPAN_IS_NT(x) (((zap_isdn_data_t *)(x)->signal_data)->mode == Q921_NT)
-
-
-#ifdef HAVE_LIBPCAP
-/*-------------------------------------------------------------------------*/
-/*Q931ToPcap functions*/
-#include
-#endif
-
-#define SNAPLEN 1522
-#define MAX_ETHER_PAYLOAD_SIZE 1500
-#define MIN_ETHER_PAYLOAD_SIZE 42
-#define SIZE_ETHERNET 18
-#define VLANID_OFFSET 15
-#define SIZE_IP 20
-#define SIZE_TCP 20
-#define SIZE_TPKT 4
-#define SIZE_ETHERNET_CRC 4
-#define OVERHEAD SIZE_ETHERNET+SIZE_IP+SIZE_TCP+SIZE_TPKT
-#define MAX_Q931_SIZE MAX_ETHER_PAYLOAD_SIZE-SIZE_IP-SIZE_TCP-SIZE_TPKT
-#define TPKT_SIZE_OFFSET SIZE_ETHERNET+SIZE_IP+SIZE_TCP+2
-#define IP_SIZE_OFFSET SIZE_ETHERNET+2
-#define TCP_SEQ_OFFSET SIZE_ETHERNET+SIZE_IP+4
-
-#ifdef HAVE_LIBPCAP
-/*Some globals*/
-unsigned long pcapfilesize = 0;
-unsigned long tcp_next_seq_no_send = 0;
-unsigned long tcp_next_seq_no_rec = 0;
-pcap_dumper_t *pcapfile = NULL;
-struct pcap_pkthdr pcaphdr;
-pcap_t *pcaphandle = NULL;
-char *pcapfn = NULL;
-int do_q931ToPcap= 0;
-
-/*Predefined Ethernet Frame with Q931-over-IP encapsulated - From remote TDM host to FreeSWITCH*/
-L3UCHAR recFrame[SNAPLEN]= {
- /*IEEE 802.3 VLAN 802.1q Ethernet Frame Header*/
- 2,0,1,0xAA,0xAA,0xAA,2,0,1,0xBB,0xBB,0xBB,0x81,0,0xE0,0,0x08,0,
- /*IPv4 Header (minimal size; no options)*/
- 0x45,0,0,44,0,0,0,0,64,6,0,0,2,2,2,2,1,1,1,1,
- /*TCP-Header*/
- 0,0x66,0,0x66,0,0,0,0,0,0,0,0,0x50,0,0,1,0,0,0,0,
- /*TPKT-Header RFC 1006*/
- 3,0,0,0
- };
-
-/*Predefined Ethernet Frame with Q931-over-IP encapsulated - Frome FreeSWITCH to remote TDM host*/
-L3UCHAR sendFrame[SNAPLEN]= {
- /*IEEE 802.3 VLAN 802.1q Ethernet Frame Header*/
- 2,0,1,0xBB,0xBB,0xBB,2,0,1,0xAA,0xAA,0xAA,0x81,0,0xE0,0,0x08,0,
- /*IPv4 Header (minimal size; no options)*/
- 0x45,0,0,44,0,0,0,0,64,6,0,0,1,1,1,1,2,2,2,2,
- /*TCP-Header*/
- 0,0x66,0,0x66,0,0,0,0,0,0,0,0,0x50,0,0,1,0,0,0,0,
- /*TPKT-Header RFC 1006*/
- 3,0,0,0
- };
-
-/**
- * \brief Opens a pcap file for capture
- * \return Success or failure
- */
-static zap_status_t openPcapFile(void)
-{
- if(!pcaphandle)
- {
- pcaphandle = pcap_open_dead(DLT_EN10MB, SNAPLEN);
- if (!pcaphandle)
- {
- zap_log(ZAP_LOG_ERROR, "Can't open pcap session: (%s)\n", pcap_geterr(pcaphandle));
- return ZAP_FAIL;
- }
- }
-
- if(!pcapfile){
- /* Open the dump file */
- if(!(pcapfile=pcap_dump_open(pcaphandle, pcapfn))){
- zap_log(ZAP_LOG_ERROR, "Error opening output file (%s)\n", pcap_geterr(pcaphandle));
- return ZAP_FAIL;
- }
- }
- else{
- zap_log(ZAP_LOG_WARNING, "Pcap file is already open!\n");
- return ZAP_FAIL;
- }
-
- zap_log(ZAP_LOG_DEBUG, "Pcap file '%s' successfully opened!\n", pcapfn);
-
- pcaphdr.ts.tv_sec = 0;
- pcaphdr.ts.tv_usec = 0;
- pcapfilesize = 24; /*current pcap file header seems to be 24 bytes*/
- tcp_next_seq_no_send = 0;
- tcp_next_seq_no_rec = 0;
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Closes a pcap file
- * \return Success
- */
-static zap_status_t closePcapFile(void)
-{
- if (pcapfile) {
- pcap_dump_close(pcapfile);
- if (pcaphandle) pcap_close(pcaphandle);
-
- zap_log(ZAP_LOG_DEBUG, "Pcap file closed! File size is %lu bytes.\n", pcapfilesize);
-
- pcaphdr.ts.tv_sec = 0;
- pcaphdr.ts.tv_usec = 0;
- pcapfile = NULL;
- pcaphandle = NULL;
- pcapfilesize = 0;
- tcp_next_seq_no_send = 0;
- tcp_next_seq_no_rec = 0;
- }
-
- /*We have allways success with this? I think so*/
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Writes a Q931 packet to a pcap file
- * \return Success or failure
- */
-static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction)
-{
- L3UCHAR *frame = NULL;
- struct timeval ts;
- u_char spanid = (u_char)span_id;
- unsigned long *tcp_next_seq_no = NULL;
-
- spanid=span_id;
-
- /*The total length of the ethernet frame generated by this function has a min length of 66
- so we don't have to care about padding :)*/
-
-
- /*FS is sending the packet*/
- if(direction==0){
- frame=sendFrame;
- tcp_next_seq_no = &tcp_next_seq_no_send;
- }
- /*FS is receiving the packet*/
- else{
- frame=recFrame;
- tcp_next_seq_no = &tcp_next_seq_no_rec;
- }
-
- /*Set spanid in VLAN-ID tag*/
- frame[VLANID_OFFSET] = spanid;
-
- /*** Write sent packet ***/
- if(q931size > MAX_Q931_SIZE)
- {
- /*WARNING*/
- zap_log(ZAP_LOG_WARNING, "Q931 packet size is too big (%u)! Ignoring it!\n", q931size);
- return ZAP_FAIL;
- }
-
- /*Copy q931 buffer into frame*/
- memcpy(frame+OVERHEAD,q931buf,q931size);
-
- /*Store TCP sequence number in TCP header*/
- frame[TCP_SEQ_OFFSET]=(*tcp_next_seq_no>>24)&0xFF;
- frame[TCP_SEQ_OFFSET+1]=(*tcp_next_seq_no>>16)&0xFF;
- frame[TCP_SEQ_OFFSET+2]=(*tcp_next_seq_no>>8)&0xFF;
- frame[TCP_SEQ_OFFSET+3]=*tcp_next_seq_no & 0xFF;
-
- /*Store size of TPKT packet*/
- q931size+=4;
- frame[TPKT_SIZE_OFFSET]=(q931size>>8)&0xFF;
- frame[TPKT_SIZE_OFFSET+1]=q931size&0xFF;
-
- /*Calc next TCP sequence number*/
- *tcp_next_seq_no+=q931size;
-
- /*Store size of IP packet*/
- q931size+=SIZE_IP+SIZE_TCP;
- frame[IP_SIZE_OFFSET]=(q931size>>8)&0xFF;
- frame[IP_SIZE_OFFSET+1]=q931size&0xFF;
-
- pcaphdr.caplen = SIZE_ETHERNET+SIZE_ETHERNET_CRC+q931size;
- pcaphdr.len = pcaphdr.caplen;
-
- /* Set Timestamp */
- /* Get Time in ms. usecs would be better ... */
- gettimeofday(&ts, NULL);
- /*Write it into packet header*/
- pcaphdr.ts.tv_sec = ts.tv_sec;
- pcaphdr.ts.tv_usec = ts.tv_usec;
-
- pcap_dump((u_char*)pcapfile, &pcaphdr, frame);
- pcap_dump_flush(pcapfile);
-
- /*Maintain pcap file size*/
- pcapfilesize+=pcaphdr.caplen;
- pcapfilesize+=sizeof(struct pcap_pkthdr);
-
- zap_log(ZAP_LOG_DEBUG, "Added %u bytes to pcap file. File size is now %lu, \n", q931size, pcapfilesize);
-
- return ZAP_SUCCESS;
-}
-
-#endif
-
-/**
- * \brief Unloads pcap IO
- * \return Success or failure
- */
-static ZIO_IO_UNLOAD_FUNCTION(close_pcap)
-{
-#ifdef HAVE_LIBPCAP
- return closePcapFile();
-#else
- return ZAP_SUCCESS;
-#endif
-}
-
-/*Q931ToPcap functions DONE*/
-/*-------------------------------------------------------------------------*/
-
-/**
- * \brief Gets current time
- * \return Current time (in ms)
- */
-static L2ULONG zap_time_now(void)
-{
- return (L2ULONG)zap_current_time_in_ms();
-}
-
-/**
- * \brief Initialises an ISDN channel (outgoing call)
- * \param zchan Channel to initiate call on
- * \return Success or failure
- */
-static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call)
-{
- zap_status_t status = ZAP_SUCCESS;
- zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING);
- return status;
-}
-
-/**
- * \brief Requests an ISDN channel on a span (outgoing call)
- * \param span Span where to get a channel
- * \param chan_id Specific channel to get (0 for any)
- * \param direction Call direction (inbound, outbound)
- * \param caller_data Caller information
- * \param zchan Channel to initialise
- * \return Success or failure
- */
-static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request)
-{
- Q931mes_Generic *gen = (Q931mes_Generic *) caller_data->raw_data;
- Q931ie_BearerCap BearerCap;
- Q931ie_ChanID ChanID = { 0 };
- Q931ie_CallingNum CallingNum;
- Q931ie_CallingNum *ptrCallingNum;
- Q931ie_CalledNum CalledNum;
- Q931ie_CalledNum *ptrCalledNum;
- Q931ie_Display Display, *ptrDisplay;
- Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */
- Q931ie_ProgInd Progress; /* Progress Indicator IE */
- zap_status_t status = ZAP_FAIL;
- zap_isdn_data_t *isdn_data = span->signal_data;
- int sanity = 60000;
- int codec = 0;
-
- /*
- * get codec type
- */
- zap_channel_command(span->channels[chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec);
-
- /*
- * Q.931 Setup Message
- */
- Q931InitMesGeneric(gen);
- gen->MesType = Q931mes_SETUP;
- gen->CRVFlag = 0; /* outgoing call */
-
- /*
- * Bearer Capability IE
- */
- Q931InitIEBearerCap(&BearerCap);
- BearerCap.CodStand = Q931_CODING_ITU; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */
- BearerCap.ITC = Q931_ITC_SPEECH; /* Speech */
- BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */
- BearerCap.ITR = Q931_ITR_64K; /* 64k */
- BearerCap.Layer1Ident = 1;
- BearerCap.UIL1Prot = (codec == ZAP_CODEC_ALAW) ? Q931_UIL1P_G711A : Q931_UIL1P_G711U; /* U-law = 2, A-law = 3 */
- gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap);
-
- /*
- * Channel ID IE
- */
- Q931InitIEChanID(&ChanID);
- ChanID.IntType = ZAP_SPAN_IS_BRI(span) ? 0 : 1; /* PRI = 1, BRI = 0 */
-
- if(!ZAP_SPAN_IS_NT(span)) {
- ChanID.PrefExcl = (isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1; /* 0 = preferred, 1 exclusive */
- } else {
- ChanID.PrefExcl = 1; /* always exclusive in NT-mode */
- }
-
- if(ChanID.IntType) {
- ChanID.InfoChanSel = 1; /* None = 0, See Slot = 1, Any = 3 */
- ChanID.ChanMapType = 3; /* B-Chan */
- ChanID.ChanSlot = (unsigned char)chan_id;
- } else {
- ChanID.InfoChanSel = (unsigned char)chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */
- }
- gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
-
- /*
- * Progress IE
- */
- Q931InitIEProgInd(&Progress);
- Progress.CodStand = Q931_CODING_ITU; /* 0 = ITU */
- Progress.Location = 0; /* 0 = User, 1 = Private Network */
- Progress.ProgDesc = 3; /* 1 = Not end-to-end ISDN */
- gen->ProgInd = Q931AppendIE((L3UCHAR *)gen, (L3UCHAR *)&Progress);
-
- /*
- * Display IE
- */
- if (!(isdn_data->opts & ZAP_ISDN_OPT_OMIT_DISPLAY_IE)) {
- Q931InitIEDisplay(&Display);
- Display.Size = Display.Size + (unsigned char)strlen(caller_data->cid_name);
- gen->Display = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &Display);
- ptrDisplay = Q931GetIEPtr(gen->Display, gen->buf);
- zap_copy_string((char *)ptrDisplay->Display, caller_data->cid_name, strlen(caller_data->cid_name)+1);
- }
-
- /*
- * Calling Number IE
- */
- Q931InitIECallingNum(&CallingNum);
- CallingNum.TypNum = Q931_TON_UNKNOWN;
- CallingNum.NumPlanID = Q931_NUMPLAN_E164;
- CallingNum.PresInd = Q931_PRES_ALLOWED;
- CallingNum.ScreenInd = Q931_SCREEN_USER_NOT_SCREENED;
- CallingNum.Size = CallingNum.Size + (unsigned char)strlen(caller_data->cid_num.digits);
- gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum);
- ptrCallingNum = Q931GetIEPtr(gen->CallingNum, gen->buf);
- zap_copy_string((char *)ptrCallingNum->Digit, caller_data->cid_num.digits, strlen(caller_data->cid_num.digits)+1);
-
-
- /*
- * Called number IE
- */
- Q931InitIECalledNum(&CalledNum);
- CalledNum.TypNum = Q931_TON_UNKNOWN;
- CalledNum.NumPlanID = Q931_NUMPLAN_E164;
- CalledNum.Size = CalledNum.Size + (unsigned char)strlen(caller_data->ani.digits);
- gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum);
- ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf);
- zap_copy_string((char *)ptrCalledNum->Digit, caller_data->ani.digits, strlen(caller_data->ani.digits)+1);
-
- /*
- * High-Layer Compatibility IE (Note: Required for AVM FritzBox)
- */
- Q931InitIEHLComp(&HLComp);
- HLComp.CodStand = Q931_CODING_ITU; /* ITU */
- HLComp.Interpret = 4; /* only possible value */
- HLComp.PresMeth = 1; /* High-layer protocol profile */
- HLComp.HLCharID = 1; /* Telephony = 1, Fax G2+3 = 4, Fax G4 = 65 (Class I)/ 68 (Class II or III) */
- gen->HLComp = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &HLComp);
-
- caller_data->call_state = ZAP_CALLER_STATE_DIALING;
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
-
- isdn_data->outbound_crv[gen->CRV] = caller_data;
- //isdn_data->channels_local_crv[gen->CRV] = zchan;
-
- while(zap_running() && caller_data->call_state == ZAP_CALLER_STATE_DIALING) {
- zap_sleep(1);
-
- if (!--sanity) {
- caller_data->call_state = ZAP_CALLER_STATE_FAIL;
- break;
- }
- }
- isdn_data->outbound_crv[gen->CRV] = NULL;
-
- if (caller_data->call_state == ZAP_CALLER_STATE_SUCCESS) {
- zap_channel_t *new_chan = NULL;
- int fail = 1;
-
- new_chan = NULL;
- if (caller_data->chan_id < ZAP_MAX_CHANNELS_SPAN && caller_data->chan_id <= span->chan_count) {
- new_chan = span->channels[caller_data->chan_id];
- }
-
- if (new_chan && (status = zap_channel_open_chan(new_chan) == ZAP_SUCCESS)) {
- if (zap_test_flag(new_chan, ZAP_CHANNEL_INUSE) || new_chan->state != ZAP_CHANNEL_STATE_DOWN) {
- if (new_chan->state == ZAP_CHANNEL_STATE_DOWN || new_chan->state >= ZAP_CHANNEL_STATE_TERMINATING) {
- int x = 0;
- zap_log(ZAP_LOG_WARNING, "Channel %d:%d ~ %d:%d is already in use waiting for it to become available.\n");
-
- for (x = 0; x < 200; x++) {
- if (!zap_test_flag(new_chan, ZAP_CHANNEL_INUSE)) {
- break;
- }
- zap_sleep(5);
- }
- }
- if (zap_test_flag(new_chan, ZAP_CHANNEL_INUSE)) {
- zap_log(ZAP_LOG_ERROR, "Channel %d:%d ~ %d:%d is already in use.\n",
- new_chan->span_id,
- new_chan->chan_id,
- new_chan->physical_span_id,
- new_chan->physical_chan_id
- );
- new_chan = NULL;
- }
- }
-
- if (new_chan && new_chan->state == ZAP_CHANNEL_STATE_DOWN) {
- isdn_data->channels_local_crv[gen->CRV] = new_chan;
- memset(&new_chan->caller_data, 0, sizeof(new_chan->caller_data));
- zap_set_flag(new_chan, ZAP_CHANNEL_OUTBOUND);
- zap_set_state_locked(new_chan, ZAP_CHANNEL_STATE_DIALING);
- switch(gen->MesType) {
- case Q931mes_ALERTING:
- new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA;
- break;
- case Q931mes_CONNECT:
- new_chan->init_state = ZAP_CHANNEL_STATE_UP;
- break;
- default:
- new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS;
- break;
- }
-
- fail = 0;
- }
- }
-
- if (!fail) {
- *zchan = new_chan;
- return ZAP_SUCCESS;
- } else {
- Q931ie_Cause cause;
- gen->MesType = Q931mes_DISCONNECT;
- cause.IEId = Q931ie_CAUSE;
- cause.Size = sizeof(Q931ie_Cause);
- cause.CodStand = 0;
- cause.Location = 1;
- cause.Recom = 1;
- //should we be casting here.. or do we need to translate value?
- cause.Value = (unsigned char) ZAP_CAUSE_WRONG_CALL_STATE;
- *cause.Diag = '\0';
- gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
-
- if (gen->CRV) {
- Q931ReleaseCRV(&isdn_data->q931, gen->CRV);
- }
-
- if (new_chan) {
- zap_log(ZAP_LOG_CRIT, "Channel is busy\n");
- } else {
- zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n");
- }
- }
- }
-
- *zchan = NULL;
- return ZAP_FAIL;
-
-}
-
-/**
- * \brief Handler for Q931 error
- * \param pvt Private structure (span?)
- * \param id Error number
- * \param p1 ??
- * \param p2 ??
- * \return 0
- */
-static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2)
-{
- zap_log(ZAP_LOG_ERROR, "ERROR: [%s] [%d] [%d]\n", q931_error_to_name(id), p1, p2);
- return 0;
-}
-
-/**
- * \brief Handler for Q931 event message
- * \param pvt Span to handle
- * \param msg Message string
- * \param mlen Message string length
- * \return 0
- */
-static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen)
-{
- zap_span_t *span = (zap_span_t *) pvt;
- zap_isdn_data_t *isdn_data = span->signal_data;
- Q931mes_Generic *gen = (Q931mes_Generic *) msg;
- uint32_t chan_id = 0;
- int chan_hunt = 0;
- zap_channel_t *zchan = NULL;
- zap_caller_data_t *caller_data = NULL;
-
- if (Q931IsIEPresent(gen->ChanID)) {
- Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf);
-
- if(chanid->IntType)
- chan_id = chanid->ChanSlot;
- else
- chan_id = chanid->InfoChanSel;
-
- /* "any" channel specified */
- if(chanid->InfoChanSel == 3) {
- chan_hunt++;
- }
- } else if (ZAP_SPAN_IS_NT(span)) {
- /* no channel ie */
- chan_hunt++;
- }
-
- assert(span != NULL);
- assert(isdn_data != NULL);
-
- zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d] CRV: %d (%#hx, CTX: %s)\n", gen->MesType, gen->Size, gen->CRV, gen->CRV, gen->CRVFlag ? "Terminator" : "Originator");
-
- if (gen->CRVFlag && (caller_data = isdn_data->outbound_crv[gen->CRV])) {
- if (chan_id) {
- caller_data->chan_id = chan_id;
- }
-
- switch(gen->MesType) {
- case Q931mes_STATUS:
- case Q931mes_CALL_PROCEEDING:
- break;
- case Q931mes_ALERTING:
- case Q931mes_PROGRESS:
- case Q931mes_CONNECT:
- {
- caller_data->call_state = ZAP_CALLER_STATE_SUCCESS;
- }
- break;
- default:
- caller_data->call_state = ZAP_CALLER_STATE_FAIL;
- break;
- }
-
- return 0;
- }
-
- if (gen->CRVFlag) {
- zchan = isdn_data->channels_local_crv[gen->CRV];
- } else {
- zchan = isdn_data->channels_remote_crv[gen->CRV];
- }
-
- zap_log(ZAP_LOG_DEBUG, "zchan %x (%d:%d) source isdn_data->channels_%s_crv[%#hx]\n", zchan, zchan ? zchan->span_id : -1, zchan ? zchan->chan_id : -1, gen->CRVFlag ? "local" : "remote", gen->CRV);
-
-
- if (gen->ProtDisc == 3) {
- switch(gen->MesType) {
- case Q931mes_SERVICE:
- {
- Q931ie_ChangeStatus *changestatus = Q931GetIEPtr(gen->ChangeStatus, gen->buf);
- if (zchan) {
- switch (changestatus->NewStatus) {
- case 0: /* change status to "in service" */
- {
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_SUSPENDED);
- zap_log(ZAP_LOG_DEBUG, "Channel %d:%d in service\n", zchan->span_id, zchan->chan_id);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- }
- break;
- case 1:
- { /* change status to "maintenance" */
- zap_set_flag_locked(zchan, ZAP_CHANNEL_SUSPENDED);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_SUSPENDED);
- }
- break;
- case 2:
- { /* change status to "out of service" */
- zap_set_flag_locked(zchan, ZAP_CHANNEL_SUSPENDED);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_SUSPENDED);
- }
- break;
- default: /* unknown */
- {
- break;
- }
- }
- }
- }
- break;
- default:
- break;
- }
- } else {
- switch(gen->MesType) {
- case Q931mes_RESTART:
- {
- if (chan_id) {
- zchan = span->channels[chan_id];
- }
- if (zchan) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- } else {
- uint32_t i;
- for (i = 1; i < span->chan_count; i++) {
- zap_set_state_locked((span->channels[i]), ZAP_CHANNEL_STATE_RESTART);
- }
- }
- }
- break;
- case Q931mes_RELEASE:
- case Q931mes_RELEASE_COMPLETE:
- {
- const char *what = gen->MesType == Q931mes_RELEASE ? "Release" : "Release Complete";
- if (zchan) {
- if (zchan->state == ZAP_CHANNEL_STATE_TERMINATING || zchan->state == ZAP_CHANNEL_STATE_HANGUP) {
- if (gen->MesType == Q931mes_RELEASE) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- else if((gen->MesType == Q931mes_RELEASE && zchan->state <= ZAP_CHANNEL_STATE_UP) ||
- (gen->MesType == Q931mes_RELEASE_COMPLETE && zchan->state == ZAP_CHANNEL_STATE_DIALING)) {
-
- /*
- * Don't keep inbound channels open if the remote side hangs up before we answered
- */
- Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf);
- zap_sigmsg_t sig;
- zap_status_t status;
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
- sig.channel->caller_data.hangup_cause = (cause) ? cause->Value : ZAP_CAUSE_NORMAL_UNSPECIFIED;
-
- sig.event_id = ZAP_SIGEVENT_STOP;
- status = zap_span_send_signal(zchan->span, &sig);
-
- zap_log(ZAP_LOG_DEBUG, "Received %s in state %s, requested hangup for channel %d:%d\n", what, zap_channel_state2str(zchan->state), zchan->span_id, chan_id);
- }
- else {
- zap_log(ZAP_LOG_DEBUG, "Ignoring %s on channel %d\n", what, chan_id);
- }
- } else {
- zap_log(ZAP_LOG_CRIT, "Received %s with no matching channel %d\n", what, chan_id);
- }
- }
- break;
- case Q931mes_DISCONNECT:
- {
- if (zchan) {
- Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf);
- zchan->caller_data.hangup_cause = cause->Value;
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING);
- } else {
- zap_log(ZAP_LOG_CRIT, "Received Disconnect with no matching channel %d\n", chan_id);
- }
- }
- break;
- case Q931mes_ALERTING:
- {
- if (zchan) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA);
- } else {
- zap_log(ZAP_LOG_CRIT, "Received Alerting with no matching channel %d\n", chan_id);
- }
- }
- break;
- case Q931mes_PROGRESS:
- {
- if (zchan) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS);
- } else {
- zap_log(ZAP_LOG_CRIT, "Received Progress with no matching channel %d\n", chan_id);
- }
- }
- break;
- case Q931mes_CONNECT:
- {
- if (zchan) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
-
- gen->MesType = Q931mes_CONNECT_ACKNOWLEDGE;
- gen->CRVFlag = 0; /* outbound */
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
- } else {
- zap_log(ZAP_LOG_CRIT, "Received Connect with no matching channel %d\n", chan_id);
- }
- }
- break;
- case Q931mes_SETUP:
- {
- Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf);
- Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf);
- int fail = 1;
- int fail_cause = 0;
- int overlap_dial = 0;
- uint32_t cplen = mlen;
-
- if(zchan && zchan == isdn_data->channels_remote_crv[gen->CRV]) {
- zap_log(ZAP_LOG_INFO, "Duplicate SETUP message(?) for Channel %d:%d ~ %d:%d in state %s [ignoring]\n",
- zchan->span_id,
- zchan->chan_id,
- zchan->physical_span_id,
- zchan->physical_chan_id,
- zap_channel_state2str(zchan->state));
- break;
- }
-
- zchan = NULL;
- /*
- * Channel selection for incoming calls:
- */
- if (ZAP_SPAN_IS_NT(span) && chan_hunt) {
- uint32_t x;
-
- /*
- * In NT-mode with channel selection "any",
- * try to find a free channel
- */
- for (x = 1; x <= span->chan_count; x++) {
- zap_channel_t *zc = span->channels[x];
-
- if (!zap_test_flag(zc, ZAP_CHANNEL_INUSE) && zc->state == ZAP_CHANNEL_STATE_DOWN) {
- zchan = zc;
- break;
- }
- }
- }
- else if (!ZAP_SPAN_IS_NT(span) && chan_hunt) {
- /*
- * In TE-mode this ("any") is invalid
- */
- fail_cause = ZAP_CAUSE_CHANNEL_UNACCEPTABLE;
-
- zap_log(ZAP_LOG_ERROR, "Invalid channel selection in incoming call (network side didn't specify a channel)\n");
- }
- else {
- /*
- * Otherwise simply try to select the channel we've been told
- *
- * TODO: NT mode is abled to select a different channel if the one chosen
- * by the TE side is already in use
- */
- if (chan_id > 0 && chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) {
- zchan = span->channels[chan_id];
- }
- else {
- /* invalid channel id */
- fail_cause = ZAP_CAUSE_CHANNEL_UNACCEPTABLE;
-
- zap_log(ZAP_LOG_ERROR, "Invalid channel selection in incoming call (none selected or out of bounds)\n");
- }
- }
-
- if (!callednum || !strlen((char *)callednum->Digit)) {
- if (ZAP_SPAN_IS_NT(span)) {
- zap_log(ZAP_LOG_NOTICE, "No destination number found, assuming overlap dial\n");
- overlap_dial++;
- }
- else {
- zap_log(ZAP_LOG_ERROR, "No destination number found\n");
- zchan = NULL;
- }
- }
-
- if (zchan) {
- if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE) || zchan->state != ZAP_CHANNEL_STATE_DOWN) {
- if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state >= ZAP_CHANNEL_STATE_TERMINATING) {
- int x = 0;
- zap_log(ZAP_LOG_WARNING, "Channel %d:%d ~ %d:%d is already in use waiting for it to become available.\n",
- zchan->span_id,
- zchan->chan_id,
- zchan->physical_span_id,
- zchan->physical_chan_id);
-
- for (x = 0; x < 200; x++) {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) {
- break;
- }
- zap_sleep(5);
- }
- }
- if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) {
- zap_log(ZAP_LOG_ERROR, "Channel %d:%d ~ %d:%d is already in use.\n",
- zchan->span_id,
- zchan->chan_id,
- zchan->physical_span_id,
- zchan->physical_chan_id
- );
- zchan = NULL;
- }
- }
-
- if (zchan && zchan->state == ZAP_CHANNEL_STATE_DOWN) {
- isdn_data->channels_remote_crv[gen->CRV] = zchan;
- memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
-
- if (zchan->mod_data) {
- memset(zchan->mod_data, 0, sizeof(zap_isdn_bchan_data_t));
- }
-
- zap_set_string(zchan->caller_data.cid_num.digits, (char *)callingnum->Digit);
- zap_set_string(zchan->caller_data.cid_name, (char *)callingnum->Digit);
- zap_set_string(zchan->caller_data.ani.digits, (char *)callingnum->Digit);
- if (!overlap_dial) {
- zap_set_string(zchan->caller_data.dnis.digits, (char *)callednum->Digit);
- }
-
- zchan->caller_data.CRV = gen->CRV;
- if (cplen > sizeof(zchan->caller_data.raw_data)) {
- cplen = sizeof(zchan->caller_data.raw_data);
- }
- gen->CRVFlag = !(gen->CRVFlag);
- memcpy(zchan->caller_data.raw_data, msg, cplen);
- zchan->caller_data.raw_data_len = cplen;
- fail = 0;
- }
- }
-
- if (fail) {
- Q931ie_Cause cause;
- gen->MesType = Q931mes_DISCONNECT;
- gen->CRVFlag = 1; /* inbound call */
- cause.IEId = Q931ie_CAUSE;
- cause.Size = sizeof(Q931ie_Cause);
- cause.CodStand = Q931_CODING_ITU;
- cause.Location = 1;
- cause.Recom = 1;
- //should we be casting here.. or do we need to translate value?
- cause.Value = (unsigned char)((fail_cause) ? fail_cause : ZAP_CAUSE_WRONG_CALL_STATE);
- *cause.Diag = '\0';
- gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
-
- if (gen->CRV) {
- Q931ReleaseCRV(&isdn_data->q931, gen->CRV);
- }
-
- if (zchan) {
- zap_log(ZAP_LOG_CRIT, "Channel is busy\n");
- } else {
- zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n");
- }
-
- } else {
- Q931ie_ChanID ChanID;
-
- /*
- * Update Channel ID IE
- */
- Q931InitIEChanID(&ChanID);
- ChanID.IntType = ZAP_SPAN_IS_BRI(zchan->span) ? 0 : 1; /* PRI = 1, BRI = 0 */
- ChanID.PrefExcl = ZAP_SPAN_IS_NT(zchan->span) ? 1 : 0; /* Exclusive in NT-mode = 1, Preferred otherwise = 0 */
- if(ChanID.IntType) {
- ChanID.InfoChanSel = 1; /* None = 0, See Slot = 1, Any = 3 */
- ChanID.ChanMapType = 3; /* B-Chan */
- ChanID.ChanSlot = (unsigned char)zchan->chan_id;
- } else {
- ChanID.InfoChanSel = (unsigned char)zchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */
- }
- gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
-
- if (overlap_dial) {
- Q931ie_ProgInd progress;
-
- /*
- * Setup Progress indicator
- */
- progress.IEId = Q931ie_PROGRESS_INDICATOR;
- progress.Size = sizeof(Q931ie_ProgInd);
- progress.CodStand = Q931_CODING_ITU; /* ITU */
- progress.Location = 1; /* private network serving the local user */
- progress.ProgDesc = 8; /* call is not end-to-end isdn = 1, in-band information available = 8 */
- gen->ProgInd = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &progress);
-
- /*
- * Send SETUP ACK
- */
- gen->MesType = Q931mes_SETUP_ACKNOWLEDGE;
- gen->CRVFlag = 1; /* inbound call */
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
-
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALTONE);
- } else {
- /*
- * Advance to RING state
- */
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING);
- }
- }
- }
- break;
-
- case Q931mes_CALL_PROCEEDING:
- {
- if (zchan) {
- zap_log(ZAP_LOG_CRIT, "Received CALL PROCEEDING message for channel %d\n", chan_id);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS);
- } else {
- zap_log(ZAP_LOG_CRIT, "Received CALL PROCEEDING with no matching channel %d\n", chan_id);
- }
- }
- break;
- case Q931mes_CONNECT_ACKNOWLEDGE:
- {
- if (zchan) {
- zap_log(ZAP_LOG_DEBUG, "Received CONNECT_ACK message for channel %d\n", chan_id);
- } else {
- zap_log(ZAP_LOG_DEBUG, "Received CONNECT_ACK with no matching channel %d\n", chan_id);
- }
- }
- break;
-
- case Q931mes_INFORMATION:
- {
- if (zchan) {
- zap_log(ZAP_LOG_CRIT, "Received INFORMATION message for channel %d\n", zchan->chan_id);
-
- if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) {
- char digit = '\0';
-
- /*
- * overlap dial digit indication
- */
- if (Q931IsIEPresent(gen->CalledNum)) {
- zap_isdn_bchan_data_t *data = (zap_isdn_bchan_data_t *)zchan->mod_data;
- Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf);
- int pos;
-
- digit = callednum->Digit[strlen((char *)callednum->Digit) - 1];
- if (digit == '#') {
- callednum->Digit[strlen((char *)callednum->Digit) - 1] = '\0';
- }
-
- /* TODO: make this more safe with strncat() */
- pos = (int)strlen(zchan->caller_data.dnis.digits);
- strcat(&zchan->caller_data.dnis.digits[pos], (char *)callednum->Digit);
-
- /* update timer */
- data->digit_timeout = zap_time_now() + isdn_data->digit_timeout;
-
- zap_log(ZAP_LOG_DEBUG, "Received new overlap digit (%s), destination number: %s\n", callednum->Digit, zchan->caller_data.dnis.digits);
- }
-
- if (Q931IsIEPresent(gen->SendComplete) || digit == '#') {
- zap_log(ZAP_LOG_DEBUG, "Leaving overlap dial mode\n");
-
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING);
- }
- }
- } else {
- zap_log(ZAP_LOG_CRIT, "Received INFORMATION message with no matching channel\n");
- }
- }
- break;
-
- case Q931mes_STATUS_ENQUIRY:
- {
- /*
- * !! HACK ALERT !!
- *
- * Map OpenZAP channel states to Q.931 states
- */
- Q931ie_CallState state;
- Q931ie_Cause cause;
-
- gen->MesType = Q931mes_STATUS;
- gen->CRVFlag = gen->CRVFlag ? 0 : 1;
-
- state.CodStand = Q931_CODING_ITU; /* ITU-T */
- state.CallState = Q931_U0; /* Default: Null */
-
- cause.IEId = Q931ie_CAUSE;
- cause.Size = sizeof(Q931ie_Cause);
- cause.CodStand = Q931_CODING_ITU; /* ITU */
- cause.Location = 1; /* private network */
- cause.Recom = 1; /* */
- *cause.Diag = '\0';
-
- if(zchan) {
- switch(zchan->state) {
- case ZAP_CHANNEL_STATE_UP:
- state.CallState = Q931_U10; /* Active */
- break;
- case ZAP_CHANNEL_STATE_RING:
- state.CallState = Q931_U6; /* Call present */
- break;
- case ZAP_CHANNEL_STATE_DIALING:
- state.CallState = Q931_U1; /* Call initiated */
- break;
- case ZAP_CHANNEL_STATE_DIALTONE:
- state.CallState = Q931_U25; /* Overlap receiving */
- break;
-
- /* TODO: map missing states */
-
- default:
- state.CallState = Q931_U0;
- }
-
- cause.Value = 30; /* response to STATUS ENQUIRY */
- } else {
- cause.Value = 98; /* */
- }
-
- gen->CallState = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &state);
- gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
- }
- break;
-
- default:
- zap_log(ZAP_LOG_CRIT, "Received unhandled message %d (%#x)\n", (int)gen->MesType, (int)gen->MesType);
- break;
- }
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for Q921 read event
- * \param pvt Span were message is coming from
- * \param ind Q921 indication
- * \param tei Terminal Endpoint Identifier
- * \param msg Message string
- * \param mlen Message string length
- * \return 0 on success, 1 on failure
- */
-static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg, L2INT mlen)
-{
- int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3;
- char bb[4096] = "";
-
- switch(ind) {
- case Q921_DL_DATA:
- case Q921_DL_UNIT_DATA:
- print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb));
-#ifdef HAVE_LIBPCAP
- /*Q931ToPcap*/
- if(do_q931ToPcap==1){
- zap_span_t *span = (zap_span_t *) pvt;
- if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 1) != ZAP_SUCCESS){
- zap_log(ZAP_LOG_WARNING, "Couldn't write Q931 buffer to pcap file!\n");
- }
- }
- /*Q931ToPcap done*/
-#endif
- zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n\n", (int)mlen - offset, LINE, bb);
-
- default:
- ret = Q931Rx23(pvt, ind, tei, msg, mlen);
- if (ret != 0)
- zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret));
- break;
- }
-
- return ((ret >= 0) ? 1 : 0);
-}
-
-/**
- * \brief Handler for Q921 write event
- * \param pvt Span were message is coming from
- * \param msg Message string
- * \param mlen Message string length
- * \return 0 on success, -1 on failure
- */
-static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen)
-{
- zap_span_t *span = (zap_span_t *) pvt;
- zap_size_t len = (zap_size_t) mlen;
- zap_isdn_data_t *isdn_data = span->signal_data;
-
-#ifdef IODEBUG
- char bb[4096] = "";
- print_hex_bytes(msg, len, bb, sizeof(bb));
- print_bits(msg, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
- zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb);
-
-#endif
-
- assert(span != NULL);
- return zap_channel_write(isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1;
-}
-
-/**
- * \brief Handler for channel state change
- * \param zchan Channel to handle
- */
-static __inline__ void state_advance(zap_channel_t *zchan)
-{
- Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data;
- zap_isdn_data_t *isdn_data = zchan->span->signal_data;
- zap_sigmsg_t sig;
- zap_status_t status;
-
- zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n",
- zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state));
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
-
- switch (zchan->state) {
- case ZAP_CHANNEL_STATE_DOWN:
- {
- if (gen->CRV) {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- isdn_data->channels_local_crv[gen->CRV] = NULL;
- } else {
- isdn_data->channels_remote_crv[gen->CRV] = NULL;
- }
- Q931ReleaseCRV(&isdn_data->q931, gen->CRV);
- }
- zap_channel_done(zchan);
- }
- break;
- case ZAP_CHANNEL_STATE_PROGRESS:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_PROGRESS;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else {
- gen->MesType = Q931mes_CALL_PROCEEDING;
- gen->CRVFlag = 1; /* inbound */
-
- if (ZAP_SPAN_IS_NT(zchan->span)) {
- Q931ie_ChanID ChanID;
-
- /*
- * Set new Channel ID
- */
- Q931InitIEChanID(&ChanID);
- ChanID.IntType = ZAP_SPAN_IS_BRI(zchan->span) ? 0 : 1; /* PRI = 1, BRI = 0 */
- ChanID.PrefExcl = 1; /* always exclusive in NT-mode */
-
- if(ChanID.IntType) {
- ChanID.InfoChanSel = 1; /* None = 0, See Slot = 1, Any = 3 */
- ChanID.ChanMapType = 3; /* B-Chan */
- ChanID.ChanSlot = (unsigned char)zchan->chan_id;
- } else {
- ChanID.InfoChanSel = (unsigned char)zchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */
- }
- gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
- }
-
- Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_DIALTONE:
- {
- zap_isdn_bchan_data_t *data = (zap_isdn_bchan_data_t *)zchan->mod_data;
-
- if (data) {
- data->digit_timeout = zap_time_now() + isdn_data->digit_timeout;
- }
- }
- break;
- case ZAP_CHANNEL_STATE_RING:
- {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_START;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_RESTART:
- {
- zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED;
- sig.event_id = ZAP_SIGEVENT_RESTART;
- status = zap_span_send_signal(zchan->span, &sig);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- break;
- case ZAP_CHANNEL_STATE_PROGRESS_MEDIA:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- return;
- }
- }
- gen->MesType = Q931mes_ALERTING;
- gen->CRVFlag = 1; /* inbound call */
- Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_UP:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_UP;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- return;
- }
- }
- gen->MesType = Q931mes_CONNECT;
- gen->BearerCap = 0;
- gen->CRVFlag = 1; /* inbound call */
- Q931Rx43(&isdn_data->q931, (void *)gen, zchan->caller_data.raw_data_len);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_DIALING:
- if (!(isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) {
- Q931ie_BearerCap BearerCap;
- Q931ie_ChanID ChanID;
- Q931ie_CallingNum CallingNum;
- Q931ie_CallingNum *ptrCallingNum;
- Q931ie_CalledNum CalledNum;
- Q931ie_CalledNum *ptrCalledNum;
- Q931ie_Display Display, *ptrDisplay;
- Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */
- Q931ie_ProgInd Progress; /* Progress Indicator IE */
- int codec = 0;
-
- /*
- * get codec type
- */
- zap_channel_command(zchan->span->channels[zchan->chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec);
-
- /*
- * Q.931 Setup Message
- */
- Q931InitMesGeneric(gen);
- gen->MesType = Q931mes_SETUP;
- gen->CRVFlag = 0; /* outbound(?) */
-
- /*
- * Bearer Capability IE
- */
- Q931InitIEBearerCap(&BearerCap);
- BearerCap.CodStand = Q931_CODING_ITU; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */
- BearerCap.ITC = Q931_ITC_SPEECH; /* Speech */
- BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */
- BearerCap.ITR = Q931_ITR_64K; /* 64k = 16, Packet mode = 0 */
- BearerCap.Layer1Ident = 1;
- BearerCap.UIL1Prot = (codec == ZAP_CODEC_ALAW) ? 3 : 2; /* U-law = 2, A-law = 3 */
- gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap);
-
- /*
- * ChannelID IE
- */
- Q931InitIEChanID(&ChanID);
- ChanID.IntType = ZAP_SPAN_IS_BRI(zchan->span) ? 0 : 1; /* PRI = 1, BRI = 0 */
- ChanID.PrefExcl = ZAP_SPAN_IS_NT(zchan->span) ? 1 : 0; /* Exclusive in NT-mode = 1, Preferred otherwise = 0 */
- if(ChanID.IntType) {
- ChanID.InfoChanSel = 1; /* None = 0, See Slot = 1, Any = 3 */
- ChanID.ChanMapType = 3; /* B-Chan */
- ChanID.ChanSlot = (unsigned char)zchan->chan_id;
- } else {
- ChanID.InfoChanSel = (unsigned char)zchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */
- }
- gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
-
- /*
- * Progress IE
- */
- Q931InitIEProgInd(&Progress);
- Progress.CodStand = Q931_CODING_ITU; /* 0 = ITU */
- Progress.Location = 0; /* 0 = User, 1 = Private Network */
- Progress.ProgDesc = 3; /* 1 = Not end-to-end ISDN */
- gen->ProgInd = Q931AppendIE((L3UCHAR *)gen, (L3UCHAR *)&Progress);
-
- /*
- * Display IE
- */
- if (!(isdn_data->opts & ZAP_ISDN_OPT_OMIT_DISPLAY_IE)) {
- Q931InitIEDisplay(&Display);
- Display.Size = Display.Size + (unsigned char)strlen(zchan->caller_data.cid_name);
- gen->Display = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &Display);
- ptrDisplay = Q931GetIEPtr(gen->Display, gen->buf);
- zap_copy_string((char *)ptrDisplay->Display, zchan->caller_data.cid_name, strlen(zchan->caller_data.cid_name)+1);
- }
-
- /*
- * CallingNum IE
- */
- Q931InitIECallingNum(&CallingNum);
- CallingNum.TypNum = zchan->caller_data.ani.type;
- CallingNum.NumPlanID = Q931_NUMPLAN_E164;
- CallingNum.PresInd = Q931_PRES_ALLOWED;
- CallingNum.ScreenInd = Q931_SCREEN_USER_NOT_SCREENED;
- CallingNum.Size = CallingNum.Size + (unsigned char)strlen(zchan->caller_data.cid_num.digits);
- gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum);
- ptrCallingNum = Q931GetIEPtr(gen->CallingNum, gen->buf);
- zap_copy_string((char *)ptrCallingNum->Digit, zchan->caller_data.cid_num.digits, strlen(zchan->caller_data.cid_num.digits)+1);
-
- /*
- * CalledNum IE
- */
- Q931InitIECalledNum(&CalledNum);
- CalledNum.TypNum = Q931_TON_UNKNOWN;
- CalledNum.NumPlanID = Q931_NUMPLAN_E164;
- CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani.digits);
- gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum);
- ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf);
- zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani.digits, strlen(zchan->caller_data.ani.digits)+1);
-
- /*
- * High-Layer Compatibility IE (Note: Required for AVM FritzBox)
- */
- Q931InitIEHLComp(&HLComp);
- HLComp.CodStand = Q931_CODING_ITU; /* ITU */
- HLComp.Interpret = 4; /* only possible value */
- HLComp.PresMeth = 1; /* High-layer protocol profile */
- HLComp.HLCharID = Q931_HLCHAR_TELEPHONY; /* Telephony = 1, Fax G2+3 = 4, Fax G4 = 65 (Class I)/ 68 (Class II or III) */ /* TODO: make accessible from user layer */
- gen->HLComp = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &HLComp);
-
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
- isdn_data->channels_local_crv[gen->CRV] = zchan;
- }
- break;
- case ZAP_CHANNEL_STATE_HANGUP_COMPLETE:
- {
- /* reply RELEASE with RELEASE_COMPLETE message */
- if(zchan->last_state == ZAP_CHANNEL_STATE_HANGUP) {
- gen->MesType = Q931mes_RELEASE_COMPLETE;
-
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
- }
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- break;
- case ZAP_CHANNEL_STATE_HANGUP:
- {
- Q931ie_Cause cause;
-
- zap_log(ZAP_LOG_DEBUG, "Hangup: Direction %s\n", zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? "Outbound" : "Inbound");
-
- gen->CRVFlag = zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? 0 : 1;
-
- cause.IEId = Q931ie_CAUSE;
- cause.Size = sizeof(Q931ie_Cause);
- cause.CodStand = Q931_CODING_ITU; /* ITU */
- cause.Location = 1; /* private network */
- cause.Recom = 1; /* */
-
- /*
- * BRI PTMP needs special handling here...
- * TODO: cleanup / refine (see above)
- */
- if (zchan->last_state == ZAP_CHANNEL_STATE_RING) {
- /*
- * inbound call [was: number unknown (= not found in routing state)]
- * (in Q.931 spec terms: Reject request)
- */
- gen->MesType = Q931mes_RELEASE_COMPLETE;
-
- //cause.Value = (unsigned char) ZAP_CAUSE_UNALLOCATED;
- cause.Value = (unsigned char) zchan->caller_data.hangup_cause;
- *cause.Diag = '\0';
- gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
-
- /* we're done, release channel */
- //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- else if (zchan->last_state <= ZAP_CHANNEL_STATE_PROGRESS) {
- /*
- * just release all unanswered calls [was: inbound call, remote side hung up before we answered]
- */
- gen->MesType = Q931mes_RELEASE;
-
- cause.Value = (unsigned char) zchan->caller_data.hangup_cause;
- *cause.Diag = '\0';
- gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
- Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size);
-
- /* this will be triggered by the RELEASE_COMPLETE reply */
- /* zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); */
- }
- else {
- /*
- * call connected, hangup
- */
- gen->MesType = Q931mes_DISCONNECT;
-
- cause.Value = (unsigned char) zchan->caller_data.hangup_cause;
- *cause.Diag = '\0';
- gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
- Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_TERMINATING:
- {
- zap_log(ZAP_LOG_DEBUG, "Terminating: Direction %s\n", zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? "Outbound" : "Inbound");
-
- sig.event_id = ZAP_SIGEVENT_STOP;
- status = zap_span_send_signal(zchan->span, &sig);
- gen->MesType = Q931mes_RELEASE;
- gen->CRVFlag = zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? 0 : 1;
- Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size);
- }
- default:
- break;
- }
-}
-
-/**
- * \brief Checks current state on a span
- * \param span Span to check status on
- */
-static __inline__ void check_state(zap_span_t *span)
-{
- if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) {
- uint32_t j;
- zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE);
- for(j = 1; j <= span->chan_count; j++) {
- if (zap_test_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) {
- zap_mutex_lock(span->channels[j]->mutex);
- zap_clear_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE);
- state_advance(span->channels[j]);
- zap_channel_complete_state(span->channels[j]);
- zap_mutex_unlock(span->channels[j]->mutex);
- }
- }
- }
-}
-
-/**
- * \brief Processes Openzap event on a span
- * \param span Span to process event on
- * \param event Event to process
- * \return Success or failure
- */
-static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event)
-{
- zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n",
- zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state));
-
- switch(event->enum_id) {
- case ZAP_OOB_ALARM_TRAP:
- {
- if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) {
- if (event->channel->type == ZAP_CHAN_TYPE_B) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART);
- }
- }
-
-
- zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED);
-
-
- zap_channel_get_alarms(event->channel);
- zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) has alarms! [%s]\n",
- event->channel->span_id, event->channel->chan_id,
- event->channel->physical_span_id, event->channel->physical_chan_id,
- event->channel->last_error);
- }
- break;
- case ZAP_OOB_ALARM_CLEAR:
- {
-
- zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) alarms Cleared!\n", event->channel->span_id, event->channel->chan_id,
- event->channel->physical_span_id, event->channel->physical_chan_id);
-
- zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED);
- zap_channel_get_alarms(event->channel);
- }
- break;
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Checks for events on a span
- * \param span Span to check for events
- */
-static __inline__ void check_events(zap_span_t *span)
-{
- zap_status_t status;
-
- status = zap_span_poll_event(span, 5);
-
- switch(status) {
- case ZAP_SUCCESS:
- {
- zap_event_t *event;
- while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
- if (event->enum_id == ZAP_OOB_NOOP) {
- continue;
- }
- if (process_event(span, event) != ZAP_SUCCESS) {
- break;
- }
- }
- }
- break;
- case ZAP_FAIL:
- {
- zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running());
- }
- break;
- default:
- break;
- }
-}
-
-/**
- * \brief Retrieves tone generation output to be sent
- * \param ts Teletone generator
- * \param map Tone map
- * \return -1 on error, 0 on success
- */
-static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
-{
- zap_buffer_t *dt_buffer = ts->user_data;
- int wrote;
-
- if (!dt_buffer) {
- return -1;
- }
- wrote = teletone_mux_tones(ts, map);
- zap_buffer_write(dt_buffer, ts->buffer, wrote * 2);
- return 0;
-}
-
-/**
- * \brief Main thread function for tone generation on a span
- * \param me Current thread
- * \param obj Span to generate tones on
- */
-static void *zap_isdn_tones_run(zap_thread_t *me, void *obj)
-{
- zap_span_t *span = (zap_span_t *) obj;
- zap_isdn_data_t *isdn_data = span->signal_data;
- zap_buffer_t *dt_buffer = NULL;
- teletone_generation_session_t ts = {{{{0}}}};
- unsigned char frame[1024];
- uint32_t x;
- int interval = 0;
- int offset = 0;
-
- zap_log(ZAP_LOG_DEBUG, "ISDN tones thread starting.\n");
- zap_set_flag(isdn_data, ZAP_ISDN_TONES_RUNNING);
-
- if (zap_buffer_create(&dt_buffer, 1024, 1024, 0) != ZAP_SUCCESS) {
- snprintf(isdn_data->dchan->last_error, sizeof(isdn_data->dchan->last_error), "memory error!");
- zap_log(ZAP_LOG_ERROR, "MEM ERROR\n");
- goto done;
- }
- zap_buffer_set_loops(dt_buffer, -1);
-
- /* get a tone generation friendly interval to avoid distortions */
- for (x = 1; x <= span->chan_count; x++) {
- if (span->channels[x]->type != ZAP_CHAN_TYPE_DQ921) {
- zap_channel_command(span->channels[x], ZAP_COMMAND_GET_INTERVAL, &interval);
- break;
- }
- }
- if (!interval) {
- interval = 20;
- }
- zap_log(ZAP_LOG_NOTICE, "Tone generating interval %d\n", interval);
-
- /* init teletone */
- teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
- ts.rate = 8000;
- ts.duration = ts.rate;
-
- /* main loop */
- while(zap_running() && zap_test_flag(isdn_data, ZAP_ISDN_TONES_RUNNING) && !zap_test_flag(isdn_data, ZAP_ISDN_STOP)) {
- zap_wait_flag_t flags;
- zap_status_t status;
- int last_chan_state = 0;
- int gated = 0;
- L2ULONG now = zap_time_now();
-
- /*
- * check b-channel states and generate & send tones if neccessary
- */
- for (x = 1; x <= span->chan_count; x++) {
- zap_channel_t *zchan = span->channels[x];
- zap_size_t len = sizeof(frame), rlen;
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
- continue;
- }
-
- /*
- * Generate tones based on current bchan state
- * (Recycle buffer content if succeeding channels share the
- * same state, this saves some cpu cycles)
- */
- switch (zchan->state) {
- case ZAP_CHANNEL_STATE_DIALTONE:
- {
- zap_isdn_bchan_data_t *data = (zap_isdn_bchan_data_t *)zchan->mod_data;
-
- /* check overlap dial timeout first before generating tone */
- if (data && data->digit_timeout && data->digit_timeout <= now) {
- if (strlen(zchan->caller_data.dnis.digits) > 0) {
- zap_log(ZAP_LOG_DEBUG, "Overlap dial timeout, advancing to RING state\n");
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING);
- } else {
- /* no digits received, hangup */
- zap_log(ZAP_LOG_DEBUG, "Overlap dial timeout, no digits received, going to HANGUP state\n");
- zchan->caller_data.hangup_cause = ZAP_CAUSE_RECOVERY_ON_TIMER_EXPIRE; /* TODO: probably wrong cause value */
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- data->digit_timeout = 0;
- continue;
- }
-
- if (last_chan_state != zchan->state) {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]);
- last_chan_state = zchan->state;
- }
- }
- break;
-
- case ZAP_CHANNEL_STATE_RING:
- {
- if (last_chan_state != zchan->state) {
- zap_buffer_zero(dt_buffer);
- teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]);
- last_chan_state = zchan->state;
- }
- }
- break;
-
- default: /* Not in a tone generating state, go to next round */
- continue;
- }
-
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- continue;
- }
- zap_log(ZAP_LOG_NOTICE, "Successfully opened channel %d:%d\n", zchan->span_id, zchan->chan_id);
- }
-
- flags = ZAP_READ;
-
- status = zap_channel_wait(zchan, &flags, (gated) ? 0 : interval);
- switch(status) {
- case ZAP_FAIL:
- continue;
-
- case ZAP_TIMEOUT:
- gated = 1;
- continue;
-
- default:
- if (!(flags & ZAP_READ)) {
- continue;
- }
- }
- gated = 1;
-
- status = zap_channel_read(zchan, frame, &len);
- if (status != ZAP_SUCCESS || len <= 0) {
- continue;
- }
-
- if (zchan->effective_codec != ZAP_CODEC_SLIN) {
- len *= 2;
- }
-
- /* seek to current offset */
- zap_buffer_seek(dt_buffer, offset);
-
- rlen = zap_buffer_read_loop(dt_buffer, frame, len);
-
- if (zchan->effective_codec != ZAP_CODEC_SLIN) {
- zio_codec_t codec_func = NULL;
-
- if (zchan->native_codec == ZAP_CODEC_ULAW) {
- codec_func = zio_slin2ulaw;
- } else if (zchan->native_codec == ZAP_CODEC_ALAW) {
- codec_func = zio_slin2alaw;
- }
-
- if (codec_func) {
- status = codec_func(frame, sizeof(frame), &rlen);
- } else {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!");
- goto done;
- }
- }
- zap_channel_write(zchan, frame, sizeof(frame), &rlen);
- }
-
- /*
- * sleep a bit if there was nothing to do
- */
- if (!gated) {
- zap_sleep(interval);
- }
-
- offset += (ts.rate / (1000 / interval)) << 1;
- if (offset >= ts.rate) {
- offset = 0;
- }
- }
-
-done:
- if (ts.buffer) {
- teletone_destroy_session(&ts);
- }
-
- if (dt_buffer) {
- zap_buffer_destroy(&dt_buffer);
- }
-
- zap_log(ZAP_LOG_DEBUG, "ISDN tone thread ended.\n");
- zap_clear_flag(isdn_data, ZAP_ISDN_TONES_RUNNING);
-
- return NULL;
-}
-
-/**
- * \brief Main thread function for an ISDN span
- * \param me Current thread
- * \param obj Span to monitor
- */
-static void *zap_isdn_run(zap_thread_t *me, void *obj)
-{
- zap_span_t *span = (zap_span_t *) obj;
- zap_isdn_data_t *isdn_data = span->signal_data;
- unsigned char frame[1024];
- zap_size_t len = sizeof(frame);
- int errs = 0;
-
-#ifdef WIN32
- timeBeginPeriod(1);
-#endif
-
- zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n");
- zap_set_flag(isdn_data, ZAP_ISDN_RUNNING);
-
- Q921Start(&isdn_data->q921);
-
- while(zap_running() && zap_test_flag(isdn_data, ZAP_ISDN_RUNNING) && !zap_test_flag(isdn_data, ZAP_ISDN_STOP)) {
- zap_wait_flag_t flags = ZAP_READ;
- zap_status_t status = zap_channel_wait(isdn_data->dchan, &flags, 100);
-
- Q921TimerTick(&isdn_data->q921);
- Q931TimerTick(&isdn_data->q931);
- check_state(span);
- check_events(span);
-
- /*
- *
- */
- switch(status) {
- case ZAP_FAIL:
- {
- zap_log(ZAP_LOG_ERROR, "D-Chan Read Error!\n");
- snprintf(span->last_error, sizeof(span->last_error), "D-Chan Read Error!");
- if (++errs == 10) {
- isdn_data->dchan->state = ZAP_CHANNEL_STATE_UP;
- goto done;
- }
- }
- break;
- case ZAP_TIMEOUT:
- {
- errs = 0;
- }
- break;
- default:
- {
- errs = 0;
- if (flags & ZAP_READ) {
-
- if (zap_test_flag(isdn_data->dchan, ZAP_CHANNEL_SUSPENDED)) {
- zap_clear_flag_all(span, ZAP_CHANNEL_SUSPENDED);
- }
- len = sizeof(frame);
- if (zap_channel_read(isdn_data->dchan, frame, &len) == ZAP_SUCCESS) {
-#ifdef IODEBUG
- char bb[4096] = "";
- print_hex_bytes(frame, len, bb, sizeof(bb));
-
- print_bits(frame, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
- zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb);
-#endif
-
- Q921QueueHDLCFrame(&isdn_data->q921, frame, (int)len);
- Q921Rx12(&isdn_data->q921);
- }
- } else {
- zap_log(ZAP_LOG_DEBUG, "No Read FLAG!\n");
- }
- }
- break;
- }
- }
-
- done:
- zap_channel_close(&isdn_data->dchans[0]);
- zap_channel_close(&isdn_data->dchans[1]);
- zap_clear_flag(isdn_data, ZAP_ISDN_RUNNING);
-
-#ifdef WIN32
- timeEndPeriod(1);
-#endif
-
- zap_log(ZAP_LOG_DEBUG, "ISDN thread ended.\n");
- return NULL;
-}
-
-/**
- * \brief Openzap ISDN signaling module initialisation
- * \return Success
- */
-static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init)
-{
- Q931Initialize();
-
- Q921SetGetTimeCB(zap_time_now);
- Q931SetGetTimeCB(zap_time_now);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Receives a Q931 indication message
- * \param pvt Span were message is coming from
- * \param ind Q931 indication
- * \param tei Terminal Endpoint Identifier
- * \param msg Message string
- * \param mlen Message string length
- * \return 0 on success
- */
-static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3INT mlen)
-{
- int offset = 4;
- char bb[4096] = "";
-
- switch(ind) {
- case Q921_DL_UNIT_DATA:
- offset = 3;
-
- case Q921_DL_DATA:
- print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb));
-#ifdef HAVE_LIBPCAP
- /*Q931ToPcap*/
- if(do_q931ToPcap==1){
- zap_span_t *span = (zap_span_t *) pvt;
- if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 0) != ZAP_SUCCESS){
- zap_log(ZAP_LOG_WARNING, "Couldn't write Q931 buffer to pcap file!\n");
- }
- }
- /*Q931ToPcap done*/
-#endif
- zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb);
- break;
-
- default:
- break;
- }
-
- return Q921Rx32(pvt, ind, tei, msg, mlen);
-}
-
-/**
- * \brief Logs Q921 message
- * \param pvt Span were message is coming from
- * \param level Q921 log level
- * \param msg Message string
- * \param size Message string length
- * \return 0
- */
-static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size)
-{
- zap_span_t *span = (zap_span_t *) pvt;
-
- zap_log("Span", "Q.921", span->span_id, (int)level, "%s", msg);
- return 0;
-}
-
-/**
- * \brief Logs Q931 message
- * \param pvt Span were message is coming from
- * \param level Q931 log level
- * \param msg Message string
- * \param size Message string length
- * \return 0
- */
-static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size)
-{
- zap_span_t *span = (zap_span_t *) pvt;
-
- zap_log("Span", "Q.931", span->span_id, (int)level, "%s", msg);
- return 0;
-}
-/**
- * \brief ISDN state map
- */
-static zap_state_map_t isdn_state_map = {
- {
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_ANY_STATE},
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- {ZAP_CHANNEL_STATE_DIALING, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DIALING, ZAP_END},
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_UP, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}
- },
-
- /****************************************/
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_ANY_STATE},
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- {ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_RING, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DIALTONE, ZAP_END},
- {ZAP_CHANNEL_STATE_RING, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_UP, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_PROGRESS_MEDIA,
- ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_UP, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_UP, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- },
-
-
- }
-};
-
-/**
- * \brief Stops an ISDN span
- * \param span Span to halt
- * \return Success
- *
- * Sets a stop flag and waits for the threads to end
- */
-static zap_status_t zap_isdn_stop(zap_span_t *span)
-{
- zap_isdn_data_t *isdn_data = span->signal_data;
-
- if (!zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) {
- return ZAP_FAIL;
- }
-
- zap_set_flag(isdn_data, ZAP_ISDN_STOP);
-
- while(zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) {
- zap_sleep(100);
- }
-
- while(zap_test_flag(isdn_data, ZAP_ISDN_TONES_RUNNING)) {
- zap_sleep(100);
- }
-
- return ZAP_SUCCESS;
-
-}
-
-/**
- * \brief Starts an ISDN span
- * \param span Span to halt
- * \return Success or failure
- *
- * Launches a thread to monitor the span and a thread to generate tones on the span
- */
-static zap_status_t zap_isdn_start(zap_span_t *span)
-{
- zap_status_t ret;
- zap_isdn_data_t *isdn_data = span->signal_data;
-
- if (zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) {
- return ZAP_FAIL;
- }
-
- zap_clear_flag(isdn_data, ZAP_ISDN_STOP);
- ret = zap_thread_create_detached(zap_isdn_run, span);
-
- if (ret != ZAP_SUCCESS) {
- return ret;
- }
-
- if (ZAP_SPAN_IS_NT(span) && !(isdn_data->opts & ZAP_ISDN_OPT_DISABLE_TONES)) {
- ret = zap_thread_create_detached(zap_isdn_tones_run, span);
- }
- return ret;
-}
-
-/**
- * \brief Parses an option string to flags
- * \param in String to parse for configuration options
- * \return Flags
- */
-static uint32_t parse_opts(const char *in)
-{
- uint32_t flags = 0;
-
- if (!in) {
- return 0;
- }
-
- if (strstr(in, "suggest_channel")) {
- flags |= ZAP_ISDN_OPT_SUGGEST_CHANNEL;
- }
-
- if (strstr(in, "omit_display")) {
- flags |= ZAP_ISDN_OPT_OMIT_DISPLAY_IE;
- }
-
- if (strstr(in, "disable_tones")) {
- flags |= ZAP_ISDN_OPT_DISABLE_TONES;
- }
-
- return flags;
-}
-
-/**
- * \brief Initialises an ISDN span from configuration variables
- * \param span Span to configure
- * \param sig_cb Callback function for event signals
- * \param ap List of configuration variables
- * \return Success or failure
- */
-static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span)
-{
- uint32_t i, x = 0;
- zap_channel_t *dchans[2] = {0};
- zap_isdn_data_t *isdn_data;
- const char *tonemap = "us";
- char *var, *val;
- Q931Dialect_t dialect = Q931_Dialect_National;
- int32_t digit_timeout = 0;
- int q921loglevel = -1;
- int q931loglevel = -1;
-#ifdef HAVE_LIBPCAP
- int q931topcap = -1; /*Q931ToPcap*/
- int openPcap = 0; /*Flag: open Pcap file please*/
-#endif
-
- if (span->signal_type) {
-#ifdef HAVE_LIBPCAP
- /*Q931ToPcap: Get the content of the q931topcap and pcapfilename args given by mod_openzap */
- while((var = va_arg(ap, char *))) {
- if (!strcasecmp(var, "q931topcap")) {
- q931topcap = va_arg(ap, int);
- if(q931topcap==1) {
- /*PCAP on*/;
- openPcap=1;
- } else if (q931topcap==0) {
- /*PCAP off*/
- if (closePcapFile() != ZAP_SUCCESS) return ZAP_FAIL;
- do_q931ToPcap=0;
- return ZAP_SUCCESS;
- }
- }
- if (!strcasecmp(var, "pcapfilename")) {
- /*Put filename into global var*/
- pcapfn = va_arg(ap, char*);
- }
- }
- /*We know now, that user wants to enable Q931ToPcap and what file name he wants, so open it please*/
- if(openPcap==1){
- if(openPcapFile() != ZAP_SUCCESS) return ZAP_FAIL;
- do_q931ToPcap=1;
- return ZAP_SUCCESS;
- }
- /*Q931ToPcap done*/
-#endif
- snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type);
- return ZAP_FAIL;
- }
-
- if (span->trunk_type >= ZAP_TRUNK_NONE) {
- zap_log(ZAP_LOG_WARNING, "Invalid trunk type '%s' defaulting to T1.\n", zap_trunk_type2str(span->trunk_type));
- span->trunk_type = ZAP_TRUNK_T1;
- }
-
- for(i = 1; i <= span->chan_count; i++) {
- if (span->channels[i]->type == ZAP_CHAN_TYPE_DQ921) {
- if (x > 1) {
- snprintf(span->last_error, sizeof(span->last_error), "Span has more than 2 D-Channels!");
- return ZAP_FAIL;
- } else {
- if (zap_channel_open(span->span_id, i, &dchans[x]) == ZAP_SUCCESS) {
- zap_log(ZAP_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, dchans[x]->span_id, dchans[x]->chan_id);
- dchans[x]->state = ZAP_CHANNEL_STATE_UP;
- x++;
- }
- }
- }
- }
-
- if (!x) {
- snprintf(span->last_error, sizeof(span->last_error), "Span has no D-Channels!");
- return ZAP_FAIL;
- }
-
- isdn_data = malloc(sizeof(*isdn_data));
- assert(isdn_data != NULL);
- memset(isdn_data, 0, sizeof(*isdn_data));
-
- isdn_data->mode = Q931_TE;
- dialect = Q931_Dialect_National;
-
- while((var = va_arg(ap, char *))) {
- if (!strcasecmp(var, "mode")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- isdn_data->mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT;
- } else if (!strcasecmp(var, "dialect")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- dialect = q931_str2Q931Dialect_type(val);
- if (dialect == Q931_Dialect_Count) {
- return ZAP_FAIL;
- }
- } else if (!strcasecmp(var, "opts")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- isdn_data->opts = parse_opts(val);
- } else if (!strcasecmp(var, "tonemap")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- tonemap = (const char *)val;
- } else if (!strcasecmp(var, "digit_timeout")) {
- int *optp;
- if (!(optp = va_arg(ap, int *))) {
- break;
- }
- digit_timeout = *optp;
- } else if (!strcasecmp(var, "q921loglevel")) {
- q921loglevel = va_arg(ap, int);
- if (q921loglevel < Q921_LOG_NONE) {
- q921loglevel = Q921_LOG_NONE;
- } else if (q921loglevel > Q921_LOG_DEBUG) {
- q921loglevel = Q921_LOG_DEBUG;
- }
- } else if (!strcasecmp(var, "q931loglevel")) {
- q931loglevel = va_arg(ap, int);
- if (q931loglevel < Q931_LOG_NONE) {
- q931loglevel = Q931_LOG_NONE;
- } else if (q931loglevel > Q931_LOG_DEBUG) {
- q931loglevel = Q931_LOG_DEBUG;
- }
- } else {
- snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
- return ZAP_FAIL;
- }
- }
-
-
- if (!digit_timeout) {
- digit_timeout = DEFAULT_DIGIT_TIMEOUT;
- }
- else if (digit_timeout < 3000 || digit_timeout > 30000) {
- zap_log(ZAP_LOG_WARNING, "Digit timeout %d ms outside of range (3000 - 30000 ms), using default (10000 ms)\n", digit_timeout);
- digit_timeout = DEFAULT_DIGIT_TIMEOUT;
- }
-
- /* allocate per b-chan data */
- if (isdn_data->mode == Q931_NT) {
- zap_isdn_bchan_data_t *data;
-
- data = malloc((span->chan_count - 1) * sizeof(zap_isdn_bchan_data_t));
- if (!data) {
- return ZAP_FAIL;
- }
-
- for (i = 1; i <= span->chan_count; i++, data++) {
- if (span->channels[i]->type == ZAP_CHAN_TYPE_B) {
- span->channels[i]->mod_data = data;
- memset(data, 0, sizeof(zap_isdn_bchan_data_t));
- }
- }
- }
-
- span->start = zap_isdn_start;
- span->stop = zap_isdn_stop;
- span->signal_cb = sig_cb;
- isdn_data->dchans[0] = dchans[0];
- isdn_data->dchans[1] = dchans[1];
- isdn_data->dchan = isdn_data->dchans[0];
- isdn_data->digit_timeout = digit_timeout;
-
- Q921_InitTrunk(&isdn_data->q921,
- 0,
- 0,
- isdn_data->mode,
- span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP,
- 0,
- zap_isdn_921_21,
- (Q921Tx23CB_t)zap_isdn_921_23,
- span,
- &isdn_data->q931);
-
- Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data);
- Q921SetLogLevel(&isdn_data->q921, (Q921LogLevel_t)q921loglevel);
-
- Q931Api_InitTrunk(&isdn_data->q931,
- dialect,
- isdn_data->mode,
- span->trunk_type,
- zap_isdn_931_34,
- (Q931Tx32CB_t)q931_rx_32,
- zap_isdn_931_err,
- &isdn_data->q921,
- span);
-
- Q931SetLogCB(&isdn_data->q931, &zap_isdn_q931_log, isdn_data);
- Q931SetLogLevel(&isdn_data->q931, (Q931LogLevel_t)q931loglevel);
-
- isdn_data->q931.autoRestartAck = 1;
- isdn_data->q931.autoConnectAck = 0;
- isdn_data->q931.autoServiceAck = 1;
- span->signal_data = isdn_data;
- span->signal_type = ZAP_SIGTYPE_ISDN;
- span->outgoing_call = isdn_outgoing_call;
-
- if ((isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) {
- span->channel_request = isdn_channel_request;
- span->suggest_chan_id = 1;
- }
- span->state_map = &isdn_state_map;
-
- zap_span_load_tones(span, tonemap);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Openzap ISDN signaling module definition
- */
-EX_DECLARE_DATA zap_module_t zap_module = {
- "isdn",
- NULL,
- close_pcap,
- zap_isdn_init,
- zap_isdn_configure_span,
- NULL
-};
-
-
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h
deleted file mode 100644
index 7e1e70ea11..0000000000
--- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_ISDN_H
-#define ZAP_ISDN_H
-#include "openzap.h"
-
-#define DEFAULT_DIGIT_TIMEOUT 10000 /* default overlap timeout: 10 seconds */
-
-
-typedef enum {
- ZAP_ISDN_OPT_NONE = 0,
- ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0),
- ZAP_ISDN_OPT_OMIT_DISPLAY_IE = (1 << 1), /*!< Do not send Caller name in outgoing SETUP message (= Display IE) */
- ZAP_ISDN_OPT_DISABLE_TONES = (1 << 2), /*!< Disable tone generating thread (NT mode) */
-
- ZAP_ISDN_OPT_MAX = (2 << 0)
-} zap_isdn_opts_t;
-
-typedef enum {
- ZAP_ISDN_RUNNING = (1 << 0),
- ZAP_ISDN_TONES_RUNNING = (1 << 1),
- ZAP_ISDN_STOP = (1 << 2)
-} zap_isdn_flag_t;
-
-
-struct zap_isdn_data {
- Q921Data_t q921;
- Q931_TrunkInfo_t q931;
- zap_channel_t *dchan;
- zap_channel_t *dchans[2];
- struct zap_sigmsg sigmsg;
- uint32_t flags;
- int32_t mode;
- int32_t digit_timeout;
- zap_isdn_opts_t opts;
- zap_caller_data_t *outbound_crv[32768];
- zap_channel_t *channels_local_crv[32768];
- zap_channel_t *channels_remote_crv[32768];
-};
-
-typedef struct zap_isdn_data zap_isdn_data_t;
-
-
-/* b-channel private data */
-struct zap_isdn_bchan_data
-{
- L2ULONG digit_timeout;
-};
-
-typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t;
-
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
-
diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c
deleted file mode 100644
index 77194416f1..0000000000
--- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * Copyright (c) 2009-2012, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-//#define IODEBUG
-
-#include "openzap.h"
-#include "lpwrap_pri.h"
-#ifndef HAVE_GETTIMEOFDAY
-
-#ifdef WIN32
-#include
-
-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 lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = {
- {0, LPWRAP_PRI_EVENT_ANY, "ANY"},
- {1, LPWRAP_PRI_EVENT_DCHAN_UP, "DCHAN_UP"},
- {2, LPWRAP_PRI_EVENT_DCHAN_DOWN, "DCHAN_DOWN"},
- {3, LPWRAP_PRI_EVENT_RESTART, "RESTART"},
- {4, LPWRAP_PRI_EVENT_CONFIG_ERR, "CONFIG_ERR"},
- {5, LPWRAP_PRI_EVENT_RING, "RING"},
- {6, LPWRAP_PRI_EVENT_HANGUP, "HANGUP"},
- {7, LPWRAP_PRI_EVENT_RINGING, "RINGING"},
- {8, LPWRAP_PRI_EVENT_ANSWER, "ANSWER"},
- {9, LPWRAP_PRI_EVENT_HANGUP_ACK, "HANGUP_ACK"},
- {10, LPWRAP_PRI_EVENT_RESTART_ACK, "RESTART_ACK"},
- {11, LPWRAP_PRI_EVENT_FACNAME, "FACNAME"},
- {12, LPWRAP_PRI_EVENT_INFO_RECEIVED, "INFO_RECEIVED"},
- {13, LPWRAP_PRI_EVENT_PROCEEDING, "PROCEEDING"},
- {14, LPWRAP_PRI_EVENT_SETUP_ACK, "SETUP_ACK"},
- {15, LPWRAP_PRI_EVENT_HANGUP_REQ, "HANGUP_REQ"},
- {16, LPWRAP_PRI_EVENT_NOTIFY, "NOTIFY"},
- {17, LPWRAP_PRI_EVENT_PROGRESS, "PROGRESS"},
- {18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"},
- {19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"},
-};
-
-#define LINE "--------------------------------------------------------------------------------"
-
-const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id)
-{
- return LPWRAP_PRI_EVENT_LIST[event_id].name;
-}
-
-static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
-{
- struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri);
- zap_size_t len = buflen;
- int res;
- zap_status_t zst;
-
- if ((zst = zap_channel_read(spri->dchan, buf, &len)) != ZAP_SUCCESS) {
- if (zst == ZAP_FAIL) {
- zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
- spri->errs++;
- } else {
- zap_log(ZAP_LOG_CRIT, "span %d D-READ TIMEOUT\n", spri->span->span_id);
- }
-
- zap_clear_flag(spri, LPWRAP_PRI_READY);
- return -1;
- }
- spri->errs = 0;
- res = (int)len;
- memset(&((unsigned char*)buf)[res],0,2);
- res+=2;
-
-#ifdef IODEBUG
- {
- char bb[2048] = { 0 };
-
- print_hex_bytes(buf, res - 2, bb, sizeof(bb));
- zap_log(ZAP_LOG_DEBUG, "READ %d\n", res-2);
- }
-#endif
-
- return res;
-}
-
-static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
-{
- struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri);
- zap_size_t len = buflen -2;
-
- if (zap_channel_write(spri->dchan, buf, buflen, &len) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
- zap_clear_flag(spri, LPWRAP_PRI_READY);
- return -1;
- }
-
-#ifdef IODEBUG
- {
- char bb[2048] = { 0 };
-
- print_hex_bytes(buf, buflen - 2, bb, sizeof(bb));
- zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", (int)buflen-2);
- }
-#endif
-
- return (int) buflen;
-}
-
-int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug)
-{
- int ret = -1;
-
- memset(spri, 0, sizeof(struct lpwrap_pri));
-
- spri->dchan = dchan;
- spri->span = span;
-
- if ((spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){
- unsigned char buf[4] = { 0 };
- size_t buflen = sizeof(buf), len = 0;
- pri_set_debug(spri->pri, debug);
- ret = 0;
- zap_set_flag(spri, LPWRAP_PRI_READY);
- zap_channel_write(spri->dchan, buf, buflen, &len);
- } else {
- fprintf(stderr, "Unable to create PRI\n");
- }
-
- return ret;
-}
-
-
-int lpwrap_one_loop(struct lpwrap_pri *spri)
-{
- fd_set rfds, efds;
- struct timeval now = {0,0}, *next;
- pri_event *event;
- event_handler handler;
- int sel;
-
- if (spri->on_loop) {
- if ((sel = spri->on_loop(spri)) < 0) {
- return sel;
- }
- }
-
- if (spri->errs >= 2) {
- spri->errs = 0;
- return -1;
- }
-
- 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(pri_fd(spri->pri), &rfds);
- FD_SET(pri_fd(spri->pri), &efds);
-
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
- now.tv_sec = 0;
- now.tv_usec = 100000;
-
- sel = select(pri_fd(spri->pri) + 1, &rfds, NULL, &efds, &now);
-
- event = NULL;
-
- if (!sel) {
- if ((next = pri_schedule_next(spri->pri))) {
- gettimeofday(&now, NULL);
- if (now.tv_sec >= next->tv_sec && (now.tv_usec >= next->tv_usec || next->tv_usec <= 100000)) {
- //zap_log(ZAP_LOG_DEBUG, "Check event\n");
- event = pri_schedule_run(spri->pri);
- }
- }
- } else if (sel > 0) {
- event = pri_check_event(spri->pri);
- }
-
- if (event) {
- /* 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 {
- zap_log(ZAP_LOG_CRIT, "No event handler found for event %d.\n", event->e);
- }
- }
-
-
- return sel;
-
-
- if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_IO_FAIL] ? spri->eventmap[LPWRAP_PRI_EVENT_IO_FAIL] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
- handler(spri, LPWRAP_PRI_EVENT_IO_FAIL, NULL);
- }
-
- return -1;
-}
-
-int lpwrap_run_pri(struct lpwrap_pri *spri)
-{
- int ret = 0;
-
- for (;;){
- ret = lpwrap_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
- zap_log(ZAP_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno));
- break;
- }
- }
-
- return ret;
-
-}
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h
deleted file mode 100644
index bd63db15c2..0000000000
--- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2009-2012, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _LPWRAP_PRI_H
-#define _LPWRAP_PRI_H
-#include
-#include
-
-
-#define LPWRAP_MAX_CHAN_PER_SPAN 32
-
-typedef enum {
- LPWRAP_PRI_EVENT_ANY = 0,
- LPWRAP_PRI_EVENT_DCHAN_UP = PRI_EVENT_DCHAN_UP,
- LPWRAP_PRI_EVENT_DCHAN_DOWN = PRI_EVENT_DCHAN_DOWN,
- LPWRAP_PRI_EVENT_RESTART = PRI_EVENT_RESTART,
- LPWRAP_PRI_EVENT_CONFIG_ERR = PRI_EVENT_CONFIG_ERR,
- LPWRAP_PRI_EVENT_RING = PRI_EVENT_RING,
- LPWRAP_PRI_EVENT_HANGUP = PRI_EVENT_HANGUP,
- LPWRAP_PRI_EVENT_RINGING = PRI_EVENT_RINGING,
- LPWRAP_PRI_EVENT_ANSWER = PRI_EVENT_ANSWER,
- LPWRAP_PRI_EVENT_HANGUP_ACK = PRI_EVENT_HANGUP_ACK,
- LPWRAP_PRI_EVENT_RESTART_ACK = PRI_EVENT_RESTART_ACK,
- LPWRAP_PRI_EVENT_FACNAME = PRI_EVENT_FACNAME,
- LPWRAP_PRI_EVENT_INFO_RECEIVED = PRI_EVENT_INFO_RECEIVED,
- LPWRAP_PRI_EVENT_PROCEEDING = PRI_EVENT_PROCEEDING,
- LPWRAP_PRI_EVENT_SETUP_ACK = PRI_EVENT_SETUP_ACK,
- LPWRAP_PRI_EVENT_HANGUP_REQ = PRI_EVENT_HANGUP_REQ,
- LPWRAP_PRI_EVENT_NOTIFY = PRI_EVENT_NOTIFY,
- LPWRAP_PRI_EVENT_PROGRESS = PRI_EVENT_PROGRESS,
- LPWRAP_PRI_EVENT_KEYPAD_DIGIT = PRI_EVENT_KEYPAD_DIGIT,
- LPWRAP_PRI_EVENT_IO_FAIL = 19,
-
- /* don't touch */
- LPWRAP_PRI_EVENT_MAX
-} lpwrap_pri_event_t;
-
-typedef enum {
- LPWRAP_PRI_NETWORK = PRI_NETWORK,
- LPWRAP_PRI_CPE = PRI_CPE
-} lpwrap_pri_node_t;
-
-typedef enum {
- LPWRAP_PRI_SWITCH_UNKNOWN = PRI_SWITCH_UNKNOWN,
- LPWRAP_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,
- LPWRAP_PRI_SWITCH_DMS100 = PRI_SWITCH_DMS100,
- LPWRAP_PRI_SWITCH_LUCENT5E = PRI_SWITCH_LUCENT5E,
- LPWRAP_PRI_SWITCH_ATT4ESS = PRI_SWITCH_ATT4ESS,
- LPWRAP_PRI_SWITCH_EUROISDN_E1 = PRI_SWITCH_EUROISDN_E1,
- LPWRAP_PRI_SWITCH_EUROISDN_T1 = PRI_SWITCH_EUROISDN_T1,
- LPWRAP_PRI_SWITCH_NI1 = PRI_SWITCH_NI1,
- LPWRAP_PRI_SWITCH_GR303_EOC = PRI_SWITCH_GR303_EOC,
- LPWRAP_PRI_SWITCH_GR303_TMC = PRI_SWITCH_GR303_TMC,
- LPWRAP_PRI_SWITCH_QSIG = PRI_SWITCH_QSIG,
-
- /* don't touch */
- LPWRAP_PRI_SWITCH_MAX
-} lpwrap_pri_switch_t;
-
-typedef enum {
- LPWRAP_PRI_READY = (1 << 0)
-} lpwrap_pri_flag_t;
-
-struct lpwrap_pri;
-typedef int (*event_handler)(struct lpwrap_pri *, lpwrap_pri_event_t, pri_event *);
-typedef int (*loop_handler)(struct lpwrap_pri *);
-
-struct lpwrap_pri {
- struct pri *pri;
- zap_span_t *span;
- zap_channel_t *dchan;
- unsigned int flags;
- void *private_info;
- event_handler eventmap[LPWRAP_PRI_EVENT_MAX];
- loop_handler on_loop;
- int errs;
-};
-
-typedef struct lpwrap_pri lpwrap_pri_t;
-
-struct lpwrap_pri_event_list {
- int event_id;
- int pri_event;
- const char *name;
-};
-
-
-
-#define LPWRAP_MAP_PRI_EVENT(spri, event, func) spri.eventmap[event] = func;
-
-const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id);
-int lpwrap_one_loop(struct lpwrap_pri *spri);
-int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug);
-int lpwrap_run_pri(struct lpwrap_pri *spri);
-
-#endif
diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c
deleted file mode 100644
index 674e26129e..0000000000
--- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c
+++ /dev/null
@@ -1,1363 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "openzap.h"
-#include "ozmod_libpri.h"
-
-/**
- * \brief Unloads libpri IO module
- * \return Success
- */
-static ZIO_IO_UNLOAD_FUNCTION(zap_libpri_unload)
-{
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Starts a libpri channel (outgoing call)
- * \param zchan Channel to initiate call on
- * \return Success or failure
- */
-static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call)
-{
- zap_status_t status = ZAP_SUCCESS;
- zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING);
- return status;
-}
-
-/**
- * \brief Requests an libpri channel on a span (outgoing call)
- * \param span Span where to get a channel (unused)
- * \param chan_id Specific channel to get (0 for any) (unused)
- * \param direction Call direction (unused)
- * \param caller_data Caller information (unused)
- * \param zchan Channel to initialise (unused)
- * \return Failure
- */
-static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request)
-{
- return ZAP_FAIL;
-}
-
-#ifdef WIN32
-/**
- * \brief Logs a libpri error
- * \param s Error string
- */
-static void s_pri_error(char *s)
-#else
-/**
- * \brief Logs a libpri error
- * \param pri libpri structure (unused)
- * \param s Error string
- */
-static void s_pri_error(struct pri *pri, char *s)
-#endif
-{
- zap_log(ZAP_LOG_ERROR, "%s", s);
-}
-
-#ifdef WIN32
-/**
- * \brief Logs a libpri message
- * \param s Message string
- */
-static void s_pri_message(char *s)
-#else
-/**
- * \brief Logs a libpri message
- * \param pri libpri structure (unused)
- * \param s Message string
- */
-static void s_pri_message(struct pri *pri, char *s)
-#endif
-{
- zap_log(ZAP_LOG_DEBUG, "%s", s);
-}
-
-/**
- * \brief Parses an option string to flags
- * \param in String to parse for configuration options
- * \return Flags
- */
-static uint32_t parse_opts(const char *in)
-{
- uint32_t flags = 0;
-
- if (!in) {
- return 0;
- }
-
- if (strstr(in, "suggest_channel")) {
- flags |= OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL;
- }
-
- if (strstr(in, "omit_display")) {
- flags |= OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE;
- }
-
- if (strstr(in, "omit_redirecting_number")) {
- flags |= OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE;
- }
-
- return flags;
-}
-
-/**
- * \brief Parses a debug string to flags
- * \param in Debug string to parse for
- * \return Flags
- */
-static int parse_debug(const char *in)
-{
- int flags = 0;
-
- if (!in) {
- return 0;
- }
-
- if (strstr(in, "q921_raw")) {
- flags |= PRI_DEBUG_Q921_RAW;
- }
-
- if (strstr(in, "q921_dump")) {
- flags |= PRI_DEBUG_Q921_DUMP;
- }
-
- if (strstr(in, "q921_state")) {
- flags |= PRI_DEBUG_Q921_STATE;
- }
-
- if (strstr(in, "config")) {
- flags |= PRI_DEBUG_CONFIG;
- }
-
- if (strstr(in, "q931_dump")) {
- flags |= PRI_DEBUG_Q931_DUMP;
- }
-
- if (strstr(in, "q931_state")) {
- flags |= PRI_DEBUG_Q931_STATE;
- }
-
- if (strstr(in, "q931_anomaly")) {
- flags |= PRI_DEBUG_Q931_ANOMALY;
- }
-
- if (strstr(in, "apdu")) {
- flags |= PRI_DEBUG_APDU;
- }
-
- if (strstr(in, "aoc")) {
- flags |= PRI_DEBUG_AOC;
- }
-
- if (strstr(in, "all")) {
- flags |= PRI_DEBUG_ALL;
- }
-
- if (strstr(in, "none")) {
- flags = 0;
- }
-
- return flags;
-}
-
-static zap_io_interface_t zap_libpri_interface;
-
-static zap_status_t zap_libpri_start(zap_span_t *span);
-
-/**
- * \brief API function to kill or debug a libpri span
- * \param stream API stream handler
- * \param data String containing argurments
- * \return Flags
- */
-static ZIO_API_FUNCTION(zap_libpri_api)
-{
- char *mycmd = NULL, *argv[10] = { 0 };
- int argc = 0;
-
- if (data) {
- mycmd = strdup(data);
- argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- }
-
- if (argc == 2) {
- if (!strcasecmp(argv[0], "kill")) {
- int span_id = atoi(argv[1]);
- zap_span_t *span = NULL;
-
- if (zap_span_find_by_name(argv[1], &span) == ZAP_SUCCESS || zap_span_find(span_id, &span) == ZAP_SUCCESS) {
- zap_libpri_data_t *isdn_data = span->signal_data;
-
- if (span->start != zap_libpri_start) {
- stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__);
- goto done;
- }
-
- zap_clear_flag((&isdn_data->spri), LPWRAP_PRI_READY);
- stream->write_function(stream, "%s: +OK killed.\n", __FILE__);
- goto done;
- } else {
- stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__);
- goto done;
- }
- }
- }
-
- if (argc > 2) {
- if (!strcasecmp(argv[0], "debug")) {
- zap_span_t *span = NULL;
-
- if (zap_span_find_by_name(argv[1], &span) == ZAP_SUCCESS) {
- zap_libpri_data_t *isdn_data = span->signal_data;
- if (span->start != zap_libpri_start) {
- stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__);
- goto done;
- }
-
- pri_set_debug(isdn_data->spri.pri, parse_debug(argv[2]));
- stream->write_function(stream, "%s: +OK debug set.\n", __FILE__);
- goto done;
- } else {
- stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__);
- goto done;
- }
- }
-
- }
-
- stream->write_function(stream, "%s: -ERR invalid command.\n", __FILE__);
-
- done:
-
- zap_safe_free(mycmd);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Loads libpri IO module
- * \param zio Openzap IO interface
- * \return Success
- */
-static ZIO_IO_LOAD_FUNCTION(zap_libpri_io_init)
-{
- assert(zio != NULL);
- memset(&zap_libpri_interface, 0, sizeof(zap_libpri_interface));
-
- zap_libpri_interface.name = "libpri";
- zap_libpri_interface.api = zap_libpri_api;
-
- *zio = &zap_libpri_interface;
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Loads libpri signaling module
- * \param zio Openzap IO interface
- * \return Success
- */
-static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init)
-{
- pri_set_error(s_pri_error);
- pri_set_message(s_pri_message);
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief libpri state map
- */
-static zap_state_map_t isdn_state_map = {
- {
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_ANY_STATE},
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- {ZAP_CHANNEL_STATE_DIALING, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DIALING, ZAP_END},
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_UP, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}
- },
-
- /****************************************/
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_ANY_STATE},
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- {ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_RING, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DIALTONE, ZAP_END},
- {ZAP_CHANNEL_STATE_RING, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_UP, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_PROGRESS_MEDIA,
- ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_UP, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_UP, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- },
-
-
- }
-};
-
-/**
- * \brief Handler for channel state change
- * \param zchan Channel to handle
- */
-static __inline__ void state_advance(zap_channel_t *zchan)
-{
- //Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data;
- zap_libpri_data_t *isdn_data = zchan->span->signal_data;
- zap_status_t status;
- zap_sigmsg_t sig;
- q931_call *call = (q931_call *) zchan->call_data;
-
-
- zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n",
- zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state));
-
-
-#if 0
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) && !call) {
- zap_log(ZAP_LOG_WARNING, "NO CALL!!!!\n");
- }
-#endif
-
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
-
-
- switch (zchan->state) {
- case ZAP_CHANNEL_STATE_DOWN:
- {
- zchan->call_data = NULL;
- zap_channel_done(zchan);
- }
- break;
- case ZAP_CHANNEL_STATE_PROGRESS:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_PROGRESS;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else if (call) {
- pri_progress(isdn_data->spri.pri, call, zchan->chan_id, 1);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_PROGRESS_MEDIA:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else if (call) {
- pri_proceeding(isdn_data->spri.pri, call, zchan->chan_id, 1);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_RING:
- {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- if (call) {
- pri_acknowledge(isdn_data->spri.pri, call, zchan->chan_id, 0);
- sig.event_id = ZAP_SIGEVENT_START;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_RESTART:
- {
- zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED;
- sig.event_id = ZAP_SIGEVENT_RESTART;
- status = zap_span_send_signal(zchan->span, &sig);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- break;
- case ZAP_CHANNEL_STATE_UP:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_UP;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else if (call) {
- pri_answer(isdn_data->spri.pri, call, 0, 1);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_DIALING:
- if (isdn_data) {
- struct pri_sr *sr;
- int dp;
-
- if (!(call = pri_new_call(isdn_data->spri.pri))) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- return;
- }
-
-
- dp = zchan->caller_data.ani.type;
- switch(dp) {
- case ZAP_TON_NATIONAL:
- dp = PRI_NATIONAL_ISDN;
- break;
- case ZAP_TON_INTERNATIONAL:
- dp = PRI_INTERNATIONAL_ISDN;
- break;
- case ZAP_TON_SUBSCRIBER_NUMBER:
- dp = PRI_LOCAL_ISDN;
- break;
- default:
- dp = isdn_data->dp;
- }
-
- zchan->call_data = call;
- sr = pri_sr_new();
- assert(sr);
- pri_sr_set_channel(sr, zchan->chan_id, 0, 0);
- pri_sr_set_bearer(sr, 0, isdn_data->l1);
- pri_sr_set_called(sr, zchan->caller_data.ani.digits, dp, 1);
- pri_sr_set_caller(sr, zchan->caller_data.cid_num.digits, (isdn_data->opts & OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE ? NULL : zchan->caller_data.cid_name),
- dp, (zchan->caller_data.pres != 1 ? PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN : PRES_PROHIB_USER_NUMBER_NOT_SCREENED));
-
- if (!(isdn_data->opts & OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE)) {
- pri_sr_set_redirecting(sr, zchan->caller_data.cid_num.digits, dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
- }
-
- if (pri_setup(isdn_data->spri.pri, call, sr)) {
- zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER;
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
-
- pri_sr_free(sr);
- }
-
- break;
- case ZAP_CHANNEL_STATE_HANGUP:
- {
- if (call) {
- pri_hangup(isdn_data->spri.pri, call, zchan->caller_data.hangup_cause);
- pri_destroycall(isdn_data->spri.pri, call);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_HANGUP_COMPLETE:
- break;
- case ZAP_CHANNEL_STATE_TERMINATING:
- {
- sig.event_id = ZAP_SIGEVENT_STOP;
- status = zap_span_send_signal(zchan->span, &sig);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
-
- }
- default:
- break;
- }
-
-
-
- return;
-}
-
-/**
- * \brief Checks current state on a span
- * \param span Span to check status on
- */
-static __inline__ void check_state(zap_span_t *span)
-{
- if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) {
- uint32_t j;
- zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE);
- for(j = 1; j <= span->chan_count; j++) {
- if (zap_test_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) {
- zap_mutex_lock(span->channels[j]->mutex);
- zap_clear_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE);
- state_advance(span->channels[j]);
- zap_channel_complete_state(span->channels[j]);
- zap_mutex_unlock(span->channels[j]->mutex);
- }
- }
- }
-}
-
-/**
- * \brief Handler for libpri information event (incoming call?)
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
-
- zap_log(ZAP_LOG_DEBUG, "number is: %s\n", pevent->ring.callednum);
- if (strlen(pevent->ring.callednum) > 3) {
- zap_log(ZAP_LOG_DEBUG, "final number is: %s\n", pevent->ring.callednum);
- pri_answer(spri->pri, pevent->ring.call, 0, 1);
- }
- return 0;
-}
-
-/**
- * \brief Handler for libpri hangup event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
- zap_span_t *span = spri->private_info;
- zap_channel_t *zchan = NULL;
- q931_call *call = NULL;
- zchan = span->channels[pevent->hangup.channel];
-
- if (zchan) {
- call = (q931_call *) zchan->call_data;
- zap_log(ZAP_LOG_DEBUG, "-- Hangup on channel %d:%d\n", spri->span->span_id, pevent->hangup.channel);
- zchan->caller_data.hangup_cause = pevent->hangup.cause;
- pri_release(spri->pri, call, 0);
- pri_destroycall(spri->pri, call);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING);
- } else {
- zap_log(ZAP_LOG_DEBUG, "-- Hangup on channel %d:%d %s but it's not in use?\n", spri->span->span_id,
- pevent->hangup.channel, zchan->chan_id);
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for libpri answer event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
- zap_span_t *span = spri->private_info;
- zap_channel_t *zchan = NULL;
-
- zchan = span->channels[pevent->answer.channel];
-
- if (zchan) {
- zap_log(ZAP_LOG_DEBUG, "-- Answer on channel %d:%d\n", spri->span->span_id, pevent->answer.channel);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
- } else {
- zap_log(ZAP_LOG_DEBUG, "-- Answer on channel %d:%d %s but it's not in use?\n", spri->span->span_id, pevent->answer.channel, zchan->chan_id);
-
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for libpri proceed event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
- zap_span_t *span = spri->private_info;
- zap_channel_t *zchan = NULL;
-
- zchan = span->channels[pevent->proceeding.channel];
-
- if (zchan) {
- zap_log(ZAP_LOG_DEBUG, "-- Proceeding on channel %d:%d\n", spri->span->span_id, pevent->proceeding.channel);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA);
- } else {
- zap_log(ZAP_LOG_DEBUG, "-- Proceeding on channel %d:%d %s but it's not in use?\n", spri->span->span_id,
- pevent->proceeding.channel, zchan->chan_id);
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for libpri ringing event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
- zap_span_t *span = spri->private_info;
- zap_channel_t *zchan = NULL;
-
- zchan = span->channels[pevent->ringing.channel];
-
- if (zchan) {
- zap_log(ZAP_LOG_DEBUG, "-- Ringing on channel %d:%d\n", spri->span->span_id, pevent->ringing.channel);
- /* we may get on_ringing even when we're already in ZAP_CHANNEL_STATE_PROGRESS_MEDIA */
- if (zchan->state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) {
- /* dont try to move to STATE_PROGRESS to avoid annoying veto warning */
- return 0;
- }
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS);
- } else {
- zap_log(ZAP_LOG_DEBUG, "-- Ringing on channel %d:%d %s but it's not in use?\n", spri->span->span_id,
- pevent->ringing.channel, zchan->chan_id);
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for libpri ring event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0 on success
- */
-static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
- zap_span_t *span = spri->private_info;
- zap_channel_t *zchan = NULL;
- int ret = 0;
-
- //switch_mutex_lock(globals.channel_mutex);
-
- zchan = span->channels[pevent->ring.channel];
- if (!zchan || zchan->state != ZAP_CHANNEL_STATE_DOWN || zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) {
- zap_log(ZAP_LOG_WARNING, "--Duplicate Ring on channel %d:%d (ignored)\n", spri->span->span_id, pevent->ring.channel);
- ret = 0;
- goto done;
- }
-
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_WARNING, "--Failure opening channel %d:%d (ignored)\n", spri->span->span_id, pevent->ring.channel);
- ret = 0;
- goto done;
- }
-
-
- zap_log(ZAP_LOG_NOTICE, "-- Ring on channel %d:%d (from %s to %s)\n", spri->span->span_id, pevent->ring.channel,
- pevent->ring.callingnum, pevent->ring.callednum);
-
- memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
-
- zap_set_string(zchan->caller_data.cid_num.digits, (char *)pevent->ring.callingnum);
- if (!zap_strlen_zero((char *)pevent->ring.callingname)) {
- zap_set_string(zchan->caller_data.cid_name, (char *)pevent->ring.callingname);
- } else {
- zap_set_string(zchan->caller_data.cid_name, (char *)pevent->ring.callingnum);
- }
- zap_set_string(zchan->caller_data.ani.digits, (char *)pevent->ring.callingani);
- zap_set_string(zchan->caller_data.dnis.digits, (char *)pevent->ring.callednum);
-
- if (pevent->ring.ani2 >= 0) {
- snprintf(zchan->caller_data.aniII, 5, "%.2d", pevent->ring.ani2);
- }
-
- // scary to trust this pointer, you'd think they would give you a copy of the call data so you own it......
- zchan->call_data = pevent->ring.call;
-
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING);
-
- done:
- //switch_mutex_unlock(globals.channel_mutex);
-
- return ret;
-}
-
-/**
- * \brief Processes openzap event
- * \param span Span on which the event was fired
- * \param event Event to be treated
- * \return Success or failure
- */
-static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event)
-{
- zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d][%d:%d] STATE [%s]\n",
- zap_oob_event2str(event->enum_id), event->enum_id, event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state));
-
- switch(event->enum_id) {
- case ZAP_OOB_ALARM_TRAP:
- {
- if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) {
- if (event->channel->type == ZAP_CHAN_TYPE_B) {
- zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART);
- }
- }
-
-
- zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED);
-
-
- zap_channel_get_alarms(event->channel);
- zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) has alarms! [%s]\n",
- event->channel->span_id, event->channel->chan_id,
- event->channel->physical_span_id, event->channel->physical_chan_id,
- event->channel->last_error);
- }
- break;
- case ZAP_OOB_ALARM_CLEAR:
- {
- zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) alarms Cleared!\n", event->channel->span_id, event->channel->chan_id,
- event->channel->physical_span_id, event->channel->physical_chan_id);
-
- zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED);
- zap_channel_get_alarms(event->channel);
- }
- break;
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Checks for events on a span
- * \param span Span to check for events
- */
-static __inline__ void check_events(zap_span_t *span)
-{
- zap_status_t status;
-
- status = zap_span_poll_event(span, 5);
-
- switch(status) {
- case ZAP_SUCCESS:
- {
- zap_event_t *event;
- while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
- if (event->enum_id == ZAP_OOB_NOOP) {
- continue;
- }
- if (process_event(span, event) != ZAP_SUCCESS) {
- break;
- }
- }
- }
- break;
- case ZAP_FAIL:
- {
- zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running());
- zap_sleep(2000);
- }
- break;
- default:
- break;
- }
-}
-
-/**
- * \brief Checks flags on a pri span
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \return 0 on success, -1 on error
- */
-static int check_flags(lpwrap_pri_t *spri)
-{
- zap_span_t *span = spri->private_info;
-
- if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) {
- return -1;
- }
-
- check_state(span);
- check_events(span);
-
-
- return 0;
-}
-
-/**
- * \brief Handler for libpri restart event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
- zap_span_t *span = spri->private_info;
- zap_channel_t *zchan;
-
- zap_log(ZAP_LOG_NOTICE, "-- Restarting %d:%d\n", spri->span->span_id, pevent->restart.channel);
-
- zchan = span->channels[pevent->restart.channel];
-
- if (!zchan) {
- return 0;
- }
-
- if (pevent->restart.channel < 1) {
- zap_set_state_all(zchan->span, ZAP_CHANNEL_STATE_RESTART);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART);
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for libpri dchan up event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
-
- if (!zap_test_flag(spri, LPWRAP_PRI_READY)) {
- zap_log(ZAP_LOG_INFO, "Span %d D-Chan UP!\n", spri->span->span_id);
- zap_set_flag(spri, LPWRAP_PRI_READY);
- zap_set_state_all(spri->span, ZAP_CHANNEL_STATE_RESTART);
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for libpri dchan down event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
-
- if (zap_test_flag(spri, LPWRAP_PRI_READY)) {
- zap_log(ZAP_LOG_INFO, "Span %d D-Chan DOWN!\n", spri->span->span_id);
- zap_clear_flag(spri, LPWRAP_PRI_READY);
- zap_set_state_all(spri->span, ZAP_CHANNEL_STATE_RESTART);
-
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for any libpri event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
-
- zap_log(ZAP_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span->span_id, event_type, lpwrap_pri_event_str(event_type));
- return 0;
-}
-
-/**
- * \brief Handler for libpri io fail event
- * \param spri Pri wrapper structure (libpri, span, dchan)
- * \param event_type Event type (unused)
- * \param pevent Event
- * \return 0
- */
-static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent)
-{
-
- zap_log(ZAP_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span->span_id, event_type, lpwrap_pri_event_str(event_type));
- return 0;
-}
-
-/**
- * \brief Main thread function for libpri span (monitor)
- * \param me Current thread
- * \param obj Span to run in this thread
- */
-static void *zap_libpri_run(zap_thread_t *me, void *obj)
-{
- zap_span_t *span = (zap_span_t *) obj;
- zap_libpri_data_t *isdn_data = span->signal_data;
- int i, x = 0;
- int down = 0;
- int got_d = 0;
-
- zap_set_flag(span, ZAP_SPAN_IN_THREAD);
-
- while(zap_running() && !zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) {
- if (!got_d) {
- for(i = 1; i <= span->chan_count; i++) {
- if (span->channels[i]->type == ZAP_CHAN_TYPE_DQ921) {
- if (zap_channel_open(span->span_id, i, &isdn_data->dchan) == ZAP_SUCCESS) {
- zap_log(ZAP_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, isdn_data->dchan->span_id, isdn_data->dchan->chan_id);
- isdn_data->dchan->state = ZAP_CHANNEL_STATE_UP;
- got_d = 1;
- x++;
- break;
- }
- }
- }
- }
-
-
- if (lpwrap_init_pri(&isdn_data->spri,
- span, // span
- isdn_data->dchan, // dchan
- isdn_data->pswitch,
- isdn_data->node,
- isdn_data->debug) < 0) {
- snprintf(span->last_error, sizeof(span->last_error), "PRI init FAIL!");
- } else {
-
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_ANY, on_anything);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RING, on_ring);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RINGING, on_ringing);
- //LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_SETUP_ACK, on_proceed);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_PROCEEDING, on_proceed);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_ANSWER, on_answer);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_DCHAN_UP, on_dchan_up);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_DCHAN_DOWN, on_dchan_down);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_HANGUP_REQ, on_hangup);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_HANGUP, on_hangup);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_INFO_RECEIVED, on_info);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RESTART, on_restart);
- LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_IO_FAIL, on_io_fail);
-
- if (down) {
- zap_log(ZAP_LOG_INFO, "PRI back up on span %d\n", isdn_data->spri.span->span_id);
- zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART);
- down = 0;
- }
-
- isdn_data->spri.on_loop = check_flags;
- isdn_data->spri.private_info = span;
- lpwrap_run_pri(&isdn_data->spri);
-
- }
-
- if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) {
- break;
- }
-
- zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span->span_id);
-
- if (!down) {
- zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART);
- check_state(span);
- }
-
- check_state(span);
- check_events(span);
-
- down++;
- zap_sleep(5000);
- }
-
- zap_log(ZAP_LOG_DEBUG, "PRI thread ended on span %d\n", isdn_data->spri.span->span_id);
-
- zap_clear_flag(span, ZAP_SPAN_IN_THREAD);
- zap_clear_flag(isdn_data, OZMOD_LIBPRI_RUNNING);
-
- return NULL;
-}
-
-/**
- * \brief Stops a libpri span
- * \param span Span to halt
- * \return Success
- *
- * Sets a stop flag and waits for the thread to end
- */
-static zap_status_t zap_libpri_stop(zap_span_t *span)
-{
- zap_libpri_data_t *isdn_data = span->signal_data;
-
- if (!zap_test_flag(isdn_data, OZMOD_LIBPRI_RUNNING)) {
- return ZAP_FAIL;
- }
-
- zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART);
- check_state(span);
- zap_set_flag(span, ZAP_SPAN_STOP_THREAD);
- while(zap_test_flag(span, ZAP_SPAN_IN_THREAD)) {
- zap_sleep(100);
- }
- check_state(span);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Starts a libpri span
- * \param span Span to halt
- * \return Success or failure
- *
- * Launches a thread to monitor the span
- */
-static zap_status_t zap_libpri_start(zap_span_t *span)
-{
- zap_status_t ret;
- zap_libpri_data_t *isdn_data = span->signal_data;
-
- if (zap_test_flag(isdn_data, OZMOD_LIBPRI_RUNNING)) {
- return ZAP_FAIL;
- }
-
- zap_clear_flag(span, ZAP_SPAN_STOP_THREAD);
- zap_clear_flag(span, ZAP_SPAN_IN_THREAD);
-
- zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING);
- ret = zap_thread_create_detached(zap_libpri_run, span);
-
- if (ret != ZAP_SUCCESS) {
- return ret;
- }
-
- return ret;
-}
-
-/**
- * \brief Converts a node string to node value
- * \param node Node string to convert
- * \return -1 on failure, node value on success
- */
-static int str2node(char *node)
-{
- if (!strcasecmp(node, "cpe") || !strcasecmp(node, "user"))
- return PRI_CPE;
- if (!strcasecmp(node, "network") || !strcasecmp(node, "net"))
- return PRI_NETWORK;
- return -1;
-}
-
-/**
- * \brief Converts a switch string to switch value
- * \param swtype Swtype string to convert
- * \return Switch value
- */
-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") || !strcasecmp(swtype, "5ess"))
- return PRI_SWITCH_LUCENT5E;
- if (!strcasecmp(swtype, "att4ess") || !strcasecmp(swtype, "4ess"))
- 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 PRI_SWITCH_DMS100;
-}
-
-/**
- * \brief Converts a L1 string to L1 value
- * \param l1 L1 string to convert
- * \return L1 value
- */
-static int str2l1(char *l1)
-{
- if (!strcasecmp(l1, "alaw"))
- return PRI_LAYER_1_ALAW;
-
- return PRI_LAYER_1_ULAW;
-}
-
-/**
- * \brief Converts a DP string to DP value
- * \param dp DP string to convert
- * \return DP value
- */
-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;
-}
-
-/**
- * \brief Initialises a libpri span from configuration variables
- * \param span Span to configure
- * \param sig_cb Callback function for event signals
- * \param ap List of configuration variables
- * \return Success or failure
- */
-static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span)
-{
- uint32_t i, x = 0;
- //zap_channel_t *dchans[2] = {0};
- zap_libpri_data_t *isdn_data;
- char *var, *val;
- char *debug = NULL;
-
- if (span->trunk_type >= ZAP_TRUNK_NONE) {
- zap_log(ZAP_LOG_WARNING, "Invalid trunk type '%s' defaulting to T1.\n", zap_trunk_type2str(span->trunk_type));
- span->trunk_type = ZAP_TRUNK_T1;
- }
-
- for(i = 1; i <= span->chan_count; i++) {
- if (span->channels[i]->type == ZAP_CHAN_TYPE_DQ921) {
- if (x > 1) {
- snprintf(span->last_error, sizeof(span->last_error), "Span has more than 2 D-Channels!");
- return ZAP_FAIL;
- } else {
-#if 0
- if (zap_channel_open(span->span_id, i, &dchans[x]) == ZAP_SUCCESS) {
- zap_log(ZAP_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, dchans[x]->span_id, dchans[x]->chan_id);
- dchans[x]->state = ZAP_CHANNEL_STATE_UP;
- x++;
- }
-#endif
- }
- }
- }
-
-#if 0
- if (!x) {
- snprintf(span->last_error, sizeof(span->last_error), "Span has no D-Channels!");
- return ZAP_FAIL;
- }
-#endif
-
- isdn_data = malloc(sizeof(*isdn_data));
- assert(isdn_data != NULL);
- memset(isdn_data, 0, sizeof(*isdn_data));
-
- if (span->trunk_type == ZAP_TRUNK_E1) {
- zap_log(ZAP_LOG_NOTICE, "Setting default Layer 1 to ALAW since this is an E1 trunk\n");
- isdn_data->l1 = PRI_LAYER_1_ALAW;
- } else if (span->trunk_type == ZAP_TRUNK_T1) {
- zap_log(ZAP_LOG_NOTICE, "Setting default Layer 1 to ULAW since this is a T1 trunk\n");
- isdn_data->l1 = PRI_LAYER_1_ULAW;
- }
-
- while((var = va_arg(ap, char *))) {
- if (!strcasecmp(var, "node")) {
- int node;
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- node = str2node(val);
- if (-1 == node) {
- zap_log(ZAP_LOG_ERROR, "Unknown node type %s, defaulting to CPE mode\n", val);
- node = PRI_CPE;
- }
- isdn_data->node = node;
- } else if (!strcasecmp(var, "switch")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- isdn_data->pswitch = str2switch(val);
- } else if (!strcasecmp(var, "opts")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- isdn_data->opts = parse_opts(val);
- } else if (!strcasecmp(var, "dp")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- isdn_data->dp = str2dp(val);
- } else if (!strcasecmp(var, "l1")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- isdn_data->l1 = str2l1(val);
- } else if (!strcasecmp(var, "debug")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- debug = val;
- } else {
- snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
- return ZAP_FAIL;
- }
- }
-
- span->start = zap_libpri_start;
- span->stop = zap_libpri_stop;
- span->signal_cb = sig_cb;
- //isdn_data->dchans[0] = dchans[0];
- //isdn_data->dchans[1] = dchans[1];
- //isdn_data->dchan = isdn_data->dchans[0];
-
- isdn_data->debug = parse_debug(debug);
-
-
- span->signal_data = isdn_data;
- span->signal_type = ZAP_SIGTYPE_ISDN;
- span->outgoing_call = isdn_outgoing_call;
-
- if ((isdn_data->opts & OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) {
- span->channel_request = isdn_channel_request;
- span->suggest_chan_id = 1;
- }
-
- span->state_map = &isdn_state_map;
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Openzap libpri signaling and IO module definition
- */
-zap_module_t zap_module = {
- "libpri",
- zap_libpri_io_init,
- zap_libpri_unload,
- zap_libpri_init,
- zap_libpri_configure_span,
- NULL
-};
-
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h
deleted file mode 100644
index ef79e517c7..0000000000
--- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2009-2012, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#ifndef OZMOD_LIBPRI_H
-#define OZMOD_LIBPRI_H
-#include "openzap.h"
-#include "lpwrap_pri.h"
-
-typedef enum {
- OZMOD_LIBPRI_OPT_NONE = 0,
- OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0),
- OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1),
- OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2),
-
- OZMOD_LIBPRI_OPT_MAX = (1 << 3)
-} zap_isdn_opts_t;
-
-typedef enum {
- OZMOD_LIBPRI_RUNNING = (1 << 0)
-} zap_isdn_flag_t;
-
-
-struct zap_libpri_data {
- zap_channel_t *dchan;
- zap_channel_t *dchans[2];
- struct zap_sigmsg sigmsg;
- uint32_t flags;
- int32_t mode;
- zap_isdn_opts_t opts;
-
- int node;
- int pswitch;
- char *dialplan;
- unsigned int l1;
- unsigned int dp;
-
- int debug;
-
- lpwrap_pri_t spri;
-};
-
-typedef struct zap_libpri_data zap_libpri_data_t;
-
-
-/* b-channel private data */
-struct zap_isdn_bchan_data
-{
- int32_t digit_timeout;
-};
-
-typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t;
-
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
-
diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2005.vcproj b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2005.vcproj
deleted file mode 100644
index c62eddd423..0000000000
--- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2005.vcproj
+++ /dev/null
@@ -1,197 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj
deleted file mode 100644
index 2e3cfceb13..0000000000
--- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj
+++ /dev/null
@@ -1,197 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c
deleted file mode 100644
index e7283d0582..0000000000
--- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c
+++ /dev/null
@@ -1,1469 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "openzap.h"
-#include "zap_pika.h"
-
-
-#define MAX_NUMBER_OF_TRUNKS 64
-#define PIKA_BLOCK_SIZE 160
-#define PIKA_BLOCK_LEN 20
-#define PIKA_NUM_BUFFERS 8
-#define TRY_OR_DIE(__code, __status, __label) if ((status = __code ) != __status) goto __label
-#define pk_atof(__a) (PK_FLOAT) atof(__a)
-
-PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event);
-
-ZAP_ENUM_NAMES(PIKA_SPAN_NAMES, PIKA_SPAN_STRINGS)
-PIKA_STR2ENUM(pika_str2span, pika_span2str, PIKA_TSpanFraming, PIKA_SPAN_NAMES, PIKA_SPAN_INVALID)
-
-ZAP_ENUM_NAMES(PIKA_SPAN_ENCODING_NAMES, PIKA_SPAN_ENCODING_STRINGS)
-PIKA_STR2ENUM(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding, PIKA_SPAN_ENCODING_NAMES, PIKA_SPAN_ENCODING_INVALID)
-
-ZAP_ENUM_NAMES(PIKA_LL_NAMES, PIKA_LL_STRINGS)
-PIKA_STR2ENUM(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength, PIKA_LL_NAMES, PIKA_SPAN_LOOP_INVALID)
-
-ZAP_ENUM_NAMES(PIKA_LBO_NAMES, PIKA_LBO_STRINGS)
-PIKA_STR2ENUM(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut, PIKA_LBO_NAMES, PIKA_SPAN_LBO_INVALID)
-
-ZAP_ENUM_NAMES(PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_STRINGS)
-PIKA_STR2ENUM(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_INVALID)
-
-
-typedef enum {
- PK_FLAG_READY = (1 << 0),
- PK_FLAG_LOCKED = (1 << 1)
-} pk_flag_t;
-
-struct general_config {
- uint32_t region;
-};
-typedef struct general_config general_config_t;
-
-struct pika_channel_profile {
- char name[80];
- PKH_TRecordConfig record_config;
- PKH_TPlayConfig play_config;
- int ec_enabled;
- PKH_TECConfig ec_config;
- PKH_TSpanConfig span_config;
- general_config_t general_config;
- int cust_span;
-};
-typedef struct pika_channel_profile pika_channel_profile_t;
-
-static struct {
- PKH_TSystemDeviceList board_list;
- TPikaHandle open_boards[MAX_NUMBER_OF_TRUNKS];
- TPikaHandle system_handle;
- PKH_TSystemConfig system_config;
- PKH_TRecordConfig record_config;
- PKH_TPlayConfig play_config;
- PKH_TECConfig ec_config;
- PKH_TSpanConfig t1_span_config;
- PKH_TSpanConfig e1_span_config;
- zap_hash_t *profile_hash;
- general_config_t general_config;
-} globals;
-
-
-struct pika_span_data {
- TPikaHandle event_queue;
- PKH_TPikaEvent last_oob_event;
- uint32_t boardno;
- PKH_TSpanConfig span_config;
- TPikaHandle handle;
- uint32_t flags;
-};
-typedef struct pika_span_data pika_span_data_t;
-
-struct pika_chan_data {
- TPikaHandle handle;
- TPikaHandle media_in;
- TPikaHandle media_out;
- TPikaHandle media_in_queue;
- TPikaHandle media_out_queue;
- PKH_TPikaEvent last_media_event;
- PKH_TPikaEvent last_oob_event;
- PKH_TRecordConfig record_config;
- PKH_TPlayConfig play_config;
- int ec_enabled;
- PKH_TECConfig ec_config;
- PKH_THDLCConfig hdlc_config;
- zap_buffer_t *digit_buffer;
- zap_mutex_t *digit_mutex;
- zap_size_t dtmf_len;
- uint32_t flags;
- uint32_t hdlc_bytes;
-};
-typedef struct pika_chan_data pika_chan_data_t;
-
-static const char *pika_board_type_string(PK_UINT type)
-{
- if (type == PKH_BOARD_TYPE_DIGITAL_GATEWAY) {
- return "digital_gateway";
- }
-
- if (type == PKH_BOARD_TYPE_ANALOG_GATEWAY) {
- return "analog_gateway";
- }
-
- return "unknown";
-}
-
-/**
- * \brief Process configuration variable for a pika profile
- * \param category Pika profile name
- * \param var Variable name
- * \param val Variable value
- * \param lineno Line number from configuration file (unused)
- * \return Success
- */
-static ZIO_CONFIGURE_FUNCTION(pika_configure)
-{
- pika_channel_profile_t *profile = NULL;
- int ok = 1;
-
- if (!(profile = (pika_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) {
- profile = malloc(sizeof(*profile));
- memset(profile, 0, sizeof(*profile));
- zap_set_string(profile->name, category);
- profile->ec_config = globals.ec_config;
- profile->record_config = globals.record_config;
- profile->play_config = globals.play_config;
- hashtable_insert(globals.profile_hash, (void *)profile->name, profile, HASHTABLE_FLAG_NONE);
- zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category);
- }
-
- if (!strcasecmp(var, "rx-gain")) {
- profile->record_config.gain = pk_atof(val);
- } else if (!strcasecmp(var, "rx-agc-enabled")) {
- profile->record_config.AGC.enabled = zap_true(val);
- } else if (!strcasecmp(var, "rx-agc-targetPower")) {
- profile->record_config.AGC.targetPower = pk_atof(val);
- } else if (!strcasecmp(var, "rx-agc-minGain")) {
- profile->record_config.AGC.minGain = pk_atof(val);
- } else if (!strcasecmp(var, "rx-agc-maxGain")) {
- profile->record_config.AGC.maxGain = pk_atof(val);
- } else if (!strcasecmp(var, "rx-agc-attackRate")) {
- profile->record_config.AGC.attackRate = atoi(val);
- } else if (!strcasecmp(var, "rx-agc-decayRate")) {
- profile->record_config.AGC.decayRate = atoi(val);
- } else if (!strcasecmp(var, "rx-agc-speechThreshold")) {
- profile->record_config.AGC.speechThreshold = pk_atof(val);
- } else if (!strcasecmp(var, "rx-vad-enabled")) {
- profile->record_config.VAD.enabled = zap_true(val);
- } else if (!strcasecmp(var, "rx-vad-activationThreshold")) {
- profile->record_config.VAD.activationThreshold = pk_atof(val);
- } else if (!strcasecmp(var, "rx-vad-activationDebounceTime")) {
- profile->record_config.VAD.activationDebounceTime = atoi(val);
- } else if (!strcasecmp(var, "rx-vad-deactivationThreshold")) {
- profile->record_config.VAD.deactivationThreshold = pk_atof(val);
- } else if (!strcasecmp(var, "rx-vad-deactivationDebounceTime")) {
- profile->record_config.VAD.deactivationDebounceTime = atoi(val);
- } else if (!strcasecmp(var, "rx-vad-preSpeechBufferSize")) {
- profile->record_config.VAD.preSpeechBufferSize = atoi(val);
- } else if (!strcasecmp(var, "tx-gain")) {
- profile->play_config.gain = pk_atof(val);
- } else if (!strcasecmp(var, "tx-agc-enabled")) {
- profile->play_config.AGC.enabled = zap_true(val);
- } else if (!strcasecmp(var, "tx-agc-targetPower")) {
- profile->play_config.AGC.targetPower = pk_atof(val);
- } else if (!strcasecmp(var, "tx-agc-minGain")) {
- profile->play_config.AGC.minGain = pk_atof(val);
- } else if (!strcasecmp(var, "tx-agc-maxGain")) {
- profile->play_config.AGC.maxGain = pk_atof(val);
- } else if (!strcasecmp(var, "tx-agc-attackRate")) {
- profile->play_config.AGC.attackRate = atoi(val);
- } else if (!strcasecmp(var, "tx-agc-decayRate")) {
- profile->play_config.AGC.decayRate = atoi(val);
- } else if (!strcasecmp(var, "tx-agc-speechThreshold")) {
- profile->play_config.AGC.speechThreshold = pk_atof(val);
- } else if (!strcasecmp(var, "ec-enabled")) {
- profile->ec_enabled = zap_true(val);
- } else if (!strcasecmp(var, "ec-doubleTalkerThreshold")) {
- profile->ec_config.doubleTalkerThreshold = pk_atof(val);
- } else if (!strcasecmp(var, "ec-speechPresentThreshold")) {
- profile->ec_config.speechPresentThreshold = pk_atof(val);
- } else if (!strcasecmp(var, "ec-echoSuppressionThreshold")) {
- profile->ec_config.echoSuppressionThreshold = pk_atof(val);
- } else if (!strcasecmp(var, "ec-echoSuppressionEnabled")) {
- profile->ec_config.echoSuppressionEnabled = zap_true(val);
- } else if (!strcasecmp(var, "ec-comfortNoiseEnabled")) {
- profile->ec_config.comfortNoiseEnabled = zap_true(val);
- } else if (!strcasecmp(var, "ec-adaptationModeEnabled")) {
- profile->ec_config.adaptationModeEnabled = zap_true(val);
- } else if (!strcasecmp(var, "framing")) {
- profile->span_config.framing = pika_str2span(val);
- profile->cust_span++;
- } else if (!strcasecmp(var, "encoding")) {
- profile->span_config.encoding = pika_str2span_encoding(val);
- profile->cust_span++;
- } else if (!strcasecmp(var, "loopLength")) {
- profile->span_config.loopLength = pika_str2loop_length(val);
- profile->cust_span++;
- } else if (!strcasecmp(var, "buildOut")) {
- profile->span_config.buildOut = pika_str2lbo(val);
- profile->cust_span++;
- } else if (!strcasecmp(var, "compandMode")) {
- profile->span_config.compandMode = pika_str2compand_mode(val);
- profile->cust_span++;
- } else if (!strcasecmp(var, "region")) {
- if (!strcasecmp(val, "eu")) {
- profile->general_config.region = PKH_TRUNK_EU;
- } else {
- profile->general_config.region = PKH_TRUNK_NA;
- }
- } else {
- ok = 0;
- }
-
- if (ok) {
- zap_log(ZAP_LOG_INFO, "setting param [%s]=[%s] for profile [%s]\n", var, val, category);
- } else {
- zap_log(ZAP_LOG_ERROR, "unknown param [%s]\n", var);
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Pika event handler
- * \param event Pika event
- */
-PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event)
-{
- PK_STATUS pk_status;
- zap_channel_t *zchan = event->userData;
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
-
- //PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH];
- //PKH_EVENT_GetText(event->id, event_text, sizeof(event_text));
- //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", event_text);
-
- switch (event->id) {
- case PKH_EVENT_PLAY_IDLE:
- {
- while (zap_buffer_inuse(chan_data->digit_buffer)) {
- char dtmf[128] = "";
- zap_mutex_lock(chan_data->digit_mutex);
- chan_data->dtmf_len = zap_buffer_read(chan_data->digit_buffer, dtmf, sizeof(dtmf));
- pk_status = PKH_TG_PlayDTMF(chan_data->media_out, dtmf);
- zap_mutex_unlock(chan_data->digit_mutex);
- }
- }
- break;
- case PKH_EVENT_TG_TONE_PLAYED:
- {
-
- if (!event->p1) {
- zap_mutex_lock(chan_data->digit_mutex);
- PKH_PLAY_Start(chan_data->media_out);
- chan_data->dtmf_len = 0;
- zap_mutex_unlock(chan_data->digit_mutex);
- }
-
-
- }
- break;
- default:
- break;
- }
-
-}
-
-/**
- * \brief Initialises a range of pika channels
- * \param span Openzap span
- * \param boardno Pika board number
- * \param spanno Pika span number
- * \param start Initial pika channel number
- * \param end Final pika channel number
- * \param type Openzap channel type
- * \param name Openzap span name
- * \param number Openzap span number
- * \param profile Pika channel profile
- * \return number of spans configured
- */
-static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spanno, unsigned start, unsigned end,
- zap_chan_type_t type, char *name, char *number, pika_channel_profile_t *profile)
-{
- unsigned configured = 0, x;
- PK_STATUS status;
- PK_CHAR error_text[PKH_ERROR_MAX_NAME_LENGTH];
- pika_span_data_t *span_data;
-
- if (boardno >= globals.board_list.numberOfBoards) {
- zap_log(ZAP_LOG_ERROR, "Board %u is not present!\n", boardno);
- return 0;
- }
-
- if (!globals.open_boards[boardno]) {
- status = PKH_BOARD_Open(globals.board_list.board[boardno].id,
- NULL,
- &globals.open_boards[boardno]);
- if(status != PK_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error: PKH_BOARD_Open %d failed(%s)!\n", boardno,
- PKH_ERROR_GetText(status, error_text, sizeof(error_text)));
- return 0;
- }
-
- zap_log(ZAP_LOG_DEBUG, "Open board %u\n", boardno);
-
- //PKH_BOARD_SetDebugTrace(globals.open_boards[boardno], 1, 0);
-
- }
-
- if (span->mod_data) {
- span_data = span->mod_data;
- } else {
- span_data = malloc(sizeof(*span_data));
- assert(span_data != NULL);
- memset(span_data, 0, sizeof(*span_data));
- span_data->boardno = boardno;
-
- status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &span_data->event_queue);
-
- if (status != PK_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error: PKH_QUEUE_Create failed(%s)!\n",
- PKH_ERROR_GetText(status, error_text, sizeof(error_text)));
- free(span_data);
- return 0;
- }
-
- //PKH_QUEUE_Attach(span_data->event_queue, globals.open_boards[boardno], NULL);
-
- span->mod_data = span_data;
- }
-
- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) {
- start--;
- end--;
- }
-
- for(x = start; x < end; x++) {
- zap_channel_t *chan;
- pika_chan_data_t *chan_data = NULL;
-
- chan_data = malloc(sizeof *chan_data);
- assert(chan_data);
- memset(chan_data, 0, sizeof(*chan_data));
- zap_span_add_channel(span, 0, type, &chan);
- chan->mod_data = chan_data;
-
- if ((type == ZAP_CHAN_TYPE_B || type == ZAP_CHAN_TYPE_DQ921) && !span_data->handle) {
- PKH_TBoardConfig boardConfig;
-
- TRY_OR_DIE(PKH_BOARD_GetConfig(globals.open_boards[boardno], &boardConfig), PK_SUCCESS, error);
- if ((profile && profile->general_config.region == PKH_TRUNK_EU) || zap_test_flag(span_data, PK_FLAG_LOCKED)) {
- if (span->trunk_type == ZAP_TRUNK_T1) {
- zap_log(ZAP_LOG_WARNING, "Changing trunk type to E1 based on previous config.\n");
- }
- span->trunk_type = ZAP_TRUNK_E1;
- }
-
- if (span->trunk_type == ZAP_TRUNK_T1) {
- if (zap_test_flag(span_data, PK_FLAG_LOCKED)) {
- zap_log(ZAP_LOG_WARNING, "Already locked into E1 mode!\n");
- }
- } else if (span->trunk_type == ZAP_TRUNK_E1) {
- boardConfig.specific.DigitalGateway.interfaceType = PKH_BOARD_INTERFACE_TYPE_E1;
- if ((status = PKH_BOARD_SetConfig(globals.open_boards[boardno], &boardConfig)) != PK_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error: [%s]\n",
- PKH_ERROR_GetText(status, error_text, sizeof(error_text)));
- }
- zap_set_flag(span_data, PK_FLAG_LOCKED);
- }
-
- TRY_OR_DIE(PKH_SPAN_Open(globals.open_boards[boardno], spanno, NULL, &span_data->handle), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_SPAN_GetConfig(span_data->handle, &span_data->span_config), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, span_data->handle, (PK_VOID*) span), PK_SUCCESS, error);
- }
-
- if (type == ZAP_CHAN_TYPE_FXO) {
- PKH_TTrunkConfig trunkConfig;
-
- TRY_OR_DIE(PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_TRUNK_Seize(chan_data->handle), PK_SUCCESS, error);
-
- if (profile && profile->general_config.region == PKH_TRUNK_EU) {
- TRY_OR_DIE(PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, error);
- trunkConfig.internationalControl = PKH_PHONE_INTERNATIONAL_CONTROL_EU;
- trunkConfig.audioFormat = PKH_AUDIO_ALAW;
- trunkConfig.compandMode = PKH_PHONE_AUDIO_ALAW;
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW;
- TRY_OR_DIE(PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, error);
- } else {
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW;
- }
-
-
- TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_TRUNK_Start(chan_data->handle), PK_SUCCESS, error);
- } else if (type == ZAP_CHAN_TYPE_FXS) {
- PKH_TPhoneConfig phoneConfig;
-
- if (profile && profile->general_config.region == PKH_TRUNK_EU) {
- TRY_OR_DIE(PKH_PHONE_GetConfig(chan_data->handle, &phoneConfig), PK_SUCCESS, error);
- phoneConfig.internationalControl = PKH_PHONE_INTERNATIONAL_CONTROL_EU;
- phoneConfig.compandMode = PKH_PHONE_AUDIO_ALAW;
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW;
- TRY_OR_DIE(PKH_PHONE_SetConfig(chan_data->handle, &phoneConfig), PK_SUCCESS, error);
- } else {
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW;
- }
-
- TRY_OR_DIE(PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_PHONE_Seize(chan_data->handle), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_PHONE_Start(chan_data->handle), PK_SUCCESS, error);
- } else if (type == ZAP_CHAN_TYPE_B) {
- TRY_OR_DIE(PKH_SPAN_SeizeChannel(span_data->handle, x), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_SPAN_GetMediaStreams(span_data->handle, x, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, error);
- } else if (type == ZAP_CHAN_TYPE_DQ921) {
- TRY_OR_DIE(PKH_SPAN_HDLC_Open(span_data->handle, PKH_SPAN_HDLC_MODE_NORMAL, &chan_data->handle), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_SPAN_HDLC_GetConfig(chan_data->handle, &chan_data->hdlc_config), PK_SUCCESS, error);
- chan_data->hdlc_config.channelId = x;
- TRY_OR_DIE(PKH_SPAN_HDLC_SetConfig(chan_data->handle, &chan_data->hdlc_config), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, error);
- TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, error);
-
- if (profile) {
- if (profile->cust_span) {
- span_data->span_config.framing = profile->span_config.framing;
- span_data->span_config.encoding = profile->span_config.encoding;
- span_data->span_config.loopLength = profile->span_config.loopLength;
- span_data->span_config.buildOut = profile->span_config.buildOut;
- span_data->span_config.compandMode = profile->span_config.compandMode;
- } else {
- if (profile->general_config.region == PKH_TRUNK_EU) {
- span_data->span_config = globals.e1_span_config;
- } else {
- span_data->span_config = globals.t1_span_config;
- }
- }
- } else {
- if (span->trunk_type == ZAP_TRUNK_E1) {
- span_data->span_config = globals.e1_span_config;
- } else {
- span_data->span_config = globals.t1_span_config;
- }
- }
-
- PKH_SPAN_SetConfig(span_data->handle, &span_data->span_config);
- TRY_OR_DIE(PKH_SPAN_Start(span_data->handle), PK_SUCCESS, error);
- }
-
- goto ok;
-
- error:
- PKH_ERROR_GetText(status, error_text, sizeof(error_text));
- zap_log(ZAP_LOG_ERROR, "failure configuring device b%ds%dc%d [%s]\n", boardno, spanno, x, error_text);
- continue;
- ok:
- zap_set_flag(chan_data, PK_FLAG_READY);
- status = PKH_RECORD_GetConfig(chan_data->media_in, &chan_data->record_config);
- chan_data->record_config.encoding = PKH_RECORD_ENCODING_MU_LAW;
- chan_data->record_config.samplingRate = PKH_RECORD_SAMPLING_RATE_8KHZ;
- chan_data->record_config.bufferSize = PIKA_BLOCK_SIZE;
- chan_data->record_config.numberOfBuffers = PIKA_NUM_BUFFERS;
- chan_data->record_config.VAD.enabled = PK_FALSE;
- //chan_data->record_config.speechSegmentEventsEnabled = PK_FALSE;
- //chan_data->record_config.gain = rxgain;
-
- status = PKH_PLAY_GetConfig(chan_data->media_out, &chan_data->play_config);
- chan_data->play_config.encoding = PKH_RECORD_ENCODING_MU_LAW;
- chan_data->play_config.samplingRate = PKH_RECORD_SAMPLING_RATE_8KHZ;
- chan_data->play_config.AGC.enabled = PK_FALSE;
- zap_log(ZAP_LOG_INFO, "configuring device b%ds%dc%d as OpenZAP device %d:%d\n", boardno, spanno, x, chan->span_id, chan->chan_id);
-
- if (profile) {
- zap_log(ZAP_LOG_INFO, "applying config profile %s to device %d:%d\n", profile->name, chan->span_id, chan->chan_id);
- chan_data->record_config.gain = profile->record_config.gain;
- chan_data->record_config.AGC = profile->record_config.AGC;
- chan_data->record_config.VAD = profile->record_config.VAD;
- chan_data->play_config.gain = profile->play_config.gain;
- chan_data->play_config.AGC = profile->play_config.AGC;
- chan_data->ec_enabled = profile->ec_enabled;
- chan_data->ec_config = profile->ec_config;
- }
-
- if (type == ZAP_CHAN_TYPE_B) {
- if (span_data->span_config.compandMode == PKH_SPAN_COMPAND_MODE_A_LAW) {
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW;
- } else {
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW;
- }
- }
-
- status = PKH_RECORD_SetConfig(chan_data->media_in, &chan_data->record_config);
- status = PKH_PLAY_SetConfig(chan_data->media_out, &chan_data->play_config);
-
- chan->physical_span_id = spanno;
- chan->physical_chan_id = x;
-
- chan->rate = 8000;
- chan->packet_len = (uint32_t)chan_data->record_config.bufferSize;
- chan->effective_interval = chan->native_interval = chan->packet_len / 8;
-
- PKH_RECORD_Start(chan_data->media_in);
- PKH_PLAY_Start(chan_data->media_out);
- if (chan_data->ec_enabled) {
- PKH_EC_SetConfig(chan_data->media_in, &chan_data->ec_config);
- PKH_EC_Start(chan_data->media_in, chan_data->media_in, chan_data->media_out);
- }
-
- if (!zap_strlen_zero(name)) {
- zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name));
- }
-
- if (!zap_strlen_zero(number)) {
- zap_copy_string(chan->chan_number, number, sizeof(chan->chan_number));
- }
-
- zap_channel_set_feature(chan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE);
- zap_buffer_create(&chan_data->digit_buffer, 128, 128, 0);
- zap_mutex_create(&chan_data->digit_mutex);
-
- configured++;
- }
-
-
- return configured;
-}
-
-/**
- * \brief Initialises an openzap pika span from a configuration string
- * \param span Openzap span
- * \param str Configuration string
- * \param type Openzap span type
- * \param name Openzap span name
- * \param number Openzap span number
- * \return Success or failure
- */
-static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span)
-{
- int items, i;
- char *mydata, *item_list[10];
- char *bd, *sp, *ch = NULL, *mx;
- int boardno;
- int channo;
- int spanno;
- int top = 0;
- unsigned configured = 0;
- char *profile_name = NULL;
- pika_channel_profile_t *profile = NULL;
-
- assert(str != NULL);
-
- mydata = strdup(str);
- assert(mydata != NULL);
-
- if ((profile_name = strchr(mydata, '@'))) {
- *profile_name++ = '\0';
- if (!zap_strlen_zero(profile_name)) {
- profile = (pika_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)profile_name);
- }
- }
-
- items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0])));
-
- for(i = 0; i < items; i++) {
- bd = item_list[i];
- if ((sp = strchr(bd, ':'))) {
- *sp++ = '\0';
- if ((ch = strchr(sp, ':'))) {
- *ch++ = '\0';
- }
- }
-
- if (!(bd && sp && ch)) {
- zap_log(ZAP_LOG_ERROR, "Invalid input\n");
- continue;
- }
-
- boardno = atoi(bd);
- channo = atoi(ch);
- spanno = atoi(sp);
-
-
- if (boardno < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid board number %d\n", boardno);
- continue;
- }
-
- if (channo < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid channel number %d\n", channo);
- continue;
- }
-
- if (spanno < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid span number %d\n", channo);
- continue;
- }
-
- if ((mx = strchr(ch, '-'))) {
- mx++;
- top = atoi(mx) + 1;
- } else {
- top = channo + 1;
- }
-
-
- if (top < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top);
- continue;
- }
-
- configured += pika_open_range(span, boardno, spanno, channo, top, type, name, number, profile);
-
- }
-
- free(mydata);
-
- return configured;
-}
-
-/**
- * \brief Opens Pika channel
- * \param zchan Channel to open
- * \return Success or failure
- */
-static ZIO_OPEN_FUNCTION(pika_open)
-{
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
-
- if (!chan_data && !zap_test_flag(chan_data, PK_FLAG_READY)) {
- return ZAP_FAIL;
- }
-
- if (chan_data->media_in_queue) {
- PKH_QUEUE_Flush(chan_data->media_in_queue);
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO || zchan->type == ZAP_CHAN_TYPE_B) {
- PKH_PLAY_Start(chan_data->media_out);
- }
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Closes Pika channel
- * \param zchan Channel to close
- * \return Success
- */
-static ZIO_CLOSE_FUNCTION(pika_close)
-{
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Waits for an event on a Pika channel
- * \param zchan Channel to open
- * \param flags Type of event to wait for
- * \param to Time to wait (in ms)
- * \return Success, failure or timeout
- */
-static ZIO_WAIT_FUNCTION(pika_wait)
-{
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
- PK_STATUS status;
- zap_wait_flag_t myflags = *flags;
- PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH];
-
- *flags = ZAP_NO_FLAGS;
-
- if (myflags & ZAP_READ) {
- if (chan_data->hdlc_bytes) {
- *flags |= ZAP_READ;
- return ZAP_SUCCESS;
- }
- status = PKH_QUEUE_WaitOnEvent(chan_data->media_in_queue, to, &chan_data->last_media_event);
-
- if (status == PK_SUCCESS) {
- if (chan_data->last_media_event.id == PKH_EVENT_QUEUE_TIMEOUT || chan_data->last_media_event.id == PKH_EVENT_RECORD_BUFFER_OVERFLOW) {
- return ZAP_TIMEOUT;
- }
-
- *flags |= ZAP_READ;
- return ZAP_SUCCESS;
- }
-
- PKH_EVENT_GetText(chan_data->last_media_event.id, event_text, sizeof(event_text));
- zap_log(ZAP_LOG_DEBUG, "Event: %s\n", event_text);
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Reads data from a Pika channel
- * \param zchan Channel to read from
- * \param data Data buffer
- * \param datalen Size of data buffer
- * \return Success or failure
- */
-static ZIO_READ_FUNCTION(pika_read)
-{
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
- PK_STATUS status;
- PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH];
- uint32_t len;
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
- if ((status = PKH_SPAN_HDLC_GetMessage(chan_data->handle, data, *datalen)) == PK_SUCCESS) {
- *datalen = chan_data->hdlc_bytes;
- chan_data->hdlc_bytes = 0;
- return ZAP_SUCCESS;
- }
- return ZAP_FAIL;
- }
-
- if (!(len = chan_data->last_media_event.p0)) {
- len = zchan->packet_len;
- }
-
- if (len < *datalen) {
- *datalen = len;
- }
-
- if ((status = PKH_RECORD_GetData(chan_data->media_in, data, *datalen)) == PK_SUCCESS) {
- return ZAP_SUCCESS;
- }
-
-
- PKH_ERROR_GetText(status, event_text, sizeof(event_text));
- zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", event_text);
- return ZAP_FAIL;
-}
-
-/**
- * \brief Writes data to a Pika channel
- * \param zchan Channel to write to
- * \param data Data buffer
- * \param datalen Size of data buffer
- * \return Success or failure
- */
-static ZIO_WRITE_FUNCTION(pika_write)
-{
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
- PK_STATUS status;
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
- if ((status = PKH_SPAN_HDLC_SendMessage(chan_data->handle, data, *datalen)) == PK_SUCCESS) {
- return ZAP_SUCCESS;
- }
- return ZAP_FAIL;
- }
-
- if (PKH_PLAY_AddData(chan_data->media_out, 0, data, *datalen) == PK_SUCCESS) {
- return ZAP_SUCCESS;
- }
-
- return ZAP_FAIL;
-}
-
-/**
- * \brief Executes an Openzap command on a Pika channel
- * \param zchan Channel to execute command on
- * \param command Openzap command to execute
- * \param obj Object (unused)
- * \return Success or failure
- */
-static ZIO_COMMAND_FUNCTION(pika_command)
-{
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
- //pika_span_data_t *span_data = (pika_span_data_t *) zchan->span->mod_data;
- PK_STATUS pk_status;
- zap_status_t status = ZAP_SUCCESS;
-
- switch(command) {
- case ZAP_COMMAND_OFFHOOK:
- {
- if ((pk_status = PKH_TRUNK_SetHookSwitch(chan_data->handle, PKH_TRUNK_OFFHOOK)) != PK_SUCCESS) {
- PKH_ERROR_GetText(pk_status, zchan->last_error, sizeof(zchan->last_error));
- GOTO_STATUS(done, ZAP_FAIL);
- } else {
- zap_set_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK);
- }
- }
- break;
- case ZAP_COMMAND_ONHOOK:
- {
- if ((pk_status = PKH_TRUNK_SetHookSwitch(chan_data->handle, PKH_TRUNK_ONHOOK)) != PK_SUCCESS) {
- PKH_ERROR_GetText(pk_status, zchan->last_error, sizeof(zchan->last_error));
- GOTO_STATUS(done, ZAP_FAIL);
- } else {
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK);
- }
- }
- break;
- case ZAP_COMMAND_GENERATE_RING_ON:
- {
- if ((pk_status = PKH_PHONE_RingStart(chan_data->handle, 0, 0)) != PK_SUCCESS) {
- PKH_ERROR_GetText(pk_status, zchan->last_error, sizeof(zchan->last_error));
- GOTO_STATUS(done, ZAP_FAIL);
- } else {
- zap_set_flag_locked(zchan, ZAP_CHANNEL_RINGING);
- }
- }
- break;
- case ZAP_COMMAND_GENERATE_RING_OFF:
- {
- if ((pk_status = PKH_PHONE_RingStop(chan_data->handle)) != PK_SUCCESS) {
- PKH_ERROR_GetText(pk_status, zchan->last_error, sizeof(zchan->last_error));
- GOTO_STATUS(done, ZAP_FAIL);
- } else {
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING);
- }
- }
- break;
- case ZAP_COMMAND_GET_INTERVAL:
- {
-
- ZAP_COMMAND_OBJ_INT = zchan->native_interval;
-
- }
- break;
- case ZAP_COMMAND_SET_INTERVAL:
- {
- int interval = ZAP_COMMAND_OBJ_INT;
- int len = interval * 8;
- chan_data->record_config.bufferSize = len;
- chan_data->record_config.numberOfBuffers = (PK_UINT)chan_data->record_config.bufferSize;
- zchan->packet_len = (uint32_t)chan_data->record_config.bufferSize;
- zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8;
- PKH_RECORD_SetConfig(chan_data->media_in, &chan_data->record_config);
- GOTO_STATUS(done, ZAP_SUCCESS);
- }
- break;
- case ZAP_COMMAND_GET_DTMF_ON_PERIOD:
- {
-
- ZAP_COMMAND_OBJ_INT = zchan->dtmf_on;
- GOTO_STATUS(done, ZAP_SUCCESS);
-
- }
- break;
- case ZAP_COMMAND_GET_DTMF_OFF_PERIOD:
- {
- ZAP_COMMAND_OBJ_INT = zchan->dtmf_on;
- GOTO_STATUS(done, ZAP_SUCCESS);
- }
- break;
- case ZAP_COMMAND_SET_DTMF_ON_PERIOD:
- {
- int val = ZAP_COMMAND_OBJ_INT;
- if (val > 10 && val < 1000) {
- zchan->dtmf_on = val;
- GOTO_STATUS(done, ZAP_SUCCESS);
- } else {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val);
- GOTO_STATUS(done, ZAP_FAIL);
- }
- }
- break;
- case ZAP_COMMAND_SET_DTMF_OFF_PERIOD:
- {
- int val = ZAP_COMMAND_OBJ_INT;
- if (val > 10 && val < 1000) {
- zchan->dtmf_off = val;
- GOTO_STATUS(done, ZAP_SUCCESS);
- } else {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val);
- GOTO_STATUS(done, ZAP_FAIL);
- }
- }
- break;
- case ZAP_COMMAND_SEND_DTMF:
- {
- char *digits = ZAP_COMMAND_OBJ_CHAR_P;
- zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits);
- zap_mutex_lock(chan_data->digit_mutex);
- zap_buffer_write(chan_data->digit_buffer, digits, strlen(digits));
- zap_mutex_unlock(chan_data->digit_mutex);
- pk_status = PKH_PLAY_Stop(chan_data->media_out);
-
- if (pk_status != PK_SUCCESS) {
- PKH_ERROR_GetText(pk_status, zchan->last_error, sizeof(zchan->last_error));
- GOTO_STATUS(done, ZAP_FAIL);
- }
- GOTO_STATUS(done, ZAP_SUCCESS);
- }
- break;
- default:
- break;
- };
-
- done:
- return status;
-}
-
-/**
- * \brief Checks for events on a Pika span
- * \param span Span to check for events
- * \param ms Time to wait for event
- * \return Success if event is waiting or failure if not
- */
-static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event)
-{
- pika_span_data_t *span_data = (pika_span_data_t *) span->mod_data;
- PK_STATUS status;
- PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH];
-
- status = PKH_QUEUE_WaitOnEvent(span_data->event_queue, ms, &span_data->last_oob_event);
-
- if (status == PK_SUCCESS) {
- zap_channel_t *zchan = NULL;
- uint32_t *data = (uint32_t *) span_data->last_oob_event.userData;
- zap_data_type_t data_type = ZAP_TYPE_NONE;
-
- if (span_data->last_oob_event.id == PKH_EVENT_QUEUE_TIMEOUT) {
- return ZAP_TIMEOUT;
- }
-
- if (data) {
- data_type = *data;
- }
-
- if (data_type == ZAP_TYPE_CHANNEL) {
- zchan = span_data->last_oob_event.userData;
- } else if (data_type == ZAP_TYPE_SPAN) {
- zap_time_t last_event_time = zap_current_time_in_ms();
- uint32_t event_id = 0;
-
- switch (span_data->last_oob_event.id) {
- case PKH_EVENT_SPAN_ALARM_T1_RED:
- case PKH_EVENT_SPAN_ALARM_T1_YELLOW:
- case PKH_EVENT_SPAN_ALARM_T1_AIS:
- case PKH_EVENT_SPAN_ALARM_E1_RED:
- case PKH_EVENT_SPAN_ALARM_E1_RAI:
- case PKH_EVENT_SPAN_ALARM_E1_AIS:
- case PKH_EVENT_SPAN_ALARM_E1_RMAI:
- case PKH_EVENT_SPAN_ALARM_E1_TS16AIS:
- case PKH_EVENT_SPAN_ALARM_E1_TS16LOS:
- case PKH_EVENT_SPAN_OUT_OF_SYNC:
- case PKH_EVENT_SPAN_FRAMING_ERROR:
- case PKH_EVENT_SPAN_LOSS_OF_SIGNAL:
- case PKH_EVENT_SPAN_OUT_OF_CRC_MF_SYNC:
- case PKH_EVENT_SPAN_OUT_OF_CAS_MF_SYNC:
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_T1_RED_CLEAR:
- case PKH_EVENT_SPAN_ALARM_T1_YELLOW_CLEAR:
- case PKH_EVENT_SPAN_ALARM_T1_AIS_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_RED_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_RAI_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_AIS_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_RMAI_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_TS16AIS_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_TS16LOS_CLEAR:
- case PKH_EVENT_SPAN_IN_SYNC:
- case PKH_EVENT_SPAN_LOSS_OF_SIGNAL_CLEAR:
- case PKH_EVENT_SPAN_IN_CRC_MF_SYNC:
- case PKH_EVENT_SPAN_IN_CAS_MF_SYNC:
- event_id = ZAP_OOB_ALARM_CLEAR;
- break;
- case PKH_EVENT_SPAN_MESSAGE:
- case PKH_EVENT_SPAN_ABCD_SIGNAL_CHANGE:
- break;
- }
-
- if (event_id) {
- uint32_t x = 0;
- zap_channel_t *zchan;
- pika_chan_data_t *chan_data;
- for(x = 1; x <= span->chan_count; x++) {
- zchan = span->channels[x];
- assert(zchan != NULL);
- chan_data = (pika_chan_data_t *) zchan->mod_data;
- assert(chan_data != NULL);
-
-
- zap_set_flag(zchan, ZAP_CHANNEL_EVENT);
- zchan->last_event_time = last_event_time;
- chan_data->last_oob_event = span_data->last_oob_event;
- }
-
- }
-
- }
-
- PKH_EVENT_GetText(span_data->last_oob_event.id, event_text, sizeof(event_text));
- //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", event_text);
-
- if (zchan) {
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
-
- assert(chan_data != NULL);
- zap_set_flag(zchan, ZAP_CHANNEL_EVENT);
- zchan->last_event_time = zap_current_time_in_ms();
- chan_data->last_oob_event = span_data->last_oob_event;
- }
-
- return ZAP_SUCCESS;
- }
-
- return ZAP_FAIL;
-}
-
-/**
- * \brief Retrieves an event from a Pika span
- * \param span Span to retrieve event from
- * \param event Openzap event to return
- * \return Success or failure
- */
-static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event)
-{
- uint32_t i, event_id = 0;
-
- for(i = 1; i <= span->chan_count; i++) {
- if (zap_test_flag(span->channels[i], ZAP_CHANNEL_EVENT)) {
- pika_chan_data_t *chan_data = (pika_chan_data_t *) span->channels[i]->mod_data;
- PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH];
-
- zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT);
-
- PKH_EVENT_GetText(chan_data->last_oob_event.id, event_text, sizeof(event_text));
-
- switch(chan_data->last_oob_event.id) {
- case PKH_EVENT_HDLC_MESSAGE:
- chan_data->hdlc_bytes = chan_data->last_oob_event.p2;
- continue;
- case PKH_EVENT_TRUNK_HOOKFLASH:
- event_id = ZAP_OOB_FLASH;
- break;
- case PKH_EVENT_TRUNK_RING_OFF:
- event_id = ZAP_OOB_RING_STOP;
- break;
- case PKH_EVENT_TRUNK_RING_ON:
- event_id = ZAP_OOB_RING_START;
- break;
-
- case PKH_EVENT_PHONE_OFFHOOK:
- zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_OFFHOOK);
- event_id = ZAP_OOB_OFFHOOK;
- break;
-
- case PKH_EVENT_TRUNK_BELOW_THRESHOLD:
- case PKH_EVENT_TRUNK_ABOVE_THRESHOLD:
- case PKH_EVENT_PHONE_ONHOOK:
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_OFFHOOK);
- event_id = ZAP_OOB_ONHOOK;
- break;
-
-
-
- case PKH_EVENT_SPAN_ALARM_T1_RED:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED);
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "RED ALARM");
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_T1_YELLOW:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_YELLOW);
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "YELLOW ALARM");
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_T1_AIS:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS);
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "AIS ALARM");
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_E1_RED:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED);
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "RED ALARM");
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_E1_RAI:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RAI);
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "RAI ALARM");
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_E1_AIS:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS);
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "AIS ALARM");
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_E1_RMAI:
- case PKH_EVENT_SPAN_ALARM_E1_TS16AIS:
- case PKH_EVENT_SPAN_ALARM_E1_TS16LOS:
- case PKH_EVENT_SPAN_OUT_OF_SYNC:
- case PKH_EVENT_SPAN_FRAMING_ERROR:
- case PKH_EVENT_SPAN_LOSS_OF_SIGNAL:
- case PKH_EVENT_SPAN_OUT_OF_CRC_MF_SYNC:
- case PKH_EVENT_SPAN_OUT_OF_CAS_MF_SYNC:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_GENERAL);
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "GENERAL ALARM");
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- case PKH_EVENT_SPAN_ALARM_T1_RED_CLEAR:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED);
- case PKH_EVENT_SPAN_ALARM_T1_YELLOW_CLEAR:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_YELLOW);
- case PKH_EVENT_SPAN_ALARM_T1_AIS_CLEAR:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS);
- case PKH_EVENT_SPAN_ALARM_E1_RED_CLEAR:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED);
- case PKH_EVENT_SPAN_ALARM_E1_RAI_CLEAR:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RAI);
- case PKH_EVENT_SPAN_ALARM_E1_AIS_CLEAR:
- zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS);
- case PKH_EVENT_SPAN_ALARM_E1_RMAI_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_TS16AIS_CLEAR:
- case PKH_EVENT_SPAN_ALARM_E1_TS16LOS_CLEAR:
- case PKH_EVENT_SPAN_IN_SYNC:
- case PKH_EVENT_SPAN_LOSS_OF_SIGNAL_CLEAR:
- case PKH_EVENT_SPAN_IN_CRC_MF_SYNC:
- case PKH_EVENT_SPAN_IN_CAS_MF_SYNC:
- zap_clear_alarm_flag(span->channels[i], ZAP_ALARM_GENERAL);
- event_id = ZAP_OOB_ALARM_CLEAR;
- break;
- case PKH_EVENT_SPAN_MESSAGE:
- case PKH_EVENT_SPAN_ABCD_SIGNAL_CHANGE:
- break;
-
-
-
-
- case PKH_EVENT_TRUNK_ONHOOK:
- case PKH_EVENT_TRUNK_OFFHOOK:
- case PKH_EVENT_TRUNK_DIALED :
- case PKH_EVENT_TRUNK_REVERSAL:
- case PKH_EVENT_TRUNK_LCSO:
- case PKH_EVENT_TRUNK_DROPOUT:
- case PKH_EVENT_TRUNK_LOF:
- case PKH_EVENT_TRUNK_RX_OVERLOAD:
- default:
- zap_log(ZAP_LOG_DEBUG, "Unhandled event %d on channel %d [%s]\n", chan_data->last_oob_event.id, i, event_text);
- event_id = ZAP_OOB_INVALID;
- break;
- }
-
- span->channels[i]->last_event_time = 0;
- span->event_header.e_type = ZAP_EVENT_OOB;
- span->event_header.enum_id = event_id;
- span->event_header.channel = span->channels[i];
- *event = &span->event_header;
- return ZAP_SUCCESS;
- }
- }
-
- return ZAP_FAIL;
-}
-
-/**
- * \brief Destroys a Pika Span
- * \param span Span to destroy
- * \return Success
- */
-static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy)
-{
- pika_span_data_t *span_data = (pika_span_data_t *) span->mod_data;
-
- if (span_data) {
- PKH_QUEUE_Destroy(span_data->event_queue);
- free(span_data);
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Destroys a Pika Channel
- * \param zchan Channel to destroy
- * \return Success or failure
- */
-static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy)
-{
- pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data;
- pika_span_data_t *span_data = (pika_span_data_t *) zchan->span->mod_data;
-
- if (!chan_data) {
- return ZAP_FAIL;
- }
-
- if (!zap_test_flag(chan_data, PK_FLAG_READY)) {
- goto end;
- }
-
- PKH_RECORD_Stop(chan_data->media_in);
- PKH_PLAY_Stop(chan_data->media_out);
- PKH_QUEUE_Destroy(chan_data->media_in_queue);
- PKH_QUEUE_Destroy(chan_data->media_out_queue);
-
- switch(zchan->type) {
- case ZAP_CHAN_TYPE_FXS:
- PKH_QUEUE_Detach(span_data->event_queue, chan_data->handle);
- PKH_PHONE_Close(chan_data->handle);
- break;
- case ZAP_CHAN_TYPE_FXO:
- PKH_QUEUE_Detach(span_data->event_queue, chan_data->handle);
- PKH_TRUNK_Close(chan_data->handle);
- break;
- case ZAP_CHAN_TYPE_DQ921:
- PKH_SPAN_Stop(span_data->handle);
- break;
- default:
- break;
- }
-
-
- zap_mutex_destroy(&chan_data->digit_mutex);
- zap_buffer_destroy(&chan_data->digit_buffer);
-
- end:
- zap_safe_free(chan_data);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Gets alarms from a Pika Channel (does nothing)
- * \param zchan Channel to get alarms from
- * \return Failure
- */
-static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms)
-{
- return ZAP_FAIL;
-}
-
-static zap_io_interface_t pika_interface;
-
-/**
- * \brief Loads Pika IO module
- * \param zio Openzap IO interface
- * \return Success or failure
- */
-static ZIO_IO_LOAD_FUNCTION(pika_init)
-{
-
- PK_STATUS status;
- PK_CHAR error_text[PKH_ERROR_MAX_NAME_LENGTH];
- uint32_t i;
- int ok = 0;
- PKH_TLogMasks m;
- TPikaHandle tmpHandle;
-
- assert(zio != NULL);
- memset(&pika_interface, 0, sizeof(pika_interface));
- memset(&globals, 0, sizeof(globals));
- globals.general_config.region = PKH_TRUNK_NA;
-
- globals.profile_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
-
- // Open the system object, to enumerate boards configured for this system
- if ((status = PKH_SYSTEM_Open(&globals.system_handle)) != PK_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error: PKH_SYSTEM_Open failed(%s)!\n",
- PKH_ERROR_GetText(status, error_text, sizeof(error_text)));
- return ZAP_FAIL;
- }
-
- // Retrieves a list of all boards in this system, existing,
- // or listed in pika.cfg
- if ((status = PKH_SYSTEM_Detect(globals.system_handle, &globals.board_list)) != PK_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error: PKH_SYSTEM_Detect failed(%s)!\n",
- PKH_ERROR_GetText(status, error_text, sizeof(error_text)));
- return ZAP_FAIL;
- }
-
- PKH_SYSTEM_GetConfig(globals.system_handle, &globals.system_config);
- globals.system_config.maxAudioProcessBlockSize = PIKA_BLOCK_LEN;
- globals.system_config.playBufferSize = PIKA_BLOCK_SIZE;
- globals.system_config.recordBufferSize = PIKA_BLOCK_SIZE;
- globals.system_config.recordNumberOfBuffers = PIKA_NUM_BUFFERS;
- PKH_SYSTEM_SetConfig(globals.system_handle, &globals.system_config);
-
- status = PKH_MEDIA_STREAM_Create(&tmpHandle);
- status = PKH_RECORD_GetConfig(tmpHandle, &globals.record_config);
- status = PKH_PLAY_GetConfig(tmpHandle, &globals.play_config);
- status = PKH_EC_GetConfig(tmpHandle, &globals.ec_config);
- status = PKH_MEDIA_STREAM_Destroy(tmpHandle);
-
-
-
- zap_log(ZAP_LOG_DEBUG, "Found %u board%s\n", globals.board_list.numberOfBoards, globals.board_list.numberOfBoards == 1 ? "" : "s");
- for(i = 0; i < globals.board_list.numberOfBoards; ++i) {
- zap_log(ZAP_LOG_INFO, "Found PIKA board type:[%s] id:[%u] serno:[%u]\n",
- pika_board_type_string(globals.board_list.board[i].type), globals.board_list.board[i].id, (uint32_t)
- globals.board_list.board[i].serialNumber);
-
- if (globals.board_list.board[i].type == PKH_BOARD_TYPE_DIGITAL_GATEWAY) {
- TPikaHandle board_handle, span_handle;
- PKH_TBoardConfig boardConfig;
- PKH_BOARD_GetConfig(board_handle, &boardConfig);
- PKH_BOARD_Open(globals.board_list.board[i].id, NULL, &board_handle);
- PKH_SPAN_Open(board_handle, 0, NULL, &span_handle);
- PKH_SPAN_GetConfig(span_handle, &globals.t1_span_config);
- PKH_SPAN_Close(span_handle);
- boardConfig.specific.DigitalGateway.interfaceType = PKH_BOARD_INTERFACE_TYPE_E1;
- PKH_BOARD_SetConfig(board_handle, &boardConfig);
- PKH_SPAN_Open(board_handle, 0, NULL, &span_handle);
- PKH_SPAN_GetConfig(span_handle, &globals.e1_span_config);
- PKH_SPAN_Close(span_handle);
- boardConfig.specific.DigitalGateway.interfaceType = PKH_BOARD_INTERFACE_TYPE_T1;
- PKH_BOARD_SetConfig(board_handle, &boardConfig);
- PKH_BOARD_Close(board_handle);
- }
- ok++;
-
- }
-
- if (!ok) {
- return ZAP_FAIL;
- }
-
- pika_interface.name = "pika";
- pika_interface.configure = pika_configure;
- pika_interface.configure_span = pika_configure_span;
- pika_interface.open = pika_open;
- pika_interface.close = pika_close;
- pika_interface.wait = pika_wait;
- pika_interface.read = pika_read;
- pika_interface.write = pika_write;
- pika_interface.command = pika_command;
- pika_interface.poll_event = pika_poll_event;
- pika_interface.next_event = pika_next_event;
- pika_interface.channel_destroy = pika_channel_destroy;
- pika_interface.span_destroy = pika_span_destroy;
- pika_interface.get_alarms = pika_get_alarms;
- *zio = &pika_interface;
-
-
- zap_log(ZAP_LOG_INFO, "Dumping Default configs:\n");
- zap_log(ZAP_LOG_INFO, "rx-gain => %0.2f\n", (float)globals.record_config.gain);
- zap_log(ZAP_LOG_INFO, "rx-agc-enabled => %s\n", globals.record_config.AGC.enabled ? "true" : "false");
- zap_log(ZAP_LOG_INFO, "rx-agc-targetPower => %0.2f\n", (float)globals.record_config.AGC.targetPower);
- zap_log(ZAP_LOG_INFO, "rx-agc-minGain => %0.2f\n", (float)globals.record_config.AGC.minGain);
- zap_log(ZAP_LOG_INFO, "rx-agc-maxGain => %0.2f\n", (float)globals.record_config.AGC.maxGain);
- zap_log(ZAP_LOG_INFO, "rx-agc-attackRate => %d\n", (int)globals.record_config.AGC.attackRate);
- zap_log(ZAP_LOG_INFO, "rx-agc-decayRate => %d\n", (int)globals.record_config.AGC.decayRate);
- zap_log(ZAP_LOG_INFO, "rx-agc-speechThreshold => %0.2f\n", (float)globals.record_config.AGC.speechThreshold);
- zap_log(ZAP_LOG_INFO, "rx-vad-enabled => %s\n", globals.record_config.VAD.enabled ? "true" : "false");
- zap_log(ZAP_LOG_INFO, "rx-vad-activationThreshold => %0.2f\n", (float)globals.record_config.VAD.activationThreshold);
- zap_log(ZAP_LOG_INFO, "rx-vad-activationDebounceTime => %d\n", (int)globals.record_config.VAD.activationDebounceTime);
- zap_log(ZAP_LOG_INFO, "rx-vad-deactivationThreshold => %0.2f\n", (float)globals.record_config.VAD.deactivationThreshold);
- zap_log(ZAP_LOG_INFO, "rx-vad-deactivationDebounceTime => %d\n", (int)globals.record_config.VAD.deactivationDebounceTime);
- zap_log(ZAP_LOG_INFO, "rx-vad-preSpeechBufferSize => %d\n", (int)globals.record_config.VAD.preSpeechBufferSize);
- zap_log(ZAP_LOG_INFO, "tx-gain => %0.2f\n", (float)globals.play_config.gain);
- zap_log(ZAP_LOG_INFO, "tx-agc-enabled => %s\n", globals.play_config.AGC.enabled ? "true" : "false");
- zap_log(ZAP_LOG_INFO, "tx-agc-targetPower => %0.2f\n", (float)globals.play_config.AGC.targetPower);
- zap_log(ZAP_LOG_INFO, "tx-agc-minGain => %0.2f\n", (float)globals.play_config.AGC.minGain);
- zap_log(ZAP_LOG_INFO, "tx-agc-maxGain => %0.2f\n", (float)globals.play_config.AGC.maxGain);
- zap_log(ZAP_LOG_INFO, "tx-agc-attackRate => %d\n", (int)globals.play_config.AGC.attackRate);
- zap_log(ZAP_LOG_INFO, "tx-agc-decayRate => %d\n", (int)globals.play_config.AGC.decayRate);
- zap_log(ZAP_LOG_INFO, "tx-agc-speechThreshold => %0.2f\n", (float)globals.play_config.AGC.speechThreshold);
- zap_log(ZAP_LOG_INFO, "ec-doubleTalkerThreshold => %0.2f\n", (float)globals.ec_config.doubleTalkerThreshold);
- zap_log(ZAP_LOG_INFO, "ec-speechPresentThreshold => %0.2f\n", (float)globals.ec_config.speechPresentThreshold);
- zap_log(ZAP_LOG_INFO, "ec-echoSuppressionThreshold => %0.2f\n", (float)globals.ec_config.echoSuppressionThreshold);
- zap_log(ZAP_LOG_INFO, "ec-echoSuppressionEnabled => %s\n", globals.ec_config.echoSuppressionEnabled ? "true" : "false");
- zap_log(ZAP_LOG_INFO, "ec-comfortNoiseEnabled => %s\n", globals.ec_config.comfortNoiseEnabled ? "true" : "false");
- zap_log(ZAP_LOG_INFO, "ec-adaptationModeEnabled => %s\n", globals.ec_config.adaptationModeEnabled ? "true" : "false");
-
-
-
- memset(&m, 0, sizeof(m));
- //m.apiMask = 0xffffffff;
- //PKH_LOG_SetMasks(&m);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Unloads Pika IO module
- * \return Success
- */
-static ZIO_IO_UNLOAD_FUNCTION(pika_destroy)
-{
- uint32_t x;
- PK_STATUS status;
- PK_CHAR error_text[PKH_ERROR_MAX_NAME_LENGTH];
-
- for (x = 0; x < MAX_NUMBER_OF_TRUNKS; x++) {
- if (globals.open_boards[x]) {
- zap_log(ZAP_LOG_INFO, "Closing board %u\n", x);
- PKH_BOARD_Close(globals.open_boards[x]);
- }
- }
-
- // The system can now be closed.
- if ((status = PKH_SYSTEM_Close(globals.system_handle)) != PK_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error: PKH_SYSTEM_Close failed(%s)!\n",
- PKH_ERROR_GetText(status, error_text, sizeof(error_text)));
- } else {
- zap_log(ZAP_LOG_INFO, "Closing system handle\n");
- }
-
- hashtable_destroy(globals.profile_hash);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Pika IO module definition
- */
-EX_DECLARE_DATA zap_module_t zap_module = {
- "pika",
- pika_init,
- pika_destroy,
-};
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h b/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h
deleted file mode 100644
index 42e7571da2..0000000000
--- a/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_PIKA_H
-#define ZAP_PIKA_H
-#include "openzap.h"
-#include "pikahmpapi.h"
-
-
-
-#define PIKA_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type);
-#define PIKA_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \
- _TYPE _FUNC1 (const char *name) \
- { \
- int i; \
- _TYPE t = _MAX ; \
- \
- for (i = 0; i < _MAX ; i++) { \
- if (!strcasecmp(name, _STRINGS[i])) { \
- t = (_TYPE) i; \
- break; \
- } \
- } \
- \
- return t; \
- } \
- const char * _FUNC2 (_TYPE type) \
- { \
- if (type > _MAX) { \
- type = _MAX; \
- } \
- return _STRINGS[(int)type]; \
- }
-
-
-typedef enum {
- PIKA_SPAN_FRAMING_T1_D4,
- PIKA_SPAN_FRAMING_T1_ESF,
- PIKA_SPAN_FRAMING_E1_BASIC,
- PIKA_SPAN_FRAMING_E1_CRC4,
- PIKA_SPAN_INVALID
-} PIKA_TSpanFraming;
-#define PIKA_SPAN_STRINGS "T1_D4", "T1_ESF", "E1_BASIC", "E1_CRC4"
-PIKA_STR2ENUM_P(pika_str2span, pika_span2str, PIKA_TSpanFraming)
-
-typedef enum {
- PIKA_SPAN_ENCODING_T1_AMI_ZS_NONE,
- PIKA_SPAN_ENCODING_T1_AMI_ZS_GTE,
- PIKA_SPAN_ENCODING_T1_AMI_ZS_BELL,
- PIKA_SPAN_ENCODING_T1_AMI_ZS_JAM8,
- PIKA_SPAN_ENCODING_T1_B8ZS,
- PIKA_SPAN_ENCODING_E1_AMI,
- PIKA_SPAN_ENCODING_E1_HDB3,
- PIKA_SPAN_ENCODING_INVALID
-} PIKA_TSpanEncoding;
-#define PIKA_SPAN_ENCODING_STRINGS "T1_AMI_ZS_NONE", "T1_AMI_ZS_GTE", "T1_AMI_ZS_BELL", "T1_AMI_ZS_JAM8", "T1_B8ZS", "E1_AMI", "E1_HDB3"
-PIKA_STR2ENUM_P(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding)
-
-typedef enum {
- PIKA_SPAN_LOOP_LENGTH_SHORT_HAUL,
- PIKA_SPAN_LOOP_LENGTH_LONG_HAUL,
- PIKA_SPAN_LOOP_INVALID
-} PIKA_TSpanLoopLength;
-#define PIKA_LL_STRINGS "SHORT_HAUL", "LONG_HAUL"
-PIKA_STR2ENUM_P(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength)
-
-typedef enum {
- PIKA_SPAN_LBO_T1_LONG_0_DB,
- PIKA_SPAN_LBO_T1_LONG_7_DB,
- PIKA_SPAN_LBO_T1_LONG_15_DB,
- PIKA_SPAN_LBO_T1_LONG_22_DB,
- PIKA_SPAN_LBO_T1_SHORT_133_FT,
- PIKA_SPAN_LBO_T1_SHORT_266_FT,
- PIKA_SPAN_LBO_T1_SHORT_399_FT,
- PIKA_SPAN_LBO_T1_SHORT_533_FT,
- PIKA_SPAN_LBO_T1_SHORT_655_FT,
- PIKA_SPAN_LBO_E1_WAVEFORM_120_OHM,
- PIKA_SPAN_LBO_INVALID
-} PIKA_TSpanBuildOut;
-#define PIKA_LBO_STRINGS "T1_LONG_0_DB", "T1_LONG_7_DB", "T1_LONG_15_DB", "T1_LONG_22_DB", "T1_SHORT_133_FT", "T1_SHORT_266_FT", "T1_SHORT_399_FT", "T1_SHORT_533_FT", "T1_SHORT_655_FT", "E1_WAVEFORM_120_OHM"
-PIKA_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut)
-
-typedef enum {
- PIKA_SPAN_COMPAND_MODE_MU_LAW = 1,
- PIKA_SPAN_COMPAND_MODE_A_LAW,
- PIKA_SPAN_COMPAND_MODE_INVALID
-} PIKA_TSpanCompandMode;
-#define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW"
-PIKA_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode)
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c
deleted file mode 100644
index 85456d2645..0000000000
--- a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c
+++ /dev/null
@@ -1,1364 +0,0 @@
-/*
- * Copyright (c) 2009, Moises Silva
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include
-#include
-#include
-#include "openzap.h"
-
-/* debug thread count for r2 legs */
-static zap_mutex_t* g_thread_count_mutex;
-static int32_t g_thread_count = 0;
-
-/* when the users kills a span we clear this flag to kill the signaling thread */
-/* FIXME: what about the calls that are already up-and-running? */
-typedef enum {
- ZAP_R2_RUNNING = (1 << 0),
-} zap_r2_flag_t;
-
-/* private call information stored in zchan->call_data void* ptr */
-#define R2CALL(zchan) ((zap_r2_call_t*)((zchan)->call_data))
-typedef struct zap_r2_call_t {
- openr2_chan_t *r2chan;
- int accepted:1;
- int answer_pending:1;
- int state_ack_pending:1;
- int disconnect_rcvd:1;
- int zap_started:1;
- zap_channel_state_t chanstate;
- zap_size_t dnis_index;
- zap_size_t ani_index;
- char name[10];
-} zap_r2_call_t;
-
-/* this is just used as place holder in the stack when configuring the span to avoid using bunch of locals */
-typedef struct oz_r2_conf_s {
- /* openr2 types */
- openr2_variant_t variant;
- openr2_calling_party_category_t category;
- openr2_log_level_t loglevel;
-
- /* strings */
- char *logdir;
- char *advanced_protocol_file;
-
- /* ints */
- int32_t max_ani;
- int32_t max_dnis;
- int32_t mfback_timeout;
- int32_t metering_pulse_timeout;
-
- /* booleans */
- int immediate_accept;
- int skip_category;
- int get_ani_first;
- int call_files;
- int double_answer;
- int charge_calls;
- int forced_release;
- int allow_collect_calls;
-} oz_r2_conf_t;
-
-/* r2 configuration stored in span->signal_data */
-typedef struct zap_r2_data_s {
- /* span flags */
- zap_r2_flag_t flags;
- /* openr2 handle for the R2 variant context */
- openr2_context_t *r2context;
- /* category to use when making calls */
- openr2_calling_party_category_t category;
- /* whether to use OR2_CALL_WITH_CHARGE or OR2_CALL_NO_CHARGE when accepting a call */
- int charge_calls:1;
- /* allow or reject collect calls */
- int allow_collect_calls:1;
- /* whether to use forced release when hanging up */
- int forced_release:1;
- /* whether accept the call when offered, or wait until the user decides to accept */
- int accept_on_offer:1;
-} zap_r2_data_t;
-
-/* one element per span will be stored in g_mod_data_hash global var to keep track of them
- and destroy them on module unload */
-typedef struct zap_r2_span_pvt_s {
- openr2_context_t *r2context; /* r2 context allocated for this span */
- zap_hash_t *r2calls; /* hash table of allocated call data per channel for this span */
-} zap_r2_span_pvt_t;
-
-/* span monitor thread */
-static void *zap_r2_run(zap_thread_t *me, void *obj);
-
-/* channel monitor thread */
-static void *zap_r2_channel_run(zap_thread_t *me, void *obj);
-
-/* hash of all the private span allocations
- we need to keep track of them to destroy them when unloading the module
- since openzap does not notify signaling modules when destroying a span
- span -> zap_r2_mod_allocs_t */
-static zap_hash_t *g_mod_data_hash;
-
-/* IO interface for the command API */
-static zap_io_interface_t g_zap_r2_interface;
-
-static void oz_r2_clean_call(zap_r2_call_t *call)
-{
- openr2_chan_t *r2chan = call->r2chan;
- memset(call, 0, sizeof(*call));
- call->r2chan = r2chan;
-}
-
-static void oz_r2_accept_call(zap_channel_t *zchan)
-{
- openr2_chan_t *r2chan = R2CALL(zchan)->r2chan;
- // FIXME: not always accept as no charge, let the user decide that
- // also we should check the return code from openr2_chan_accept_call and handle error condition
- // hanging up the call with protocol error as the reason, this openr2 API will fail only when there something
- // wrong at the I/O layer or the library itself
- openr2_chan_accept_call(r2chan, OR2_CALL_NO_CHARGE);
- R2CALL(zchan)->accepted = 1;
-}
-
-static void oz_r2_answer_call(zap_channel_t *zchan)
-{
- openr2_chan_t *r2chan = R2CALL(zchan)->r2chan;
- // FIXME
- // 1. check openr2_chan_answer_call return code
- // 2. The openr2_chan_answer_call_with_mode should be used depending on user settings
- // openr2_chan_answer_call_with_mode(r2chan, OR2_ANSWER_SIMPLE);
- openr2_chan_answer_call(r2chan);
- R2CALL(zchan)->answer_pending = 0;
-}
-
-static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(r2_outgoing_call)
-{
- zap_status_t status;
- zap_mutex_lock(zchan->mutex);
-
- /* the channel may be down but the thread not quite done */
- zap_wait_for_flag_cleared(zchan, ZAP_CHANNEL_INTHREAD, 200);
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
- zap_log(ZAP_LOG_ERROR, "%d:%d Yay! R2 outgoing call in channel that is already in thread.\n",
- zchan->span_id, zchan->chan_id);
- zap_mutex_unlock(zchan->mutex);
- return ZAP_FAIL;
- }
-
- oz_r2_clean_call(zchan->call_data);
- R2CALL(zchan)->chanstate = ZAP_CHANNEL_STATE_DOWN;
- zap_channel_set_state(zchan, ZAP_CHANNEL_STATE_DIALING, 0);
- zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
- R2CALL(zchan)->zap_started = 1;
- zap_mutex_unlock(zchan->mutex);
-
- status = zap_thread_create_detached(zap_r2_channel_run, zchan);
- if (status == ZAP_FAIL) {
- zap_log(ZAP_LOG_ERROR, "%d:%d Cannot handle request to start call in channel, failed to create thread!\n",
- zchan->span_id, zchan->chan_id);
- zap_channel_done(zchan);
- return ZAP_FAIL;
- }
-
- return ZAP_SUCCESS;
-}
-
-static zap_status_t zap_r2_start(zap_span_t *span)
-{
- zap_r2_data_t *r2_data = span->signal_data;
- zap_set_flag(r2_data, ZAP_R2_RUNNING);
- return zap_thread_create_detached(zap_r2_run, span);
-}
-
-/* always called from the monitor thread */
-static void zap_r2_on_call_init(openr2_chan_t *r2chan)
-{
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
- zap_status_t status;
- zap_log(ZAP_LOG_NOTICE, "Received request to start call on chan %d\n", openr2_chan_get_number(r2chan));
-
- zap_mutex_lock(zchan->mutex);
-
- if (zchan->state != ZAP_CHANNEL_STATE_DOWN) {
- zap_log(ZAP_LOG_ERROR, "Cannot handle request to start call in channel %d, invalid state (%d)\n",
- openr2_chan_get_number(r2chan), zchan->state);
- zap_mutex_unlock(zchan->mutex);
- return;
- }
-
- /* the channel may be down but the thread not quite done */
- zap_wait_for_flag_cleared(zchan, ZAP_CHANNEL_INTHREAD, 200);
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
- zap_log(ZAP_LOG_ERROR, "Cannot handle request to start call in channel %d, already in thread!\n",
- openr2_chan_get_number(r2chan));
- zap_mutex_unlock(zchan->mutex);
- return;
- }
- oz_r2_clean_call(zchan->call_data);
- R2CALL(zchan)->chanstate = ZAP_CHANNEL_STATE_DOWN;
- zap_channel_set_state(zchan, ZAP_CHANNEL_STATE_COLLECT, 0);
- zap_mutex_unlock(zchan->mutex);
-
- status = zap_thread_create_detached(zap_r2_channel_run, zchan);
- if (status == ZAP_FAIL) {
- zap_log(ZAP_LOG_ERROR, "Cannot handle request to start call in channel %d, failed to create thread!\n",
- openr2_chan_get_number(r2chan));
- }
-}
-
-/* only called for incoming calls when the ANI, DNIS etc is complete and the user has to decide either to accept or reject the call */
-static void zap_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, const char *dnis, openr2_calling_party_category_t category)
-{
- zap_sigmsg_t sigev;
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
-
- zap_log(ZAP_LOG_NOTICE, "Call offered on chan %d, ANI = %s, DNIS = %s, Category = %s\n", openr2_chan_get_number(r2chan),
- ani, dnis, openr2_proto_get_category_string(category));
-
- /* notify the user about the new call */
- memset(&sigev, 0, sizeof(sigev));
- sigev.chan_id = zchan->chan_id;
- sigev.span_id = zchan->span_id;
- sigev.channel = zchan;
- sigev.event_id = ZAP_SIGEVENT_START;
-
- if (zap_span_send_signal(zchan->span, &sigev) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_NOTICE, "Failed to handle call offered on chan %d\n", openr2_chan_get_number(r2chan));
- openr2_chan_disconnect_call(r2chan, OR2_CAUSE_OUT_OF_ORDER);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CANCEL);
- return;
- }
- zap_channel_use(zchan);
- R2CALL(zchan)->zap_started = 1;
-}
-
-static void zap_r2_on_call_accepted(openr2_chan_t *r2chan, openr2_call_mode_t mode)
-{
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
- zap_log(ZAP_LOG_NOTICE, "Call accepted on chan %d\n", openr2_chan_get_number(r2chan));
- /* at this point the MF signaling has ended and there is no point on keep reading */
- openr2_chan_disable_read(r2chan);
- if (OR2_DIR_BACKWARD == openr2_chan_get_direction(r2chan)) {
- R2CALL(zchan)->state_ack_pending = 1;
- if (R2CALL(zchan)->answer_pending) {
- zap_log(ZAP_LOG_DEBUG, "Answer was pending on chan %d, answering now.\n", openr2_chan_get_number(r2chan));
- oz_r2_answer_call(zchan);
- return;
- }
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS);
- }
-}
-
-static void zap_r2_on_call_answered(openr2_chan_t *r2chan)
-{
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
- zap_log(ZAP_LOG_NOTICE, "Call answered on chan %d\n", openr2_chan_get_number(r2chan));
- /* notify the upper layer of progress in the outbound call */
- if (OR2_DIR_FORWARD == openr2_chan_get_direction(r2chan)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
- }
-}
-
-/* may be called in the signaling or media thread depending on whether the hangup is product of MF or CAS signaling */
-static void zap_r2_on_call_disconnect(openr2_chan_t *r2chan, openr2_call_disconnect_cause_t cause)
-{
- zap_sigmsg_t sigev;
- zap_r2_data_t *r2data;
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
- zap_log(ZAP_LOG_NOTICE, "Call disconnected on chan %d\n", openr2_chan_get_number(r2chan));
-
- zap_log(ZAP_LOG_DEBUG, "Got openr2 disconnection, clearing call on channel %d\n", zchan->physical_chan_id);
-
- R2CALL(zchan)->disconnect_rcvd = 1;
-
- /* acknowledge the hangup, cause will be ignored. From here to -> HANGUP once the openzap side hangs up as well */
- openr2_chan_disconnect_call(r2chan, OR2_CAUSE_NORMAL_CLEARING);
-
- /* if the call has not been started yet we must go to HANGUP right here */
- if (!R2CALL(zchan)->zap_started) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- return;
- }
-
- /* FIXME: use the cause received from openr2 and map it to zap cause */
- zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING;
-
- /* notify the user of the call terminating */
- memset(&sigev, 0, sizeof(sigev));
- sigev.chan_id = zchan->chan_id;
- sigev.span_id = zchan->span_id;
- sigev.channel = zchan;
- sigev.event_id = ZAP_SIGEVENT_STOP;
- r2data = zchan->span->signal_data;
-
- zap_span_send_signal(zchan->span, &sigev);
-}
-
-static void zap_r2_on_call_end(openr2_chan_t *r2chan)
-{
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
- zap_log(ZAP_LOG_NOTICE, "Call finished on chan %d\n", openr2_chan_get_number(r2chan));
- /* this means the openzap side disconnected the call, therefore we must move to DOWN here */
- if (!R2CALL(zchan)->disconnect_rcvd) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- return;
- }
-}
-
-static void zap_r2_on_call_read(openr2_chan_t *r2chan, const unsigned char *buf, int buflen)
-{
- zap_log(ZAP_LOG_NOTICE, "Call read data on chan %d\n", openr2_chan_get_number(r2chan));
-}
-
-static void zap_r2_on_hardware_alarm(openr2_chan_t *r2chan, int alarm)
-{
- zap_log(ZAP_LOG_NOTICE, "Alarm on chan %d (%d)\n", openr2_chan_get_number(r2chan), alarm);
-}
-
-static void zap_r2_on_os_error(openr2_chan_t *r2chan, int errorcode)
-{
- zap_log(ZAP_LOG_ERROR, "OS error on chan %d: %s\n", openr2_chan_get_number(r2chan), strerror(errorcode));
-}
-
-static void zap_r2_on_protocol_error(openr2_chan_t *r2chan, openr2_protocol_error_t reason)
-{
- zap_sigmsg_t sigev;
- zap_r2_data_t *r2data;
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
-
- zap_log(ZAP_LOG_ERROR, "Protocol error on chan %d\n", openr2_chan_get_number(r2chan));
-
- R2CALL(zchan)->disconnect_rcvd = 1;
-
- if (!R2CALL(zchan)->zap_started) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- return;
- }
-
- zchan->caller_data.hangup_cause = ZAP_CAUSE_PROTOCOL_ERROR;
-
- /* notify the user of the call terminating */
- memset(&sigev, 0, sizeof(sigev));
- sigev.chan_id = zchan->chan_id;
- sigev.span_id = zchan->span_id;
- sigev.channel = zchan;
- sigev.event_id = ZAP_SIGEVENT_STOP;
- r2data = zchan->span->signal_data;
-
- zap_span_send_signal(zchan->span, &sigev);
-}
-
-static void zap_r2_on_line_blocked(openr2_chan_t *r2chan)
-{
- zap_log(ZAP_LOG_NOTICE, "Far end blocked on chan %d\n", openr2_chan_get_number(r2chan));
-}
-
-static void zap_r2_on_line_idle(openr2_chan_t *r2chan)
-{
- zap_log(ZAP_LOG_NOTICE, "Far end unblocked on chan %d\n", openr2_chan_get_number(r2chan));
-}
-
-static void zap_r2_write_log(openr2_log_level_t level, const char *message)
-{
- switch (level) {
- case OR2_LOG_NOTICE:
- zap_log(ZAP_LOG_NOTICE, "%s", message);
- break;
- case OR2_LOG_WARNING:
- zap_log(ZAP_LOG_WARNING, "%s", message);
- break;
- case OR2_LOG_ERROR:
- zap_log(ZAP_LOG_ERROR, "%s", message);
- break;
- case OR2_LOG_STACK_TRACE:
- case OR2_LOG_MF_TRACE:
- case OR2_LOG_CAS_TRACE:
- case OR2_LOG_DEBUG:
- case OR2_LOG_EX_DEBUG:
- zap_log(ZAP_LOG_DEBUG, "%s", message);
- break;
- default:
- zap_log(ZAP_LOG_WARNING, "We should handle logging level %d here.\n", level);
- zap_log(ZAP_LOG_DEBUG, "%s", message);
- break;
- }
-}
-
-static void zap_r2_on_context_log(openr2_context_t *r2context, openr2_log_level_t level, const char *fmt, va_list ap)
-{
-#define CONTEXT_TAG "Context -"
- char logmsg[256];
- char completemsg[sizeof(logmsg) + sizeof(CONTEXT_TAG) - 1];
- vsnprintf(logmsg, sizeof(logmsg), fmt, ap);
- snprintf(completemsg, sizeof(completemsg), CONTEXT_TAG "%s", logmsg);
- zap_r2_write_log(level, completemsg);
-#undef CONTEXT_TAG
-}
-
-static void zap_r2_on_chan_log(openr2_chan_t *r2chan, openr2_log_level_t level, const char *fmt, va_list ap)
-{
-#define CHAN_TAG "Chan "
- char logmsg[256];
- char completemsg[sizeof(logmsg) + sizeof(CHAN_TAG) - 1];
- vsnprintf(logmsg, sizeof(logmsg), fmt, ap);
- snprintf(completemsg, sizeof(completemsg), CHAN_TAG "%d: %s", openr2_chan_get_number(r2chan), logmsg);
- zap_r2_write_log(level, completemsg);
-#undef CHAN_TAG
-}
-
-static int zap_r2_on_dnis_digit_received(openr2_chan_t *r2chan, char digit)
-{
- zap_sigmsg_t sigev;
- zap_r2_data_t *r2data;
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
- zap_size_t collected_len = R2CALL(zchan)->dnis_index;
-
- zap_log(ZAP_LOG_DEBUG, "DNIS digit %d received chan %d\n", digit, openr2_chan_get_number(r2chan));
-
- /* save the digit we just received */
- zchan->caller_data.dnis.digits[collected_len] = digit;
- collected_len++;
- zchan->caller_data.dnis.digits[collected_len] = '\0';
- R2CALL(zchan)->dnis_index = collected_len;
-
- /* notify the user about the new digit and check if we should stop requesting more DNIS */
- memset(&sigev, 0, sizeof(sigev));
- sigev.chan_id = zchan->chan_id;
- sigev.span_id = zchan->span_id;
- sigev.channel = zchan;
- sigev.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT;
- r2data = zchan->span->signal_data;
- if (zap_span_send_signal(zchan->span, &sigev) == ZAP_BREAK) {
- zap_log(ZAP_LOG_NOTICE, "Requested to stop getting DNIS. Current DNIS = %s on chan %d\n", zchan->caller_data.dnis.digits, openr2_chan_get_number(r2chan));
- return OR2_STOP_DNIS_REQUEST;
- }
-
- /* the only other reason to stop requesting DNIS is that there is no more room to save it */
- if (collected_len == (sizeof(zchan->caller_data.dnis.digits) - 1)) {
- zap_log(ZAP_LOG_NOTICE, "No more room for DNIS. Current DNIS = %s on chan %d\n", zchan->caller_data.dnis.digits, openr2_chan_get_number(r2chan));
- return OR2_STOP_DNIS_REQUEST;
- }
-
- return OR2_CONTINUE_DNIS_REQUEST;
-}
-
-static void zap_r2_on_ani_digit_received(openr2_chan_t *r2chan, char digit)
-{
- zap_channel_t *zchan = openr2_chan_get_client_data(r2chan);
- zap_size_t collected_len = R2CALL(zchan)->ani_index;
-
- /* check if we should drop ANI */
- if (collected_len == (sizeof(zchan->caller_data.ani.digits) - 1)) {
- zap_log(ZAP_LOG_NOTICE, "No more room for ANI %c on chan %d, digit dropped.\n", digit, openr2_chan_get_number(r2chan));
- return;
- }
- zap_log(ZAP_LOG_DEBUG, "ANI digit %c received chan %d\n", digit, openr2_chan_get_number(r2chan));
-
- /* save the digit we just received */
- zchan->caller_data.ani.digits[collected_len++] = digit;
- zchan->caller_data.ani.digits[collected_len] = '\0';
-}
-
-static openr2_event_interface_t zap_r2_event_iface = {
- .on_call_init = zap_r2_on_call_init,
- .on_call_offered = zap_r2_on_call_offered,
- .on_call_accepted = zap_r2_on_call_accepted,
- .on_call_answered = zap_r2_on_call_answered,
- .on_call_disconnect = zap_r2_on_call_disconnect,
- .on_call_end = zap_r2_on_call_end,
- .on_call_read = zap_r2_on_call_read,
- .on_hardware_alarm = zap_r2_on_hardware_alarm,
- .on_os_error = zap_r2_on_os_error,
- .on_protocol_error = zap_r2_on_protocol_error,
- .on_line_blocked = zap_r2_on_line_blocked,
- .on_line_idle = zap_r2_on_line_idle,
- /* cast seems to be needed to get rid of the annoying warning regarding format attribute */
- .on_context_log = (openr2_handle_context_logging_func)zap_r2_on_context_log,
- .on_dnis_digit_received = zap_r2_on_dnis_digit_received,
- .on_ani_digit_received = zap_r2_on_ani_digit_received,
- /* so far we do nothing with billing pulses */
- .on_billing_pulse_received = NULL
-};
-
-static int zap_r2_io_set_cas(openr2_chan_t *r2chan, int cas)
-{
- zap_channel_t *zap_chan = openr2_chan_get_fd(r2chan);
- zap_status_t status = zap_channel_command(zap_chan, ZAP_COMMAND_SET_CAS_BITS, &cas);
- if (ZAP_FAIL == status) {
- return -1;
- }
- return 0;
-}
-
-static int zap_r2_io_get_cas(openr2_chan_t *r2chan, int *cas)
-{
- zap_channel_t *zap_chan = openr2_chan_get_fd(r2chan);
- zap_status_t status = zap_channel_command(zap_chan, ZAP_COMMAND_GET_CAS_BITS, cas);
- if (ZAP_FAIL == status) {
- return -1;
- }
- return 0;
-}
-
-static int zap_r2_io_flush_write_buffers(openr2_chan_t *r2chan)
-{
- zap_channel_t *zap_chan = openr2_chan_get_fd(r2chan);
- zap_status_t status = zap_channel_command(zap_chan, ZAP_COMMAND_FLUSH_TX_BUFFERS, NULL);
- if (ZAP_FAIL == status) {
- return -1;
- }
- return 0;
-}
-
-static int zap_r2_io_write(openr2_chan_t *r2chan, const void *buf, int size)
-{
- zap_channel_t *zap_chan = openr2_chan_get_fd(r2chan);
- zap_size_t outsize = size;
- zap_status_t status = zap_channel_write(zap_chan, (void *)buf, size, &outsize);
- if (ZAP_FAIL == status) {
- return -1;
- }
- return outsize;
-}
-
-static int zap_r2_io_read(openr2_chan_t *r2chan, const void *buf, int size)
-{
- zap_channel_t *zap_chan = openr2_chan_get_fd(r2chan);
- zap_size_t outsize = size;
- zap_status_t status = zap_channel_read(zap_chan, (void *)buf, &outsize);
- if (ZAP_FAIL == status) {
- return -1;
- }
- return outsize;
-}
-
-static int zap_r2_io_wait(openr2_chan_t *r2chan, int *flags, int block)
-{
- zap_status_t status;
- zap_wait_flag_t zapflags = 0;
-
- zap_channel_t *zap_chan = openr2_chan_get_fd(r2chan);
- int32_t timeout = block ? -1 : 0;
-
- if (*flags & OR2_IO_READ) {
- zapflags |= ZAP_READ;
- }
- if (*flags & OR2_IO_WRITE) {
- zapflags |= ZAP_WRITE;
- }
- if (*flags & OR2_IO_OOB_EVENT) {
- zapflags |= ZAP_EVENTS;
- }
-
- status = zap_channel_wait(zap_chan, &zapflags, timeout);
-
- if (ZAP_SUCCESS != status) {
- return -1;
- }
-
- *flags = 0;
- if (zapflags & ZAP_READ) {
- *flags |= OR2_IO_READ;
- }
- if (zapflags & ZAP_WRITE) {
- *flags |= OR2_IO_WRITE;
- }
- if (zapflags & ZAP_EVENTS) {
- *flags |= OR2_IO_OOB_EVENT;
- }
-
- return 0;
-}
-
-/* The following openr2 hooks never get called, read on for reasoning ... */
-/* since openzap takes care of opening the file descriptor and using openr2_chan_new_from_fd, openr2 should never call this hook */
-static openr2_io_fd_t zap_r2_io_open(openr2_context_t *r2context, int channo)
-{
- zap_log(ZAP_LOG_ERROR, "I should not be called (I/O open)!!\n");
- return NULL;
-}
-
-/* since openzap takes care of closing the file descriptor and uses openr2_chan_new_from_fd, openr2 should never call this hook */
-static int zap_r2_io_close(openr2_chan_t *r2chan)
-{
- zap_log(ZAP_LOG_ERROR, "I should not be called (I/O close)!!\n");
- return 0;
-}
-
-/* since openzap takes care of opening the file descriptor and using openr2_chan_new_from_fd, openr2 should never call this hook */
-static int zap_r2_io_setup(openr2_chan_t *r2chan)
-{
- zap_log(ZAP_LOG_ERROR, "I should not be called (I/O Setup)!!\n");
- return 0;
-}
-
-/* since the signaling thread calls openr2_chan_process_cas_signaling directly, openr2 should never call this hook */
-static int zap_r2_io_get_oob_event(openr2_chan_t *r2chan, openr2_oob_event_t *event)
-{
- *event = 0;
- zap_log(ZAP_LOG_ERROR, "I should not be called (I/O get oob event)!!\n");
- return 0;
-}
-
-static openr2_io_interface_t zap_r2_io_iface = {
- .open = zap_r2_io_open, /* never called */
- .close = zap_r2_io_close, /* never called */
- .set_cas = zap_r2_io_set_cas,
- .get_cas = zap_r2_io_get_cas,
- .flush_write_buffers = zap_r2_io_flush_write_buffers,
- .write = zap_r2_io_write,
- .read = zap_r2_io_read,
- .setup = zap_r2_io_setup, /* never called */
- .wait = zap_r2_io_wait,
- .get_oob_event = zap_r2_io_get_oob_event /* never called */
-};
-
-static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span)
- //zap_status_t (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap)
-{
- int i = 0;
- int conf_failure = 0;
- char *var = NULL;
- char *val = NULL;
- zap_r2_data_t *r2data = NULL;
- zap_r2_span_pvt_t *spanpvt = NULL;
- zap_r2_call_t *r2call = NULL;
- openr2_chan_t *r2chan = NULL;
-
- assert(sig_cb != NULL);
-
- oz_r2_conf_t r2conf =
- {
- .variant = OR2_VAR_ITU,
- .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER,
- .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
- .max_ani = 10,
- .max_dnis = 4,
- .mfback_timeout = -1,
- .metering_pulse_timeout = -1,
- .allow_collect_calls = -1,
- .immediate_accept = -1,
- .skip_category = -1,
- .forced_release = -1,
- .charge_calls = -1,
- .get_ani_first = -1,
- .call_files = -1,
- .logdir = NULL,
- .advanced_protocol_file = NULL
- };
-
-
- if (span->signal_type) {
- snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling.");
- return ZAP_FAIL;
- }
-
- while ((var = va_arg(ap, char *))) {
- zap_log(ZAP_LOG_DEBUG, "Reading R2 parameter %s for span %d\n", var, span->span_id);
- if (!strcasecmp(var, "variant")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- if (zap_strlen_zero_buf(val)) {
- zap_log(ZAP_LOG_NOTICE, "Ignoring empty R2 variant parameter\n");
- continue;
- }
- r2conf.variant = openr2_proto_get_variant(val);
- if (r2conf.variant == OR2_VAR_UNKNOWN) {
- zap_log(ZAP_LOG_ERROR, "Unknown R2 variant %s\n", val);
- conf_failure = 1;
- break;
- }
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d for variant %s\n", span->span_id, val);
- } else if (!strcasecmp(var, "category")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- if (zap_strlen_zero_buf(val)) {
- zap_log(ZAP_LOG_NOTICE, "Ignoring empty R2 category parameter\n");
- continue;
- }
- r2conf.category = openr2_proto_get_category(val);
- if (r2conf.category == OR2_CALLING_PARTY_CATEGORY_UNKNOWN) {
- zap_log(ZAP_LOG_ERROR, "Unknown R2 caller category %s\n", val);
- conf_failure = 1;
- break;
- }
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with default category %s\n", span->span_id, val);
- } else if (!strcasecmp(var, "logdir")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- if (zap_strlen_zero_buf(val)) {
- zap_log(ZAP_LOG_NOTICE, "Ignoring empty R2 logdir parameter\n");
- continue;
- }
- r2conf.logdir = val;
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with logdir %s\n", span->span_id, val);
- } else if (!strcasecmp(var, "logging")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- if (zap_strlen_zero_buf(val)) {
- zap_log(ZAP_LOG_NOTICE, "Ignoring empty R2 logging parameter\n");
- continue;
- }
- openr2_log_level_t tmplevel;
- char *clevel;
- char *logval = malloc(strlen(val)+1); /* alloca man page scared me, so better to use good ol' malloc */
- if (!logval) {
- zap_log(ZAP_LOG_WARNING, "Ignoring R2 logging parameter: '%s', failed to alloc memory\n", val);
- continue;
- }
- strcpy(logval, val);
- while (logval) {
- clevel = strsep(&logval, ",");
- if (-1 == (tmplevel = openr2_log_get_level(clevel))) {
- zap_log(ZAP_LOG_WARNING, "Ignoring invalid R2 logging level: '%s'\n", clevel);
- continue;
- }
- r2conf.loglevel |= tmplevel;
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with loglevel %s\n", span->span_id, clevel);
- }
- free(logval);
- } else if (!strcasecmp(var, "advanced_protocol_file")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- if (zap_strlen_zero_buf(val)) {
- zap_log(ZAP_LOG_NOTICE, "Ignoring empty R2 advanced_protocol_file parameter\n");
- continue;
- }
- r2conf.advanced_protocol_file = val;
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with advanced protocol file %s\n", span->span_id, val);
- } else if (!strcasecmp(var, "allow_collect_calls")) {
- r2conf.allow_collect_calls = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with allow collect calls max ani = %d\n", span->span_id, r2conf.allow_collect_calls);
- } else if (!strcasecmp(var, "double_answer")) {
- r2conf.double_answer = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with double answer = %d\n", span->span_id, r2conf.double_answer);
- } else if (!strcasecmp(var, "immediate_accept")) {
- r2conf.immediate_accept = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with immediate accept = %d\n", span->span_id, r2conf.immediate_accept);
- } else if (!strcasecmp(var, "skip_category")) {
- r2conf.skip_category = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with skip category = %d\n", span->span_id, r2conf.skip_category);
- } else if (!strcasecmp(var, "forced_release")) {
- r2conf.forced_release = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with forced release = %d\n", span->span_id, r2conf.forced_release);
- } else if (!strcasecmp(var, "charge_calls")) {
- r2conf.charge_calls = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with charge calls = %d\n", span->span_id, r2conf.charge_calls);
- } else if (!strcasecmp(var, "get_ani_first")) {
- r2conf.get_ani_first = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with get ani first = %d\n", span->span_id, r2conf.get_ani_first);
- } else if (!strcasecmp(var, "call_files")) {
- r2conf.call_files = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with call files = %d\n", span->span_id, r2conf.call_files);
- } else if (!strcasecmp(var, "mfback_timeout")) {
- r2conf.mfback_timeout = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with MF backward timeout = %dms\n", span->span_id, r2conf.mfback_timeout);
- } else if (!strcasecmp(var, "metering_pulse_timeout")) {
- r2conf.metering_pulse_timeout = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with metering pulse timeout = %dms\n", span->span_id, r2conf.metering_pulse_timeout);
- } else if (!strcasecmp(var, "max_ani")) {
- r2conf.max_ani = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with max ani = %d\n", span->span_id, r2conf.max_ani);
- } else if (!strcasecmp(var, "max_dnis")) {
- r2conf.max_dnis = va_arg(ap, int);
- zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with max dnis = %d\n", span->span_id, r2conf.max_dnis);
- } else {
- snprintf(span->last_error, sizeof(span->last_error), "Unknown R2 parameter [%s]", var);
- return ZAP_FAIL;
- }
- }
-
- if (conf_failure) {
- snprintf(span->last_error, sizeof(span->last_error), "R2 configuration error");
- return ZAP_FAIL;
- }
-
- r2data = malloc(sizeof(*r2data));
- if (!r2data) {
- snprintf(span->last_error, sizeof(span->last_error), "Failed to allocate R2 data.");
- return ZAP_FAIL;
- }
- memset(r2data, 0, sizeof(*r2data));
-
- spanpvt = malloc(sizeof(*spanpvt));
- if (!spanpvt) {
- snprintf(span->last_error, sizeof(span->last_error), "Failed to allocate private span data container.");
- goto fail;
- }
- memset(spanpvt, 0, sizeof(*spanpvt));
-
- r2data->r2context = openr2_context_new(r2conf.variant, &zap_r2_event_iface, r2conf.max_ani, r2conf.max_dnis);
- if (!r2data->r2context) {
- snprintf(span->last_error, sizeof(span->last_error), "Cannot create openr2 context for span.");
- goto fail;
- }
- openr2_context_set_io_type(r2data->r2context, OR2_IO_CUSTOM, &zap_r2_io_iface);
- openr2_context_set_log_level(r2data->r2context, r2conf.loglevel);
- openr2_context_set_ani_first(r2data->r2context, r2conf.get_ani_first);
- openr2_context_set_skip_category_request(r2data->r2context, r2conf.skip_category);
- openr2_context_set_mf_back_timeout(r2data->r2context, r2conf.mfback_timeout);
- openr2_context_set_metering_pulse_timeout(r2data->r2context, r2conf.metering_pulse_timeout);
- openr2_context_set_double_answer(r2data->r2context, r2conf.double_answer);
- openr2_context_set_immediate_accept(r2data->r2context, r2conf.immediate_accept);
- if (r2conf.logdir) {
- openr2_context_set_log_directory(r2data->r2context, r2conf.logdir);
- }
- if (r2conf.advanced_protocol_file) {
- openr2_context_configure_from_advanced_file(r2data->r2context, r2conf.advanced_protocol_file);
- }
-
- spanpvt->r2calls = create_hashtable(ZAP_MAX_CHANNELS_SPAN, zap_hash_hashfromstring, zap_hash_equalkeys);
- if (!spanpvt->r2calls) {
- snprintf(span->last_error, sizeof(span->last_error), "Cannot create channel calls hash for span.");
- goto fail;
- }
-
- for (i = 1; (i <= span->chan_count) && (i <= ZAP_MAX_CHANNELS_SPAN); i++) {
- r2chan = openr2_chan_new_from_fd(r2data->r2context, span->channels[i], span->channels[i]->physical_chan_id);
- if (!r2chan) {
- snprintf(span->last_error, sizeof(span->last_error), "Cannot create all openr2 channels for span.");
- goto fail;
- }
- if (r2conf.call_files) {
- openr2_chan_enable_call_files(r2chan);
- openr2_chan_set_log_level(r2chan, r2conf.loglevel);
- }
-
- r2call = malloc(sizeof(*r2call));
- if (!r2call) {
- snprintf(span->last_error, sizeof(span->last_error), "Cannot create all R2 call data structures for the span.");
- zap_safe_free(r2chan);
- goto fail;
- }
- memset(r2call, 0, sizeof(*r2call));
- openr2_chan_set_logging_func(r2chan, zap_r2_on_chan_log);
- openr2_chan_set_client_data(r2chan, span->channels[i]);
- r2call->r2chan = r2chan;
- span->channels[i]->call_data = r2call;
- /* value and key are the same so just free one of them */
- snprintf(r2call->name, sizeof(r2call->name), "chancall%d", i);
- hashtable_insert(spanpvt->r2calls, (void *)r2call->name, r2call, HASHTABLE_FLAG_FREE_VALUE);
-
- }
- spanpvt->r2context = r2data->r2context;
-
- /* just the value must be freed by the hash */
- hashtable_insert(g_mod_data_hash, (void *)span->name, spanpvt, HASHTABLE_FLAG_FREE_VALUE);
-
- span->start = zap_r2_start;
- r2data->flags = 0;
- span->signal_cb = sig_cb;
- span->signal_type = ZAP_SIGTYPE_R2;
- span->signal_data = r2data;
- span->outgoing_call = r2_outgoing_call;
-
- return ZAP_SUCCESS;
-
-fail:
-
- if (r2data && r2data->r2context) {
- openr2_context_delete(r2data->r2context);
- }
- if (spanpvt && spanpvt->r2calls) {
- hashtable_destroy(spanpvt->r2calls);
- }
- zap_safe_free(r2data);
- zap_safe_free(spanpvt);
- return ZAP_FAIL;
-
-}
-
-static void *zap_r2_channel_run(zap_thread_t *me, void *obj)
-{
- zap_channel_t *closed_chan;
- uint32_t interval = 0;
- zap_sigmsg_t sigev;
- zap_channel_t *zchan = (zap_channel_t *)obj;
- openr2_chan_t *r2chan = R2CALL(zchan)->r2chan;
-
- zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD);
-
- zap_mutex_lock(g_thread_count_mutex);
- g_thread_count++;
- zap_mutex_unlock(g_thread_count_mutex);
-
- zap_log(ZAP_LOG_DEBUG, "R2 CHANNEL thread starting on %d in state %s.\n",
- zchan->physical_chan_id,
- zap_channel_state2str(zchan->state));
-
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
- goto endthread;
- }
-
- zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval);
-
- assert(interval != 0);
- zap_log(ZAP_LOG_DEBUG, "Got %d interval for chan %d\n", interval, zchan->physical_chan_id);
-
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- /* FIXME: is this needed? */
- memset(zchan->caller_data.dnis.digits, 0, sizeof(zchan->caller_data.collected));
- memset(zchan->caller_data.ani.digits, 0, sizeof(zchan->caller_data.collected));
- }
-
- memset(&sigev, 0, sizeof(sigev));
- sigev.chan_id = zchan->chan_id;
- sigev.span_id = zchan->span_id;
- sigev.channel = zchan;
-
- while (zap_running()) {
- int32_t read_enabled = openr2_chan_get_read_enabled(r2chan);
- zap_wait_flag_t flags = read_enabled ? ( ZAP_READ | ZAP_WRITE ) : 0;
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE) && (R2CALL(zchan)->chanstate != zchan->state)) {
-
- zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state));
- R2CALL(zchan)->chanstate = zchan->state;
-
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) && !R2CALL(zchan)->accepted &&
- (zchan->state == ZAP_CHANNEL_STATE_PROGRESS ||
- zchan->state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA ||
- zchan->state == ZAP_CHANNEL_STATE_UP) ) {
- /* if an accept ack will be required we should not acknowledge the state change just yet,
- it will be done below after processing the MF signals, otherwise we have a race condition between openzap calling
- openr2_chan_answer_call and openr2 accepting the call first, if openzap calls openr2_chan_answer_call before the accept cycle
- completes, openr2 will fail to answer the call */
- zap_log(ZAP_LOG_DEBUG, "State ack in chan %d:%d for state %s will have to wait a bit\n", zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state));
- } else if (zchan->state != ZAP_CHANNEL_STATE_DOWN){
- /* the down state will be completed in zap_channel_done below */
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
- zap_channel_complete_state(zchan);
- }
-
- switch (zchan->state) {
-
- /* starting an incoming call */
- case ZAP_CHANNEL_STATE_COLLECT:
- {
- zap_log(ZAP_LOG_DEBUG, "COLLECT: Starting processing of incoming call in channel %d with interval %d\n", zchan->physical_chan_id, interval);
- }
- break;
-
- /* starting an outgoing call */
- case ZAP_CHANNEL_STATE_DIALING:
- {
- // FIXME: use user defined calling party
- zap_channel_use(zchan);
- zap_log(ZAP_LOG_DEBUG, "DIALING: Starting processing of outgoing call in channel %d with interval %d\n", zchan->physical_chan_id, interval);
- if (openr2_chan_make_call(r2chan, zchan->caller_data.cid_num.digits, zchan->caller_data.ani.digits, OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER)) {
- zap_log(ZAP_LOG_ERROR, "%d:%d Failed to make call in R2 channel, openr2_chan_make_call failed\n", zchan->span_id, zchan->chan_id);
- zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER;
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- }
- break;
-
- /* the call is ringing */
- case ZAP_CHANNEL_STATE_PROGRESS:
- case ZAP_CHANNEL_STATE_PROGRESS_MEDIA:
- {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- if (!R2CALL(zchan)->accepted) {
- zap_log(ZAP_LOG_DEBUG, "PROGRESS: Accepting call on channel %d\n", zchan->physical_chan_id);
- oz_r2_accept_call(zchan);
- }
- } else {
- zap_log(ZAP_LOG_DEBUG, "PROGRESS: Notifying progress in channel %d\n", zchan->physical_chan_id);
- sigev.event_id = ZAP_SIGEVENT_PROGRESS;
- if (zap_span_send_signal(zchan->span, &sigev) != ZAP_SUCCESS) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- }
- }
- break;
-
- /* the call was answered */
- case ZAP_CHANNEL_STATE_UP:
- {
- zap_log(ZAP_LOG_DEBUG, "UP: Call was answered on channel %d\n", zchan->physical_chan_id);
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- if (!R2CALL(zchan)->accepted) {
- zap_log(ZAP_LOG_DEBUG, "UP: Call has not been accepted, need to accept first\n");
- // the answering will be done in the on_call_accepted handler
- oz_r2_accept_call(zchan);
- R2CALL(zchan)->answer_pending = 1;
- } else {
- oz_r2_answer_call(zchan);
- }
- } else {
- zap_log(ZAP_LOG_DEBUG, "UP: Notifying of call answered in channel %d\n", zchan->physical_chan_id);
- sigev.event_id = ZAP_SIGEVENT_UP;
- if (zap_span_send_signal(zchan->span, &sigev) != ZAP_SUCCESS) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- }
- }
- break;
-
- /* just got hangup */
- case ZAP_CHANNEL_STATE_HANGUP:
- {
- /* FIXME: the cause should be retrieved from zchan->caller_data.hangup_cause and translated from Q931 to R2 cause */
- zap_log(ZAP_LOG_DEBUG, "HANGUP: Clearing call on channel %d\n", zchan->physical_chan_id);
- if (!R2CALL(zchan)->disconnect_rcvd) {
- /* this will disconnect the call, but need to wait for the call end before moving to DOWN */
- openr2_chan_disconnect_call(r2chan, OR2_CAUSE_NORMAL_CLEARING);
- } else {
- /* at this point on_call_end possibly was already called,
- * but we needed to wait for the openzap confirmation before moving to DOWN */
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- }
- break;
-
- /* just got hangup from the openzap side due to abnormal failure */
- case ZAP_CHANNEL_STATE_CANCEL:
- {
- zap_log(ZAP_LOG_DEBUG, "CANCEL: Unable to receive call on channel %d\n", zchan->physical_chan_id);
- openr2_chan_disconnect_call(r2chan, OR2_CAUSE_OUT_OF_ORDER);
- }
- break;
-
- /* finished call for good */
- case ZAP_CHANNEL_STATE_DOWN:
- {
- zap_log(ZAP_LOG_DEBUG, "DOWN: Placing channel %d back to the pool of available channels\n", zchan->physical_chan_id);
- zap_channel_done(zchan);
- goto endthread;
- }
- break;
-
- default:
- {
- zap_log(ZAP_LOG_ERROR, "%s: Unhandled channel state change in channel %d\n", zap_channel_state2str(zchan->state), zchan->physical_chan_id);
- }
- break;
-
- }
- }
-
- if (flags) {
- if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_DEBUG, "zap_channel_wait did not return ZAP_SUCCESS\n");
- continue;
- }
-
- /* handle timeout events first if any */
- openr2_chan_run_schedule(r2chan);
-
- /* openr2 will now try to detect MF tones, make sense out of them, reply if necessary with another tone and trigger
- * telephony events via the call event interface we provided when creating the R2 context.
- * openr2 will also call our I/O callbacks to retrieve audio from the channel and call our wait poll I/O registered callback
- * and will not return from this function until the I/O poll callback returns no pending events
- * */
- openr2_chan_process_mf_signaling(r2chan);
- if (R2CALL(zchan)->state_ack_pending) {
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE);
- zap_channel_complete_state(zchan);
- R2CALL(zchan)->state_ack_pending = 0;
- }
- } else {
- /* once the MF signaling has end we just loop here waiting for state changes */
- zap_sleep(interval);
- }
-
- }
-
-endthread:
-
- closed_chan = zchan;
- zap_channel_close(&closed_chan);
- zap_clear_flag(zchan, ZAP_CHANNEL_INTHREAD);
- zap_log(ZAP_LOG_DEBUG, "R2 channel %d thread ended.\n", zchan->physical_chan_id);
-
- zap_mutex_lock(g_thread_count_mutex);
- g_thread_count--;
- zap_mutex_unlock(g_thread_count_mutex);
-
- return NULL;
-}
-
-static void *zap_r2_run(zap_thread_t *me, void *obj)
-{
- openr2_chan_t *r2chan;
- zap_status_t status;
- zap_span_t *span = (zap_span_t *) obj;
- zap_r2_data_t *r2data = span->signal_data;
- int waitms = 1000;
- int i;
-
- zap_log(ZAP_LOG_DEBUG, "OpenR2 monitor thread started.\n");
- r2chan = NULL;
- for (i = 1; i <= span->chan_count; i++) {
- r2chan = R2CALL(span->channels[i])->r2chan;
- openr2_chan_set_idle(r2chan);
- openr2_chan_process_cas_signaling(r2chan);
- }
-
- while (zap_running() && zap_test_flag(r2data, ZAP_R2_RUNNING)) {
- status = zap_span_poll_event(span, waitms);
- if (ZAP_FAIL == status) {
- zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error);
- continue;
- }
- if (ZAP_SUCCESS == status) {
- zap_event_t *event;
- while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
- if (event->enum_id == ZAP_OOB_CAS_BITS_CHANGE) {
- r2chan = R2CALL(event->channel)->r2chan;
- zap_log(ZAP_LOG_DEBUG, "Handling CAS on channel %d.\n", openr2_chan_get_number(r2chan));
- // we only expect CAS and other OOB events on this thread/loop, once a call is started
- // the MF events (in-band signaling) are handled in the call thread
- openr2_chan_process_cas_signaling(r2chan);
- } else {
- zap_log(ZAP_LOG_DEBUG, "Ignoring event %d on channel %d.\n", event->enum_id, openr2_chan_get_number(r2chan));
- // XXX TODO: handle alarms here XXX
- }
- }
- } else if (status != ZAP_TIMEOUT) {
- zap_log(ZAP_LOG_ERROR, "zap_span_poll_event returned %d.\n", status);
- } else {
- //zap_log(ZAP_LOG_DEBUG, "timed out waiting for event on span %d\n", span->span_id);
- }
- }
-
- /*
- FIXME: we should set BLOCKED but at this point I/O routines of openzap caused segfault
- for (i = 1; i <= span->chan_count; i++) {
- r2chan = R2CALL(span->channels[i])->r2chan;
- openr2_chan_set_blocked(r2chan);
- }
- */
-
- zap_clear_flag(r2data, ZAP_R2_RUNNING);
- zap_log(ZAP_LOG_DEBUG, "R2 thread ending.\n");
-
- return NULL;
-
-}
-
-static ZIO_API_FUNCTION(zap_r2_api)
-{
- char *mycmd = NULL, *argv[10] = { 0 };
- int argc = 0;
-
- if (data) {
- mycmd = strdup(data);
- argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- }
-
- if (argc == 2) {
- if (!strcasecmp(argv[0], "kill")) {
- int span_id = atoi(argv[1]);
- zap_span_t *span = NULL;
-
- if (zap_span_find_by_name(argv[1], &span) == ZAP_SUCCESS || zap_span_find(span_id, &span) == ZAP_SUCCESS) {
- zap_r2_data_t *r2data = span->signal_data;
-
- if (span->start != zap_r2_start) {
- stream->write_function(stream, "-ERR invalid span.\n");
- goto done;
- }
-
- zap_clear_flag(r2data, ZAP_R2_RUNNING);
- stream->write_function(stream, "+OK killed.\n");
- goto done;
- } else {
- stream->write_function(stream, "-ERR invalid span.\n");
- goto done;
- }
- }
-
- if (!strcasecmp(argv[0], "status")) {
- int span_id = atoi(argv[1]);
- zap_r2_data_t *r2data = NULL;
- zap_span_t *span = NULL;
- openr2_chan_t *r2chan = NULL;
- openr2_context_t *r2context = NULL;
- int i = 0;
-
- if (zap_span_find_by_name(argv[1], &span) == ZAP_SUCCESS || zap_span_find(span_id, &span) == ZAP_SUCCESS) {
- if (span->start != zap_r2_start) {
- stream->write_function(stream, "-ERR not an R2 span.\n");
- goto done;
- }
- if (!(r2data = span->signal_data)) {
- stream->write_function(stream, "-ERR invalid span. No R2 singal data in span.\n");
- goto done;
- }
- r2context = r2data->r2context;
- openr2_variant_t r2variant = openr2_context_get_variant(r2context);
- stream->write_function(stream,
- "Variant: %s\n"
- "Max ANI: %d\n"
- "Max DNIS: %d\n"
- "ANI First: %s\n"
- "Immediate Accept: %s\n",
- openr2_proto_get_variant_string(r2variant),
- openr2_context_get_max_ani(r2context),
- openr2_context_get_max_dnis(r2context),
- openr2_context_get_ani_first(r2context) ? "Yes" : "No",
- openr2_context_get_immediate_accept(r2context) ? "Yes" : "No");
- stream->write_function(stream, "\n");
- stream->write_function(stream, "%4s %-12.12s %-12.12s\n", "Channel", "Tx CAS", "Rx CAS");
- for (i = 1; i <= span->chan_count; i++) {
- if (i == 16) continue;
- r2chan = R2CALL(span->channels[i])->r2chan;
- stream->write_function(stream, "%4d %-12.12s %-12.12s\n",
- span->channels[i]->physical_chan_id,
- openr2_chan_get_tx_cas_string(r2chan),
- openr2_chan_get_rx_cas_string(r2chan));
- }
- stream->write_function(stream, "\n");
- stream->write_function(stream, "+OK.\n");
- goto done;
- } else {
- stream->write_function(stream, "-ERR invalid span.\n");
- goto done;
- }
- }
-
- }
-
- if (argc == 1) {
- if (!strcasecmp(argv[0], "threads")) {
- zap_mutex_lock(g_thread_count_mutex);
- stream->write_function(stream, "%d R2 channel threads up\n", g_thread_count);
- zap_mutex_unlock(g_thread_count_mutex);
- stream->write_function(stream, "+OK.\n");
- goto done;
- }
-
- if (!strcasecmp(argv[0], "version")) {
- stream->write_function(stream, "OpenR2 version: %s, revision: %s\n", openr2_get_version(), openr2_get_revision());
- stream->write_function(stream, "+OK.\n");
- goto done;
- }
-
- if (!strcasecmp(argv[0], "variants")) {
- int32_t numvariants = 0;
- const openr2_variant_entry_t *variants = openr2_proto_get_variant_list(&numvariants);
- if (!variants) {
- stream->write_function(stream, "-ERR failed to retrieve openr2 variant list.\n");
- goto done;
- }
-#define VARIANT_FORMAT "%4s %40s\n"
- stream->write_function(stream, VARIANT_FORMAT, "Variant Code", "Country");
- numvariants--;
- for (; numvariants; numvariants--) {
- stream->write_function(stream, VARIANT_FORMAT, variants[numvariants].name, variants[numvariants].country);
- }
- stream->write_function(stream, "+OK.\n");
-#undef VARIANT_FORMAT
- goto done;
- }
- }
-
- stream->write_function(stream, "-ERR invalid command.\n");
-
-done:
-
- zap_safe_free(mycmd);
-
- return ZAP_SUCCESS;
-
-}
-
-static ZIO_IO_LOAD_FUNCTION(zap_r2_io_init)
-{
- assert(zio != NULL);
- memset(&g_zap_r2_interface, 0, sizeof(g_zap_r2_interface));
-
- g_zap_r2_interface.name = "r2";
- g_zap_r2_interface.api = zap_r2_api;
-
- *zio = &g_zap_r2_interface;
-
- return ZAP_SUCCESS;
-}
-
-static ZIO_SIG_LOAD_FUNCTION(zap_r2_init)
-{
- g_mod_data_hash = create_hashtable(10, zap_hash_hashfromstring, zap_hash_equalkeys);
- if (!g_mod_data_hash) {
- return ZAP_FAIL;
- }
- zap_mutex_create(&g_thread_count_mutex);
- return ZAP_SUCCESS;
-}
-
-static ZIO_SIG_UNLOAD_FUNCTION(zap_r2_destroy)
-{
- zap_hash_iterator_t *i = NULL;
- zap_r2_span_pvt_t *spanpvt = NULL;
- const void *key = NULL;
- void *val = NULL;
- for (i = hashtable_first(g_mod_data_hash); i; i = hashtable_next(i)) {
- hashtable_this(i, &key, NULL, &val);
- if (key && val) {
- spanpvt = val;
- openr2_context_delete(spanpvt->r2context);
- hashtable_destroy(spanpvt->r2calls);
- }
- }
- hashtable_destroy(g_mod_data_hash);
- zap_mutex_destroy(&g_thread_count_mutex);
- return ZAP_SUCCESS;
-}
-
-zap_module_t zap_module = {
- "r2",
- zap_r2_io_init,
- NULL,
- zap_r2_init,
- zap_r2_configure_span,
- zap_r2_destroy
-};
-
-
-/* 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 noet
- */
diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c
deleted file mode 100644
index 616746debf..0000000000
--- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c
+++ /dev/null
@@ -1,1960 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "openzap.h"
-#include "sangoma_boost_client.h"
-#include "zap_sangoma_boost.h"
-#ifdef HAVE_SYS_SELECT_H
-#include
-#endif
-#ifndef __WINDOWS__
-#include
-#endif
-
-#define MAX_TRUNK_GROUPS 64
-static time_t congestion_timeouts[MAX_TRUNK_GROUPS];
-
-/**
- * \brief Strange flag
- */
-typedef enum {
- SFLAG_FREE_REQ_ID = (1 << 0),
- SFLAG_SENT_FINAL_MSG = (1 << 1),
- SFLAG_SENT_ACK = (1 << 2),
- SFLAG_RECVD_ACK = (1 << 3),
- SFLAG_HANGUP = (1 << 4),
- SFLAG_TERMINATING = (1 << 5)
-} sflag_t;
-
-typedef uint16_t sangoma_boost_request_id_t;
-
-/**
- * \brief SANGOMA boost request status
- */
-typedef enum {
- BST_FREE,
- BST_WAITING,
- BST_ACK,
- BST_READY,
- BST_FAIL
-} sangoma_boost_request_status_t;
-
-/**
- * \brief SANGOMA boost request structure
- */
-typedef struct {
- sangoma_boost_request_status_t status;
- sangomabc_short_event_t event;
- zap_span_t *span;
- zap_channel_t *zchan;
- int hangup_cause;
- int flags;
-} sangoma_boost_request_t;
-
-//#define MAX_REQ_ID ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * ZAP_MAX_CHANNELS_PHYSICAL_SPAN
-#define MAX_REQ_ID 6000
-
-static uint16_t SETUP_GRID[ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN+1][ZAP_MAX_CHANNELS_PHYSICAL_SPAN+1] = {{ 0 }};
-
-static sangoma_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }};
-
-static zap_mutex_t *request_mutex = NULL;
-
-static uint8_t req_map[MAX_REQ_ID+1] = { 0 };
-static uint8_t nack_map[MAX_REQ_ID+1] = { 0 };
-
-/**
- * \brief Releases span and channel from setup grid
- * \param span Span number
- * \param chan Channel number
- * \param func Calling function
- * \param line Line number on request
- * \return NULL if not found, channel otherwise
- */
-static void __release_request_id_span_chan(int span, int chan, const char *func, int line)
-{
- int id;
-
- zap_mutex_lock(request_mutex);
- if ((id = SETUP_GRID[span][chan])) {
- assert(id <= MAX_REQ_ID);
- req_map[id] = 0;
- SETUP_GRID[span][chan] = 0;
- }
- zap_mutex_unlock(request_mutex);
-}
-#define release_request_id_span_chan(s, c) __release_request_id_span_chan(s, c, __FUNCTION__, __LINE__)
-
-/**
- * \brief Releases request ID
- * \param func Calling function
- * \param line Line number on request
- * \return NULL if not found, channel otherwise
- */
-static void __release_request_id(sangoma_boost_request_id_t r, const char *func, int line)
-{
- assert(r <= MAX_REQ_ID);
- zap_mutex_lock(request_mutex);
- req_map[r] = 0;
- zap_mutex_unlock(request_mutex);
-}
-#define release_request_id(r) __release_request_id(r, __FUNCTION__, __LINE__)
-
-static sangoma_boost_request_id_t last_req = 0;
-
-/**
- * \brief Gets the first available tank request ID
- * \param func Calling function
- * \param line Line number on request
- * \return 0 on failure, request ID on success
- */
-static sangoma_boost_request_id_t __next_request_id(const char *func, int line)
-{
- sangoma_boost_request_id_t r = 0, i = 0;
- int found=0;
-
- zap_mutex_lock(request_mutex);
- //r = ++last_req;
- //while(!r || req_map[r]) {
-
- for (i=1; i<= MAX_REQ_ID; i++){
- r = ++last_req;
-
- if (r >= MAX_REQ_ID) {
- r = i = last_req = 1;
- }
-
- if (req_map[r]) {
- /* Busy find another */
- continue;
-
- }
-
- req_map[r] = 1;
- found=1;
- break;
-
- }
-
- zap_mutex_unlock(request_mutex);
-
- if (!found) {
- return 0;
- }
-
- return r;
-}
-#define next_request_id() __next_request_id(__FUNCTION__, __LINE__)
-
-/**
- * \brief Finds the channel that triggered an event
- * \param span Span where to search the channel
- * \param event SANGOMA event
- * \param force Do not wait for the channel to be available if in use
- * \return NULL if not found, channel otherwise
- */
-static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *event, int force)
-{
- int i;
- zap_channel_t *zchan = NULL;
-
- for(i = 1; i <= span->chan_count; i++) {
- if (span->channels[i]->physical_span_id == event->span+1 && span->channels[i]->physical_chan_id == event->chan+1) {
- zchan = span->channels[i];
- if (force || (zchan->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(zchan, ZAP_CHANNEL_INUSE))) {
- break;
- } else {
- zchan = NULL;
- zap_log(ZAP_LOG_DEBUG, "Channel %d:%d ~ %d:%d is already in use.\n",
- span->channels[i]->span_id,
- span->channels[i]->chan_id,
- span->channels[i]->physical_span_id,
- span->channels[i]->physical_chan_id
- );
- break;
- }
- }
- }
-
- return zchan;
-}
-
-static int check_congestion(int trunk_group)
-{
- if (congestion_timeouts[trunk_group]) {
- time_t now = time(NULL);
-
- if (now >= congestion_timeouts[trunk_group]) {
- congestion_timeouts[trunk_group] = 0;
- } else {
- return 1;
- }
- }
-
- return 0;
-}
-
-
-/**
- * \brief Requests an sangoma boost channel on a span (outgoing call)
- * \param span Span where to get a channel
- * \param chan_id Specific channel to get (0 for any)
- * \param direction Call direction
- * \param caller_data Caller information
- * \param zchan Channel to initialise
- * \return Success or failure
- */
-static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
-{
- zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
- zap_status_t status = ZAP_FAIL;
- sangoma_boost_request_id_t r;
- sangomabc_event_t event = {0};
-
- /* sanity has to be more than 8 seconds.
- * In PRI specs, timeout is 4 seconds for remote switch to respond to a SETUP,
- * and PRI stack will retransmit a second SETUP after the first timeout, so
- * we should allow for at least 8 seconds */
-
- int sanity = 10000;
- sangoma_boost_request_status_t st;
- char ani[128] = "";
- char *gr = NULL;
- uint32_t count = 0;
- int tg=0;
-
- if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) {
- zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n");
- *zchan = NULL;
- return ZAP_FAIL;
- }
-
- zap_set_string(ani, caller_data->ani.digits);
-
- if ((gr = strchr(ani, '@'))) {
- *gr++ = '\0';
- }
-
- if (gr && *(gr+1)) {
- tg = atoi(gr+1);
- if (tg > 0) {
- tg--;
- }
- }
- event.trunk_group = tg;
-
- if (check_congestion(tg)) {
- zap_log(ZAP_LOG_CRIT, "All circuits are busy. Trunk Group=%i (BOOST REQUESTED BACK OFF)\n",tg+1);
- *zchan = NULL;
- return ZAP_FAIL;
- }
-
- zap_span_channel_use_count(span, &count);
-
- if (count >= span->chan_count) {
- zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n");
- *zchan = NULL;
- return ZAP_FAIL;
- }
-
- r = next_request_id();
- if (r == 0) {
- zap_log(ZAP_LOG_CRIT, "All tanks ids are busy.\n");
- *zchan = NULL;
- return ZAP_FAIL;
- }
-
- /* sangomabc_call_init (event, calling, called, setup_id) */
- sangomabc_call_init(&event, caller_data->cid_num.digits, ani, r);
- //sangoma_bc_call_init will clear the trunk_group val so we need to set it again
- event.trunk_group=tg;
-
- if (gr && *(gr+1)) {
-
- switch(*gr) {
- case 'g':
- event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC;
- break;
- case 'G':
- event.hunt_group = SIGBOOST_HUNTGRP_SEQ_DESC;
- break;
- case 'r':
- event.hunt_group = SIGBOOST_HUNTGRP_RR_ASC;
- break;
- case 'R':
- event.hunt_group = SIGBOOST_HUNTGRP_RR_DESC;
- break;
- default:
- zap_log(ZAP_LOG_WARNING, "Failed to determine huntgroup (%s)\n", gr);
- event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC;
- }
- }
-
- zap_set_string(event.calling_name, caller_data->cid_name);
- zap_set_string(event.rdnis.digits, caller_data->rdnis.digits);
-
- if (strlen(caller_data->rdnis.digits)) {
- event.rdnis.digits_count = strlen(caller_data->rdnis.digits)+1;
- event.rdnis.ton = caller_data->rdnis.type;
- event.rdnis.npi = caller_data->rdnis.plan;
- }
-
- event.calling.screening_ind = caller_data->screen;
- event.calling.presentation_ind = caller_data->pres;
-
- event.calling.ton = caller_data->cid_num.type;
- event.calling.npi = caller_data->cid_num.plan;
-
- event.called.ton = caller_data->ani.type;
- event.called.npi = caller_data->ani.plan;
-
- if (caller_data->raw_data_len) {
- zap_set_string((char *)event.isup_in_rdnis, (char *)caller_data->raw_data);
- event.isup_in_rdnis_size = caller_data->raw_data_len;
- }
-
- OUTBOUND_REQUESTS[r].status = BST_WAITING;
- OUTBOUND_REQUESTS[r].span = span;
-
- if (sangomabc_connection_write(&sangoma_boost_data->mcon, &event) <= 0) {
- zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]\n", strerror(errno));
- status = ZAP_FAIL;
- OUTBOUND_REQUESTS[r].status = ZAP_FAIL;
- *zchan = NULL;
- goto done;
- }
-
- while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) {
- zap_sleep(1);
- if (--sanity <= 0) {
- status = ZAP_FAIL;
- *zchan = NULL;
- goto done;
- }
- }
-
- if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) {
- *zchan = OUTBOUND_REQUESTS[r].zchan;
- status = ZAP_SUCCESS;
- } else {
- status = ZAP_FAIL;
- *zchan = NULL;
- }
-
- done:
-
- st = OUTBOUND_REQUESTS[r].status;
- OUTBOUND_REQUESTS[r].status = BST_FREE;
-
- if (status == ZAP_FAIL) {
- if (st == BST_FAIL) {
- caller_data->hangup_cause = OUTBOUND_REQUESTS[r].hangup_cause;
- } else {
- caller_data->hangup_cause = ZAP_CAUSE_RECOVERY_ON_TIMER_EXPIRE;
- }
- }
-
- if (st == BST_FAIL) {
- release_request_id(r);
- } else if (st != BST_READY) {
- assert(r <= MAX_REQ_ID);
- nack_map[r] = 1;
- sangomabc_exec_command(&sangoma_boost_data->mcon,
- 0,
- 0,
- r,
- SIGBOOST_EVENT_CALL_START_NACK,
- 0,
- 0);
- }
-
- return status;
-}
-
-/**
- * \brief Starts an sangoma boost channel (outgoing call)
- * \param zchan Channel to initiate call on
- * \return Success
- */
-static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call)
-{
- zap_status_t status = ZAP_SUCCESS;
-
- return status;
-}
-
-/**
- * \brief Handler for call start ack no media event
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_call_progress(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan;
-
-
- if ((zchan = find_zchan(span, event, 1))) {
- zap_mutex_lock(zchan->mutex);
- if (zchan->state == ZAP_CHANNEL_STATE_HOLD) {
- if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) {
- zchan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA;
- zap_log(ZAP_LOG_DEBUG, "Channel init state updated to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id);
- } else if ((event->flags & SIGBOOST_PROGRESS_RING)) {
- zchan->init_state = ZAP_CHANNEL_STATE_PROGRESS;
- zap_log(ZAP_LOG_DEBUG, "Channel init state updated to PROGRESS [Csid:%d]\n", event->call_setup_id);
- } else {
- zchan->init_state = ZAP_CHANNEL_STATE_IDLE;
- zap_log(ZAP_LOG_DEBUG, "Channel init state updated to IDLE [Csid:%d]\n", event->call_setup_id);
- }
- } else {
- if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA);
- } else if ((event->flags & SIGBOOST_PROGRESS_RING)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS);
- } else {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
- }
- }
- zap_mutex_unlock(zchan->mutex);
- }
-}
-
-/**
- * \brief Handler for call start ack event
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan;
-
- if (nack_map[event->call_setup_id]) {
- return;
- }
-
-
-
- if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0))) {
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
- } else {
-
- /* Only bind the setup id to GRID when we are sure that channel is ready
- otherwise we could overwite the original call */
- OUTBOUND_REQUESTS[event->call_setup_id].event = *event;
- SETUP_GRID[event->span][event->chan] = event->call_setup_id;
-
- zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
- zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE);
- zchan->extra_id = event->call_setup_id;
- zap_log(ZAP_LOG_DEBUG, "Assign chan %d:%d (%d:%d) CSid=%d\n", zchan->span_id, zchan->chan_id, event->span+1,event->chan+1, event->call_setup_id);
- zchan->sflags = SFLAG_RECVD_ACK;
-
- if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) {
- zchan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA;
- zap_log(ZAP_LOG_DEBUG, "Channel init state changed to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id);
- } else if ((event->flags & SIGBOOST_PROGRESS_RING)) {
- zchan->init_state = ZAP_CHANNEL_STATE_PROGRESS;
- zap_log(ZAP_LOG_DEBUG, "Channel init state changed to PROGRESS [Csid:%d]\n", event->call_setup_id);
- } else {
- zchan->init_state = ZAP_CHANNEL_STATE_IDLE;
- zap_log(ZAP_LOG_DEBUG, "Channel init state changed to IDLE [Csid:%d]\n", event->call_setup_id);
- }
-
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HOLD);
-
- OUTBOUND_REQUESTS[event->call_setup_id].flags = event->flags;
- OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan;
- OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY;
- return;
- }
- } else {
- if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, (sangomabc_short_event_t*)event, 1))) {
- int r;
-
- /* NC: If we get CALL START ACK and channel is in active state
- then we are completely out of sync with the other end.
- Treat CALL START ACK as CALL STOP and hangup the current call.
- */
-
- if (zchan->state == ZAP_CHANNEL_STATE_UP ||
- zchan->state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA ||
- zchan->state == ZAP_CHANNEL_STATE_PROGRESS) {
- zap_log(ZAP_LOG_CRIT, "ZCHAN CALL ACK STATE %s -> Changed to HANGUP %d:%d\n",
- zap_channel_state2str(zchan->state),event->span+1,event->chan+1);
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r);
-
- } else if (zchan->state == ZAP_CHANNEL_STATE_HANGUP || zap_test_sflag(zchan, SFLAG_HANGUP)) {
- zap_log(ZAP_LOG_CRIT, "ZCHAN CALL ACK STATE HANGUP -> Changed to HANGUP %d:%d\n", event->span+1,event->chan+1);
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, 0, r);
- /* Do nothing because outgoing STOP will generaate a stop ack */
-
- } else {
- zap_log(ZAP_LOG_CRIT, "ZCHAN CALL ACK STATE INVALID %s s%dc%d\n",
- zap_channel_state2str(zchan->state),event->span+1,event->chan+1);
- }
- zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG);
- zchan=NULL;
- }
- }
-
- //printf("WTF BAD ACK CSid=%d span=%d chan=%d\n", event->call_setup_id, event->span+1,event->chan+1);
- if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 1))) {
- //printf("WTF BAD ACK2 %d:%d (%d:%d) CSid=%d xtra_id=%d out=%d state=%s\n", zchan->span_id, zchan->chan_id, event->span+1,event->chan+1, event->call_setup_id, zchan->extra_id, zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND), zap_channel_state2str(zchan->state));
- }
-
- if (zchan) {
- zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG);
- }
-
- zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1);
- sangomabc_exec_command(mcon,
- event->span,
- event->chan,
- event->call_setup_id,
- SIGBOOST_EVENT_CALL_STOPPED,
- ZAP_CAUSE_DESTINATION_OUT_OF_ORDER, 0);
- OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL;
- OUTBOUND_REQUESTS[event->call_setup_id].hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER;
-
-}
-
-/**
- * \brief Handler for call done event
- * \param span Span where event was fired
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan;
- int r = 0;
-
- if ((zchan = find_zchan(span, event, 1))) {
- zap_mutex_lock(zchan->mutex);
-
- if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state == ZAP_CHANNEL_STATE_HANGUP_COMPLETE || zap_test_sflag(zchan, SFLAG_TERMINATING)) {
- goto done;
- }
-
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, 0, r);
- if (r) {
- zap_set_sflag(zchan, SFLAG_FREE_REQ_ID);
- zap_mutex_unlock(zchan->mutex);
- return;
- }
- }
-
- done:
-
- if (zchan) {
- zap_mutex_unlock(zchan->mutex);
- }
-
- if (event->call_setup_id) {
- release_request_id(event->call_setup_id);
- } else {
- release_request_id_span_chan(event->span, event->chan);
- }
-}
-
-/**
- * \brief Handler for call start nack event
- * \param span Span where event was fired
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan;
-
- if (event->release_cause == SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY) {
- uint32_t count = 0;
- int delay = 0;
- int tg=event->trunk_group;
-
- zap_span_channel_use_count(span, &count);
-
- delay = (int) (count / 100) * 2;
-
- if (delay > 10) {
- delay = 10;
- } else if (delay < 1) {
- delay = 1;
- }
-
- if (tg < 0 || tg >= MAX_TRUNK_GROUPS) {
- zap_log(ZAP_LOG_CRIT, "Invalid All Ckt Busy trunk group number %i\n", tg);
- tg=0;
- }
-
- congestion_timeouts[tg] = time(NULL) + delay;
- event->release_cause = 17;
-
- } else if (event->release_cause == SIGBOOST_CALL_SETUP_CSUPID_DBL_USE) {
- event->release_cause = 17;
- }
-
- if (event->call_setup_id) {
-
- sangomabc_exec_command(mcon,
- 0,
- 0,
- event->call_setup_id,
- SIGBOOST_EVENT_CALL_START_NACK_ACK,
- 0, 0);
-
- OUTBOUND_REQUESTS[event->call_setup_id].event = *event;
- OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL;
- OUTBOUND_REQUESTS[event->call_setup_id].hangup_cause = event->release_cause;
- return;
- } else {
- if ((zchan = find_zchan(span, event, 1))) {
- int r = 0;
- assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND));
-
- zchan->call_data = (void*)(intptr_t)event->event_id;
-
- zap_mutex_lock(zchan->mutex);
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r);
- if (r == ZAP_STATE_CHANGE_SUCCESS) {
- zchan->caller_data.hangup_cause = event->release_cause;
- }
- zap_mutex_unlock(zchan->mutex);
- if (r) {
- return;
- }
- }
- }
-
- if (zchan) {
- zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
- }
-
- /* nobody else will do it so we have to do it ourselves */
- sangomabc_exec_command(mcon,
- event->span,
- event->chan,
- 0,
- SIGBOOST_EVENT_CALL_START_NACK_ACK,
- 0, 0);
-}
-
-/**
- * \brief Handler for call stop event
- * \param span Span where event was fired
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan;
-
- if ((zchan = find_zchan(span, event, 1))) {
- int r = 0;
-
- zap_mutex_lock(zchan->mutex);
-
- if (zap_test_sflag(zchan, SFLAG_HANGUP) || zchan->state == ZAP_CHANNEL_STATE_DOWN) {
-
- /* NC: Checking for state DOWN because ss7box can
- send CALL_STOP twice in a row. If we do not check for
- STATE_DOWN we will set the state back to termnating
- and block the channel forever
- */
-
- /* racing condition where both sides initiated a hangup
- * Do not change current state as channel is already clearing
- * itself through local initiated hangup */
-
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_STOPPED_ACK,
- 0, 0);
- zap_mutex_unlock(zchan->mutex);
- return;
- } else {
- if (zchan->state == ZAP_CHANNEL_STATE_HOLD) {
- zchan->init_state = ZAP_CHANNEL_STATE_TERMINATING;
- zap_log(ZAP_LOG_DEBUG, "Channel init state updated to TERMINATING [Csid:%d]\n", event->call_setup_id);
- OUTBOUND_REQUESTS[event->call_setup_id].hangup_cause = event->release_cause;
- zchan->caller_data.hangup_cause = event->release_cause;
- zap_mutex_unlock(zchan->mutex);
- return;
- } else {
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r);
- }
- }
-
- if (r == ZAP_STATE_CHANGE_SUCCESS) {
- zchan->caller_data.hangup_cause = event->release_cause;
- }
-
- if (r) {
- zap_set_sflag(zchan, SFLAG_FREE_REQ_ID);
- }
-
- zap_mutex_unlock(zchan->mutex);
-
- if (r) {
- return;
- }
- } /* else we have to do it ourselves.... */
-
- zap_log(ZAP_LOG_WARNING, "We could not find chan: s%dc%d\n", event->span, event->chan);
- release_request_id_span_chan(event->span, event->chan);
-}
-
-/**
- * \brief Handler for call answer event
- * \param span Span where event was fired
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_call_answer(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan;
-
- if ((zchan = find_zchan(span, event, 1))) {
- zap_mutex_lock(zchan->mutex);
- if (zap_test_sflag(zchan, SFLAG_HANGUP) ||
- zchan->state == ZAP_CHANNEL_STATE_DOWN ||
- zchan->state == ZAP_CHANNEL_STATE_TERMINATING) {
- /* NC: Do nothing here because we are in process
- of stopping the call. So ignore the ANSWER. */
- zap_log(ZAP_LOG_CRIT, "ANSWER BUT CALL IS HANGUP %d:%d\n", event->span+1,event->chan+1);
-
- } else if (zchan->state == ZAP_CHANNEL_STATE_HOLD) {
- zchan->init_state = ZAP_CHANNEL_STATE_UP;
- } else {
- int r = 0;
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_UP, 0, r);
- }
- zap_mutex_unlock(zchan->mutex);
- } else {
- zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1);
- sangomabc_exec_command(mcon,
- event->span,
- event->chan,
- event->call_setup_id,
- SIGBOOST_EVENT_CALL_STOPPED,
- ZAP_CAUSE_DESTINATION_OUT_OF_ORDER, 0);
- }
-}
-
-static __inline__ void advance_chan_states(zap_channel_t *zchan);
-static __inline__ void stop_loop(zap_channel_t *zchan);
-
-/**
- * \brief Handler for call start event
- * \param span Span where event was fired
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_event_t *event)
-{
- zap_channel_t *zchan;
- int hangup_cause = ZAP_CAUSE_CALL_REJECTED;
- int retry = 1;
-
-tryagain:
-
- if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) {
- if ((zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) {
- int r;
-
- /* NC: If we get CALL START and channel is in active state
- then we are completely out of sync with the other end.
- Treat CALL START as CALL STOP and hangup the current call.
- */
-
- if (zchan->state == ZAP_CHANNEL_STATE_UP ||
- zchan->state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA ||
- zchan->state == ZAP_CHANNEL_STATE_PROGRESS) {
- zap_log(ZAP_LOG_CRIT, "ZCHAN CALL STATE %s -> Changed to TERMINATING %d:%d\n",
- zap_channel_state2str(zchan->state),event->span+1,event->chan+1);
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r);
-
- } else if (zchan->state == ZAP_CHANNEL_STATE_HANGUP || zap_test_sflag(zchan, SFLAG_HANGUP)) {
- zap_log(ZAP_LOG_CRIT, "ZCHAN CALL STATE HANGUP -> Changed to HANGUP %d:%d\n", event->span+1,event->chan+1);
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, 0, r);
- /* Do nothing because outgoing STOP will generaate a stop ack */
- } else if (zchan->state == ZAP_CHANNEL_STATE_IN_LOOP && retry) {
- /* workaround ss7box sending us call start without sending first a loop stop */
- stop_loop(zchan);
- advance_chan_states(zchan);
- retry = 0;
- goto tryagain;
- } else {
- zap_log(ZAP_LOG_CRIT, "ZCHAN CALL ACK STATE INVALID %s s%dc%d\n",
- zap_channel_state2str(zchan->state),event->span+1,event->chan+1);
- }
-
- zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG);
- zchan=NULL;
- }
- zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d\n", event->span+1,event->chan+1);
- goto error;
- }
-
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_CRIT, "START CANT OPEN CHAN %d:%d\n", event->span+1,event->chan+1);
- goto error;
- }
-
- zchan->sflags = 0;
- zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling.digits);
- zap_set_string(zchan->caller_data.cid_name, (char *)event->calling.digits);
- zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling.digits);
- zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called.digits);
- zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->rdnis.digits);
- if (event->custom_data_size) {
- zap_set_string(zchan->caller_data.raw_data, event->custom_data);
- zchan->caller_data.raw_data_len = event->custom_data_size;
- }
-
- if (strlen(event->calling_name)) {
- zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_name);
- }
-
- zchan->caller_data.cid_num.plan = event->calling.npi;
- zchan->caller_data.cid_num.type = event->calling.ton;
-
- zchan->caller_data.ani.plan = event->calling.npi;
- zchan->caller_data.ani.type = event->calling.ton;
-
- zchan->caller_data.dnis.plan = event->called.npi;
- zchan->caller_data.dnis.type = event->called.ton;
-
- zchan->caller_data.rdnis.plan = event->rdnis.npi;
- zchan->caller_data.rdnis.type = event->rdnis.ton;
-
- zchan->caller_data.screen = event->calling.screening_ind;
- zchan->caller_data.pres = event->calling.presentation_ind;
-
- /* more info about custom data: http://www.ss7box.com/smg_manual.html#ISUP-IN-RDNIS-NEW */
- if (event->custom_data_size) {
- char* p = NULL;
-
- p = strstr(event->custom_data,"PRI001-ANI2-");
- if ( p != NULL) {
- int ani2 = 0;
- sscanf(p, "PRI001-ANI2-%d", &ani2);
- snprintf(zchan->caller_data.aniII, 5, "%.2d", ani2);
- }
-
- }
-
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING);
- return;
-
- error:
- if (zchan) {
- hangup_cause = zchan->caller_data.hangup_cause;
- } else {
- zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1);
- hangup_cause = ZAP_CAUSE_REQUESTED_CHAN_UNAVAIL;
- }
- sangomabc_exec_command(mcon,
- event->span,
- event->chan,
- 0,
- SIGBOOST_EVENT_CALL_START_NACK,
- hangup_cause, 0);
-
-}
-
-static void handle_call_loop_start(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_state_change_result_t res = ZAP_FAIL;
- zap_channel_t *zchan;
-
- if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) {
- zap_log(ZAP_LOG_CRIT, "CANNOT START LOOP, CHAN NOT AVAILABLE %d:%d\n", event->span+1,event->chan+1);
- return;
- }
-
- if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_CRIT, "CANNOT START LOOP, CANT OPEN CHAN %d:%d\n", event->span+1,event->chan+1);
- return;
- }
-
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_IN_LOOP, 0, res);
- if (res != ZAP_STATE_CHANGE_SUCCESS) {
- zap_log(ZAP_LOG_CRIT, "yay, could not set the state of the channel to IN_LOOP, loop will fail\n");
- zap_channel_done(zchan);
- return;
- }
- zap_log(ZAP_LOG_DEBUG, "%d:%d starting loop\n", zchan->span_id, zchan->chan_id);
- zap_channel_command(zchan, ZAP_COMMAND_ENABLE_LOOP, NULL);
-}
-
-static __inline__ void stop_loop(zap_channel_t *zchan)
-{
- zap_state_change_result_t res = ZAP_STATE_CHANGE_FAIL;
- zap_channel_command(zchan, ZAP_COMMAND_DISABLE_LOOP, NULL);
- /* even when we did not sent a msg we set this flag to avoid sending call stop in the DOWN state handler */
- zap_set_flag(zchan, SFLAG_SENT_FINAL_MSG);
- zap_set_state_r(zchan, ZAP_CHANNEL_STATE_DOWN, 0, res);
- if (res != ZAP_STATE_CHANGE_SUCCESS) {
- zap_log(ZAP_LOG_CRIT, "yay, could not set the state of the channel from IN_LOOP to DOWN\n");
- }
-}
-
-static void handle_call_loop_stop(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan;
- if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) {
- zap_log(ZAP_LOG_CRIT, "CANNOT STOP LOOP, INVALID CHAN REQUESTED %d:%d\n", event->span+1,event->chan+1);
- return;
- }
- if (zchan->state != ZAP_CHANNEL_STATE_IN_LOOP) {
- zap_log(ZAP_LOG_ERROR, "Got stop loop request in a channel that is not in loop, ignoring ...\n");
- return;
- }
- stop_loop(zchan);
-}
-
-/**
- * \brief Handler for heartbeat event
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static void handle_heartbeat(sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- int err;
-
- err = sangomabc_connection_writep(mcon, (sangomabc_event_t*)event);
-
- if (err <= 0) {
- zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]: %s\n", strerror(errno));
- }
-
- mcon->hb_elapsed = 0;
-
- return;
-}
-
-/**
- * \brief Handler for restart ack event
- * \param mcon sangoma boost connection
- * \param span Span where event was fired
- * \param event Event to handle
- */
-static void handle_restart_ack(sangomabc_connection_t *mcon, zap_span_t *span, sangomabc_short_event_t *event)
-{
- zap_log(ZAP_LOG_DEBUG, "RECV RESTART ACK\n");
-}
-
-/**
- * \brief Handler for restart event
- * \param mcon sangoma boost connection
- * \param span Span where event was fired
- * \param event Event to handle
- */
-static void handle_restart(sangomabc_connection_t *mcon, zap_span_t *span, sangomabc_short_event_t *event)
-{
- zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
-
- mcon->rxseq_reset = 0;
- zap_set_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN);
- zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED);
- zap_set_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING);
-
- mcon->hb_elapsed = 0;
-}
-
-/**
- * \brief Handler for incoming digit event
- * \param mcon sangoma boost connection
- * \param span Span where event was fired
- * \param event Event to handle
- */
-static void handle_incoming_digit(sangomabc_connection_t *mcon, zap_span_t *span, sangomabc_event_t *event)
-{
- zap_channel_t *zchan = NULL;
- char digits[MAX_DIALED_DIGITS + 2] = "";
-
- if (!(zchan = find_zchan(span, (sangomabc_short_event_t *)event, 1))) {
- zap_log(ZAP_LOG_ERROR, "Invalid channel\n");
- return;
- }
-
- if (event->called_number_digits_count == 0) {
- zap_log(ZAP_LOG_WARNING, "Error Incoming digit with len %s %d [w%dg%d]\n",
- event->called_number_digits,
- event->called_number_digits_count,
- event->span+1, event->chan+1);
- return;
- }
-
- zap_log(ZAP_LOG_WARNING, "Incoming digit with len %s %d [w%dg%d]\n",
- event->called_number_digits,
- event->called_number_digits_count,
- event->span+1, event->chan+1);
-
- memcpy(digits, event->called_number_digits, event->called_number_digits_count);
- zap_channel_queue_dtmf(zchan, digits);
-
- return;
-}
-
-
-/**
- * \brief Checks if span has state changes pending and processes
- * \param span Span where event was fired
- * \param event Event to handle
- */
-static zap_channel_t* event_process_states(zap_span_t *span, sangomabc_short_event_t *event)
-{
- zap_channel_t *zchan = NULL;
-
- switch (event->event_id) {
- case SIGBOOST_EVENT_CALL_START_NACK:
- case SIGBOOST_EVENT_CALL_START_NACK_ACK:
- if (event->call_setup_id) {
- return NULL;
- }
- //if event->span and event->chan is valid, fall-through
- case SIGBOOST_EVENT_CALL_START:
- case SIGBOOST_EVENT_CALL_START_ACK:
- case SIGBOOST_EVENT_CALL_STOPPED:
- case SIGBOOST_EVENT_CALL_PROGRESS:
- case SIGBOOST_EVENT_CALL_ANSWERED:
- case SIGBOOST_EVENT_CALL_STOPPED_ACK:
- case SIGBOOST_EVENT_DIGIT_IN:
- case SIGBOOST_EVENT_INSERT_CHECK_LOOP:
- case SIGBOOST_EVENT_REMOVE_CHECK_LOOP:
- if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) {
- zap_log(ZAP_LOG_DEBUG, "PROCESS STATES CANT FIND CHAN %d:%d\n", event->span+1,event->chan+1);
- return NULL;
- }
- break;
- case SIGBOOST_EVENT_HEARTBEAT:
- case SIGBOOST_EVENT_SYSTEM_RESTART_ACK:
- case SIGBOOST_EVENT_SYSTEM_RESTART:
- case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE:
- return NULL;
- default:
- zap_log(ZAP_LOG_CRIT, "Unhandled event id:%d\n", event->event_id);
- return NULL;
- }
-
- zap_mutex_lock(zchan->mutex);
- advance_chan_states(zchan);
- return zchan;
-}
-
-/**
- * \brief Handler for sangoma boost event
- * \param span Span where event was fired
- * \param mcon sangoma boost connection
- * \param event Event to handle
- */
-static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
-{
- zap_channel_t* zchan = NULL;
-
- if (!zap_running()) {
- zap_log(ZAP_LOG_WARNING, "System is shutting down.\n");
- goto end;
- }
-
- assert(event->call_setup_id <= MAX_REQ_ID);
-
- /* process all pending state changes for that channel before
- processing the new boost event */
- zchan = event_process_states(span, event);
-
- switch(event->event_id) {
- case SIGBOOST_EVENT_CALL_START:
- handle_call_start(span, mcon, (sangomabc_event_t*)event);
- break;
- case SIGBOOST_EVENT_CALL_STOPPED:
- handle_call_stop(span, mcon, event);
- break;
- case SIGBOOST_EVENT_CALL_START_ACK:
- handle_call_start_ack(mcon, event);
- break;
- case SIGBOOST_EVENT_CALL_PROGRESS:
- handle_call_progress(span, mcon, event);
- break;
- case SIGBOOST_EVENT_CALL_START_NACK:
- handle_call_start_nack(span, mcon, event);
- break;
- case SIGBOOST_EVENT_CALL_ANSWERED:
- handle_call_answer(span, mcon, event);
- break;
- case SIGBOOST_EVENT_HEARTBEAT:
- handle_heartbeat(mcon, event);
- break;
- case SIGBOOST_EVENT_CALL_STOPPED_ACK:
- handle_call_done(span, mcon, event);
- break;
- case SIGBOOST_EVENT_CALL_START_NACK_ACK:
- handle_call_done(span, mcon, event);
- nack_map[event->call_setup_id] = 0;
- break;
- case SIGBOOST_EVENT_INSERT_CHECK_LOOP:
- handle_call_loop_start(span, mcon, event);
- break;
- case SIGBOOST_EVENT_REMOVE_CHECK_LOOP:
- handle_call_loop_stop(span, mcon, event);
- break;
- case SIGBOOST_EVENT_SYSTEM_RESTART_ACK:
- handle_restart_ack(mcon, span, event);
- break;
- case SIGBOOST_EVENT_SYSTEM_RESTART:
- handle_restart(mcon, span, event);
- break;
- case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE:
- //handle_gap_abate(event);
- break;
- case SIGBOOST_EVENT_DIGIT_IN:
- handle_incoming_digit(mcon, span, (sangomabc_event_t*)event);
- break;
- default:
- zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", sangomabc_event_id_name(event->event_id));
- break;
- }
-
- end:
- if(zchan != NULL) {
- advance_chan_states(zchan);
- zap_mutex_unlock(zchan->mutex);
- }
-
- return 0;
-}
-
-/**
- * \brief Handler for channel state change
- * \param zchan Channel to handle
- */
-static __inline__ void state_advance(zap_channel_t *zchan)
-{
-
- zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data;
- sangomabc_connection_t *mcon = &sangoma_boost_data->mcon;
- zap_sigmsg_t sig;
- zap_status_t status;
-
- zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n", zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state));
-
- memset(&sig, 0, sizeof(sig));
- sig.chan_id = zchan->chan_id;
- sig.span_id = zchan->span_id;
- sig.channel = zchan;
-
- switch (zchan->state) {
- case ZAP_CHANNEL_STATE_DOWN:
- {
- if (zchan->last_state == ZAP_CHANNEL_STATE_IN_LOOP) {
- /* nothing to do after a loop */
- zap_log(ZAP_LOG_DEBUG, "%d:%d terminating loop\n", zchan->span_id, zchan->chan_id);
- } else {
- /* Always try to clear the GRID */
- release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1);
-
- if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) {
- zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
-
- if (zchan->call_data && ((uint32_t)(intptr_t)zchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) {
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_START_NACK_ACK,
- 0, 0);
-
- } else {
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_STOPPED_ACK,
- 0, 0);
- }
- }
- }
- zchan->extra_id = 0;
- zchan->sflags = 0;
- zchan->call_data = NULL;
- zap_channel_done(zchan);
- }
- break;
- case ZAP_CHANNEL_STATE_PROGRESS_MEDIA:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else {
- if (!zap_test_sflag(zchan, SFLAG_SENT_ACK)) {
- zap_set_sflag(zchan, SFLAG_SENT_ACK);
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_START_ACK,
- 0,
- SIGBOOST_PROGRESS_MEDIA);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_PROGRESS:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_PROGRESS;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else {
- if (!zap_test_sflag(zchan, SFLAG_SENT_ACK)) {
- zap_set_sflag(zchan, SFLAG_SENT_ACK);
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_START_ACK,
- 0,
- SIGBOOST_PROGRESS_RING);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_IDLE:
- case ZAP_CHANNEL_STATE_HOLD:
- /* twiddle */
- break;
- case ZAP_CHANNEL_STATE_RING:
- {
- if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_START;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_RESTART:
- {
- sig.event_id = ZAP_SIGEVENT_RESTART;
- status = zap_span_send_signal(zchan->span, &sig);
- zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- break;
- case ZAP_CHANNEL_STATE_UP:
- {
- if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
- sig.event_id = ZAP_SIGEVENT_UP;
- if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
- }
- } else {
- if (!(zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA))) {
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_START_ACK,
- 0, 0);
- }
-
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_ANSWERED,
- 0, 0);
- }
- }
- break;
- case ZAP_CHANNEL_STATE_DIALING:
- {
- }
- break;
- case ZAP_CHANNEL_STATE_HANGUP_COMPLETE:
- {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN);
- }
- break;
- case ZAP_CHANNEL_STATE_HANGUP:
- {
- zap_set_sflag_locked(zchan, SFLAG_HANGUP);
-
- if (zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG) || zap_test_sflag(zchan, SFLAG_TERMINATING)) {
- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE);
- } else {
- zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) ||
- zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) ||
- zap_test_flag(zchan, ZAP_CHANNEL_MEDIA) || zap_test_sflag(zchan, SFLAG_RECVD_ACK)) {
-
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_STOPPED,
- zchan->caller_data.hangup_cause, 0);
- } else {
- sangomabc_exec_command(mcon,
- zchan->physical_span_id-1,
- zchan->physical_chan_id-1,
- 0,
- SIGBOOST_EVENT_CALL_START_NACK,
- zchan->caller_data.hangup_cause, 0);
- }
- }
- }
- break;
- case ZAP_CHANNEL_STATE_TERMINATING:
- {
- zap_set_sflag_locked(zchan, SFLAG_TERMINATING);
- sig.event_id = ZAP_SIGEVENT_STOP;
- status = zap_span_send_signal(zchan->span, &sig);
- }
- break;
- case ZAP_CHANNEL_STATE_IN_LOOP:
- {
- /* nothing to do, we sent the ZAP_COMMAND_ENABLE_LOOP command in handle_call_loop_start() right away */
- }
- break;
- default:
- break;
- }
-}
-
-static __inline__ void advance_chan_states(zap_channel_t *zchan)
-{
- while (zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) {
- zap_clear_flag(zchan, ZAP_CHANNEL_STATE_CHANGE);
- state_advance(zchan);
- zap_channel_complete_state(zchan);
- }
-}
-
-/**
- * \brief Initialises outgoing requests array
- */
-static __inline__ void init_outgoing_array(void)
-{
- memset(&OUTBOUND_REQUESTS, 0, sizeof(OUTBOUND_REQUESTS));
-
-}
-
-/**
- * \brief Checks current state on a span
- * \param span Span to check status on
- */
-static __inline__ void check_state(zap_span_t *span)
-{
- zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
- int susp = zap_test_flag(span, ZAP_SPAN_SUSPENDED);
-
- if (susp && zap_check_state_all(span, ZAP_CHANNEL_STATE_DOWN)) {
- susp = 0;
- }
-
- if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE) || susp) {
- uint32_t j;
- zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE);
- for(j = 1; j <= span->chan_count; j++) {
- if (zap_test_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE) || susp) {
- zap_mutex_lock(span->channels[j]->mutex);
- zap_clear_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE);
- if (susp && span->channels[j]->state != ZAP_CHANNEL_STATE_DOWN) {
- zap_channel_set_state(span->channels[j], ZAP_CHANNEL_STATE_RESTART, 0);
- }
- state_advance(span->channels[j]);
- zap_channel_complete_state(span->channels[j]);
- zap_mutex_unlock(span->channels[j]->mutex);
- }
- }
- }
-
- if (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING)) {
- if (zap_check_state_all(span, ZAP_CHANNEL_STATE_DOWN)) {
- sangomabc_exec_command(&sangoma_boost_data->mcon,
- 0,
- 0,
- -1,
- SIGBOOST_EVENT_SYSTEM_RESTART_ACK,
- 0, 0);
- zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING);
- zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED);
- zap_clear_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN);
- sangoma_boost_data->mcon.hb_elapsed = 0;
- init_outgoing_array();
- }
- }
-}
-
-
-/**
- * \brief Checks for events on a span
- * \param span Span to check for events
- */
-static __inline__ void check_events(zap_span_t *span, int ms_timeout)
-{
- zap_status_t status;
-
- status = zap_span_poll_event(span, ms_timeout);
-
- switch(status) {
- case ZAP_SUCCESS:
- {
- zap_event_t *event;
- while (zap_span_next_event(span, &event) == ZAP_SUCCESS) {
- // for now we do nothing with events, this is here
- // just to have the hardware layer to get any HW DTMF
- // events and enqueue the DTMF on the channel (done during zap_span_next_event())
- }
- }
- break;
- case ZAP_FAIL:
- {
- zap_log(ZAP_LOG_DEBUG, "Boost Check Event Failure Failure! %d\n", zap_running());
- }
- break;
- default:
- break;
- }
-
- return;
-}
-
-/**
- * \brief Main thread function for sangoma boost span (monitor)
- * \param me Current thread
- * \param obj Span to run in this thread
- */
-static void *zap_sangoma_events_run(zap_thread_t *me, void *obj)
-{
- zap_span_t *span = (zap_span_t *) obj;
- zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
-
- while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING) && zap_running()) {
- check_events(span,100);
- }
-
- return NULL;
-}
-
-
-#ifndef __WINDOWS__
-static int waitfor_2sockets(int fda, int fdb, char *a, char *b, int timeout)
-{
- struct pollfd pfds[2];
- int res = 0;
- int errflags = (POLLERR | POLLHUP | POLLNVAL);
-
- if (fda < 0 || fdb < 0) {
- return -1;
- }
-
-
-waitfor_2sockets_tryagain:
-
- *a=0;
- *b=0;
-
-
- memset(pfds, 0, sizeof(pfds));
-
- pfds[0].fd = fda;
- pfds[1].fd = fdb;
- pfds[0].events = POLLIN | errflags;
- pfds[1].events = POLLIN | errflags;
-
- res = poll(pfds, 2, timeout);
-
- if (res > 0) {
- res = 1;
- if ((pfds[0].revents & errflags) || (pfds[1].revents & errflags)) {
- res = -1;
- } else {
- if ((pfds[0].revents & POLLIN)) {
- *a=1;
- res++;
- }
- if ((pfds[1].revents & POLLIN)) {
- *b=1;
- res++;
- }
- }
-
- if (res == 1) {
- /* No event found what to do */
- res=-1;
- }
- } else if (res < 0) {
-
- if (errno == EINTR || errno == EAGAIN) {
- goto waitfor_2sockets_tryagain;
- }
-
- }
-
- return res;
-}
-#endif
-
-/**
- * \brief Main thread function for sangoma boost span (monitor)
- * \param me Current thread
- * \param obj Span to run in this thread
- */
-static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj)
-{
- zap_span_t *span = (zap_span_t *) obj;
- zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
- sangomabc_connection_t *mcon, *pcon;
- uint32_t ms = 10; //, too_long = 20000;
- int max, activity, i;
- sangomabc_event_t *event;
- struct timeval tv;
- fd_set rfds, efds;
-#ifndef __WINDOWS__
- char a=0,b=0;
-#endif
-
- sangoma_boost_data->pcon = sangoma_boost_data->mcon;
-
- if (sangomabc_connection_open(&sangoma_boost_data->mcon,
- sangoma_boost_data->mcon.cfg.local_ip,
- sangoma_boost_data->mcon.cfg.local_port,
- sangoma_boost_data->mcon.cfg.remote_ip,
- sangoma_boost_data->mcon.cfg.remote_port) < 0) {
- zap_log(ZAP_LOG_ERROR, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno));
- goto end;
- }
-
- if (sangomabc_connection_open(&sangoma_boost_data->pcon,
- sangoma_boost_data->pcon.cfg.local_ip,
- ++sangoma_boost_data->pcon.cfg.local_port,
- sangoma_boost_data->pcon.cfg.remote_ip,
- ++sangoma_boost_data->pcon.cfg.remote_port) < 0) {
- zap_log(ZAP_LOG_ERROR, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno));
- goto end;
- }
-
- mcon = &sangoma_boost_data->mcon;
- pcon = &sangoma_boost_data->pcon;
-
- init_outgoing_array();
-
- sangomabc_exec_commandp(pcon,
- 0,
- 0,
- -1,
- SIGBOOST_EVENT_SYSTEM_RESTART,
- 0);
- zap_set_flag(mcon, MSU_FLAG_DOWN);
-
- while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING)) {
-
- tv.tv_sec = 0;
- tv.tv_usec = ms* 1000;
- max=0;
- activity=0;
- i=0;
- event = NULL;
-
- if (!zap_running()) {
- sangomabc_exec_commandp(pcon,
- 0,
- 0,
- -1,
- SIGBOOST_EVENT_SYSTEM_RESTART,
- 0);
- zap_set_flag(mcon, MSU_FLAG_DOWN);
- break;
- }
-
- FD_ZERO(&rfds);
- FD_ZERO(&efds);
- FD_SET(mcon->socket, &rfds);
- FD_SET(mcon->socket, &efds);
- FD_SET(pcon->socket, &rfds);
- FD_SET(pcon->socket, &efds);
-
- max = ((pcon->socket > mcon->socket) ? pcon->socket : mcon->socket) + 1;
-
-#ifdef __WINDOWS__
- if ((activity = select(max, &rfds, NULL, &efds, &tv)) < 0) {
- goto error;
- }
-
- if (activity) {
- if (FD_ISSET(pcon->socket, &efds) || FD_ISSET(mcon->socket, &efds)) {
- goto error;
- }
-
- if (FD_ISSET(pcon->socket, &rfds)) {
- while ((event = sangomabc_connection_readp(pcon, i))) {
- parse_sangoma_event(span, pcon, (sangomabc_short_event_t*)event);
- i++;
- }
- }
- i=0;
-
- if (FD_ISSET(mcon->socket, &rfds)) {
- if ((event = sangomabc_connection_read(mcon, i))) {
- parse_sangoma_event(span, mcon, (sangomabc_short_event_t*)event);
- i++;
- }
- }
-
- }
-#else
-
- a=0;
- b=0;
- i=0;
- tv.tv_sec=0;
- activity = waitfor_2sockets(pcon->socket,mcon->socket,&a,&b,ms);
- if (activity) {
- if (a) {
- while ((event = sangomabc_connection_readp(pcon, i))) {
- parse_sangoma_event(span, pcon, (sangomabc_short_event_t*)event);
- i++;
- }
- }
- i=0;
-
- if (b) {
- if ((event = sangomabc_connection_read(mcon, i))) {
- parse_sangoma_event(span, mcon, (sangomabc_short_event_t*)event);
- i++;
- }
- }
- } else if (activity < 0) {
- goto error;
- }
-
-#endif
-
- pcon->hb_elapsed += ms;
-
- if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) || zap_test_flag(mcon, MSU_FLAG_DOWN)) {
- pcon->hb_elapsed = 0;
- }
-
-
-#if 0
- if (pcon->hb_elapsed >= too_long) {
- zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n");
- zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED);
- zap_set_flag(mcon, MSU_FLAG_DOWN);
- sangomabc_exec_commandp(pcon,
- 0,
- 0,
- -1,
- SIGBOOST_EVENT_SYSTEM_RESTART,
- 0);
- }
-#endif
-
- if (zap_running()) {
- check_state(span);
- }
- }
-
- goto end;
-
- error:
- zap_log(ZAP_LOG_CRIT, "Socket Error!\n");
-
- end:
-
- sangomabc_connection_close(&sangoma_boost_data->mcon);
- sangomabc_connection_close(&sangoma_boost_data->pcon);
-
- zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING);
-
- zap_log(ZAP_LOG_DEBUG, "SANGOMA_BOOST thread ended.\n");
- return NULL;
-}
-
-/**
- * \brief Loads sangoma boost signaling module
- * \param zio Openzap IO interface
- * \return Success
- */
-static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init)
-{
- zap_mutex_create(&request_mutex);
-
- return ZAP_SUCCESS;
-}
-
-static zap_status_t zap_sangoma_boost_start(zap_span_t *span)
-{
- int err;
- zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
- zap_set_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING);
- err=zap_thread_create_detached(zap_sangoma_boost_run, span);
- if (err) {
- zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING);
- return err;
- }
- // launch the events thread to handle HW DTMF and possibly
- // other events in the future
- err=zap_thread_create_detached(zap_sangoma_events_run, span);
- if (err) {
- zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING);
- }
- return err;
-}
-
-static zap_state_map_t boost_state_map = {
- {
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_ANY_STATE},
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_HOLD, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HOLD, ZAP_END},
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS,
- ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_IDLE, ZAP_END},
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_IDLE, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_HANGUP, ZAP_END}
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_OUTBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_UP, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}
- },
-
- /****************************************/
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_ANY_STATE},
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RESTART, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DOWN},
- {ZAP_CHANNEL_STATE_IN_LOOP, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_IN_LOOP},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- {ZAP_CHANNEL_STATE_RING, ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_RING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA,ZAP_END}
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_HANGUP, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- {ZAP_CHANNEL_STATE_DOWN, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END},
- },
- {
- ZSD_INBOUND,
- ZSM_UNACCEPTABLE,
- {ZAP_CHANNEL_STATE_UP, ZAP_END},
- {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END},
- },
-
-
- }
-};
-
-/**
- * \brief Initialises an sangoma boost span from configuration variables
- * \param span Span to configure
- * \param sig_cb Callback function for event signals
- * \param ap List of configuration variables
- * \return Success or failure
- */
-static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span)
-{
- zap_sangoma_boost_data_t *sangoma_boost_data = NULL;
- const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66";
- int local_port = 53000, remote_port = 53000;
- char *var, *val;
- int *intval;
-
- while((var = va_arg(ap, char *))) {
- if (!strcasecmp(var, "local_ip")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- local_ip = val;
- } else if (!strcasecmp(var, "remote_ip")) {
- if (!(val = va_arg(ap, char *))) {
- break;
- }
- remote_ip = val;
- } else if (!strcasecmp(var, "local_port")) {
- if (!(intval = va_arg(ap, int *))) {
- break;
- }
- local_port = *intval;
- } else if (!strcasecmp(var, "remote_port")) {
- if (!(intval = va_arg(ap, int *))) {
- break;
- }
- remote_port = *intval;
- } else {
- snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var);
- return ZAP_FAIL;
- }
- }
-
-
- if (!local_ip && local_port && remote_ip && remote_port && sig_cb) {
- zap_set_string(span->last_error, "missing params");
- return ZAP_FAIL;
- }
-
- sangoma_boost_data = malloc(sizeof(*sangoma_boost_data));
- assert(sangoma_boost_data);
- memset(sangoma_boost_data, 0, sizeof(*sangoma_boost_data));
-
- zap_set_string(sangoma_boost_data->mcon.cfg.local_ip, local_ip);
- sangoma_boost_data->mcon.cfg.local_port = local_port;
- zap_set_string(sangoma_boost_data->mcon.cfg.remote_ip, remote_ip);
- sangoma_boost_data->mcon.cfg.remote_port = remote_port;
- span->signal_cb = sig_cb;
- span->start = zap_sangoma_boost_start;
- span->signal_data = sangoma_boost_data;
- span->signal_type = ZAP_SIGTYPE_SANGOMABOOST;
- span->outgoing_call = sangoma_boost_outgoing_call;
- span->channel_request = sangoma_boost_channel_request;
- span->state_map = &boost_state_map;
- zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED);
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Openzap sangoma boost signaling module definition
- */
-zap_module_t zap_module = {
- "sangoma_boost",
- NULL,
- NULL,
- zap_sangoma_boost_init,
- zap_sangoma_boost_configure_span,
- NULL
-};
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c
deleted file mode 100644
index 68f046799f..0000000000
--- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c
+++ /dev/null
@@ -1,527 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II, Nenad Corbic
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#if HAVE_NETDB_H
-#include
-#endif
-
-#include "openzap.h"
-#include
-
-#ifndef HAVE_GETHOSTBYNAME_R
-extern int gethostbyname_r (const char *__name,
- struct hostent *__result_buf,
- char *__buf, size_t __buflen,
- struct hostent **__result,
- int *__h_errnop);
-#endif
-
-struct sangomabc_map {
- uint32_t event_id;
- const char *name;
-};
-
-static struct sangomabc_map sangomabc_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_PROGRESS, "CALL PROGRESS"},
- {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_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"},
- {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"},
- {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"},
- {SIGBOOST_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"},
- {SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE, "AUTO_CALL_GAP_ABATE"},
- {SIGBOOST_EVENT_DIGIT_IN, "DIGIT_IN"}
-};
-
-
-
-static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_event_t *event, int priority, int dir, const char *file, const char *func, int line)
-{
- if (event->event_id == SIGBOOST_EVENT_HEARTBEAT)
- return;
-
- zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n",
- dir ? "TX":"RX",
- sangomabc_event_id_name(event->event_id),
- event->event_id,
- event->span+1,
- event->chan+1,
- event->call_setup_id,
- event->fseqno,
- strlen(event->calling_name)?event->calling_name:"N/A",
- (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->isup_in_rdnis);
-
-}
-static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_short_event_t *event, int priority, int dir, const char *file, const char *func, int line)
-{
- if (event->event_id == SIGBOOST_EVENT_HEARTBEAT)
- return;
- zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n",
- dir ? "TX":"RX",
- priority ? "P":"N",
- sangomabc_event_id_name(event->event_id),
- event->event_id,
- event->span+1,
- event->chan+1,
- event->release_cause,
- event->call_setup_id,
- event->fseqno);
-}
-
-
-static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
-{
- int rc;
- struct hostent *result, *local_result;
- char buf[512], local_buf[512];
- int err = 0, local_err = 0;
-
- memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp));
- memset(&mcon->local_hp, 0, sizeof(mcon->local_hp));
-#ifdef HAVE_NETINET_SCTP_H
- zap_log(ZAP_LOG_DEBUG, "Creating SCTP socket L=%s:%d R=%s:%d\n",
- local_ip, local_port, ip, port);
- mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
-#else
- zap_log(ZAP_LOG_DEBUG, "Creating UDP socket L=%s:%d R=%s:%d\n",
- local_ip, local_port, ip, port);
- mcon->socket = socket(AF_INET, SOCK_DGRAM, 0);
-#endif
-
- if (mcon->socket >= 0) {
- int flag;
-
- flag = 1;
-#ifdef HAVE_GETHOSTBYNAME_R_FIVE
- gethostbyname_r(ip, &mcon->remote_hp, buf, sizeof(buf), &err);
- gethostbyname_r(local_ip, &mcon->local_hp, local_buf, sizeof(local_buf), &local_err);
- if (!err && !local_err) {
-#else
- gethostbyname_r(ip, &mcon->remote_hp, buf, sizeof(buf), &result, &err);
- gethostbyname_r(local_ip, &mcon->local_hp, local_buf, sizeof(local_buf), &local_result, &local_err);
- if (result && local_result) {
-#endif
- mcon->remote_addr.sin_family = mcon->remote_hp.h_addrtype;
- memcpy((char *) &mcon->remote_addr.sin_addr.s_addr, mcon->remote_hp.h_addr_list[0], mcon->remote_hp.h_length);
- mcon->remote_addr.sin_port = htons(port);
-
- mcon->local_addr.sin_family = mcon->local_hp.h_addrtype;
- memcpy((char *) &mcon->local_addr.sin_addr.s_addr, mcon->local_hp.h_addr_list[0], mcon->local_hp.h_length);
- mcon->local_addr.sin_port = htons(local_port);
-
-#ifdef HAVE_NETINET_SCTP_H
- setsockopt(mcon->socket, IPPROTO_SCTP, SCTP_NODELAY,
- (char *)&flag, sizeof(int));
-#endif
-
- if ((rc = bind(mcon->socket,
- (struct sockaddr *) &mcon->local_addr,
- sizeof(mcon->local_addr))) < 0) {
- close(mcon->socket);
- mcon->socket = -1;
- } else {
-#ifdef HAVE_NETINET_SCTP_H
- rc=listen(mcon->socket, 100);
- if (rc) {
- close(mcon->socket);
- mcon->socket = -1;
- }
-#endif
- }
- }
- }
-
- zap_mutex_create(&mcon->mutex);
-
- return mcon->socket;
-}
-
-int sangomabc_connection_close(sangomabc_connection_t *mcon)
-{
- if (mcon->socket > -1) {
- close(mcon->socket);
- }
-
- if (mcon->mutex) {
- zap_mutex_lock(mcon->mutex);
- zap_mutex_unlock(mcon->mutex);
- zap_mutex_destroy(&mcon->mutex);
- }
- memset(mcon, 0, sizeof(*mcon));
- mcon->socket = -1;
-
- return 0;
-}
-
-int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
-{
- create_conn_socket(mcon, local_ip, local_port, ip, port);
- return mcon->socket;
-}
-
-
-int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause, int flags)
-{
- sangomabc_short_event_t oevent;
- int retry = 5;
-
- sangomabc_event_init(&oevent, cmd, chan, span);
- oevent.release_cause = cause;
- oevent.flags = flags;
-
- if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART || cmd == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) {
- mcon->rxseq_reset = 1;
- mcon->txseq = 0;
- mcon->rxseq = 0;
- mcon->txwindow = 0;
- }
-
- if (id >= 0) {
- oevent.call_setup_id = id;
- }
-
- while (sangomabc_connection_write(mcon, (sangomabc_event_t*)&oevent) <= 0) {
- if (--retry <= 0) {
- zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket: %s\n", strerror(errno));
- return -1;
- } else {
- zap_log(ZAP_LOG_WARNING, "Failed to tx on ISUP socket: %s :retry %i\n", strerror(errno), retry);
- zap_sleep(1);
- }
- }
-
- return 0;
-}
-
-
-int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause)
-{
- sangomabc_short_event_t oevent;
- int retry = 5;
-
- sangomabc_event_init(&oevent, cmd, chan, span);
- oevent.release_cause = cause;
-
- if (id >= 0) {
- oevent.call_setup_id = id;
- }
-
- while (sangomabc_connection_writep(pcon, (sangomabc_event_t*)&oevent) <= 0) {
- if (--retry <= 0) {
- zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket: %s\n", strerror(errno));
- return -1;
- } else {
- zap_log(ZAP_LOG_WARNING, "Failed to tx on ISUP socket: %s :retry %i\n", strerror(errno), retry);
- zap_sleep(1);
- }
- }
-
- return 0;
-}
-
-sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line)
-{
- unsigned int fromlen = sizeof(struct sockaddr_in);
- int bytes = 0;
- int msg_ok = 0;
-
- bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT,
- (struct sockaddr *) &mcon->local_addr, &fromlen);
-
- if (bytes <= 0) {
- return NULL;
- }
-
- if (mcon->event.version != SIGBOOST_VERSION) {
- zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION);
- }
-
- /* Must check for < 0 cannot rely on bytes > MIN_SIZE_... compiler issue */
- if (bytes < 0) {
- msg_ok=0;
-
- } else if ((bytes >= MIN_SIZE_CALLSTART_MSG) && boost_full_event(mcon->event.event_id)) {
- msg_ok=1;
-
- } else if (bytes == sizeof(sangomabc_short_event_t)) {
- msg_ok=1;
-
- } else {
- msg_ok=0;
- }
-
- if (msg_ok){
-
- if (sangomabc_test_flag(mcon, MSU_FLAG_DOWN)) {
- if (mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART &&
- mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK &&
- mcon->event.event_id != SIGBOOST_EVENT_HEARTBEAT) {
- zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "Not reading packets when connection is down. [%s]\n",
- sangomabc_event_id_name(mcon->event.event_id));
- return NULL;
- }
- }
-
- if (boost_full_event(mcon->event.event_id)) {
- sangomabc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line);
- } else {
- sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)&mcon->event, 0, 0, file, func, line);
- }
-
-#if 0
-/* NC: NOT USED ANY MORE */
- if (mcon->rxseq_reset) {
- //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) {
- zap_log(ZAP_LOG_DEBUG, "Rx sync ok\n");
- mcon->rxseq = mcon->event.fseqno;
- return &mcon->event;
- //}
- errno=EAGAIN;
- zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n");
- return NULL;
- }
-#endif
-
- mcon->txwindow = mcon->txseq - mcon->event.bseqno;
- mcon->rxseq++;
-
-#if 0
- if (mcon->rxseq != mcon->event.fseqno) {
- zap_log(ZAP_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno);
- return NULL;
- }
-#endif
-
- return &mcon->event;
- } else {
- if (iteration == 0) {
- zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
- return NULL;
- }
- }
-
- return NULL;
-}
-
-sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line)
-{
- unsigned int fromlen = sizeof(struct sockaddr_in);
- int bytes = 0;
-
- bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen);
-
- if (bytes <= 0) {
- return NULL;
- }
-
- if (mcon->event.version != SIGBOOST_VERSION) {
- zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION);
- }
-
- if (bytes == sizeof(sangomabc_short_event_t)) {
-
- if (boost_full_event(mcon->event.event_id)) {
- sangomabc_print_event_call(mcon, &mcon->event, 1, 0, file, func, line);
- } else {
- sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)&mcon->event, 1, 0, file, func, line);
- }
-
- return &mcon->event;
- } else {
- if (iteration == 0) {
- zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event));
- return NULL;
- }
- }
-
- return NULL;
-}
-
-
-int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line)
-{
- int err;
- int event_size=MIN_SIZE_CALLSTART_MSG+event->isup_in_rdnis_size;
-
- if (!event || mcon->socket < 0 || !mcon->mutex) {
- zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n");
- return -EINVAL;
- abort();
- }
-
- if (event->span >= ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN || event->chan >= ZAP_MAX_CHANNELS_PHYSICAL_SPAN ) {
- zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", sangomabc_event_id_name(event->event_id), event->span, event->chan);
- abort();
- return -1;
- }
-
- if (!boost_full_event(event->event_id)) {
- event_size=sizeof(sangomabc_short_event_t);
- }
-
- if (sangomabc_test_flag(mcon, MSU_FLAG_DOWN)) {
- if (event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART &&
- event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK &&
- event->event_id != SIGBOOST_EVENT_HEARTBEAT) {
- zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "Not writing packets when connection is down. [%s]\n",
- sangomabc_event_id_name(event->event_id));
- return 0;
- }
- }
-
- zap_mutex_lock(mcon->mutex);
- if (event->event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) {
- mcon->txseq=0;
- mcon->rxseq=0;
- event->fseqno=0;
- } else {
- event->fseqno = mcon->txseq++;
- }
- event->bseqno = mcon->rxseq;
- event->version = SIGBOOST_VERSION;
- err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr));
-
- zap_mutex_unlock(mcon->mutex);
-
- if (err != event_size) {
- err = -1;
- abort();
- }
-
- if (boost_full_event(event->event_id)) {
- sangomabc_print_event_call(mcon, event, 0, 1, file, func, line);
- } else {
- sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)event, 0, 1, file, func, line);
- }
-
- return err;
-}
-
-
-int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line)
-{
- int err;
- int event_size=sizeof(sangomabc_event_t);
-
- if (!event || mcon->socket < 0 || !mcon->mutex) {
- zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n");
- return -EINVAL;
- abort();
- }
-
- if (!boost_full_event(event->event_id)) {
- event_size=sizeof(sangomabc_short_event_t);
- }
-
- zap_mutex_lock(mcon->mutex);
- event->version = SIGBOOST_VERSION;
- err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr));
- zap_mutex_unlock(mcon->mutex);
-
- if (err != event_size) {
- err = -1;
- abort();
- }
-
- if (boost_full_event(event->event_id)) {
- sangomabc_print_event_call(mcon, event, 1, 1, file, func, line);
- } else {
- sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)event, 1, 1, file, func, line);
- }
-
- return err;
-}
-
-
-void sangomabc_call_init(sangomabc_event_t *event, const char *calling, const char *called, int setup_id)
-{
- memset(event, 0, sizeof(sangomabc_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;
-
-}
-
-void sangomabc_event_init(sangomabc_short_event_t *event, sangomabc_event_id_t event_id, int chan, int span)
-{
- memset(event, 0, sizeof(sangomabc_short_event_t));
- event->event_id = event_id;
- event->chan = chan;
- event->span = span;
-}
-
-const char *sangomabc_event_id_name(uint32_t event_id)
-{
- unsigned int x;
- const char *ret = NULL;
-
- for (x = 0 ; x < sizeof(sangomabc_table)/sizeof(struct sangomabc_map); x++) {
- if (sangomabc_table[x].event_id == event_id) {
- ret = sangomabc_table[x].name;
- break;
- }
- }
-
- return ret;
-}
-
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h
deleted file mode 100644
index bbed200765..0000000000
--- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II, Nenad Corbic
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _SANGOMABC_H
-#define _SANGOMABC_H
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#ifdef HAVE_NETINET_SCTP_H
-#include
-#endif
-#include
-#include
-#include
-#include
-#include
-
-#define sangomabc_test_flag(p,flag) ({ \
- ((p)->flags & (flag)); \
- })
-
-#define sangomabc_set_flag(p,flag) do { \
- ((p)->flags |= (flag)); \
- } while (0)
-
-#define sangomabc_clear_flag(p,flag) do { \
- ((p)->flags &= ~(flag)); \
- } while (0)
-
-#define sangomabc_copy_flags(dest,src,flagz) do { \
- (dest)->flags &= ~(flagz); \
- (dest)->flags |= ((src)->flags & (flagz)); \
- } while (0)
-
-typedef t_sigboost_callstart sangomabc_event_t;
-typedef t_sigboost_short sangomabc_short_event_t;
-typedef uint32_t sangomabc_event_id_t;
-
-typedef struct sangomabc_ip_cfg
-{
- char local_ip[25];
- int local_port;
- char remote_ip[25];
- int remote_port;
-}sangomabc_ip_cfg_t;
-
-typedef enum {
- MSU_FLAG_EVENT = (1 << 0),
- MSU_FLAG_DOWN = (1 << 1)
-} sangomabc_flag_t;
-
-
-struct sangomabc_connection {
- zap_socket_t socket;
- struct sockaddr_in local_addr;
- struct sockaddr_in remote_addr;
- sangomabc_event_t event;
- struct hostent remote_hp;
- struct hostent local_hp;
- unsigned int flags;
- zap_mutex_t *mutex;
- FILE *log;
- unsigned int txseq;
- unsigned int rxseq;
- unsigned int txwindow;
- unsigned int rxseq_reset;
- sangomabc_ip_cfg_t cfg;
- uint32_t hb_elapsed;
-};
-
-typedef struct sangomabc_connection sangomabc_connection_t;
-
-/* disable nagle's algorythm */
-static inline void sctp_no_nagle(int socket)
-{
-#ifdef HAVE_NETINET_SCTP_H
- int flag = 1;
- setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int));
-#endif
-}
-
-int sangomabc_connection_close(sangomabc_connection_t *mcon);
-int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port);
-sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line);
-sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line);
-int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line);
-int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line);
-#define sangomabc_connection_write(_m,_e) __sangomabc_connection_write(_m, _e, __FILE__, __func__, __LINE__)
-#define sangomabc_connection_writep(_m,_e) __sangomabc_connection_writep(_m, _e, __FILE__, __func__, __LINE__)
-#define sangomabc_connection_read(_m,_e) __sangomabc_connection_read(_m, _e, __FILE__, __func__, __LINE__)
-#define sangomabc_connection_readp(_m,_e) __sangomabc_connection_readp(_m, _e, __FILE__, __func__, __LINE__)
-void sangomabc_event_init(sangomabc_short_event_t *event, sangomabc_event_id_t event_id, int chan, int span);
-void sangomabc_call_init(sangomabc_event_t *event, const char *calling, const char *called, int setup_id);
-const char *sangomabc_event_id_name(uint32_t event_id);
-int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause, int flags);
-int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause);
-
-#endif
-
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h
deleted file mode 100644
index 7522ea7db4..0000000000
--- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h
+++ /dev/null
@@ -1,227 +0,0 @@
-/****************************************************************************
- * sigboost.h $Revision: 1.13 $
- *
- * 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_
-
-#define SIGBOOST_VERSION 103
-
-#include
-#include
-
-#ifdef HAVE_FREETDM
-#include
-#endif
-
-enum e_sigboost_event_id_values
-{
- SIGBOOST_EVENT_CALL_START = 0x80, /*128*/
- SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129*/
- SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130*/
- SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131*/
- SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/
- SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/
- SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/
- SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/
- SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/
- /* CALL_RELEASED is aimed to fix a race condition that became obvious
- * when the boost socket was replaced by direct function calls
- * and the channel hunting was moved to freetdm, the problem is
- * we can get CALL_STOPPED msg and reply with CALL_STOPPED_ACK
- * but the signaling module will still (in PRI) send RELEASE and
- * wait for RELEASE_COMPLETE from the isdn network before
- * marking the channel as available, therefore freetdm should
- * also not mark the channel as available until CALL_RELEASED
- * is received, for socket mode we can continue working as usual
- * with CALL_STOPPED being the last step because the hunting is
- * done in the signaling module.
- *
- * CALL_RELEASED is only used in queue mode
- * */
- SIGBOOST_EVENT_CALL_RELEASED = 0x51, /* 81 */
- SIGBOOST_EVENT_CALL_PROGRESS = 0x50, /*decimal 80*/
- /* Following IDs are ss7boost to sangoma_mgd only. */
- SIGBOOST_EVENT_HEARTBEAT = 0x89, /*137*/
- SIGBOOST_EVENT_INSERT_CHECK_LOOP = 0x8a, /*138*/
- SIGBOOST_EVENT_REMOVE_CHECK_LOOP = 0x8b, /*139*/
- SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE = 0x8c, /*140*/
- SIGBOOST_EVENT_DIGIT_IN = 0x8d, /*141*/
-};
-
-#define BOOST_DECODE_EVENT_ID(id) \
- (id==SIGBOOST_EVENT_CALL_START)?"SIGBOOST_EVENT_CALL_START": \
- (id==SIGBOOST_EVENT_CALL_START_ACK)?"SIGBOOST_EVENT_CALL_START_ACK": \
- (id==SIGBOOST_EVENT_CALL_START_NACK)?"SIGBOOST_EVENT_CALL_START_NACK": \
- (id==SIGBOOST_EVENT_CALL_ANSWERED)?"SIGBOOST_EVENT_CALL_ANSWERED": \
- (id==SIGBOOST_EVENT_CALL_STOPPED)?"SIGBOOST_EVENT_CALL_STOPPED": \
- (id==SIGBOOST_EVENT_CALL_STOPPED_ACK)?"SIGBOOST_EVENT_CALL_STOPPED_ACK": \
- (id==SIGBOOST_EVENT_SYSTEM_RESTART)?"SIGBOOST_EVENT_SYSTEM_RESTART": \
- (id==SIGBOOST_EVENT_SYSTEM_RESTART_ACK)?"SIGBOOST_EVENT_SYSTEM_RESTART_ACK": \
- (id==SIGBOOST_EVENT_CALL_RELEASED)?"SIGBOOST_EVENT_CALL_RELEASED": \
- (id==SIGBOOST_EVENT_CALL_PROGRESS)?"SIGBOOST_EVENT_CALL_PROGRESS": \
- (id==SIGBOOST_EVENT_HEARTBEAT)?"SIGBOOST_EVENT_HEARTBEAT": \
- (id==SIGBOOST_EVENT_INSERT_CHECK_LOOP)?"SIGBOOST_EVENT_INSERT_CHECK_LOOP": \
- (id==SIGBOOST_EVENT_REMOVE_CHECK_LOOP)?"SIGBOOST_EVENT_REMOVE_CHECK_LOOP": \
- (id==SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE)?"SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE": \
- (id==SIGBOOST_EVENT_DIGIT_IN)?"SIGBOOST_EVENT_DIGIT_IN": "Unknown"
-
-enum e_sigboost_release_cause_values
-{
- SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0,
- SIGBOOST_RELEASE_CAUSE_NORMAL = 16,
- /* probable elimination */
- //SIGBOOST_RELEASE_CAUSE_BUSY = 0x91, /* 145 */
- //SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92, /* 146 */
- //SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93, /* 147 */
- //SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94, /* 148 */
-};
-
-enum e_sigboost_call_setup_ack_nack_cause_values
-{
- //SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 34, /* Q.850 value - don't use */
- SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 117, /* non Q.850 value indicates local all ckt busy
- causing sangoma_mgd to perform automatic call
- gapping*/
- SIGBOOST_CALL_SETUP_NACK_TEST_CKT_BUSY = 17, /* Q.850 value */
- SIGBOOST_CALL_SETUP_NACK_INVALID_NUMBER = 28, /* Q.850 value */
- SIGBOOST_CALL_SETUP_CSUPID_DBL_USE = 200, /* unused Q.850 value */
-};
-
-
-enum e_sigboost_huntgroup_values
-{
- SIGBOOST_HUNTGRP_SEQ_ASC = 0x00, /* sequential with lowest available first */
- SIGBOOST_HUNTGRP_SEQ_DESC = 0x01, /* sequential with highest available first */
- SIGBOOST_HUNTGRP_RR_ASC = 0x02, /* round-robin with lowest available first */
- SIGBOOST_HUNTGRP_RR_DESC = 0x03, /* round-robin with highest available first */
-};
-
-enum e_sigboost_event_info_par_values
-{
- SIGBOOST_EVI_SPARE = 0x00,
- SIGBOOST_EVI_ALERTING = 0x01,
- SIGBOOST_EVI_PROGRESS = 0x02,
-};
-
-enum e_sigboost_progress_flags
-{
- SIGBOOST_PROGRESS_RING = (1 << 0),
- SIGBOOST_PROGRESS_MEDIA = (1 << 1)
-};
-
-#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 32
-#define MAX_PENDING_CALLS CORE_MAX_SPANS * CORE_MAX_CHAN_PER_SPAN
-/* 0..(MAX_PENDING_CALLS-1) is range of call_setup_id below */
-
-/* Should only be used by server */
-#define MAX_CALL_SETUP_ID 0xFFFF
-
-#define SIZE_CUSTOM 900
-#define SIZE_RDNIS SIZE_CUSTOM
-
-
-#pragma pack(1)
-
-typedef struct
-{
- uint8_t capability;
- uint8_t uil1p;
-} t_sigboost_bearer;
-
-typedef struct
-{
- uint8_t digits_count;
- char digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
- uint8_t npi;
- uint8_t ton;
- uint8_t screening_ind;
- uint8_t presentation_ind;
-}t_sigboost_digits;
-
-typedef struct
-{
- uint16_t version;
- uint32_t event_id;
- /* delete sequence numbers - SCTP does not need them */
- uint32_t fseqno;
- uint32_t bseqno;
- uint16_t call_setup_id;
- uint32_t trunk_group;
- uint8_t span;
- uint8_t chan;
- uint32_t flags;
- /* struct timeval tv; */
- t_sigboost_digits called;
- t_sigboost_digits calling;
- t_sigboost_digits rdnis;
- /* ref. Q.931 Table 4-11 and Q.951 Section 3 */
- char calling_name[MAX_DIALED_DIGITS + 1];
- t_sigboost_bearer bearer;
- uint8_t hunt_group;
- uint16_t custom_data_size;
- char custom_data[SIZE_CUSTOM]; /* it's a null terminated string */
-
-} t_sigboost_callstart;
-
-#define called_number_digits_count called.digits_count
-#define called_number_digits called.digits
-#define calling_number_digits_count calling.digits_count
-#define calling_number_digits calling.digits
-#define calling_number_screening_ind calling.screening_ind
-#define calling_number_presentation calling.presentation_ind
-
-#define isup_in_rdnis_size custom_data_size
-#define isup_in_rdnis custom_data
-
-
-#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_CUSTOM
-
-typedef struct
-{
- uint16_t version;
- uint32_t event_id;
- /* delete sequence numbers - SCTP does not need them */
- uint32_t fseqno;
- uint32_t bseqno;
- uint16_t call_setup_id;
- uint32_t trunk_group;
- uint8_t span;
- uint8_t chan;
- uint32_t flags;
- /* struct timeval tv; */
- uint8_t release_cause;
-} t_sigboost_short;
-#pragma pack()
-
-
-static inline int boost_full_event(int event_id)
-{
- switch (event_id) {
- case SIGBOOST_EVENT_CALL_START:
- case SIGBOOST_EVENT_DIGIT_IN:
- case SIGBOOST_EVENT_CALL_PROGRESS:
- return 1;
- default:
- break;
- }
-
- return 0;
-}
-
-#endif
diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h
deleted file mode 100644
index ca4ecbf469..0000000000
--- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_SANGOMA_BOOST_H
-#define ZAP_SANGOMA_BOOST_H
-#include "sangoma_boost_client.h"
-#include "openzap.h"
-
-typedef enum {
- ZAP_SANGOMA_BOOST_RUNNING = (1 << 0),
- ZAP_SANGOMA_BOOST_RESTARTING = (1 << 1)
-} zap_sangoma_boost_flag_t;
-
-typedef struct zap_sangoma_boost_data {
- sangomabc_connection_t mcon;
- sangomabc_connection_t pcon;
- uint32_t flags;
-} zap_sangoma_boost_data_t;
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
-
diff --git a/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c b/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c
deleted file mode 100644
index 0c706fbd8f..0000000000
--- a/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "openzap.h"
-//#include "zap_skel.h"
-
-static ZIO_CONFIGURE_FUNCTION(skel_configure)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_OPEN_FUNCTION(skel_open)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_CLOSE_FUNCTION(skel_close)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_WAIT_FUNCTION(skel_wait)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_READ_FUNCTION(skel_read)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_WRITE_FUNCTION(skel_write)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_COMMAND_FUNCTION(skel_command)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_SPAN_POLL_EVENT_FUNCTION(skel_poll_event)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_SPAN_NEXT_EVENT_FUNCTION(skel_next_event)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_SPAN_DESTROY_FUNCTION(skel_span_destroy)
-{
- return ZAP_FAIL;
-}
-
-static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms)
-{
- return ZAP_FAIL;
-}
-
-static zap_io_interface_t skel_interface;
-
-static ZIO_IO_LOAD_FUNCTION(skel_init)
-{
- assert(zio != NULL);
- memset(&skel_interface, 0, sizeof(skel_interface));
-
- skel_interface.name = "skel";
- skel_interface.configure = skel_configure;
- skel_interface.configure_span = skel_configure_span;
- skel_interface.open = skel_open;
- skel_interface.close = skel_close;
- skel_interface.wait = skel_wait;
- skel_interface.read = skel_read;
- skel_interface.write = skel_write;
- skel_interface.command = skel_command;
- skel_interface.poll_event = skel_poll_event;
- skel_interface.next_event = skel_next_event;
- skel_interface.channel_destroy = skel_channel_destroy;
- skel_interface.span_destroy = skel_span_destroy;
- skel_interface.get_alarms = skel_get_alarms;
- *zio = &skel_interface;
-
- return ZAP_SUCCESS;
-}
-
-static ZIO_IO_UNLOAD_FUNCTION(skel_destroy)
-{
- return ZAP_SUCCESS;
-}
-
-
-zap_module_t zap_module = {
- "skel",
- skel_init,
- skel_destroy,
-};
-
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj
deleted file mode 100644
index da21a76b7a..0000000000
--- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj
+++ /dev/null
@@ -1,196 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj
deleted file mode 100644
index c66eb3becb..0000000000
--- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj
+++ /dev/null
@@ -1,355 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c
deleted file mode 100644
index 0d35747461..0000000000
--- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c
+++ /dev/null
@@ -1,1275 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifdef __sun
-#include
-#include
-#endif
-#include "openzap.h"
-#ifndef __WINDOWS__
-#include
-#include
-#endif
-#include "libsangoma.h"
-
-#if defined(__WINDOWS__)
-/*! Backward compatible defines - current code is all using the old names*/
-#define sangoma_open_tdmapi_span_chan sangoma_open_api_span_chan
-#define sangoma_open_tdmapi_span sangoma_open_api_span
-#define sangoma_open_tdmapi_ctrl sangoma_open_api_ctrl
-#define sangoma_tdm_get_fe_status sangoma_get_fe_status
-#define sangoma_socket_close sangoma_close
-#define sangoma_tdm_get_hw_coding sangoma_get_hw_coding
-#define sangoma_tdm_set_fe_status sangoma_set_fe_status
-#define sangoma_tdm_get_link_status sangoma_get_link_status
-#define sangoma_tdm_flush_bufs sangoma_flush_bufs
-#define sangoma_tdm_cmd_exec sangoma_cmd_exec
-#define sangoma_tdm_read_event sangoma_read_event
-#define sangoma_readmsg_tdm sangoma_readmsg
-#define sangoma_readmsg_socket sangoma_readmsg
-#define sangoma_sendmsg_socket sangoma_writemsg
-#define sangoma_writemsg_tdm sangoma_writemsg
-#define sangoma_create_socket_intr sangoma_open_api_span_chan
-#endif
-
-/*! Starting with libsangoma 3 we can use the new libsangoma waitable API, the poor souls of those using a release were LIBSANGOMA version
- * is defined but the version is not higher or equal to 3.0.0 will be forced to upgrade
- * */
-#ifdef LIBSANGOMA_VERSION
-#if LIBSANGOMA_VERSION_CODE < LIBSANGOMA_VERSION(3,0,0)
-#undef LIBSANGOMA_VERSION
-#endif
-#endif
-
-/**
- * \brief Wanpipe flags
- */
-typedef enum {
- WP_RINGING = (1 << 0)
-} wp_flag_t;
-
-/**
- * \brief Wanpipe globals
- */
-static struct {
- uint32_t codec_ms;
- uint32_t wink_ms;
- uint32_t flash_ms;
- uint32_t ring_on_ms;
- uint32_t ring_off_ms;
-} wp_globals;
-
-/* a bunch of this stuff should go into the wanpipe_tdm_api_iface.h */
-
-ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event);
-ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event);
-
-/**
- * \brief Poll for event on a wanpipe socket
- * \param fd Wanpipe socket descriptor
- * \param timeout Time to wait for event
- * \param flags Sangoma event flags
- * \return -1 on failure, wanpipe event flags on success
- *
- * a cross platform way to poll on an actual pollset (span and/or list of spans) will probably also be needed for analog
- * so we can have one analong handler thread that will deal with all the idle analog channels for events
- * the alternative would be for the driver to provide one socket for all of the oob events for all analog channels
- */
-static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, int *flags)
-{
-
-#ifdef LIBSANGOMA_VERSION
- int err;
- uint32_t inflags = *flags;
- uint32_t outflags = 0;
- sangoma_wait_obj_t *sangoma_wait_obj = zchan->mod_data;
-
- err = sangoma_waitfor(sangoma_wait_obj, inflags, &outflags, timeout);
- *flags = 0;
- if (err == SANG_STATUS_SUCCESS) {
- *flags = outflags;
- err = 1; /* ideally should be the number of file descriptors with something to read */
- }
- if (err == SANG_STATUS_APIPOLL_TIMEOUT) {
- err = 0;
- }
- return err;
-#else
- struct pollfd pfds[1];
- int res;
-
- memset(&pfds[0], 0, sizeof(pfds[0]));
- pfds[0].fd = zchan->sockfd;
- pfds[0].events = *flags;
- res = poll(pfds, 1, timeout);
- *flags = 0;
-
- if (pfds[0].revents & POLLERR) {
- res = -1;
- }
-
- if (res > 0) {
- *flags = pfds[0].revents;
- }
-
- return res;
-#endif
-
-}
-
-/**
- * \brief Opens a sangoma channel socket (TDM API)
- * \param span Span number
- * \param chan Channel number
- * \return 0 on success, wanpipe error code on failure
- */
-static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan)
-{
- return sangoma_open_tdmapi_span_chan(span, chan);
-}
-
-#ifdef LIBSANGOMA_VERSION
-static __inline__ sng_fd_t __tdmv_api_open_span_chan(int span, int chan)
-{
- return __sangoma_open_tdmapi_span_chan(span, chan);
-}
-#endif
-
-static zap_io_interface_t wanpipe_interface;
-
-/**
- * \brief Inverts bit string
- * \param cas_bits CAS bit string
- * \return Swapped bits
- */
-static unsigned char wanpipe_swap_bits(unsigned char cas_bits)
-{
- unsigned char swapped_bits = 0x0;
- if (cas_bits & 0x8) {
- swapped_bits |= 0x1;
- }
- if (cas_bits & 0x4) {
- swapped_bits |= 0x2;
- }
- if (cas_bits & 0x2) {
- swapped_bits |= 0x4;
- }
- if (cas_bits & 0x1) {
- swapped_bits |= 0x8;
- }
- return swapped_bits;
-}
-
-/**
- * \brief Initialises a range of wanpipe channels
- * \param span Openzap span
- * \param spanno Wanpipe span number
- * \param start Initial wanpipe channel number
- * \param end Final wanpipe channel number
- * \param type Openzap channel type
- * \param name Openzap span name
- * \param number Openzap span number
- * \param cas_bits CAS bits
- * \return number of spans configured
- */
-static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number, unsigned char cas_bits)
-{
- unsigned configured = 0, x;
-#ifdef LIBSANGOMA_VERSION
- sangoma_status_t sangstatus;
- sangoma_wait_obj_t *sangoma_wait_obj;
-#endif
-
- if (type == ZAP_CHAN_TYPE_CAS) {
- zap_log(ZAP_LOG_DEBUG, "Configuring Wanpipe CAS channels with abcd == 0x%X\n", cas_bits);
- }
- for(x = start; x < end; x++) {
- zap_channel_t *chan;
- zap_socket_t sockfd = ZAP_INVALID_SOCKET;
- const char *dtmf = "none";
- if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == ZAP_TRUNK_T1 && x == 24) {
-#ifdef LIBSANGOMA_VERSION
- sockfd = __tdmv_api_open_span_chan(spanno, x);
-#else
- zap_log(ZAP_LOG_ERROR, "span %d channel %d cannot be configured as smg_prid_nfas, you need to compile openzap with newer libsangoma\n", spanno, x);
-#endif
- } else {
- sockfd = tdmv_api_open_span_chan(spanno, x);
- }
-
- if (sockfd == ZAP_INVALID_SOCKET) {
- zap_log(ZAP_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x);
- continue;
- }
-
- if (zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) {
- wanpipe_tdm_api_t tdm_api;
- memset(&tdm_api, 0, sizeof(tdm_api));
-#ifdef LIBSANGOMA_VERSION
- sangstatus = sangoma_wait_obj_create(&sangoma_wait_obj, sockfd, SANGOMA_DEVICE_WAIT_OBJ);
- if (sangstatus != SANG_STATUS_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "failure create waitable object for s%dc%d\n", spanno, x);
- continue;
- }
- chan->mod_data = sangoma_wait_obj;
-#endif
-
- chan->physical_span_id = spanno;
- chan->physical_chan_id = x;
- chan->rate = 8000;
-
- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) {
- int err;
-
- dtmf = "software";
-
- /* FIXME: Handle Error Condition Check for return code */
- err = sangoma_tdm_get_hw_coding(chan->sockfd, &tdm_api);
-
- if (tdm_api.wp_tdm_cmd.hw_tdm_coding) {
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW;
- } else {
- chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW;
- }
-
- err = sangoma_tdm_get_hw_dtmf(chan->sockfd, &tdm_api);
- if (err > 0) {
- zap_channel_set_feature(chan, ZAP_CHANNEL_FEATURE_DTMF_DETECT);
- dtmf = "hardware";
- }
- }
-
-#ifdef LIBSANGOMA_VERSION
- if (type == ZAP_CHAN_TYPE_FXS) {
- if (sangoma_tdm_disable_ring_trip_detect_events(chan->sockfd, &tdm_api)) {
- /* we had problems of on-hook/off-hook detection due to how ring trip events were handled
- * if this fails, I believe we will still work ok as long as we dont handle them incorrectly */
- zap_log(ZAP_LOG_WARNING, "Failed to disable ring trip events in channel s%dc%d\n", spanno, x);
- }
- }
-#endif
-#if 0
- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) {
- /* Enable FLASH/Wink Events */
- int err=sangoma_set_rm_rxflashtime(chan->sockfd, &tdm_api, wp_globals.flash_ms);
- if (err == 0) {
- zap_log(ZAP_LOG_ERROR, "flash enabled s%dc%d\n", spanno, x);
- } else {
- zap_log(ZAP_LOG_ERROR, "flash disabled s%dc%d\n", spanno, x);
- }
- }
-#endif
-
- if (type == ZAP_CHAN_TYPE_CAS || type == ZAP_CHAN_TYPE_EM) {
-#ifdef LIBSANGOMA_VERSION
- sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id, wanpipe_swap_bits(cas_bits));
-
- /* this should probably be done for old libsangoma but I am not sure if the API is available and I'm lazy to check,
- The poll rate is hard coded to 100 per second (done in the driver, is the max rate of polling allowed by wanpipe)
- */
- if (sangoma_tdm_enable_rbs_events(chan->sockfd, &tdm_api, 100)) {
- zap_log(ZAP_LOG_ERROR, "Failed to enable RBS/CAS events in device %d:%d fd:%d\n", chan->span_id, chan->chan_id, sockfd);
- continue;
- }
- /* probably done by the driver but lets write defensive code this time */
- sangoma_flush_bufs(chan->sockfd, &tdm_api);
-#else
- /*
- * With wanpipe 3.4.4.2 I get failure even though the events are enabled, /var/log/messages said:
- * wanpipe4: WARNING: Event type 9 is already pending!
- * wanpipe4: Failed to add new fe event 09 ch_map=FFFFFFFF!
- * may be we should not send an error until that is fixed in the driver
- */
- if (sangoma_tdm_enable_rbs_events(chan->sockfd, &tdm_api, 100)) {
- zap_log(ZAP_LOG_ERROR, "Failed to enable RBS/CAS events in device %d:%d fd:%d\n", chan->span_id, chan->chan_id, sockfd);
- }
- /* probably done by the driver but lets write defensive code this time */
- sangoma_tdm_flush_bufs(chan->sockfd, &tdm_api);
- sangoma_tdm_write_rbs(chan->sockfd,&tdm_api, wanpipe_swap_bits(cas_bits));
-#endif
- }
-
- if (!zap_strlen_zero(name)) {
- zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name));
- }
-
- if (!zap_strlen_zero(number)) {
- zap_copy_string(chan->chan_number, number, sizeof(chan->chan_number));
- }
- configured++;
- zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d DTMF: %s\n",
- spanno, x, chan->span_id, chan->chan_id, sockfd, dtmf);
-
- } else {
- zap_log(ZAP_LOG_ERROR, "zap_span_add_channel failed for wanpipe span %d channel %d\n", spanno, x);
- }
- }
-
- return configured;
-}
-
-/**
- * \brief Process configuration variable for a Wanpipe profile
- * \param category Wanpipe profile name
- * \param var Variable name
- * \param val Variable value
- * \param lineno Line number from configuration file
- * \return Success
- */
-static ZIO_CONFIGURE_FUNCTION(wanpipe_configure)
-{
- int num;
-
- if (!strcasecmp(category, "defaults")) {
- if (!strcasecmp(var, "codec_ms")) {
- num = atoi(val);
- if (num < 10 || num > 60) {
- zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", lineno);
- } else {
- wp_globals.codec_ms = num;
- }
- } else if (!strcasecmp(var, "wink_ms")) {
- num = atoi(val);
- if (num < 50 || num > 3000) {
- zap_log(ZAP_LOG_WARNING, "invalid wink ms at line %d\n", lineno);
- } else {
- wp_globals.wink_ms = num;
- }
- } else if (!strcasecmp(var, "flash_ms")) {
- num = atoi(val);
- if (num < 50 || num > 3000) {
- zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno);
- } else {
- wp_globals.flash_ms = num;
- }
- } else if (!strcasecmp(var, "ring_on_ms")) {
- num = atoi(val);
- if (num < 500 || num > 5000) {
- zap_log(ZAP_LOG_WARNING, "invalid ring_on_ms at line %d (valid range 500 to 5000)\n", lineno);
- } else {
- wp_globals.ring_on_ms = num;
- }
- } else if (!strcasecmp(var, "ring_off_ms")) {
- num = atoi(val);
- if (num < 500 || num > 5000) {
- zap_log(ZAP_LOG_WARNING, "invalid ring_off_ms at line %d (valid range 500 to 5000)\n", lineno);
- } else {
- wp_globals.ring_off_ms = num;
- }
- }
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Initialises an openzap Wanpipe span from a configuration string
- * \param span Openzap span
- * \param str Configuration string
- * \param type Openzap span type
- * \param name Openzap span name
- * \param number Openzap span number
- * \return Success or failure
- */
-static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span)
-{
- int items, i;
- char *mydata, *item_list[10];
- char *sp, *ch, *mx;
- unsigned char cas_bits = 0;
- int channo;
- int spanno;
- int top = 0;
- unsigned configured = 0;
-
- assert(str != NULL);
-
-
- mydata = strdup(str);
- assert(mydata != NULL);
-
-
- items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0])));
-
- for(i = 0; i < items; i++) {
- sp = item_list[i];
- if ((ch = strchr(sp, ':'))) {
- *ch++ = '\0';
- }
-
- if (!(sp && ch)) {
- zap_log(ZAP_LOG_ERROR, "No valid wanpipe span and channel was specified\n");
- continue;
- }
-
- channo = atoi(ch);
- spanno = atoi(sp);
-
- if (channo < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid channel number %d\n", channo);
- continue;
- }
-
- if (spanno < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid span number %d\n", channo);
- continue;
- }
-
- if ((mx = strchr(ch, '-'))) {
- mx++;
- top = atoi(mx) + 1;
- } else {
- top = channo + 1;
- }
-
-
- if (top < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top);
- continue;
- }
- if (ZAP_CHAN_TYPE_CAS == type && zap_config_get_cas_bits(ch, &cas_bits)) {
- zap_log(ZAP_LOG_ERROR, "Failed to get CAS bits in CAS channel\n");
- continue;
- }
- configured += wp_open_range(span, spanno, channo, top, type, name, number, cas_bits);
-
- }
-
- free(mydata);
-
- return configured;
-}
-
-/**
- * \brief Opens Wanpipe channel
- * \param zchan Channel to open
- * \return Success or failure
- */
-static ZIO_OPEN_FUNCTION(wanpipe_open)
-{
-
- wanpipe_tdm_api_t tdm_api;
-
- memset(&tdm_api,0,sizeof(tdm_api));
- sangoma_tdm_flush_bufs(zchan->sockfd, &tdm_api);
-#ifdef LIBSANGOMA_VERSION
- sangoma_flush_event_bufs(zchan->sockfd, &tdm_api);
-#endif
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) {
- zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE;
- } else {
- zchan->effective_codec = zchan->native_codec;
-
- sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, wp_globals.codec_ms);
-
- zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL);
- zchan->effective_interval = zchan->native_interval = wp_globals.codec_ms;
- zchan->packet_len = zchan->native_interval * 8;
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Closes Wanpipe channel
- * \param zchan Channel to close
- * \return Success
- */
-static ZIO_CLOSE_FUNCTION(wanpipe_close)
-{
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Executes an Openzap command on a Wanpipe channel
- * \param zchan Channel to execute command on
- * \param command Openzap command to execute
- * \param obj Object (unused)
- * \return Success or failure
- */
-static ZIO_COMMAND_FUNCTION(wanpipe_command)
-{
- wanpipe_tdm_api_t tdm_api;
- int err = 0;
-
- memset(&tdm_api, 0, sizeof(tdm_api));
-
- switch(command) {
- case ZAP_COMMAND_OFFHOOK:
- {
- err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed");
- return ZAP_FAIL;
- }
- zap_set_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK);
- }
- break;
- case ZAP_COMMAND_ONHOOK:
- {
- err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed");
- return ZAP_FAIL;
- }
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK);
- }
- break;
- case ZAP_COMMAND_GENERATE_RING_ON:
- {
- err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed");
- return ZAP_FAIL;
- }
- zap_set_flag_locked(zchan, ZAP_CHANNEL_RINGING);
- zap_set_pflag_locked(zchan, WP_RINGING);
- zchan->ring_time = zap_current_time_in_ms() + wp_globals.ring_on_ms;
- }
- break;
- case ZAP_COMMAND_GENERATE_RING_OFF:
- {
- err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed");
- return ZAP_FAIL;
- }
- zap_clear_pflag_locked(zchan, WP_RINGING);
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING);
- }
- break;
- case ZAP_COMMAND_GET_INTERVAL:
- {
- err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api);
- if (err > 0 ) {
- ZAP_COMMAND_OBJ_INT = err;
- err=0;
- }
- }
- break;
- case ZAP_COMMAND_ENABLE_ECHOCANCEL:
- {
- err=sangoma_tdm_enable_hwec(zchan->sockfd, &tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "HWEC Enable Failed");
- return ZAP_FAIL;
- }
- }
- break;
- case ZAP_COMMAND_DISABLE_ECHOCANCEL:
- {
- err=sangoma_tdm_disable_hwec(zchan->sockfd, &tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "HWEC Disable Failed");
- return ZAP_FAIL;
- }
- }
- break;
- case ZAP_COMMAND_ENABLE_DTMF_DETECT:
- {
-#ifdef WP_API_FEATURE_DTMF_EVENTS
- err = sangoma_tdm_enable_dtmf_events(zchan->sockfd, &tdm_api);
- if (err) {
- zap_log(ZAP_LOG_WARNING, "Enabling of Sangoma HW DTMF failed\n");
- snprintf(zchan->last_error, sizeof(zchan->last_error), "HW DTMF Enable Failed");
- return ZAP_FAIL;
- }
- zap_log(ZAP_LOG_DEBUG, "Enabled DTMF events on chan %d:%d\n", zchan->span_id, zchan->chan_id);
-#else
- return ZAP_NOTIMPL;
-#endif
- }
- break;
- case ZAP_COMMAND_DISABLE_DTMF_DETECT:
- {
-#ifdef WP_API_FEATURE_DTMF_EVENTS
- err = sangoma_tdm_disable_dtmf_events(zchan->sockfd, &tdm_api);
- if (err) {
- zap_log(ZAP_LOG_WARNING, "Disabling of Sangoma HW DTMF failed\n");
- snprintf(zchan->last_error, sizeof(zchan->last_error), "HW DTMF Disable Failed");
- return ZAP_FAIL;
- }
- zap_log(ZAP_LOG_DEBUG, "Disabled DTMF events on chan %d:%d\n", zchan->span_id, zchan->chan_id);
-#else
- return ZAP_NOTIMPL;
-#endif
- }
- break;
- case ZAP_COMMAND_ENABLE_LOOP:
- {
-#ifdef WP_API_FEATURE_LOOP
- err=sangoma_tdm_enable_loop(zchan->sockfd, &tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Loop Enable Failed");
- return ZAP_FAIL;
- }
-#endif
- }
- break;
- case ZAP_COMMAND_DISABLE_LOOP:
- {
-#ifdef WP_API_FEATURE_LOOP
- err=sangoma_tdm_disable_loop(zchan->sockfd, &tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Loop Disable Failed");
- return ZAP_FAIL;
- }
-#endif
- }
- break;
- case ZAP_COMMAND_SET_INTERVAL:
- {
- err=sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, ZAP_COMMAND_OBJ_INT);
- zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8);
- }
- break;
- case ZAP_COMMAND_SET_CAS_BITS:
- {
-#ifdef LIBSANGOMA_VERSION
- err = sangoma_tdm_write_rbs(zchan->sockfd,&tdm_api, zchan->physical_chan_id, wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT));
-#else
- err = sangoma_tdm_write_rbs(zchan->sockfd, &tdm_api, wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT));
-#endif
- }
- break;
- case ZAP_COMMAND_GET_CAS_BITS:
- {
-#ifdef LIBSANGOMA_VERSION
- unsigned char rbsbits;
- err = sangoma_tdm_read_rbs(zchan->sockfd, &tdm_api, zchan->physical_chan_id, &rbsbits);
- if (!err) {
- ZAP_COMMAND_OBJ_INT = wanpipe_swap_bits(rbsbits);
- }
-#else
- // does sangoma_tdm_read_rbs is available here?
- ZAP_COMMAND_OBJ_INT = zchan->rx_cas_bits;
-#endif
- }
- break;
- default:
- break;
- };
-
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- }
-
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Reads data from a Wanpipe channel
- * \param zchan Channel to read from
- * \param data Data buffer
- * \param datalen Size of data buffer
- * \return Success, failure or timeout
- */
-static ZIO_READ_FUNCTION(wanpipe_read)
-{
- int rx_len = 0;
- wp_tdm_api_rx_hdr_t hdrframe;
-
- memset(&hdrframe, 0, sizeof(hdrframe));
-
- rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0);
- *datalen = rx_len;
-
- if (rx_len == 0 || rx_len == -17) {
- return ZAP_TIMEOUT;
- }
-
- if (rx_len < 0) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- }
-
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Writes data to a Wanpipe channel
- * \param zchan Channel to write to
- * \param data Data buffer
- * \param datalen Size of data buffer
- * \return Success or failure
- */
-static ZIO_WRITE_FUNCTION(wanpipe_write)
-{
- int bsent;
- wp_tdm_api_tx_hdr_t hdrframe;
-
- /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */
- memset(&hdrframe, 0, sizeof(hdrframe));
- if (*datalen == 0) {
- return ZAP_SUCCESS;
- }
- bsent = sangoma_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen),0);
-
- /* should we be checking if bsent == *datalen here? */
- if (bsent > 0) {
- *datalen = bsent;
- return ZAP_SUCCESS;
- }
-
- return ZAP_FAIL;
-}
-
-/**
- * \brief Waits for an event on a Wanpipe channel
- * \param zchan Channel to open
- * \param flags Type of event to wait for
- * \param to Time to wait (in ms)
- * \return Success, failure or timeout
- */
-
-static ZIO_WAIT_FUNCTION(wanpipe_wait)
-{
- int32_t inflags = 0;
- int result;
-
- if (*flags & ZAP_READ) {
- inflags |= POLLIN;
- }
-
- if (*flags & ZAP_WRITE) {
- inflags |= POLLOUT;
- }
-
- if (*flags & ZAP_EVENTS) {
- inflags |= POLLPRI;
- }
-
- result = tdmv_api_wait_socket(zchan, to, &inflags);
-
- *flags = ZAP_NO_FLAGS;
-
- if (result < 0){
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed");
- return ZAP_FAIL;
- }
-
- if (result == 0) {
- return ZAP_TIMEOUT;
- }
-
- if (inflags & POLLIN) {
- *flags |= ZAP_READ;
- }
-
- if (inflags & POLLOUT) {
- *flags |= ZAP_WRITE;
- }
-
- if (inflags & POLLPRI) {
- *flags |= ZAP_EVENTS;
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Checks for events on a Wanpipe span
- * \param span Span to check for events
- * \param ms Time to wait for event
- * \return Success if event is waiting or failure if not
- */
-ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event)
-{
-#ifdef LIBSANGOMA_VERSION
- sangoma_status_t sangstatus;
- sangoma_wait_obj_t *pfds[ZAP_MAX_CHANNELS_SPAN] = { 0 };
- uint32_t inflags[ZAP_MAX_CHANNELS_SPAN];
- uint32_t outflags[ZAP_MAX_CHANNELS_SPAN];
-#else
- struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN];
-#endif
-
- uint32_t i, j = 0, k = 0, l = 0;
- int r;
-
- for(i = 1; i <= span->chan_count; i++) {
- zap_channel_t *zchan = span->channels[i];
-
- if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == ZAP_TRUNK_T1 && zchan->physical_chan_id == 24) {
- continue;
- }
-
-#ifdef LIBSANGOMA_VERSION
- if (!zchan->mod_data) {
- continue; /* should never happen but happens when shutting down */
- }
- pfds[j] = zchan->mod_data;
- inflags[j] = POLLPRI;
-#else
- memset(&pfds[j], 0, sizeof(pfds[j]));
- pfds[j].fd = span->channels[i]->sockfd;
- pfds[j].events = POLLPRI;
-#endif
-
- /* The driver probably should be able to do this wink/flash/ringing by itself this is sort of a hack to make it work! */
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_WINK) || zap_test_flag(zchan, ZAP_CHANNEL_FLASH)) {
- l = 5;
- }
-
- j++;
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) {
- l = 5;
- }
-
- if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING) && zap_current_time_in_ms() >= zchan->ring_time) {
- wanpipe_tdm_api_t tdm_api;
- int err;
- memset(&tdm_api, 0, sizeof(tdm_api));
- if (zap_test_pflag(zchan, WP_RINGING)) {
- err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed");
- return ZAP_FAIL;
- }
- zap_clear_pflag_locked(zchan, WP_RINGING);
- zchan->ring_time = zap_current_time_in_ms() + wp_globals.ring_off_ms;
- } else {
- err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api);
- if (err) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed");
- return ZAP_FAIL;
- }
- zap_set_pflag_locked(zchan, WP_RINGING);
- zchan->ring_time = zap_current_time_in_ms() + wp_globals.ring_on_ms;
- }
- }
- }
-
- if (l) {
- ms = l;
- }
-#ifdef LIBSANGOMA_VERSION
- sangstatus = sangoma_waitfor_many(pfds, inflags, outflags, j, ms);
- if (SANG_STATUS_APIPOLL_TIMEOUT == sangstatus) {
- r = 0;
- } else if (SANG_STATUS_SUCCESS == sangstatus) {
- r = 1; /* hopefully we never need how many changed -_- */
- } else {
- r = -1;
- }
-#else
- r = poll(pfds, j, ms);
-#endif
-
- if (r == 0) {
- return l ? ZAP_SUCCESS : ZAP_TIMEOUT;
- } else if (r < 0) {
- snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- }
-
- for(i = 1; i <= span->chan_count; i++) {
- zap_channel_t *zchan = span->channels[i];
-
-#ifdef LIBSANGOMA_VERSION
- if (outflags[i-1] & POLLPRI) {
-#else
- if (pfds[i-1].revents & POLLPRI) {
-#endif
- zap_set_flag(zchan, ZAP_CHANNEL_EVENT);
- zchan->last_event_time = zap_current_time_in_ms();
- k++;
- }
- }
-
-
- return k ? ZAP_SUCCESS : ZAP_FAIL;
-}
-
-/**
- * \brief Gets alarms from a Wanpipe Channel
- * \param zchan Channel to get alarms from
- * \return Success or failure
- */
-static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms)
-{
- wanpipe_tdm_api_t tdm_api;
- unsigned int alarms = 0;
- int err;
-
- memset(&tdm_api,0,sizeof(tdm_api));
-
-#ifdef LIBSANGOMA_VERSION
- if ((err = sangoma_tdm_get_fe_alarms(zchan->sockfd, &tdm_api, &alarms))) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "ioctl failed (%s)", strerror(errno));
- snprintf(zchan->span->last_error, sizeof(zchan->span->last_error), "ioctl failed (%s)", strerror(errno));
- return ZAP_FAIL;
- }
-#else
- if ((err = sangoma_tdm_get_fe_alarms(zchan->sockfd, &tdm_api)) < 0){
- snprintf(zchan->last_error, sizeof(zchan->last_error), "ioctl failed (%s)", strerror(errno));
- snprintf(zchan->span->last_error, sizeof(zchan->span->last_error), "ioctl failed (%s)", strerror(errno));
- return ZAP_FAIL;
- }
- alarms = tdm_api.wp_tdm_cmd.fe_alarms;
-#endif
- zchan->alarm_flags = ZAP_ALARM_NONE;
-
- if (alarms & WAN_TE_BIT_ALARM_RED) {
- zchan->alarm_flags |= ZAP_ALARM_RED;
- alarms &= ~WAN_TE_BIT_ALARM_RED;
- }
-
- if (alarms & WAN_TE_BIT_ALARM_AIS) {
- zchan->alarm_flags |= ZAP_ALARM_AIS;
- zchan->alarm_flags |= ZAP_ALARM_BLUE;
- alarms &= ~WAN_TE_BIT_ALARM_AIS;
- }
-
- if (alarms & WAN_TE_BIT_ALARM_RAI) {
- zchan->alarm_flags |= ZAP_ALARM_RAI;
- zchan->alarm_flags |= ZAP_ALARM_YELLOW;
- alarms &= ~WAN_TE_BIT_ALARM_RAI;
- }
-
- /* still missing to map:
- * ZAP_ALARM_RECOVER
- * ZAP_ALARM_LOOPBACK
- * ZAP_ALARM_NOTOPEN
- * */
-
- /* if we still have alarms that we did not map, set the general alarm */
- if (alarms) {
- zap_log(ZAP_LOG_DEBUG, "Unmapped wanpipe alarms: %d\n", alarms);
- zchan->alarm_flags |= ZAP_ALARM_GENERAL;
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Retrieves an event from a wanpipe span
- * \param span Span to retrieve event from
- * \param event Openzap event to return
- * \return Success or failure
- */
-ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event)
-{
- uint32_t i,err;
- zap_oob_event_t event_id;
- for(i = 1; i <= span->chan_count; i++) {
- if (span->channels[i]->last_event_time && !zap_test_flag(span->channels[i], ZAP_CHANNEL_EVENT)) {
- uint32_t diff = (uint32_t)(zap_current_time_in_ms() - span->channels[i]->last_event_time);
- /* XX printf("%u %u %u\n", diff, (unsigned)zap_current_time_in_ms(), (unsigned)span->channels[i]->last_event_time); */
- if (zap_test_flag(span->channels[i], ZAP_CHANNEL_WINK)) {
- if (diff > wp_globals.wink_ms) {
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_WINK);
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH);
- zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_OFFHOOK);
- event_id = ZAP_OOB_OFFHOOK;
- goto event;
- }
- }
-
- if (zap_test_flag(span->channels[i], ZAP_CHANNEL_FLASH)) {
- if (diff > wp_globals.flash_ms) {
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH);
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_WINK);
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_OFFHOOK);
- event_id = ZAP_OOB_ONHOOK;
-
- if (span->channels[i]->type == ZAP_CHAN_TYPE_FXO) {
- zap_channel_t *zchan = span->channels[i];
- wanpipe_tdm_api_t tdm_api;
- memset(&tdm_api, 0, sizeof(tdm_api));
-
- sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api);
- }
- zap_log(ZAP_LOG_DEBUG, "%d:%d Returning fake ONHOOK\n", span->channels[i]->span_id, span->channels[i]->chan_id);
- goto event;
- }
- }
- }
- if (zap_test_flag(span->channels[i], ZAP_CHANNEL_EVENT)) {
- wanpipe_tdm_api_t tdm_api;
- zap_channel_t *zchan = span->channels[i];
- memset(&tdm_api, 0, sizeof(tdm_api));
- zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT);
-
- err = sangoma_tdm_read_event(zchan->sockfd, &tdm_api);
- if (err != ZAP_SUCCESS) {
- snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- }
-
- zap_log(ZAP_LOG_DEBUG, "%d:%d wanpipe returned event %d\n", span->channels[i]->span_id, span->channels[i]->chan_id, tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type);
- switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) {
-
- case WP_TDMAPI_EVENT_LINK_STATUS:
- {
- zap_sigmsg_t sigmsg;
- memset(&sigmsg, 0, sizeof(sigmsg));
- switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_link_status) {
- case WP_TDMAPI_EVENT_LINK_STATUS_CONNECTED:
- event_id = ZAP_OOB_ALARM_CLEAR;
- break;
- default:
- event_id = ZAP_OOB_ALARM_TRAP;
- break;
- };
- sigmsg.chan_id = zchan->chan_id;
- sigmsg.span_id = zchan->span_id;
- sigmsg.channel = zchan;
- sigmsg.event_id = (event_id == ZAP_OOB_ALARM_CLEAR) ? ZAP_SIGEVENT_ALARM_CLEAR : ZAP_SIGEVENT_ALARM_TRAP;
- zap_span_send_signal(zchan->span, &sigmsg);
- }
- break;
-
- case WP_TDMAPI_EVENT_RXHOOK:
- {
- zap_log(ZAP_LOG_DEBUG, "%d:%d rxhook, state %d\n", span->channels[i]->span_id, span->channels[i]->chan_id,
- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_hook_state);
- if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) {
- event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_hook_state & WP_TDMAPI_EVENT_RXHOOK_OFF ? ZAP_OOB_OFFHOOK : ZAP_OOB_ONHOOK;
- if (event_id == ZAP_OOB_OFFHOOK) {
- if (zap_test_flag(span->channels[i], ZAP_CHANNEL_FLASH)) {
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH);
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_WINK);
- event_id = ZAP_OOB_FLASH;
- goto event;
- } else {
- zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_WINK);
- }
- } else {
- if (zap_test_flag(span->channels[i], ZAP_CHANNEL_WINK)) {
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_WINK);
- zap_clear_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH);
- event_id = ZAP_OOB_WINK;
- goto event;
- } else {
- zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH);
- }
- }
- continue;
- } else {
- int err;
- zap_channel_t *zchan = span->channels[i];
- err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api);
- if (err) {
- snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "ONHOOK Failed");
- return ZAP_FAIL;
- }
- event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_hook_state & WP_TDMAPI_EVENT_RXHOOK_OFF ? ZAP_OOB_ONHOOK : ZAP_OOB_NOOP;
- }
- }
- break;
- case WP_TDMAPI_EVENT_RING_DETECT:
- {
- event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_ring_state == WP_TDMAPI_EVENT_RING_PRESENT ? ZAP_OOB_RING_START : ZAP_OOB_RING_STOP;
- }
- break;
- /*
- disabled this ones when configuring, we don't need them, do we?
- case WP_TDMAPI_EVENT_RING_TRIP_DETECT:
- {
- event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_ring_state == WP_TDMAPI_EVENT_RING_PRESENT ? ZAP_OOB_ONHOOK : ZAP_OOB_OFFHOOK;
- }
- break;
- */
- case WP_TDMAPI_EVENT_RBS:
- {
- event_id = ZAP_OOB_CAS_BITS_CHANGE;
- span->channels[i]->rx_cas_bits = wanpipe_swap_bits(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rbs_bits);
- }
- break;
- case WP_TDMAPI_EVENT_DTMF:
- {
- char tmp_dtmf[2] = { tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_digit, 0 };
- event_id = ZAP_OOB_NOOP;
-
- //zap_log(ZAP_LOG_WARNING, "%d:%d queue hardware dtmf %s %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf,
- //tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_PRESENT ? "on" : "off");
- if (tmp_dtmf[0] == 'f') {
- if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) {
- zap_channel_queue_dtmf(zchan, tmp_dtmf);
- }
- break;
- }
-
- if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_PRESENT) {
- zap_set_flag_locked(zchan, ZAP_CHANNEL_MUTE);
- }
-
- if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) {
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_MUTE);
- if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) {
- zap_channel_queue_dtmf(zchan, tmp_dtmf);
- }
- }
- }
- break;
- case WP_TDMAPI_EVENT_ALARM:
- {
- zap_sigmsg_t sigmsg;
- zap_log(ZAP_LOG_DEBUG, "Got wanpipe alarms %d\n", tdm_api.wp_tdm_cmd.event.wp_api_event_alarm);
- memset(&sigmsg, 0, sizeof(sigmsg));
- event_id = ZAP_OOB_ALARM_TRAP;
- sigmsg.chan_id = zchan->chan_id;
- sigmsg.span_id = zchan->span_id;
- sigmsg.channel = zchan;
- sigmsg.event_id = (event_id == ZAP_OOB_ALARM_CLEAR) ? ZAP_SIGEVENT_ALARM_CLEAR : ZAP_SIGEVENT_ALARM_TRAP;
- zap_span_send_signal(zchan->span, &sigmsg);
- }
- break;
- default:
- {
- zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type);
- event_id = ZAP_OOB_INVALID;
- }
- break;
- }
-
- event:
-
- span->channels[i]->last_event_time = 0;
- span->event_header.e_type = ZAP_EVENT_OOB;
- span->event_header.enum_id = event_id;
- span->event_header.channel = span->channels[i];
- *event = &span->event_header;
- return ZAP_SUCCESS;
- }
- }
-
- return ZAP_FAIL;
-
-}
-
-/**
- * \brief Destroys a Wanpipe Channel
- * \param zchan Channel to destroy
- * \return Success
- */
-static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy)
-{
-#ifdef LIBSANGOMA_VERSION
- if (zchan->mod_data) {
- sangoma_wait_obj_t *sangoma_wait_obj;
- sangoma_wait_obj = zchan->mod_data;
- zchan->mod_data = NULL;
- sangoma_wait_obj_delete(&sangoma_wait_obj);
- }
-#endif
- if (zchan->sockfd != ZAP_INVALID_SOCKET) {
- /* enable HW DTMF. As odd as it seems. Why enable when the channel is being destroyed and won't be used anymore?
- * because that way we can transfer the DTMF state back to the driver, if we're being restarted we will set again
- * the FEATURE_DTMF flag and use HW DTMF, if we don't enable here, then on module restart we won't see
- * HW DTMF available and will use software */
- if (zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) {
- wanpipe_tdm_api_t tdm_api;
- int err;
- memset(&tdm_api, 0, sizeof(tdm_api));
- err = sangoma_tdm_enable_dtmf_events(zchan->sockfd, &tdm_api);
- if (err) {
- zap_log(ZAP_LOG_WARNING, "Failed to enable Sangoma HW DTMF on channel %d:%d at destroy\n",
- zchan->span_id, zchan->chan_id);
- }
- }
- sangoma_close(&zchan->sockfd);
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Loads wanpipe IO module
- * \param zio Openzap IO interface
- * \return Success
- */
-static ZIO_IO_LOAD_FUNCTION(wanpipe_init)
-{
- assert(zio != NULL);
- memset(&wanpipe_interface, 0, sizeof(wanpipe_interface));
-
- wp_globals.codec_ms = 20;
- wp_globals.wink_ms = 150;
- wp_globals.flash_ms = 750;
- wp_globals.ring_on_ms = 2000;
- wp_globals.ring_off_ms = 4000;
- wanpipe_interface.name = "wanpipe";
- wanpipe_interface.configure_span = wanpipe_configure_span;
- wanpipe_interface.configure = wanpipe_configure;
- wanpipe_interface.open = wanpipe_open;
- wanpipe_interface.close = wanpipe_close;
- wanpipe_interface.command = wanpipe_command;
- wanpipe_interface.wait = wanpipe_wait;
- wanpipe_interface.read = wanpipe_read;
- wanpipe_interface.write = wanpipe_write;
- wanpipe_interface.poll_event = wanpipe_poll_event;
- wanpipe_interface.next_event = wanpipe_next_event;
- wanpipe_interface.channel_destroy = wanpipe_channel_destroy;
- wanpipe_interface.get_alarms = wanpipe_get_alarms;
- *zio = &wanpipe_interface;
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Unloads wanpipe IO module
- * \return Success
- */
-static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy)
-{
- memset(&wanpipe_interface, 0, sizeof(wanpipe_interface));
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Openzap wanpipe IO module definition
- */
-EX_DECLARE_DATA zap_module_t zap_module = {
- "wanpipe",
- wanpipe_init,
- wanpipe_destroy,
-};
-
-/* 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 noet
- */
diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h b/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h
deleted file mode 100644
index 3801ff9c8c..0000000000
--- a/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h
+++ /dev/null
@@ -1,351 +0,0 @@
-/*****************************************************************************
-* wanpipe_tdm_api_iface.h
-*
-* WANPIPE(tm) AFT TE1 Hardware Support
-*
-* Authors: Nenad Corbic
-*
-* Copyright (c) 2007 - 08, Sangoma Technologies
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * Neither the name of the nor the
-* names of its contributors may be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-* ============================================================================
-* Oct 04, 2005 Nenad Corbic Initial version.
-*
-* Jul 25, 2006 David Rokhvarg Ported to Windows.
-*****************************************************************************/
-
-#ifndef __WANPIPE_TDM_API_IFACE_H_
-#define __WANPIPE_TDM_API_IFACE_H_
-
-
-#if defined(__WINDOWS__)
-typedef HANDLE sng_fd_t;
-#else
-typedef int sng_fd_t;
-#endif
-
-/* Indicate to library that new features exist */
-#define WP_TDM_FEATURE_DTMF_EVENTS 1
-#define WP_TDM_FEATURE_FE_ALARM 1
-#define WP_TDM_FEATURE_EVENTS 1
-#define WP_TDM_FEATURE_LINK_STATUS 1
-
-enum wanpipe_tdm_api_cmds {
-
- SIOC_WP_TDM_GET_USR_MTU_MRU, /* 0x00 */
-
- SIOC_WP_TDM_SET_USR_PERIOD, /* 0x01 */
- SIOC_WP_TDM_GET_USR_PERIOD, /* 0x02 */
-
- SIOC_WP_TDM_SET_HW_MTU_MRU, /* 0x03 */
- SIOC_WP_TDM_GET_HW_MTU_MRU, /* 0x04 */
-
- SIOC_WP_TDM_SET_CODEC, /* 0x05 */
- SIOC_WP_TDM_GET_CODEC, /* 0x06 */
-
- SIOC_WP_TDM_SET_POWER_LEVEL, /* 0x07 */
- SIOC_WP_TDM_GET_POWER_LEVEL, /* 0x08 */
-
- SIOC_WP_TDM_TOGGLE_RX, /* 0x09 */
- SIOC_WP_TDM_TOGGLE_TX, /* 0x0A */
-
- SIOC_WP_TDM_GET_HW_CODING, /* 0x0B */
- SIOC_WP_TDM_SET_HW_CODING, /* 0x0C */
-
- SIOC_WP_TDM_GET_FULL_CFG, /* 0x0D */
-
- SIOC_WP_TDM_SET_EC_TAP, /* 0x0E */
- SIOC_WP_TDM_GET_EC_TAP, /* 0x0F */
-
- SIOC_WP_TDM_ENABLE_RBS_EVENTS, /* 0x10 */
- SIOC_WP_TDM_DISABLE_RBS_EVENTS, /* 0x11 */
- SIOC_WP_TDM_WRITE_RBS_BITS, /* 0x12 */
-
- SIOC_WP_TDM_GET_STATS, /* 0x13 */
- SIOC_WP_TDM_FLUSH_BUFFERS, /* 0x14 */
-
- SIOC_WP_TDM_READ_EVENT, /* 0x15 */
-
- SIOC_WP_TDM_SET_EVENT, /* 0x16 */
-
- SIOC_WP_TDM_SET_RX_GAINS, /* 0x17 */
- SIOC_WP_TDM_SET_TX_GAINS, /* 0x18 */
- SIOC_WP_TDM_CLEAR_RX_GAINS, /* 0x19 */
- SIOC_WP_TDM_CLEAR_TX_GAINS, /* 0x1A */
-
- SIOC_WP_TDM_GET_FE_ALARMS, /* 0x1B */
-
- SIOC_WP_TDM_ENABLE_HWEC, /* 0x1C */
- SIOC_WP_TDM_DISABLE_HWEC, /* 0x1D */
-
- SIOC_WP_TDM_SET_FE_STATUS, /* 0x1E */
- SIOC_WP_TDM_GET_FE_STATUS, /* 0x1F */
-
- SIOC_WP_TDM_GET_HW_DTMF, /* 0x20 */
-
- SIOC_WP_TDM_NOTSUPP /* */
-
-};
-
-#define SIOC_WP_TDM_GET_LINK_STATUS SIOC_WP_TDM_GET_FE_STATUS
-
-enum wanpipe_tdm_api_events {
- WP_TDMAPI_EVENT_NONE,
- WP_TDMAPI_EVENT_RBS,
- WP_TDMAPI_EVENT_ALARM,
- WP_TDMAPI_EVENT_DTMF,
- WP_TDMAPI_EVENT_RM_DTMF,
- WP_TDMAPI_EVENT_RXHOOK,
- WP_TDMAPI_EVENT_RING,
- WP_TDMAPI_EVENT_RING_DETECT,
- WP_TDMAPI_EVENT_RING_TRIP_DETECT,
- WP_TDMAPI_EVENT_TONE,
- WP_TDMAPI_EVENT_TXSIG_KEWL,
- WP_TDMAPI_EVENT_TXSIG_START,
- WP_TDMAPI_EVENT_TXSIG_OFFHOOK,
- WP_TDMAPI_EVENT_TXSIG_ONHOOK,
- WP_TDMAPI_EVENT_ONHOOKTRANSFER,
- WP_TDMAPI_EVENT_SETPOLARITY,
- WP_TDMAPI_EVENT_BRI_CHAN_LOOPBACK,
- WP_TDMAPI_EVENT_LINK_STATUS
-};
-
-#define WP_TDMAPI_EVENT_FE_ALARM WP_TDMAPI_EVENT_ALARM
-
-
-#define WP_TDMAPI_EVENT_ENABLE 0x01
-#define WP_TDMAPI_EVENT_DISABLE 0x02
-#define WP_TDMAPI_EVENT_MODE_DECODE(mode) \
- ((mode) == WP_TDMAPI_EVENT_ENABLE) ? "Enable" : \
- ((mode) == WP_TDMAPI_EVENT_DISABLE) ? "Disable" : \
- "(Unknown mode)"
-
-#define WPTDM_A_BIT WAN_RBS_SIG_A
-#define WPTDM_B_BIT WAN_RBS_SIG_B
-#define WPTDM_C_BIT WAN_RBS_SIG_C
-#define WPTDM_D_BIT WAN_RBS_SIG_D
-
-#define WP_TDMAPI_EVENT_RXHOOK_OFF 0x01
-#define WP_TDMAPI_EVENT_RXHOOK_ON 0x02
-#define WP_TDMAPI_EVENT_RXHOOK_DECODE(state) \
- ((state) == WP_TDMAPI_EVENT_RXHOOK_OFF) ? "Off-hook" : \
- ((state) == WP_TDMAPI_EVENT_RXHOOK_ON) ? "On-hook" : \
- "(Unknown state)"
-
-#define WP_TDMAPI_EVENT_RING_PRESENT 0x01
-#define WP_TDMAPI_EVENT_RING_STOP 0x02
-#define WP_TDMAPI_EVENT_RING_DECODE(state) \
- ((state) == WP_TDMAPI_EVENT_RING_PRESENT) ? "Ring Present" : \
- ((state) == WP_TDMAPI_EVENT_RING_STOP) ? "Ring Stop" : \
- "(Unknown state)"
-
-#define WP_TDMAPI_EVENT_RING_TRIP_PRESENT 0x01
-#define WP_TDMAPI_EVENT_RING_TRIP_STOP 0x02
-#define WP_TDMAPI_EVENT_RING_TRIP_DECODE(state) \
- ((state) == WP_TDMAPI_EVENT_RING_TRIP_PRESENT) ? "Ring Present" : \
- ((state) == WP_TDMAPI_EVENT_RING_TRIP_STOP) ? "Ring Stop" : \
- "(Unknown state)"
-/*Link Status */
-#define WP_TDMAPI_EVENT_LINK_STATUS_CONNECTED 0x01
-#define WP_TDMAPI_EVENT_LINK_STATUS_DISCONNECTED 0x02
-#define WP_TDMAPI_EVENT_LINK_STATUS_DECODE(status) \
- ((status) == WP_TDMAPI_EVENT_LINK_STATUS_CONNECTED) ? "Connected" : \
- ((status) == WP_TDMAPI_EVENT_LINK_STATUS_DISCONNECTED) ? "Disconnected" : \
- "Unknown"
-#define WP_TDMAPI_EVENT_TONE_DIAL 0x01
-#define WP_TDMAPI_EVENT_TONE_BUSY 0x02
-#define WP_TDMAPI_EVENT_TONE_RING 0x03
-#define WP_TDMAPI_EVENT_TONE_CONGESTION 0x04
-
-/* BRI channels list */
-#define WAN_BRI_BCHAN1 0x01
-#define WAN_BRI_BCHAN2 0x02
-#define WAN_BRI_DCHAN 0x03
-
-
-typedef struct {
-
- u_int8_t type;
- u_int8_t mode;
- u_int32_t time_stamp;
- u_int8_t channel;
- u_int32_t chan_map;
- u_int8_t span;
- union {
- struct {
- u_int8_t alarm;
- } te1_alarm;
- struct {
- u_int8_t rbs_bits;
- } te1_rbs;
- struct {
- u_int8_t state;
- u_int8_t sig;
- } rm_hook;
- struct {
- u_int8_t state;
- } rm_ring;
- struct {
- u_int8_t type;
- } rm_tone;
- struct {
- u_int8_t digit; /* DTMF: digit */
- u_int8_t port; /* DTMF: SOUT/ROUT */
- u_int8_t type; /* DTMF: PRESET/STOP */
- } dtmf;
- struct {
- u_int16_t polarity;
- u_int16_t ohttimer;
- } rm_common;
- struct{
- u_int16_t status;
- } linkstatus;
- } wp_tdm_api_event_u;
-#define wp_tdm_api_event_type type
-#define wp_tdm_api_event_mode mode
-#define wp_tdm_api_event_alarm wp_tdm_api_event_u.te1_alarm.alarm
-#define wp_tdm_api_event_alarm wp_tdm_api_event_u.te1_alarm.alarm
-#define wp_tdm_api_event_rbs_bits wp_tdm_api_event_u.te1_rbs.rbs_bits
-#define wp_tdm_api_event_hook_state wp_tdm_api_event_u.rm_hook.state
-#define wp_tdm_api_event_hook_sig wp_tdm_api_event_u.rm_hook.sig
-#define wp_tdm_api_event_ring_state wp_tdm_api_event_u.rm_ring.state
-#define wp_tdm_api_event_tone_type wp_tdm_api_event_u.rm_tone.type
-#define wp_tdm_api_event_dtmf_digit wp_tdm_api_event_u.dtmf.digit
-#define wp_tdm_api_event_dtmf_type wp_tdm_api_event_u.dtmf.type
-#define wp_tdm_api_event_dtmf_port wp_tdm_api_event_u.dtmf.port
-#define wp_tdm_api_event_ohttimer wp_tdm_api_event_u.rm_common.ohttimer
-#define wp_tdm_api_event_polarity wp_tdm_api_event_u.rm_common.polarity
-#define wp_tdm_api_event_link_status wp_tdm_api_event_u.linkstatus.status
-} wp_tdm_api_event_t;
-
-typedef struct {
- union {
- unsigned char reserved[16];
- }wp_rx_hdr_u;
-} 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;
-
-
-
-typedef struct wp_tdm_chan_stats
-{
- unsigned int rx_packets; /* total packets received */
- unsigned int tx_packets; /* total packets transmitted */
- unsigned int rx_bytes; /* total bytes received */
- unsigned int tx_bytes; /* total bytes transmitted */
- unsigned int rx_errors; /* bad packets received */
- unsigned int tx_errors; /* packet transmit problems */
- unsigned int rx_dropped; /* no space in linux buffers */
- unsigned int tx_dropped; /* no space available in linux */
- unsigned int multicast; /* multicast packets received */
-#if !defined(__WINDOWS__)
- unsigned int collisions;
-#endif
- /* detailed rx_errors: */
- unsigned int rx_length_errors;
- unsigned int rx_over_errors; /* receiver ring buff overflow */
- unsigned int rx_crc_errors; /* recved pkt with crc error */
- unsigned int rx_frame_errors; /* recv'd frame alignment error */
-#if !defined(__WINDOWS__)
- unsigned int rx_fifo_errors; /* recv'r fifo overrun */
-#endif
- unsigned int rx_missed_errors; /* receiver missed packet */
-
- /* detailed tx_errors */
-#if !defined(__WINDOWS__)
- unsigned int tx_aborted_errors;
- unsigned int tx_carrier_errors;
-#endif
- unsigned int tx_fifo_errors;
- unsigned int tx_heartbeat_errors;
- unsigned int tx_window_errors;
-
-}wp_tdm_chan_stats_t;
-
-
-
-typedef struct wanpipe_tdm_api_cmd{
- unsigned int cmd;
- unsigned int hw_tdm_coding; /* Set/Get HW TDM coding: uLaw muLaw */
- unsigned int hw_mtu_mru; /* Set/Get HW TDM MTU/MRU */
- unsigned int usr_period; /* Set/Get User Period in ms */
- unsigned int tdm_codec; /* Set/Get TDM Codec: SLinear */
- unsigned int power_level; /* Set/Get Power level treshold */
- unsigned int rx_disable; /* Enable/Disable Rx */
- unsigned int tx_disable; /* Enable/Disable Tx */
- unsigned int usr_mtu_mru; /* Set/Get User TDM MTU/MRU */
- unsigned int ec_tap; /* Echo Cancellation Tap */
- unsigned int rbs_poll; /* Enable/Disable RBS Polling */
- unsigned int rbs_rx_bits; /* Rx RBS Bits */
- unsigned int rbs_tx_bits; /* Tx RBS Bits */
- unsigned int hdlc; /* HDLC based device */
- unsigned int idle_flag; /* IDLE flag to Tx */
- unsigned int fe_alarms; /* FE Alarms detected */
- wp_tdm_chan_stats_t stats; /* TDM Statistics */
- /* Do NOT add anything above this! Important for binary backward compatibility. */
- wp_tdm_api_event_t event; /* TDM Event */
- unsigned int data_len;
- void *data;
- unsigned char fe_status; /* FE status - Connected or Disconnected */
- unsigned int hw_dtmf; /* HW DTMF enabled */
-}wanpipe_tdm_api_cmd_t;
-
-typedef struct wanpipe_tdm_api_event{
- int (*wp_rbs_event)(sng_fd_t fd, unsigned char rbs_bits);
- int (*wp_dtmf_event)(sng_fd_t fd, unsigned char dtmf, unsigned char type, unsigned char port);
- int (*wp_rxhook_event)(sng_fd_t fd, unsigned char hook_state);
- int (*wp_ring_detect_event)(sng_fd_t fd, unsigned char ring_state);
- int (*wp_ring_trip_detect_event)(sng_fd_t fd, unsigned char ring_state);
- int (*wp_fe_alarm_event)(sng_fd_t fd, unsigned char fe_alarm_event);
- int (*wp_link_status_event)(sng_fd_t fd, unsigned char link_status_event);
-}wanpipe_tdm_api_event_t;
-
-typedef struct wanpipe_tdm_api{
- wanpipe_tdm_api_cmd_t wp_tdm_cmd;
- wanpipe_tdm_api_event_t wp_tdm_event;
-}wanpipe_tdm_api_t;
-
-
-#endif
diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c
deleted file mode 100644
index a6017529c8..0000000000
--- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c
+++ /dev/null
@@ -1,1253 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "openzap.h"
-#include "ozmod_zt.h"
-
-/**
- * \brief Zaptel globals
- */
-static struct {
- uint32_t codec_ms;
- uint32_t wink_ms;
- uint32_t flash_ms;
- uint32_t eclevel;
- uint32_t etlevel;
- float rxgain;
- float txgain;
-} zt_globals;
-
-/**
- * \brief General IOCTL codes
- */
-struct ioctl_codes {
- int GET_BLOCKSIZE;
- int SET_BLOCKSIZE;
- int FLUSH;
- int SYNC;
- int GET_PARAMS;
- int SET_PARAMS;
- int HOOK;
- int GETEVENT;
- int IOMUX;
- int SPANSTAT;
- int MAINT;
- int GETCONF;
- int SETCONF;
- int CONFLINK;
- int CONFDIAG;
- int GETGAINS;
- int SETGAINS;
- int SPANCONFIG;
- int CHANCONFIG;
- int SET_BUFINFO;
- int GET_BUFINFO;
- int AUDIOMODE;
- int ECHOCANCEL;
- int HDLCRAWMODE;
- int HDLCFCSMODE;
- int SPECIFY;
- int SETLAW;
- int SETLINEAR;
- int GETCONFMUTE;
- int ECHOTRAIN;
- int SETTXBITS;
- int GETRXBITS;
-};
-
-/**
- * \brief Zaptel IOCTL codes
- */
-static struct ioctl_codes zt_ioctl_codes = {
- .GET_BLOCKSIZE = ZT_GET_BLOCKSIZE,
- .SET_BLOCKSIZE = ZT_SET_BLOCKSIZE,
- .FLUSH = ZT_FLUSH,
- .SYNC = ZT_SYNC,
- .GET_PARAMS = ZT_GET_PARAMS,
- .SET_PARAMS = ZT_SET_PARAMS,
- .HOOK = ZT_HOOK,
- .GETEVENT = ZT_GETEVENT,
- .IOMUX = ZT_IOMUX,
- .SPANSTAT = ZT_SPANSTAT,
- .MAINT = ZT_MAINT,
- .GETCONF = ZT_GETCONF,
- .SETCONF = ZT_SETCONF,
- .CONFLINK = ZT_CONFLINK,
- .CONFDIAG = ZT_CONFDIAG,
- .GETGAINS = ZT_GETGAINS,
- .SETGAINS = ZT_SETGAINS,
- .SPANCONFIG = ZT_SPANCONFIG,
- .CHANCONFIG = ZT_CHANCONFIG,
- .SET_BUFINFO = ZT_SET_BUFINFO,
- .GET_BUFINFO = ZT_GET_BUFINFO,
- .AUDIOMODE = ZT_AUDIOMODE,
- .ECHOCANCEL = ZT_ECHOCANCEL,
- .HDLCRAWMODE = ZT_HDLCRAWMODE,
- .HDLCFCSMODE = ZT_HDLCFCSMODE,
- .SPECIFY = ZT_SPECIFY,
- .SETLAW = ZT_SETLAW,
- .SETLINEAR = ZT_SETLINEAR,
- .GETCONFMUTE = ZT_GETCONFMUTE,
- .ECHOTRAIN = ZT_ECHOTRAIN,
- .SETTXBITS = ZT_SETTXBITS,
- .GETRXBITS = ZT_GETRXBITS
-};
-
-/**
- * \brief Dahdi IOCTL codes
- */
-static struct ioctl_codes dahdi_ioctl_codes = {
- .GET_BLOCKSIZE = DAHDI_GET_BLOCKSIZE,
- .SET_BLOCKSIZE = DAHDI_SET_BLOCKSIZE,
- .FLUSH = DAHDI_FLUSH,
- .SYNC = DAHDI_SYNC,
- .GET_PARAMS = DAHDI_GET_PARAMS,
- .SET_PARAMS = DAHDI_SET_PARAMS,
- .HOOK = DAHDI_HOOK,
- .GETEVENT = DAHDI_GETEVENT,
- .IOMUX = DAHDI_IOMUX,
- .SPANSTAT = DAHDI_SPANSTAT,
- .MAINT = DAHDI_MAINT,
- .GETCONF = DAHDI_GETCONF,
- .SETCONF = DAHDI_SETCONF,
- .CONFLINK = DAHDI_CONFLINK,
- .CONFDIAG = DAHDI_CONFDIAG,
- .GETGAINS = DAHDI_GETGAINS,
- .SETGAINS = DAHDI_SETGAINS,
- .SPANCONFIG = DAHDI_SPANCONFIG,
- .CHANCONFIG = DAHDI_CHANCONFIG,
- .SET_BUFINFO = DAHDI_SET_BUFINFO,
- .GET_BUFINFO = DAHDI_GET_BUFINFO,
- .AUDIOMODE = DAHDI_AUDIOMODE,
- .ECHOCANCEL = DAHDI_ECHOCANCEL,
- .HDLCRAWMODE = DAHDI_HDLCRAWMODE,
- .HDLCFCSMODE = DAHDI_HDLCFCSMODE,
- .SPECIFY = DAHDI_SPECIFY,
- .SETLAW = DAHDI_SETLAW,
- .SETLINEAR = DAHDI_SETLINEAR,
- .GETCONFMUTE = DAHDI_GETCONFMUTE,
- .ECHOTRAIN = DAHDI_ECHOTRAIN,
- .SETTXBITS = DAHDI_SETTXBITS,
- .GETRXBITS = DAHDI_GETRXBITS
-};
-
-#define ZT_INVALID_SOCKET -1
-static struct ioctl_codes codes;
-static const char *ctlpath = NULL;
-static const char *chanpath = NULL;
-
-static const char dahdi_ctlpath[] = "/dev/dahdi/ctl";
-static const char dahdi_chanpath[] = "/dev/dahdi/channel";
-
-static const char zt_ctlpath[] = "/dev/zap/ctl";
-static const char zt_chanpath[] = "/dev/zap/channel";
-
-static zap_socket_t CONTROL_FD = ZT_INVALID_SOCKET;
-
-ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event);
-ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event);
-
-/**
- * \brief Initialises codec, and rx/tx gains
- * \param g Structure for gains to be initialised
- * \param rxgain RX gain value
- * \param txgain TX gain value
- * \param codec Codec
- */
-static void zt_build_gains(struct zt_gains *g, float rxgain, float txgain, int codec)
-{
- int j;
- int k;
- float linear_rxgain = pow(10.0, rxgain / 20.0);
- float linear_txgain = pow(10.0, txgain / 20.0);
-
- switch (codec) {
- case ZAP_CODEC_ALAW:
- for (j = 0; j < (sizeof(g->receive_gain) / sizeof(g->receive_gain[0])); j++) {
- if (rxgain) {
- k = (int) (((float) alaw_to_linear(j)) * linear_rxgain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->receive_gain[j] = linear_to_alaw(k);
- } else {
- g->receive_gain[j] = j;
- }
- if (txgain) {
- k = (int) (((float) alaw_to_linear(j)) * linear_txgain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->transmit_gain[j] = linear_to_alaw(k);
- } else {
- g->transmit_gain[j] = j;
- }
- }
- break;
- case ZAP_CODEC_ULAW:
- for (j = 0; j < (sizeof(g->receive_gain) / sizeof(g->receive_gain[0])); j++) {
- if (rxgain) {
- k = (int) (((float) ulaw_to_linear(j)) * linear_rxgain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->receive_gain[j] = linear_to_ulaw(k);
- } else {
- g->receive_gain[j] = j;
- }
- if (txgain) {
- k = (int) (((float) ulaw_to_linear(j)) * linear_txgain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->transmit_gain[j] = linear_to_ulaw(k);
- } else {
- g->transmit_gain[j] = j;
- }
- }
- break;
- }
-}
-
-/**
- * \brief Initialises a range of zaptel channels
- * \param span Openzap span
- * \param start Initial wanpipe channel number
- * \param end Final wanpipe channel number
- * \param type Openzap channel type
- * \param name Openzap span name
- * \param number Openzap span number
- * \param cas_bits CAS bits
- * \return number of spans configured
- */
-static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number, unsigned char cas_bits)
-{
- unsigned configured = 0, x;
- zt_params_t ztp;
-
- memset(&ztp, 0, sizeof(ztp));
-
- if (type == ZAP_CHAN_TYPE_CAS) {
- zap_log(ZAP_LOG_DEBUG, "Configuring CAS channels with abcd == 0x%X\n", cas_bits);
- }
- for(x = start; x < end; x++) {
- zap_channel_t *zchan;
- zap_socket_t sockfd = ZT_INVALID_SOCKET;
- int len;
-
- sockfd = open(chanpath, O_RDWR);
- if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) {
-
- if (ioctl(sockfd, codes.SPECIFY, &x)) {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", chanpath, x, sockfd, strerror(errno));
- close(sockfd);
- continue;
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
- struct zt_bufferinfo binfo;
- memset(&binfo, 0, sizeof(binfo));
- binfo.txbufpolicy = 0;
- binfo.rxbufpolicy = 0;
- binfo.numbufs = 32;
- binfo.bufsize = 1024;
- if (ioctl(sockfd, codes.SET_BUFINFO, &binfo)) {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", chanpath, zchan->span_id, zchan->chan_id, sockfd);
- close(sockfd);
- continue;
- }
- }
-
- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) {
- struct zt_chanconfig cc;
- memset(&cc, 0, sizeof(cc));
- cc.chan = cc.master = x;
-
- switch(type) {
- case ZAP_CHAN_TYPE_FXS:
- {
- switch(span->start_type) {
- case ZAP_ANALOG_START_KEWL:
- cc.sigtype = ZT_SIG_FXOKS;
- break;
- case ZAP_ANALOG_START_LOOP:
- cc.sigtype = ZT_SIG_FXOLS;
- break;
- case ZAP_ANALOG_START_GROUND:
- cc.sigtype = ZT_SIG_FXOGS;
- break;
- default:
- break;
- }
- }
- break;
- case ZAP_CHAN_TYPE_FXO:
- {
- switch(span->start_type) {
- case ZAP_ANALOG_START_KEWL:
- cc.sigtype = ZT_SIG_FXSKS;
- break;
- case ZAP_ANALOG_START_LOOP:
- cc.sigtype = ZT_SIG_FXSLS;
- break;
- case ZAP_ANALOG_START_GROUND:
- cc.sigtype = ZT_SIG_FXSGS;
- break;
- default:
- break;
- }
- }
- break;
- default:
- break;
- }
-
- if (ioctl(CONTROL_FD, codes.CHANCONFIG, &cc)) {
- zap_log(ZAP_LOG_WARNING, "this ioctl fails on older zaptel but is harmless if you used ztcfg\n[device %s chan %d fd %d (%s)]\n", chanpath, x, CONTROL_FD, strerror(errno));
- }
- }
-
- if (type == ZAP_CHAN_TYPE_CAS) {
- struct zt_chanconfig cc;
- memset(&cc, 0, sizeof(cc));
- cc.chan = cc.master = x;
- cc.sigtype = ZT_SIG_CAS;
- cc.idlebits = cas_bits;
- if (ioctl(CONTROL_FD, codes.CHANCONFIG, &cc)) {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s", chanpath, zchan->span_id, zchan->chan_id, sockfd, strerror(errno));
- close(sockfd);
- continue;
- }
- }
-
- if (zchan->type != ZAP_CHAN_TYPE_DQ921 && zchan->type != ZAP_CHAN_TYPE_DQ931) {
- len = zt_globals.codec_ms * 8;
- if (ioctl(zchan->sockfd, codes.SET_BLOCKSIZE, &len)) {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n",
- chanpath, zchan->span_id, zchan->chan_id, sockfd, strerror(errno));
- close(sockfd);
- continue;
- }
-
- zchan->packet_len = len;
- zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8;
-
- if (zchan->effective_codec == ZAP_CODEC_SLIN) {
- zchan->packet_len *= 2;
- }
- }
-
- if (ioctl(sockfd, codes.GET_PARAMS, &ztp) < 0) {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", chanpath, zchan->span_id, zchan->chan_id, sockfd);
- close(sockfd);
- continue;
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
- if (
- (ztp.sig_type != ZT_SIG_HDLCRAW) &&
- (ztp.sig_type != ZT_SIG_HDLCFCS) &&
- (ztp.sig_type != ZT_SIG_HARDHDLC)
- ) {
- zap_log(ZAP_LOG_ERROR, "Failure configuring device %s as OpenZAP device %d:%d fd:%d, hardware signaling is not HDLC, fix your Zap/DAHDI configuration!\n", chanpath, zchan->span_id, zchan->chan_id, sockfd);
- close(sockfd);
- continue;
- }
- }
-
- zap_log(ZAP_LOG_INFO, "configuring device %s channel %d as OpenZAP device %d:%d fd:%d\n", chanpath, x, zchan->span_id, zchan->chan_id, sockfd);
-
- zchan->rate = 8000;
- zchan->physical_span_id = ztp.span_no;
- zchan->physical_chan_id = ztp.chan_no;
-
- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_EM || type == ZAP_CHAN_TYPE_B) {
- if (ztp.g711_type == ZT_G711_ALAW) {
- zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW;
- } else if (ztp.g711_type == ZT_G711_MULAW) {
- zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW;
- } else {
- int type;
-
- if (zchan->span->trunk_type == ZAP_TRUNK_E1) {
- type = ZAP_CODEC_ALAW;
- } else {
- type = ZAP_CODEC_ULAW;
- }
-
- zchan->native_codec = zchan->effective_codec = type;
-
- }
- }
-
- ztp.wink_time = zt_globals.wink_ms;
- ztp.flash_time = zt_globals.flash_ms;
-
- if (ioctl(sockfd, codes.SET_PARAMS, &ztp) < 0) {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", chanpath, zchan->span_id, zchan->chan_id, sockfd);
- close(sockfd);
- continue;
- }
-
- if (!zap_strlen_zero(name)) {
- zap_copy_string(zchan->chan_name, name, sizeof(zchan->chan_name));
- }
- if (!zap_strlen_zero(number)) {
- zap_copy_string(zchan->chan_number, number, sizeof(zchan->chan_number));
- }
- configured++;
- } else {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", chanpath);
- }
- }
-
-
-
- return configured;
-}
-
-/**
- * \brief Initialises an openzap zaptel span from a configuration string
- * \param span Openzap span
- * \param str Configuration string
- * \param type Openzap span type
- * \param name Openzap span name
- * \param number Openzap span number
- * \return Success or failure
- */
-static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span)
-{
-
- int items, i;
- char *mydata, *item_list[10];
- char *ch, *mx;
- unsigned char cas_bits = 0;
- int channo;
- int top = 0;
- unsigned configured = 0;
-
- assert(str != NULL);
-
-
- mydata = strdup(str);
- assert(mydata != NULL);
-
-
- items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0])));
-
- for(i = 0; i < items; i++) {
- ch = item_list[i];
-
- if (!(ch)) {
- zap_log(ZAP_LOG_ERROR, "Invalid input\n");
- continue;
- }
-
- channo = atoi(ch);
-
- if (channo < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid channel number %d\n", channo);
- continue;
- }
-
- if ((mx = strchr(ch, '-'))) {
- mx++;
- top = atoi(mx) + 1;
- } else {
- top = channo + 1;
- }
-
-
- if (top < 0) {
- zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top);
- continue;
- }
- if (ZAP_CHAN_TYPE_CAS == type && zap_config_get_cas_bits(ch, &cas_bits)) {
- zap_log(ZAP_LOG_ERROR, "Failed to get CAS bits in CAS channel\n");
- continue;
- }
- configured += zt_open_range(span, channo, top, type, name, number, cas_bits);
-
- }
-
- free(mydata);
-
- return configured;
-
-}
-
-/**
- * \brief Process configuration variable for a zaptel profile
- * \param category Wanpipe profile name
- * \param var Variable name
- * \param val Variable value
- * \param lineno Line number from configuration file
- * \return Success
- */
-static ZIO_CONFIGURE_FUNCTION(zt_configure)
-{
-
- int num;
- float fnum;
-
- if (!strcasecmp(category, "defaults")) {
- if (!strcasecmp(var, "codec_ms")) {
- num = atoi(val);
- if (num < 10 || num > 60) {
- zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", lineno);
- } else {
- zt_globals.codec_ms = num;
- }
- } else if (!strcasecmp(var, "wink_ms")) {
- num = atoi(val);
- if (num < 50 || num > 3000) {
- zap_log(ZAP_LOG_WARNING, "invalid wink ms at line %d\n", lineno);
- } else {
- zt_globals.wink_ms = num;
- }
- } else if (!strcasecmp(var, "flash_ms")) {
- num = atoi(val);
- if (num < 50 || num > 3000) {
- zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno);
- } else {
- zt_globals.flash_ms = num;
- }
- } else if (!strcasecmp(var, "echo_cancel_level")) {
- num = atoi(val);
- if (num < 0 || num > 256) {
- zap_log(ZAP_LOG_WARNING, "invalid echo can val at line %d\n", lineno);
- } else {
- zt_globals.eclevel = num;
- }
- } else if (!strcasecmp(var, "echo_train_level")) {
- if (zt_globals.eclevel < 1) {
- zap_log(ZAP_LOG_WARNING, "can't set echo train level without setting echo cancel level first at line %d\n", lineno);
- } else {
- num = atoi(val);
- if (num < 0 || num > 256) {
- zap_log(ZAP_LOG_WARNING, "invalid echo can val at line %d\n", lineno);
- } else {
- zt_globals.etlevel = num;
- }
- }
- } else if (!strcasecmp(var, "rxgain")) {
- fnum = (float)atof(val);
- if (fnum < -100.0 || fnum > 100.0) {
- zap_log(ZAP_LOG_WARNING, "invalid rxgain val at line %d\n", lineno);
- } else {
- zt_globals.rxgain = fnum;
- zap_log(ZAP_LOG_INFO, "Setting rxgain val to %f\n", fnum);
- }
-
- } else if (!strcasecmp(var, "txgain")) {
- fnum = (float)atof(val);
- if (fnum < -100.0 || fnum > 100.0) {
- zap_log(ZAP_LOG_WARNING, "invalid txgain val at line %d\n", lineno);
- } else {
- zt_globals.txgain = fnum;
- zap_log(ZAP_LOG_INFO, "Setting txgain val to %f\n", fnum);
- }
-
- }
- }
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Opens a zaptel channel
- * \param zchan Channel to open
- * \return Success or failure
- */
-static ZIO_OPEN_FUNCTION(zt_open)
-{
- zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL);
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) {
- zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE;
- } else {
- int blocksize = zt_globals.codec_ms * (zchan->rate / 1000);
- int err;
- if ((err = ioctl(zchan->sockfd, codes.SET_BLOCKSIZE, &blocksize))) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- } else {
- zchan->effective_interval = zchan->native_interval;
- zchan->packet_len = blocksize;
- zchan->native_codec = zchan->effective_codec;
- }
-
- if (zchan->type == ZAP_CHAN_TYPE_B) {
- int one = 1;
- if (ioctl(zchan->sockfd, codes.AUDIOMODE, &one)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
- zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error);
- return ZAP_FAIL;
- }
- }
-
- if (zt_globals.rxgain || zt_globals.txgain) {
- struct zt_gains gains;
- memset(&gains, 0, sizeof(gains));
-
- gains.chan_no = zchan->physical_chan_id;
- zt_build_gains(&gains, zt_globals.rxgain, zt_globals.txgain, zchan->native_codec);
-
- if(zt_globals.rxgain)
- zap_log(ZAP_LOG_INFO, "Setting rxgain to %f on channel %d\n", zt_globals.rxgain, gains.chan_no);
-
- if(zt_globals.txgain)
- zap_log(ZAP_LOG_INFO, "Setting txgain to %f on channel %d\n", zt_globals.txgain, gains.chan_no);
-
- if (ioctl(zchan->sockfd, codes.SETGAINS, &gains) < 0) {
- zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", chanpath, zchan->span_id, zchan->chan_id, zchan->sockfd);
- }
- }
-
- if (zt_globals.eclevel >= 0) {
- int len = zt_globals.eclevel;
-
- if (len) {
- zap_log(ZAP_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, zchan->span_id, zchan->chan_id);
- } else {
- zap_log(ZAP_LOG_INFO, "Disable echo cancel for %d:%d\n", zchan->span_id, zchan->chan_id);
- }
-
- if (ioctl(zchan->sockfd, codes.ECHOCANCEL, &len)) {
- zap_log(ZAP_LOG_WARNING, "Echo cancel not available for %d:%d\n", zchan->span_id, zchan->chan_id);
- } else if (zt_globals.etlevel > 0) {
- len = zt_globals.etlevel;
- if (ioctl(zchan->sockfd, codes.ECHOTRAIN, &len)) {
- zap_log(ZAP_LOG_WARNING, "Echo training not available for %d:%d\n", zchan->span_id, zchan->chan_id);
- }
- }
- }
-
- }
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Closes zaptel channel
- * \param zchan Channel to close
- * \return Success
- */
-static ZIO_CLOSE_FUNCTION(zt_close)
-{
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Executes an Openzap command on a zaptel channel
- * \param zchan Channel to execute command on
- * \param command Openzap command to execute
- * \param obj Object (unused)
- * \return Success or failure
- */
-static ZIO_COMMAND_FUNCTION(zt_command)
-{
- zt_params_t ztp;
- int err = 0;
-
- memset(&ztp, 0, sizeof(ztp));
-
- switch(command) {
- case ZAP_COMMAND_ENABLE_ECHOCANCEL:
- {
- int level = ZAP_COMMAND_OBJ_INT;
- err = ioctl(zchan->sockfd, codes.ECHOCANCEL, &level);
- ZAP_COMMAND_OBJ_INT = level;
- }
- case ZAP_COMMAND_DISABLE_ECHOCANCEL:
- {
- int level = 0;
- err = ioctl(zchan->sockfd, codes.ECHOCANCEL, &level);
- ZAP_COMMAND_OBJ_INT = level;
- }
- break;
- case ZAP_COMMAND_ENABLE_ECHOTRAIN:
- {
- int level = ZAP_COMMAND_OBJ_INT;
- err = ioctl(zchan->sockfd, codes.ECHOTRAIN, &level);
- ZAP_COMMAND_OBJ_INT = level;
- }
- case ZAP_COMMAND_DISABLE_ECHOTRAIN:
- {
- int level = 0;
- err = ioctl(zchan->sockfd, codes.ECHOTRAIN, &level);
- ZAP_COMMAND_OBJ_INT = level;
- }
- break;
- case ZAP_COMMAND_OFFHOOK:
- {
- int command = ZT_OFFHOOK;
- if (ioctl(zchan->sockfd, codes.HOOK, &command)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed");
- return ZAP_FAIL;
- }
- zap_set_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK);
- }
- break;
- case ZAP_COMMAND_ONHOOK:
- {
- int command = ZT_ONHOOK;
- if (ioctl(zchan->sockfd, codes.HOOK, &command)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed");
- return ZAP_FAIL;
- }
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK);
- }
- break;
- case ZAP_COMMAND_FLASH:
- {
- int command = ZT_FLASH;
- if (ioctl(zchan->sockfd, codes.HOOK, &command)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "FLASH Failed");
- return ZAP_FAIL;
- }
- }
- break;
- case ZAP_COMMAND_WINK:
- {
- int command = ZT_WINK;
- if (ioctl(zchan->sockfd, codes.HOOK, &command)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "WINK Failed");
- return ZAP_FAIL;
- }
- }
- break;
- case ZAP_COMMAND_GENERATE_RING_ON:
- {
- int command = ZT_RING;
- if (ioctl(zchan->sockfd, codes.HOOK, &command)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed");
- return ZAP_FAIL;
- }
- zap_set_flag_locked(zchan, ZAP_CHANNEL_RINGING);
- }
- break;
- case ZAP_COMMAND_GENERATE_RING_OFF:
- {
- int command = ZT_RINGOFF;
- if (ioctl(zchan->sockfd, codes.HOOK, &command)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off failed");
- return ZAP_FAIL;
- }
- zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING);
- }
- break;
- case ZAP_COMMAND_GET_INTERVAL:
- {
-
- if (!(err = ioctl(zchan->sockfd, codes.GET_BLOCKSIZE, &zchan->packet_len))) {
- zchan->native_interval = zchan->packet_len / 8;
- if (zchan->effective_codec == ZAP_CODEC_SLIN) {
- zchan->packet_len *= 2;
- }
- ZAP_COMMAND_OBJ_INT = zchan->native_interval;
- }
- }
- break;
- case ZAP_COMMAND_SET_INTERVAL:
- {
- int interval = ZAP_COMMAND_OBJ_INT;
- int len = interval * 8;
-
- if (!(err = ioctl(zchan->sockfd, codes.SET_BLOCKSIZE, &len))) {
- zchan->packet_len = len;
- zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8;
-
- if (zchan->effective_codec == ZAP_CODEC_SLIN) {
- zchan->packet_len *= 2;
- }
- }
- }
- break;
- case ZAP_COMMAND_SET_CAS_BITS:
- {
- int bits = ZAP_COMMAND_OBJ_INT;
- err = ioctl(zchan->sockfd, codes.SETTXBITS, &bits);
- }
- break;
- case ZAP_COMMAND_GET_CAS_BITS:
- {
- err = ioctl(zchan->sockfd, codes.GETRXBITS, &zchan->rx_cas_bits);
- if (!err) {
- ZAP_COMMAND_OBJ_INT = zchan->rx_cas_bits;
- }
- }
- break;
- case ZAP_COMMAND_FLUSH_TX_BUFFERS:
- {
- int flushmode = ZT_FLUSH_WRITE;
- err = ioctl(zchan->sockfd, codes.FLUSH, &flushmode);
- }
- break;
- case ZAP_COMMAND_FLUSH_RX_BUFFERS:
- {
- int flushmode = ZT_FLUSH_READ;
- err = ioctl(zchan->sockfd, codes.FLUSH, &flushmode);
- }
- break;
- case ZAP_COMMAND_FLUSH_BUFFERS:
- {
- int flushmode = ZT_FLUSH_BOTH;
- err = ioctl(zchan->sockfd, codes.FLUSH, &flushmode);
- }
- break;
- default:
- err = ZAP_NOTIMPL;
- break;
- };
-
- if (err && err != ZAP_NOTIMPL) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- }
-
-
- return err == 0 ? ZAP_SUCCESS : err;
-}
-
-/**
- * \brief Gets alarms from a zaptel Channel
- * \param zchan Channel to get alarms from
- * \return Success or failure
- */
-static ZIO_GET_ALARMS_FUNCTION(zt_get_alarms)
-{
- struct zt_spaninfo info;
-
- memset(&info, 0, sizeof(info));
- info.span_no = zchan->physical_span_id;
-
- if (ioctl(CONTROL_FD, codes.SPANSTAT, &info)) {
- snprintf(zchan->last_error, sizeof(zchan->last_error), "ioctl failed (%s)", strerror(errno));
- snprintf(zchan->span->last_error, sizeof(zchan->span->last_error), "ioctl failed (%s)", strerror(errno));
- return ZAP_FAIL;
- }
-
- zchan->alarm_flags = info.alarms;
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Waits for an event on a zaptel channel
- * \param zchan Channel to open
- * \param flags Type of event to wait for
- * \param to Time to wait (in ms)
- * \return Success, failure or timeout
- */
-static ZIO_WAIT_FUNCTION(zt_wait)
-{
- int32_t inflags = 0;
- int result;
- struct pollfd pfds[1];
-
- if (*flags & ZAP_READ) {
- inflags |= POLLIN;
- }
-
- if (*flags & ZAP_WRITE) {
- inflags |= POLLOUT;
- }
-
- if (*flags & ZAP_EVENTS) {
- inflags |= POLLPRI;
- }
-
-
- memset(&pfds[0], 0, sizeof(pfds[0]));
- pfds[0].fd = zchan->sockfd;
- pfds[0].events = inflags;
- result = poll(pfds, 1, to);
- *flags = 0;
-
- if (pfds[0].revents & POLLERR) {
- result = -1;
- }
-
- if (result > 0) {
- inflags = pfds[0].revents;
- }
-
- *flags = ZAP_NO_FLAGS;
-
- if (result < 0){
- snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed");
- return ZAP_FAIL;
- }
-
- if (result == 0) {
- return ZAP_TIMEOUT;
- }
-
- if (inflags & POLLIN) {
- *flags |= ZAP_READ;
- }
-
- if (inflags & POLLOUT) {
- *flags |= ZAP_WRITE;
- }
-
- if (inflags & POLLPRI) {
- *flags |= ZAP_EVENTS;
- }
-
- return ZAP_SUCCESS;
-
-}
-
-/**
- * \brief Checks for events on a zaptel span
- * \param span Span to check for events
- * \param ms Time to wait for event
- * \return Success if event is waiting or failure if not
- */
-ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event)
-{
- struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN];
- uint32_t i, j = 0, k = 0;
- int r;
-
- for(i = 1; i <= span->chan_count; i++) {
- memset(&pfds[j], 0, sizeof(pfds[j]));
- pfds[j].fd = span->channels[i]->sockfd;
- pfds[j].events = POLLPRI;
- j++;
- }
-
- r = poll(pfds, j, ms);
-
- if (r == 0) {
- return ZAP_TIMEOUT;
- } else if (r < 0 || (pfds[i-1].revents & POLLERR)) {
- snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- }
-
- for(i = 1; i <= span->chan_count; i++) {
- if (pfds[i-1].revents & POLLPRI) {
- zap_set_flag(span->channels[i], ZAP_CHANNEL_EVENT);
- span->channels[i]->last_event_time = zap_current_time_in_ms();
- k++;
- }
- }
-
- if (!k) {
- snprintf(span->last_error, sizeof(span->last_error), "no matching descriptor");
- }
-
- return k ? ZAP_SUCCESS : ZAP_FAIL;
-}
-
-/**
- * \brief Retrieves an event from a zaptel span
- * \param span Span to retrieve event from
- * \param event Openzap event to return
- * \return Success or failure
- */
-ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event)
-{
- uint32_t i, event_id = ZAP_OOB_INVALID;
- zt_event_t zt_event_id = 0;
-
- for(i = 1; i <= span->chan_count; i++) {
- if (zap_test_flag(span->channels[i], ZAP_CHANNEL_EVENT)) {
- zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT);
- if (ioctl(span->channels[i]->sockfd, codes.GETEVENT, &zt_event_id) == -1) {
- snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno));
- return ZAP_FAIL;
- }
-
- switch(zt_event_id) {
- case ZT_EVENT_RINGEROFF:
- {
- return ZAP_FAIL;
- }
- break;
- case ZT_EVENT_RINGERON:
- {
- return ZAP_FAIL;
- }
- break;
- case ZT_EVENT_RINGBEGIN:
- {
- event_id = ZAP_OOB_RING_START;
- }
- break;
- case ZT_EVENT_ONHOOK:
- {
- event_id = ZAP_OOB_ONHOOK;
- }
- break;
- case ZT_EVENT_WINKFLASH:
- {
- if (span->channels[i]->state == ZAP_CHANNEL_STATE_DOWN || span->channels[i]->state == ZAP_CHANNEL_STATE_DIALING) {
- event_id = ZAP_OOB_WINK;
- } else {
- event_id = ZAP_OOB_FLASH;
- }
- }
- break;
- case ZT_EVENT_RINGOFFHOOK:
- {
- if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS || (span->channels[i]->type == ZAP_CHAN_TYPE_EM && span->channels[i]->state != ZAP_CHANNEL_STATE_UP)) {
- zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_OFFHOOK);
- event_id = ZAP_OOB_OFFHOOK;
- } else if (span->channels[i]->type == ZAP_CHAN_TYPE_FXO) {
- event_id = ZAP_OOB_RING_START;
- } else {
- event_id = ZAP_OOB_NOOP;
- }
- }
- break;
- case ZT_EVENT_ALARM:
- {
- zap_sigmsg_t sigmsg;
- zap_channel_t *zchan = span->channels[i];
- event_id = ZAP_OOB_ALARM_TRAP;
- memset(&sigmsg, 0, sizeof(sigmsg));
- sigmsg.chan_id = zchan->chan_id;
- sigmsg.span_id = zchan->span_id;
- sigmsg.channel = zchan;
- sigmsg.event_id = ZAP_SIGEVENT_ALARM_TRAP;
- zap_span_send_signal(zchan->span, &sigmsg);
- }
- break;
- case ZT_EVENT_NOALARM:
- {
- zap_sigmsg_t sigmsg;
- zap_channel_t *zchan = span->channels[i];
- event_id = ZAP_OOB_ALARM_CLEAR;
- memset(&sigmsg, 0, sizeof(sigmsg));
- sigmsg.chan_id = zchan->chan_id;
- sigmsg.span_id = zchan->span_id;
- sigmsg.channel = zchan;
- sigmsg.event_id = ZAP_SIGEVENT_ALARM_CLEAR;
- zap_span_send_signal(zchan->span, &sigmsg);
- }
- break;
- case ZT_EVENT_BITSCHANGED:
- {
- event_id = ZAP_OOB_CAS_BITS_CHANGE;
- int bits = 0;
- int err = ioctl(span->channels[i]->sockfd, codes.GETRXBITS, &bits);
- if (err) {
- return ZAP_FAIL;
- }
- span->channels[i]->rx_cas_bits = bits;
- }
- break;
- default:
- {
- zap_log(ZAP_LOG_WARNING, "Unhandled event %d for %d:%d\n", zt_event_id, span->span_id, i);
- event_id = ZAP_OOB_INVALID;
- }
- break;
- }
-
- span->channels[i]->last_event_time = 0;
- span->event_header.e_type = ZAP_EVENT_OOB;
- span->event_header.enum_id = event_id;
- span->event_header.channel = span->channels[i];
- *event = &span->event_header;
- return ZAP_SUCCESS;
- }
- }
-
- return ZAP_FAIL;
-
-}
-
-/**
- * \brief Reads data from a zaptel channel
- * \param zchan Channel to read from
- * \param data Data buffer
- * \param datalen Size of data buffer
- * \return Success, failure or timeout
- */
-static ZIO_READ_FUNCTION(zt_read)
-{
- zap_ssize_t r = 0;
- int errs = 0;
-
- while (errs++ < 30) {
- if ((r = read(zchan->sockfd, data, *datalen)) > 0) {
- break;
- }
- zap_sleep(10);
- if (r == 0) {
- errs--;
- }
- }
-
- if (r > 0) {
- *datalen = r;
- if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
- *datalen -= 2;
- }
- return ZAP_SUCCESS;
- }
-
- return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL;
-}
-
-/**
- * \brief Writes data to a zaptel channel
- * \param zchan Channel to write to
- * \param data Data buffer
- * \param datalen Size of data buffer
- * \return Success or failure
- */
-static ZIO_WRITE_FUNCTION(zt_write)
-{
- zap_ssize_t w = 0;
- zap_size_t bytes = *datalen;
-
- if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
- memset(data+bytes, 0, 2);
- bytes += 2;
- }
-
- w = write(zchan->sockfd, data, bytes);
-
- if (w >= 0) {
- *datalen = w;
- return ZAP_SUCCESS;
- }
-
- return ZAP_FAIL;
-}
-
-/**
- * \brief Destroys a zaptel Channel
- * \param zchan Channel to destroy
- * \return Success
- */
-static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy)
-{
- close(zchan->sockfd);
- zchan->sockfd = ZT_INVALID_SOCKET;
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Global Openzap IO interface for zaptel
- */
-static zap_io_interface_t zt_interface;
-
-/**
- * \brief Loads zaptel IO module
- * \param zio Openzap IO interface
- * \return Success or failure
- */
-static ZIO_IO_LOAD_FUNCTION(zt_init)
-{
- assert(zio != NULL);
- struct stat statbuf;
- memset(&zt_interface, 0, sizeof(zt_interface));
- memset(&zt_globals, 0, sizeof(zt_globals));
-
- if (!stat(zt_ctlpath, &statbuf)) {
- zap_log(ZAP_LOG_NOTICE, "Using Zaptel control device\n");
- ctlpath = zt_ctlpath;
- chanpath = zt_chanpath;
- memcpy(&codes, &zt_ioctl_codes, sizeof(codes));
- } else if (!stat(dahdi_ctlpath, &statbuf)) {
- zap_log(ZAP_LOG_NOTICE, "Using DAHDI control device\n");
- ctlpath = dahdi_ctlpath;
- chanpath = dahdi_chanpath;
- memcpy(&codes, &dahdi_ioctl_codes, sizeof(codes));
- } else {
- zap_log(ZAP_LOG_ERROR, "No DAHDI or Zap control device found in /dev/\n");
- return ZAP_FAIL;
- }
- if ((CONTROL_FD = open(ctlpath, O_RDWR)) < 0) {
- zap_log(ZAP_LOG_ERROR, "Cannot open control device %s: %s\n", ctlpath, strerror(errno));
- return ZAP_FAIL;
- }
-
- zt_globals.codec_ms = 20;
- zt_globals.wink_ms = 150;
- zt_globals.flash_ms = 750;
- zt_globals.eclevel = 0;
- zt_globals.etlevel = 0;
-
- zt_interface.name = "zt";
- zt_interface.configure = zt_configure;
- zt_interface.configure_span = zt_configure_span;
- zt_interface.open = zt_open;
- zt_interface.close = zt_close;
- zt_interface.command = zt_command;
- zt_interface.wait = zt_wait;
- zt_interface.read = zt_read;
- zt_interface.write = zt_write;
- zt_interface.poll_event = zt_poll_event;
- zt_interface.next_event = zt_next_event;
- zt_interface.channel_destroy = zt_channel_destroy;
- zt_interface.get_alarms = zt_get_alarms;
- *zio = &zt_interface;
-
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Unloads zaptel IO module
- * \return Success
- */
-static ZIO_IO_UNLOAD_FUNCTION(zt_destroy)
-{
- close(CONTROL_FD);
- memset(&zt_interface, 0, sizeof(zt_interface));
- return ZAP_SUCCESS;
-}
-
-/**
- * \brief Openzap zaptel IO module definition
- */
-zap_module_t zap_module = {
- "zt",
- zt_init,
- zt_destroy,
-};
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h
deleted file mode 100644
index 006c87a7fe..0000000000
--- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_ZT_H
-#define ZAP_ZT_H
-#include "openzap.h"
-#include
-#include
-
-#ifdef __sun
-#include
-#include
-#include
-#endif
-
-/* Hardware interface structures and defines */
-/* Based on documentation of the structures required for the hardware interface */
-/* from http://wiki.freeswitch.org/wiki/Zapata_zaptel_interface */
-
-/* Structures */
-
-/* Used with ioctl: ZT_GET_PARAMS and ZT_SET_PARAMS */
-struct zt_params {
- int chan_no; /* Channel Number */
- int span_no; /* Span Number */
- int chan_position; /* Channel Position */
- int sig_type; /* Signal Type (read-only) */
- int sig_cap; /* Signal Cap (read-only) */
- int receive_offhook; /* Receive is offhook (read-only) */
- int receive_bits; /* Number of bits in receive (read-only) */
- int transmit_bits; /* Number of bits in transmit (read-only) */
- int transmit_hook_sig; /* Transmit Hook Signal (read-only) */
- int receive_hook_sig; /* Receive Hook Signal (read-only) */
- int g711_type; /* Member of zt_g711_t (read-only) */
- int idlebits; /* bits for the idle state (read-only) */
- char chan_name[40]; /* Channel Name */
- int prewink_time;
- int preflash_time;
- int wink_time;
- int flash_time;
- int start_time;
- int receive_wink_time;
- int receive_flash_time;
- int debounce_time;
- int pulse_break_time;
- int pulse_make_time;
- int pulse_after_time;
- /* latest version of this struct include chan_alarms field */
- uint32_t chan_alarms;
-};
-
-typedef struct zt_params zt_params_t;
-
-/* Used with ioctl: ZT_CONFLINK, ZT_GETCONF and ZT_SETCONF */
-struct zt_confinfo {
- int chan_no; /* Channel Number, 0 for current */
- int conference_number;
- int conference_mode;
-};
-
-/* Used with ioctl: ZT_GETGAINS and ZT_SETGAINS */
-struct zt_gains {
- int chan_no; /* Channel Number, 0 for current */
- unsigned char receive_gain[256]; /* Receive gain table */
- unsigned char transmit_gain[256]; /* Transmit gain table */
-};
-
-/* Used with ioctl: ZT_SPANSTAT */
-struct zt_spaninfo {
- int span_no; /* span number (-1 to use name) */
- char name[20]; /* Name of span */
- char description[40]; /* Description of span */
- int alarms; /* alarms status */
- int transmit_level; /* Transmit level */
- int receive_level; /* Receive level */
- int bpv_count; /* Current BPV count */
- int crc4_count; /* Current CRC4 error count */
- int ebit_count; /* Current E-bit error count */
- int fas_count; /* Current FAS error count */
- int irq_misses; /* Current IRQ misses */
- int sync_src; /* Span # of sync source (0 = free run) */
- int configured_chan_count; /* Count of channels configured on the span */
- int channel_count; /* Total count of channels on the span */
- int span_count; /* Total count of zaptel spans on the system*/
- /* end v1 of the struct */
- /* as long as we don't use the fields below we should be ok regardless of the zaptel/dahdi version */
- int lbo; /* Line Build Out */
- int lineconfig; /* framing/coding */
- /* end of v2 of the struct */
- char lboname[40]; /* Line Build Out in text form */
- char location[40]; /* span's device location in system */
- char manufacturer[40]; /* manufacturer of span's device */
- char devicetype[40]; /* span's device type */
- int irq; /* span's device IRQ */
- int linecompat; /* signaling modes possible on this span */
- char spantype[6]; /* type of span in text form */
-};
-
-struct zt_maintinfo {
- int span_no; /* span number */
- int command; /* Maintenance mode to set (from zt_maintenance_mode_t) */
-};
-
-struct zt_lineconfig {
-/* Used in ZT_SPANCONFIG */
- int span; /* Which span number (0 to use name) */
- char name[20]; /* Name of span to use */
- int lbo; /* line build-outs */
- int lineconfig; /* line config parameters (framing, coding) */
- int sync; /* what level of sync source we are */
-};
-
-struct zt_chanconfig {
-/* Used in ZT_CHANCONFIG */
- int chan; /* Channel we're applying this to (0 to use name) */
- char name[40]; /* Name of channel to use */
- int sigtype; /* Signal type */
- int deflaw; /* Default law (ZT_LAW_DEFAULT, ZT_LAW_MULAW, or ZT_LAW_ALAW */
- int master; /* Master channel if sigtype is ZT_SLAVE */
- int idlebits; /* Idle bits (if this is a CAS channel) or channel to monitor (if this is DACS channel) */
- char netdev_name[16]; /* name for the hdlc network device */
-};
-
-struct zt_bufferinfo {
-/* used in ZT_SET_BUFINFO and ZT_GET_BUFINFO */
- int txbufpolicy; /* Policy for handling receive buffers */
- int rxbufpolicy; /* Policy for handling receive buffers */
- int numbufs; /* How many buffers to use */
- int bufsize; /* How big each buffer is */
- int readbufs; /* How many read buffers are full (read-only) */
- int writebufs; /* How many write buffers are full (read-only) */
-};
-
-/* Enumerations */
-
-/* Values in zt_params structure for member g711_type */
-typedef enum {
- ZT_G711_DEFAULT = 0, /* Default mulaw/alaw from the span */
- ZT_G711_MULAW = 1,
- ZT_G711_ALAW = 2
-} zt_g711_t;
-
-typedef enum {
- ZT_EVENT_NONE = 0,
- ZT_EVENT_ONHOOK = 1,
- ZT_EVENT_RINGOFFHOOK = 2,
- ZT_EVENT_WINKFLASH = 3,
- ZT_EVENT_ALARM = 4,
- ZT_EVENT_NOALARM = 5,
- ZT_EVENT_ABORT = 6,
- ZT_EVENT_OVERRUN = 7,
- ZT_EVENT_BADFCS = 8,
- ZT_EVENT_DIALCOMPLETE = 9,
- ZT_EVENT_RINGERON = 10,
- ZT_EVENT_RINGEROFF = 11,
- ZT_EVENT_HOOKCOMPLETE = 12,
- ZT_EVENT_BITSCHANGED = 13,
- ZT_EVENT_PULSE_START = 14,
- ZT_EVENT_TIMER_EXPIRED = 15,
- ZT_EVENT_TIMER_PING = 16,
- ZT_EVENT_POLARITY = 17,
- ZT_EVENT_RINGBEGIN = 18
-} zt_event_t;
-
-typedef enum {
- ZT_FLUSH_READ = 1,
- ZT_FLUSH_WRITE = 2,
- ZT_FLUSH_BOTH = (ZT_FLUSH_READ | ZT_FLUSH_WRITE),
- ZT_FLUSH_EVENT = 4,
- ZT_FLUSH_ALL = (ZT_FLUSH_READ | ZT_FLUSH_WRITE | ZT_FLUSH_EVENT)
-} zt_flush_t;
-
-typedef enum {
- ZT_IOMUX_READ = 1,
- ZT_IOMUX_WRITE = 2,
- ZT_IOMUX_WRITEEMPTY = 4,
- ZT_IOMUX_SIGEVENT = 8,
- ZT_IOMUX_NOWAIT = 256
-} zt_iomux_t;
-
-typedef enum {
- ZT_ONHOOK = 0,
- ZT_OFFHOOK = 1,
- ZT_WINK = 2,
- ZT_FLASH = 3,
- ZT_START = 4,
- ZT_RING = 5,
- ZT_RINGOFF = 6
-} zt_hookstate_t;
-
-typedef enum {
- ZT_MAINT_NONE = 0, /* Normal Mode */
- ZT_MAINT_LOCALLOOP = 1, /* Local Loopback */
- ZT_MAINT_REMOTELOOP = 2, /* Remote Loopback */
- ZT_MAINT_LOOPUP = 3, /* Send Loopup Code */
- ZT_MAINT_LOOPDOWN = 4, /* Send Loopdown Code */
- ZT_MAINT_LOOPSTOP = 5 /* Stop Sending Loop Codes */
-} zt_maintenance_mode_t;
-
-typedef enum {
-/* Signalling type */
-ZT_SIG_NONE = 0, /* chan not configured. */
-
-ZT_SIG_FXSLS = ((1 << 0) | (1 << 13)), /* FXS, Loopstart */
-ZT_SIG_FXSGS = ((1 << 1) | (1 << 13)), /* FXS, Groundstart */
-ZT_SIG_FXSKS = ((1 << 2) | (1 << 13)), /* FXS, Kewlstart */
-ZT_SIG_FXOLS = ((1 << 3) | (1 << 12)), /* FXO, Loopstart */
-ZT_SIG_FXOGS = ((1 << 4) | (1 << 12)), /* FXO, Groupstart */
-ZT_SIG_FXOKS = ((1 << 5) | (1 << 12)), /* FXO, Kewlstart */
-ZT_SIG_EM = (1 << 6), /* E&M */
-ZT_SIG_CLEAR = (1 << 7),
-ZT_SIG_HDLCRAW = ((1 << 8) | ZT_SIG_CLEAR),
-ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW),
-ZT_SIG_CAS = (1 << 15),
-ZT_SIG_HARDHDLC = ((1 << 19) | ZT_SIG_CLEAR),
-} zt_sigtype_t;
-
-typedef enum {
-ZT_DBIT = 1,
-ZT_CBIT = 2,
-ZT_BBIT = 4,
-ZT_ABIT = 8
-} zt_cas_bit_t;
-
-/* Defines */
-
-#define ZT_MAX_BLOCKSIZE 8192
-#define ZT_DEFAULT_MTU_MRU 2048
-
-/* ioctl defines */
-
-#define ZT_CODE 'J'
-#define DAHDI_CODE 0xDA
-
-
-#define ZT_GET_BLOCKSIZE _IOR (ZT_CODE, 1, int) /* Get Transfer Block Size. */
-#define ZT_SET_BLOCKSIZE _IOW (ZT_CODE, 2, int) /* Set Transfer Block Size. */
-#define ZT_FLUSH _IOW (ZT_CODE, 3, int) /* Flush Buffer(s) and stop I/O */
-#define ZT_SYNC _IOW (ZT_CODE, 4, int) /* Wait for Write to Finish */
-#define ZT_GET_PARAMS _IOR (ZT_CODE, 5, struct zt_params) /* Get channel parameters */
-#define ZT_SET_PARAMS _IOW (ZT_CODE, 6, struct zt_params) /* Set channel parameters */
-#define ZT_HOOK _IOW (ZT_CODE, 7, int) /* Set Hookswitch Status */
-#define ZT_GETEVENT _IOR (ZT_CODE, 8, int) /* Get Signalling Event */
-#define ZT_IOMUX _IOWR (ZT_CODE, 9, int) /* Wait for something to happen (IO Mux) */
-#define ZT_SPANSTAT _IOWR (ZT_CODE, 10, struct zt_spaninfo) /* Get Span Status */
-#define ZT_MAINT _IOW (ZT_CODE, 11, struct zt_maintinfo)/* Set Maintenance Mode for a span */
-#define ZT_GETCONF _IOWR (ZT_CODE, 12, struct zt_confinfo) /* Get Conference Mode */
-#define ZT_SETCONF _IOWR (ZT_CODE, 13, struct zt_confinfo) /* Set Conference Mode */
-#define ZT_CONFLINK _IOW (ZT_CODE, 14, struct zt_confinfo) /* Setup or Remove Conference Link */
-#define ZT_CONFDIAG _IOR (ZT_CODE, 15, int) /* Display Conference Diagnostic Information on Console */
-
-#define ZT_GETGAINS _IOWR (ZT_CODE, 16, struct zt_gains) /* Get Channel audio gains */
-#define ZT_SETGAINS _IOWR (ZT_CODE, 17, struct zt_gains) /* Set Channel audio gains */
-#define ZT_SPANCONFIG _IOW (ZT_CODE, 18, struct zt_lineconfig)/* Set Line (T1) Configurations and start system */
-#define ZT_CHANCONFIG _IOW (ZT_CODE, 19, struct zt_chanconfig)/* Set Channel Configuration */
-#define ZT_SET_BUFINFO _IOW (ZT_CODE, 27, struct zt_bufferinfo)/* Set buffer policy */
-#define ZT_GET_BUFINFO _IOR (ZT_CODE, 28, struct zt_bufferinfo)/* Get current buffer info */
-#define ZT_AUDIOMODE _IOW (ZT_CODE, 32, int) /* Set a clear channel into audio mode */
-#define ZT_ECHOCANCEL _IOW (ZT_CODE, 33, int) /* Control Echo Canceller */
-#define ZT_HDLCRAWMODE _IOW (ZT_CODE, 36, int) /* Set a clear channel into HDLC w/out FCS checking/calculation mode */
-#define ZT_HDLCFCSMODE _IOW (ZT_CODE, 37, int) /* Set a clear channel into HDLC w/ FCS mode */
-
-/* Specify a channel on /dev/zap/chan -- must be done before any other ioctl's and is only valid on /dev/zap/chan */
-#define ZT_SPECIFY _IOW (ZT_CODE, 38, int)
-
-/* Temporarily set the law on a channel to ZT_LAW_DEFAULT, ZT_LAW_ALAW, or ZT_LAW_MULAW. Is reset on close. */
-#define ZT_SETLAW _IOW (ZT_CODE, 39, int)
-
-/* Temporarily set the channel to operate in linear mode when non-zero or default law if 0 */
-#define ZT_SETLINEAR _IOW (ZT_CODE, 40, int)
-
-#define ZT_GETCONFMUTE _IOR (ZT_CODE, 49, int) /* Get Conference to mute mode */
-#define ZT_ECHOTRAIN _IOW (ZT_CODE, 50, int) /* Control Echo Trainer */
-
-/* Set/Get CAS bits */
-#define ZT_SETTXBITS _IOW (ZT_CODE, 43, int)
-#define ZT_GETRXBITS _IOR (ZT_CODE, 45, int)
-
-#define DAHDI_GET_BLOCKSIZE _IOR (DAHDI_CODE, 1, int) /* Get Transfer Block Size. */
-#define DAHDI_SET_BLOCKSIZE _IOW (DAHDI_CODE, 1, int) /* Set Transfer Block Size. */
-#define DAHDI_FLUSH _IOW (DAHDI_CODE, 3, int) /* Flush Buffer(s) and stop I/O */
-#define DAHDI_SYNC _IO (DAHDI_CODE, 4) /* Wait for Write to Finish */
-#define DAHDI_GET_PARAMS _IOR (DAHDI_CODE, 5, struct zt_params) /* Get channel parameters */
-#define DAHDI_SET_PARAMS _IOW (DAHDI_CODE, 5, struct zt_params) /* Set channel parameters */
-#define DAHDI_HOOK _IOW (DAHDI_CODE, 7, int) /* Set Hookswitch Status */
-#define DAHDI_GETEVENT _IOR (DAHDI_CODE, 8, int) /* Get Signalling Event */
-#define DAHDI_IOMUX _IOWR (DAHDI_CODE, 9, int) /* Wait for something to happen (IO Mux) */
-#define DAHDI_SPANSTAT _IOWR (DAHDI_CODE, 10, struct zt_spaninfo) /* Get Span Status */
-#define DAHDI_MAINT _IOW (DAHDI_CODE, 11, struct zt_maintinfo) /* Set Maintenance Mode for a span */
-#define DAHDI_GETCONF _IOR (DAHDI_CODE, 12, struct zt_confinfo) /* Get Conference Mode */
-#define DAHDI_SETCONF _IOW (DAHDI_CODE, 12, struct zt_confinfo) /* Set Conference Mode */
-#define DAHDI_CONFLINK _IOW (DAHDI_CODE, 14, struct zt_confinfo) /* Setup or Remove Conference Link */
-#define DAHDI_CONFDIAG _IOR (DAHDI_CODE, 15, int) /* Display Conference Diagnostic Information on Console */
-
-#define DAHDI_GETGAINS _IOR (DAHDI_CODE, 16, struct zt_gains) /* Get Channel audio gains */
-#define DAHDI_SETGAINS _IOW (DAHDI_CODE, 16, struct zt_gains) /* Set Channel audio gains */
-#define DAHDI_SPANCONFIG _IOW (DAHDI_CODE, 18, struct zt_lineconfig)/* Set Line (T1) Configurations and start system */
-#define DAHDI_CHANCONFIG _IOW (DAHDI_CODE, 19, struct zt_chanconfig)/* Set Channel Configuration */
-#define DAHDI_SET_BUFINFO _IOW (DAHDI_CODE, 27, struct zt_bufferinfo)/* Set buffer policy */
-#define DAHDI_GET_BUFINFO _IOR (DAHDI_CODE, 27, struct zt_bufferinfo)/* Get current buffer info */
-#define DAHDI_AUDIOMODE _IOW (DAHDI_CODE, 32, int) /* Set a clear channel into audio mode */
-#define DAHDI_ECHOCANCEL _IOW (DAHDI_CODE, 33, int) /* Control Echo Canceller */
-#define DAHDI_HDLCRAWMODE _IOW (DAHDI_CODE, 36, int) /* Set a clear channel into HDLC w/out FCS checking/calculation mode */
-#define DAHDI_HDLCFCSMODE _IOW (DAHDI_CODE, 37, int) /* Set a clear channel into HDLC w/ FCS mode */
-
-/* Specify a channel on /dev/dahdi/chan -- must be done before any other ioctl's and is only valid on /dev/dahdi/chan */
-#define DAHDI_SPECIFY _IOW (DAHDI_CODE, 38, int)
-
-/* Temporarily set the law on a channel to DAHDI_LAW_DEFAULT, DAHDI_LAW_ALAW, or DAHDI_LAW_MULAW. Is reset on close. */
-#define DAHDI_SETLAW _IOW (DAHDI_CODE, 39, int)
-
-/* Temporarily set the channel to operate in linear mode when non-zero or default law if 0 */
-#define DAHDI_SETLINEAR _IOW (DAHDI_CODE, 40, int)
-
-#define DAHDI_GETCONFMUTE _IOR (DAHDI_CODE, 49, int) /* Get Conference to mute mode */
-#define DAHDI_ECHOTRAIN _IOW (DAHDI_CODE, 50, int) /* Control Echo Trainer */
-
-/* Set/Get CAS bits */
-#define DAHDI_SETTXBITS _IOW (DAHDI_CODE, 43, int)
-#define DAHDI_GETRXBITS _IOR (DAHDI_CODE, 43, int)
-
-
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/priserver.c b/libs/openzap/src/priserver.c
deleted file mode 100644
index 1928786af0..0000000000
--- a/libs/openzap/src/priserver.c
+++ /dev/null
@@ -1,328 +0,0 @@
-/*****************************************************************************
- * priserver.c Refactoring of pritest.c
- *
- * Author(s): Anthony Minessale II
- * Nenad Corbic
- *
- * Copyright: (c) 2005-2014 Anthony Minessale II
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- * ============================================================================
- */
-
-#include "openzap.h"
-#include
-#include
-#include
-#include
-#include
-#include
-
-typedef struct {
- int pid;
- q931_call call;
- void *pri;
- int ready;
-}call_info_t;
-
-
-#define SANGOMA_MAX_CHAN_PER_SPAN 32
-
-static call_info_t pidmap[SANGOMA_MAX_CHAN_PER_SPAN];
-
-ZIO_EVENT_CB_FUNCTION(my_zap_event_handler)
-{
- if (event->e_type = ZAP_EVENT_DTMF) {
- char *dtmf = event->data;
- printf("DTMF %s\n", dtmf);
- }
-}
-
-/* Stupid runtime process to play a file to a b channel*/
-#define BYTES 320
-#define MAX_BYTES 1000
-
-static int ready = 1;
-
-static void handle_SIGINT(int sig)
-{
- if (sig) {
- ready = 0;
- }
-
- return;
-}
-
-static void launch_channel(struct sangoma_pri *spri, int channo)
-{
- pid_t pid;
- int fd = 0, file = 0, inlen = 0, outlen = 0;
- unsigned char inframe[MAX_BYTES], outframe[MAX_BYTES];
- fd_set readfds;
- int mtu_mru=BYTES / 2;
- int err;
- zap_channel_t *chan;
- zap_codec_t codec = ZAP_CODEC_SLIN;
- unsigned ms = 20;
- unsigned int lead = 50;
- int ifd = -1;
- zap_tone_type_t tt = ZAP_TONE_DTMF;
- char dtmf[] = "1234567890";
- int loops = 0;
-
- pid = fork();
-
- if (pid) {
- pidmap[channo-1].pid = pid;
- printf("-- Launching process %d to handle channel %d\n", pid, channo);
- return;
- }
-
- signal(SIGINT, handle_SIGINT);
-
- //ifd = open("/nfs/sounds/ptest.raw", O_WRONLY|O_CREAT|O_TRUNC, 777);
-
- memset(inframe, 0, MAX_BYTES);
- memset(outframe, 0, MAX_BYTES);
-
- if (zap_channel_open(spri->span, channo, &chan) != ZAP_SUCCESS) {
- printf("DEBUG cant open fd!\n");
- }
-
-
-
-#if 1
- if (zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec) != ZAP_SUCCESS) {
- printf("Critical Error: Failed to set driver codec!\n");
- zap_channel_close(&chan);
- exit(-1);
- }
-#endif
-
-#if 1
- if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) {
- printf("Critical Error: Failed to set dtmf detect!\n");
- zap_channel_close(&chan);
- exit(-1);
- }
- zap_channel_set_event_callback(chan, my_zap_event_handler);
-#endif
-
-
- if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) != ZAP_SUCCESS) {
- printf("Critical Error: Failed to set codec interval!\n");
- zap_channel_close(&chan);
- exit(-1);
- }
-
- file = open("sound.raw", O_RDONLY);
- if (file < 0){
- printf("Critical Error: Failed to open sound file!\n");
- zap_channel_close(&chan);
- exit(-1);
- }
-
-
- while(ready) {
- zap_wait_flag_t flags = ZAP_READ;
- zap_size_t len;
- loops++;
-
- if (lead) {
- lead--;
- }
-
- if (!lead && loops == 300) {
-#if 1
- if (zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, dtmf) != ZAP_SUCCESS) {
- printf("Critical Error: Failed to send dtmf\n");
- zap_channel_close(&chan);
- exit(-1);
- }
-#endif
-
- }
-
- if (zap_channel_wait(chan, &flags, 2000) != ZAP_SUCCESS) {
- printf("wait FAIL! [%s]\n", chan->last_error);
- break;
- }
-
- if (flags & ZAP_READ) {
- len = MAX_BYTES;
- if (zap_channel_read(chan, inframe, &len) == ZAP_SUCCESS) {
- //printf("READ: %d\n", len);
- //write(ifd, inframe, len);
- if(!lead && (outlen = read(file, outframe, len)) <= 0) {
- break;
- }
-
- } else {
- printf("READ FAIL! %d [%s]\n", len, chan->last_error);
- break;
- }
- if (lead) {
- continue;
- }
- zap_channel_write(chan, outframe, sizeof(outframe), &len);
- } else {
- printf("BREAK");
- break;
- }
- }
-
- printf("loop done\n");
-
- //sangoma_get_full_cfg(fd, &tdm_api);
- close(file);
- //close(ifd);
-
- pri_hangup(spri->pri, channo, 16);
- if (zap_channel_close(&chan) != ZAP_SUCCESS) {
- printf("Critical Error: Failed to close channel [%s]\n", chan->last_error);
- }
-
- printf("Call Handler: Process Finished\n");
- exit(0);
-}
-
-
-/* Event Handlers */
-
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
-{
- printf( "number is: %s\n", event->ring.callednum);
- if(strlen(event->ring.callednum) > 3) {
- printf( "final number is: %s\n", event->ring.callednum);
- pri_answer(spri->pri, event->ring.call, 0, 1);
- }
- return 0;
-}
-
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
-{
- //pri_hangup(spri->pri, event->hangup.call, event->hangup.cause);
- printf("-- Hanging up channel %d\n", event->hangup.channel);
- if(pidmap[event->hangup.channel-1].pid) {
- pri_hangup(spri->pri, event->hangup.call, 16);
- pri_destroycall(spri->pri, event->hangup.call);
- kill(pidmap[event->hangup.channel-1].pid, SIGINT);
- pidmap[event->hangup.channel-1].pid = 0;
- }
- return 0;
-}
-
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
-{
- printf("-- Ring on channel %d (from %s to %s), answering...\n", event->ring.channel, event->ring.callingnum, event->ring.callednum);
- pri_answer(spri->pri, event->ring.call, event->ring.channel, 1);
- memcpy(&pidmap[event->ring.channel-1].call, event->ring.call, sizeof(q931_call));
- pidmap[event->ring.channel-1].pri=spri->pri;
- pidmap[event->ring.channel-1].call = *event->ring.call;
- launch_channel(spri, event->ring.channel);
- return 0;
-}
-
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
-{
- printf("-- Restarting channel %d\n", event->restart.channel);
- return 0;
-}
-
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
-{
- printf("%s: Caught Event %d (%s)\n", __FUNCTION__, event_type, sangoma_pri_event_str(event_type));
- return 0;
-}
-
-/* Generic Reaper */
-static void chan_ended(int sig)
-{
- int status;
- int x;
- struct rusage rusage;
- pid_t pid;
- pid = wait4(-1, &status, WNOHANG, &rusage);
-
- printf("-- PID %d ended\n", pid);
-
- for (x=0;x -1) {
- fprintf(stderr, "--!! Unknown PID %d exited\n", pid);
- signal(SIGCHLD, chan_ended);
- return;
- }
-}
-
-/* Our Program */
-int main(int argc, char *argv[])
-{
- struct sangoma_pri spri;
- int debug = 0;
- if (argv[1]) {
- debug = atoi(argv[1]);
- }
-
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
- if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- printf("OpenZAP loaded\n");
-
-
- debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE;
- printf("WTF %d\n", debug);
-
- if (sangoma_init_pri(&spri,
- 1, // span
- 24, // dchan
- SANGOMA_PRI_SWITCH_DMS100,
- SANGOMA_PRI_CPE,
- debug) < 0) {
- return -1;
- }
- //spri.pri->debug = (PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_STATE);
-
- //pri_set_debug(&spri.pri, (PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_STATE));
-
- 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_HANGUP, on_hangup);
- SANGOMA_MAP_PRI_EVENT(spri, SANGOMA_PRI_EVENT_HANGUP_REQ, 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);
-
- signal(SIGCHLD, chan_ended);
- sangoma_run_pri(&spri);
- return 0;
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/sangoma_pri.c b/libs/openzap/src/sangoma_pri.c
deleted file mode 100644
index 27a44cd1ff..0000000000
--- a/libs/openzap/src/sangoma_pri.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*****************************************************************************
- * sangoma_pri.c libpri Sangoma integration
- *
- * Author(s): Anthony Minessale II
- * Nenad Corbic
- *
- * Copyright: (c) 2005-2014 Anthony Minessale II
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- * ============================================================================
- */
-
-#include "openzap.h"
-#include
-#ifndef HAVE_GETTIMEOFDAY
-
-#ifdef WIN32
-#include
-
-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, "RING"},
- {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"}
-};
-
-#define LINE "--------------------------------------------------------------------------------"
-
-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)
-{
- struct sangoma_pri *spri = (struct sangoma_pri *) pri->userdata;
- zap_size_t len = buflen;
- int res;
- char bb[4096] = "";
-
-
- if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) {
- printf("D-READ FAIL! [%s]\n", spri->zdchan->last_error);
- return 0;
- }
- res = (int)len;
- memset(&((unsigned char*)buf)[res],0,2);
- res+=2;
-
- //print_bits(buf, res-2, bb, sizeof(bb), 1, 0);
- //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb);
-
- return res;
-}
-
-static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen)
-{
- struct sangoma_pri *spri = (struct sangoma_pri *) pri->userdata;
- int res;
- zap_size_t len = buflen -2;
- char bb[4096] = "";
-
- if (zap_channel_write(spri->zdchan, buf, buflen, &len) != ZAP_SUCCESS) {
- printf("D-WRITE FAIL! [%s]\n", spri->zdchan->last_error);
- return 0;
- }
-
- //print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0);
- //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)buflen-2, LINE, bb);
-
- return (int) buflen;
-}
-
-int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, int node, int debug)
-{
- int ret = -1;
- zap_socket_t dfd = 0;
-
- memset(spri, 0, sizeof(struct sangoma_pri));
-
- if (zap_channel_open(span, dchan, &spri->zdchan) != ZAP_SUCCESS) {
- fprintf(stderr, "Unable to open DCHAN %d for span %d (%s)\n", dchan, span, strerror(errno));
- } else {
- if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, spri))){
- spri->span = span;
- 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 (!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;
-
-}
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/sangoma_pri.h b/libs/openzap/src/sangoma_pri.h
deleted file mode 100644
index a706f7c0df..0000000000
--- a/libs/openzap/src/sangoma_pri.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*****************************************************************************
- * libsangoma.c AFT T1/E1: HDLC API Code Library
- *
- * Author(s): Anthony Minessale II
- * Nenad Corbic
- *
- * Copyright: (c) 2005-2014 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
-#include
-
-
-#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;
- zap_channel_t *zdchan;
-};
-
-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/libs/openzap/src/ss7/README b/libs/openzap/src/ss7/README
deleted file mode 100644
index 0efe94c94a..0000000000
--- a/libs/openzap/src/ss7/README
+++ /dev/null
@@ -1,3 +0,0 @@
-SS7 Coming soon
-
--Shane Burrell-
diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c
deleted file mode 100644
index 79c6a3134b..0000000000
--- a/libs/openzap/src/testanalog.c
+++ /dev/null
@@ -1,133 +0,0 @@
-#include "openzap.h"
-
-
-static void *test_call(zap_thread_t *me, void *obj)
-{
- zap_channel_t *chan = (zap_channel_t *) obj;
- uint8_t frame[1024];
- zap_size_t len;
- char *number = strdup("5551212");
-
- zap_sleep(10 * 1000);
-
- zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n");
-
- zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP);
- zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, number);
-
- while (chan->state == ZAP_CHANNEL_STATE_UP) {
- zap_wait_flag_t flags = ZAP_READ;
-
- if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) {
- break;
- }
- len = sizeof(frame);
- if (flags & ZAP_READ) {
- if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) {
- //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", len);
- zap_channel_write(chan, frame, sizeof(frame), &len);
- } else {
- break;
- }
- }
- }
-
- if (chan->state == ZAP_CHANNEL_STATE_UP) {
- zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY);
- }
-
- zap_log(ZAP_LOG_DEBUG, "call over\n");
- free(number);
- return NULL;
-}
-
-static ZIO_SIGNAL_CB_FUNCTION(on_signal)
-{
- zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id));
-
- switch(sigmsg->event_id) {
- case ZAP_SIGEVENT_START:
- zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING);
- zap_log(ZAP_LOG_DEBUG, "launching thread and indicating ring\n");
- zap_thread_create_detached(test_call, sigmsg->channel);
- break;
- default:
- break;
- }
-
- return ZAP_SUCCESS;
-}
-
-static int R = 0;
-#if 0
-static void handle_SIGINT(int sig)
-{
- if (sig);
- R = 0;
- return;
-}
-#endif
-
-int main(int argc, char *argv[])
-{
- zap_span_t *span;
- int span_id;
- int digit_timeout = 2000;
- int max_dialstr = 11;
-
- if (argc < 2) {
- printf("usage %s \n", argv[0]);
- exit(-1);
- }
-
- span_id = atoi(argv[1]);
-
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
-
- if (zap_global_init() != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n");
-
- if (zap_span_find(span_id, &span) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n");
- goto done;
- }
-
-
- if (zap_configure_span("analog", span, on_signal,
- "tonemap", "us",
- "digit_timeout", &digit_timeout,
- "max_dialstr", &max_dialstr,
- TAG_END
- ) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n");
- goto done;
- }
- zap_span_start(span);
-
- R = 1;
-
- while(zap_running() && R) {
- zap_sleep(1 * 1000);
- }
-
-done:
-
- zap_global_destroy();
- return 0;
-}
-
-/* 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 noet:
- */
-
diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c
deleted file mode 100644
index e024dabccd..0000000000
--- a/libs/openzap/src/testapp.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "openzap.h"
-
-int main(int argc, char *argv[])
-{
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
- zap_channel_t *chan;
- unsigned ms = 20;
- zap_codec_t codec = ZAP_CODEC_SLIN;
- unsigned runs = 1;
-
-
- if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- printf("OpenZAP loaded\n");
-
- top:
- //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) {
- if (zap_channel_open(1, 1, &chan) == ZAP_SUCCESS) {
- int x = 0;
- printf("opened channel %d:%d\n", chan->span_id, chan->chan_id);
-
-#if 1
- if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) {
- ms = 0;
- zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &ms);
- printf("interval set to %u\n", ms);
- } else {
- printf("set interval failed [%s]\n", chan->last_error);
- }
-#endif
- if (zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec) == ZAP_SUCCESS) {
- codec = 1;
- zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &codec);
- printf("codec set to %u\n", codec);
- } else {
- printf("set codec failed [%s]\n", chan->last_error);
- }
-
- for(x = 0; x < 25; x++) {
- unsigned char buf[2048];
- zap_size_t len = sizeof(buf);
- zap_wait_flag_t flags = ZAP_READ;
-
- if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) {
- printf("wait FAIL! %u [%s]\n", (unsigned)len, chan->last_error);
- }
- if (flags & ZAP_READ) {
- if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) {
- printf("READ: %u\n", (unsigned)len);
- } else {
- printf("READ FAIL! %u [%s]\n", (unsigned)len, chan->last_error);
- break;
- }
- } else {
- printf("wait fail [%s]\n", chan->last_error);
- }
- }
- zap_channel_close(&chan);
- } else {
- printf("open fail [%s]\n", chan->last_error);
- }
-
- if(--runs) {
- goto top;
- }
-
- zap_global_destroy();
- return 0;
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/testboost.c b/libs/openzap/src/testboost.c
deleted file mode 100644
index 59daa56f58..0000000000
--- a/libs/openzap/src/testboost.c
+++ /dev/null
@@ -1,75 +0,0 @@
-#include "openzap.h"
-
-static ZIO_SIGNAL_CB_FUNCTION(on_signal)
-{
- return ZAP_FAIL;
-}
-
-static int R = 0;
-#if 0
-static void handle_SIGINT(int sig)
-{
- if (sig);
- R = 0;
- return;
-}
-#endif
-int main(int argc, char *argv[])
-{
- zap_span_t *span;
- int local_port, remote_port;
-
- local_port = remote_port = 53000;
-
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
-
- if (argc < 2) {
- printf("umm no\n");
- exit(-1);
- }
-
- if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- printf("OpenZAP loaded\n");
-
- if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
- fprintf(stderr, "Error finding OpenZAP span\n");
- goto done;
- }
-
- if (zap_configure_span("ss7_boost", span, on_signal,
- "local_ip", "127.0.0.65",
- "local_port", &local_port,
- "remote_ip", "127.0.0.66",
- "remote_port", &remote_port,
- TAG_END) == ZAP_SUCCESS) {
- zap_span_start(span);
- } else {
- fprintf(stderr, "Error starting SS7_BOOST\n");
- goto done;
- }
-
- while(zap_running() && R) {
- zap_sleep(1 * 1000);
- }
-
- done:
-
- zap_global_destroy();
-
- return 0;
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c
deleted file mode 100644
index 0018bb9a5d..0000000000
--- a/libs/openzap/src/testcid.c
+++ /dev/null
@@ -1,108 +0,0 @@
-#include "openzap.h"
-zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data);
-
-struct helper {
- int fd;
- int wrote;
-};
-
-zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data)
-{
- struct helper *foo = (struct helper *) user_data;
- size_t len;
- len = write(foo->fd, buf, buflen * 2);
- if (!len) return ZAP_FAIL;
- foo->wrote += buflen * 2;
- return ZAP_SUCCESS;
-}
-
-int main(int argc, char *argv[])
-{
- struct zap_fsk_modulator fsk_trans;
- zap_fsk_data_state_t fsk_data = {0};
- int fd = -1;
- int16_t buf[160] = {0};
- ssize_t len = 0;
- size_t type, mlen;
- char *sp;
- char str[128] = "";
- char fbuf[256];
- uint8_t databuf[1024] = "";
- struct helper foo = {0};
- // int x, bytes, start_bits = 180, stop_bits = 5, sbits = 300;
- char time_str[9];
- struct tm tm;
- time_t now;
-
- if (argc < 2) {
- int x;
- const char *url = "sip:cool@rad.com";
-
- if ((fd = open("tone.raw", O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
- fprintf(stderr, "File Error! [%s]\n", strerror(errno));
- exit(-1);
- }
-
-
- time(&now);
- localtime_r(&now, &tm);
- strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm);
-
- zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf));
-#if 1
-
- zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *)time_str, strlen(time_str));
- //zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06091213", 8);
- zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, (uint8_t *)"14149361212", 7);
- zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, (uint8_t *)"Fred Smith", 10);
- for(x = 0; x < 0; x++)
- zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, (uint8_t *)url, strlen(url));
-#else
- zap_fsk_data_add_sdmf(&fsk_data, "06061234", "0");
- //zap_fsk_data_add_sdmf(&state, "06061234", "5551212");
-#endif
- zap_fsk_data_add_checksum(&fsk_data);
-
- foo.fd = fd;
-
-
- zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, 8000, &fsk_data, -14, 180, 5, 300, my_write_sample, &foo);
- zap_fsk_modulator_send_all((&fsk_trans));
-
- printf("%u %d %d\n", (unsigned) fsk_data.dlen, foo.wrote, fsk_trans.est_bytes);
-
- if (fd > -1) {
- close (fd);
- }
-
- return 0;
- }
-
- if (zap_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) {
- printf("wtf\n");
- return 0;
- }
-
- if ((fd = open(argv[1], O_RDONLY)) < 0) {
- fprintf(stderr, "cant open file %s\n", argv[1]);
- exit (-1);
- }
-
- while((len = read(fd, buf, sizeof(buf))) > 0) {
- if (zap_fsk_demod_feed(&fsk_data, buf, len / 2) != ZAP_SUCCESS) {
- break;
- }
- }
-
- while(zap_fsk_data_parse(&fsk_data, &type, &sp, &mlen) == ZAP_SUCCESS) {
- zap_copy_string(str, sp, mlen+1);
- *(str+mlen) = '\0';
- zap_clean_string(str);
- printf("TYPE %u (%s) LEN %u VAL [%s]\n", (unsigned)type, zap_mdmf_type2str(type), (unsigned)mlen, str);
- }
-
- zap_fsk_demod_destroy(&fsk_data);
-
- close(fd);
- return 0;
-}
diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c
deleted file mode 100644
index bc39cb5e5e..0000000000
--- a/libs/openzap/src/testisdn.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "openzap.h"
-#include
-
-
-static ZIO_SIGNAL_CB_FUNCTION(on_signal)
-{
- return ZAP_FAIL;
-}
-
-static int R = 0;
-static void handle_SIGINT(int sig)
-{
- if (sig);
- R = 0;
- return;
-}
-
-int main(int argc, char *argv[])
-{
- zap_span_t *span;
-
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
-
- if (argc < 2) {
- printf("umm no\n");
- exit(-1);
- }
-
- if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- printf("OpenZAP loaded\n");
-
- if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
- fprintf(stderr, "Error finding OpenZAP span\n");
- goto done;
- }
-
- if (zap_configure_span("isdn", span, on_signal,
- "mode", "te",
- "dialect", "national",
- TAG_END) == ZAP_SUCCESS) {
- zap_span_start(span);
- } else {
- fprintf(stderr, "Error starting ISDN D-Channel\n");
- goto done;
- }
-
- signal(SIGINT, handle_SIGINT);
- R = 1;
- while(R) {
- zap_sleep(1 * 1000);
- }
-
- done:
-
- zap_global_destroy();
-
- return 1;
-
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/testm3ua.c b/libs/openzap/src/testm3ua.c
deleted file mode 100644
index 16377cd067..0000000000
--- a/libs/openzap/src/testm3ua.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * testm3ua.c
- * openzap
- *
- * Created by Shane Burrell on 4/8/08.
- * Copyright 2008 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "testm3ua.h"
-#include "openzap.h"
-#include "zap_m3ua.h"
-
-static ZIO_SIGNAL_CB_FUNCTION(on_signal)
-{
- return ZAP_FAIL;
-}
-
-int main(int argc, char *argv[])
-{
- zap_span_t *span;
- //m3ua_data_t *data;
-
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
-
- if (argc < 5) {
- printf("more args needed\n");
- exit(-1);
- }
-
- if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- printf("OpenZAP loaded\n");
-
- if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
- fprintf(stderr, "Error finding OpenZAP span\n");
- goto done;
- }
-
-
- if (zap_m3ua_configure_span(span) == ZAP_SUCCESS) {
- //data = span->signal_data;
- zap_m3ua_start(span);
- } else {
- fprintf(stderr, "Error starting M3UA\n");
- goto done;
- }
-
- //while(zap_test_flag(data, ZAP_M3UA_RUNNING)) {
- // zap_sleep(1 * 1000);
- //}
-
- done:
-
- zap_global_destroy();
-
-}
diff --git a/libs/openzap/src/testpri.c b/libs/openzap/src/testpri.c
deleted file mode 100644
index 38d8222440..0000000000
--- a/libs/openzap/src/testpri.c
+++ /dev/null
@@ -1,162 +0,0 @@
-#include "openzap.h"
-#include
-
-static int THREADS[4][31] = { {0} };
-static int R = 0;
-static int T = 0;
-static zap_mutex_t *mutex = NULL;
-
-
-static void *channel_run(zap_thread_t *me, void *obj)
-{
- zap_channel_t *zchan = obj;
- int fd = -1;
- short buf[160];
-
- zap_mutex_lock(mutex);
- T++;
- zap_mutex_unlock(mutex);
-
- zap_set_state_locked_wait(zchan, ZAP_CHANNEL_STATE_UP);
-
- if ((fd = open("test.raw", O_RDONLY, 0)) < 0) {
- goto end;
- }
-
- while(R == 1 && THREADS[zchan->span_id][zchan->chan_id] == 1) {
- ssize_t bytes = read(fd, buf, sizeof(buf));
- size_t bbytes;
-
- if (bytes <= 0) {
- break;
- }
-
- bbytes = (size_t) bytes;
-
- zio_slin2alaw(buf, sizeof(buf), &bbytes);
-
- if (zap_channel_write(zchan, buf, sizeof(buf), &bbytes) != ZAP_SUCCESS) {
- break;
- }
- }
-
- close(fd);
-
- end:
-
- zap_set_state_locked_wait(zchan, ZAP_CHANNEL_STATE_HANGUP);
-
- THREADS[zchan->span_id][zchan->chan_id] = 0;
-
- zap_mutex_lock(mutex);
- T = 0;
- zap_mutex_unlock(mutex);
-
- return NULL;
-}
-
-static ZIO_SIGNAL_CB_FUNCTION(on_signal)
-{
- zap_log(ZAP_LOG_DEBUG, "got sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, zap_signal_event2str(sigmsg->event_id));
-
- switch(sigmsg->event_id) {
-
- case ZAP_SIGEVENT_STOP:
- THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = -1;
- break;
-
- case ZAP_SIGEVENT_START:
- if (!THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id]) {
- THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = 1;
- zap_thread_create_detached(channel_run, sigmsg->channel);
- }
-
- break;
- default:
- break;
- }
-
- return ZAP_SUCCESS;
-}
-
-
-static void handle_SIGINT(int sig)
-{
- if (sig);
-
- zap_mutex_lock(mutex);
- R = 0;
- zap_mutex_unlock(mutex);
-
- return;
-}
-
-int main(int argc, char *argv[])
-{
- zap_span_t *span;
- zap_mutex_create(&mutex);
-
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
-
- if (argc < 2) {
- printf("umm no\n");
- exit(-1);
- }
-
- if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- printf("OpenZAP loaded\n");
-
- if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
- fprintf(stderr, "Error finding OpenZAP span\n");
- goto done;
- }
-
-
-
- if (zap_configure_span(
- "libpri", span, on_signal,
- "node", "cpe",
- "switch", "euroisdn",
- "dp", "unknown",
- "l1", "alaw",
- "debug", NULL,
- "opts", 0,
- TAG_END) == ZAP_SUCCESS) {
-
-
- zap_span_start(span);
- } else {
- fprintf(stderr, "Error starting ISDN D-Channel\n");
- goto done;
- }
-
- signal(SIGINT, handle_SIGINT);
- zap_mutex_lock(mutex);
- R = 1;
- zap_mutex_unlock(mutex);
- while(R || T) {
- zap_sleep(1 * 1000);
- }
-
- done:
-
- zap_global_destroy();
-
- return 1;
-
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/testr2.c b/libs/openzap/src/testr2.c
deleted file mode 100644
index 50ced29543..0000000000
--- a/libs/openzap/src/testr2.c
+++ /dev/null
@@ -1,86 +0,0 @@
-#include "openzap.h"
-#include
-
-static int R = 0;
-static zap_mutex_t *mutex = NULL;
-
-static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal)
-{
- zap_log(ZAP_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", zap_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id);
- return ZAP_SUCCESS;
-}
-
-static void handle_SIGINT(int sig)
-{
- zap_mutex_lock(mutex);
- R = 0;
- zap_mutex_unlock(mutex);
- return;
-}
-
-int main(int argc, char *argv[])
-{
- zap_span_t *span;
- zap_mutex_create(&mutex);
-
- zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
-
- if (argc < 2) {
- printf("umm no\n");
- exit(-1);
- }
-
- if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
- exit(-1);
- }
-
- printf("OpenZAP loaded\n");
-
- if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) {
- fprintf(stderr, "Error finding OpenZAP span\n");
- goto done;
- }
-
-
-
- if (zap_configure_span("r2", span, on_r2_signal,
- "variant", "mx",
- "max_ani", 10,
- "max_dnis", 4,
- "logging", "all",
- TAG_END) == ZAP_SUCCESS) {
-
-
- zap_span_start(span);
- } else {
- fprintf(stderr, "Error starting R2 span\n");
- goto done;
- }
-
- signal(SIGINT, handle_SIGINT);
- zap_mutex_lock(mutex);
- R = 1;
- zap_mutex_unlock(mutex);
- while(R) {
- zap_sleep(1 * 1000);
- }
-
- done:
-
- zap_global_destroy();
-
- return 1;
-
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/testtones.c b/libs/openzap/src/testtones.c
deleted file mode 100644
index 273b793acf..0000000000
--- a/libs/openzap/src/testtones.c
+++ /dev/null
@@ -1,76 +0,0 @@
-#include "openzap.h"
-
-struct ttmp {
- int fd;
-};
-
-static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
-{
- struct ttmp *tmp = ts->user_data;
- int wrote;
- size_t len;
-
- wrote = teletone_mux_tones(ts, map);
- len = write(tmp->fd, ts->buffer, wrote * 2);
-
- if (!len) return -1;
-
- return 0;
-}
-
-#if 1
-int main(int argc, char *argv[])
-{
- teletone_generation_session_t ts;
- struct ttmp tmp;
-
- if (argc < 3) {
- fprintf(stderr, "Arg Error! \n");
- exit(-1);
- }
-
- if ((tmp.fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
- fprintf(stderr, "File Error! [%s]\n", strerror(errno));
- exit(-1);
- }
-
- teletone_init_session(&ts, 0, teletone_handler, &tmp);
- ts.rate = 8000;
- ts.debug = 1;
- ts.debug_stream = stdout;
- teletone_run(&ts, argv[2]);
- close(tmp.fd);
-
- return 0;
-}
-#else
-int32_t main(int argc, char *argv[])
-{
- int32_t j, i, fd = -1;
- int32_t rate = 8000;
- /* SIT tones and durations */
- float tones[] = { 913.8, 1370.6, 1776.7, 0 };
- int32_t durations[] = {274, 274, 380, 0};
- teletone_dds_state_t dds = {0};
- int16_t sample;
- size_t len = 1;
-
- if (argc < 2 || (fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
- fprintf(stderr, "File Error!\n", strerror(errno));
- exit(-1);
- }
-
- for (j = 0; tones[j] && durations[j]; j++) {
-
- teletone_dds_state_set_tone(&dds, tones[j], rate, -50);
-
- for(i = 0; (i < durations[j] * rate / 1000) && len != 0; i++) {
- sample = teletone_dds_modulate_sample(&dds) * 20;
- len = write(fd, &sample, sizeof(sample));
- }
-
- }
-
- close(fd);
-}
-#endif
diff --git a/libs/openzap/src/uart.c b/libs/openzap/src/uart.c
deleted file mode 100644
index 5e0dd85350..0000000000
--- a/libs/openzap/src/uart.c
+++ /dev/null
@@ -1,124 +0,0 @@
-
-/*
- * uart.c
- *
- * Copyright (c) 2005 Robert Krten. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This module contains a simple 8-bit UART, which performs a callback
- * with the decoded byte value.
- *
- * 2005 06 11 R. Krten created
-*/
-
-#include
-#include
-#include
-#include
-
-#include "uart.h"
-
-/*
- * dsp_uart_attr_init
- *
- * Initializes the attributes structure; this must be done before the
- * attributes structure is used.
-*/
-
-void dsp_uart_attr_init (dsp_uart_attr_t *attr)
-{
- memset (attr, 0, sizeof (*attr));
-}
-
-/*
- * dsp_uart_attr_get_bytehandler
- * dsp_uart_attr_set_bytehandler
- *
- * These functions get and set their respective elements from the
- * attributes structure. If an error code is returned, it is just
- * zero == ok, -1 == fail.
-*/
-
-bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attr, void **bytehandler_arg)
-{
- *bytehandler_arg = attr->bytehandler_arg;
- return attr->bytehandler;
-}
-
-void dsp_uart_attr_set_bytehandler(dsp_uart_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg)
-{
- attr->bytehandler = bytehandler;
- attr->bytehandler_arg = bytehandler_arg;
-}
-
-dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr)
-{
- dsp_uart_handle_t *handle;
-
- handle = malloc(sizeof (*handle));
- if (handle) {
- memset(handle, 0, sizeof (*handle));
-
- /* fill the attributes member */
- memcpy(&handle->attr, attr, sizeof (*attr));
- }
- return handle;
-}
-
-void dsp_uart_destroy(dsp_uart_handle_t **handle)
-{
- if (*handle) {
- free(*handle);
- *handle = NULL;
- }
-}
-
-
-void dsp_uart_bit_handler(void *x, int bit)
-{
- dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x;
-
- if (!handle->have_start) {
- if (bit) {
- return; /* waiting for start bit (0) */
- }
- handle->have_start = 1;
- handle->data = 0;
- handle->nbits = 0;
- return;
- }
-
- handle->data >>= 1;
- handle->data |= 0x80 * !!bit;
- handle->nbits++;
-
- if (handle->nbits == 8) {
- handle->attr.bytehandler(handle->attr.bytehandler_arg, handle->data);
- handle->nbits = 0;
- handle->data = 0;
- handle->have_start = 0;
- }
-/* might consider handling errors in the future... */
-}
-
diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c
deleted file mode 100644
index e317ac23e2..0000000000
--- a/libs/openzap/src/zap_buffer.c
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "openzap.h"
-#include "zap_buffer.h"
-
-static unsigned buffer_id = 0;
-
-struct zap_buffer {
- unsigned char *data;
- unsigned char *head;
- zap_size_t used;
- zap_size_t actually_used;
- zap_size_t datalen;
- zap_size_t max_len;
- zap_size_t blocksize;
- unsigned id;
- int loops;
-};
-
-
-OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len)
-{
- zap_buffer_t *new_buffer;
-
- new_buffer = malloc(sizeof(*new_buffer));
- if (new_buffer) {
- memset(new_buffer, 0, sizeof(*new_buffer));
-
- if (start_len) {
- new_buffer->data = malloc(start_len);
- if (!new_buffer->data) {
- free(new_buffer);
- return ZAP_MEMERR;
- }
- memset(new_buffer->data, 0, start_len);
- }
-
- new_buffer->max_len = max_len;
- new_buffer->datalen = start_len;
- new_buffer->id = buffer_id++;
- new_buffer->blocksize = blocksize;
- new_buffer->head = new_buffer->data;
-
- *buffer = new_buffer;
- return ZAP_SUCCESS;
- }
-
- return ZAP_MEMERR;
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer)
-{
-
- assert(buffer != NULL);
-
- return buffer->datalen;
-
-}
-
-
-OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer)
-{
- assert(buffer != NULL);
-
-
- if (buffer->max_len) {
- return (zap_size_t) (buffer->max_len - buffer->used);
- }
- return 1000000;
-
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer)
-{
- assert(buffer != NULL);
-
- return buffer->used;
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen)
-{
- zap_size_t reading = 0;
-
- assert(buffer != NULL);
-
- if (buffer->used < 1) {
- buffer->used = 0;
- return 0;
- } else if (buffer->used >= datalen) {
- reading = datalen;
- } else {
- reading = buffer->used;
- }
-
- buffer->used = buffer->actually_used - reading;
- buffer->head = buffer->data + reading;
-
- return reading;
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen)
-{
- zap_size_t reading = 0;
-
- assert(buffer != NULL);
-
- if (buffer->used < 1) {
- buffer->used = 0;
- return 0;
- } else if (buffer->used >= datalen) {
- reading = datalen;
- } else {
- reading = buffer->used;
- }
-
- buffer->used -= reading;
- buffer->head += reading;
-
- return buffer->used;
-}
-
-OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int loops)
-{
- buffer->loops = loops;
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen)
-{
- zap_size_t len;
- if ((len = zap_buffer_read(buffer, data, datalen)) < datalen) {
- if (buffer->loops == 0) {
- return len;
- }
- buffer->head = buffer->data;
- buffer->used = buffer->actually_used;
- len = zap_buffer_read(buffer, (char*)data + len, datalen - len);
- buffer->loops--;
- }
- return len;
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen)
-{
- zap_size_t reading = 0;
-
- assert(buffer != NULL);
- assert(data != NULL);
-
-
- if (buffer->used < 1) {
- buffer->used = 0;
- return 0;
- } else if (buffer->used >= datalen) {
- reading = datalen;
- } else {
- reading = buffer->used;
- }
-
- memcpy(data, buffer->head, reading);
- buffer->used -= reading;
- buffer->head += reading;
-
- /* if (buffer->id == 4) printf("%u o %d = %d\n", buffer->id, (unsigned)reading, (unsigned)buffer->used); */
- return reading;
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen)
-{
- zap_size_t freespace, actual_freespace;
-
- assert(buffer != NULL);
- assert(data != NULL);
- assert(buffer->data != NULL);
-
- if (!datalen) {
- return buffer->used;
- }
-
- actual_freespace = buffer->datalen - buffer->actually_used;
- if (actual_freespace < datalen && (!buffer->max_len || (buffer->used + datalen <= buffer->max_len))) {
- memmove(buffer->data, buffer->head, buffer->used);
- buffer->head = buffer->data;
- buffer->actually_used = buffer->used;
- }
-
- freespace = buffer->datalen - buffer->used;
-
- /*
- if (buffer->data != buffer->head) {
- memmove(buffer->data, buffer->head, buffer->used);
- buffer->head = buffer->data;
- }
- */
-
- if (freespace < datalen) {
- zap_size_t new_size, new_block_size;
- void *data;
-
- new_size = buffer->datalen + datalen;
- new_block_size = buffer->datalen + buffer->blocksize;
-
- if (new_block_size > new_size) {
- new_size = new_block_size;
- }
- buffer->head = buffer->data;
- data = realloc(buffer->data, new_size);
- if (!data) {
- return 0;
- }
- buffer->data = data;
- buffer->head = buffer->data;
- buffer->datalen = new_size;
- }
-
-
- freespace = buffer->datalen - buffer->used;
-
- if (freespace < datalen) {
- return 0;
- } else {
- memcpy(buffer->head + buffer->used, data, datalen);
- buffer->used += datalen;
- buffer->actually_used += datalen;
- }
- /* if (buffer->id == 4) printf("%u i %d = %d\n", buffer->id, (unsigned)datalen, (unsigned)buffer->used); */
-
- return buffer->used;
-}
-
-OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer)
-{
- assert(buffer != NULL);
- assert(buffer->data != NULL);
-
- buffer->used = 0;
- buffer->actually_used = 0;
- buffer->head = buffer->data;
-}
-
-OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen)
-{
- zap_size_t w;
-
- if (!(w = zap_buffer_write(buffer, data, datalen))) {
- zap_buffer_zero(buffer);
- return zap_buffer_write(buffer, data, datalen);
- }
-
- return w;
-}
-
-OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer)
-{
- if (*buffer) {
- free((*buffer)->data);
- free(*buffer);
- }
-
- *buffer = NULL;
-}
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c
deleted file mode 100644
index 7a6e658261..0000000000
--- a/libs/openzap/src/zap_callerid.c
+++ /dev/null
@@ -1,307 +0,0 @@
-#include "openzap.h"
-#include "fsk.h"
-#include "uart.h"
-
-
-
-static void fsk_byte_handler (void *x, int data)
-{
- zap_fsk_data_state_t *state = (zap_fsk_data_state_t *) x;
- uint8_t byte = (uint8_t)data;
-
- top:
-
- if (state->init == 3) {
- return;
- }
-
- if (state->dlen) {
- goto add_byte;
- }
-
- if (state->bpos == 1) {
- state->blen = byte;
-
- if ((uint32_t)(state->dlen = state->bpos + byte + 2) > state->bufsize) {
- state->dlen = state->bufsize;
- }
- goto top;
- }
-
- add_byte:
-
- if (state->bpos <= state->dlen) {
- state->buf[state->bpos++] = byte;
- } else {
- state->init = 3;
- }
-}
-
-OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen)
-{
- memset(state, 0, sizeof(*state));
- state->buf = data;
- state->bufsize = datalen;
- state->bpos = 2;
-
- return ZAP_SUCCESS;
-}
-
-OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number)
-{
- size_t dlen = strlen(date);
- size_t nlen = strlen(number);
-
- state->buf[0] = ZAP_CID_TYPE_SDMF;
- memcpy(&state->buf[state->bpos], date, dlen);
- state->bpos += dlen;
- memcpy(&state->buf[state->bpos], number, nlen);
- state->bpos += nlen;
-
- return ZAP_SUCCESS;
-}
-
-OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen)
-{
- state->buf[0] = ZAP_CID_TYPE_MDMF;
- state->buf[state->bpos++] = type;
- state->buf[state->bpos++] = (uint8_t)datalen;
- memcpy(&state->buf[state->bpos], data, datalen);
- state->bpos += datalen;
- return ZAP_SUCCESS;
-}
-
-
-OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state)
-{
- uint32_t i;
- uint8_t check = 0;
-
- state->buf[1] = (uint8_t)(state->bpos - 2);
-
- for (i = 0; i < state->bpos; i++) {
- check = check + state->buf[i];
- }
-
- state->checksum = state->buf[state->bpos] = (uint8_t)(256 - check);
- state->bpos++;
-
- state->dlen = state->bpos;
- state->blen = state->buf[1];
-
- return ZAP_SUCCESS;
-}
-
-
-OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len)
-{
-
- zap_size_t i;
- int sum = 0;
-
- top:
-
- if (state->checksum != 0 || state->ppos >= state->dlen - 1) {
- return ZAP_FAIL;
- }
-
- if (!state->ppos) {
- for(i = 0; i < state->bpos; i++) {
- sum += state->buf[i];
- }
- state->checksum = sum % 256;
- state->ppos = 2;
-
- if (state->buf[0] != ZAP_CID_TYPE_MDMF && state->buf[0] != ZAP_CID_TYPE_SDMF) {
- state->checksum = -1;
- }
- goto top;
- }
-
- if (state->buf[0] == ZAP_CID_TYPE_SDMF) {
- /* convert sdmf to mdmf so we don't need 2 parsers */
- if (state->ppos == 2) {
- *type = MDMF_DATETIME;
- *len = 8;
- } else {
- if (state->buf[state->ppos] == 'P' || state->buf[state->ppos] == 'O') {
- *type = MDMF_NO_NUM;
- *len = 1;
- } else {
- *type = MDMF_PHONE_NUM;
- *len = state->blen - 8;
- }
- }
- *data = (char *)&state->buf[state->ppos];
- state->ppos += *len;
- return ZAP_SUCCESS;
- } else if (state->buf[0] == ZAP_CID_TYPE_MDMF) {
- *type = state->buf[state->ppos++];
- *len = state->buf[state->ppos++];
- *data = (char *)&state->buf[state->ppos];
- state->ppos += *len;
- return ZAP_SUCCESS;
- }
-
- return ZAP_FAIL;
-}
-
-OZ_DECLARE(zap_status_t) zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, zap_size_t samples)
-{
- uint32_t x;
- int16_t *sp = data;
-
- if (state->init == 3) {
- return ZAP_FAIL;
- }
-
- for (x = 0; x < samples; x++) {
- dsp_fsk_sample (state->fsk1200_handle, (double) *sp++ / 32767.0);
- if (state->dlen && state->bpos >= state->dlen) {
- state->init = 3;
- return ZAP_FAIL;
- }
- }
-
- return ZAP_SUCCESS;
-}
-
-OZ_DECLARE(zap_status_t) zap_fsk_demod_destroy(zap_fsk_data_state_t *state)
-{
- dsp_fsk_destroy(&state->fsk1200_handle);
- memset(state, 0, sizeof(*state));
- return ZAP_SUCCESS;
-}
-
-OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_size_t bufsize)
-{
-
- dsp_fsk_attr_t fsk1200_attr;
-
- if (state->fsk1200_handle) {
- dsp_fsk_destroy(&state->fsk1200_handle);
- }
-
- memset(state, 0, sizeof(*state));
- memset(buf, 0, bufsize);
- state->buf = buf;
- state->bufsize = bufsize;
-
- dsp_fsk_attr_init (&fsk1200_attr);
- dsp_fsk_attr_set_samplerate (&fsk1200_attr, rate);
- dsp_fsk_attr_set_bytehandler (&fsk1200_attr, fsk_byte_handler, state);
- state->fsk1200_handle = dsp_fsk_create (&fsk1200_attr);
-
- if (state->fsk1200_handle == NULL) {
- return ZAP_FAIL;
- }
-
- return ZAP_SUCCESS;
-}
-
-OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen)
-{
- zap_size_t i;
-
- for(i = 0 ; i < buflen; i++) {
- fsk_trans->bit_accum += fsk_trans->bit_factor;
- if (fsk_trans->bit_accum >= ZAP_FSK_MOD_FACTOR) {
- fsk_trans->bit_accum -= (ZAP_FSK_MOD_FACTOR + fsk_trans->bit_factor);
- break;
- }
-
- buf[i] = teletone_dds_state_modulate_sample(&fsk_trans->dds, bit);
- }
-
- return i;
-}
-
-
-OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits)
-{
- uint32_t i = 0;
- zap_size_t r = 0;
- int8_t bit = 1;
-
- for (i = 0; i < bits; i++) {
- if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
- if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) {
- break;
- }
- } else {
- break;
- }
- }
-
- return i;
-}
-
-
-OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans)
-{
- uint32_t i = 0;
- zap_size_t r = 0;
- int8_t bit = 0;
-
- for (i = 0; i < fsk_trans->chan_sieze_bits; i++) {
- if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
- if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) {
- break;
- }
- } else {
- break;
- }
- bit = !bit;
- }
-
-
-}
-
-
-OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans)
-{
- zap_size_t r = 0;
- int8_t bit = 0;
-
- while((bit = zap_bitstream_get_bit(&fsk_trans->bs)) > -1) {
- if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) {
- if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) {
- break;
- }
- } else {
- break;
- }
- }
-}
-
-
-OZ_DECLARE(zap_status_t) zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans,
- fsk_modem_types_t modem_type,
- uint32_t sample_rate,
- zap_fsk_data_state_t *fsk_data,
- float db_level,
- uint32_t carrier_bits_start,
- uint32_t carrier_bits_stop,
- uint32_t chan_sieze_bits,
- zap_fsk_write_sample_t write_sample_callback,
- void *user_data)
-{
- memset(fsk_trans, 0, sizeof(*fsk_trans));
- fsk_trans->modem_type = modem_type;
- teletone_dds_state_set_tone(&fsk_trans->dds, fsk_modem_definitions[fsk_trans->modem_type].freq_space, sample_rate, 0);
- teletone_dds_state_set_tone(&fsk_trans->dds, fsk_modem_definitions[fsk_trans->modem_type].freq_mark, sample_rate, 1);
- fsk_trans->bit_factor = (uint32_t)((fsk_modem_definitions[fsk_trans->modem_type].baud_rate * ZAP_FSK_MOD_FACTOR) / (float)sample_rate);
- fsk_trans->samples_per_bit = (uint32_t) (sample_rate / fsk_modem_definitions[fsk_trans->modem_type].baud_rate);
- fsk_trans->est_bytes = (int32_t)(((fsk_data->dlen * 10) + carrier_bits_start + carrier_bits_stop + chan_sieze_bits) * ((fsk_trans->samples_per_bit + 1) * 2));
- fsk_trans->bit_accum = 0;
- fsk_trans->fsk_data = fsk_data;
- teletone_dds_state_set_tx_level(&fsk_trans->dds, db_level);
- zap_bitstream_init(&fsk_trans->bs, fsk_trans->fsk_data->buf, (uint32_t)fsk_trans->fsk_data->dlen, ZAP_ENDIAN_BIG, 1);
- fsk_trans->carrier_bits_start = carrier_bits_start;
- fsk_trans->carrier_bits_stop = carrier_bits_stop;
- fsk_trans->chan_sieze_bits = chan_sieze_bits;
- fsk_trans->write_sample_callback = write_sample_callback;
- fsk_trans->user_data = user_data;
- return ZAP_SUCCESS;
-}
-
diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c
deleted file mode 100644
index 3951f6b4fe..0000000000
--- a/libs/openzap/src/zap_config.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright (c) 2007-2014, Anthony Minessale II
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "openzap.h"
-#include "zap_config.h"
-
-int zap_config_open_file(zap_config_t *cfg, const char *file_path)
-{
- FILE *f;
- const char *path = NULL;
- char path_buf[1024];
-
- if (file_path[0] == '/') {
- path = file_path;
- } else {
- snprintf(path_buf, sizeof(path_buf), "%s%s%s", ZAP_CONFIG_DIR, ZAP_PATH_SEPARATOR, file_path);
- path = path_buf;
- }
-
- if (!path) {
- return 0;
- }
-
- memset(cfg, 0, sizeof(*cfg));
- cfg->lockto = -1;
- zap_log(ZAP_LOG_DEBUG, "Configuration file is %s.\n", path);
- f = fopen(path, "r");
-
- if (!f) {
- if (file_path[0] != '/') {
- int last = -1;
- char *var, *val;
-
- snprintf(path_buf, sizeof(path_buf), "%s%sopenzap.conf", ZAP_CONFIG_DIR, ZAP_PATH_SEPARATOR);
- path = path_buf;
-
- if ((f = fopen(path, "r")) == 0) {
- return 0;
- }
-
- cfg->file = f;
- zap_set_string(cfg->path, path);
-
- while (zap_config_next_pair(cfg, &var, &val)) {
- if ((cfg->sectno != last) && !strcmp(cfg->section, file_path)) {
- cfg->lockto = cfg->sectno;
- return 1;
- }
- }
-
- zap_config_close_file(cfg);
- memset(cfg, 0, sizeof(*cfg));
- return 0;
- }
-
- return 0;
- } else {
- cfg->file = f;
- zap_set_string(cfg->path, path);
- return 1;
- }
-}
-
-void zap_config_close_file(zap_config_t *cfg)
-{
-
- if (cfg->file) {
- fclose(cfg->file);
- }
-
- memset(cfg, 0, sizeof(*cfg));
-}
-
-
-
-int zap_config_next_pair(zap_config_t *cfg, char **var, char **val)
-{
- int ret = 0;
- char *p, *end;
-
- *var = *val = NULL;
-
- if (!cfg->path) {
- return 0;
- }
-
- for (;;) {
- cfg->lineno++;
-
- if (!fgets(cfg->buf, sizeof(cfg->buf), cfg->file)) {
- ret = 0;
- break;
- }
- *var = cfg->buf;
-
- if (**var == '[' && (end = strchr(*var, ']')) != 0) {
- *end = '\0';
- (*var)++;
- if (**var == '+') {
- (*var)++;
- zap_copy_string(cfg->section, *var, sizeof(cfg->section));
- cfg->sectno++;
-
- if (cfg->lockto > -1 && cfg->sectno != cfg->lockto) {
- break;
- }
- cfg->catno = 0;
- cfg->lineno = 0;
- *var = (char *) "";
- *val = (char *) "";
- return 1;
- } else {
- zap_copy_string(cfg->category, *var, sizeof(cfg->category));
- cfg->catno++;
- }
- continue;
- }
-
-
-
- if (**var == '#' || **var == ';' || **var == '\n' || **var == '\r') {
- continue;
- }
-
- if (!strncmp(*var, "__END__", 7)) {
- break;
- }
-
-
- if ((end = strchr(*var, ';')) && *(end+1) == *end) {
- *end = '\0';
- end--;
- } else if ((end = strchr(*var, '\n')) != 0) {
- if (*(end - 1) == '\r') {
- end--;
- }
- *end = '\0';
- }
-
- p = *var;
- while ((*p == ' ' || *p == '\t') && p != end) {
- *p = '\0';
- p++;
- }
- *var = p;
-
-
- if ((*val = strchr(*var, '=')) == 0) {
- ret = -1;
- /* log_printf(0, server.log, "Invalid syntax on %s: line %d\n", cfg->path, cfg->lineno); */
- continue;
- } else {
- p = *val - 1;
- *(*val) = '\0';
- (*val)++;
- if (*(*val) == '>') {
- *(*val) = '\0';
- (*val)++;
- }
-
- while ((*p == ' ' || *p == '\t') && p != *var) {
- *p = '\0';
- p--;
- }
-
- p = *val;
- while ((*p == ' ' || *p == '\t') && p != end) {
- *p = '\0';
- p++;
- }
- *val = p;
- ret = 1;
- break;
- }
- }
-
-
- return ret;
-
-}
-
-OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits)
-{
- char cas_bits[5];
- unsigned char bit = 0x8;
- int x = 0;
- char *double_colon = strchr(strvalue, ':');
- if (!double_colon) {
- zap_log(ZAP_LOG_ERROR, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", strvalue);
- return -1;
- }
- double_colon++;
- *outbits = 0;
- cas_bits[4] = 0;
- if (sscanf(double_colon, "%c%c%c%c", &cas_bits[0], &cas_bits[1], &cas_bits[2], &cas_bits[3]) != 4) {
- zap_log(ZAP_LOG_ERROR, "Invalid CAS bits specified: '%s', :xxxx definition expected, where x is 1 or 0\n", double_colon);
- return -1;
- }
- zap_log(ZAP_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits);
- for (; cas_bits[x]; x++) {
- if ('1' == cas_bits[x]) {
- *outbits |= bit;
- } else if ('0' != cas_bits[x]) {
- zap_log(ZAP_LOG_ERROR, "Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n");
- return -1;
- }
- bit >>= 1;
- }
- return 0;
-}
-
-/* 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 noet:
- */
diff --git a/libs/openzap/src/zap_cpu_monitor.c b/libs/openzap/src/zap_cpu_monitor.c
deleted file mode 100644
index 412c80489e..0000000000
--- a/libs/openzap/src/zap_cpu_monitor.c
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Copyright (c) 2009, Sangoma Technologies
- * Moises Silva
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the original author; nor the names of any contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Contributors:
- * David Yat Sin
- *
- */
-
-#ifdef WIN32
-#define _WIN32_WINNT 0x0501 // To make GetSystemTimes visible in windows.h
-#include